Search in sources :

Example 21 with ClientConfig

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

the class ClientRegressionWithRealNetworkTest method testClientPortConnection.

@Test
public void testClientPortConnection() {
    final Config config1 = new Config();
    config1.getGroupConfig().setName("foo");
    config1.getNetworkConfig().setPort(5701);
    final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config1);
    instance1.getMap("map").put("key", "value");
    final Config config2 = new Config();
    config2.getGroupConfig().setName("bar");
    config2.getNetworkConfig().setPort(5702);
    HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config2);
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.getGroupConfig().setName("bar");
    final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    final IMap<Object, Object> map = client.getMap("map");
    assertNull(map.put("key", "value"));
    assertEquals(1, map.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with ClientConfig

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

the class ClientServiceTest method testNumberOfClients_afterUnAuthenticatedClient_withTwoNode.

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

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

the class ClientMaxAllowedInvocationTest method testMaxAllowed_withUnfinishedCallback.

@Test(expected = HazelcastOverloadException.class)
public void testMaxAllowed_withUnfinishedCallback() throws ExecutionException, InterruptedException {
    int MAX_ALLOWED = 10;
    hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty(ClientProperty.MAX_CONCURRENT_INVOCATIONS.getName(), String.valueOf(MAX_ALLOWED));
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    String name = randomString();
    IMap map = client.getMap(name);
    IExecutorService executorService = client.getExecutorService(randomString());
    for (int i = 0; i < MAX_ALLOWED - 1; i++) {
        executorService.submit(new SleepyProcessor(Integer.MAX_VALUE));
    }
    ClientDelegatingFuture future = (ClientDelegatingFuture) executorService.submit(new SleepyProcessor(2000));
    CountDownLatch countDownLatch = new CountDownLatch(1);
    future.andThenInternal(new SleepyCallback(countDownLatch), false);
    future.get();
    try {
        map.get(1);
    } catch (HazelcastOverloadException e) {
        throw e;
    } finally {
        countDownLatch.countDown();
    }
}
Also used : IMap(com.hazelcast.core.IMap) ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastOverloadException(com.hazelcast.core.HazelcastOverloadException) IExecutorService(com.hazelcast.core.IExecutorService) 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 24 with ClientConfig

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

the class ClientMaxAllowedInvocationTest method testMaxAllowed_withSyncOperation.

@Test(expected = HazelcastOverloadException.class)
public void testMaxAllowed_withSyncOperation() {
    int MAX_ALLOWED = 10;
    hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty(ClientProperty.MAX_CONCURRENT_INVOCATIONS.getName(), String.valueOf(MAX_ALLOWED));
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    IMap map = client.getMap(randomString());
    IExecutorService executorService = client.getExecutorService(randomString());
    for (int i = 0; i < MAX_ALLOWED; i++) {
        executorService.submit(new SleepyProcessor(Integer.MAX_VALUE));
    }
    map.get(2);
}
Also used : IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IExecutorService(com.hazelcast.core.IExecutorService) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 25 with ClientConfig

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

the class ClientNearCacheConfigTest method testSpecificNearCacheConfig_whenAsteriskAtTheEnd.

@Test
public void testSpecificNearCacheConfig_whenAsteriskAtTheEnd() {
    final ClientConfig clientConfig = new ClientConfig();
    final NearCacheConfig genericNearCacheConfig = new NearCacheConfig();
    genericNearCacheConfig.setName("map*");
    clientConfig.addNearCacheConfig(genericNearCacheConfig);
    final NearCacheConfig specificNearCacheConfig = new NearCacheConfig();
    specificNearCacheConfig.setName("mapStudent*");
    clientConfig.addNearCacheConfig(specificNearCacheConfig);
    final NearCacheConfig mapFoo = clientConfig.getNearCacheConfig("mapFoo");
    final NearCacheConfig mapStudentFoo = clientConfig.getNearCacheConfig("mapStudentFoo");
    assertEquals(genericNearCacheConfig, mapFoo);
    assertEquals(specificNearCacheConfig, mapStudentFoo);
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) 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