blob: cfad4e4152b4c2b5d82ce77049aeba2aad1fa658 [file] [log] [blame]
Madan Jampanidbe67032015-07-08 22:48:09 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Madan Jampanidbe67032015-07-08 22:48:09 -07003 *
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 Jampanif4c88502016-01-21 12:35:36 -080016package org.onosproject.store.primitives.impl;
Madan Jampanidbe67032015-07-08 22:48:09 -070017
18import static org.junit.Assert.assertEquals;
19import static org.junit.Assert.assertFalse;
20import static org.junit.Assert.assertNull;
21import static org.junit.Assert.assertTrue;
22
23import org.junit.Test;
Madan Jampanif4c88502016-01-21 12:35:36 -080024import org.onosproject.store.LogicalTimestamp;
Madan Jampanidbe67032015-07-08 22:48:09 -070025import org.onosproject.store.Timestamp;
Madan Jampanif4c88502016-01-21 12:35:36 -080026import org.onosproject.store.primitives.impl.MapValue.Digest;
Madan Jampanidbe67032015-07-08 22:48:09 -070027
28/**
29 * Unit tests for MapValue.
30 */
31public class MapValueTest {
32
33 @Test
34 public void testConstruction() {
35 Timestamp ts = new LogicalTimestamp(10);
36 MapValue<String> mv = new MapValue<>("foo", ts);
37 assertEquals("foo", mv.get());
38 assertEquals(ts, mv.timestamp());
39 assertTrue(mv.isAlive());
40 }
41
42 @Test
43 public void testDigest() {
44 Timestamp ts = new LogicalTimestamp(10);
45 MapValue<String> mv = new MapValue<>("foo", ts);
46 Digest actual = mv.digest();
47 Digest expected = new MapValue.Digest(ts, false);
48 assertEquals(actual, expected);
49 }
50
Yuta HIGUCHIfbd9ae92018-01-24 23:39:06 -080051 @SuppressWarnings("SelfComparison")
Madan Jampanidbe67032015-07-08 22:48:09 -070052 @Test
53 public void testComparison() {
54 Timestamp ts1 = new LogicalTimestamp(9);
55 Timestamp ts2 = new LogicalTimestamp(10);
56 Timestamp ts3 = new LogicalTimestamp(11);
57 MapValue<String> mv1 = new MapValue<>("foo", ts1);
58 MapValue<String> mv2 = new MapValue<>("foo", ts2);
59 MapValue<String> mv3 = new MapValue<>("foo", ts3);
60 assertTrue(mv2.isNewerThan(mv1));
61 assertFalse(mv1.isNewerThan(mv3));
62
63 assertTrue(mv3.isNewerThan(ts2));
64 assertFalse(mv1.isNewerThan(ts2));
65
66 assertTrue(mv1.compareTo(mv2) < 0);
67 assertTrue(mv1.compareTo(mv1) == 0);
68 assertTrue(mv3.compareTo(mv2) > 0);
69 }
70
71 @Test
72 public void testTombstone() {
73 Timestamp ts1 = new LogicalTimestamp(9);
74 MapValue<String> mv = MapValue.tombstone(ts1);
75 assertTrue(mv.isTombstone());
76 assertFalse(mv.isAlive());
77 assertNull(mv.get());
78 assertEquals(ts1, mv.timestamp());
79 }
80}