use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class HazelcastConnectorTest method when_readMap_withPredicateAndFunction.
@Test
public void when_readMap_withPredicateAndFunction() {
IMap<Integer, Integer> sourceMap = instance().getMap(sourceName);
range(0, ENTRY_COUNT).forEach(i -> sourceMap.put(i, i));
DAG dag = new DAG();
Vertex source = dag.newVertex("source", readMapP(sourceName, e -> !e.getKey().equals(0), Map.Entry::getKey));
Vertex sink = dag.newVertex("sink", writeListP(sinkName));
dag.edge(between(source, sink));
instance().getJet().newJob(dag).join();
IList<Object> list = instance().getList(sinkName);
assertEquals(ENTRY_COUNT - 1, list.size());
assertFalse(list.contains(0));
assertTrue(list.contains(1));
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class HazelcastConnectorTest method when_streamMap_withFilterAndProjection.
@Test
public void when_streamMap_withFilterAndProjection() {
DAG dag = new DAG();
Vertex source = dag.newVertex("source", SourceProcessors.<Integer, Integer, Integer>streamMapP(streamSourceName, event -> event.getKey() != 0, EventJournalMapEvent::getKey, START_FROM_OLDEST, eventTimePolicy(i -> i, limitingLag(0), 1, 0, 10_000)));
Vertex sink = dag.newVertex("sink", writeListP(streamSinkName));
dag.edge(between(source, sink));
Job job = instance().getJet().newJob(dag);
IMap<Integer, Integer> sourceMap = instance().getMap(streamSourceName);
range(0, ENTRY_COUNT).forEach(i -> sourceMap.put(i, i));
assertSizeEventually(ENTRY_COUNT - 1, instance().getList(streamSinkName));
assertFalse(instance().getList(streamSinkName).contains(0));
assertTrue(instance().getList(streamSinkName).contains(1));
job.cancel();
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class ReadMapOrCacheP_ConsistencyTest method test_addingItems.
private void test_addingItems(IMap<Integer, Integer> map, ClientConfig clientConfig) {
// use low initial item count to force resizing
int initialItemCount = 1024;
for (int i = 0; i < initialItemCount; i++) {
map.put(i, i);
}
Pipeline p = Pipeline.create();
p.readFrom(mapSource(clientConfig)).map(o -> {
proceedLatch.await();
// apply some gentle backpressure
if (processedCount.incrementAndGet() % 128 == 0) {
Thread.sleep(10);
}
return o.getKey();
}).setLocalParallelism(1).writeTo(AssertionSinks.assertCollected(list -> {
// check no duplicates
Set<Integer> collected = new HashSet<>(list);
assertEquals("there were duplicates", list.size(), collected.size());
// check all initial items before iteration started
for (int i = 0; i < initialItemCount; i++) {
assertTrue("key " + i + " was missing", collected.contains(i));
}
}));
Job job = hz.getJet().newJob(p);
proceedLatch.countDown();
// put some additional items
for (int i = initialItemCount; i < initialItemCount + NUM_ITEMS; i++) {
map.put(i, i);
}
job.join();
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class BatchStageTest method mapUsingIMap_when_functionThrows_then_jobFails.
@Test
public void mapUsingIMap_when_functionThrows_then_jobFails() {
// Given
IMap<Integer, String> map = member.getMap(randomMapName());
map.put(1, "1");
// When
BatchStage<Entry<Integer, String>> stage = batchStageFromList(singletonList(1)).groupingKey(i -> i).mapUsingIMap(map, (k, v) -> {
throw new RuntimeException("mock error");
});
// Then
stage.writeTo(sink);
Job job = hz().getJet().newJob(p);
assertThatThrownBy(() -> job.join()).hasMessageContaining("mock error");
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class HazelcastXATest method testParallel.
@Test
public void testParallel() throws Exception {
final HazelcastInstance instance = createHazelcastInstance();
// this is needed due to a racy bug in atomikos
txn(instance);
int size = 100;
ExecutorService executorService = Executors.newFixedThreadPool(5);
final CountDownLatch latch = new CountDownLatch(size);
for (int i = 0; i < size; i++) {
executorService.execute(new Runnable() {
public void run() {
try {
txn(instance);
} catch (Exception e) {
LOGGER.severe("Exception during txn", e);
} finally {
latch.countDown();
}
}
});
}
assertOpenEventually(latch, 20);
final IMap map = instance.getMap("m");
for (int i = 0; i < 10; i++) {
assertFalse(map.isLocked(i));
}
}
Aggregations