Migrate to tech.pantheon.TrieMap
[yangtools.git] / third-party / triemap / src / test / java / org / opendaylight / yangtools / triemap / SnapshotTest.java
1 /*
2  * (C) Copyright 2017 Pantheon Technologies, s.r.o. and others.
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  */
16 package org.opendaylight.yangtools.triemap;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertTrue;
21
22 import java.util.Map;
23 import org.junit.Before;
24 import org.junit.Test;
25
26 @Deprecated
27 public class SnapshotTest {
28     private TrieMap<String, String> map;
29
30     @Before
31     public void setUp() {
32         map = TrieMap.create();
33         map.put("k1", "v1");
34         map.put("k2", "v2");
35     }
36
37     private static void assertMutableIsolation(final Map<String, String> m1, final Map<String, String> m2) {
38         assertTrue(m2.containsKey("k1"));
39         assertTrue(m2.containsKey("k2"));
40
41         m1.remove("k1");
42         assertFalse(m1.containsKey("k1"));
43         assertTrue(m2.containsKey("k1"));
44
45         m2.remove("k2");
46         assertFalse(m1.containsKey("k1"));
47         assertTrue(m2.containsKey("k1"));
48
49         assertEquals(1, m1.size());
50         assertEquals(1, m2.size());
51     }
52
53     @Test
54     public void testMutableSnapshotIsolation() {
55         assertMutableIsolation(map, map.mutableSnapshot());
56     }
57
58     @Test
59     public void testMutableSnapshotIsolationAcrossImmutable() {
60         final TrieMap<String, String> snap = map.immutableSnapshot();
61         assertTrue(snap.containsKey("k1"));
62         assertTrue(snap.containsKey("k2"));
63
64         assertMutableIsolation(map, snap.mutableSnapshot());
65
66         assertTrue(snap.containsKey("k1"));
67         assertTrue(snap.containsKey("k2"));
68
69     }
70 }