Skip to content

Commit 0dcea5c

Browse files
author
Dave Syer
committed
Put back date format hack
Signed-off-by: Dave Syer <[email protected]>
1 parent 9da67f7 commit 0dcea5c

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.io.IOException;
2727
import java.net.HttpURLConnection;
2828
import java.time.Duration;
29+
import java.time.format.DateTimeFormatter;
30+
import java.time.format.DateTimeFormatterBuilder;
2931
import java.util.ArrayList;
3032
import java.util.Collection;
3133
import java.util.List;
@@ -76,14 +78,28 @@ public LeaderElectorTest(LockType lockType) {
7678
} catch (IOException ex) {
7779
throw new RuntimeException("Couldn't create ApiClient", ex);
7880
}
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+
}
7996
this.lockType = lockType;
8097
}
8198

8299
@Before
83100
public void setup() throws Exception {
84101
// 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
87103
switch (lockType) {
88104
case ConfigMap:
89105
deleteConfigMapLockResource();
@@ -169,8 +185,8 @@ public void testMultiCandidateLeaderElection() throws Exception {
169185
Assert.assertNotNull(leaderRef.get());
170186
Assert.assertTrue(candidate1.equals(leaderRef.get()) || candidate2.equals(leaderRef.get()));
171187

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
174190
if (candidate1.equals(leaderRef.get())) {
175191
leaderElector2.close();
176192
leaderElector1.close();

0 commit comments

Comments
 (0)