Search in sources :

Example 11 with LifecycleEvent

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();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) LifecycleEvent(com.hazelcast.core.LifecycleEvent) LifecycleListener(com.hazelcast.core.LifecycleListener) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 12 with LifecycleEvent

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) LifecycleEvent(com.hazelcast.core.LifecycleEvent) LifecycleListener(com.hazelcast.core.LifecycleListener) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with LifecycleEvent

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();
            }
        }
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Node(com.hazelcast.instance.Node) LifecycleEvent(com.hazelcast.core.LifecycleEvent) LifecycleListener(com.hazelcast.core.LifecycleListener) LifecycleServiceImpl(com.hazelcast.instance.LifecycleServiceImpl)

Example 14 with LifecycleEvent

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) LifecycleEvent(com.hazelcast.core.LifecycleEvent) LifecycleListener(com.hazelcast.core.LifecycleListener) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with LifecycleEvent

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) LifecycleEvent(com.hazelcast.core.LifecycleEvent) DistributedObject(com.hazelcast.core.DistributedObject) LifecycleListener(com.hazelcast.core.LifecycleListener) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

LifecycleEvent (com.hazelcast.core.LifecycleEvent)25 LifecycleListener (com.hazelcast.core.LifecycleListener)25 HazelcastInstance (com.hazelcast.core.HazelcastInstance)22 CountDownLatch (java.util.concurrent.CountDownLatch)22 Test (org.junit.Test)20 ClientConfig (com.hazelcast.client.config.ClientConfig)13 ParallelTest (com.hazelcast.test.annotation.ParallelTest)13 QuickTest (com.hazelcast.test.annotation.QuickTest)13 NightlyTest (com.hazelcast.test.annotation.NightlyTest)9 Config (com.hazelcast.config.Config)8 ListenerConfig (com.hazelcast.config.ListenerConfig)6 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)5 AssertTask (com.hazelcast.test.AssertTask)5 JoinConfig (com.hazelcast.config.JoinConfig)3 NetworkConfig (com.hazelcast.config.NetworkConfig)3 DistributedObject (com.hazelcast.core.DistributedObject)3 ExecutionException (java.util.concurrent.ExecutionException)3 LifecycleService (com.hazelcast.core.LifecycleService)2 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance)2 Node (com.hazelcast.instance.Node)2