use of java.time.temporal.ChronoUnit in project janusgraph by JanusGraph.
the class CommonConfigTest method testDateParsing.
@Test
public void testDateParsing() {
final BaseConfiguration base = ConfigurationUtil.createBaseConfiguration();
CommonsConfiguration config = new CommonsConfiguration(base);
for (ChronoUnit unit : Arrays.asList(ChronoUnit.NANOS, ChronoUnit.MICROS, ChronoUnit.MILLIS, ChronoUnit.SECONDS, ChronoUnit.MINUTES, ChronoUnit.HOURS, ChronoUnit.DAYS)) {
base.setProperty("test", "100 " + unit.toString());
Duration d = config.get("test", Duration.class);
assertEquals(TimeUnit.NANOSECONDS.convert(100, Temporals.timeUnit(unit)), d.toNanos());
}
Map<ChronoUnit, String> mapping = ImmutableMap.of(ChronoUnit.MICROS, "us", ChronoUnit.DAYS, "d");
for (Map.Entry<ChronoUnit, String> entry : mapping.entrySet()) {
base.setProperty("test", "100 " + entry.getValue());
Duration d = config.get("test", Duration.class);
assertEquals(TimeUnit.NANOSECONDS.convert(100, Temporals.timeUnit(entry.getKey())), d.toNanos());
}
}
use of java.time.temporal.ChronoUnit in project simba-os by cegeka.
the class UserTokenFactoryTest method userCreationUserToken_GebruiktUserCreationExpirationTime_ConfigurationParameter.
@Test
public void userCreationUserToken_GebruiktUserCreationExpirationTime_ConfigurationParameter() {
when(coreConfigurationService.getValue(USER_CREATION_USERTOKEN_EXPIRATION_TIME)).thenReturn(3L);
ChronoUnit USER_CREATION_USERTOKEN_EXPIRATION_TIME_UNIT = ChronoUnit.valueOf(USER_CREATION_USERTOKEN_EXPIRATION_TIME.getChronoUnit().name());
Token token = generateToken();
LocalDateTime tokenGenerationTime = on(2017, 12, 8, 13, 18, 45);
systemDate.freeze(tokenGenerationTime);
UserCreationUserToken userCreationUserToken = userTokenFactory.userCreationUserToken(token, 1337);
assertThat(userCreationUserToken.getToken()).isEqualTo(token);
LocalDateTime expirationTime = tokenGenerationTime.plus(3, USER_CREATION_USERTOKEN_EXPIRATION_TIME_UNIT);
assertThat(userCreationUserToken.getExpiresOn()).isEqualTo(expirationTime);
}
use of java.time.temporal.ChronoUnit in project aeron by real-logic.
the class ClusterEventEncoderTest method testEncodeElectionStateChange.
@Test
void testEncodeElectionStateChange() {
final int offset = 8;
final ChronoUnit to = ChronoUnit.MILLENNIA;
final int memberId = 278;
final int leaderId = -100;
final long candidateTermId = 777L;
final long leadershipTermId = 42L;
final long logPosition = 128L;
final long logLeadershipTermId = 1L;
final long appendPosition = 998L;
final long catchupPosition = 200L;
final int captureLength = captureLength(electionStateChangeLength(null, to));
final int length = encodedLength(captureLength);
final int encodedLength = encodeElectionStateChange(buffer, offset, captureLength, length, null, to, memberId, leaderId, candidateTermId, leadershipTermId, logPosition, logLeadershipTermId, appendPosition, catchupPosition);
assertEquals(length, encodedLength);
int index = offset;
assertEquals(captureLength, buffer.getInt(index, LITTLE_ENDIAN));
index += SIZE_OF_INT;
assertEquals(length, buffer.getInt(index, LITTLE_ENDIAN));
index += SIZE_OF_INT;
assertNotEquals(0, buffer.getLong(index, LITTLE_ENDIAN));
index += SIZE_OF_LONG;
assertEquals(memberId, buffer.getInt(index, LITTLE_ENDIAN));
index += SIZE_OF_INT;
assertEquals(leaderId, buffer.getInt(index, LITTLE_ENDIAN));
index += SIZE_OF_INT;
assertEquals(candidateTermId, buffer.getLong(index, LITTLE_ENDIAN));
index += SIZE_OF_LONG;
assertEquals(leadershipTermId, buffer.getLong(index, LITTLE_ENDIAN));
index += SIZE_OF_LONG;
assertEquals(logPosition, buffer.getLong(index, LITTLE_ENDIAN));
index += SIZE_OF_LONG;
assertEquals(logLeadershipTermId, buffer.getLong(index, LITTLE_ENDIAN));
index += SIZE_OF_LONG;
assertEquals(appendPosition, buffer.getLong(index, LITTLE_ENDIAN));
index += SIZE_OF_LONG;
assertEquals(catchupPosition, buffer.getLong(index, LITTLE_ENDIAN));
index += SIZE_OF_LONG;
assertEquals("null" + STATE_SEPARATOR + to.name(), buffer.getStringAscii(index));
}
use of java.time.temporal.ChronoUnit in project aeron by real-logic.
the class ArchiveEventEncoderTest method testSessionStateChangeLength.
@Test
void testSessionStateChangeLength() {
final ChronoUnit from = ChronoUnit.ERAS;
final ChronoUnit to = ChronoUnit.MILLENNIA;
final String payload = from.name() + STATE_SEPARATOR + to.name();
assertEquals(payload.length() + SIZE_OF_LONG + SIZE_OF_INT, sessionStateChangeLength(from, to));
}
use of java.time.temporal.ChronoUnit in project aeron by real-logic.
the class ClusterEventLoggerTest method logElectionStateChange.
@Test
void logElectionStateChange() {
final int offset = ALIGNMENT * 4;
logBuffer.putLong(CAPACITY + TAIL_POSITION_OFFSET, offset);
final ChronoUnit from = ChronoUnit.ERAS;
final ChronoUnit to = null;
final int memberId = 18;
final int leaderId = -1;
final long candidateTermId = 29L;
final long leadershipTermId = 0L;
final long logPosition = 100L;
final long logLeadershipTermId = -9L;
final long appendPosition = 16 * 1024L;
final long catchupPosition = 8192L;
final int length = electionStateChangeLength(from, to);
logger.logElectionStateChange(from, to, memberId, leaderId, candidateTermId, leadershipTermId, logPosition, logLeadershipTermId, appendPosition, catchupPosition);
verifyLogHeader(logBuffer, offset, ELECTION_STATE_CHANGE.toEventCodeId(), length, length);
int index = encodedMsgOffset(offset) + LOG_HEADER_LENGTH;
assertEquals(memberId, logBuffer.getInt(index, LITTLE_ENDIAN));
index += SIZE_OF_INT;
assertEquals(leaderId, logBuffer.getInt(index, LITTLE_ENDIAN));
index += SIZE_OF_INT;
assertEquals(candidateTermId, logBuffer.getLong(index, LITTLE_ENDIAN));
index += SIZE_OF_LONG;
assertEquals(leadershipTermId, logBuffer.getLong(index, LITTLE_ENDIAN));
index += SIZE_OF_LONG;
assertEquals(logPosition, logBuffer.getLong(index, LITTLE_ENDIAN));
index += SIZE_OF_LONG;
assertEquals(logLeadershipTermId, logBuffer.getLong(index, LITTLE_ENDIAN));
index += SIZE_OF_LONG;
assertEquals(appendPosition, logBuffer.getLong(index, LITTLE_ENDIAN));
index += SIZE_OF_LONG;
assertEquals(catchupPosition, logBuffer.getLong(index, LITTLE_ENDIAN));
index += SIZE_OF_LONG;
assertEquals(from.name() + STATE_SEPARATOR + "null", logBuffer.getStringAscii(index));
}
Aggregations