2 * (C) Copyright 2017 Pantheon Technologies, s.r.o. and others.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.opendaylight.yangtools.triemap;
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertTrue;
23 import org.junit.Before;
24 import org.junit.Test;
26 public class SnapshotTest {
27 private TrieMap<String, String> map;
31 map = TrieMap.create();
36 private static void assertMutableIsolation(final Map<String, String> m1, final Map<String, String> m2) {
37 assertTrue(m2.containsKey("k1"));
38 assertTrue(m2.containsKey("k2"));
41 assertFalse(m1.containsKey("k1"));
42 assertTrue(m2.containsKey("k1"));
45 assertFalse(m1.containsKey("k1"));
46 assertTrue(m2.containsKey("k1"));
48 assertEquals(1, m1.size());
49 assertEquals(1, m2.size());
53 public void testMutableSnapshotIsolation() {
54 assertMutableIsolation(map, map.mutableSnapshot());
58 public void testMutableSnapshotIsolationAcrossImmutable() {
59 final TrieMap<String, String> snap = map.immutableSnapshot();
60 assertTrue(snap.containsKey("k1"));
61 assertTrue(snap.containsKey("k2"));
63 assertMutableIsolation(map, snap.mutableSnapshot());
65 assertTrue(snap.containsKey("k1"));
66 assertTrue(snap.containsKey("k2"));