Search in sources :

Example 16 with ChronoUnit

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());
    }
}
Also used : BaseConfiguration(org.apache.commons.configuration2.BaseConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) Duration(java.time.Duration) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ChronoUnit(java.time.temporal.ChronoUnit) Test(org.junit.jupiter.api.Test)

Example 17 with ChronoUnit

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) Token.generateToken(org.simbasecurity.core.domain.communication.token.Token.generateToken) ChronoUnit(java.time.temporal.ChronoUnit) Test(org.junit.Test)

Example 18 with ChronoUnit

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));
}
Also used : ChronoUnit(java.time.temporal.ChronoUnit) Test(org.junit.jupiter.api.Test)

Example 19 with ChronoUnit

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));
}
Also used : ChronoUnit(java.time.temporal.ChronoUnit) Test(org.junit.jupiter.api.Test)

Example 20 with ChronoUnit

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));
}
Also used : ChronoUnit(java.time.temporal.ChronoUnit) Test(org.junit.jupiter.api.Test)

Aggregations

ChronoUnit (java.time.temporal.ChronoUnit)42 Test (org.junit.jupiter.api.Test)11 Test (org.junit.Test)6 LocalDateTime (java.time.LocalDateTime)5 Matcher (java.util.regex.Matcher)5 Duration (java.time.Duration)4 Map (java.util.Map)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ChronoLocalDateTime (java.time.chrono.ChronoLocalDateTime)3 ArrayList (java.util.ArrayList)3 Pattern (java.util.regex.Pattern)3 Given (cucumber.api.java.en.Given)2 CommandSubscriber (de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)2 CommandSubscriber (de.nikos410.discordbot.framework.annotations.CommandSubscriber)2 CommandUtils (de.nikos410.discordbot.util.CommandUtils)2 FaultToleranceService (fish.payara.microprofile.faulttolerance.FaultToleranceService)2 Instant (java.time.Instant)2 ZonedDateTime (java.time.ZonedDateTime)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 ScheduledFuture (java.util.concurrent.ScheduledFuture)2