Skip to content

Commit c856aa4

Browse files
committed
added tests
Signed-off-by: wind57 <[email protected]>
1 parent 945b17d commit c856aa4

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-leader-election/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.cloud</groupId>
88
<artifactId>spring-cloud-kubernetes-integration-tests</artifactId>
9-
<version>5.0.0-SNAPSHOT</version>
9+
<version>5.0.1-SNAPSHOT</version>
1010
</parent>
1111

1212
<properties>

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-leader-election/src/test/java/org/springframework/cloud/kubernetes/fabric8/leader/election/AbstractLeaderElection.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ void afterEach() {
7575
.withTimeout(10, TimeUnit.SECONDS)
7676
.delete();
7777
}
78+
7879
Lease getLease() {
7980
return kubernetesClient.leases().inNamespace("default").withName("spring-k8s-leader-election-lock").get();
8081
}

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-leader-election/src/test/java/org/springframework/cloud/kubernetes/fabric8/leader/election/Assertions.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,23 @@ static void assertAcquireAndRenew(CapturedOutput output, Supplier<Lease> leaseSu
4848
assertThat(output.getOut()).contains("starting leader initiator : " + candidateIdentity);
4949

5050
// 3. we try to acquire the lease (comes from fabric8 code)
51-
assertThat(output.getOut()).contains(
52-
"Attempting to acquire leader lease 'LeaseLock: default - spring-k8s-leader-election-lock " +
53-
"(" + candidateIdentity + ")'");
51+
assertThat(output.getOut())
52+
.contains("Attempting to acquire leader lease 'LeaseLock: default - spring-k8s-leader-election-lock " + "("
53+
+ candidateIdentity + ")'");
5454

5555
// 4. lease has been acquired
56-
assertThat(output.getOut())
57-
.contains("Acquired lease 'LeaseLock: default - spring-k8s-leader-election-lock " +
58-
"(" + candidateIdentity + ")'");
56+
assertThat(output.getOut()).contains("Acquired lease 'LeaseLock: default - spring-k8s-leader-election-lock "
57+
+ "(" + candidateIdentity + ")'");
5958

6059
// 5. we are the leader (comes from fabric8 code)
6160
assertThat(output.getOut()).contains("Leader changed from null to " + candidateIdentity);
6261

6362
// 6. wait until a renewal happens (comes from fabric code)
6463
// this one means that we have extended our leadership
6564
awaitUntil(30, 500,
66-
() -> output.getOut()
67-
.contains("Attempting to renew leader lease 'LeaseLock: "
68-
+ "default - spring-k8s-leader-election-lock (" + candidateIdentity + ")'"));
65+
() -> output.getOut()
66+
.contains("Attempting to renew leader lease 'LeaseLock: "
67+
+ "default - spring-k8s-leader-election-lock (" + candidateIdentity + ")'"));
6968

7069
Lease lease = leaseSupplier.get();
7170

@@ -84,5 +83,4 @@ static void assertAcquireAndRenew(CapturedOutput output, Supplier<Lease> leaseSu
8483
});
8584
}
8685

87-
8886
}

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-leader-election/src/test/java/org/springframework/cloud/kubernetes/fabric8/leader/election/Fabric8LeaderElectionCompletedExceptionallyAndRestartedIT.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
import org.springframework.boot.test.system.CapturedOutput;
2424
import org.springframework.test.context.TestPropertySource;
2525

26+
import static org.assertj.core.api.Assertions.assertThat;
2627
import static org.springframework.cloud.kubernetes.fabric8.leader.election.Assertions.assertAcquireAndRenew;
2728
import static org.springframework.cloud.kubernetes.integration.tests.commons.Awaitilities.awaitUntil;
28-
import static org.assertj.core.api.Assertions.assertThat;
2929

3030
/**
3131
* <pre>
@@ -35,7 +35,7 @@
3535
* @author wind57
3636
*/
3737
@TestPropertySource(properties = { "spring.cloud.kubernetes.leader.election.wait-for-pod-ready=true",
38-
"spring.cloud.kubernetes.leader.election.restart-on-failure=true", "readiness.passes=true" })
38+
"spring.cloud.kubernetes.leader.election.restart-on-failure=true", "readiness.passes=true" })
3939
class Fabric8LeaderElectionCompletedExceptionallyAndRestartedIT extends AbstractLeaderElection {
4040

4141
private static final String NAME = "acquired-then-fails";
@@ -68,8 +68,7 @@ void test(CapturedOutput output) {
6868
}
6969

7070
private void afterLeaderFailure(int afterLeaderFailure, CapturedOutput output) {
71-
awaitUntil(60, 100, () -> output.getOut().substring(afterLeaderFailure).
72-
contains(NAME + " is the new leader"));
71+
awaitUntil(60, 100, () -> output.getOut().substring(afterLeaderFailure).contains(NAME + " is the new leader"));
7372

7473
// lease has been re-acquired
7574
assertThat(output.getOut().substring(afterLeaderFailure))
@@ -78,9 +77,10 @@ private void afterLeaderFailure(int afterLeaderFailure, CapturedOutput output) {
7877
// renewal happens (comes from fabric code)
7978
// this one means that we have extended our leadership
8079
awaitUntil(30, 500,
81-
() -> output.getOut().substring(afterLeaderFailure)
82-
.contains("Attempting to renew leader lease 'LeaseLock: "
83-
+ "default - spring-k8s-leader-election-lock (" + NAME + ")'"));
80+
() -> output.getOut()
81+
.substring(afterLeaderFailure)
82+
.contains("Attempting to renew leader lease 'LeaseLock: "
83+
+ "default - spring-k8s-leader-election-lock (" + NAME + ")'"));
8484
}
8585

8686
}

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-leader-election/src/test/java/org/springframework/cloud/kubernetes/fabric8/leader/election/Fabric8LeaderElectionIsLostAndRestartedIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
import static org.springframework.cloud.kubernetes.integration.tests.commons.Awaitilities.awaitUntil;
2828

2929
/**
30-
* We acquire leadership, then lose it, then acquire it back.
31-
* This tests the "leaderFuture finished normally, will re-start it for" branch
30+
* We acquire leadership, then lose it, then acquire it back. This tests the "leaderFuture
31+
* finished normally, will re-start it for" branch
3232
*
3333
* @author wind57
3434
*/
35-
@TestPropertySource(properties = { "spring.cloud.kubernetes.leader.election.wait-for-pod-ready=true",
36-
"readiness.passes=true" })
35+
@TestPropertySource(
36+
properties = { "spring.cloud.kubernetes.leader.election.wait-for-pod-ready=true", "readiness.passes=true" })
3737
public class Fabric8LeaderElectionIsLostAndRestartedIT extends AbstractLeaderElection {
3838

3939
private static final String NAME = "drops-than-recovers";

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-leader-election/src/test/java/org/springframework/cloud/kubernetes/fabric8/leader/election/Fabric8LeaderElectionReadinessCanceledIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ static void beforeAll() {
4747
void test(CapturedOutput output) {
4848

4949
// we are trying readiness at least once
50-
awaitUntil(60, 500, () -> output.getOut().contains("Pod : canceled-readiness-it in namespace : "
51-
+ "default is not ready, will retry in one second"));
50+
awaitUntil(60, 500, () -> output.getOut()
51+
.contains(
52+
"Pod : canceled-readiness-it in namespace : " + "default is not ready, will retry in one second"));
5253

5354
initiator.preDestroy();
5455

0 commit comments

Comments
 (0)