Java Code Examples for java.time.Duration#minusSeconds()

The following examples show how to use java.time.Duration#minusSeconds() . 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 check out the related API usage on the sidebar.
Example 1
@Test(dataProvider="MinusSeconds")
public void minusSeconds_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.minusSeconds(amount);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
 
Example 2
@Test(dataProvider="MinusSeconds")
public void minusSeconds_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.minusSeconds(amount);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
 
Example 3
@Test(dataProvider="MinusSeconds")
public void minusSeconds_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.minusSeconds(amount);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
 
Example 4
@Test(dataProvider="MinusSeconds")
public void minusSeconds_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.minusSeconds(amount);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
 
Example 5
@Test(dataProvider="MinusSeconds")
public void minusSeconds_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.minusSeconds(amount);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
 
Example 6
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Duration t = Duration.ofSeconds(-2, 0);
    t.minusSeconds(Long.MAX_VALUE);
}
 
Example 7
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Duration t = Duration.ofSeconds(1, 0);
    t.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 8
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Duration t = Duration.ofSeconds(-2, 0);
    t.minusSeconds(Long.MAX_VALUE);
}
 
Example 9
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Duration t = Duration.ofSeconds(-2, 0);
    t.minusSeconds(Long.MAX_VALUE);
}
 
Example 10
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Duration t = Duration.ofSeconds(1, 0);
    t.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 11
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Duration t = Duration.ofSeconds(-2, 0);
    t.minusSeconds(Long.MAX_VALUE);
}
 
Example 12
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Duration t = Duration.ofSeconds(-2, 0);
    t.minusSeconds(Long.MAX_VALUE);
}
 
Example 13
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Duration t = Duration.ofSeconds(1, 0);
    t.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 14
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Duration t = Duration.ofSeconds(1, 0);
    t.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 15
/**
 * Attempts to make a websocket connection as an authenticated user, and stream values from a view.
 */
@Test
public void test_authenticated_webSocketConnection() throws InterruptedException {
    // Create a count down latch to know when we have consumed all of our records.
    final CountDownLatch countDownLatch = new CountDownLatch(kafkaRecords.size());

    // Create a list we can add our consumed records to
    final List<Map> consumedRecords = new ArrayList<>();

    // Login to instance.
    final UserLoginDetails userLoginDetails = login();

    final WebSocketHttpHeaders socketHttpHeaders = new WebSocketHttpHeaders(userLoginDetails.getHttpHeaders());
    final long userId = userLoginDetails.getUserId();

    // Create websocket client
    final SockJsClient sockJsClient = new SockJsClient(createTransportClient());
    final WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient);
    stompClient.setMessageConverter(new MappingJackson2MessageConverter());

    // Connect to websocket
    stompClient.connect(WEBSOCKET_URL, socketHttpHeaders, new StompSessionHandlerAdapter() {
        /**
         * After we connect, subscribe to our view.
         */
        @Override
        public void afterConnected(final StompSession session, final StompHeaders connectedHeaders) {
            session.setAutoReceipt(false);
            subscribeToResults(session, view.getId(), userId, countDownLatch, consumedRecords);
            try {
                requestNewStream(session, view.getId());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }, port);

    // Start the client.
    stompClient.start();

    // Define a max time of 15 seconds
    Duration testTimeout = Duration.ofSeconds(15);

    while (countDownLatch.getCount() > 0) {
        // Sleep for a period and recheck.
        Thread.sleep(1000L);
        testTimeout = testTimeout.minusSeconds(1);

        if (testTimeout.isNegative()) {
            fail("Test timed out!");
        }
    }

    // Success!
    assertEquals("Found all messages!", consumedRecords.size(), kafkaRecords.size());
}
 
Example 16
Source Project: hottub   File: TCKDuration.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Duration t = Duration.ofSeconds(-2, 0);
    t.minusSeconds(Long.MAX_VALUE);
}
 
Example 17
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Duration t = Duration.ofSeconds(-2, 0);
    t.minusSeconds(Long.MAX_VALUE);
}
 
Example 18
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Duration t = Duration.ofSeconds(1, 0);
    t.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 19
Source Project: j2objc   File: TCKDuration.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected = ArithmeticException.class)
public void minusSeconds_long_overflowTooSmall() {
    Duration t = Duration.ofSeconds(-2, 0);
    t.minusSeconds(Long.MAX_VALUE);
}
 
Example 20
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Duration t = Duration.ofSeconds(1, 0);
    t.minusSeconds(Long.MIN_VALUE + 1);
}