Java Code Examples for java.time.Instant.minusSeconds()

The following are Jave code examples for showing how to use minusSeconds() of the java.time.Instant class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: tg-eventstore   File: MergedEventSourceTest.java   View Source Code Vote up 6 votes
@Test public void
does_not_skip_newer_events_for_out_of_order_older_events_when_applying_a_delay() throws Exception {
    Instant event1Instant = clock.instant();
    Instant event2Instant = event1Instant.minusSeconds(1L);

    EventReader input = new EventReader() {
        @Override
        public Stream<ResolvedEvent> readAllForwards(Position positionExclusive) {
            return ImmutableList.of(
                    new ResolvedEvent(new Position() { }, eventRecord(event1Instant, streamId("a", "1"), 1L, "X", new byte[0], new byte[0])),
                    new ResolvedEvent(new Position() { }, eventRecord(event2Instant, streamId("b", "1"), 1L, "X", new byte[0], new byte[0]))
            ).stream();
        }

        @Override public Position emptyStorePosition() { return null; }
    };

    EventReader outputReader = MergedEventSource.streamOrderMergedEventSource(clock, ofSeconds(1L), new NamedReaderWithCodec("a", input, JavaInMemoryEventStore.CODEC)).readAll();

    assertThat(outputReader.readAllForwards().count(), is(0L));

    clock.bump(ofSeconds(1L));
    assertThat(outputReader.readAllForwards().count(), is(2L));
}
 
Example 2
Project: jdk8u-jdk   File: TCKInstant.java   View Source Code Vote up 5 votes
@Test(dataProvider="MinusSeconds")
public void minusSeconds_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Instant i = Instant.ofEpochSecond(seconds, nanos);
    i = i.minusSeconds(amount);
    assertEquals(i.getEpochSecond(), expectedSeconds);
    assertEquals(i.getNano(), expectedNanoOfSecond);
}
 
Example 3
Project: openjdk-jdk10   File: TCKInstant.java   View Source Code Vote up 5 votes
@Test(dataProvider="MinusSeconds")
public void minusSeconds_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Instant i = Instant.ofEpochSecond(seconds, nanos);
    i = i.minusSeconds(amount);
    assertEquals(i.getEpochSecond(), expectedSeconds);
    assertEquals(i.getNano(), expectedNanoOfSecond);
}
 
Example 4
Project: jdk8u-jdk   File: TCKInstant.java   View Source Code Vote up 4 votes
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 5
Project: jdk8u-jdk   File: TCKInstant.java   View Source Code Vote up 4 votes
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Instant i = Instant.ofEpochSecond(-2, 0);
    i.minusSeconds(Long.MAX_VALUE);
}
 
Example 6
Project: openjdk-jdk10   File: TCKInstant.java   View Source Code Vote up 4 votes
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 7
Project: openjdk-jdk10   File: TCKInstant.java   View Source Code Vote up 4 votes
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Instant i = Instant.ofEpochSecond(-2, 0);
    i.minusSeconds(Long.MAX_VALUE);
}