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());
}
});
}
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());
}
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());
});
}
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());
});
}
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);
}
}
});
}
Aggregations