1 | private void evictOrRemoveAllTest(boolean evict) {↵ | | 1 | private void evictOrRemoveAllTest(boolean evict) {↵
|
2 | ↵ | | 2 | ↵
|
3 | final String KEY = KEY_BASE + testCount++;↵ | | 3 | final String KEY = KEY_BASE + testCount++;↵
|
4 | ↵ | | 4 | ↵
|
5 | Fqn regionFqn = getRegionFqn(REGION_NAME, REGION_PREFIX);↵ | | 5 | Fqn regionFqn = getRegionFqn(REGION_NAME, REGION_PREFIX);↵
|
6 | ↵ | | 6 | ↵
|
7 | Node regionRoot = localCache.getRoot().getChild(regionFqn);↵ | | 7 | Node regionRoot = localCache.getRoot().getChild(regionFqn);↵
|
8 | assertFalse(regionRoot == null);↵ | | 8 | assertFalse(regionRoot == null);↵
|
9 | assertEquals(0, getValidChildrenCount(regionRoot));↵ | | 9 | assertEquals(0, getValidChildrenCount(regionRoot));↵
|
10 | assertTrue(regionRoot.isResident());↵ | | 10 | assertTrue(regionRoot.isResident());↵
|
11 | ↵ | | 11 | ↵
|
12 | if (isUsingOptimisticLocking()) {↵ | | 12 | if (isUsingOptimisticLocking()) {↵
|
13 | assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());↵ | | 13 | assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());↵
|
14 | }↵ | | 14 | }↵
|
|
15 | regionRoot = remoteCache.getRoot().getChild(regionFqn);↵ | | 15 | regionRoot = remoteCache.getRoot().getChild(regionFqn);↵
|
16 | assertFalse(regionRoot == null);↵ | | 16 | assertFalse(regionRoot == null);↵
|
17 | assertEquals(0, getValidChildrenCount(regionRoot));↵ | | 17 | assertEquals(0, getValidChildrenCount(regionRoot));↵
|
18 | assertTrue(regionRoot.isResident());↵ | | 18 | assertTrue(regionRoot.isResident());↵
|
19 | ↵ | | 19 | ↵
|
20 | if (isUsingOptimisticLocking()) {↵ | | 20 | if (isUsingOptimisticLocking()) {↵
|
21 | assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());↵ | | 21 | assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());↵
|
22 | }↵ | | 22 | }↵
|
23 | ↵ | | 23 | ↵
|
24 | assertNull("local is clean", localAccessStrategy.get(KEY, System.currentTimeMillis()));↵ | | 24 | assertNull("local is clean", localAccessStrategy.get(KEY, System.currentTimeMillis()));↵
|
25 | assertNull("remote is clean", remoteAccessStrategy.get(KEY, System.currentTimeMillis()));↵ | | 25 | assertNull("remote is clean", remoteAccessStrategy.get(KEY, System.currentTimeMillis()));↵
|
26 | ↵ | | 26 | ↵
|
27 | localAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));↵ | | 27 | localAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));↵
|
28 | assertEquals(VALUE1, localAccessStrategy.get(KEY, System.currentTimeMillis()));↵ | | 28 | assertEquals(VALUE1, localAccessStrategy.get(KEY, System.currentTimeMillis()));↵
|
| | | 29 | ↵
|
| | | 30 | // Wait for async propagation↵
|
| | | 31 | sleep(250);↵
|
| | | 32 | ↵
|
29 | remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));↵ | | 33 | remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));↵
|
30 | assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));↵ | | 34 | assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));↵
|
31 | ↵ | | 35 | ↵
|
32 | // Wait for async propagation↵ | | 36 | // Wait for async propagation↵
|
33 | sleep(250);↵ | | 37 | sleep(250);↵
|
34 | ↵ | | 38 | ↵
|
35 | if (isUsingOptimisticLocking()) {↵ | | 39 | if (isUsingOptimisticLocking()) {↵
|
36 | regionRoot = localCache.getRoot().getChild(regionFqn);↵ | | 40 | regionRoot = localCache.getRoot().getChild(regionFqn);↵
|
37 | assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());↵ | | 41 | assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());↵
|
38 | regionRoot = remoteCache.getRoot().getChild(regionFqn);↵ | | 42 | regionRoot = remoteCache.getRoot().getChild(regionFqn);↵
|
39 | assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());↵ | | 43 | assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());↵
|
40 | }↵ | | 44 | }↵
|
41 | ↵ | | 45 | ↵
|
42 | if (evict)↵ | | 46 | if (evict)↵
|
43 | localAccessStrategy.evictAll();↵ | | 47 | localAccessStrategy.evictAll();↵
|
44 | else↵ | | 48 | else↵
|
45 | localAccessStrategy.removeAll();↵ | | 49 | localAccessStrategy.removeAll();↵
|
46 | ↵ | | 50 | ↵
|
47 | // This should re-establish the region root node in the optimistic case↵ | | 51 | // This should re-establish the region root node in the optimistic case↵
|
48 | assertNull(localAccessStrategy.get(KEY, System.currentTimeMillis()));↵ | | 52 | assertNull(localAccessStrategy.get(KEY, System.currentTimeMillis()));↵
|
49 | ↵ | | 53 | ↵
|
50 | regionRoot = localCache.getRoot().getChild(regionFqn);↵ | | 54 | regionRoot = localCache.getRoot().getChild(regionFqn);↵
|
51 | if (isUsingOptimisticLocking()) {↵ | | 55 | if (isUsingOptimisticLocking()) {↵
|
52 | assertFalse(regionRoot == null);↵ | | 56 | assertFalse(regionRoot == null);↵
|
53 | assertEquals(0, getValidChildrenCount(regionRoot));↵ | | 57 | assertEquals(0, getValidChildrenCount(regionRoot));↵
|
54 | assertTrue(regionRoot.isValid());↵ | | 58 | assertTrue(regionRoot.isValid());↵
|
55 | assertTrue(regionRoot.isResident());↵ | | 59 | assertTrue(regionRoot.isResident());↵
|
56 | }↵ | | 60 | }↵
|
57 | else {↵ | | 61 | else {↵
|
58 | assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());↵ | | 62 | assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());↵
|
59 | }↵ | | 63 | }↵
|
|
60 | // Re-establishing the region root on the local node doesn't ↵ | | 64 | // Re-establishing the region root on the local node doesn't ↵
|
61 | // propagate it to other nodes. Do a get on the remote node to re-establish↵ | | 65 | // propagate it to other nodes. Do a get on the remote node to re-establish↵
|
62 | // This only adds a node in the case of optimistic locking↵ | | |
|
63 | assertEquals(null, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));↵ | | 66 | assertEquals(null, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));↵
|
|
64 | regionRoot = remoteCache.getRoot().getChild(regionFqn);↵ | | 67 | regionRoot = remoteCache.getRoot().getChild(regionFqn);↵
|
65 | if (isUsingOptimisticLocking()) {↵ | | 68 | if (isUsingOptimisticLocking()) {↵
|
66 | assertFalse(regionRoot == null);↵ | | 69 | assertFalse(regionRoot == null);↵
|
67 | assertTrue(regionRoot.isValid());↵ | | 70 | assertTrue(regionRoot.isValid());↵
|
68 | assertTrue(regionRoot.isResident());↵ | | 71 | assertTrue(regionRoot.isResident());↵
|
69 | // Not invalidation, so we didn't insert a child above↵ | | 72 | // Not invalidation, so we didn't insert a child above↵
|
70 | assertEquals(0, getValidChildrenCount(regionRoot));↵ | | 73 | assertEquals(0, getValidChildrenCount(regionRoot));↵
|
71 | } ↵ | | 74 | } ↵
|
72 | else {↵ | | 75 | else {↵
|
73 | assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());↵ | | 76 | assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());↵
|
74 | }↵ | | 77 | }↵
|
75 | ↵ | | 78 | ↵
|
76 | // Test whether the get above messes up the optimistic version↵ | | 79 | // Test whether the get above messes up the optimistic version↵
|
77 | remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));↵ | | 80 | remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));↵
|
78 | assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));↵ | | 81 | assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));↵
|
79 | ↵ | | 82 | ↵
|
80 | // Revalidate the region root↵ | | 83 | // Revalidate the region root↵
|
81 | regionRoot = remoteCache.getRoot().getChild(regionFqn);↵ | | 84 | regionRoot = remoteCache.getRoot().getChild(regionFqn);↵
|
82 | assertFalse(regionRoot == null);↵ | | 85 | assertFalse(regionRoot == null);↵
|
83 | assertTrue(regionRoot.isValid());↵ | | 86 | assertTrue(regionRoot.isValid());↵
|
84 | assertTrue(regionRoot.isResident());↵ | | 87 | assertTrue(regionRoot.isResident());↵
|
85 | // Region root should have 1 child -- the one we added above↵ | | 88 | // Region root should have 1 child -- the one we added above↵
|
86 | assertEquals(1, getValidChildrenCount(regionRoot));↵ | | 89 | assertEquals(1, getValidChildrenCount(regionRoot));↵
|
87 | ↵ | | 90 | ↵
|
88 | // Wait for async propagation of the putFromLoad↵ | | 91 | // Wait for async propagation↵
|
89 | sleep(250);↵ | | 92 | sleep(250);↵
|
90 | ↵ | | 93 | ↵
|
91 | assertEquals("local is correct", (isUsingInvalidation() ? null : VALUE1), localAccessStrategy.get(KEY, System.currentTimeMillis()));↵ | | 94 | assertEquals("local is correct", (isUsingInvalidation() ? null : VALUE1), localAccessStrategy.get(KEY, System.currentTimeMillis()));↵
|
92 | assertEquals("remote is correct", VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));↵ | | 95 | assertEquals("remote is correct", VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));↵
|
93 | | | 96 |
|