Skip to content

Commit

Permalink
Move static profiles to Profile interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuujo committed Apr 27, 2018
1 parent 76e381f commit 3c02f05
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
17 changes: 17 additions & 0 deletions core/src/main/java/io/atomix/core/profile/Profile.java
Expand Up @@ -22,6 +22,23 @@
*/
public interface Profile {

/**
* The consensus profile configures an Atomix instance with a Raft system partition and a multi-Raft data partition group.
*/
ConsensusProfile CONSENSUS = new ConsensusProfile();

/**
* The data grid profile configures an Atomix instance with a primary-backup system partition if no system partition
* is configured, and a primary-backup data partition group.
*/
DataGridProfile DATA_GRID = new DataGridProfile();

/**
* The client profile configures the local member as a {@link io.atomix.cluster.Member.Type#EPHEMERAL} member and
* does not configure any system or primitive partition groups.
*/
ClientProfile CLIENT = new ClientProfile();

/**
* Configures the Atomix instance.
*
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/java/io/atomix/core/profile/Profiles.java
Expand Up @@ -22,9 +22,6 @@
* Atomix profiles.
*/
public final class Profiles {
public static final ConsensusProfile CONSENSUS = new ConsensusProfile();
public static final DataGridProfile DATA_GRID = new DataGridProfile();
public static final ClientProfile CLIENT = new ClientProfile();

/**
* Returns the Atomix profile for the given name
Expand Down
8 changes: 4 additions & 4 deletions core/src/test/java/io/atomix/core/AbstractPrimitiveTest.java
Expand Up @@ -16,7 +16,7 @@
package io.atomix.core;

import io.atomix.cluster.Member;
import io.atomix.core.profile.Profiles;
import io.atomix.core.profile.Profile;
import io.atomix.primitive.protocol.PrimitiveProtocol;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -57,9 +57,9 @@ protected Atomix atomix() throws Exception {
public static void setupAtomix() throws Exception {
AbstractAtomixTest.setupAtomix();
instances = new ArrayList<>();
instances.add(createAtomix(Member.Type.PERSISTENT, 1, Arrays.asList(1, 2, 3), Arrays.asList(), Profiles.CONSENSUS, Profiles.DATA_GRID));
instances.add(createAtomix(Member.Type.PERSISTENT, 2, Arrays.asList(1, 2, 3), Arrays.asList(), Profiles.CONSENSUS, Profiles.DATA_GRID));
instances.add(createAtomix(Member.Type.PERSISTENT, 3, Arrays.asList(1, 2, 3), Arrays.asList(), Profiles.CONSENSUS, Profiles.DATA_GRID));
instances.add(createAtomix(Member.Type.PERSISTENT, 1, Arrays.asList(1, 2, 3), Arrays.asList(), Profile.CONSENSUS, Profile.DATA_GRID));
instances.add(createAtomix(Member.Type.PERSISTENT, 2, Arrays.asList(1, 2, 3), Arrays.asList(), Profile.CONSENSUS, Profile.DATA_GRID));
instances.add(createAtomix(Member.Type.PERSISTENT, 3, Arrays.asList(1, 2, 3), Arrays.asList(), Profile.CONSENSUS, Profile.DATA_GRID));
List<CompletableFuture<Atomix>> futures = instances.stream().map(Atomix::start).collect(Collectors.toList());
CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).get(30, TimeUnit.SECONDS);
}
Expand Down
43 changes: 21 additions & 22 deletions core/src/test/java/io/atomix/core/AtomixTest.java
Expand Up @@ -19,7 +19,6 @@
import io.atomix.cluster.ClusterMembershipEventListener;
import io.atomix.cluster.Member;
import io.atomix.core.profile.Profile;
import io.atomix.core.profile.Profiles;
import io.atomix.utils.concurrent.Futures;
import io.atomix.utils.net.Address;
import org.junit.After;
Expand Down Expand Up @@ -92,9 +91,9 @@ protected CompletableFuture<Atomix> startAtomix(Member.Type type, int id, List<I
*/
@Test
public void testScaleUpPersistent() throws Exception {
Atomix atomix1 = startAtomix(Member.Type.PERSISTENT, 1, Arrays.asList(1), Arrays.asList(), Profiles.CONSENSUS).join();
Atomix atomix2 = startAtomix(Member.Type.PERSISTENT, 2, Arrays.asList(1, 2), Arrays.asList(), Profiles.CLIENT).join();
Atomix atomix3 = startAtomix(Member.Type.PERSISTENT, 3, Arrays.asList(1, 2, 3), Arrays.asList(), Profiles.CLIENT).join();
Atomix atomix1 = startAtomix(Member.Type.PERSISTENT, 1, Arrays.asList(1), Arrays.asList(), Profile.CONSENSUS).join();
Atomix atomix2 = startAtomix(Member.Type.PERSISTENT, 2, Arrays.asList(1, 2), Arrays.asList(), Profile.CLIENT).join();
Atomix atomix3 = startAtomix(Member.Type.PERSISTENT, 3, Arrays.asList(1, 2, 3), Arrays.asList(), Profile.CLIENT).join();
}

/**
Expand All @@ -103,9 +102,9 @@ public void testScaleUpPersistent() throws Exception {
@Test
public void testBootstrapEphemeral() throws Exception {
List<CompletableFuture<Atomix>> futures = new ArrayList<>(3);
futures.add(startAtomix(Member.Type.EPHEMERAL, 1, Arrays.asList(), Arrays.asList(), Profiles.DATA_GRID));
futures.add(startAtomix(Member.Type.EPHEMERAL, 2, Arrays.asList(), Arrays.asList(1), Profiles.DATA_GRID));
futures.add(startAtomix(Member.Type.EPHEMERAL, 3, Arrays.asList(), Arrays.asList(1), Profiles.DATA_GRID));
futures.add(startAtomix(Member.Type.EPHEMERAL, 1, Arrays.asList(), Arrays.asList(), Profile.DATA_GRID));
futures.add(startAtomix(Member.Type.EPHEMERAL, 2, Arrays.asList(), Arrays.asList(1), Profile.DATA_GRID));
futures.add(startAtomix(Member.Type.EPHEMERAL, 3, Arrays.asList(), Arrays.asList(1), Profile.DATA_GRID));
CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).join();
}

Expand All @@ -114,28 +113,28 @@ public void testBootstrapEphemeral() throws Exception {
*/
@Test
public void testScaleUpEphemeral() throws Exception {
Atomix atomix1 = startAtomix(Member.Type.EPHEMERAL, 1, Arrays.asList(), Arrays.asList(), Profiles.DATA_GRID).join();
Atomix atomix2 = startAtomix(Member.Type.EPHEMERAL, 2, Arrays.asList(), Arrays.asList(1), Profiles.DATA_GRID).join();
Atomix atomix3 = startAtomix(Member.Type.EPHEMERAL, 3, Arrays.asList(), Arrays.asList(1), Profiles.DATA_GRID).join();
Atomix atomix1 = startAtomix(Member.Type.EPHEMERAL, 1, Arrays.asList(), Arrays.asList(), Profile.DATA_GRID).join();
Atomix atomix2 = startAtomix(Member.Type.EPHEMERAL, 2, Arrays.asList(), Arrays.asList(1), Profile.DATA_GRID).join();
Atomix atomix3 = startAtomix(Member.Type.EPHEMERAL, 3, Arrays.asList(), Arrays.asList(1), Profile.DATA_GRID).join();
}

@Test
public void testDiscoverData() throws Exception {
Address multicastAddress = Address.from("230.0.0.1", findAvailablePort(1234));
Atomix atomix1 = startAtomix(Member.Type.EPHEMERAL, 1, Arrays.asList(), Arrays.asList(), builder ->
builder.withProfiles(Profiles.DATA_GRID)
builder.withProfiles(Profile.DATA_GRID)
.withMulticastEnabled()
.withMulticastAddress(multicastAddress)
.build())
.join();
Atomix atomix2 = startAtomix(Member.Type.EPHEMERAL, 2, Arrays.asList(), Arrays.asList(), builder ->
builder.withProfiles(Profiles.DATA_GRID)
builder.withProfiles(Profile.DATA_GRID)
.withMulticastEnabled()
.withMulticastAddress(multicastAddress)
.build())
.join();
Atomix atomix3 = startAtomix(Member.Type.EPHEMERAL, 3, Arrays.asList(), Arrays.asList(), builder ->
builder.withProfiles(Profiles.DATA_GRID)
builder.withProfiles(Profile.DATA_GRID)
.withMulticastEnabled()
.withMulticastAddress(multicastAddress)
.build())
Expand All @@ -150,7 +149,7 @@ public void testDiscoverData() throws Exception {

@Test
public void testStopStartConsensus() throws Exception {
Atomix atomix1 = startAtomix(Member.Type.PERSISTENT, 1, Arrays.asList(1), Arrays.asList(), Profiles.CONSENSUS).join();
Atomix atomix1 = startAtomix(Member.Type.PERSISTENT, 1, Arrays.asList(1), Arrays.asList(), Profile.CONSENSUS).join();
atomix1.stop().join();
try {
atomix1.start().join();
Expand All @@ -167,9 +166,9 @@ public void testStopStartConsensus() throws Exception {
@Test
public void testScaleDownPersistent() throws Exception {
List<CompletableFuture<Atomix>> futures = new ArrayList<>();
futures.add(startAtomix(Member.Type.PERSISTENT, 1, Arrays.asList(1, 2, 3), Arrays.asList(), Profiles.DATA_GRID));
futures.add(startAtomix(Member.Type.PERSISTENT, 2, Arrays.asList(1, 2, 3), Arrays.asList(), Profiles.DATA_GRID));
futures.add(startAtomix(Member.Type.PERSISTENT, 3, Arrays.asList(1, 2, 3), Arrays.asList(), Profiles.DATA_GRID));
futures.add(startAtomix(Member.Type.PERSISTENT, 1, Arrays.asList(1, 2, 3), Arrays.asList(), Profile.DATA_GRID));
futures.add(startAtomix(Member.Type.PERSISTENT, 2, Arrays.asList(1, 2, 3), Arrays.asList(), Profile.DATA_GRID));
futures.add(startAtomix(Member.Type.PERSISTENT, 3, Arrays.asList(1, 2, 3), Arrays.asList(), Profile.DATA_GRID));
Futures.allOf(futures).join();
instances.get(0).stop().join();
instances.get(1).stop().join();
Expand All @@ -182,15 +181,15 @@ public void testScaleDownPersistent() throws Exception {
@Test
public void testClientJoinLeaveCore() throws Exception {
List<CompletableFuture<Atomix>> futures = new ArrayList<>();
futures.add(startAtomix(Member.Type.PERSISTENT, 1, Arrays.asList(1, 2, 3), Profiles.CONSENSUS));
futures.add(startAtomix(Member.Type.PERSISTENT, 2, Arrays.asList(1, 2, 3), Profiles.CONSENSUS));
futures.add(startAtomix(Member.Type.PERSISTENT, 3, Arrays.asList(1, 2, 3), Profiles.CONSENSUS));
futures.add(startAtomix(Member.Type.PERSISTENT, 1, Arrays.asList(1, 2, 3), Profile.CONSENSUS));
futures.add(startAtomix(Member.Type.PERSISTENT, 2, Arrays.asList(1, 2, 3), Profile.CONSENSUS));
futures.add(startAtomix(Member.Type.PERSISTENT, 3, Arrays.asList(1, 2, 3), Profile.CONSENSUS));
Futures.allOf(futures).join();

TestClusterMembershipEventListener dataListener = new TestClusterMembershipEventListener();
instances.get(0).membershipService().addListener(dataListener);

Atomix client1 = startAtomix(Member.Type.EPHEMERAL, 4, Arrays.asList(1, 2, 3), Profiles.CLIENT).join();
Atomix client1 = startAtomix(Member.Type.EPHEMERAL, 4, Arrays.asList(1, 2, 3), Profile.CLIENT).join();
assertEquals(1, client1.partitionService().getPartitionGroups().size());

// client1 added to data node
Expand All @@ -204,7 +203,7 @@ public void testClientJoinLeaveCore() throws Exception {
TestClusterMembershipEventListener clientListener = new TestClusterMembershipEventListener();
client1.membershipService().addListener(clientListener);

Atomix client2 = startAtomix(Member.Type.EPHEMERAL, 5, Arrays.asList(1, 2, 3), Profiles.CLIENT).join();
Atomix client2 = startAtomix(Member.Type.EPHEMERAL, 5, Arrays.asList(1, 2, 3), Profile.CLIENT).join();
assertEquals(1, client2.partitionService().getPartitionGroups().size());

// client2 added to data node
Expand Down

0 comments on commit 3c02f05

Please sign in to comment.