Search in sources :

Example 11 with MembershipListener

use of com.hazelcast.core.MembershipListener in project hazelcast by hazelcast.

the class MemberAttributeTest method testRemoveAttributes.

@Test(timeout = 120000)
public void testRemoveAttributes() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance h1 = factory.newHazelcastInstance();
    Member m1 = h1.getCluster().getLocalMember();
    m1.setIntAttribute("Test", 123);
    HazelcastInstance h2 = factory.newHazelcastInstance();
    assertEquals(2, h2.getCluster().getMembers().size());
    Member member = null;
    for (Member m : h2.getCluster().getMembers()) {
        if (m == h2.getCluster().getLocalMember())
            continue;
        member = m;
    }
    assertNotNull(member);
    assertEquals(m1, member);
    assertNotNull(member.getIntAttribute("Test"));
    assertEquals(123, (int) member.getIntAttribute("Test"));
    final CountDownLatch latch = new CountDownLatch(2);
    final MembershipListener listener = new LatchMembershipListener(latch);
    h2.getCluster().addMembershipListener(listener);
    h1.getCluster().addMembershipListener(listener);
    m1.removeAttribute("Test");
    // Force sleep to distribute value
    assertOpenEventually(latch);
    assertNull(member.getIntAttribute("Test"));
    h1.shutdown();
    h2.shutdown();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CountDownLatch(java.util.concurrent.CountDownLatch) MembershipListener(com.hazelcast.core.MembershipListener) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with MembershipListener

use of com.hazelcast.core.MembershipListener in project hazelcast by hazelcast.

the class MemberAttributeTest method testChangeAttributes.

@Test(timeout = 120000)
public void testChangeAttributes() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance h1 = factory.newHazelcastInstance();
    Member m1 = h1.getCluster().getLocalMember();
    m1.setIntAttribute("Test", 123);
    HazelcastInstance h2 = factory.newHazelcastInstance();
    assertEquals(2, h2.getCluster().getMembers().size());
    Member member = null;
    for (Member m : h2.getCluster().getMembers()) {
        if (m == h2.getCluster().getLocalMember())
            continue;
        member = m;
    }
    assertNotNull(member);
    assertEquals(m1, member);
    assertNotNull(member.getIntAttribute("Test"));
    assertEquals(123, (int) member.getIntAttribute("Test"));
    final CountDownLatch latch = new CountDownLatch(2);
    final MembershipListener listener = new LatchMembershipListener(latch);
    h2.getCluster().addMembershipListener(listener);
    h1.getCluster().addMembershipListener(listener);
    m1.setIntAttribute("Test", 321);
    // Force sleep to distribute value
    assertOpenEventually(latch);
    assertNotNull(member.getIntAttribute("Test"));
    assertEquals(321, (int) member.getIntAttribute("Test"));
    h1.shutdown();
    h2.shutdown();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CountDownLatch(java.util.concurrent.CountDownLatch) MembershipListener(com.hazelcast.core.MembershipListener) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MembershipListener (com.hazelcast.core.MembershipListener)12 HazelcastInstance (com.hazelcast.core.HazelcastInstance)10 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 Test (org.junit.Test)9 ListenerConfig (com.hazelcast.config.ListenerConfig)6 Member (com.hazelcast.core.Member)6 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)6 Config (com.hazelcast.config.Config)5 JoinConfig (com.hazelcast.config.JoinConfig)4 MembershipEvent (com.hazelcast.core.MembershipEvent)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 MemberAttributeConfig (com.hazelcast.config.MemberAttributeConfig)3 MemberAttributeEvent (com.hazelcast.core.MemberAttributeEvent)3 Cluster (com.hazelcast.core.Cluster)2 InitialMembershipListener (com.hazelcast.core.InitialMembershipListener)2 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)1 NetworkConfig (com.hazelcast.config.NetworkConfig)1 ClientListener (com.hazelcast.core.ClientListener)1