|
26 | 26 | import java.io.IOException;
|
27 | 27 | import java.net.HttpURLConnection;
|
28 | 28 | import java.time.Duration;
|
| 29 | +import java.time.format.DateTimeFormatter; |
| 30 | +import java.time.format.DateTimeFormatterBuilder; |
29 | 31 | import java.util.ArrayList;
|
30 | 32 | import java.util.Collection;
|
31 | 33 | import java.util.List;
|
@@ -76,14 +78,28 @@ public LeaderElectorTest(LockType lockType) {
|
76 | 78 | } catch (IOException ex) {
|
77 | 79 | throw new RuntimeException("Couldn't create ApiClient", ex);
|
78 | 80 | }
|
| 81 | + // Lease resource requires special care with DateTime |
| 82 | + if (lockType == LockType.Lease) { |
| 83 | + // TODO: switch date-time library so that micro-sec timestamp can be serialized |
| 84 | + // in RFC3339 |
| 85 | + // format w/ correct precision without the hacks |
| 86 | + |
| 87 | + // This formatter is used for Lease resource spec's acquire/renewTime |
| 88 | + DateTimeFormatter formatter = |
| 89 | + new DateTimeFormatterBuilder() |
| 90 | + .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'")) |
| 91 | + .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")) |
| 92 | + .toFormatter(); |
| 93 | + |
| 94 | + apiClient.setOffsetDateTimeFormat(formatter); |
| 95 | + } |
79 | 96 | this.lockType = lockType;
|
80 | 97 | }
|
81 | 98 |
|
82 | 99 | @Before
|
83 | 100 | public void setup() throws Exception {
|
84 | 101 | // delete the lock resource if it exists, or else first leader candidate might need to wait for
|
85 |
| - // a whole |
86 |
| - // leaseDuration configured |
| 102 | + // a whole leaseDuration configured |
87 | 103 | switch (lockType) {
|
88 | 104 | case ConfigMap:
|
89 | 105 | deleteConfigMapLockResource();
|
@@ -169,8 +185,8 @@ public void testMultiCandidateLeaderElection() throws Exception {
|
169 | 185 | Assert.assertNotNull(leaderRef.get());
|
170 | 186 | Assert.assertTrue(candidate1.equals(leaderRef.get()) || candidate2.equals(leaderRef.get()));
|
171 | 187 |
|
172 |
| - // stop both LeaderElectors, in order .. non-leader, then leader so that non-leader doesn't get |
173 |
| - // to become leader |
| 188 | + // stop both LeaderElectors, in order .. non-leader, then leader so that |
| 189 | + // non-leader doesn't get to become leader |
174 | 190 | if (candidate1.equals(leaderRef.get())) {
|
175 | 191 | leaderElector2.close();
|
176 | 192 | leaderElector1.close();
|
|
0 commit comments