@@ -120,6 +120,7 @@ public void testSuccess() throws Exception {
120
120
RetryingExecutorWithContext <String > executor =
121
121
getExecutor (getAlgorithm (getDefaultRetrySettings (), 0 , null ));
122
122
RetryingFuture <String > future = executor .createFuture (callable , retryingContext );
123
+ callable .setExternalFuture (future );
123
124
future .setAttemptFuture (executor .submit (future ));
124
125
125
126
assertFutureSuccess (future );
@@ -136,6 +137,7 @@ public void testSuccessWithFailures() throws Exception {
136
137
RetryingExecutorWithContext <String > executor =
137
138
getExecutor (getAlgorithm (getDefaultRetrySettings (), 0 , null ));
138
139
RetryingFuture <String > future = executor .createFuture (callable , retryingContext );
140
+ callable .setExternalFuture (future );
139
141
future .setAttemptFuture (executor .submit (future ));
140
142
141
143
assertFutureSuccess (future );
@@ -153,6 +155,7 @@ public void testSuccessWithFailuresPeekGetAttempt() throws Exception {
153
155
RetryingExecutorWithContext <String > executor =
154
156
getExecutor (getAlgorithm (getDefaultRetrySettings (), 0 , null ));
155
157
RetryingFuture <String > future = executor .createFuture (callable , retryingContext );
158
+ callable .setExternalFuture (future );
156
159
157
160
assertNull (future .peekAttemptResult ());
158
161
assertSame (future .peekAttemptResult (), future .peekAttemptResult ());
@@ -179,6 +182,7 @@ public void testMaxRetriesExceeded() throws Exception {
179
182
RetryingExecutorWithContext <String > executor =
180
183
getExecutor (getAlgorithm (getDefaultRetrySettings (), 0 , null ));
181
184
RetryingFuture <String > future = executor .createFuture (callable , retryingContext );
185
+ callable .setExternalFuture (future );
182
186
future .setAttemptFuture (executor .submit (future ));
183
187
184
188
assertFutureFail (future , CustomException .class );
@@ -211,6 +215,7 @@ public void testTotalTimeoutExceeded() throws Exception {
211
215
context = FakeCallContext .createDefault ().withTracer (tracer );
212
216
}
213
217
RetryingFuture <String > future = executor .createFuture (callable , context );
218
+ callable .setExternalFuture (future );
214
219
future .setAttemptFuture (executor .submit (future ));
215
220
216
221
assertFutureFail (future , CustomException .class );
@@ -222,28 +227,29 @@ public void testTotalTimeoutExceeded() throws Exception {
222
227
}
223
228
224
229
@ Test
225
- public void testCancelOuterFutureBeforeStart () throws Exception {
226
- FailingCallable callable = new FailingCallable (4 , "request" , "SUCCESS " , tracer );
230
+ public void testCancelOuterFutureBeforeStart () {
231
+ FailingCallable callable = new FailingCallable (0 , "request" , "FAILURE " , tracer );
227
232
228
233
RetrySettings retrySettings =
229
234
FAST_RETRY_SETTINGS
230
235
.toBuilder ()
231
236
.setInitialRetryDelay (Duration .ofMillis (1_000L ))
232
237
.setMaxRetryDelay (Duration .ofMillis (1_000L ))
233
- .setTotalTimeout (Duration .ofMillis (10_0000L ))
238
+ .setTotalTimeout (Duration .ofMillis (10_000L ))
234
239
.build ();
235
240
RetryingExecutorWithContext <String > executor =
236
241
getExecutor (getAlgorithm (retrySettings , 0 , null ));
237
242
RetryingFuture <String > future = executor .createFuture (callable , retryingContext );
243
+ callable .setExternalFuture (future );
238
244
boolean res = future .cancel (false );
239
-
240
245
assertTrue (res );
246
+ assertTrue (future .isCancelled ());
241
247
242
248
future .setAttemptFuture (executor .submit (future ));
243
-
244
- assertFutureCancel (future );
245
249
assertEquals (0 , future .getAttemptSettings ().getAttemptCount ());
246
250
251
+ // Tracer should have 0 interactions as the externalFuture has already been cancelled
252
+ // FailingCallable should exit immediately and no tracer logic should be invoked
247
253
verifyNoMoreInteractions (tracer );
248
254
}
249
255
@@ -253,6 +259,7 @@ public void testCancelByRetryingAlgorithm() throws Exception {
253
259
RetryingExecutorWithContext <String > executor =
254
260
getExecutor (getAlgorithm (getDefaultRetrySettings (), 5 , new CancellationException ()));
255
261
RetryingFuture <String > future = executor .createFuture (callable , retryingContext );
262
+ callable .setExternalFuture (future );
256
263
future .setAttemptFuture (executor .submit (future ));
257
264
258
265
assertFutureCancel (future );
@@ -272,6 +279,7 @@ public void testUnexpectedExceptionFromRetryAlgorithm() throws Exception {
272
279
RetryingExecutorWithContext <String > executor =
273
280
getExecutor (getAlgorithm (getDefaultRetrySettings (), 5 , new RuntimeException ()));
274
281
RetryingFuture <String > future = executor .createFuture (callable , retryingContext );
282
+ callable .setExternalFuture (future );
275
283
future .setAttemptFuture (executor .submit (future ));
276
284
277
285
assertFutureFail (future , RuntimeException .class );
@@ -311,6 +319,7 @@ public void testPollExceptionByPollAlgorithm() throws Exception {
311
319
context = FakeCallContext .createDefault ().withTracer (tracer );
312
320
}
313
321
RetryingFuture <String > future = executor .createFuture (callable , context );
322
+ callable .setExternalFuture (future );
314
323
future .setAttemptFuture (executor .submit (future ));
315
324
316
325
assertFutureFail (future , PollException .class );
0 commit comments