use of com.hazelcast.replicatedmap.ReplicatedMap in project hazelcast by hazelcast.
the class ClientReplicatedMapTest method testAdd.
@Test
public void testAdd() {
HazelcastInstance instance1 = factory.newHazelcastInstance(config);
HazelcastInstance instance2 = factory.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.replicatedmap.ReplicatedMap in project hazelcast by hazelcast.
the class ClientReplicatedMapTest method remove_empties_internal_ttl_schedulers.
@Test
public void remove_empties_internal_ttl_schedulers() {
String mapName = "test";
HazelcastInstance node = factory.newHazelcastInstance(config);
HazelcastInstance client = factory.newHazelcastClient();
ReplicatedMap map = client.getReplicatedMap(mapName);
for (int i = 0; i < 1000; i++) {
map.put(i, i, 100, TimeUnit.DAYS);
}
for (int i = 0; i < 1000; i++) {
map.remove(i);
}
assertAllTtlSchedulersEmpty(node.getReplicatedMap(mapName));
}
use of com.hazelcast.replicatedmap.ReplicatedMap in project hazelcast by hazelcast.
the class ClientReplicatedMapTest method testNearCacheInvalidation_withClear.
@Test
public void testNearCacheInvalidation_withClear() {
String mapName = randomString();
ClientConfig clientConfig = getClientConfigWithNearCacheInvalidationEnabled();
factory.newHazelcastInstance(config);
HazelcastInstance client1 = factory.newHazelcastClient(clientConfig);
HazelcastInstance client2 = factory.newHazelcastClient(clientConfig);
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 {
assertNull(replicatedMap1.get(1));
}
});
}
use of com.hazelcast.replicatedmap.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.replicatedmap.ReplicatedMap in project hazelcast by hazelcast.
the class Hz3EnrichmentTest method testMapUsingReplicatedMap.
@Test
public void testMapUsingReplicatedMap() {
ReplicatedMap<Object, Object> map = hz3.getReplicatedMap("test-replicated-map");
map.put(1, "a");
map.put(2, "b");
HazelcastInstance hz = createHazelcastInstance();
IList<String> results = hz.getList("result-list");
Pipeline p = Pipeline.create();
ServiceFactory<Hz3MapAdapter, Map<Integer, String>> hz3MapSF = hz3ReplicatedMapServiceFactory("test-replicated-map", HZ3_CLIENT_CONFIG);
BiFunctionEx<? super Map<Integer, String>, ? super Integer, String> mapFn = mapUsingIMap(FunctionEx.identity(), (Integer i, String s) -> s);
BatchStage<String> mapStage = p.readFrom(TestSources.items(1, 2, 3)).mapUsingService(hz3MapSF, mapFn);
mapStage.writeTo(Sinks.list(results));
JobConfig config = getJobConfig(mapStage.name());
hz.getJet().newJob(p, config).join();
assertThat(results).containsOnly("a", "b");
}
Aggregations