From cb43720a940ee174d83567663193addb27f04907 Mon Sep 17 00:00:00 2001 From: Jordan Halterman Date: Sun, 17 Dec 2017 15:35:00 -0800 Subject: [PATCH] Start test instances in AbstractAtomixTest --- .../java/io/atomix/AbstractAtomixTest.java | 28 +++++++------------ .../io/atomix/queue/impl/WorkQueueTest.java | 4 +-- .../io/atomix/tree/impl/DocumentTreeTest.java | 6 ++-- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/core/src/test/java/io/atomix/AbstractAtomixTest.java b/core/src/test/java/io/atomix/AbstractAtomixTest.java index 7067663497..58fcf0e84b 100644 --- a/core/src/test/java/io/atomix/AbstractAtomixTest.java +++ b/core/src/test/java/io/atomix/AbstractAtomixTest.java @@ -46,6 +46,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -64,8 +65,8 @@ public abstract class AbstractAtomixTest { * * @return a new Atomix instance. */ - protected Atomix atomix() { - Atomix instance = createAtomix(Node.Type.CLIENT, id++, 1, 2, 3).join(); + protected Atomix atomix() throws Exception { + Atomix instance = createAtomix(Node.Type.CLIENT, id++, 1, 2, 3).start().get(10, TimeUnit.SECONDS); instances.add(instance); return instance; } @@ -76,26 +77,17 @@ public static void setupAtomix() throws Exception { messagingServiceFactory = new TestMessagingServiceFactory(); endpoints = new HashMap<>(); instances = new ArrayList<>(); - List> futures = new ArrayList<>(); - futures.add(createAtomix(Node.Type.DATA, 1, 1, 2, 3).thenApply(instance -> { - instances.add(instance); - return instance; - })); - futures.add(createAtomix(Node.Type.DATA, 2, 1, 2, 3).thenApply(instance -> { - instances.add(instance); - return instance; - })); - futures.add(createAtomix(Node.Type.DATA, 3, 1, 2, 3).thenApply(instance -> { - instances.add(instance); - return instance; - })); - CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).join(); + instances.add(createAtomix(Node.Type.DATA, 1, 1, 2, 3)); + instances.add(createAtomix(Node.Type.DATA, 2, 1, 2, 3)); + instances.add(createAtomix(Node.Type.DATA, 3, 1, 2, 3)); + List> futures = instances.stream().map(Atomix::start).collect(Collectors.toList()); + CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).get(30, TimeUnit.SECONDS); } /** * Creates an Atomix instance. */ - private static CompletableFuture createAtomix(Node.Type type, int id, Integer... ids) { + private static Atomix createAtomix(Node.Type type, int id, Integer... ids) { Node localNode = Node.builder(String.valueOf(id)) .withType(type) .withEndpoint(endpoints.computeIfAbsent(id, i -> Endpoint.from("localhost", BASE_PORT + id))) @@ -114,7 +106,7 @@ private static CompletableFuture createAtomix(Node.Type type, int id, In .withLocalNode(localNode) .withBootstrapNodes(bootstrapNodes) .withDataPartitions(3) // Lower number of partitions for faster testing - .buildAsync(); + .build(); } @AfterClass diff --git a/core/src/test/java/io/atomix/queue/impl/WorkQueueTest.java b/core/src/test/java/io/atomix/queue/impl/WorkQueueTest.java index 82ae1c779a..fa205e1279 100644 --- a/core/src/test/java/io/atomix/queue/impl/WorkQueueTest.java +++ b/core/src/test/java/io/atomix/queue/impl/WorkQueueTest.java @@ -157,7 +157,7 @@ public void testAutomaticTaskProcessing() throws Throwable { } @Test - public void testDestroy() { + public void testDestroy() throws Exception { String queueName = UUID.randomUUID().toString(); AsyncWorkQueue queue1 = atomix().workQueueBuilder(queueName).build().async(); String item = DEFAULT_PAYLOAD; @@ -181,7 +181,7 @@ public void testDestroy() { } @Test - public void testCompleteAttemptWithIncorrectSession() { + public void testCompleteAttemptWithIncorrectSession() throws Exception { String queueName = UUID.randomUUID().toString(); AsyncWorkQueue queue1 = atomix().workQueueBuilder(queueName).build().async(); String item = DEFAULT_PAYLOAD; diff --git a/core/src/test/java/io/atomix/tree/impl/DocumentTreeTest.java b/core/src/test/java/io/atomix/tree/impl/DocumentTreeTest.java index b0bab226c5..f4e258f446 100644 --- a/core/src/test/java/io/atomix/tree/impl/DocumentTreeTest.java +++ b/core/src/test/java/io/atomix/tree/impl/DocumentTreeTest.java @@ -46,11 +46,11 @@ */ public class DocumentTreeTest extends AbstractAtomixTest { - protected AsyncDocumentTree newTree(String name) { + protected AsyncDocumentTree newTree(String name) throws Exception { return newTree(name, null); } - protected AsyncDocumentTree newTree(String name, Ordering ordering) { + protected AsyncDocumentTree newTree(String name, Ordering ordering) throws Exception { return atomix().documentTreeBuilder(name) .withOrdering(ordering) .withMaxRetries(5) @@ -325,7 +325,7 @@ public void testGetChildren() throws Throwable { * Tests destroy. */ @Test - public void testClear() { + public void testClear() throws Exception { AsyncDocumentTree tree = newTree(UUID.randomUUID().toString()); tree.create(path("root.a"), "a").join(); tree.create(path("root.a.b"), "ab").join();