Skip to content

Commit 5b51bbd

Browse files
committed
more changes
Signed-off-by: wind57 <[email protected]>
1 parent 43d4d3f commit 5b51bbd

File tree

2 files changed

+15
-4
lines changed
  • spring-cloud-kubernetes-commons/src

2 files changed

+15
-4
lines changed

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/election/PodReadyRunner.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public CompletableFuture<Void> podReady(BooleanSupplier podReadySupplier) {
5252
ScheduledFuture<?> scheduledFuture = podReadySelfShutDownScheduler.scheduleWithFixedDelay(() -> {
5353

5454
if (podReadyCompletableFuture.isDone()) {
55-
LOG.info(() -> "pod readiness is known, not running another cycle");
55+
LOG.info(() -> "podReadyCompletableFuture is done");
5656
return;
5757
}
5858

@@ -82,7 +82,16 @@ public CompletableFuture<Void> podReady(BooleanSupplier podReadySupplier) {
8282
}
8383

8484
/**
85-
* call scheduledFuture::cancel, thus the podReadySelfShutDownScheduler will shutdown.
85+
* <pre>
86+
* This can be called from two sides:
87+
* - when readiness ScheduledFuture is still running and CompletableFuture::cancel is called.
88+
* 1. in this case, the inner "whenComplete" is called, scheduledFuture is canceled and done
89+
* 2. podReadyCompletableFuture.isDone() from the above is hit, scheduledFuture is canceled and done
90+
*
91+
* - when readiness ScheduledFuture is done already, CompletableFuture is completed also.
92+
* in this case, we will call scheduledFuture.cancel(true) also, because the scheduledFuture
93+
* still runs, although it will do nothing because we check against: podReadyCompletableFuture.isDone()
94+
* </pre>
8695
*/
8796
private void attachShutDownHook(CompletableFuture<Void> podReadyCompletableFuture,
8897
ScheduledFuture<?> scheduledFuture) {
@@ -105,7 +114,8 @@ private void attachShutDownHook(CompletableFuture<Void> podReadyCompletableFutur
105114

106115
// no matter the outcome, we cancel the future and thus shut down the
107116
// executor that runs it.
108-
scheduledFuture.cancel(true);
117+
boolean canceled = scheduledFuture.cancel(true);
118+
LOG.info(() -> "scheduledFuture is canceled: " + canceled);
109119
});
110120
}
111121

spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/leader/election/PodReadyRunnerTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,13 @@ void readinessCanceledOnTheSecondCycleAttachNewPipeline(CapturedOutput output) t
222222
assertThat(output.getOut()).doesNotContain("leader election for : identity was not successful");
223223
assertThat(output.getOut()).contains("readiness failed and we caught that");
224224

225-
await().atMost(Duration.ofSeconds(3))
225+
await().atMost(Duration.ofSeconds(3000))
226226
.pollInterval(Duration.ofMillis(200))
227227
.until(() -> output.getOut().contains("Shutting down executor : podReadyExecutor"));
228228

229229
assertThat(output.getOut()).contains("canceling scheduled future because completable future was cancelled");
230230
assertThat(output.getOut()).doesNotContain("canceling scheduled future because readiness failed");
231+
assertThat(output.getOut()).contains("scheduledFuture is canceled: true");
231232

232233

233234
}

0 commit comments

Comments
 (0)