@@ -229,6 +229,75 @@ void retryableSubAsyncRequestBodyEnabled_shouldBeAbleToResubscribe() throws Exec
229229 }
230230 }
231231
232+ @ ParameterizedTest
233+ @ ValueSource (booleans = {true , false })
234+ void upstreamError_shouldPropagateToCurrentBodySubscriber (boolean enableRetryableSubAsyncRequestBody ) throws Exception {
235+ RuntimeException upstreamError = new RuntimeException ("upstream failure" );
236+ AsyncRequestBody errorBody = new AsyncRequestBody () {
237+ @ Override
238+ public Optional <Long > contentLength () {
239+ return Optional .of (20L );
240+ }
241+
242+ @ Override
243+ public void subscribe (Subscriber <? super ByteBuffer > s ) {
244+ s .onSubscribe (new Subscription () {
245+ private int calls = 0 ;
246+
247+ @ Override
248+ public void request (long n ) {
249+ if (calls ++ == 0 ) {
250+ // Send partial data, then error
251+ s .onNext (ByteBuffer .wrap (new byte [3 ]));
252+ } else {
253+ s .onError (upstreamError );
254+ }
255+ }
256+
257+ @ Override
258+ public void cancel () {
259+ }
260+ });
261+ }
262+ };
263+
264+ SplittingPublisher splittingPublisher =
265+ SplittingPublisher .builder ()
266+ .asyncRequestBody (errorBody )
267+ .splitConfiguration (AsyncRequestBodySplitConfiguration .builder ()
268+ .chunkSizeInBytes (10L )
269+ .bufferSizeInBytes (20L )
270+ .build ())
271+ .retryableSubAsyncRequestBodyEnabled (enableRetryableSubAsyncRequestBody )
272+ .build ();
273+
274+ CompletableFuture <Throwable > bodyError = new CompletableFuture <>();
275+ splittingPublisher .subscribe (requestBody -> {
276+ requestBody .subscribe (new Subscriber <ByteBuffer >() {
277+ @ Override
278+ public void onSubscribe (Subscription s ) {
279+ s .request (Long .MAX_VALUE );
280+ }
281+
282+ @ Override
283+ public void onNext (ByteBuffer byteBuffer ) {
284+ }
285+
286+ @ Override
287+ public void onError (Throwable t ) {
288+ bodyError .complete (t );
289+ }
290+
291+ @ Override
292+ public void onComplete () {
293+ }
294+ });
295+ });
296+
297+ Throwable error = bodyError .get (5 , TimeUnit .SECONDS );
298+ assertThat (error ).isEqualTo (upstreamError );
299+ }
300+
232301 private static void verifySplitContent (AsyncRequestBody asyncRequestBody , int chunkSize ) throws Exception {
233302 SplittingPublisher splittingPublisher = SplittingPublisher .builder ()
234303 .asyncRequestBody (asyncRequestBody )
0 commit comments