Search in sources :

Example 16 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientRegressionWithMockNetworkTest method testOperationRedo.

@Test(timeout = 60000)
public void testOperationRedo() throws Exception {
    final HazelcastInstance hz1 = hazelcastFactory.newHazelcastInstance();
    hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().setRedoOperation(true);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    final Thread thread = new Thread() {

        public void run() {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            hz1.getLifecycleService().shutdown();
        }
    };
    final IMap map = client.getMap("m");
    thread.start();
    int expected = 1000;
    for (int i = 0; i < expected; i++) {
        map.put(i, "item" + i);
    }
    thread.join();
    assertEquals(expected, map.size());
}
Also used : IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientRegressionWithMockNetworkTest method testLock_WhenClientAndOwnerNodeDiesTogether.

private void testLock_WhenClientAndOwnerNodeDiesTogether(boolean smart) throws InterruptedException {
    hazelcastFactory.newHazelcastInstance();
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().setSmartRouting(smart);
    final int tryCount = 5;
    for (int i = 0; i < tryCount; i++) {
        final HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
        final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
        final ILock lock = client.getLock("lock");
        assertTrue(lock.tryLock(1, TimeUnit.MINUTES));
        //with client is dead, lock should be released.
        client.getLifecycleService().terminate();
        instance.getLifecycleService().terminate();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) ILock(com.hazelcast.core.ILock)

Example 18 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientRegressionWithMockNetworkTest method testDeadlock_WhenDoingOperationFromLifecycleListenerWithInitialPartitionTable.

@Test
public void testDeadlock_WhenDoingOperationFromLifecycleListenerWithInitialPartitionTable() {
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    final ClientConfig clientConfig = new ClientConfig();
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig.setExecutorPoolSize(1));
    hazelcastFactory.newHazelcastInstance();
    final CountDownLatch latch = new CountDownLatch(1);
    final IMap<Object, Object> map = client.getMap(randomMapName());
    // Let the partition table retrieved the first time
    map.get(1);
    client.getLifecycleService().addLifecycleListener(new LifecycleListener() {

        @Override
        public void stateChanged(LifecycleEvent event) {
            if (event.getState() == LifecycleState.CLIENT_DISCONNECTED) {
                for (int i = 0; i < 1000; i++) {
                    map.get(i);
                }
                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)

Example 19 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientRegressionWithMockNetworkTest method testMemberAddedWithListeners_thenCheckOperationsNotHanging.

@Test(timeout = 120000)
public void testMemberAddedWithListeners_thenCheckOperationsNotHanging() throws Exception {
    hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty(ClientExecutionServiceImpl.INTERNAL_EXECUTOR_POOL_SIZE.getName(), "1");
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    IMap map = client.getMap("map");
    map.addEntryListener(mock(MapListener.class), true);
    HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance();
    String key = generateKeyOwnedBy(h2);
    map.get(key);
}
Also used : IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapListener(com.hazelcast.map.listener.MapListener) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 20 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientRegressionWithRealNetworkTest method testClientConnectionBeforeServerReady.

@Test
public void testClientConnectionBeforeServerReady() throws InterruptedException {
    ExecutorService executorService = Executors.newFixedThreadPool(2);
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            Hazelcast.newHazelcastInstance();
        }
    });
    final CountDownLatch clientLatch = new CountDownLatch(1);
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            ClientConfig config = new ClientConfig();
            config.getNetworkConfig().setConnectionAttemptLimit(10);
            HazelcastInstance client = HazelcastClient.newHazelcastClient(config);
            clientLatch.countDown();
        }
    });
    assertOpenEventually(clientLatch);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ClientConfig (com.hazelcast.client.config.ClientConfig)214 Test (org.junit.Test)129 HazelcastInstance (com.hazelcast.core.HazelcastInstance)110 QuickTest (com.hazelcast.test.annotation.QuickTest)107 ParallelTest (com.hazelcast.test.annotation.ParallelTest)81 Config (com.hazelcast.config.Config)45 NearCacheConfig (com.hazelcast.config.NearCacheConfig)32 NightlyTest (com.hazelcast.test.annotation.NightlyTest)32 CountDownLatch (java.util.concurrent.CountDownLatch)25 AssertTask (com.hazelcast.test.AssertTask)20 Before (org.junit.Before)20 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)16 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)15 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)13 CachingProvider (javax.cache.spi.CachingProvider)13 IMap (com.hazelcast.core.IMap)12 LifecycleListener (com.hazelcast.core.LifecycleListener)12 LifecycleEvent (com.hazelcast.core.LifecycleEvent)11 Data (com.hazelcast.nio.serialization.Data)11 NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)10