Search in sources :

Example 1 with ReplicatedMap

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

the class ReplicatedMapAbstractTest method createMapOnEachInstance.

public List<ReplicatedMap> createMapOnEachInstance(HazelcastInstance[] instances, String replicatedMapName) {
    ArrayList<ReplicatedMap> maps = new ArrayList<ReplicatedMap>();
    for (HazelcastInstance instance : instances) {
        ReplicatedMap<Object, Object> replicatedMap = instance.getReplicatedMap(replicatedMapName);
        maps.add(replicatedMap);
    }
    return maps;
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ArrayList(java.util.ArrayList) ReplicatedMap(com.hazelcast.core.ReplicatedMap)

Example 2 with ReplicatedMap

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

the class ReplicatedMapWriteOrderTest method testDataIntegrity.

@Test
public void testDataIntegrity() throws InterruptedException {
    System.out.println("nodeCount = " + nodeCount);
    System.out.println("operations = " + operations);
    System.out.println("keyCount = " + keyCount);
    Config config = new Config();
    config.getReplicatedMapConfig("test").setReplicationDelayMillis(0);
    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(nodeCount);
    final HazelcastInstance[] instances = factory.newInstances(config);
    String replicatedMapName = "test";
    final List<ReplicatedMap> maps = createMapOnEachInstance(instances, replicatedMapName);
    ArrayList<Integer> keys = generateRandomIntegerList(keyCount);
    Thread[] threads = createThreads(nodeCount, maps, keys, operations);
    for (Thread thread : threads) {
        thread.start();
    }
    for (Thread thread : threads) {
        thread.join();
    }
    for (int i = 0; i < keyCount; i++) {
        final String key = "foo-" + keys.get(i);
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() throws Exception {
                System.out.println("---------------------");
                System.out.println("key = " + key);
                printValues();
                assertValuesAreEqual();
            }

            private void printValues() throws Exception {
                for (int j = 0; j < maps.size(); j++) {
                    ReplicatedMap map = maps.get(j);
                    System.out.println("value[" + j + "] = " + map.get(key) + " , store version : " + getStore(map, key).getVersion());
                }
            }

            private void assertValuesAreEqual() {
                for (int i = 0; i < maps.size() - 1; i++) {
                    ReplicatedMap map1 = maps.get(i);
                    ReplicatedMap map2 = maps.get(i + 1);
                    Object v1 = map1.get(key);
                    Object v2 = map2.get(key);
                    assertNotNull(v1);
                    assertNotNull(v2);
                    assertEquals(v1, v2);
                }
            }
        }, 120);
    }
}
Also used : Config(com.hazelcast.config.Config) ReplicatedMap(com.hazelcast.core.ReplicatedMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Test(org.junit.Test)

Example 3 with ReplicatedMap

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

the class MBeanTest method testReplicatedMap.

@Test
public void testReplicatedMap() throws Exception {
    String replicatedMapName = randomString();
    ReplicatedMap replicatedMap = holder.getHz().getReplicatedMap(replicatedMapName);
    replicatedMap.size();
    holder.assertMBeanExistEventually("ReplicatedMap", replicatedMap.getName());
}
Also used : ReplicatedMap(com.hazelcast.core.ReplicatedMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with ReplicatedMap

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

the class MBeanDestroyTest method testReplicatedMap.

@Test
public void testReplicatedMap() throws Exception {
    String replicatedMapName = randomString();
    ReplicatedMap replicatedMap = holder.getHz().getReplicatedMap(replicatedMapName);
    replicatedMap.size();
    holder.assertMBeanExistEventually("ReplicatedMap", replicatedMap.getName());
    destroyObjectAndAssert(replicatedMap, "ReplicatedMap");
}
Also used : ReplicatedMap(com.hazelcast.core.ReplicatedMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with ReplicatedMap

use of com.hazelcast.core.ReplicatedMap 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)

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