Skip to content

Commit

Permalink
Put back date format hack
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Syer <dsyer@vmware.com>
  • Loading branch information
dsyer committed Jan 5, 2021
1 parent 9da67f7 commit 0dcea5c
Showing 1 changed file with 20 additions and 4 deletions.
Expand Up @@ -26,6 +26,8 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.time.Duration;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -76,14 +78,28 @@ public LeaderElectorTest(LockType lockType) {
} catch (IOException ex) {
throw new RuntimeException("Couldn't create ApiClient", ex);
}
// Lease resource requires special care with DateTime
if (lockType == LockType.Lease) {
// TODO: switch date-time library so that micro-sec timestamp can be serialized
// in RFC3339
// format w/ correct precision without the hacks

// This formatter is used for Lease resource spec's acquire/renewTime
DateTimeFormatter formatter =
new DateTimeFormatterBuilder()
.appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'"))
.appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"))
.toFormatter();

apiClient.setOffsetDateTimeFormat(formatter);
}
this.lockType = lockType;
}

@Before
public void setup() throws Exception {
// delete the lock resource if it exists, or else first leader candidate might need to wait for
// a whole
// leaseDuration configured
// a whole leaseDuration configured
switch (lockType) {
case ConfigMap:
deleteConfigMapLockResource();
Expand Down Expand Up @@ -169,8 +185,8 @@ public void testMultiCandidateLeaderElection() throws Exception {
Assert.assertNotNull(leaderRef.get());
Assert.assertTrue(candidate1.equals(leaderRef.get()) || candidate2.equals(leaderRef.get()));

// stop both LeaderElectors, in order .. non-leader, then leader so that non-leader doesn't get
// to become leader
// stop both LeaderElectors, in order .. non-leader, then leader so that
// non-leader doesn't get to become leader
if (candidate1.equals(leaderRef.get())) {
leaderElector2.close();
leaderElector1.close();
Expand Down

0 comments on commit 0dcea5c

Please sign in to comment.