Committed by
Gerrit Code Review
Changes to speed up tests.
Change-Id: I1830f564710b9cb06d9c41d31e31854a272fbf4d
Showing
5 changed files
with
119 additions
and
91 deletions
... | @@ -19,20 +19,18 @@ package org.onosproject.store.primitives.resources.impl; | ... | @@ -19,20 +19,18 @@ package org.onosproject.store.primitives.resources.impl; |
19 | import com.google.common.collect.Lists; | 19 | import com.google.common.collect.Lists; |
20 | import com.google.common.collect.Multiset; | 20 | import com.google.common.collect.Multiset; |
21 | import com.google.common.collect.TreeMultiset; | 21 | import com.google.common.collect.TreeMultiset; |
22 | -import com.google.common.io.Files; | ||
23 | import io.atomix.resource.ResourceType; | 22 | import io.atomix.resource.ResourceType; |
24 | import org.apache.commons.collections.keyvalue.DefaultMapEntry; | 23 | import org.apache.commons.collections.keyvalue.DefaultMapEntry; |
25 | -import org.junit.Ignore; | 24 | +import org.junit.AfterClass; |
25 | +import org.junit.BeforeClass; | ||
26 | import org.junit.Test; | 26 | import org.junit.Test; |
27 | import org.onlab.util.Tools; | 27 | import org.onlab.util.Tools; |
28 | 28 | ||
29 | -import java.io.File; | ||
30 | import java.util.Arrays; | 29 | import java.util.Arrays; |
31 | import java.util.Collection; | 30 | import java.util.Collection; |
32 | import java.util.Comparator; | 31 | import java.util.Comparator; |
33 | import java.util.List; | 32 | import java.util.List; |
34 | import java.util.Map; | 33 | import java.util.Map; |
35 | -import java.util.concurrent.atomic.AtomicInteger; | ||
36 | 34 | ||
37 | import static org.junit.Assert.assertEquals; | 35 | import static org.junit.Assert.assertEquals; |
38 | import static org.junit.Assert.assertFalse; | 36 | import static org.junit.Assert.assertFalse; |
... | @@ -41,9 +39,7 @@ import static org.junit.Assert.assertTrue; | ... | @@ -41,9 +39,7 @@ import static org.junit.Assert.assertTrue; |
41 | /** | 39 | /** |
42 | * Tests the {@link AsyncConsistentSetMultimap}. | 40 | * Tests the {@link AsyncConsistentSetMultimap}. |
43 | */ | 41 | */ |
44 | -@Ignore | ||
45 | public class AsyncConsistentSetMultimapTest extends AtomixTestBase { | 42 | public class AsyncConsistentSetMultimapTest extends AtomixTestBase { |
46 | - private final File testDir = Files.createTempDir(); | ||
47 | private final String keyOne = "hello"; | 43 | private final String keyOne = "hello"; |
48 | private final String keyTwo = "goodbye"; | 44 | private final String keyTwo = "goodbye"; |
49 | private final String keyThree = "foo"; | 45 | private final String keyThree = "foo"; |
... | @@ -58,7 +54,16 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { | ... | @@ -58,7 +54,16 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { |
58 | valueTwo, | 54 | valueTwo, |
59 | valueThree, | 55 | valueThree, |
60 | valueFour); | 56 | valueFour); |
61 | - private final AtomicInteger port = new AtomicInteger(49200); | 57 | + |
58 | + @BeforeClass | ||
59 | + public static void preTestSetup() throws Throwable { | ||
60 | + createCopycatServers(3); | ||
61 | + } | ||
62 | + | ||
63 | + @AfterClass | ||
64 | + public static void postTestCleanup() throws Exception { | ||
65 | + clearTests(); | ||
66 | + } | ||
62 | 67 | ||
63 | @Override | 68 | @Override |
64 | protected ResourceType resourceType() { | 69 | protected ResourceType resourceType() { |
... | @@ -71,8 +76,7 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { | ... | @@ -71,8 +76,7 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { |
71 | */ | 76 | */ |
72 | @Test | 77 | @Test |
73 | public void testSize() throws Throwable { | 78 | public void testSize() throws Throwable { |
74 | - clearTests(); | 79 | + AsyncConsistentSetMultimap map = createResource("testOneMap"); |
75 | - AsyncConsistentSetMultimap map = createResource(3); | ||
76 | //Simplest operation case | 80 | //Simplest operation case |
77 | map.isEmpty().thenAccept(result -> assertTrue(result)); | 81 | map.isEmpty().thenAccept(result -> assertTrue(result)); |
78 | map.put(keyOne, valueOne). | 82 | map.put(keyOne, valueOne). |
... | @@ -114,7 +118,6 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { | ... | @@ -114,7 +118,6 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { |
114 | map.isEmpty().thenAccept(result -> assertTrue(result)); | 118 | map.isEmpty().thenAccept(result -> assertTrue(result)); |
115 | 119 | ||
116 | map.destroy().join(); | 120 | map.destroy().join(); |
117 | - clearTests(); | ||
118 | } | 121 | } |
119 | 122 | ||
120 | /** | 123 | /** |
... | @@ -122,8 +125,7 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { | ... | @@ -122,8 +125,7 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { |
122 | */ | 125 | */ |
123 | @Test | 126 | @Test |
124 | public void containsTest() throws Throwable { | 127 | public void containsTest() throws Throwable { |
125 | - clearTests(); | 128 | + AsyncConsistentSetMultimap map = createResource("testTwoMap"); |
126 | - AsyncConsistentSetMultimap map = createResource(3); | ||
127 | 129 | ||
128 | //Populate the maps | 130 | //Populate the maps |
129 | allKeys.forEach(key -> { | 131 | allKeys.forEach(key -> { |
... | @@ -174,7 +176,6 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { | ... | @@ -174,7 +176,6 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { |
174 | }); | 176 | }); |
175 | 177 | ||
176 | map.destroy().join(); | 178 | map.destroy().join(); |
177 | - clearTests(); | ||
178 | } | 179 | } |
179 | 180 | ||
180 | /** | 181 | /** |
... | @@ -183,8 +184,7 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { | ... | @@ -183,8 +184,7 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { |
183 | */ | 184 | */ |
184 | @Test | 185 | @Test |
185 | public void addAndRemoveTest() throws Exception { | 186 | public void addAndRemoveTest() throws Exception { |
186 | - clearTests(); | 187 | + AsyncConsistentSetMultimap map = createResource("testThreeMap"); |
187 | - AsyncConsistentSetMultimap map = createResource(3); | ||
188 | 188 | ||
189 | //Test single put | 189 | //Test single put |
190 | allKeys.forEach(key -> { | 190 | allKeys.forEach(key -> { |
... | @@ -309,7 +309,6 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { | ... | @@ -309,7 +309,6 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { |
309 | }); | 309 | }); |
310 | 310 | ||
311 | map.destroy().join(); | 311 | map.destroy().join(); |
312 | - clearTests(); | ||
313 | } | 312 | } |
314 | 313 | ||
315 | /** | 314 | /** |
... | @@ -319,8 +318,7 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { | ... | @@ -319,8 +318,7 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { |
319 | */ | 318 | */ |
320 | @Test | 319 | @Test |
321 | public void testAccessors() throws Exception { | 320 | public void testAccessors() throws Exception { |
322 | - clearTests(); | 321 | + AsyncConsistentSetMultimap map = createResource("testFourMap"); |
323 | - AsyncConsistentSetMultimap map = createResource(3); | ||
324 | 322 | ||
325 | //Populate for full map behavior tests | 323 | //Populate for full map behavior tests |
326 | allKeys.forEach(key -> { | 324 | allKeys.forEach(key -> { |
... | @@ -400,15 +398,13 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { | ... | @@ -400,15 +398,13 @@ public class AsyncConsistentSetMultimapTest extends AtomixTestBase { |
400 | map.entries() | 398 | map.entries() |
401 | .thenAccept(result -> assertTrue(result.isEmpty())).join(); | 399 | .thenAccept(result -> assertTrue(result.isEmpty())).join(); |
402 | 400 | ||
403 | - map.destroy(); | 401 | + map.destroy().join(); |
404 | - clearTests(); | ||
405 | } | 402 | } |
406 | 403 | ||
407 | - private AsyncConsistentSetMultimap createResource(int clusterSize) { | 404 | + private AsyncConsistentSetMultimap createResource(String mapName) { |
408 | try { | 405 | try { |
409 | - createCopycatServers(clusterSize); | ||
410 | AsyncConsistentSetMultimap map = createAtomixClient(). | 406 | AsyncConsistentSetMultimap map = createAtomixClient(). |
411 | - getResource("testMap", AsyncConsistentSetMultimap.class) | 407 | + getResource("mapName", AsyncConsistentSetMultimap.class) |
412 | .join(); | 408 | .join(); |
413 | return map; | 409 | return map; |
414 | } catch (Throwable e) { | 410 | } catch (Throwable e) { | ... | ... |
... | @@ -18,7 +18,8 @@ package org.onosproject.store.primitives.resources.impl; | ... | @@ -18,7 +18,8 @@ package org.onosproject.store.primitives.resources.impl; |
18 | import com.google.common.base.Throwables; | 18 | import com.google.common.base.Throwables; |
19 | import com.google.common.collect.Sets; | 19 | import com.google.common.collect.Sets; |
20 | import io.atomix.resource.ResourceType; | 20 | import io.atomix.resource.ResourceType; |
21 | -import org.junit.Ignore; | 21 | +import org.junit.AfterClass; |
22 | +import org.junit.BeforeClass; | ||
22 | import org.junit.Test; | 23 | import org.junit.Test; |
23 | import org.onlab.util.Tools; | 24 | import org.onlab.util.Tools; |
24 | import org.onosproject.store.primitives.MapUpdate; | 25 | import org.onosproject.store.primitives.MapUpdate; |
... | @@ -49,9 +50,17 @@ import static org.junit.Assert.fail; | ... | @@ -49,9 +50,17 @@ import static org.junit.Assert.fail; |
49 | /** | 50 | /** |
50 | * Unit tests for {@link AtomixConsistentMap}. | 51 | * Unit tests for {@link AtomixConsistentMap}. |
51 | */ | 52 | */ |
52 | -@Ignore | ||
53 | public class AtomixConsistentMapTest extends AtomixTestBase { | 53 | public class AtomixConsistentMapTest extends AtomixTestBase { |
54 | 54 | ||
55 | + @BeforeClass | ||
56 | + public static void preTestSetup() throws Throwable { | ||
57 | + createCopycatServers(3); | ||
58 | + } | ||
59 | + | ||
60 | + @AfterClass | ||
61 | + public static void postTestCleanup() throws Exception { | ||
62 | + clearTests(); | ||
63 | + } | ||
55 | @Override | 64 | @Override |
56 | protected ResourceType resourceType() { | 65 | protected ResourceType resourceType() { |
57 | return new ResourceType(AtomixConsistentMap.class); | 66 | return new ResourceType(AtomixConsistentMap.class); |
... | @@ -98,12 +107,11 @@ public class AtomixConsistentMapTest extends AtomixTestBase { | ... | @@ -98,12 +107,11 @@ public class AtomixConsistentMapTest extends AtomixTestBase { |
98 | } | 107 | } |
99 | 108 | ||
100 | protected void basicMapOperationTests(int clusterSize) throws Throwable { | 109 | protected void basicMapOperationTests(int clusterSize) throws Throwable { |
101 | - createCopycatServers(clusterSize); | ||
102 | - | ||
103 | final byte[] rawFooValue = Tools.getBytesUtf8("Hello foo!"); | 110 | final byte[] rawFooValue = Tools.getBytesUtf8("Hello foo!"); |
104 | final byte[] rawBarValue = Tools.getBytesUtf8("Hello bar!"); | 111 | final byte[] rawBarValue = Tools.getBytesUtf8("Hello bar!"); |
105 | 112 | ||
106 | - AtomixConsistentMap map = createAtomixClient().getResource("test", AtomixConsistentMap.class).join(); | 113 | + AtomixConsistentMap map = createAtomixClient().getResource("testBasicMapOperationMap", |
114 | + AtomixConsistentMap.class).join(); | ||
107 | 115 | ||
108 | map.isEmpty().thenAccept(result -> { | 116 | map.isEmpty().thenAccept(result -> { |
109 | assertTrue(result); | 117 | assertTrue(result); |
... | @@ -228,12 +236,12 @@ public class AtomixConsistentMapTest extends AtomixTestBase { | ... | @@ -228,12 +236,12 @@ public class AtomixConsistentMapTest extends AtomixTestBase { |
228 | } | 236 | } |
229 | 237 | ||
230 | public void mapComputeOperationTests(int clusterSize) throws Throwable { | 238 | public void mapComputeOperationTests(int clusterSize) throws Throwable { |
231 | - createCopycatServers(clusterSize); | ||
232 | final byte[] value1 = Tools.getBytesUtf8("value1"); | 239 | final byte[] value1 = Tools.getBytesUtf8("value1"); |
233 | final byte[] value2 = Tools.getBytesUtf8("value2"); | 240 | final byte[] value2 = Tools.getBytesUtf8("value2"); |
234 | final byte[] value3 = Tools.getBytesUtf8("value3"); | 241 | final byte[] value3 = Tools.getBytesUtf8("value3"); |
235 | 242 | ||
236 | - AtomixConsistentMap map = createAtomixClient().getResource("test", AtomixConsistentMap.class).join(); | 243 | + AtomixConsistentMap map = createAtomixClient().getResource("testMapComputeOperationsMap", |
244 | + AtomixConsistentMap.class).join(); | ||
237 | 245 | ||
238 | map.computeIfAbsent("foo", k -> value1).thenAccept(result -> { | 246 | map.computeIfAbsent("foo", k -> value1).thenAccept(result -> { |
239 | assertTrue(Arrays.equals(Versioned.valueOrElse(result, null), value1)); | 247 | assertTrue(Arrays.equals(Versioned.valueOrElse(result, null), value1)); |
... | @@ -266,12 +274,12 @@ public class AtomixConsistentMapTest extends AtomixTestBase { | ... | @@ -266,12 +274,12 @@ public class AtomixConsistentMapTest extends AtomixTestBase { |
266 | 274 | ||
267 | 275 | ||
268 | protected void mapListenerTests(int clusterSize) throws Throwable { | 276 | protected void mapListenerTests(int clusterSize) throws Throwable { |
269 | - createCopycatServers(clusterSize); | ||
270 | final byte[] value1 = Tools.getBytesUtf8("value1"); | 277 | final byte[] value1 = Tools.getBytesUtf8("value1"); |
271 | final byte[] value2 = Tools.getBytesUtf8("value2"); | 278 | final byte[] value2 = Tools.getBytesUtf8("value2"); |
272 | final byte[] value3 = Tools.getBytesUtf8("value3"); | 279 | final byte[] value3 = Tools.getBytesUtf8("value3"); |
273 | 280 | ||
274 | - AtomixConsistentMap map = createAtomixClient().getResource("test", AtomixConsistentMap.class).join(); | 281 | + AtomixConsistentMap map = createAtomixClient().getResource("testMapListenerMap", |
282 | + AtomixConsistentMap.class).join(); | ||
275 | TestMapEventListener listener = new TestMapEventListener(); | 283 | TestMapEventListener listener = new TestMapEventListener(); |
276 | 284 | ||
277 | // add listener; insert new value into map and verify an INSERT event is received. | 285 | // add listener; insert new value into map and verify an INSERT event is received. |
... | @@ -326,11 +334,11 @@ public class AtomixConsistentMapTest extends AtomixTestBase { | ... | @@ -326,11 +334,11 @@ public class AtomixConsistentMapTest extends AtomixTestBase { |
326 | } | 334 | } |
327 | 335 | ||
328 | protected void transactionCommitTests(int clusterSize) throws Throwable { | 336 | protected void transactionCommitTests(int clusterSize) throws Throwable { |
329 | - createCopycatServers(clusterSize); | ||
330 | final byte[] value1 = Tools.getBytesUtf8("value1"); | 337 | final byte[] value1 = Tools.getBytesUtf8("value1"); |
331 | final byte[] value2 = Tools.getBytesUtf8("value2"); | 338 | final byte[] value2 = Tools.getBytesUtf8("value2"); |
332 | 339 | ||
333 | - AtomixConsistentMap map = createAtomixClient().getResource("test", AtomixConsistentMap.class).join(); | 340 | + AtomixConsistentMap map = createAtomixClient().getResource("testCommitTestsMap", |
341 | + AtomixConsistentMap.class).join(); | ||
334 | TestMapEventListener listener = new TestMapEventListener(); | 342 | TestMapEventListener listener = new TestMapEventListener(); |
335 | 343 | ||
336 | map.addListener(listener).join(); | 344 | map.addListener(listener).join(); |
... | @@ -421,11 +429,11 @@ public class AtomixConsistentMapTest extends AtomixTestBase { | ... | @@ -421,11 +429,11 @@ public class AtomixConsistentMapTest extends AtomixTestBase { |
421 | } | 429 | } |
422 | 430 | ||
423 | protected void transactionRollbackTests(int clusterSize) throws Throwable { | 431 | protected void transactionRollbackTests(int clusterSize) throws Throwable { |
424 | - createCopycatServers(clusterSize); | ||
425 | final byte[] value1 = Tools.getBytesUtf8("value1"); | 432 | final byte[] value1 = Tools.getBytesUtf8("value1"); |
426 | final byte[] value2 = Tools.getBytesUtf8("value2"); | 433 | final byte[] value2 = Tools.getBytesUtf8("value2"); |
427 | 434 | ||
428 | - AtomixConsistentMap map = createAtomixClient().getResource("test", AtomixConsistentMap.class).join(); | 435 | + AtomixConsistentMap map = createAtomixClient().getResource("testTransactionRollbackTestsMap", |
436 | + AtomixConsistentMap.class).join(); | ||
429 | TestMapEventListener listener = new TestMapEventListener(); | 437 | TestMapEventListener listener = new TestMapEventListener(); |
430 | 438 | ||
431 | map.addListener(listener).join(); | 439 | map.addListener(listener).join(); | ... | ... |
... | @@ -20,7 +20,8 @@ import java.util.Queue; | ... | @@ -20,7 +20,8 @@ import java.util.Queue; |
20 | import java.util.concurrent.CompletableFuture; | 20 | import java.util.concurrent.CompletableFuture; |
21 | import java.util.function.Consumer; | 21 | import java.util.function.Consumer; |
22 | 22 | ||
23 | -import org.junit.Ignore; | 23 | +import org.junit.AfterClass; |
24 | +import org.junit.BeforeClass; | ||
24 | import org.junit.Test; | 25 | import org.junit.Test; |
25 | 26 | ||
26 | import static org.junit.Assert.*; | 27 | import static org.junit.Assert.*; |
... | @@ -36,13 +37,22 @@ import io.atomix.resource.ResourceType; | ... | @@ -36,13 +37,22 @@ import io.atomix.resource.ResourceType; |
36 | /** | 37 | /** |
37 | * Unit tests for {@link AtomixLeaderElector}. | 38 | * Unit tests for {@link AtomixLeaderElector}. |
38 | */ | 39 | */ |
39 | -@Ignore | ||
40 | public class AtomixLeaderElectorTest extends AtomixTestBase { | 40 | public class AtomixLeaderElectorTest extends AtomixTestBase { |
41 | 41 | ||
42 | NodeId node1 = new NodeId("node1"); | 42 | NodeId node1 = new NodeId("node1"); |
43 | NodeId node2 = new NodeId("node2"); | 43 | NodeId node2 = new NodeId("node2"); |
44 | NodeId node3 = new NodeId("node3"); | 44 | NodeId node3 = new NodeId("node3"); |
45 | 45 | ||
46 | + @BeforeClass | ||
47 | + public static void preTestSetup() throws Throwable { | ||
48 | + createCopycatServers(3); | ||
49 | + } | ||
50 | + | ||
51 | + @AfterClass | ||
52 | + public static void postTestCleanup() throws Exception { | ||
53 | + clearTests(); | ||
54 | + } | ||
55 | + | ||
46 | @Override | 56 | @Override |
47 | protected ResourceType resourceType() { | 57 | protected ResourceType resourceType() { |
48 | return new ResourceType(AtomixLeaderElector.class); | 58 | return new ResourceType(AtomixLeaderElector.class); |
... | @@ -54,9 +64,9 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -54,9 +64,9 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
54 | } | 64 | } |
55 | 65 | ||
56 | private void leaderElectorRunTests(int numServers) throws Throwable { | 66 | private void leaderElectorRunTests(int numServers) throws Throwable { |
57 | - createCopycatServers(numServers); | ||
58 | Atomix client1 = createAtomixClient(); | 67 | Atomix client1 = createAtomixClient(); |
59 | - AtomixLeaderElector elector1 = client1.getResource("test-elector", AtomixLeaderElector.class).join(); | 68 | + AtomixLeaderElector elector1 = client1.getResource("test-elector-run", |
69 | + AtomixLeaderElector.class).join(); | ||
60 | elector1.run("foo", node1).thenAccept(result -> { | 70 | elector1.run("foo", node1).thenAccept(result -> { |
61 | assertEquals(node1, result.leaderNodeId()); | 71 | assertEquals(node1, result.leaderNodeId()); |
62 | assertEquals(1, result.leader().term()); | 72 | assertEquals(1, result.leader().term()); |
... | @@ -64,7 +74,8 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -64,7 +74,8 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
64 | assertEquals(node1, result.candidates().get(0)); | 74 | assertEquals(node1, result.candidates().get(0)); |
65 | }).join(); | 75 | }).join(); |
66 | Atomix client2 = createAtomixClient(); | 76 | Atomix client2 = createAtomixClient(); |
67 | - AtomixLeaderElector elector2 = client2.getResource("test-elector", AtomixLeaderElector.class).join(); | 77 | + AtomixLeaderElector elector2 = client2.getResource("test-elector-run", |
78 | + AtomixLeaderElector.class).join(); | ||
68 | elector2.run("foo", node2).thenAccept(result -> { | 79 | elector2.run("foo", node2).thenAccept(result -> { |
69 | assertEquals(node1, result.leaderNodeId()); | 80 | assertEquals(node1, result.leaderNodeId()); |
70 | assertEquals(1, result.leader().term()); | 81 | assertEquals(1, result.leader().term()); |
... | @@ -80,12 +91,13 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -80,12 +91,13 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
80 | } | 91 | } |
81 | 92 | ||
82 | private void leaderElectorWithdrawTests(int numServers) throws Throwable { | 93 | private void leaderElectorWithdrawTests(int numServers) throws Throwable { |
83 | - createCopycatServers(numServers); | ||
84 | Atomix client1 = createAtomixClient(); | 94 | Atomix client1 = createAtomixClient(); |
85 | - AtomixLeaderElector elector1 = client1.getResource("test-elector", AtomixLeaderElector.class).join(); | 95 | + AtomixLeaderElector elector1 = client1.getResource("test-elector-withdraw", |
96 | + AtomixLeaderElector.class).join(); | ||
86 | elector1.run("foo", node1).join(); | 97 | elector1.run("foo", node1).join(); |
87 | Atomix client2 = createAtomixClient(); | 98 | Atomix client2 = createAtomixClient(); |
88 | - AtomixLeaderElector elector2 = client2.getResource("test-elector", AtomixLeaderElector.class).join(); | 99 | + AtomixLeaderElector elector2 = client2.getResource("test-elector-withdraw", |
100 | + AtomixLeaderElector.class).join(); | ||
89 | elector2.run("foo", node2).join(); | 101 | elector2.run("foo", node2).join(); |
90 | 102 | ||
91 | LeaderEventListener listener1 = new LeaderEventListener(); | 103 | LeaderEventListener listener1 = new LeaderEventListener(); |
... | @@ -117,13 +129,15 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -117,13 +129,15 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
117 | } | 129 | } |
118 | 130 | ||
119 | private void leaderElectorAnointTests(int numServers) throws Throwable { | 131 | private void leaderElectorAnointTests(int numServers) throws Throwable { |
120 | - createCopycatServers(numServers); | ||
121 | Atomix client1 = createAtomixClient(); | 132 | Atomix client1 = createAtomixClient(); |
122 | - AtomixLeaderElector elector1 = client1.getResource("test-elector", AtomixLeaderElector.class).join(); | 133 | + AtomixLeaderElector elector1 = client1.getResource("test-elector-anoint", |
134 | + AtomixLeaderElector.class).join(); | ||
123 | Atomix client2 = createAtomixClient(); | 135 | Atomix client2 = createAtomixClient(); |
124 | - AtomixLeaderElector elector2 = client2.getResource("test-elector", AtomixLeaderElector.class).join(); | 136 | + AtomixLeaderElector elector2 = client2.getResource("test-elector-anoint", |
137 | + AtomixLeaderElector.class).join(); | ||
125 | Atomix client3 = createAtomixClient(); | 138 | Atomix client3 = createAtomixClient(); |
126 | - AtomixLeaderElector elector3 = client3.getResource("test-elector", AtomixLeaderElector.class).join(); | 139 | + AtomixLeaderElector elector3 = client3.getResource("test-elector-anoint", |
140 | + AtomixLeaderElector.class).join(); | ||
127 | elector1.run("foo", node1).join(); | 141 | elector1.run("foo", node1).join(); |
128 | elector2.run("foo", node2).join(); | 142 | elector2.run("foo", node2).join(); |
129 | 143 | ||
... | @@ -171,13 +185,15 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -171,13 +185,15 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
171 | } | 185 | } |
172 | 186 | ||
173 | private void leaderElectorPromoteTests(int numServers) throws Throwable { | 187 | private void leaderElectorPromoteTests(int numServers) throws Throwable { |
174 | - createCopycatServers(numServers); | ||
175 | AtomixClient client1 = createAtomixClient(); | 188 | AtomixClient client1 = createAtomixClient(); |
176 | - AtomixLeaderElector elector1 = client1.getResource("test-elector", AtomixLeaderElector.class).join(); | 189 | + AtomixLeaderElector elector1 = client1.getResource("test-elector-promote", |
190 | + AtomixLeaderElector.class).join(); | ||
177 | AtomixClient client2 = createAtomixClient(); | 191 | AtomixClient client2 = createAtomixClient(); |
178 | - AtomixLeaderElector elector2 = client2.getResource("test-elector", AtomixLeaderElector.class).join(); | 192 | + AtomixLeaderElector elector2 = client2.getResource("test-elector-promote", |
193 | + AtomixLeaderElector.class).join(); | ||
179 | AtomixClient client3 = createAtomixClient(); | 194 | AtomixClient client3 = createAtomixClient(); |
180 | - AtomixLeaderElector elector3 = client3.getResource("test-elector", AtomixLeaderElector.class).join(); | 195 | + AtomixLeaderElector elector3 = client3.getResource("test-elector-promote", |
196 | + AtomixLeaderElector.class).join(); | ||
181 | elector1.run("foo", node1).join(); | 197 | elector1.run("foo", node1).join(); |
182 | elector2.run("foo", node2).join(); | 198 | elector2.run("foo", node2).join(); |
183 | 199 | ||
... | @@ -229,12 +245,13 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -229,12 +245,13 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
229 | } | 245 | } |
230 | 246 | ||
231 | private void leaderElectorLeaderSessionCloseTests(int numServers) throws Throwable { | 247 | private void leaderElectorLeaderSessionCloseTests(int numServers) throws Throwable { |
232 | - createCopycatServers(numServers); | ||
233 | AtomixClient client1 = createAtomixClient(); | 248 | AtomixClient client1 = createAtomixClient(); |
234 | - AtomixLeaderElector elector1 = client1.getResource("test-elector", AtomixLeaderElector.class).join(); | 249 | + AtomixLeaderElector elector1 = client1.getResource("test-elector-leader-session-close", |
250 | + AtomixLeaderElector.class).join(); | ||
235 | elector1.run("foo", node1).join(); | 251 | elector1.run("foo", node1).join(); |
236 | Atomix client2 = createAtomixClient(); | 252 | Atomix client2 = createAtomixClient(); |
237 | - AtomixLeaderElector elector2 = client2.getResource("test-elector", AtomixLeaderElector.class).join(); | 253 | + AtomixLeaderElector elector2 = client2.getResource("test-elector-leader-session-close", |
254 | + AtomixLeaderElector.class).join(); | ||
238 | LeaderEventListener listener = new LeaderEventListener(); | 255 | LeaderEventListener listener = new LeaderEventListener(); |
239 | elector2.run("foo", node2).join(); | 256 | elector2.run("foo", node2).join(); |
240 | elector2.addChangeListener(listener).join(); | 257 | elector2.addChangeListener(listener).join(); |
... | @@ -252,12 +269,13 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -252,12 +269,13 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
252 | } | 269 | } |
253 | 270 | ||
254 | private void leaderElectorNonLeaderSessionCloseTests(int numServers) throws Throwable { | 271 | private void leaderElectorNonLeaderSessionCloseTests(int numServers) throws Throwable { |
255 | - createCopycatServers(numServers); | ||
256 | Atomix client1 = createAtomixClient(); | 272 | Atomix client1 = createAtomixClient(); |
257 | - AtomixLeaderElector elector1 = client1.getResource("test-elector", AtomixLeaderElector.class).join(); | 273 | + AtomixLeaderElector elector1 = client1.getResource("test-elector-non-leader-session-close", |
274 | + AtomixLeaderElector.class).join(); | ||
258 | elector1.run("foo", node1).join(); | 275 | elector1.run("foo", node1).join(); |
259 | AtomixClient client2 = createAtomixClient(); | 276 | AtomixClient client2 = createAtomixClient(); |
260 | - AtomixLeaderElector elector2 = client2.getResource("test-elector", AtomixLeaderElector.class).join(); | 277 | + AtomixLeaderElector elector2 = client2.getResource("test-elector-non-leader-session-close", |
278 | + AtomixLeaderElector.class).join(); | ||
261 | LeaderEventListener listener = new LeaderEventListener(); | 279 | LeaderEventListener listener = new LeaderEventListener(); |
262 | elector2.run("foo", node2).join(); | 280 | elector2.run("foo", node2).join(); |
263 | elector1.addChangeListener(listener).join(); | 281 | elector1.addChangeListener(listener).join(); |
... | @@ -275,11 +293,12 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -275,11 +293,12 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
275 | } | 293 | } |
276 | 294 | ||
277 | private void leaderElectorQueryTests(int numServers) throws Throwable { | 295 | private void leaderElectorQueryTests(int numServers) throws Throwable { |
278 | - createCopycatServers(numServers); | ||
279 | Atomix client1 = createAtomixClient(); | 296 | Atomix client1 = createAtomixClient(); |
280 | Atomix client2 = createAtomixClient(); | 297 | Atomix client2 = createAtomixClient(); |
281 | - AtomixLeaderElector elector1 = client1.getResource("test-elector", AtomixLeaderElector.class).join(); | 298 | + AtomixLeaderElector elector1 = client1.getResource("test-elector-query", |
282 | - AtomixLeaderElector elector2 = client2.getResource("test-elector", AtomixLeaderElector.class).join(); | 299 | + AtomixLeaderElector.class).join(); |
300 | + AtomixLeaderElector elector2 = client2.getResource("test-elector-query", | ||
301 | + AtomixLeaderElector.class).join(); | ||
283 | elector1.run("foo", node1).join(); | 302 | elector1.run("foo", node1).join(); |
284 | elector2.run("foo", node2).join(); | 303 | elector2.run("foo", node2).join(); |
285 | elector2.run("bar", node2).join(); | 304 | elector2.run("bar", node2).join(); | ... | ... |
... | @@ -18,7 +18,8 @@ package org.onosproject.store.primitives.resources.impl; | ... | @@ -18,7 +18,8 @@ package org.onosproject.store.primitives.resources.impl; |
18 | import io.atomix.Atomix; | 18 | import io.atomix.Atomix; |
19 | import io.atomix.resource.ResourceType; | 19 | import io.atomix.resource.ResourceType; |
20 | import io.atomix.variables.DistributedLong; | 20 | import io.atomix.variables.DistributedLong; |
21 | -import org.junit.Ignore; | 21 | +import org.junit.AfterClass; |
22 | +import org.junit.BeforeClass; | ||
22 | import org.junit.Test; | 23 | import org.junit.Test; |
23 | 24 | ||
24 | import static org.junit.Assert.assertEquals; | 25 | import static org.junit.Assert.assertEquals; |
... | @@ -28,9 +29,18 @@ import static org.junit.Assert.assertTrue; | ... | @@ -28,9 +29,18 @@ import static org.junit.Assert.assertTrue; |
28 | /**git s | 29 | /**git s |
29 | * Unit tests for {@link AtomixCounter}. | 30 | * Unit tests for {@link AtomixCounter}. |
30 | */ | 31 | */ |
31 | -@Ignore | ||
32 | public class AtomixLongTest extends AtomixTestBase { | 32 | public class AtomixLongTest extends AtomixTestBase { |
33 | 33 | ||
34 | + @BeforeClass | ||
35 | + public static void preTestSetup() throws Throwable { | ||
36 | + createCopycatServers(3); | ||
37 | + } | ||
38 | + | ||
39 | + @AfterClass | ||
40 | + public static void postTestCleanup() throws Exception { | ||
41 | + clearTests(); | ||
42 | + } | ||
43 | + | ||
34 | @Override | 44 | @Override |
35 | protected ResourceType resourceType() { | 45 | protected ResourceType resourceType() { |
36 | return new ResourceType(DistributedLong.class); | 46 | return new ResourceType(DistributedLong.class); |
... | @@ -42,9 +52,9 @@ public class AtomixLongTest extends AtomixTestBase { | ... | @@ -42,9 +52,9 @@ public class AtomixLongTest extends AtomixTestBase { |
42 | } | 52 | } |
43 | 53 | ||
44 | protected void basicOperationsTest(int clusterSize) throws Throwable { | 54 | protected void basicOperationsTest(int clusterSize) throws Throwable { |
45 | - createCopycatServers(clusterSize); | ||
46 | Atomix atomix = createAtomixClient(); | 55 | Atomix atomix = createAtomixClient(); |
47 | - AtomixCounter along = new AtomixCounter("test-long", atomix.getLong("test-long").join()); | 56 | + AtomixCounter along = new AtomixCounter("test-long-basic-operations", |
57 | + atomix.getLong("test-long").join()); | ||
48 | assertEquals(0, along.get().join().longValue()); | 58 | assertEquals(0, along.get().join().longValue()); |
49 | assertEquals(1, along.incrementAndGet().join().longValue()); | 59 | assertEquals(1, along.incrementAndGet().join().longValue()); |
50 | along.set(100).join(); | 60 | along.set(100).join(); | ... | ... |
... | @@ -27,8 +27,6 @@ import io.atomix.copycat.server.storage.Storage; | ... | @@ -27,8 +27,6 @@ import io.atomix.copycat.server.storage.Storage; |
27 | import io.atomix.copycat.server.storage.StorageLevel; | 27 | import io.atomix.copycat.server.storage.StorageLevel; |
28 | import io.atomix.manager.internal.ResourceManagerState; | 28 | import io.atomix.manager.internal.ResourceManagerState; |
29 | import io.atomix.resource.ResourceType; | 29 | import io.atomix.resource.ResourceType; |
30 | -import org.junit.After; | ||
31 | -import org.junit.Before; | ||
32 | import org.onlab.junit.TestTools; | 30 | import org.onlab.junit.TestTools; |
33 | import org.onosproject.store.primitives.impl.CatalystSerializers; | 31 | import org.onosproject.store.primitives.impl.CatalystSerializers; |
34 | 32 | ||
... | @@ -43,18 +41,18 @@ import java.util.concurrent.CountDownLatch; | ... | @@ -43,18 +41,18 @@ import java.util.concurrent.CountDownLatch; |
43 | import java.util.concurrent.atomic.AtomicInteger; | 41 | import java.util.concurrent.atomic.AtomicInteger; |
44 | 42 | ||
45 | /** | 43 | /** |
46 | - * Base class for various Atomix* tests. | 44 | + * Base class for various Atomix tests. |
47 | */ | 45 | */ |
48 | public abstract class AtomixTestBase { | 46 | public abstract class AtomixTestBase { |
49 | - private static final File TEST_DIR = new File("target/test-logs"); | 47 | + protected static File testDir; |
50 | - protected LocalServerRegistry registry; | 48 | + protected static LocalServerRegistry registry = new LocalServerRegistry(); |
51 | - protected final AtomicInteger port = new AtomicInteger(49200); | 49 | + protected static List<Address> members = new ArrayList<>(); |
52 | - protected List<Address> members; | 50 | + protected static List<CopycatClient> copycatClients = new ArrayList<>(); |
53 | - protected List<CopycatClient> copycatClients = new ArrayList<>(); | 51 | + protected static List<CopycatServer> copycatServers = new ArrayList<>(); |
54 | - protected List<CopycatServer> copycatServers = new ArrayList<>(); | 52 | + protected static List<AtomixClient> atomixClients = new ArrayList<>(); |
55 | - protected List<AtomixClient> atomixClients = new ArrayList<>(); | 53 | + protected static List<CopycatServer> atomixServers = new ArrayList<>(); |
56 | - protected List<CopycatServer> atomixServers = new ArrayList<>(); | 54 | + protected static Serializer serializer = CatalystSerializers.getSerializer(); |
57 | - protected Serializer serializer = CatalystSerializers.getSerializer(); | 55 | + protected static AtomicInteger port = new AtomicInteger(49200); |
58 | 56 | ||
59 | /** | 57 | /** |
60 | * Creates a new resource state machine. | 58 | * Creates a new resource state machine. |
... | @@ -68,7 +66,7 @@ public abstract class AtomixTestBase { | ... | @@ -68,7 +66,7 @@ public abstract class AtomixTestBase { |
68 | * | 66 | * |
69 | * @return The next server address. | 67 | * @return The next server address. |
70 | */ | 68 | */ |
71 | - private Address nextAddress() { | 69 | + private static Address nextAddress() { |
72 | Address address = new Address("127.0.0.1", | 70 | Address address = new Address("127.0.0.1", |
73 | TestTools.findAvailablePort(port.getAndIncrement())); | 71 | TestTools.findAvailablePort(port.getAndIncrement())); |
74 | members.add(address); | 72 | members.add(address); |
... | @@ -78,7 +76,8 @@ public abstract class AtomixTestBase { | ... | @@ -78,7 +76,8 @@ public abstract class AtomixTestBase { |
78 | /** | 76 | /** |
79 | * Creates a set of Copycat servers. | 77 | * Creates a set of Copycat servers. |
80 | */ | 78 | */ |
81 | - protected List<CopycatServer> createCopycatServers(int nodes) throws Throwable { | 79 | + protected static List<CopycatServer> createCopycatServers(int nodes) |
80 | + throws Throwable { | ||
82 | CountDownLatch latch = new CountDownLatch(nodes); | 81 | CountDownLatch latch = new CountDownLatch(nodes); |
83 | List<CopycatServer> servers = new ArrayList<>(); | 82 | List<CopycatServer> servers = new ArrayList<>(); |
84 | 83 | ||
... | @@ -91,20 +90,18 @@ public abstract class AtomixTestBase { | ... | @@ -91,20 +90,18 @@ public abstract class AtomixTestBase { |
91 | if (members.size() <= 1) { | 90 | if (members.size() <= 1) { |
92 | server.bootstrap().thenRun(latch::countDown).join(); | 91 | server.bootstrap().thenRun(latch::countDown).join(); |
93 | } else { | 92 | } else { |
94 | - server.join(members).thenRun(latch::countDown); | 93 | + server.join(members).join(); |
95 | } | 94 | } |
96 | servers.add(server); | 95 | servers.add(server); |
97 | } | 96 | } |
98 | 97 | ||
99 | - Uninterruptibles.awaitUninterruptibly(latch); | ||
100 | - | ||
101 | return servers; | 98 | return servers; |
102 | } | 99 | } |
103 | 100 | ||
104 | /** | 101 | /** |
105 | * Creates a Copycat server. | 102 | * Creates a Copycat server. |
106 | */ | 103 | */ |
107 | - protected CopycatServer createCopycatServer(Address address) { | 104 | + protected static CopycatServer createCopycatServer(Address address) { |
108 | CopycatServer server = CopycatServer.builder(address) | 105 | CopycatServer server = CopycatServer.builder(address) |
109 | .withTransport(NettyTransport.builder().withThreads(1).build()) | 106 | .withTransport(NettyTransport.builder().withThreads(1).build()) |
110 | .withStorage(Storage.builder() | 107 | .withStorage(Storage.builder() |
... | @@ -120,23 +117,21 @@ public abstract class AtomixTestBase { | ... | @@ -120,23 +117,21 @@ public abstract class AtomixTestBase { |
120 | return server; | 117 | return server; |
121 | } | 118 | } |
122 | 119 | ||
123 | - @Before | 120 | + public static void clearTests() throws Exception { |
124 | - @After | ||
125 | - public void clearTests() throws Exception { | ||
126 | registry = new LocalServerRegistry(); | 121 | registry = new LocalServerRegistry(); |
127 | members = new ArrayList<>(); | 122 | members = new ArrayList<>(); |
128 | 123 | ||
129 | CompletableFuture<Void> closeClients = | 124 | CompletableFuture<Void> closeClients = |
130 | CompletableFuture.allOf(atomixClients.stream() | 125 | CompletableFuture.allOf(atomixClients.stream() |
131 | - .map(AtomixClient::close) | 126 | + .map(AtomixClient::close) |
132 | - .toArray(CompletableFuture[]::new)); | 127 | + .toArray(CompletableFuture[]::new)); |
133 | 128 | ||
134 | - closeClients.thenCompose(v -> CompletableFuture.allOf(copycatServers.stream() | 129 | + closeClients |
130 | + .thenCompose(v -> CompletableFuture | ||
131 | + .allOf(copycatServers.stream() | ||
135 | .map(CopycatServer::shutdown) | 132 | .map(CopycatServer::shutdown) |
136 | .toArray(CompletableFuture[]::new))).join(); | 133 | .toArray(CompletableFuture[]::new))).join(); |
137 | 134 | ||
138 | - deleteDirectory(TEST_DIR); | ||
139 | - | ||
140 | atomixClients = new ArrayList<>(); | 135 | atomixClients = new ArrayList<>(); |
141 | 136 | ||
142 | copycatServers = new ArrayList<>(); | 137 | copycatServers = new ArrayList<>(); | ... | ... |
-
Please register or login to post a comment