Search in sources :

Example 1 with ClientConnectionRegistration

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

the class AbstractListenersOnReconnectTest method validateRegistrations.

private void validateRegistrations(final int clusterSize, final UUID registrationId, final HazelcastClientInstanceImpl clientInstanceImpl) {
    final boolean smartRouting = clientInstanceImpl.getClientConfig().getNetworkConfig().isSmartRouting();
    assertTrueEventually(() -> {
        int size = smartRouting ? clusterSize : 1;
        Map<Connection, ClientConnectionRegistration> registrations = getClientEventRegistrations(client, registrationId);
        assertEquals(size, registrations.size());
        if (smartRouting) {
            Collection<Member> members = clientInstanceImpl.getClientClusterService().getMemberList();
            for (Connection registeredSubscriber : registrations.keySet()) {
                boolean contains = false;
                for (Member member : members) {
                    contains |= registeredSubscriber.getRemoteAddress().equals(member.getAddress());
                }
                assertTrue("Registered member " + registeredSubscriber + " is not in the cluster member list " + members, contains);
            }
        } else {
            Iterator<Connection> expectedIterator = registrations.keySet().iterator();
            assertTrue(expectedIterator.hasNext());
            Iterator<Connection> iterator = clientInstanceImpl.getConnectionManager().getActiveConnections().iterator();
            assertTrue(iterator.hasNext());
            assertEquals(iterator.next(), expectedIterator.next());
        }
    });
}
Also used : Connection(com.hazelcast.internal.nio.Connection) Member(com.hazelcast.cluster.Member) ClientConnectionRegistration(com.hazelcast.client.impl.spi.impl.listener.ClientConnectionRegistration)

Example 2 with ClientConnectionRegistration

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

the class ListenerLeakTest method testMapEntryListeners.

@Test
public void testMapEntryListeners() {
    Collection<Node> nodes = createNodes();
    HazelcastInstance client = newHazelcastClient();
    IMap map = client.getMap(randomString());
    UUID id = map.addEntryListener(mock(MapListener.class), false);
    Collection<ClientConnectionRegistration> registrations = getClientEventRegistrations(client, id);
    assertTrue(map.removeEntryListener(id));
    assertNoLeftOver(nodes, client, id, registrations);
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapListener(com.hazelcast.map.listener.MapListener) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) UUID(java.util.UUID) ClientConnectionRegistration(com.hazelcast.client.impl.spi.impl.listener.ClientConnectionRegistration) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with ClientConnectionRegistration

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

the class ListenerLeakTest method testDistributedObjectListeners.

@Test
public void testDistributedObjectListeners() {
    Collection<Node> nodes = createNodes();
    HazelcastInstance client = newHazelcastClient();
    UUID id = client.addDistributedObjectListener(mock(DistributedObjectListener.class));
    Collection<ClientConnectionRegistration> registrations = getClientEventRegistrations(client, id);
    assertTrue(client.removeDistributedObjectListener(id));
    assertNoLeftOver(nodes, client, id, registrations);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) UUID(java.util.UUID) DistributedObjectListener(com.hazelcast.core.DistributedObjectListener) ClientConnectionRegistration(com.hazelcast.client.impl.spi.impl.listener.ClientConnectionRegistration) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with ClientConnectionRegistration

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

the class ListenerLeakTest method testTopicMessageListener.

@Test
public void testTopicMessageListener() {
    Collection<Node> nodes = createNodes();
    HazelcastInstance client = newHazelcastClient();
    ITopic<Object> topic = client.getTopic(randomString());
    UUID id = topic.addMessageListener(mock(MessageListener.class));
    Collection<ClientConnectionRegistration> registrations = getClientEventRegistrations(client, id);
    assertTrue(topic.removeMessageListener(id));
    assertNoLeftOver(nodes, client, id, registrations);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) MessageListener(com.hazelcast.topic.MessageListener) UUID(java.util.UUID) ClientConnectionRegistration(com.hazelcast.client.impl.spi.impl.listener.ClientConnectionRegistration) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with ClientConnectionRegistration

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

the class ListenerLeakTest method testMapPartitionLostListeners.

@Test
public void testMapPartitionLostListeners() {
    Collection<Node> nodes = createNodes();
    HazelcastInstance client = newHazelcastClient();
    IMap map = client.getMap(randomString());
    UUID id = map.addPartitionLostListener(mock(MapPartitionLostListener.class));
    Collection<ClientConnectionRegistration> registrations = getClientEventRegistrations(client, id);
    assertTrue(map.removePartitionLostListener(id));
    assertNoLeftOver(nodes, client, id, registrations);
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapPartitionLostListener(com.hazelcast.map.listener.MapPartitionLostListener) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) UUID(java.util.UUID) ClientConnectionRegistration(com.hazelcast.client.impl.spi.impl.listener.ClientConnectionRegistration) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ClientConnectionRegistration (com.hazelcast.client.impl.spi.impl.listener.ClientConnectionRegistration)10 HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 Node (com.hazelcast.instance.impl.Node)9 Accessors.getNode (com.hazelcast.test.Accessors.getNode)9 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 UUID (java.util.UUID)9 Test (org.junit.Test)9 ItemListener (com.hazelcast.collection.ItemListener)3 EntryListener (com.hazelcast.core.EntryListener)2 IMap (com.hazelcast.map.IMap)2 Member (com.hazelcast.cluster.Member)1 DistributedObjectListener (com.hazelcast.core.DistributedObjectListener)1 Connection (com.hazelcast.internal.nio.Connection)1 MapListener (com.hazelcast.map.listener.MapListener)1 MapPartitionLostListener (com.hazelcast.map.listener.MapPartitionLostListener)1 MultiMap (com.hazelcast.multimap.MultiMap)1 MessageListener (com.hazelcast.topic.MessageListener)1