blob: 370c9f6bd2253f08266ef88faa0d9b280f96dec5 [file] [log] [blame]
Madan Jampanifd26ffb2014-10-13 14:08:55 -07001package org.onlab.onos.store.impl;
2
3import static org.junit.Assert.assertTrue;
4
5import java.nio.ByteBuffer;
6
7import org.junit.Test;
8import org.onlab.onos.store.Timestamp;
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -07009import org.onlab.util.KryoNamespace;
Madan Jampanifd26ffb2014-10-13 14:08:55 -070010
11import com.google.common.testing.EqualsTester;
12
13/**
14 * Tests for {@link WallClockTimestamp}.
15 */
16public 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 HIGUCHI8d143d22014-10-19 23:15:09 -070033 final KryoNamespace kryos = KryoNamespace.newBuilder()
Madan Jampanifd26ffb2014-10-13 14:08:55 -070034 .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}