Search in sources :

Example 56 with DAG

use of com.hazelcast.jet.core.DAG in project hazelcast by hazelcast.

the class HazelcastRemoteConnectorTest method when_readRemoteMap_withPredicateAndFunction.

@Test
public void when_readRemoteMap_withPredicateAndFunction() {
    populateMap(remoteHz.getMap(SOURCE_NAME));
    DAG dag = new DAG();
    Vertex source = dag.newVertex(SOURCE_NAME, readRemoteMapP(SOURCE_NAME, clientConfig, e -> !e.getKey().equals(0), Entry::getValue)).localParallelism(4);
    Vertex sink = dag.newVertex(SINK_NAME, writeListP(SINK_NAME)).localParallelism(1);
    dag.edge(between(source, sink));
    executeAndWait(dag);
    IList<Object> list = localHz.getList(SINK_NAME);
    assertEquals(ITEM_COUNT - 1, list.size());
    assertFalse(list.contains(0));
    assertTrue(list.contains(1));
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Entry(java.util.Map.Entry) DistributedObject(com.hazelcast.core.DistributedObject) DAG(com.hazelcast.jet.core.DAG) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 57 with DAG

use of com.hazelcast.jet.core.DAG in project hazelcast by hazelcast.

the class HazelcastRemoteConnectorTest method when_readRemoteCache.

@Test
public void when_readRemoteCache() {
    populateCache(remoteHz.getCacheManager().getCache(SOURCE_NAME));
    DAG dag = new DAG();
    Vertex source = dag.newVertex(SOURCE_NAME, readRemoteCacheP(SOURCE_NAME, clientConfig));
    Vertex sink = dag.newVertex(SINK_NAME, writeListP(SINK_NAME));
    dag.edge(between(source, sink));
    executeAndWait(dag);
    assertEquals(ITEM_COUNT, localHz.getList(SINK_NAME).size());
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) DAG(com.hazelcast.jet.core.DAG) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 58 with DAG

use of com.hazelcast.jet.core.DAG in project hazelcast by hazelcast.

the class HazelcastRemoteConnectorTest method when_streamRemoteCache_withPredicateAndProjection.

@Test
public void when_streamRemoteCache_withPredicateAndProjection() {
    DAG dag = new DAG();
    Vertex source = dag.newVertex(SOURCE_NAME, SourceProcessors.<Integer, Integer, Integer>streamRemoteCacheP(SOURCE_NAME, clientConfig, event -> !event.getKey().equals(0), EventJournalCacheEvent::getKey, START_FROM_OLDEST, eventTimePolicy(i -> i, limitingLag(0), 1, 0, 10_000)));
    Vertex sink = dag.newVertex(SINK_NAME, writeListP(SINK_NAME));
    dag.edge(between(source, sink));
    Job job = localHz.getJet().newJob(dag);
    populateCache(remoteHz.getCacheManager().getCache(SOURCE_NAME));
    assertSizeEventually(ITEM_COUNT - 1, localHz.getList(SINK_NAME));
    assertFalse(localHz.getList(SINK_NAME).contains(0));
    assertTrue(localHz.getList(SINK_NAME).contains(1));
    job.cancel();
}
Also used : Address(com.hazelcast.cluster.Address) QuickTest(com.hazelcast.test.annotation.QuickTest) SourceProcessors.readMapP(com.hazelcast.jet.core.processor.SourceProcessors.readMapP) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) MapConfig(com.hazelcast.config.MapConfig) EventJournalCacheEvent(com.hazelcast.cache.EventJournalCacheEvent) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) SourceProcessors.readRemoteMapP(com.hazelcast.jet.core.processor.SourceProcessors.readRemoteMapP) DAG(com.hazelcast.jet.core.DAG) Projections(com.hazelcast.projection.Projections) SourceProcessors.readCacheP(com.hazelcast.jet.core.processor.SourceProcessors.readCacheP) AfterClass(org.junit.AfterClass) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) START_FROM_OLDEST(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST) Category(org.junit.experimental.categories.Category) Hazelcast(com.hazelcast.core.Hazelcast) EventJournalMapEvent(com.hazelcast.map.EventJournalMapEvent) Assert.assertFalse(org.junit.Assert.assertFalse) Entry(java.util.Map.Entry) IntStream(java.util.stream.IntStream) BeforeClass(org.junit.BeforeClass) SourceProcessors.readRemoteCacheP(com.hazelcast.jet.core.processor.SourceProcessors.readRemoteCacheP) HazelcastClient(com.hazelcast.client.HazelcastClient) HazelcastInstanceFactory(com.hazelcast.instance.impl.HazelcastInstanceFactory) SourceProcessors(com.hazelcast.jet.core.processor.SourceProcessors) RunWith(org.junit.runner.RunWith) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) ClientConfig(com.hazelcast.client.config.ClientConfig) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) SinkProcessors.writeRemoteMapP(com.hazelcast.jet.core.processor.SinkProcessors.writeRemoteMapP) Job(com.hazelcast.jet.Job) Before(org.junit.Before) IList(com.hazelcast.collection.IList) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SourceProcessors.streamRemoteMapP(com.hazelcast.jet.core.processor.SourceProcessors.streamRemoteMapP) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) WatermarkPolicy.limitingLag(com.hazelcast.jet.core.WatermarkPolicy.limitingLag) Vertex(com.hazelcast.jet.core.Vertex) DistributedObject(com.hazelcast.core.DistributedObject) Predicates(com.hazelcast.query.Predicates) ICache(com.hazelcast.cache.ICache) EventTimePolicy.eventTimePolicy(com.hazelcast.jet.core.EventTimePolicy.eventTimePolicy) SinkProcessors.writeRemoteCacheP(com.hazelcast.jet.core.processor.SinkProcessors.writeRemoteCacheP) SourceProcessors.streamRemoteCacheP(com.hazelcast.jet.core.processor.SourceProcessors.streamRemoteCacheP) Assert.assertEquals(org.junit.Assert.assertEquals) Edge.between(com.hazelcast.jet.core.Edge.between) SinkProcessors.writeListP(com.hazelcast.jet.core.processor.SinkProcessors.writeListP) Vertex(com.hazelcast.jet.core.Vertex) DAG(com.hazelcast.jet.core.DAG) Job(com.hazelcast.jet.Job) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 59 with DAG

