blob: ead46121e9e70c3e0fd0631aa253e975f581670b [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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.store.impl;
Madan Jampanifd26ffb2014-10-13 14:08:55 -070017
18import static org.junit.Assert.assertTrue;
19
20import java.nio.ByteBuffer;
21
22import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.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;
Jonathan Hart63939a32015-05-08 11:57:03 -070027import org.onosproject.store.service.WallClockTimestamp;
Madan Jampanifd26ffb2014-10-13 14:08:55 -070028
29/**
30 * Tests for {@link WallClockTimestamp}.
31 */
32public class WallClockTimestampTest {
33
34 @Test
35 public final void testBasic() throws InterruptedException {
36 WallClockTimestamp ts1 = new WallClockTimestamp();
37 Thread.sleep(50);
38 WallClockTimestamp ts2 = new WallClockTimestamp();
39
40 assertTrue(ts1.compareTo(ts1) == 0);
41 assertTrue(ts2.compareTo(ts1) > 0);
42 assertTrue(ts1.compareTo(ts2) < 0);
43 }
44
45 @Test
46 public final void testKryoSerializable() {
47 WallClockTimestamp ts1 = new WallClockTimestamp();
48 final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -070049 final KryoNamespace kryos = KryoNamespace.newBuilder()
Madan Jampanifd26ffb2014-10-13 14:08:55 -070050 .register(WallClockTimestamp.class)
51 .build();
52
53 kryos.serialize(ts1, buffer);
54 buffer.flip();
55 Timestamp copy = kryos.deserialize(buffer);
56
57 new EqualsTester()
58 .addEqualityGroup(ts1, copy)
59 .testEquals();
60 }
61}