Search in sources :

Example 31 with LifecycleListener

use of com.hazelcast.core.LifecycleListener in project hazelcast by hazelcast.

the class ClientTxnOwnerDisconnectedTest method testNewTransactionContextShouldFail_onDisconnectedState.

@Test(expected = TransactionException.class)
public void testNewTransactionContextShouldFail_onDisconnectedState() {
    Hazelcast.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
    clientConfig.setProperty(ClientProperty.INVOCATION_TIMEOUT_SECONDS.getName(), "3");
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    Hazelcast.newHazelcastInstance();
    final CountDownLatch clientDisconnected = new CountDownLatch(1);
    client.getLifecycleService().addLifecycleListener(new LifecycleListener() {

        @Override
        public void stateChanged(LifecycleEvent event) {
            clientDisconnected.countDown();
        }
    });
    Hazelcast.shutdownAll();
    assertOpenEventually(clientDisconnected);
    client.newTransactionContext();
}
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) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

LifecycleListener (com.hazelcast.core.LifecycleListener)31 CountDownLatch (java.util.concurrent.CountDownLatch)27 HazelcastInstance (com.hazelcast.core.HazelcastInstance)26 Test (org.junit.Test)24 LifecycleEvent (com.hazelcast.core.LifecycleEvent)23 ClientConfig (com.hazelcast.client.config.ClientConfig)18 ListenerConfig (com.hazelcast.config.ListenerConfig)14 Config (com.hazelcast.config.Config)12 QuickTest (com.hazelcast.test.annotation.QuickTest)12 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)8 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)5 NightlyTest (com.hazelcast.test.annotation.NightlyTest)5 SlowTest (com.hazelcast.test.annotation.SlowTest)4 Member (com.hazelcast.cluster.Member)3 MembershipListener (com.hazelcast.cluster.MembershipListener)3 JoinConfig (com.hazelcast.config.JoinConfig)3 NetworkConfig (com.hazelcast.config.NetworkConfig)3 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)3 AssertTask (com.hazelcast.test.AssertTask)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3