Java Code Examples for java.time.Instant#EPOCH

The following examples show how to use java.time.Instant#EPOCH . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: robozonky   File: SellInfoCacheTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void load() {
    final Instant now = Instant.now();
    final SellInfo sellInfo = mockSellInfo(BigDecimal.TEN, BigDecimal.ONE);
    final Instant instant = Instant.EPOCH;
    setClock(Clock.fixed(instant, Defaults.ZONE_ID));
    final long id = 2;
    final Zonky z = harmlessZonky();
    when(z.getSellInfo(eq(id))).thenReturn(sellInfo);
    final Tenant t = mockTenant(z);
    final Cache<SellInfo> c = Cache.forSellInfo(t);
    assertThat(c.get(id)).isEqualTo(sellInfo); // return the freshly retrieved loan
    verify(z).getSellInfo(eq(id));
    assertThat(c.getFromCache(id)).contains(sellInfo);
    verify(z, times(1)).getSellInfo(eq(id));
    // and now test eviction
    setClock(Clock.fixed(now.plus(Duration.ofHours(2)), Defaults.ZONE_ID));
    assertThat(c.getFromCache(id)).isEmpty();
}
 
Example 2
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, -200), Instant.now(), Instant.ofEpochSecond(10, -200), null},
            {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(-10), null},
            {Instant.ofEpochSecond(10), Instant.MIN, Instant.ofEpochSecond(10), null},
            {Instant.ofEpochSecond(10), Instant.MAX, Instant.ofEpochSecond(10), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZoneOffset.UTC), OffsetDateTime.of(1970, 1, 1, 0, 0, 10, 200, ZoneOffset.UTC), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, OFFSET_PTWO), OffsetDateTime.of(1970, 1, 1, 2, 0, 10, 200, OFFSET_PTWO), null},
            {Instant.ofEpochSecond(10, 200), ZonedDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZONE_PARIS), ZonedDateTime.of(1970, 1, 1, 1, 0, 10, 200, ZONE_PARIS), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class},
            {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class},

    };
}
 
Example 3
@DataProvider(name="with")
Object[][] data_with() {
    return new Object[][]{
            {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(20), null},
            {Instant.ofEpochSecond(10), Instant.ofEpochSecond(20, -100), Instant.ofEpochSecond(20, -100), null},
            {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(0), null},
            {Instant.ofEpochSecond(10), Instant.MIN, Instant.MIN, null},
            {Instant.ofEpochSecond(10), Instant.MAX, Instant.MAX, null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(20), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class},
            {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class},

    };
}
 
Example 4
Source Project: jdk8u60   File: TCKInstant.java    License: GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, -200), Instant.now(), Instant.ofEpochSecond(10, -200), null},
            {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(-10), null},
            {Instant.ofEpochSecond(10), Instant.MIN, Instant.ofEpochSecond(10), null},
            {Instant.ofEpochSecond(10), Instant.MAX, Instant.ofEpochSecond(10), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZoneOffset.UTC), OffsetDateTime.of(1970, 1, 1, 0, 0, 10, 200, ZoneOffset.UTC), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, OFFSET_PTWO), OffsetDateTime.of(1970, 1, 1, 2, 0, 10, 200, OFFSET_PTWO), null},
            {Instant.ofEpochSecond(10, 200), ZonedDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZONE_PARIS), ZonedDateTime.of(1970, 1, 1, 1, 0, 10, 200, ZONE_PARIS), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class},
            {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class},

    };
}
 
Example 5
@DataProvider(name="with")
Object[][] data_with() {
    return new Object[][]{
            {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(20), null},
            {Instant.ofEpochSecond(10), Instant.ofEpochSecond(20, -100), Instant.ofEpochSecond(20, -100), null},
            {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(0), null},
            {Instant.ofEpochSecond(10), Instant.MIN, Instant.MIN, null},
            {Instant.ofEpochSecond(10), Instant.MAX, Instant.MAX, null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(20), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class},
            {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class},

    };
}
 
Example 6
@DataProvider(name="with")
Object[][] data_with() {
    return new Object[][]{
            {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(20), null},
            {Instant.ofEpochSecond(10), Instant.ofEpochSecond(20, -100), Instant.ofEpochSecond(20, -100), null},
            {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(0), null},
            {Instant.ofEpochSecond(10), Instant.MIN, Instant.MIN, null},
            {Instant.ofEpochSecond(10), Instant.MAX, Instant.MAX, null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(20), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class},
            {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class},

    };
}
 
