blob: 433c5baa732140fb82a0d6d18ed032d0713ef8a0 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Madan Jampanifd26ffb2014-10-13 14:08:55 -070016package org.onlab.onos.store.impl;
17
18import static org.junit.Assert.assertTrue;
19
20import java.nio.ByteBuffer;
21
22import org.junit.Test;
23import org.onlab.onos.store.Timestamp;
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -070024import org.onlab.util.KryoNamespace;
Madan Jampanifd26ffb2014-10-13 14:08:55 -070025
26import com.google.common.testing.EqualsTester;
27
28/**
29 * Tests for {@link WallClockTimestamp}.
30 */
31public class WallClockTimestampTest {
32
33 @Test
34 public final void testBasic() throws InterruptedException {
35 WallClockTimestamp ts1 = new WallClockTimestamp();
36 Thread.sleep(50);
37 WallClockTimestamp ts2 = new WallClockTimestamp();
38
39 assertTrue(ts1.compareTo(ts1) == 0);
40 assertTrue(ts2.compareTo(ts1) > 0);
41 assertTrue(ts1.compareTo(ts2) < 0);
42 }
43
44 @Test
45 public final void testKryoSerializable() {
46 WallClockTimestamp ts1 = new WallClockTimestamp();
47 final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -070048 final KryoNamespace kryos = KryoNamespace.newBuilder()
Madan Jampanifd26ffb2014-10-13 14:08:55 -070049 .register(WallClockTimestamp.class)
50 .build();
51
52 kryos.serialize(ts1, buffer);
53 buffer.flip();
54 Timestamp copy = kryos.deserialize(buffer);
55
56 new EqualsTester()
57 .addEqualityGroup(ts1, copy)
58 .testEquals();
59 }
60}