Search in sources :

Example 86 with ClientConfig

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

the class ClientReplicatedMapTest method getClientConfigWithNearCacheInvalidationEnabled.

private ClientConfig getClientConfigWithNearCacheInvalidationEnabled() {
    ClientConfig config = new ClientConfig();
    NearCacheConfig nnc = new NearCacheConfig();
    nnc.setInvalidateOnChange(true);
    nnc.setInMemoryFormat(InMemoryFormat.OBJECT);
    config.addNearCacheConfig(nnc);
    return config;
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 87 with ClientConfig

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

the class ClientReplicatedMapTest method testNearCacheInvalidation_withClear.

@Test
public void testNearCacheInvalidation_withClear() {
    hazelcastFactory.newHazelcastInstance();
    ClientConfig config = getClientConfigWithNearCacheInvalidationEnabled();
    HazelcastInstance client1 = hazelcastFactory.newHazelcastClient(config);
    HazelcastInstance client2 = hazelcastFactory.newHazelcastClient(config);
    String mapName = randomString();
    final ReplicatedMap<Integer, Integer> replicatedMap1 = client1.getReplicatedMap(mapName);
    replicatedMap1.put(1, 1);
    // puts key 1 to Near Cache
    replicatedMap1.get(1);
    ReplicatedMap replicatedMap2 = client2.getReplicatedMap(mapName);
    // this should invalidate Near Cache of replicatedMap1
    replicatedMap2.clear();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(null, replicatedMap1.get(1));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) ReplicatedMap(com.hazelcast.core.ReplicatedMap) ClientConfig(com.hazelcast.client.config.ClientConfig) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 88 with ClientConfig

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

the class ClientReplicatedMapTest method testNearCacheInvalidation.

@Test
public void testNearCacheInvalidation() {
    String mapName = randomString();
    ClientConfig config = getClientConfigWithNearCacheInvalidationEnabled();
    hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client1 = hazelcastFactory.newHazelcastClient(config);
    HazelcastInstance client2 = hazelcastFactory.newHazelcastClient(config);
    final ReplicatedMap<Integer, Integer> replicatedMap1 = client1.getReplicatedMap(mapName);
    replicatedMap1.put(1, 1);
    // puts key 1 to Near Cache
    replicatedMap1.get(1);
    ReplicatedMap<Integer, Integer> replicatedMap2 = client2.getReplicatedMap(mapName);
    // this should invalidate Near Cache of replicatedMap1
    replicatedMap2.put(1, 2);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(2, (int) replicatedMap1.get(1));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 89 with ClientConfig

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

the class ClientReplicatedMapTest method testClientPortableWithoutRegisteringToNode.

@Test
public void testClientPortableWithoutRegisteringToNode() {
    hazelcastFactory.newHazelcastInstance(buildConfig(InMemoryFormat.BINARY, 0));
    SerializationConfig serializationConfig = new SerializationConfig();
    serializationConfig.addPortableFactory(5, new PortableFactory() {

        public Portable create(int classId) {
            return new SamplePortable();
        }
    });
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setSerializationConfig(serializationConfig);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    ReplicatedMap<Integer, SamplePortable> sampleMap = client.getReplicatedMap(randomString());
    sampleMap.put(1, new SamplePortable(666));
    SamplePortable samplePortable = sampleMap.get(1);
    assertEquals(666, samplePortable.a);
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SerializationConfig(com.hazelcast.config.SerializationConfig) 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 90 with ClientConfig

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

the class QuorumTestUtil method getClientConfig.

public static ClientConfig getClientConfig(HazelcastInstance instance) {
    ClientConfig clientConfig = new ClientConfig();
    Address address = getNode(instance).address;
    clientConfig.getNetworkConfig().addAddress(address.getHost() + ":" + address.getPort());
    clientConfig.getGroupConfig().setName(instance.getConfig().getGroupConfig().getName());
    return clientConfig;
}
Also used : Address(com.hazelcast.nio.Address) ClientConfig(com.hazelcast.client.config.ClientConfig)

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