Skip to content

Commit

Permalink
Start test instances in AbstractAtomixTest
Browse files Browse the repository at this point in the history
  • Loading branch information
kuujo committed Dec 17, 2017
1 parent d42c32c commit cb43720
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
28 changes: 10 additions & 18 deletions core/src/test/java/io/atomix/AbstractAtomixTest.java
Expand Up @@ -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;

Expand All @@ -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;
}
Expand All @@ -76,26 +77,17 @@ public static void setupAtomix() throws Exception {
messagingServiceFactory = new TestMessagingServiceFactory();
endpoints = new HashMap<>();
instances = new ArrayList<>();
List<CompletableFuture<Atomix>> 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<CompletableFuture<Atomix>> 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<Atomix> 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)))
Expand All @@ -114,7 +106,7 @@ private static CompletableFuture<Atomix> createAtomix(Node.Type type, int id, In
.withLocalNode(localNode)
.withBootstrapNodes(bootstrapNodes)
.withDataPartitions(3) // Lower number of partitions for faster testing
.buildAsync();
.build();
}

@AfterClass
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/io/atomix/queue/impl/WorkQueueTest.java
Expand Up @@ -157,7 +157,7 @@ public void testAutomaticTaskProcessing() throws Throwable {
}

@Test
public void testDestroy() {
public void testDestroy() throws Exception {
String queueName = UUID.randomUUID().toString();
AsyncWorkQueue<String> queue1 = atomix().<String>workQueueBuilder(queueName).build().async();
String item = DEFAULT_PAYLOAD;
Expand All @@ -181,7 +181,7 @@ public void testDestroy() {
}

@Test
public void testCompleteAttemptWithIncorrectSession() {
public void testCompleteAttemptWithIncorrectSession() throws Exception {
String queueName = UUID.randomUUID().toString();
AsyncWorkQueue<String> queue1 = atomix().<String>workQueueBuilder(queueName).build().async();
String item = DEFAULT_PAYLOAD;
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/java/io/atomix/tree/impl/DocumentTreeTest.java
Expand Up @@ -46,11 +46,11 @@
*/
public class DocumentTreeTest extends AbstractAtomixTest {

protected AsyncDocumentTree<String> newTree(String name) {
protected AsyncDocumentTree<String> newTree(String name) throws Exception {
return newTree(name, null);
}

protected AsyncDocumentTree<String> newTree(String name, Ordering ordering) {
protected AsyncDocumentTree<String> newTree(String name, Ordering ordering) throws Exception {
return atomix().<String>documentTreeBuilder(name)
.withOrdering(ordering)
.withMaxRetries(5)
Expand Down Expand Up @@ -325,7 +325,7 @@ public void testGetChildren() throws Throwable {
* Tests destroy.
*/
@Test
public void testClear() {
public void testClear() throws Exception {
AsyncDocumentTree<String> tree = newTree(UUID.randomUUID().toString());
tree.create(path("root.a"), "a").join();
tree.create(path("root.a.b"), "ab").join();
Expand Down

0 comments on commit cb43720

Please sign in to comment.