Skip to content

Commit

Permalink
Update Atomix server tests for new cmembership changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuujo committed Dec 11, 2015
1 parent 62eafc3 commit 1926f5d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
58 changes: 39 additions & 19 deletions manager/src/test/java/io/atomix/AbstractServerTest.java
Expand Up @@ -18,36 +18,38 @@
import io.atomix.catalyst.transport.Address; import io.atomix.catalyst.transport.Address;
import io.atomix.catalyst.transport.LocalServerRegistry; import io.atomix.catalyst.transport.LocalServerRegistry;
import io.atomix.catalyst.transport.LocalTransport; import io.atomix.catalyst.transport.LocalTransport;
import io.atomix.copycat.server.CopycatServer;
import io.atomix.copycat.server.state.Member;
import io.atomix.copycat.server.storage.Storage; import io.atomix.copycat.server.storage.Storage;
import io.atomix.copycat.server.storage.StorageLevel; import io.atomix.copycat.server.storage.StorageLevel;
import net.jodah.concurrentunit.ConcurrentTestCase; import net.jodah.concurrentunit.ConcurrentTestCase;
import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeMethod;


import java.io.IOException;
import java.time.Duration; import java.time.Duration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;


/** /**
* Abstract server test. * Abstract server test.
* *
* @author <a href="http://github.com/kuujo>Jordan Halterman</a> * @author <a href="http://github.com/kuujo>Jordan Halterman</a>
*/ */
public abstract class AbstractServerTest extends ConcurrentTestCase { public abstract class AbstractServerTest extends ConcurrentTestCase {
protected LocalServerRegistry registry; protected volatile LocalServerRegistry registry;
protected int port; protected volatile int port;
protected List<Address> members; protected volatile List<Member> members;
protected volatile List<Atomix> clients = new ArrayList<>();
protected volatile List<AtomixServer> servers = new ArrayList<>();


/** /**
* Returns the next server address. * Returns the next server address.
* *
* @return The next server address. * @return The next server address.
*/ */
protected Address nextAddress() { protected Member nextMember() {
Address address = new Address("localhost", port++); return new Member(CopycatServer.Type.INACTIVE, new Address("localhost", ++port), new Address("localhost", port + 1000));
members.add(address);
return address;
} }


/** /**
Expand All @@ -56,43 +58,61 @@ protected Address nextAddress() {
protected List<AtomixServer> createServers(int nodes) throws Throwable { protected List<AtomixServer> createServers(int nodes) throws Throwable {
List<AtomixServer> servers = new ArrayList<>(); List<AtomixServer> servers = new ArrayList<>();


List<Address> members = new ArrayList<>(); for (int i = 0; i < nodes; i++) {
for (int i = 1; i <= nodes; i++) { members.add(nextMember());
members.add(nextAddress());
} }


for (int i = 0; i < nodes; i++) { for (int i = 0; i < nodes; i++) {
AtomixServer server = createServer(members.get(i)); AtomixServer server = createServer(members, members.get(i));
server.open().thenRun(this::resume); server.open().thenRun(this::resume);
servers.add(server); servers.add(server);
} }


await(0, nodes); await(10000, nodes);


return servers; return servers;
} }


/** /**
* Creates an Atomix server. * Creates an Atomix server.
*/ */
protected AtomixServer createServer(Address address) { protected AtomixServer createServer(List<Member> members, Member member) {
return AtomixServer.builder(address, members) AtomixServer server = AtomixServer.builder(member.clientAddress(), member.serverAddress(), members.stream().map(Member::serverAddress).collect(Collectors.toList()))
.withTransport(new LocalTransport(registry)) .withTransport(new LocalTransport(registry))
.withStorage(Storage.builder() .withStorage(Storage.builder()
.withStorageLevel(StorageLevel.MEMORY) .withStorageLevel(StorageLevel.MEMORY)
.withMaxSegmentSize(1024 * 1024)
.withMaxEntriesPerSegment(8) .withMaxEntriesPerSegment(8)
.withMinorCompactionInterval(Duration.ofSeconds(5)) .withMinorCompactionInterval(Duration.ofSeconds(3))
.withMajorCompactionInterval(Duration.ofSeconds(10)) .withMajorCompactionInterval(Duration.ofSeconds(7))
.build()) .build())
.build(); .build();
servers.add(server);
return server;
} }


@BeforeMethod @BeforeMethod
@AfterMethod @AfterMethod
public void clearTests() throws IOException { public void clearTests() throws Exception {
port = 5000; clients.forEach(c -> {
try {
c.close().join();
} catch (Exception e) {
}
});

servers.forEach(s -> {
try {
s.close().join();
} catch (Exception e) {
}
});

registry = new LocalServerRegistry(); registry = new LocalServerRegistry();
members = new ArrayList<>(); members = new ArrayList<>();
port = 5000;
clients = new ArrayList<>();
servers = new ArrayList<>();
} }


} }
6 changes: 5 additions & 1 deletion manager/src/test/java/io/atomix/AtomixClientServerTest.java
Expand Up @@ -20,10 +20,12 @@
import io.atomix.copycat.client.Query; import io.atomix.copycat.client.Query;
import io.atomix.copycat.client.CopycatClient; import io.atomix.copycat.client.CopycatClient;
import io.atomix.copycat.server.Commit; import io.atomix.copycat.server.Commit;
import io.atomix.copycat.server.state.Member;
import io.atomix.resource.*; import io.atomix.resource.*;
import org.testng.annotations.Test; import org.testng.annotations.Test;


import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;


/** /**
* Client server test. * Client server test.
Expand Down Expand Up @@ -232,7 +234,9 @@ public void testGetResourceKeys() throws Throwable {
* Creates a client. * Creates a client.
*/ */
private Atomix createClient() throws Throwable { private Atomix createClient() throws Throwable {
Atomix client = AtomixClient.builder(members).withTransport(new LocalTransport(registry)).build(); Atomix client = AtomixClient.builder(members.stream().map(Member::clientAddress).collect(Collectors.toList()))
.withTransport(new LocalTransport(registry))
.build();
client.open().thenRun(this::resume); client.open().thenRun(this::resume);
await(10000); await(10000);
return client; return client;
Expand Down
2 changes: 1 addition & 1 deletion manager/src/test/java/io/atomix/AtomixServerTest.java
Expand Up @@ -32,7 +32,7 @@ public class AtomixServerTest extends AbstractServerTest {
*/ */
public void testServerJoin() throws Throwable { public void testServerJoin() throws Throwable {
createServers(3); createServers(3);
AtomixServer joiner = createServer(nextAddress()); AtomixServer joiner = createServer(members, nextMember());
joiner.open().thenRun(this::resume); joiner.open().thenRun(this::resume);
await(); await();
} }
Expand Down

0 comments on commit 1926f5d

Please sign in to comment.