Changes to speed up tests.
Change-Id: I1830f564710b9cb06d9c41d31e31854a272fbf4d
diff --git a/core/store/primitives/src/test/java/org/onosproject/store/primitives/resources/impl/AtomixTestBase.java b/core/store/primitives/src/test/java/org/onosproject/store/primitives/resources/impl/AtomixTestBase.java
index 01c33ec..db52ce9 100644
--- a/core/store/primitives/src/test/java/org/onosproject/store/primitives/resources/impl/AtomixTestBase.java
+++ b/core/store/primitives/src/test/java/org/onosproject/store/primitives/resources/impl/AtomixTestBase.java
@@ -27,8 +27,6 @@
import io.atomix.copycat.server.storage.StorageLevel;
import io.atomix.manager.internal.ResourceManagerState;
import io.atomix.resource.ResourceType;
-import org.junit.After;
-import org.junit.Before;
import org.onlab.junit.TestTools;
import org.onosproject.store.primitives.impl.CatalystSerializers;
@@ -43,18 +41,18 @@
import java.util.concurrent.atomic.AtomicInteger;
/**
- * Base class for various Atomix* tests.
+ * Base class for various Atomix tests.
*/
public abstract class AtomixTestBase {
- private static final File TEST_DIR = new File("target/test-logs");
- protected LocalServerRegistry registry;
- protected final AtomicInteger port = new AtomicInteger(49200);
- protected List<Address> members;
- protected List<CopycatClient> copycatClients = new ArrayList<>();
- protected List<CopycatServer> copycatServers = new ArrayList<>();
- protected List<AtomixClient> atomixClients = new ArrayList<>();
- protected List<CopycatServer> atomixServers = new ArrayList<>();
- protected Serializer serializer = CatalystSerializers.getSerializer();
+ protected static File testDir;
+ protected static LocalServerRegistry registry = new LocalServerRegistry();
+ protected static List<Address> members = new ArrayList<>();
+ protected static List<CopycatClient> copycatClients = new ArrayList<>();
+ protected static List<CopycatServer> copycatServers = new ArrayList<>();
+ protected static List<AtomixClient> atomixClients = new ArrayList<>();
+ protected static List<CopycatServer> atomixServers = new ArrayList<>();
+ protected static Serializer serializer = CatalystSerializers.getSerializer();
+ protected static AtomicInteger port = new AtomicInteger(49200);
/**
* Creates a new resource state machine.
@@ -68,7 +66,7 @@
*
* @return The next server address.
*/
- private Address nextAddress() {
+ private static Address nextAddress() {
Address address = new Address("127.0.0.1",
TestTools.findAvailablePort(port.getAndIncrement()));
members.add(address);
@@ -78,7 +76,8 @@
/**
* Creates a set of Copycat servers.
*/
- protected List<CopycatServer> createCopycatServers(int nodes) throws Throwable {
+ protected static List<CopycatServer> createCopycatServers(int nodes)
+ throws Throwable {
CountDownLatch latch = new CountDownLatch(nodes);
List<CopycatServer> servers = new ArrayList<>();
@@ -91,20 +90,18 @@
if (members.size() <= 1) {
server.bootstrap().thenRun(latch::countDown).join();
} else {
- server.join(members).thenRun(latch::countDown);
+ server.join(members).join();
}
servers.add(server);
}
- Uninterruptibles.awaitUninterruptibly(latch);
-
return servers;
}
/**
* Creates a Copycat server.
*/
- protected CopycatServer createCopycatServer(Address address) {
+ protected static CopycatServer createCopycatServer(Address address) {
CopycatServer server = CopycatServer.builder(address)
.withTransport(NettyTransport.builder().withThreads(1).build())
.withStorage(Storage.builder()
@@ -120,23 +117,21 @@
return server;
}
- @Before
- @After
- public void clearTests() throws Exception {
+ public static void clearTests() throws Exception {
registry = new LocalServerRegistry();
members = new ArrayList<>();
CompletableFuture<Void> closeClients =
CompletableFuture.allOf(atomixClients.stream()
- .map(AtomixClient::close)
- .toArray(CompletableFuture[]::new));
+ .map(AtomixClient::close)
+ .toArray(CompletableFuture[]::new));
- closeClients.thenCompose(v -> CompletableFuture.allOf(copycatServers.stream()
+ closeClients
+ .thenCompose(v -> CompletableFuture
+ .allOf(copycatServers.stream()
.map(CopycatServer::shutdown)
.toArray(CompletableFuture[]::new))).join();
- deleteDirectory(TEST_DIR);
-
atomixClients = new ArrayList<>();
copycatServers = new ArrayList<>();