Search in sources :

Example 46 with Member

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

the class ClientConnectionTest method testAsyncConnectionCreationInAsyncMethods.

@Test
public void testAsyncConnectionCreationInAsyncMethods() throws ExecutionException, InterruptedException {
    hazelcastFactory.newHazelcastInstance();
    CountDownLatch countDownLatch = new CountDownLatch(1);
    ClientConfig config = new ClientConfig();
    WaitingCredentials credentials = new WaitingCredentials("dev", "dev-pass", countDownLatch);
    config.setCredentials(credentials);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
    final IExecutorService executorService = client.getExecutorService(randomString());
    credentials.waitFlag.set(true);
    final HazelcastInstance secondInstance = hazelcastFactory.newHazelcastInstance();
    final AtomicReference<Future> atomicReference = new AtomicReference<Future>();
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            Member secondMember = secondInstance.getCluster().getLocalMember();
            Future future = executorService.submitToMember(new DummySerializableCallable(), secondMember);
            atomicReference.set(future);
        }
    });
    thread.start();
    try {
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() throws Exception {
                assertNotNull(atomicReference.get());
            }
        }, 30);
    } finally {
        thread.interrupt();
        thread.join();
        countDownLatch.countDown();
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Future(java.util.concurrent.Future) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 47 with Member

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

the class ClientSmartListenerService method start.

@Override
public void start() {
    clientConnectionManager.addConnectionListener(this);
    clientConnectionManager.addConnectionHeartbeatListener(this);
    final ClientClusterService clientClusterService = client.getClientClusterService();
    registrationExecutor.scheduleWithFixedDelay(new Runnable() {

        @Override
        public void run() {
            Collection<Member> memberList = clientClusterService.getMemberList();
            for (Member member : memberList) {
                clientConnectionManager.getOrTriggerConnect(member.getAddress(), false);
            }
        }
    }, 1, 1, TimeUnit.SECONDS);
}
Also used : Collection(java.util.Collection) Member(com.hazelcast.core.Member) ClientClusterService(com.hazelcast.client.spi.ClientClusterService)

Example 48 with Member

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

the class ClientTransactionManagerServiceImpl method getRandomAddress.

private Address getRandomAddress() {
    Member member = loadBalancer.next();
    if (member == null) {
        Set<Member> members = client.getCluster().getMembers();
        String msg;
        if (members.isEmpty()) {
            msg = "No address was return by the LoadBalancer since there are no members in the cluster";
        } else {
            msg = "No address was return by the LoadBalancer. " + "But the cluster contains the following members:" + members;
        }
        throw new IllegalStateException(msg);
    }
    return member.getAddress();
}
Also used : Member(com.hazelcast.core.Member)

Example 49 with Member

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

the class ClientMemberAttributeTest method testPresharedAttributes.

@Test(timeout = 120000)
public void testPresharedAttributes() throws Exception {
    Config c = new Config();
    JoinConfig join = c.getNetworkConfig().getJoin();
    join.getTcpIpConfig().addMember("127.0.0.1").setEnabled(true);
    join.getMulticastConfig().setEnabled(false);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(c);
    Member m1 = h1.getCluster().getLocalMember();
    m1.setIntAttribute("Test", 123);
    HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(c);
    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"));
    boolean found = false;
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    Collection<Member> members = client.getCluster().getMembers();
    for (Member m : members) {
        if (m.equals(m1)) {
            assertEquals(123, (int) m.getIntAttribute("Test"));
            found = true;
        }
    }
    assertTrue(found);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) JoinConfig(com.hazelcast.config.JoinConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) JoinConfig(com.hazelcast.config.JoinConfig) 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 50 with Member

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

the class ClientMemberAttributeTest method testRemoveAttributes.

@Test(timeout = 120000)
public void testRemoveAttributes() throws Exception {
    Config c = new Config();
    JoinConfig join = c.getNetworkConfig().getJoin();
    join.getTcpIpConfig().addMember("127.0.0.1").setEnabled(true);
    join.getMulticastConfig().setEnabled(false);
    HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(c);
    Member m1 = h1.getCluster().getLocalMember();
    m1.setIntAttribute("Test", 123);
    HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(c);
    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"));
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    final CountDownLatch latch = new CountDownLatch(3);
    final MembershipListener listener = new LatchMembershipListener(latch);
    h2.getCluster().addMembershipListener(listener);
    h1.getCluster().addMembershipListener(listener);
    client.getCluster().addMembershipListener(listener);
    m1.removeAttribute("Test");
    // Force sleep to distribute value
    assertOpenEventually(latch);
    assertNull(member.getIntAttribute("Test"));
    boolean found = false;
    Collection<Member> members = client.getCluster().getMembers();
    for (Member m : members) {
        if (m.equals(m1)) {
            assertNull(m.getIntAttribute("Test"));
            found = true;
        }
    }
    assertTrue(found);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) JoinConfig(com.hazelcast.config.JoinConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) JoinConfig(com.hazelcast.config.JoinConfig) CountDownLatch(java.util.concurrent.CountDownLatch) MembershipListener(com.hazelcast.core.MembershipListener) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Member (com.hazelcast.core.Member)167 Test (org.junit.Test)43 Address (com.hazelcast.nio.Address)39 HazelcastInstance (com.hazelcast.core.HazelcastInstance)37 QuickTest (com.hazelcast.test.annotation.QuickTest)30 ParallelTest (com.hazelcast.test.annotation.ParallelTest)26 HashMap (java.util.HashMap)21 ArrayList (java.util.ArrayList)20 Config (com.hazelcast.config.Config)18 HashSet (java.util.HashSet)18 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)17 Future (java.util.concurrent.Future)17 Data (com.hazelcast.nio.serialization.Data)13 Operation (com.hazelcast.spi.Operation)13 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)13 CacheEventData (com.hazelcast.cache.impl.CacheEventData)12 HeapData (com.hazelcast.internal.serialization.impl.HeapData)12 DefaultQueryCacheEventData (com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData)12 QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)12 OperationService (com.hazelcast.spi.OperationService)12