Search in sources :

Example 16 with ClientEventRegistration

use of com.hazelcast.client.spi.impl.listener.ClientEventRegistration in project hazelcast by hazelcast.

the class ListenerLeakTestNonSmartRouting method testQueueListeners.

@Test
public void testQueueListeners() {
    Collection<Node> nodes = createNodes();
    HazelcastInstance client = newHazelcastClient();
    IQueue<Object> queue = client.getQueue(randomString());
    String id = queue.addItemListener(mock(ItemListener.class), false);
    Collection<ClientEventRegistration> registrations = getClientEventRegistrations(client, id);
    assertTrue(queue.removeItemListener(id));
    assertNoLeftOver(nodes, client, id, registrations);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientEventRegistration(com.hazelcast.client.spi.impl.listener.ClientEventRegistration) Node(com.hazelcast.instance.Node) ItemListener(com.hazelcast.core.ItemListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with ClientEventRegistration

use of com.hazelcast.client.spi.impl.listener.ClientEventRegistration in project hazelcast by hazelcast.

the class ListenerLeakTestNonSmartRouting method testListListeners.

@Test
public void testListListeners() {
    Collection<Node> nodes = createNodes();
    HazelcastInstance client = newHazelcastClient();
    IList<Object> list = client.getList(randomString());
    String id = list.addItemListener(mock(ItemListener.class), false);
    Collection<ClientEventRegistration> registrations = getClientEventRegistrations(client, id);
    assertTrue(list.removeItemListener(id));
    assertNoLeftOver(nodes, client, id, registrations);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientEventRegistration(com.hazelcast.client.spi.impl.listener.ClientEventRegistration) Node(com.hazelcast.instance.Node) ItemListener(com.hazelcast.core.ItemListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with ClientEventRegistration

use of com.hazelcast.client.spi.impl.listener.ClientEventRegistration in project hazelcast by hazelcast.

the class ListenerLeakTestNonSmartRouting method testReplicatedMapListeners.

@Test
public void testReplicatedMapListeners() {
    Collection<Node> nodes = createNodes();
    HazelcastInstance client = newHazelcastClient();
    ReplicatedMap<Object, Object> replicatedMap = client.getReplicatedMap(randomString());
    String id = replicatedMap.addEntryListener(mock(EntryListener.class));
    Collection<ClientEventRegistration> registrations = getClientEventRegistrations(client, id);
    assertTrue(replicatedMap.removeEntryListener(id));
    assertNoLeftOver(nodes, client, id, registrations);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientEventRegistration(com.hazelcast.client.spi.impl.listener.ClientEventRegistration) Node(com.hazelcast.instance.Node) EntryListener(com.hazelcast.core.EntryListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with ClientEventRegistration

use of com.hazelcast.client.spi.impl.listener.ClientEventRegistration in project hazelcast by hazelcast.

the class AbstractListenersOnReconnectTest method validateRegistrations.

private void validateRegistrations(final int clusterSize, final String registrationId, final HazelcastClientInstanceImpl clientInstanceImpl) {
    final boolean smartRouting = clientInstanceImpl.getClientConfig().getNetworkConfig().isSmartRouting();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            int size = smartRouting ? clusterSize : 1;
            Collection<ClientEventRegistration> registrations = getClientEventRegistrations(client, registrationId);
            assertEquals(size, registrations.size());
            if (smartRouting) {
                Collection<Member> members = clientInstanceImpl.getClientClusterService().getMemberList();
                for (ClientEventRegistration registration : registrations) {
                    Connection registeredSubscriber = registration.getSubscriber();
                    boolean contains = false;
                    for (Member member : members) {
                        contains |= registeredSubscriber.getEndPoint().equals(member.getAddress());
                    }
                    assertTrue("Registered member " + registeredSubscriber + " is not in the cluster member list " + members, contains);
                }
            } else {
                ClientEventRegistration registration = registrations.iterator().next();
                assertEquals(clientInstanceImpl.getClientClusterService().getOwnerConnectionAddress(), registration.getSubscriber().getEndPoint());
            }
        }
    });
}
Also used : ClientEventRegistration(com.hazelcast.client.spi.impl.listener.ClientEventRegistration) Connection(com.hazelcast.nio.Connection) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) Member(com.hazelcast.core.Member)

Aggregations

ClientEventRegistration (com.hazelcast.client.spi.impl.listener.ClientEventRegistration)19 HazelcastInstance (com.hazelcast.core.HazelcastInstance)18 Node (com.hazelcast.instance.Node)18 ParallelTest (com.hazelcast.test.annotation.ParallelTest)18 QuickTest (com.hazelcast.test.annotation.QuickTest)18 Test (org.junit.Test)18 ItemListener (com.hazelcast.core.ItemListener)6 EntryListener (com.hazelcast.core.EntryListener)4 IMap (com.hazelcast.core.IMap)4 DistributedObjectListener (com.hazelcast.core.DistributedObjectListener)2 MessageListener (com.hazelcast.core.MessageListener)2 MultiMap (com.hazelcast.core.MultiMap)2 MapListener (com.hazelcast.map.listener.MapListener)2 MapPartitionLostListener (com.hazelcast.map.listener.MapPartitionLostListener)2 Member (com.hazelcast.core.Member)1 Connection (com.hazelcast.nio.Connection)1 AssertTask (com.hazelcast.test.AssertTask)1 Collection (java.util.Collection)1