Search in sources :

Example 11 with ReplicatedMap

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

the class ClientReplicatedMapTest method testRemove.

private void testRemove(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.remove("foo-" + i);
    }
    for (int i = 0; i < OPERATION_COUNT; i++) {
        assertNull(map2.get("foo-" + i));
    }
    for (int i = 0; i < OPERATION_COUNT; i++) {
        assertNull(map1.get("foo-" + i));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HashMap(java.util.HashMap) Map(java.util.Map) ReplicatedMap(com.hazelcast.core.ReplicatedMap)

Example 12 with ReplicatedMap

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

the class ReplicatedMapTtlTest method testPutWithTTL.

private void testPutWithTTL(int nodeCount, int keyCount, int operationCount, int threadCount, int ttl, boolean causeMigration) throws InterruptedException {
    TimeUnit timeUnit = TimeUnit.MILLISECONDS;
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance[] instances = factory.newInstances(null, nodeCount);
    String mapName = randomMapName();
    List<ReplicatedMap> maps = createMapOnEachInstance(instances, mapName);
    ArrayList<Integer> keys = generateRandomIntegerList(keyCount);
    Thread[] threads = createThreads(threadCount, maps, keys, ttl, timeUnit, operationCount);
    for (Thread thread : threads) {
        thread.start();
    }
    HazelcastInstance instance = null;
    if (causeMigration) {
        instance = factory.newHazelcastInstance();
    }
    for (Thread thread : threads) {
        thread.join();
    }
    if (causeMigration) {
        ReplicatedMap<Object, Object> map = instance.getReplicatedMap(mapName);
        maps.add(map);
    }
    for (ReplicatedMap map : maps) {
        assertSizeEventually(0, map, 60);
    }
}
Also used : ReplicatedMap(com.hazelcast.core.ReplicatedMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TimeUnit(java.util.concurrent.TimeUnit) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 13 with ReplicatedMap

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

the class HazelcastOSGiInstanceTest method getReplicatedMapCalledSuccessfullyOverOSGiInstance.

@Test
public void getReplicatedMapCalledSuccessfullyOverOSGiInstance() {
    ReplicatedMap mockReplicatedMap = mock(ReplicatedMap.class);
    HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
    HazelcastOSGiInstance hazelcastOSGiInstance = HazelcastOSGiTestUtil.createHazelcastOSGiInstance(mockHazelcastInstance);
    when(mockHazelcastInstance.getReplicatedMap("my-replicatedmap")).thenReturn(mockReplicatedMap);
    assertEquals(mockReplicatedMap, hazelcastOSGiInstance.getReplicatedMap("my-replicatedmap"));
    verify(mockHazelcastInstance).getReplicatedMap("my-replicatedmap");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ReplicatedMap(com.hazelcast.core.ReplicatedMap) 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