Search in sources :

Example 11 with ClientConfig

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

the class ClientServiceTest method testNumberOfClients_afterUnAuthenticatedClient.

@Test(timeout = 120000)
public void testNumberOfClients_afterUnAuthenticatedClient() {
    final HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.getGroupConfig().setPassword("wrongPassword");
    try {
        hazelcastFactory.newHazelcastClient(clientConfig);
    } catch (IllegalStateException ignored) {
    }
    assertEquals(0, instance.getClientService().getConnectedClients().size());
}
Also used : 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 12 with ClientConfig

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

the class ClientServiceTest method testConnectedClientsWithReAuth.

@Test(timeout = 120000)
public void testConnectedClientsWithReAuth() throws InterruptedException {
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().setConnectionAttemptPeriod(1000 * 5);
    clientConfig.getNetworkConfig().setConnectionAttemptLimit(Integer.MAX_VALUE);
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    clientConfig.addListenerConfig(new ListenerConfig(new LifecycleListener() {

        @Override
        public void stateChanged(LifecycleEvent event) {
            if (event.getState() == LifecycleEvent.LifecycleState.CLIENT_CONNECTED) {
                countDownLatch.countDown();
            }
        }
    }));
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    //restart the node
    instance.shutdown();
    final HazelcastInstance restartedInstance = hazelcastFactory.newHazelcastInstance();
    // do any operation
    client.getMap(randomMapName()).size();
    //wait for clients to reconnect & reAuth
    assertOpenEventually(countDownLatch);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, restartedInstance.getClientService().getConnectedClients().size());
        }
    });
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) LifecycleEvent(com.hazelcast.core.LifecycleEvent) AssertTask(com.hazelcast.test.AssertTask) LifecycleListener(com.hazelcast.core.LifecycleListener) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) UnknownHostException(java.net.UnknownHostException) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with ClientConfig

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

the class ClientTimeoutTest method testTimeoutToOutsideNetwork.

@Test(timeout = 20000, expected = IllegalStateException.class)
public void testTimeoutToOutsideNetwork() throws Exception {
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getGroupConfig().setName("dev").setPassword("dev-pass");
    clientConfig.getNetworkConfig().addAddress("8.8.8.8:5701");
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    IList<Object> list = client.getList("test");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with ClientConfig

use of com.hazelcast.client.config.ClientConfig 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 15 with ClientConfig

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

the class ClientRegressionWithMockNetworkTest method testNearCache_shutdownClient.

@Test
public void testNearCache_shutdownClient() {
    final ClientConfig clientConfig = new ClientConfig();
    NearCacheConfig invalidateConfig = new NearCacheConfig();
    final String mapName = randomMapName();
    invalidateConfig.setName(mapName);
    invalidateConfig.setInvalidateOnChange(true);
    clientConfig.addNearCacheConfig(invalidateConfig);
    hazelcastFactory.newHazelcastInstance();
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    final IMap<Integer, Integer> map = client.getMap(mapName);
    map.get(1);
    //test should finish without throwing any exception.
    client.shutdown();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheConfig(com.hazelcast.config.NearCacheConfig) 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)

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