Search in sources :

Example 26 with EventService

use of com.hazelcast.spi.impl.eventservice.EventService in project hazelcast by hazelcast.

the class ListenerTest method testMapPartitionLostListener_registeredViaImplementationInConfigObject.

@Test
public void testMapPartitionLostListener_registeredViaImplementationInConfigObject() {
    final String name = randomString();
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(name);
    MapPartitionLostListener listener = mock(MapPartitionLostListener.class);
    mapConfig.addMapPartitionLostListenerConfig(new MapPartitionLostListenerConfig(listener));
    mapConfig.setBackupCount(0);
    HazelcastInstance instance = createHazelcastInstance(config);
    instance.getMap(name);
    final EventService eventService = getNode(instance).getNodeEngine().getEventService();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            final Collection<EventRegistration> registrations = eventService.getRegistrations(MapService.SERVICE_NAME, name);
            assertFalse(registrations.isEmpty());
        }
    });
}
Also used : MapPartitionLostListener(com.hazelcast.map.listener.MapPartitionLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) EventService(com.hazelcast.spi.impl.eventservice.EventService) MapConfig(com.hazelcast.config.MapConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 27 with EventService

use of com.hazelcast.spi.impl.eventservice.EventService in project hazelcast by hazelcast.

the class EventServiceTest method test_deregistration_whileNewMemberJoining.

@Test
public void test_deregistration_whileNewMemberJoining() throws Exception {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance hz1 = factory.newHazelcastInstance(newConfigWithDummyService());
    HazelcastInstance hz2 = factory.newHazelcastInstance(newConfigWithDummyService());
    EventService eventService = getEventService(hz2);
    Set<UUID> registrationIds = new HashSet<UUID>();
    Object listener = new Object();
    for (int i = 0; i < 500; i++) {
        EventRegistration registration = eventService.registerListener(serviceName, topic, listener);
        registrationIds.add(registration.getId());
    }
    Future<HazelcastInstance> future = spawn(() -> factory.newHazelcastInstance(newConfigWithDummyService()));
    for (UUID registrationId : registrationIds) {
        eventService.deregisterListener(serviceName, topic, registrationId);
    }
    assertThat(eventService.getRegistrations(serviceName, topic), Matchers.empty());
    HazelcastInstance hz3 = future.get();
    EventService eventService3 = getEventService(hz3);
    assertThat(eventService3.getRegistrations(serviceName, topic), Matchers.empty());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService) UUID(java.util.UUID) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 28 with EventService

use of com.hazelcast.spi.impl.eventservice.EventService in project hazelcast by hazelcast.

the class BasicClusterStateTest method assertRegistrationsSizeEventually.

private void assertRegistrationsSizeEventually(final HazelcastInstance instance, final String serviceName, final String topic, final int size) {
    assertTrueEventually(() -> {
        EventService eventService = getNode(instance).getNodeEngine().getEventService();
        Collection<EventRegistration> registrations = eventService.getRegistrations(serviceName, topic);
        assertEquals(size, registrations.size());
    });
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 29 with EventService

use of com.hazelcast.spi.impl.eventservice.EventService in project hazelcast by hazelcast.

the class ClientMapIssueTest method testListenerRegistrations.

@Test
public void testListenerRegistrations() {
    Config config = getConfig();
    ClientConfig clientConfig = getClientConfig();
    HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    final String mapName = randomMapName();
    IMap<Object, Object> map = client.getMap(mapName);
    map.addEntryListener(new EntryAdapter<>(), true);
    HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance(config);
    instance1.getLifecycleService().terminate();
    instance1 = hazelcastFactory.newHazelcastInstance(config);
    final EventService eventService1 = getNodeEngineImpl(instance1).getEventService();
    final EventService eventService2 = getNodeEngineImpl(instance2).getEventService();
    assertTrueEventually(() -> {
        Collection<EventRegistration> regs1 = eventService1.getRegistrations(MapService.SERVICE_NAME, mapName);
        Collection<EventRegistration> regs2 = eventService2.getRegistrations(MapService.SERVICE_NAME, mapName);
        assertEquals("there should be only one registration", 1, regs1.size());
        assertEquals("there should be only one registration", 1, regs2.size());
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) EventService(com.hazelcast.spi.impl.eventservice.EventService) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 30 with EventService

use of com.hazelcast.spi.impl.eventservice.EventService in project hazelcast by hazelcast.

the class ClientMapPartitionLostListenerTest method assertRegistrationEventually.

private static void assertRegistrationEventually(final HazelcastInstance instance, final String mapName, final boolean shouldBeRegistered) {
    final EventService eventService = getNode(instance).getNodeEngine().getEventService();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            boolean registered = false;
            for (EventRegistration registration : eventService.getRegistrations(SERVICE_NAME, mapName)) {
                if (registration.getFilter() instanceof MapPartitionLostEventFilter) {
                    registered = true;
                    break;
                }
            }
            if (shouldBeRegistered != registered) {
                fail("shouldBeRegistered: " + shouldBeRegistered + " registered: " + registered);
            }
        }
    });
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) MapPartitionLostEventFilter(com.hazelcast.map.impl.MapPartitionLostEventFilter) AssertTask(com.hazelcast.test.AssertTask) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Aggregations

EventService (com.hazelcast.spi.impl.eventservice.EventService)67 EventRegistration (com.hazelcast.spi.impl.eventservice.EventRegistration)45 UUID (java.util.UUID)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 Address (com.hazelcast.cluster.Address)4 Config (com.hazelcast.config.Config)4 Data (com.hazelcast.internal.serialization.Data)4 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)4 CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)3 MapEventData (com.hazelcast.map.impl.event.MapEventData)3 AssertTask (com.hazelcast.test.AssertTask)3 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)2 CachePartitionLostListener (com.hazelcast.cache.impl.event.CachePartitionLostListener)2 ItemListener (com.hazelcast.collection.ItemListener)2 DistributedObject (com.hazelcast.core.DistributedObject)2 Nonnull (javax.annotation.Nonnull)2 CacheEventType (com.hazelcast.cache.CacheEventType)1