Example 7
@DataProvider(name="with")
Object[][] data_with() {
    return new Object[][]{
            {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(20), null},
            {Instant.ofEpochSecond(10), Instant.ofEpochSecond(20, -100), Instant.ofEpochSecond(20, -100), null},
            {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(0), null},
            {Instant.ofEpochSecond(10), Instant.MIN, Instant.MIN, null},
            {Instant.ofEpochSecond(10), Instant.MAX, Instant.MAX, null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(20), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class},
            {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class},

    };
}
 
Example 8
@Test
@DatabaseSetup("persistence/commands/init.xml")
void testUpdateCreateAndUpdate() throws GenieCheckedException {
    final Command init = this.service.getCommand(COMMAND_1_ID);
    final Instant created = init.getCreated();
    final Instant updated = init.getUpdated();

    final Command updateCommand = new Command(
        init.getId(),
        Instant.now(),
        Instant.EPOCH,
        init.getResources(),
        init.getMetadata(),
        init.getExecutable(),
        init.getMemory().orElse(null),
        init.getCheckDelay(),
        init.getClusterCriteria()
    );

    this.service.updateCommand(COMMAND_1_ID, updateCommand);
    final Command updatedCommand = this.service.getCommand(COMMAND_1_ID);
    Assertions.assertThat(updatedCommand.getCreated()).isEqualTo(created);
    Assertions.assertThat(updatedCommand.getUpdated()).isNotEqualTo(updated);
    Assertions.assertThat(updatedCommand.getUpdated()).isNotEqualTo(Instant.EPOCH);
}
 
Example 9
Source Project: conf4j   File: InstantConverterTest.java    License: MIT License 5 votes vote down vote up
@Test
public void shouldConvertFromStringWhenFormatSpecified() {
    // given
    String dateInString = "19700101 00:00:00 +00";
    String format = "yyyyMMdd HH:mm:ss x";
    Map<String, String> attributes = singletonMap("format", format);

    // when
    Instant fromConversion = instantConverter.fromString(Instant.class, dateInString, attributes);

    // then
    Instant expected = Instant.EPOCH;
    assertThat(fromConversion).isEqualTo(expected);
}
 
Example 10
Source Project: conf4j   File: InstantConverterTest.java    License: MIT License 5 votes vote down vote up
@Test
public void shouldThrowExceptionWhenConvertingToStringAndWrongFormat() {
    // given
    Instant toConvert = Instant.EPOCH;
    String format = "invalid format";
    Map<String, String> attributes = singletonMap("format", format);

    // then
    assertThatThrownBy(() -> instantConverter.toString(Instant.class, toConvert, attributes))
            .isExactlyInstanceOf(IllegalArgumentException.class)
            .hasMessage("Unable to convert Instant to String. Invalid format: 'invalid format'");
}
 
Example 11
Source Project: openAGV   File: TransportOrder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new TransportOrder.
 *
 * @param name This transport order's name.
 * @param driveOrders A list of drive orders to be processed when processing this transport
 * order.
 */
public TransportOrder(String name, List<DriveOrder> driveOrders) {
  super(name,
        new HashMap<>(),
        new ObjectHistory().withEntryAppended(new ObjectHistory.Entry(ORDER_CREATED)));
  this.driveOrders = requireNonNull(driveOrders, "driveOrders");
  this.currentDriveOrderIndex = -1;
  this.creationTime = Instant.EPOCH;
  this.intendedVehicle = null;
  this.deadline = Instant.ofEpochMilli(Long.MAX_VALUE);
  this.dispensable = false;
  this.wrappingSequence = null;
  this.dependencies = new LinkedHashSet<>();
}
 
