Search in sources :

Example 6 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class ClientServiceTest method testClientListenerDisconnected.

@Test(timeout = 120000)
public void testClientListenerDisconnected() throws InterruptedException {
    Config config = new Config();
    config.setProperty(GroupProperty.IO_THREAD_COUNT.getName(), "1");
    final HazelcastInstance hz = hazelcastFactory.newHazelcastInstance(config);
    final HazelcastInstance hz2 = hazelcastFactory.newHazelcastInstance(config);
    int clientCount = 10;
    ClientDisconnectedListenerLatch listenerLatch = new ClientDisconnectedListenerLatch(2 * clientCount);
    hz.getClientService().addClientListener(listenerLatch);
    hz2.getClientService().addClientListener(listenerLatch);
    Collection<HazelcastInstance> clients = new LinkedList<HazelcastInstance>();
    for (int i = 0; i < clientCount; i++) {
        HazelcastInstance client = hazelcastFactory.newHazelcastClient();
        IMap<Object, Object> map = client.getMap(randomMapName());
        map.addEntryListener(new EntryAdapter<Object, Object>(), true);
        map.put(generateKeyOwnedBy(hz), "value");
        map.put(generateKeyOwnedBy(hz2), "value");
        clients.add(client);
    }
    ExecutorService ex = Executors.newFixedThreadPool(4);
    try {
        for (final HazelcastInstance client : clients) {
            ex.execute(new Runnable() {

                @Override
                public void run() {
                    client.shutdown();
                }
            });
        }
        assertOpenEventually(listenerLatch);
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() throws Exception {
                assertEquals(0, hz.getClientService().getConnectedClients().size());
            }
        });
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() throws Exception {
                assertEquals(0, hz2.getClientService().getConnectedClients().size());
            }
        });
    } finally {
        ex.shutdown();
    }
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) LinkedList(java.util.LinkedList) UnknownHostException(java.net.UnknownHostException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorService(java.util.concurrent.ExecutorService) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class ClientSplitBrainTest method checkEventsEventually.

private void checkEventsEventually(final AtomicBoolean[] listenerGotEventFlags) {
    for (int i = 0; i < listenerGotEventFlags.length; i++) {
        final int id = i;
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() throws Exception {
                assertTrue("listener id " + id, listenerGotEventFlags[id].get());
            }
        });
    }
}
Also used : AssertTask(com.hazelcast.test.AssertTask)

Example 8 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class ClientRegressionWithMockNetworkTest method testNearCache_WhenRegisteredNodeIsDead.

@Test
public void testNearCache_WhenRegisteredNodeIsDead() {
    final HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().setConnectionAttemptLimit(Integer.MAX_VALUE);
    final String mapName = randomMapName();
    NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setName(mapName);
    nearCacheConfig.setInvalidateOnChange(true);
    clientConfig.addNearCacheConfig(nearCacheConfig);
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    final IMap<Object, Object> map = client.getMap(mapName);
    map.put("a", "b");
    // populate Near Cache
    map.get("a");
    instance.shutdown();
    hazelcastFactory.newHazelcastInstance();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(null, map.get("a"));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheConfig(com.hazelcast.config.NearCacheConfig) AssertTask(com.hazelcast.test.AssertTask) DistributedObject(com.hazelcast.core.DistributedObject) ClientConfig(com.hazelcast.client.config.ClientConfig) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class ClientOwnershipTest method test_ownerShip_afterClusterRestart.

@Test
public void test_ownerShip_afterClusterRestart() {
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().setConnectionAttemptLimit(Integer.MAX_VALUE);
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    instance.shutdown();
    final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
    // wait for client to connect to node
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, client.getCluster().getMembers().size());
            assertEquals(1, instance2.getCluster().getMembers().size());
        }
    });
    final String instanceUuid = instance2.getLocalEndpoint().getUuid();
    final ClientEngineImpl clientEngine2 = getClientEngineImpl(instance2);
    final String clientUuid = client.getLocalEndpoint().getUuid();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(instanceUuid, clientEngine2.getOwnerUuid(clientUuid));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientEngineImpl(com.hazelcast.client.impl.ClientEngineImpl) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class ClientOwnershipTest method test_clientOwnedInfoPropagatedToAllMembers.

@Test
public void test_clientOwnedInfoPropagatedToAllMembers() {
    HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
    final String instanceUuid = instance1.getLocalEndpoint().getUuid();
    final String clientUuid = client.getLocalEndpoint().getUuid();
    final ClientEngineImpl clientEngine1 = getClientEngineImpl(instance1);
    final ClientEngineImpl clientEngine2 = getClientEngineImpl(instance2);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(instanceUuid, clientEngine1.getOwnerUuid(clientUuid));
            assertEquals(instanceUuid, clientEngine2.getOwnerUuid(clientUuid));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientEngineImpl(com.hazelcast.client.impl.ClientEngineImpl) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

AssertTask (com.hazelcast.test.AssertTask)575 Test (org.junit.Test)489 QuickTest (com.hazelcast.test.annotation.QuickTest)428 ParallelTest (com.hazelcast.test.annotation.ParallelTest)347 HazelcastInstance (com.hazelcast.core.HazelcastInstance)263 Config (com.hazelcast.config.Config)113 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)94 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)75 ExecutionException (java.util.concurrent.ExecutionException)57 MapConfig (com.hazelcast.config.MapConfig)49 NightlyTest (com.hazelcast.test.annotation.NightlyTest)48 IOException (java.io.IOException)46 CountDownLatch (java.util.concurrent.CountDownLatch)42 IMap (com.hazelcast.core.IMap)39 NearCacheConfig (com.hazelcast.config.NearCacheConfig)38 TimeoutException (java.util.concurrent.TimeoutException)33 ClientConfig (com.hazelcast.client.config.ClientConfig)32 MapStoreConfig (com.hazelcast.config.MapStoreConfig)29 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)23 AtomicReference (java.util.concurrent.atomic.AtomicReference)20