@@ -46,8 +46,8 @@ public void testLeaderElectingController() throws ApiException, InterruptedExcep
46
46
AtomicReference <LeaderElectionRecord > record = new AtomicReference <>();
47
47
record .set (new LeaderElectionRecord ());
48
48
49
- Semaphore latch = new Semaphore (2 );
50
- Semaphore controllerLatch = new Semaphore (2 );
49
+ Semaphore apiClientSem = new Semaphore (0 );
50
+ Semaphore controllerSem = new Semaphore (0 );
51
51
52
52
when (mockLock .identity ()).thenReturn ("foo" );
53
53
when (mockLock .get ())
@@ -58,31 +58,31 @@ public void testLeaderElectingController() throws ApiException, InterruptedExcep
58
58
doAnswer (
59
59
invocationOnMock -> {
60
60
record .set (invocationOnMock .getArgument (0 ));
61
- latch .release ();
61
+ apiClientSem .release ();
62
62
return true ;
63
63
})
64
64
.when (mockLock )
65
65
.create (any ());
66
66
67
67
doAnswer (
68
68
invocationOnMock -> {
69
- latch .release ();
69
+ apiClientSem .release ();
70
70
return false ;
71
71
})
72
72
.when (mockLock )
73
73
.update (any ());
74
74
75
75
doAnswer (
76
76
invocationOnMock -> {
77
- controllerLatch .release ();
77
+ controllerSem .release ();
78
78
return null ;
79
79
})
80
80
.when (mockController )
81
81
.run ();
82
82
83
83
doAnswer (
84
84
invocationOnMock -> {
85
- controllerLatch .release ();
85
+ controllerSem .release ();
86
86
return null ;
87
87
})
88
88
.when (mockController )
@@ -98,18 +98,15 @@ public void testLeaderElectingController() throws ApiException, InterruptedExcep
98
98
Duration .ofMillis (100 ))),
99
99
mockController );
100
100
101
- latch .acquire (2 );
102
- controllerLatch .acquire (2 );
103
-
104
101
Thread controllerThread = new Thread (leaderElectingController ::run );
105
102
controllerThread .start ();
106
- latch .acquire (2 );
103
+ apiClientSem .acquire (2 );
107
104
controllerThread .interrupt ();
108
105
109
106
verify (mockLock , times (1 )).create (any ());
110
107
verify (mockLock , atLeastOnce ()).update (any ());
111
108
112
- controllerLatch .acquire (2 );
109
+ controllerSem .acquire (2 );
113
110
verify (mockController , times (1 )).run ();
114
111
verify (mockController , times (1 )).shutdown ();
115
112
}
0 commit comments