Search in sources :

Example 11 with Member

use of io.atomix.cluster.Member in project atomix by atomix.

the class AtomixTest method testClientProperties.

/**
 * Tests a client properties.
 */
@Test
public void testClientProperties() throws Exception {
    List<CompletableFuture<Atomix>> futures = new ArrayList<>();
    futures.add(startAtomix(1, Arrays.asList(1, 2, 3), ConsensusProfile.builder().withMembers("1", "2", "3").withDataPath(new File(new File(DATA_DIR, "client-properties"), "1")).build()));
    futures.add(startAtomix(2, Arrays.asList(1, 2, 3), ConsensusProfile.builder().withMembers("1", "2", "3").withDataPath(new File(new File(DATA_DIR, "client-properties"), "2")).build()));
    futures.add(startAtomix(3, Arrays.asList(1, 2, 3), ConsensusProfile.builder().withMembers("1", "2", "3").withDataPath(new File(new File(DATA_DIR, "client-properties"), "3")).build()));
    Futures.allOf(futures).get(30, TimeUnit.SECONDS);
    TestClusterMembershipEventListener dataListener = new TestClusterMembershipEventListener();
    instances.get(0).getMembershipService().addListener(dataListener);
    Properties properties = new Properties();
    properties.setProperty("a-key", "a-value");
    Atomix client1 = startAtomix(4, Arrays.asList(1, 2, 3), properties, Profile.client()).get(30, TimeUnit.SECONDS);
    assertEquals(1, client1.getPartitionService().getPartitionGroups().size());
    // client1 added to data node
    ClusterMembershipEvent event1 = dataListener.event();
    assertEquals(ClusterMembershipEvent.Type.MEMBER_ADDED, event1.type());
    Member member = event1.subject();
    assertNotNull(member.properties());
    assertEquals(1, member.properties().size());
    assertEquals("a-value", member.properties().get("a-key"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ClusterMembershipEvent(io.atomix.cluster.ClusterMembershipEvent) ArrayList(java.util.ArrayList) Properties(java.util.Properties) File(java.io.File) Member(io.atomix.cluster.Member) Test(org.junit.Test)

Aggregations

Member (io.atomix.cluster.Member)11 CompletableFuture (java.util.concurrent.CompletableFuture)5 Address (io.atomix.utils.net.Address)4 BootstrapService (io.atomix.cluster.BootstrapService)3 MemberId (io.atomix.cluster.MemberId)3 Node (io.atomix.cluster.Node)3 MessagingService (io.atomix.cluster.messaging.MessagingService)3 Test (org.junit.Test)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 ClusterMembershipEvent (io.atomix.cluster.ClusterMembershipEvent)2 ClusterMembershipService (io.atomix.cluster.ClusterMembershipService)2 ManagedClusterMembershipService (io.atomix.cluster.ManagedClusterMembershipService)2 TestBootstrapService (io.atomix.cluster.TestBootstrapService)2 BootstrapDiscoveryProvider (io.atomix.cluster.discovery.BootstrapDiscoveryProvider)2 ClusterEventService (io.atomix.cluster.messaging.ClusterEventService)2 ManagedClusterEventService (io.atomix.cluster.messaging.ManagedClusterEventService)2 HeartbeatMembershipProtocol (io.atomix.cluster.protocol.HeartbeatMembershipProtocol)2 HeartbeatMembershipProtocolConfig (io.atomix.cluster.protocol.HeartbeatMembershipProtocolConfig)2 RaftMember (io.atomix.protocols.raft.cluster.RaftMember)2