Example 12
@Test
@DatabaseSetup("persistence/clusters/init.xml")
void testUpdateCreateAndUpdate() throws GenieCheckedException {
    final Cluster getCluster = this.service.getCluster(CLUSTER_1_ID);
    final Instant created = getCluster.getCreated();
    final Instant updated = getCluster.getUpdated();

    final Cluster updateCluster = new Cluster(
        getCluster.getId(),
        Instant.now(),
        Instant.EPOCH,
        new ExecutionEnvironment(
            getCluster.getResources().getConfigs(),
            getCluster.getResources().getDependencies(),
            getCluster.getResources().getSetupFile().orElse(null)
        ),
        new ClusterMetadata.Builder(
            getCluster.getMetadata().getUser(),
            getCluster.getMetadata().getUser(),
            getCluster.getMetadata().getVersion(),
            getCluster.getMetadata().getStatus()
        )
            .withTags(getCluster.getMetadata().getTags())
            .withDescription(getCluster.getMetadata().getDescription().orElse(null))
            .build()
    );

    this.service.updateCluster(CLUSTER_1_ID, updateCluster);
    final Cluster updatedCluster = this.service.getCluster(CLUSTER_1_ID);
    Assertions.assertThat(updatedCluster.getCreated()).isEqualTo(created);
    Assertions.assertThat(updatedCluster.getUpdated()).isNotEqualTo(updated).isNotEqualTo(Instant.EPOCH);
    Assertions.assertThat(updatedCluster.getMetadata().getTags()).isEqualTo(getCluster.getMetadata().getTags());
    Assertions
        .assertThat(updatedCluster.getResources().getConfigs())
        .isEqualTo(getCluster.getResources().getConfigs());
    Assertions
        .assertThat(updatedCluster.getResources().getDependencies())
        .isEqualTo(getCluster.getResources().getDependencies());
}
 
Example 13
Source Project: phoebus   File: VTypeHelperTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testGetTimestamp() throws Exception{
    Instant epoch = Instant.EPOCH;
    Time t = Time.of(epoch);

    VInt i1 = VInt.of(1, Alarm.none(), t, Display.none());
    assertEquals(epoch, VTypeHelper.getTimestamp(i1));

    t = Time.nowInvalid();
    i1 = VInt.of(1, Alarm.none(), t, Display.none());

    Instant now = Instant.now();
    Thread.sleep(2);
    assertTrue(VTypeHelper.getTimestamp(i1).isAfter(now));
}
 
Example 14
Source Project: mewbase   File: HttpEventSource.java    License: MIT License 5 votes vote down vote up
@Override
public CompletableFuture<Subscription>  subscribeFromMostRecent(final String channelName, final EventHandler eventHandler) {

    try {
        final SubscriptionRequest.SubscriptionType subsType = SubscriptionRequest.SubscriptionType.FromMostRecent;
        final SubscriptionRequest subsRq = new SubscriptionRequest(channelName, subsType,0L,Instant.EPOCH);
        return new HttpEventSubscription(vertx.createHttpClient(options), subsRq, eventHandler).future;
    } catch (Exception exp) {
        return FallibleFuture.failedFuture(exp);
    }
}
 
Example 15
Source Project: flink   File: InstantSerializerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Instant[] getTestData() {
	final Random rnd = new Random(874597969123412341L);

	return new Instant[] {
		Instant.EPOCH, Instant.MIN, Instant.MAX,
		Instant.ofEpochSecond(rndSeconds(rnd),	rndNanos(rnd)),
		Instant.ofEpochSecond(1534135584,949495),
		Instant.ofEpochSecond(56090783)
	};
}
 
Example 16
@Test
public void testSerialization() throws JsonProcessingException {
    MegabusRef ref = new MegabusRef(TEST_TABLE_NAME, TEST_KEY, TimeUUIDs.minimumUuid(), Instant.EPOCH, MegabusRef.RefType.NORMAL);
    assertEquals(_mapper.writeValueAsString(ref), "{\"table\":\"tableA\",\"key\":\"abc123\",\"changeId\":\"00000000-0000-1000-8000-000000000000\",\"readTime\":\"1970-01-01T00:00:00Z\",\"refType\":\"NORMAL\"}");
}
 
Example 17
Source Project: spring-session   File: MapSessionTests.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Instant getCreationTime() {
	return Instant.EPOCH;
}
 
Example 18
Source Project: conga   File: TestClock.java    License: Apache License 2.0 4 votes vote down vote up
public TestClock() {
  this(Instant.EPOCH, ZoneId.of("Z"));
}
 
Example 19
@Test
public void expiresEarlyIsExpiredNow() {
  TimedWatcher timedWatcher = new UnobservableWatcher(Instant.EPOCH);
  assertThat(timedWatcher.isExpiredAt(Instant.now())).isTrue();
}
 
Example 20
@Override
public @Nullable Instant granted_tnt_license_at() {
    return Instant.EPOCH;
}