Skip to content

Commit

Permalink
Update test-tools for new API changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuujo committed Apr 17, 2015
1 parent 6638c31 commit c1122db
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
43 changes: 22 additions & 21 deletions test-tools/src/main/java/net/kuujo/copycat/test/ProtocolTest.java
Expand Up @@ -20,11 +20,12 @@
import net.kuujo.copycat.cluster.ClusterConfig;
import net.kuujo.copycat.cluster.MembershipEvent;
import net.kuujo.copycat.io.HeapBuffer;
import net.kuujo.copycat.log.LogConfig;
import net.kuujo.copycat.raft.log.LogConfig;
import net.kuujo.copycat.protocol.Protocol;
import net.kuujo.copycat.protocol.ProtocolClient;
import net.kuujo.copycat.protocol.ProtocolServer;
import net.kuujo.copycat.resource.ResourceContext;
import net.kuujo.copycat.resource.PartitionContext;
import net.kuujo.copycat.resource.ResourceConfig;
import net.kuujo.copycat.util.concurrent.NamedThreadFactory;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -55,16 +56,16 @@ public abstract class ProtocolTest extends ConcurrentTestCase {
/**
* Creates a new test resource.
*/
private TestResource createTestResource(ClusterConfig cluster) {
return new TestResource(new ResourceContext(new TestResource.Config().withLog(new LogConfig()), cluster, Executors
.newSingleThreadScheduledExecutor(new NamedThreadFactory("copycat-test-%d"))));
private TestPartition createTestResource(ClusterConfig cluster) {
return new TestPartition(new PartitionContext(new ResourceConfig() {}, new TestPartition.Config().withLog(new LogConfig()),
cluster, Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("copycat-test-%d"))));
}

/**
* Creates a new test cluster.
*/
private TestCluster<TestResource> createTestCluster() {
return TestCluster.<TestResource>builder()
private TestCluster<TestPartition> createTestCluster() {
return TestCluster.<TestPartition>builder()
.withActiveMembers(3)
.withPassiveMembers(2)
.withUriFactory(this::createUri)
Expand All @@ -77,9 +78,9 @@ private TestCluster<TestResource> createTestCluster() {
* Tests a member joining on an active member of the cluster.
*/
public void testClusterJoinActiveMember() throws Throwable {
TestCluster<TestResource> test = createTestCluster();
TestResource active = test.activeResources().iterator().next();
TestResource passive = test.passiveResources().iterator().next();
TestCluster<TestPartition> test = createTestCluster();
TestPartition active = test.activeResources().iterator().next();
TestPartition passive = test.passiveResources().iterator().next();

expectResume();
Cluster cluster = active.cluster();
Expand All @@ -99,10 +100,10 @@ public void testClusterJoinActiveMember() throws Throwable {
* Tests a member joining on a passive member of the cluster.
*/
public void testClusterJoinPassiveMember() throws Throwable {
TestCluster<TestResource> test = createTestCluster();
Iterator<TestResource> iterator = test.passiveResources().iterator();
TestResource passive1 = iterator.next();
TestResource passive2 = iterator.next();
TestCluster<TestPartition> test = createTestCluster();
Iterator<TestPartition> iterator = test.passiveResources().iterator();
TestPartition passive1 = iterator.next();
TestPartition passive2 = iterator.next();

expectResume();
Cluster cluster = passive1.cluster();
Expand All @@ -122,9 +123,9 @@ public void testClusterJoinPassiveMember() throws Throwable {
* Tests a member leaving on an active member of the cluster.
*/
public void testClusterLeaveActiveMember() throws Throwable {
TestCluster<TestResource> test = createTestCluster();
TestResource active = test.activeResources().iterator().next();
TestResource passive = test.passiveResources().iterator().next();
TestCluster<TestPartition> test = createTestCluster();
TestPartition active = test.activeResources().iterator().next();
TestPartition passive = test.passiveResources().iterator().next();

AtomicBoolean joined = new AtomicBoolean();
expectResume();
Expand All @@ -147,10 +148,10 @@ public void testClusterLeaveActiveMember() throws Throwable {
* Tests a member leaving on a passive member of the cluster.
*/
public void testClusterLeavePassiveMember() throws Throwable {
TestCluster<TestResource> test = createTestCluster();
Iterator<TestResource> iterator = test.passiveResources().iterator();
TestResource passive1 = iterator.next();
TestResource passive2 = iterator.next();
TestCluster<TestPartition> test = createTestCluster();
Iterator<TestPartition> iterator = test.passiveResources().iterator();
TestPartition passive1 = iterator.next();
TestPartition passive2 = iterator.next();

AtomicBoolean joined = new AtomicBoolean();
expectResume();
Expand Down
Expand Up @@ -18,7 +18,7 @@
import net.kuujo.copycat.cluster.ClusterConfig;
import net.kuujo.copycat.cluster.MemberConfig;
import net.kuujo.copycat.protocol.LocalProtocol;
import net.kuujo.copycat.resource.Resource;
import net.kuujo.copycat.resource.Partition;

import java.util.*;
import java.util.concurrent.CompletableFuture;
Expand All @@ -29,7 +29,7 @@
*
* @author <a href="http://github.com/kuujo">Jordan Halterman</a>
*/
public class TestCluster<T extends Resource<T>> {
public class TestCluster<T extends Partition<T>> {
private static int id = 1;
private final List<T> activeResources;
private final List<T> passiveResources;
Expand All @@ -42,14 +42,14 @@ private TestCluster(List<T> activeResources, List<T> passiveResources) {
/**
* Creates a new test cluster builder.
*/
public static <T extends Resource<T>> Builder<T> builder() {
public static <T extends Partition<T>> Builder<T> builder() {
return new Builder<>();
}

/**
* Test cluster builder.
*/
public static class Builder<T extends Resource<T>> {
public static class Builder<T extends Partition<T>> {
private int activeMembers = 3;
private int passiveMembers = 2;
private Function<Integer, String> uriFactory;
Expand Down
19 changes: 12 additions & 7 deletions test-tools/src/main/java/net/kuujo/copycat/test/TestPartition.java
Expand Up @@ -15,9 +15,9 @@
*/
package net.kuujo.copycat.test;

import net.kuujo.copycat.resource.ResourceConfig;
import net.kuujo.copycat.resource.ResourceContext;
import net.kuujo.copycat.resource.ResourceState;
import net.kuujo.copycat.resource.PartitionConfig;
import net.kuujo.copycat.resource.PartitionContext;
import net.kuujo.copycat.resource.PartitionState;
import net.kuujo.copycat.resource.internal.AbstractPartition;

/**
Expand All @@ -27,19 +27,24 @@
*/
public class TestPartition extends AbstractPartition<TestPartition> {

public TestPartition(ResourceContext context) {
public TestPartition(PartitionContext context) {
super(context);
}

@Override
public ResourceState state() {
return ResourceState.HEALTHY;
public int partition() {
return context.getPartitionId();
}

@Override
public PartitionState state() {
return PartitionState.HEALTHY;
}

/**
* Test resource configuration.
*/
public static class Config extends ResourceConfig<Config> {
public static class Config extends PartitionConfig {

public Config() {
super();
Expand Down

0 comments on commit c1122db

Please sign in to comment.