Search in sources :

Example 6 with ReplicatedMap

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

the class ClientReplicatedMapTest method testClear.

private void testClear(Config config) throws Exception {
    HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = hazelcastFactory.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());
    }
    map1.clear();
    assertEquals(0, map1.size());
    assertEquals(0, map2.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HashMap(java.util.HashMap) Map(java.util.Map) ReplicatedMap(com.hazelcast.core.ReplicatedMap)

Example 7 with ReplicatedMap

use of com.hazelcast.core.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.core.ReplicatedMap) HashMap(java.util.HashMap) Map(java.util.Map) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with ReplicatedMap

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

the class ClientReplicatedMapTest method testAdd.

private void testAdd(Config config) throws Exception {
    HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = hazelcastFactory.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) HashMap(java.util.HashMap) Map(java.util.Map) ReplicatedMap(com.hazelcast.core.ReplicatedMap)

Example 9 with ReplicatedMap

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

the class ReplicatedMapMergePolicyTest method testMapMergePolicy.

@Test
public void testMapMergePolicy() {
    final String mapName = randomMapName();
    Config config = newConfig(testCase.getMergePolicyClassName(), mapName);
    final HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config);
    TestMemberShipListener memberShipListener = new TestMemberShipListener(1);
    h2.getCluster().addMembershipListener(memberShipListener);
    TestLifeCycleListener lifeCycleListener = new TestLifeCycleListener(1);
    h2.getLifecycleService().addLifecycleListener(lifeCycleListener);
    // wait for cluster to be formed before breaking the connection
    waitAllForSafeState(h1, h2);
    closeConnectionBetween(h1, h2);
    assertOpenEventually(memberShipListener.latch);
    assertClusterSizeEventually(1, h1);
    assertClusterSizeEventually(1, h2);
    ReplicatedMap<Object, Object> map1 = h1.getReplicatedMap(mapName);
    ReplicatedMap<Object, Object> map2 = h2.getReplicatedMap(mapName);
    final Map<Object, Object> expectedValues = testCase.populateMaps(map1, map2, h1);
    assertOpenEventually(lifeCycleListener.latch);
    assertClusterSizeEventually(2, h1);
    assertClusterSizeEventually(2, h2);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            ReplicatedMap<Object, Object> mapTest = h1.getReplicatedMap(mapName);
            for (Map.Entry<Object, Object> entry : expectedValues.entrySet()) {
                assertEquals(entry.getValue(), mapTest.get(entry.getKey()));
            }
        }
    });
}
Also used : Config(com.hazelcast.config.Config) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) ReplicatedMap(com.hazelcast.core.ReplicatedMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 10 with ReplicatedMap

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

the class ClientReplicatedMapTest method testUpdate.

private void testUpdate(Config config) throws Exception {
    HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = hazelcastFactory.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());
    }
    for (int i = 0; i < OPERATION_COUNT; i++) {
        map2.put("foo-" + i, "bar2");
    }
    for (Map.Entry<String, String> entry : map2.entrySet()) {
        assertEquals("bar2", entry.getValue());
    }
    for (Map.Entry<String, String> entry : map1.entrySet()) {
        assertEquals("bar2", entry.getValue());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HashMap(java.util.HashMap) Map(java.util.Map) ReplicatedMap(com.hazelcast.core.ReplicatedMap)

Aggregations

ReplicatedMap (com.hazelcast.core.ReplicatedMap)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 Test (org.junit.Test)7 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 AssertTask (com.hazelcast.test.AssertTask)4 Config (com.hazelcast.config.Config)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)1 NightlyTest (com.hazelcast.test.annotation.NightlyTest)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1