mirror of https://github.com/apache/kafka.git
MINOR: Fix for MetadataQuorumCommandErrorTest.testRelativeTimeMs (#13784)
Reviewers: Divij Vaidya <diviv@amazon.com>, David Jacot <djacot@confluent.io>
This commit is contained in:
parent
03ab563206
commit
7e9a82c732
|
@ -195,7 +195,7 @@ public class MetadataQuorumCommand {
|
||||||
static long relativeTimeMs(long timestampMs, String desc) {
|
static long relativeTimeMs(long timestampMs, String desc) {
|
||||||
Instant lastTimestamp = Instant.ofEpochMilli(timestampMs);
|
Instant lastTimestamp = Instant.ofEpochMilli(timestampMs);
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
if (!(lastTimestamp.isAfter(Instant.EPOCH) && lastTimestamp.isBefore(now))) {
|
if (!(lastTimestamp.isAfter(Instant.EPOCH) && (lastTimestamp.isBefore(now) || lastTimestamp.equals(now)))) {
|
||||||
throw new KafkaException(
|
throw new KafkaException(
|
||||||
format("Error while computing relative time, possible drift in system clock.%n" +
|
format("Error while computing relative time, possible drift in system clock.%n" +
|
||||||
"Current timestamp is %d, %s timestamp is %d", now.toEpochMilli(), desc, timestampMs)
|
"Current timestamp is %d, %s timestamp is %d", now.toEpochMilli(), desc, timestampMs)
|
||||||
|
|
|
@ -53,12 +53,14 @@ public class MetadataQuorumCommandErrorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelativeTimeMs() {
|
public void testRelativeTimeMs() {
|
||||||
|
long validEpochMs = Instant.now().minusSeconds(5).toEpochMilli();
|
||||||
|
assertTrue(MetadataQuorumCommand.relativeTimeMs(validEpochMs, "test") >= 0);
|
||||||
long nowMs = Instant.now().toEpochMilli();
|
long nowMs = Instant.now().toEpochMilli();
|
||||||
assertTrue(MetadataQuorumCommand.relativeTimeMs(nowMs, "test") >= 0);
|
assertTrue(MetadataQuorumCommand.relativeTimeMs(nowMs, "test") >= 0);
|
||||||
long invalidEpochMs = Instant.EPOCH.minus(1, ChronoUnit.DAYS).toEpochMilli();
|
long invalidEpochMs = Instant.EPOCH.minus(1, ChronoUnit.DAYS).toEpochMilli();
|
||||||
assertThrows(KafkaException.class, () -> MetadataQuorumCommand.relativeTimeMs(invalidEpochMs, "test"));
|
assertThrows(KafkaException.class, () -> MetadataQuorumCommand.relativeTimeMs(invalidEpochMs, "test"));
|
||||||
long futureTimestampMs = Instant.now().plus(1, ChronoUnit.DAYS).toEpochMilli();
|
long futureEpochMs = Instant.now().plus(1, ChronoUnit.DAYS).toEpochMilli();
|
||||||
assertThrows(KafkaException.class, () -> MetadataQuorumCommand.relativeTimeMs(futureTimestampMs, "test"));
|
assertThrows(KafkaException.class, () -> MetadataQuorumCommand.relativeTimeMs(futureEpochMs, "test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue