Skip to content

Commit 9276dc2

Browse files
committed
do spotless:apply to fix formatting errors
1 parent 8079d67 commit 9276dc2

File tree

4 files changed

+45
-58
lines changed

4 files changed

+45
-58
lines changed

extended/src/main/java/io/kubernetes/client/extended/leaderelection/LeaderElector.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,16 @@ private boolean tryAcquireOrRenew() {
281281
|| oldLeaderElectionRecord.getAcquireTime() == null
282282
|| oldLeaderElectionRecord.getRenewTime() == null
283283
|| oldLeaderElectionRecord.getHolderIdentity() == null) {
284-
// We found the lock resource with an empty LeaderElectionRecord, try to get leadership by updating it
284+
// We found the lock resource with an empty LeaderElectionRecord, try to get leadership by
285+
// updating it
285286
if (log.isDebugEnabled()) {
286287
log.debug("Update lock to get lease");
287288
}
288289

289290
if (oldLeaderElectionRecord != null) {
290291
// maintain the leaderTransitions
291-
leaderElectionRecord.setLeaderTransitions(oldLeaderElectionRecord.getLeaderTransitions() + 1);
292+
leaderElectionRecord.setLeaderTransitions(
293+
oldLeaderElectionRecord.getLeaderTransitions() + 1);
292294
}
293295

294296
return updateLock(lock, leaderElectionRecord);
@@ -382,19 +384,23 @@ public void close() {
382384

383385
// First ensure that all executors have stopped
384386
try {
385-
boolean isTerminated = scheduledWorkers.awaitTermination(config.getRetryPeriod().getSeconds(), TimeUnit.SECONDS);
387+
boolean isTerminated =
388+
scheduledWorkers.awaitTermination(
389+
config.getRetryPeriod().getSeconds(), TimeUnit.SECONDS);
386390
if (!isTerminated) {
387391
log.warn("scheduledWorkers executor termination didn't finish.");
388392
return;
389393
}
390394

391-
isTerminated = leaseWorkers.awaitTermination(config.getRetryPeriod().getSeconds(), TimeUnit.SECONDS);
395+
isTerminated =
396+
leaseWorkers.awaitTermination(config.getRetryPeriod().getSeconds(), TimeUnit.SECONDS);
392397
if (!isTerminated) {
393398
log.warn("leaseWorkers executor termination didn't finish.");
394399
return;
395400
}
396401

397-
isTerminated = hookWorkers.awaitTermination(config.getRetryPeriod().getSeconds(), TimeUnit.SECONDS);
402+
isTerminated =
403+
hookWorkers.awaitTermination(config.getRetryPeriod().getSeconds(), TimeUnit.SECONDS);
398404
if (!isTerminated) {
399405
log.warn("hookWorkers executor termination didn't finish.");
400406
return;

extended/src/test/java/io/kubernetes/client/extended/leaderelection/LeaderElectionTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import static org.mockito.Mockito.*;
1818

1919
import io.kubernetes.client.openapi.ApiException;
20-
2120
import java.net.HttpURLConnection;
2221
import java.time.Duration;
2322
import java.util.ArrayList;
@@ -418,7 +417,7 @@ public LeaderElectionRecord get() throws ApiException {
418417
lock.lock();
419418
try {
420419
if (leaderRecord == null) {
421-
throw new ApiException("Record Not Found", HttpURLConnection.HTTP_NOT_FOUND, null, null);
420+
throw new ApiException("Record Not Found", HttpURLConnection.HTTP_NOT_FOUND, null, null);
422421
}
423422
return leaderRecord;
424423
} finally {

extended/src/test/java/io/kubernetes/client/extended/leaderelection/LeaderElectorTest.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,37 @@
1010
See the License for the specific language governing permissions and
1111
limitations under the License.
1212
*/
13-
1413
package io.kubernetes.client.extended.leaderelection;
1514

16-
import org.junit.Test;
17-
1815
import java.time.Duration;
1916
import java.util.concurrent.CountDownLatch;
2017
import java.util.concurrent.TimeUnit;
18+
import org.junit.Test;
2119

22-
/**
23-
* Leader Election tests using "simulated" locks created by {@link LockSmith}
24-
*/
25-
public class LeaderElectorTest
26-
{
20+
/** Leader Election tests using "simulated" locks created by {@link LockSmith} */
21+
public class LeaderElectorTest {
2722
/**
2823
* Tests that when a leader candidate is stopped gracefully, second candidate immediately becomes
2924
* leader.
3025
*/
3126
@Test(timeout = 20000L)
32-
public void testLeaderGracefulShutdown() throws Exception
33-
{
27+
public void testLeaderGracefulShutdown() throws Exception {
3428
LockSmith lockSmith = new LockSmith();
3529

3630
CountDownLatch startBeingLeader1 = new CountDownLatch(1);
3731
CountDownLatch stopBeingLeader1 = new CountDownLatch(1);
3832

39-
LeaderElector leaderElector1 = makeAndRunLeaderElectorAsync(lockSmith, "candidate1", startBeingLeader1, stopBeingLeader1);
33+
LeaderElector leaderElector1 =
34+
makeAndRunLeaderElectorAsync(lockSmith, "candidate1", startBeingLeader1, stopBeingLeader1);
4035

4136
// wait for candidate1 to become leader
4237
startBeingLeader1.await();
4338

4439
CountDownLatch startBeingLeader2 = new CountDownLatch(1);
4540
CountDownLatch stopBeingLeader2 = new CountDownLatch(1);
4641

47-
LeaderElector leaderElector2 = makeAndRunLeaderElectorAsync(lockSmith, "candidate2", startBeingLeader2, stopBeingLeader2);
42+
LeaderElector leaderElector2 =
43+
makeAndRunLeaderElectorAsync(lockSmith, "candidate2", startBeingLeader2, stopBeingLeader2);
4844

4945
leaderElector1.close();
5046

@@ -57,23 +53,25 @@ public void testLeaderGracefulShutdown() throws Exception
5753
leaderElector2.close();
5854
}
5955

60-
private LeaderElector makeAndRunLeaderElectorAsync(LockSmith lockSmith, String lockIdentity, CountDownLatch startBeingLeader, CountDownLatch stopBeingLeader)
61-
{
56+
private LeaderElector makeAndRunLeaderElectorAsync(
57+
LockSmith lockSmith,
58+
String lockIdentity,
59+
CountDownLatch startBeingLeader,
60+
CountDownLatch stopBeingLeader) {
6261
LeaderElectionConfig leaderElectionConfig =
6362
new LeaderElectionConfig(
6463
lockSmith.makeLock(lockIdentity),
6564
Duration.ofMillis(TimeUnit.MINUTES.toMillis(1)),
6665
Duration.ofMillis(TimeUnit.SECONDS.toMillis(51)),
67-
Duration.ofMillis(TimeUnit.SECONDS.toMillis(3))
68-
);
66+
Duration.ofMillis(TimeUnit.SECONDS.toMillis(3)));
6967
LeaderElector leaderElector = new LeaderElector(leaderElectionConfig);
7068

71-
Thread thread = new Thread(
72-
() -> leaderElector.run(
73-
() -> startBeingLeader.countDown(), () -> stopBeingLeader.countDown()
74-
),
75-
String.format("%s-leader-elector-main", lockIdentity)
76-
);
69+
Thread thread =
70+
new Thread(
71+
() ->
72+
leaderElector.run(
73+
() -> startBeingLeader.countDown(), () -> stopBeingLeader.countDown()),
74+
String.format("%s-leader-elector-main", lockIdentity));
7775
thread.setDaemon(true);
7876
thread.start();
7977

extended/src/test/java/io/kubernetes/client/extended/leaderelection/LockSmith.java

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,29 @@
1010
See the License for the specific language governing permissions and
1111
limitations under the License.
1212
*/
13-
1413
package io.kubernetes.client.extended.leaderelection;
1514

1615
import io.kubernetes.client.openapi.ApiException;
17-
1816
import java.net.HttpURLConnection;
1917
import java.util.concurrent.atomic.AtomicReference;
2018

21-
/**
22-
* Makes simulated {@link Lock} objects that behave as if they were backed by real API server.
23-
*/
24-
public class LockSmith
25-
{
19+
/** Makes simulated {@link Lock} objects that behave as if they were backed by real API server. */
20+
public class LockSmith {
2621
private AtomicReference<Resource> lockResourceRef = new AtomicReference<>();
2722

28-
public Lock makeLock(String identity)
29-
{
23+
public Lock makeLock(String identity) {
3024
return new SimulatedLock(identity);
3125
}
3226

33-
private class SimulatedLock implements Lock
34-
{
27+
private class SimulatedLock implements Lock {
3528
private final String identity;
3629

37-
public SimulatedLock(String identity)
38-
{
30+
public SimulatedLock(String identity) {
3931
this.identity = identity;
4032
}
4133

4234
@Override
43-
public LeaderElectionRecord get() throws ApiException
44-
{
35+
public LeaderElectionRecord get() throws ApiException {
4536
if (lockResourceRef.get() == null) {
4637
throw new ApiException("Record Not Found", HttpURLConnection.HTTP_NOT_FOUND, null, null);
4738
}
@@ -50,14 +41,12 @@ public LeaderElectionRecord get() throws ApiException
5041
}
5142

5243
@Override
53-
public boolean create(LeaderElectionRecord record)
54-
{
44+
public boolean create(LeaderElectionRecord record) {
5545
return lockResourceRef.compareAndSet(null, new Resource(record));
5646
}
5747

5848
@Override
59-
public boolean update(LeaderElectionRecord record)
60-
{
49+
public boolean update(LeaderElectionRecord record) {
6150
Resource res = lockResourceRef.get();
6251
if (res == null) {
6352
return false;
@@ -68,31 +57,26 @@ public boolean update(LeaderElectionRecord record)
6857
}
6958

7059
@Override
71-
public String identity()
72-
{
60+
public String identity() {
7361
return identity;
7462
}
7563

7664
@Override
77-
public String describe()
78-
{
65+
public String describe() {
7966
return "simulated/lock";
8067
}
8168
}
8269

83-
private static class Resource
84-
{
70+
private static class Resource {
8571
final int version;
8672
final LeaderElectionRecord record;
8773

88-
public Resource(LeaderElectionRecord record)
89-
{
74+
public Resource(LeaderElectionRecord record) {
9075
this.version = 0;
9176
this.record = record;
9277
}
9378

94-
public Resource(int version, LeaderElectionRecord record)
95-
{
79+
public Resource(int version, LeaderElectionRecord record) {
9680
this.version = version;
9781
this.record = record;
9882
}

0 commit comments

Comments
 (0)