Search in sources :

Example 1 with ReplicatedMap

use of com.hazelcast.replicatedmap.ReplicatedMap in project hazelcast by hazelcast.

the class ClientReplicatedMapTest method testAdd.

@Test
public void testAdd() {
    HazelcastInstance instance1 = factory.newHazelcastInstance(config);
    HazelcastInstance instance2 = factory.newHazelcastClient();
    final ReplicatedMap<String, String> map1 = instance1.getReplicatedMap("default");
    final ReplicatedMap<String, String> map2 = instance2.getReplicatedMap("default");
    for (int i = 0; i < OPERATION_COUNT; i++) {
        map1.put("foo-" + i, "bar");
    }
    for (Map.Entry<String, String> entry : map2.entrySet()) {
        assertStartsWith("foo-", entry.getKey());
        assertEquals("bar", entry.getValue());
    }
    for (Map.Entry<String, String> entry : map1.entrySet()) {
        assertStartsWith("foo-", entry.getKey());
        assertEquals("bar", entry.getValue());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Map(java.util.Map) ReplicatedMap(com.hazelcast.replicatedmap.ReplicatedMap) HashMap(java.util.HashMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with ReplicatedMap

use of com.hazelcast.replicatedmap.ReplicatedMap in project hazelcast by hazelcast.

the class ClientReplicatedMapTest method remove_empties_internal_ttl_schedulers.

@Test
public void remove_empties_internal_ttl_schedulers() {
    String mapName = "test";
    HazelcastInstance node = factory.newHazelcastInstance(config);
    HazelcastInstance client = factory.newHazelcastClient();
    ReplicatedMap map = client.getReplicatedMap(mapName);
    for (int i = 0; i < 1000; i++) {
        map.put(i, i, 100, TimeUnit.DAYS);
    }
    for (int i = 0; i < 1000; i++) {
        map.remove(i);
    }
    assertAllTtlSchedulersEmpty(node.getReplicatedMap(mapName));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ReplicatedMap(com.hazelcast.replicatedmap.ReplicatedMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with ReplicatedMap

use of com.hazelcast.replicatedmap.ReplicatedMap in project hazelcast by hazelcast.

the class ClientReplicatedMapTest method testNearCacheInvalidation_withClear.

@Test
public void testNearCacheInvalidation_withClear() {
    String mapName = randomString();
    ClientConfig clientConfig = getClientConfigWithNearCacheInvalidationEnabled();
    factory.newHazelcastInstance(config);
    HazelcastInstance client1 = factory.newHazelcastClient(clientConfig);
    HazelcastInstance client2 = factory.newHazelcastClient(clientConfig);
    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 {
            assertNull(replicatedMap1.get(1));
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) ReplicatedMap(com.hazelcast.replicatedmap.ReplicatedMap) ClientConfig(com.hazelcast.client.config.ClientConfig) IOException(java.io.IOException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with ReplicatedMap

use of com.hazelcast.replicatedmap.ReplicatedMap in project hazelcast by hazelcast.

the class DummyClientReplicatedMapTest method testEntrySet.

@Test
public void testEntrySet() throws Exception {
    HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig(instance1));
    final ReplicatedMap<String, String> map = client.getReplicatedMap(randomMapName());
    final String key = generateKeyOwnedBy(instance2);
    final String value = randomString();
    int partitionId = instance1.getPartitionService().getPartition(key).getPartitionId();
    setPartitionId(map, partitionId);
    map.put(key, value);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            Set<Map.Entry<String, String>> entries = map.entrySet();
            assertEquals(1, entries.size());
            Map.Entry<String, String> entry = entries.iterator().next();
            assertEquals(key, entry.getKey());
            assertEquals(value, entry.getValue());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Set(java.util.Set) AssertTask(com.hazelcast.test.AssertTask) ReplicatedMap(com.hazelcast.replicatedmap.ReplicatedMap) HashMap(java.util.HashMap) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with ReplicatedMap

use of com.hazelcast.replicatedmap.ReplicatedMap in project hazelcast by hazelcast.

the class Hz3EnrichmentTest method testMapUsingReplicatedMap.

@Test
public void testMapUsingReplicatedMap() {
    ReplicatedMap<Object, Object> map = hz3.getReplicatedMap("test-replicated-map");
    map.put(1, "a");
    map.put(2, "b");
    HazelcastInstance hz = createHazelcastInstance();
    IList<String> results = hz.getList("result-list");
    Pipeline p = Pipeline.create();
    ServiceFactory<Hz3MapAdapter, Map<Integer, String>> hz3MapSF = hz3ReplicatedMapServiceFactory("test-replicated-map", HZ3_CLIENT_CONFIG);
    BiFunctionEx<? super Map<Integer, String>, ? super Integer, String> mapFn = mapUsingIMap(FunctionEx.identity(), (Integer i, String s) -> s);
    BatchStage<String> mapStage = p.readFrom(TestSources.items(1, 2, 3)).mapUsingService(hz3MapSF, mapFn);
    mapStage.writeTo(Sinks.list(results));
    JobConfig config = getJobConfig(mapStage.name());
    hz.getJet().newJob(p, config).join();
    assertThat(results).containsOnly("a", "b");
}
Also used : JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Hz3MapAdapter(com.hazelcast.connector.map.Hz3MapAdapter) Map(java.util.Map) ReplicatedMap(com.hazelcast.replicatedmap.ReplicatedMap) AsyncMap(com.hazelcast.connector.map.AsyncMap) Hz3Enrichment.mapUsingIMap(com.hazelcast.connector.Hz3Enrichment.mapUsingIMap) IMap(com.hazelcast.map.IMap) Test(org.junit.Test)

Aggregations

ReplicatedMap (com.hazelcast.replicatedmap.ReplicatedMap)13 Test (org.junit.Test)13 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)12 QuickTest (com.hazelcast.test.annotation.QuickTest)12 HazelcastInstance (com.hazelcast.core.HazelcastInstance)10 Map (java.util.Map)6 HashMap (java.util.HashMap)5 AssertTask (com.hazelcast.test.AssertTask)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)1 Hz3Enrichment.mapUsingIMap (com.hazelcast.connector.Hz3Enrichment.mapUsingIMap)1 AsyncMap (com.hazelcast.connector.map.AsyncMap)1 Hz3MapAdapter (com.hazelcast.connector.map.Hz3MapAdapter)1 BiFunctionEx (com.hazelcast.function.BiFunctionEx)1 FunctionEx (com.hazelcast.function.FunctionEx)1 Functions.wholeItem (com.hazelcast.function.Functions.wholeItem)1 PredicateEx (com.hazelcast.function.PredicateEx)1 Job (com.hazelcast.jet.Job)1 Traversers.traverseItems (com.hazelcast.jet.Traversers.traverseItems)1 Util (com.hazelcast.jet.Util)1