use of com.hazelcast.jet.core.DAG in project hazelcast by hazelcast.

the class HazelcastRemoteConnectorTest method when_streamRemoteCache.

@Test
public void when_streamRemoteCache() {
    DAG dag = new DAG();
    Vertex source = dag.newVertex(SOURCE_NAME, streamRemoteCacheP(SOURCE_NAME, clientConfig, START_FROM_OLDEST, eventTimePolicy(Entry<Integer, Integer>::getValue, limitingLag(0), 1, 0, 10_000))).localParallelism(4);
    Vertex sink = dag.newVertex(SINK_NAME, writeListP(SINK_NAME)).localParallelism(1);
    dag.edge(between(source, sink));
    Job job = localHz.getJet().newJob(dag);
    populateCache(remoteHz.getCacheManager().getCache(SOURCE_NAME));
    assertSizeEventually(ITEM_COUNT, localHz.getList(SINK_NAME));
    job.cancel();
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) DAG(com.hazelcast.jet.core.DAG) Job(com.hazelcast.jet.Job) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 60 with DAG

use of com.hazelcast.jet.core.DAG in project hazelcast by hazelcast.

the class RebalanceStreamStageTest method when_rebalanceAndMap_then_dagEdgeDistributed.

@Test
public void when_rebalanceAndMap_then_dagEdgeDistributed() {
    // Given
    List<Integer> input = sequence(itemCount);
    StreamStage<Integer> srcStage = streamStageFromList(input);
    FunctionEx<Integer, String> formatFn = i -> String.format("%04d-string", i);
    // When
    StreamStage<String> mapped = srcStage.rebalance().map(formatFn);
    // Then
    mapped.writeTo(sink);
    DAG dag = p.toDag();
    Edge srcToMap = dag.getInboundEdges("map").get(0);
    assertTrue("Rebalancing should make the edge distributed", srcToMap.isDistributed());
    assertNull("Didn't rebalance by key, the edge must not be partitioned", srcToMap.getPartitioner());
    execute();
    assertEquals(streamToString(input.stream(), formatFn), streamToString(sinkStreamOf(String.class), identity()));
}
Also used : FunctionEx(com.hazelcast.function.FunctionEx) KeyedWindowResult(com.hazelcast.jet.datamodel.KeyedWindowResult) Assert.assertNotNull(org.junit.Assert.assertNotNull) AggregateOperations(com.hazelcast.jet.aggregate.AggregateOperations) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AggregateOperation1(com.hazelcast.jet.aggregate.AggregateOperation1) JetException(com.hazelcast.jet.JetException) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) WindowDefinition.tumbling(com.hazelcast.jet.pipeline.WindowDefinition.tumbling) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Function.identity(java.util.function.Function.identity) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) Assert.assertEquals(org.junit.Assert.assertEquals) WindowResult(com.hazelcast.jet.datamodel.WindowResult) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) Test(org.junit.Test)

Aggregations

DAG (com.hazelcast.jet.core.DAG)211 Test (org.junit.Test)159 Vertex (com.hazelcast.jet.core.Vertex)127 QuickTest (com.hazelcast.test.annotation.QuickTest)100 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)91 Job (com.hazelcast.jet.Job)64 Entry (java.util.Map.Entry)51 List (java.util.List)38 Assert.assertEquals (org.junit.Assert.assertEquals)37 Map (java.util.Map)36 JobConfig (com.hazelcast.jet.config.JobConfig)35 Assert.assertTrue (org.junit.Assert.assertTrue)31 Edge (com.hazelcast.jet.core.Edge)29 IntStream (java.util.stream.IntStream)29 Category (org.junit.experimental.categories.Category)28 Collectors.toList (java.util.stream.Collectors.toList)26 HazelcastInstance (com.hazelcast.core.HazelcastInstance)23 FunctionEx (com.hazelcast.function.FunctionEx)23 ArrayList (java.util.ArrayList)22 Nonnull (javax.annotation.Nonnull)21