use of com.hazelcast.core.LifecycleEvent in project hazelcast by hazelcast.
the class AbstractListenersOnReconnectTest method testListenersHeartbeatTimeoutToOwner.
private void testListenersHeartbeatTimeoutToOwner() {
setupListener();
HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
HazelcastInstance server = getOwnerServer(factory, clientInstanceImpl);
final CountDownLatch disconnectedLatch = new CountDownLatch(1);
final CountDownLatch connectedLatch = new CountDownLatch(1);
client.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (LifecycleEvent.LifecycleState.CLIENT_DISCONNECTED == event.getState()) {
disconnectedLatch.countDown();
}
if (LifecycleEvent.LifecycleState.CLIENT_CONNECTED == event.getState()) {
connectedLatch.countDown();
}
}
});
blockMessagesFromInstance(server, client);
assertOpenEventually(disconnectedLatch);
unblockMessagesFromInstance(server, client);
assertOpenEventually(connectedLatch);
validateRegistrationsAndListenerFunctionality();
}
use of com.hazelcast.core.LifecycleEvent in project hazelcast by hazelcast.
the class ClientInvocationTest method executionCallback_FailOnShutdown.
@Test
public void executionCallback_FailOnShutdown() {
HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final CountDownLatch disconnectedLatch = new CountDownLatch(1);
IMap<Object, Object> map = client.getMap(randomName());
client.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (event.getState() == LifecycleEvent.LifecycleState.CLIENT_DISCONNECTED) {
disconnectedLatch.countDown();
}
}
});
server.shutdown();
assertOpenEventually(disconnectedLatch);
int n = 100;
final CountDownLatch errorLatch = new CountDownLatch(n);
for (int i = 0; i < n; i++) {
try {
map.submitToKey(randomString(), new DummyEntryProcessor(), new ExecutionCallback() {
@Override
public void onResponse(Object response) {
}
@Override
public void onFailure(Throwable t) {
errorLatch.countDown();
}
});
} catch (Exception e) {
errorLatch.countDown();
}
}
assertOpenEventually("Not all of the requests failed", errorLatch);
}
use of com.hazelcast.core.LifecycleEvent in project hazelcast by hazelcast.
the class NodeQueryCacheContext method flushPublishersOnNodeShutdown.
/**
* This is a best effort approach; there is no guarantee that events in publishers internal buffers will be fired,
* {@link com.hazelcast.spi.EventService} can drop them.
*/
private void flushPublishersOnNodeShutdown() {
Node node = ((NodeEngineImpl) this.nodeEngine).getNode();
LifecycleServiceImpl lifecycleService = node.hazelcastInstance.getLifecycleService();
lifecycleService.addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (SHUTTING_DOWN == event.getState()) {
publisherContext.flush();
}
}
});
}
use of com.hazelcast.core.LifecycleEvent in project hazelcast by hazelcast.
the class ClientReconnectTest method testClientShutdownIfReconnectionNotPossible.
@Test
public void testClientShutdownIfReconnectionNotPossible() {
HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().setConnectionAttemptLimit(1);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
final CountDownLatch shutdownLatch = new CountDownLatch(1);
client.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (event.getState() == LifecycleEvent.LifecycleState.SHUTDOWN) {
shutdownLatch.countDown();
}
}
});
server.shutdown();
assertOpenEventually(shutdownLatch);
}
use of com.hazelcast.core.LifecycleEvent in project hazelcast by hazelcast.
the class ClientRegressionWithMockNetworkTest method testDeadlock_WhenDoingOperationFromLifecycleListener.
@Test
public void testDeadlock_WhenDoingOperationFromLifecycleListener() {
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
final ClientConfig clientConfig = new ClientConfig();
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig.setExecutorPoolSize(1));
hazelcastFactory.newHazelcastInstance();
final CountDownLatch latch = new CountDownLatch(1);
final IMap<Object, Object> map = client.getMap(randomMapName());
client.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (event.getState() == LifecycleState.CLIENT_DISCONNECTED) {
map.get(1);
latch.countDown();
}
}
});
instance.shutdown();
assertOpenEventually(latch);
}
Aggregations