@@ -244,7 +244,8 @@ public void badRequest() {
244
244
when (sdkHttpResponse .statusCode ()).thenReturn (400 );
245
245
final ProgressEvent <Model ,
246
246
StdCallbackContext > result = proxy .initiate ("client:createRespository" , proxy .newProxy (() -> null ), model , context )
247
- .translate (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ()).call ((r , c ) -> {
247
+ .translateToServiceRequest (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ())
248
+ .makeServiceCall ((r , c ) -> {
248
249
throw new BadRequestException (mock (AwsServiceException .Builder .class )) {
249
250
private static final long serialVersionUID = 1L ;
250
251
@@ -273,7 +274,8 @@ public void notFound() {
273
274
when (sdkHttpResponse .statusCode ()).thenReturn (404 );
274
275
ProgressEvent <Model ,
275
276
StdCallbackContext > result = proxy .initiate ("client:createRespository" , proxy .newProxy (() -> null ), model , context )
276
- .translate (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ()).call ((r , c ) -> {
277
+ .translateToServiceRequest (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ())
278
+ .makeServiceCall ((r , c ) -> {
277
279
throw new NotFoundException (mock (AwsServiceException .Builder .class )) {
278
280
private static final long serialVersionUID = 1L ;
279
281
@@ -302,7 +304,8 @@ public void accessDenied() {
302
304
when (sdkHttpResponse .statusCode ()).thenReturn (401 );
303
305
ProgressEvent <Model ,
304
306
StdCallbackContext > result = proxy .initiate ("client:createRespository" , proxy .newProxy (() -> null ), model , context )
305
- .translate (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ()).call ((r , c ) -> {
307
+ .translateToServiceRequest (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ())
308
+ .makeServiceCall ((r , c ) -> {
306
309
throw new AccessDenied (AwsServiceException .builder ()) {
307
310
private static final long serialVersionUID = 1L ;
308
311
@@ -354,8 +357,9 @@ public void throttleHandlingSuccess() {
354
357
355
358
ProgressEvent <Model ,
356
359
StdCallbackContext > result = proxy .initiate ("client:createRepository" , svcClient , model , context )
357
- .translate (m -> (requests [0 ] = new CreateRequest .Builder ().repoName (m .getRepoName ()).build ()))
358
- .backoff (Constant .of ().delay (Duration .ofSeconds (1 )).timeout (Duration .ofSeconds (3 )).build ()).call ((r , c ) -> {
360
+ .translateToServiceRequest (m -> (requests [0 ] = new CreateRequest .Builder ().repoName (m .getRepoName ()).build ()))
361
+ .backoffDelay (Constant .of ().delay (Duration .ofSeconds (1 )).timeout (Duration .ofSeconds (3 )).build ())
362
+ .makeServiceCall ((r , c ) -> {
359
363
if (attempt [0 ]-- > 0 ) {
360
364
throw new ThrottleException (builder ) {
361
365
private static final long serialVersionUID = 1L ;
@@ -371,8 +375,10 @@ public AwsErrorDetails awsErrorDetails() {
371
375
})
372
376
.done ((request , response , client1 , model1 , context1 ) -> proxy
373
377
.initiate ("client:readRepository" , client1 , model1 , context1 )
374
- .translate (m -> (describeRequests [0 ] = new DescribeRequest .Builder ().repoName (m .getRepoName ()).build ()))
375
- .call ((r , c ) -> (describeResponses [0 ] = c .injectCredentialsAndInvokeV2 (r , c .client ()::describeRepository )))
378
+ .translateToServiceRequest (
379
+ m -> (describeRequests [0 ] = new DescribeRequest .Builder ().repoName (m .getRepoName ()).build ()))
380
+ .makeServiceCall (
381
+ (r , c ) -> (describeResponses [0 ] = c .injectCredentialsAndInvokeV2 (r , c .client ()::describeRepository )))
376
382
.done (r -> {
377
383
Model resultModel = new Model ();
378
384
resultModel .setRepoName (r .getRepoName ());
@@ -421,8 +427,9 @@ public void throttledExceedRuntimeBailout() {
421
427
422
428
final ProgressEvent <Model ,
423
429
StdCallbackContext > result = proxy .initiate ("client:createRepository" , svcClient , model , context )
424
- .translate (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ())
425
- .backoff (Constant .of ().delay (Duration .ofSeconds (5 )).timeout (Duration .ofSeconds (10 )).build ()).call ((r , c ) -> {
430
+ .translateToServiceRequest (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ())
431
+ .backoffDelay (Constant .of ().delay (Duration .ofSeconds (5 )).timeout (Duration .ofSeconds (10 )).build ())
432
+ .makeServiceCall ((r , c ) -> {
426
433
throw new ThrottleException (AwsServiceException .builder ()) {
427
434
private static final long serialVersionUID = 1L ;
428
435
@@ -453,9 +460,9 @@ public void serviceCallWithStabilization() {
453
460
ProxyClient <ServiceClient > svcClient = proxy .newProxy (() -> client );
454
461
ProgressEvent <Model ,
455
462
StdCallbackContext > result = proxy .initiate ("client:createRepository" , svcClient , model , context )
456
- .translate (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ())
457
- .backoff (Constant .of ().delay (Duration .ofSeconds (5 )).timeout (Duration .ofSeconds (15 )).build ())
458
- .call ((r , c ) -> c .injectCredentialsAndInvokeV2 (r , c .client ()::createRepository ))
463
+ .translateToServiceRequest (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ())
464
+ .backoffDelay (Constant .of ().delay (Duration .ofSeconds (5 )).timeout (Duration .ofSeconds (15 )).build ())
465
+ .makeServiceCall ((r , c ) -> c .injectCredentialsAndInvokeV2 (r , c .client ()::createRepository ))
459
466
.stabilize ((request , response , client1 , model1 , context1 ) -> attempt [0 ]-- > 0 )
460
467
.retryErrorFilter ((request , exception , client1 , model1 , context1 ) -> exception instanceof ThrottleException )
461
468
.done (ign -> ProgressEvent .success (model , context ));
@@ -492,9 +499,9 @@ public AwsErrorDetails awsErrorDetails() {
492
499
493
500
final ProgressEvent <Model ,
494
501
StdCallbackContext > result = proxy .initiate ("client:createRepository" , svcClient , model , context )
495
- .translate (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ())
496
- .backoff (Constant .of ().delay (Duration .ofSeconds (5 )).timeout (Duration .ofSeconds (10 )).build ())
497
- .call ((r , c ) -> c .injectCredentialsAndInvokeV2 (r , c .client ()::createRepository ))
502
+ .translateToServiceRequest (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ())
503
+ .backoffDelay (Constant .of ().delay (Duration .ofSeconds (5 )).timeout (Duration .ofSeconds (10 )).build ())
504
+ .makeServiceCall ((r , c ) -> c .injectCredentialsAndInvokeV2 (r , c .client ()::createRepository ))
498
505
.retryErrorFilter ((request , response , client1 , model1 , context1 ) -> response instanceof ThrottleException )
499
506
.done (ign -> ProgressEvent .success (model , context ));
500
507
@@ -515,11 +522,13 @@ public void throwNotRetryableException() {
515
522
StdCallbackContext context = new StdCallbackContext ();
516
523
ServiceClient client = mock (ServiceClient .class );
517
524
ProxyClient <ServiceClient > svcClient = proxy .newProxy (() -> client );
518
- ProgressEvent <Model , StdCallbackContext > result = proxy .initiate ("client:createRepository" , svcClient , model , context )
519
- .translate (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ()).call ((r , g ) -> {
520
- NonRetryableException e = NonRetryableException .builder ().build ();
521
- throw e ;
522
- }).success ();
525
+ ProgressEvent <Model ,
526
+ StdCallbackContext > result = proxy .initiate ("client:createRepository" , svcClient , model , context )
527
+ .translateToServiceRequest (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ())
528
+ .makeServiceCall ((r , g ) -> {
529
+ NonRetryableException e = NonRetryableException .builder ().build ();
530
+ throw e ;
531
+ }).success ();
523
532
assertThat (result .getStatus ()).isEqualTo (OperationStatus .FAILED );
524
533
525
534
}
@@ -539,7 +548,8 @@ public void throwOtherException() {
539
548
ProxyClient <ServiceClient > svcClient = proxy .newProxy (() -> client );
540
549
assertThrows (ResourceAlreadyExistsException .class ,
541
550
() -> proxy .initiate ("client:createRepository" , svcClient , model , context )
542
- .translate (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ()).call ((r , g ) -> {
551
+ .translateToServiceRequest (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ())
552
+ .makeServiceCall ((r , g ) -> {
543
553
throw new ResourceAlreadyExistsException (new RuntimeException ("Fail" ));
544
554
}).success ());
545
555
}
@@ -555,10 +565,12 @@ public void useInitiatorPattern() {
555
565
ServiceClient client = mock (ServiceClient .class );
556
566
final CallChain .Initiator <ServiceClient , Model , StdCallbackContext > invoker = proxy
557
567
.newInitiator (() -> client , model , context ).rebindModel (model ).rebindCallback (context );
558
- assertThrows (ResourceAlreadyExistsException .class , () -> invoker .initiate ("client:createRepository" )
559
- .translate (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ()).call ((r , g ) -> {
560
- throw new ResourceAlreadyExistsException (new RuntimeException ("Fail" ));
561
- }).success ());
568
+ assertThrows (ResourceAlreadyExistsException .class ,
569
+ () -> invoker .initiate ("client:createRepository" )
570
+ .translateToServiceRequest (m -> new CreateRequest .Builder ().repoName (m .getRepoName ()).build ())
571
+ .makeServiceCall ((r , g ) -> {
572
+ throw new ResourceAlreadyExistsException (new RuntimeException ("Fail" ));
573
+ }).success ());
562
574
}
563
575
564
576
@ Test
0 commit comments