Skip to content

Commit cd1be17

Browse files
committed
wip
Signed-off-by: wind57 <[email protected]>
1 parent 723a1f7 commit cd1be17

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

spring-cloud-kubernetes-fabric8-leader/src/main/java/org/springframework/cloud/kubernetes/fabric8/leader/election/Fabric8LeaderElectionInitiator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void postConstruct() {
135135
@PreDestroy
136136
void preDestroy() {
137137
destroyCalled = true;
138-
LOG.info(() -> "preDestroy called in the leader initiator : " + candidateIdentity);
138+
LOG.info(() -> "preDestroy called on the leader initiator : " + candidateIdentity);
139139

140140
if (podReadyFuture != null && !podReadyFuture.isDone()) {
141141
// if the task is not running, this has no effect.
@@ -145,7 +145,7 @@ void preDestroy() {
145145
}
146146

147147
if (leaderFuture != null) {
148-
LOG.info(() -> "leader will be canceled : " + candidateIdentity);
148+
LOG.info(() -> "leaderFuture will be canceled for : " + candidateIdentity);
149149
// needed to release the lock, in case we are holding it.
150150
// fabric8 internally expects this one to be called
151151
leaderFuture.cancel(true);

spring-cloud-kubernetes-fabric8-leader/src/test/java/org/springframework/cloud/kubernetes/fabric8/leader/election/it/Fabric8LeaderElectionSimpleITTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.mockito.MockedStatic;
3030
import org.mockito.Mockito;
3131
import org.springframework.cloud.kubernetes.commons.leader.LeaderUtils;
32+
import org.springframework.cloud.kubernetes.commons.leader.election.LeaderElectionProperties;
3233
import org.testcontainers.k3s.K3sContainer;
3334

3435
import org.springframework.beans.factory.annotation.Autowired;
@@ -80,7 +81,7 @@ void test(CapturedOutput output) {
8081

8182
// we have become the leader
8283
Awaitility.await()
83-
.atMost(Duration.ofSeconds(10))
84+
.atMost(Duration.ofSeconds(60))
8485
.pollInterval(Duration.ofSeconds(1))
8586
.until(() -> output.getOut().contains("simple-it is the new leader"));
8687

@@ -101,12 +102,16 @@ void test(CapturedOutput output) {
101102
// 4. we are the leader (comes from our code)
102103
assertThat(output.getOut()).contains("Leader changed from null to simple-it");
103104

105+
// 5. wait until a renewal happens (comes from fabric code)
106+
// this one means that we have extended our leadership
107+
Awaitility.await()
108+
.atMost(Duration.ofSeconds(15))
109+
.pollInterval(Duration.ofSeconds(1))
110+
.until(() -> output.getOut().contains(
111+
"Attempting to renew leader lease 'LeaseLock: default - spring-k8s-leader-election-lock (simple-it)'"));
112+
104113

105114

106-
// // all these logs happen before a renewal
107-
// Assertions.assertThat(output.getOut()).contains("starting leader initiator");
108-
// Assertions.assertThat(output.getOut()).contains("Leader election started");
109-
// Assertions.assertThat(output.getOut()).contains("Successfully Acquired leader lease");
110115
//
111116
// Lease lockLease = kubernetesClient.leases()
112117
// .inNamespace("default")

0 commit comments

Comments
 (0)