Search in sources :

Example 26 with ClientConfig

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

the class ClientNearCacheConfigTest method testSpecificNearCacheConfig_whenAsteriskInTheMiddle.

@Test
public void testSpecificNearCacheConfig_whenAsteriskInTheMiddle() {
    final ClientConfig clientConfig = new ClientConfig();
    final NearCacheConfig genericNearCacheConfig = new NearCacheConfig();
    genericNearCacheConfig.setName("map*Bar");
    clientConfig.addNearCacheConfig(genericNearCacheConfig);
    final NearCacheConfig specificNearCacheConfig = new NearCacheConfig();
    specificNearCacheConfig.setName("mapStudent*Bar");
    clientConfig.addNearCacheConfig(specificNearCacheConfig);
    final NearCacheConfig mapFoo = clientConfig.getNearCacheConfig("mapFooBar");
    final NearCacheConfig mapStudentFoo = clientConfig.getNearCacheConfig("mapStudentFooBar");
    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)

Example 27 with ClientConfig

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

the class ClientNearCacheConfigTest method testSpecificNearCacheConfig_whenAsteriskAtTheBeginning.

@Test
public void testSpecificNearCacheConfig_whenAsteriskAtTheBeginning() {
    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("fooMap");
    final NearCacheConfig mapStudentFoo = clientConfig.getNearCacheConfig("fooMapStudent");
    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)

Example 28 with ClientConfig

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

the class ClientAuthenticationTest method testAuthenticationWithCustomCredentials_when_singleNode.

@Test
public void testAuthenticationWithCustomCredentials_when_singleNode() {
    PortableFactory factory = new CustomCredentialsPortableFactory();
    // with this config, the server will authenticate any credential of type CustomCredentials
    Config config = new Config();
    config.getGroupConfig().setName(USERNAME).setPassword(PASSWORD);
    config.getSerializationConfig().addPortableFactory(1, factory);
    hazelcastFactory.newHazelcastInstance(config);
    ClientConfig clientConfig = new ClientConfig();
    // make sure there are no credentials sent over the wire
    clientConfig.getSecurityConfig().setCredentials(new CustomCredentials());
    hazelcastFactory.newHazelcastClient(clientConfig);
}
Also used : Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 29 with ClientConfig

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

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

the class ClientReconnectTest method testClientReconnectOnClusterDown.

@Test
public void testClientReconnectOnClusterDown() throws Exception {
    final HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().setConnectionAttemptLimit(Integer.MAX_VALUE);
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    final CountDownLatch connectedLatch = new CountDownLatch(2);
    client.getLifecycleService().addLifecycleListener(new LifecycleListener() {

        @Override
        public void stateChanged(LifecycleEvent event) {
            connectedLatch.countDown();
        }
    });
    IMap<String, String> m = client.getMap("default");
    h1.shutdown();
    hazelcastFactory.newHazelcastInstance();
    assertOpenEventually(connectedLatch);
    assertNull(m.put("test", "test"));
    assertEquals("test", m.get("test"));
}
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) 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