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