-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent delta calculation when start time isn't available. Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
element-connector/src/test/java/org/eclipse/californium/elements/util/ClockUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License | ||
* v1.0 which is available at | ||
* https://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
********************************************************************************/ | ||
package org.eclipse.californium.elements.util; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.greaterThan; | ||
import static org.hamcrest.Matchers.greaterThanOrEqualTo; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.eclipse.californium.elements.category.Small; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
@Category(Small.class) | ||
public class ClockUtilTest { | ||
|
||
@Test | ||
public void testNanoRealtime() { | ||
long now1 = ClockUtil.nanoRealtime(); | ||
try { | ||
Thread.sleep(200); | ||
long now2 = ClockUtil.nanoRealtime(); | ||
assertThat(now2, is(greaterThanOrEqualTo(now1))); | ||
} catch (InterruptedException e) { | ||
} | ||
} | ||
|
||
@Test | ||
public void testDelta() { | ||
long now = ClockUtil.nanoRealtime(); | ||
try { | ||
Thread.sleep(200); | ||
long delta = ClockUtil.delta(now, TimeUnit.MILLISECONDS); | ||
assertThat(delta, is(greaterThan(100L))); | ||
} catch (InterruptedException e) { | ||
} | ||
long delta2 = ClockUtil.delta(0, TimeUnit.MILLISECONDS); | ||
assertThat(delta2, is(0L)); | ||
} | ||
|
||
} |