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));
}
}
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);
}
}
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");
}
Aggregations