Madan Jampani | fd26ffb | 2014-10-13 14:08:55 -0700 | [diff] [blame] | 1 | package org.onlab.onos.store.impl; |
| 2 | |
| 3 | import static org.junit.Assert.assertTrue; |
| 4 | |
| 5 | import java.nio.ByteBuffer; |
| 6 | |
| 7 | import org.junit.Test; |
| 8 | import org.onlab.onos.store.Timestamp; |
Yuta HIGUCHI | 8d143d2 | 2014-10-19 23:15:09 -0700 | [diff] [blame] | 9 | import org.onlab.util.KryoNamespace; |
Madan Jampani | fd26ffb | 2014-10-13 14:08:55 -0700 | [diff] [blame] | 10 | |
| 11 | import com.google.common.testing.EqualsTester; |
| 12 | |
| 13 | /** |
| 14 | * Tests for {@link WallClockTimestamp}. |
| 15 | */ |
| 16 | public class WallClockTimestampTest { |
| 17 | |
| 18 | @Test |
| 19 | public final void testBasic() throws InterruptedException { |
| 20 | WallClockTimestamp ts1 = new WallClockTimestamp(); |
| 21 | Thread.sleep(50); |
| 22 | WallClockTimestamp ts2 = new WallClockTimestamp(); |
| 23 | |
| 24 | assertTrue(ts1.compareTo(ts1) == 0); |
| 25 | assertTrue(ts2.compareTo(ts1) > 0); |
| 26 | assertTrue(ts1.compareTo(ts2) < 0); |
| 27 | } |
| 28 | |
| 29 | @Test |
| 30 | public final void testKryoSerializable() { |
| 31 | WallClockTimestamp ts1 = new WallClockTimestamp(); |
| 32 | final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024); |
Yuta HIGUCHI | 8d143d2 | 2014-10-19 23:15:09 -0700 | [diff] [blame] | 33 | final KryoNamespace kryos = KryoNamespace.newBuilder() |
Madan Jampani | fd26ffb | 2014-10-13 14:08:55 -0700 | [diff] [blame] | 34 | .register(WallClockTimestamp.class) |
| 35 | .build(); |
| 36 | |
| 37 | kryos.serialize(ts1, buffer); |
| 38 | buffer.flip(); |
| 39 | Timestamp copy = kryos.deserialize(buffer); |
| 40 | |
| 41 | new EqualsTester() |
| 42 | .addEqualityGroup(ts1, copy) |
| 43 | .testEquals(); |
| 44 | } |
| 45 | } |