Skip to content

Commit

Permalink
Refactored some testing stuff to base classes.
Browse files Browse the repository at this point in the history
Added timeouts for numerous await calls in tests.
  • Loading branch information
jhalterman committed Dec 15, 2015
1 parent b606485 commit 7cccfb8
Show file tree
Hide file tree
Showing 30 changed files with 519 additions and 568 deletions.
154 changes: 0 additions & 154 deletions all/src/test/java/io/atomix/AbstractAtomixTest.java

This file was deleted.

Expand Up @@ -17,8 +17,11 @@


import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;


import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; import org.testng.annotations.Test;


import io.atomix.atomix.testing.AbstractAtomixTest;
import io.atomix.copycat.client.Command; import io.atomix.copycat.client.Command;
import io.atomix.copycat.client.CopycatClient; import io.atomix.copycat.client.CopycatClient;
import io.atomix.copycat.client.Query; import io.atomix.copycat.client.Query;
Expand All @@ -35,7 +38,16 @@
* @author <a href="http://github.com/kuujo>Jordan Halterman</a> * @author <a href="http://github.com/kuujo>Jordan Halterman</a>
*/ */
@Test @Test
public class AtomixClientServerTest extends AbstractServerTest { public class AtomixClientServerTest extends AbstractAtomixTest {
@BeforeMethod
protected void beforeMethod() {
init();
}

@AfterMethod
protected void afterMethod() {
cleanup();
}


/** /**
* Tests submitting a command. * Tests submitting a command.
Expand Down Expand Up @@ -235,7 +247,7 @@ public void testGetResourceKeys() throws Throwable {
/** /**
* Test resource. * Test resource.
*/ */
@ResourceTypeInfo(id=1, stateMachine=TestStateMachine.class) @ResourceTypeInfo(id = 1, stateMachine = TestStateMachine.class)
public static class TestResource extends Resource { public static class TestResource extends Resource {
public static final ResourceType<TestResource> TYPE = new ResourceType<>(TestResource.class); public static final ResourceType<TestResource> TYPE = new ResourceType<>(TestResource.class);


Expand Down Expand Up @@ -309,7 +321,7 @@ public String value() {
/** /**
* Value resource. * Value resource.
*/ */
@ResourceTypeInfo(id=2, stateMachine=ValueStateMachine.class) @ResourceTypeInfo(id = 2, stateMachine = ValueStateMachine.class)
public static class ValueResource extends Resource { public static class ValueResource extends Resource {
public static final ResourceType<ValueResource> TYPE = new ResourceType<ValueResource>(ValueResource.class); public static final ResourceType<ValueResource> TYPE = new ResourceType<ValueResource>(ValueResource.class);


Expand Down
19 changes: 13 additions & 6 deletions all/src/test/java/io/atomix/AtomixLeaderElectionTest.java
Expand Up @@ -15,20 +15,27 @@
*/ */
package io.atomix; package io.atomix;


import io.atomix.coordination.DistributedLeaderElection;
import org.testng.annotations.Test;

import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function; import java.util.function.Function;


import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import io.atomix.atomix.testing.AbstractAtomixTest;
import io.atomix.coordination.DistributedLeaderElection;

/** /**
* Atomix leader election test. * Atomix leader election test.
* *
* @author <a href="http://github.com/kuujo>Jordan Halterman</a> * @author <a href="http://github.com/kuujo>Jordan Halterman</a>
*/ */
@Test @Test
public class AtomixLeaderElectionTest extends AbstractAtomixTest { public class AtomixLeaderElectionTest extends AbstractAtomixTest {

@BeforeClass
protected void setupCluster() throws Throwable {
createReplicas(5);
}

public void testClientLeaderElectionGet() throws Throwable { public void testClientLeaderElectionGet() throws Throwable {
Atomix client1 = createClient(); Atomix client1 = createClient();
Atomix client2 = createClient(); Atomix client2 = createClient();
Expand Down Expand Up @@ -63,7 +70,7 @@ private void testLeaderElection(Atomix client1, Atomix client2, Function<Atomix,
resume(); resume();
}).join(); }).join();


await(); await(10000);


election2.onElection(epoch -> { election2.onElection(epoch -> {
threadAssertTrue(epoch > lastEpoch.get()); threadAssertTrue(epoch > lastEpoch.get());
Expand All @@ -73,7 +80,7 @@ private void testLeaderElection(Atomix client1, Atomix client2, Function<Atomix,


client1.close(); client1.close();


await(); await(10000);
} }


} }
13 changes: 10 additions & 3 deletions all/src/test/java/io/atomix/AtomixLockTest.java
Expand Up @@ -15,10 +15,13 @@
*/ */
package io.atomix; package io.atomix;


import io.atomix.coordination.DistributedLock; import java.util.function.Function;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;


import java.util.function.Function; import io.atomix.atomix.testing.AbstractAtomixTest;
import io.atomix.coordination.DistributedLock;


/** /**
* Atomix lock test. * Atomix lock test.
Expand All @@ -27,7 +30,11 @@
*/ */
@Test @Test
public class AtomixLockTest extends AbstractAtomixTest { public class AtomixLockTest extends AbstractAtomixTest {

@BeforeClass
protected void setupCluster() throws Throwable {
createReplicas(5);
}

public void testClientLockGet() throws Throwable { public void testClientLockGet() throws Throwable {
Atomix client1 = createClient(); Atomix client1 = createClient();
Atomix client2 = createClient(); Atomix client2 = createClient();
Expand Down
13 changes: 10 additions & 3 deletions all/src/test/java/io/atomix/AtomixLongTest.java
Expand Up @@ -15,10 +15,13 @@
*/ */
package io.atomix; package io.atomix;


import io.atomix.variables.DistributedLong; import java.util.function.Function;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;


import java.util.function.Function; import io.atomix.atomix.testing.AbstractAtomixTest;
import io.atomix.variables.DistributedLong;


/** /**
* Atomix long test. * Atomix long test.
Expand All @@ -27,7 +30,11 @@
*/ */
@Test @Test
public class AtomixLongTest extends AbstractAtomixTest { public class AtomixLongTest extends AbstractAtomixTest {

@BeforeClass
protected void setupCluster() throws Throwable {
createReplicas(5);
}

public void testClientLongGet() throws Throwable { public void testClientLongGet() throws Throwable {
Atomix client1 = createClient(); Atomix client1 = createClient();
Atomix client2 = createClient(); Atomix client2 = createClient();
Expand Down
13 changes: 10 additions & 3 deletions all/src/test/java/io/atomix/AtomixMapTest.java
Expand Up @@ -15,10 +15,13 @@
*/ */
package io.atomix; package io.atomix;


import io.atomix.collections.DistributedMap; import java.util.function.Function;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;


import java.util.function.Function; import io.atomix.atomix.testing.AbstractAtomixTest;
import io.atomix.collections.DistributedMap;


/** /**
* Atomix map test. * Atomix map test.
Expand All @@ -27,7 +30,11 @@
*/ */
@Test @Test
public class AtomixMapTest extends AbstractAtomixTest { public class AtomixMapTest extends AbstractAtomixTest {

@BeforeClass
protected void setupCluster() throws Throwable {
createReplicas(5);
}

public void testClientMapGet() throws Throwable { public void testClientMapGet() throws Throwable {
Atomix client1 = createClient(); Atomix client1 = createClient();
Atomix client2 = createClient(); Atomix client2 = createClient();
Expand Down
13 changes: 10 additions & 3 deletions all/src/test/java/io/atomix/AtomixMembershipGroupTest.java
Expand Up @@ -15,10 +15,13 @@
*/ */
package io.atomix; package io.atomix;


import io.atomix.coordination.DistributedMembershipGroup; import java.util.function.Function;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;


import java.util.function.Function; import io.atomix.atomix.testing.AbstractAtomixTest;
import io.atomix.coordination.DistributedMembershipGroup;


/** /**
* Atomix membership group test. * Atomix membership group test.
Expand All @@ -27,7 +30,11 @@
*/ */
@Test @Test
public class AtomixMembershipGroupTest extends AbstractAtomixTest { public class AtomixMembershipGroupTest extends AbstractAtomixTest {

@BeforeClass
protected void setupCluster() throws Throwable {
createReplicas(5);
}

public void testClientMembershipGroupGet() throws Throwable { public void testClientMembershipGroupGet() throws Throwable {
Atomix client1 = createClient(); Atomix client1 = createClient();
Atomix client2 = createClient(); Atomix client2 = createClient();
Expand Down
15 changes: 11 additions & 4 deletions all/src/test/java/io/atomix/AtomixMessageBusTest.java
Expand Up @@ -15,11 +15,14 @@
*/ */
package io.atomix; package io.atomix;


import io.atomix.catalyst.transport.Address; import java.util.function.Function;
import io.atomix.coordination.DistributedMessageBus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;


import java.util.function.Function; import io.atomix.atomix.testing.AbstractAtomixTest;
import io.atomix.catalyst.transport.Address;
import io.atomix.coordination.DistributedMessageBus;


/** /**
* Atomix message bus test. * Atomix message bus test.
Expand All @@ -28,7 +31,11 @@
*/ */
@Test @Test
public class AtomixMessageBusTest extends AbstractAtomixTest { public class AtomixMessageBusTest extends AbstractAtomixTest {

@BeforeClass
protected void setupCluster() throws Throwable {
createReplicas(5);
}

public void testClientMessageBusGet() throws Throwable { public void testClientMessageBusGet() throws Throwable {
Atomix client1 = createClient(); Atomix client1 = createClient();
Atomix client2 = createClient(); Atomix client2 = createClient();
Expand Down

0 comments on commit 7cccfb8

Please sign in to comment.