Search in sources :

Example 1 with EventJournalMapEvent

use of com.hazelcast.map.journal.EventJournalMapEvent in project hazelcast-jet 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, wmGenParams(i -> i, limitingLag(0), noThrottling(), 10_000)));
    Vertex sink = dag.newVertex("sink", writeListP(streamSinkName));
    dag.edge(between(source, sink));
    Job job = jetInstance.newJob(dag);
    IMapJet<Integer, Integer> sourceMap = jetInstance.getMap(streamSourceName);
    range(0, ENTRY_COUNT).forEach(i -> sourceMap.put(i, i));
    assertSizeEventually(ENTRY_COUNT - 1, jetInstance.getList(streamSinkName));
    assertFalse(jetInstance.getList(streamSinkName).contains(0));
    assertTrue(jetInstance.getList(streamSinkName).contains(1));
    job.cancel();
}
Also used : WatermarkPolicies.limitingLag(com.hazelcast.jet.core.WatermarkPolicies.limitingLag) IntStream.range(java.util.stream.IntStream.range) EventJournalConfig(com.hazelcast.config.EventJournalConfig) IMapJet(com.hazelcast.jet.IMapJet) SourceProcessors.readMapP(com.hazelcast.jet.core.processor.SourceProcessors.readMapP) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) SourceProcessors.readListP(com.hazelcast.jet.core.processor.SourceProcessors.readListP) SourceProcessors.streamCacheP(com.hazelcast.jet.core.processor.SourceProcessors.streamCacheP) ICacheJet(com.hazelcast.jet.ICacheJet) Map(java.util.Map) WatermarkEmissionPolicy.noThrottling(com.hazelcast.jet.core.WatermarkEmissionPolicy.noThrottling) SinkProcessors.writeCacheP(com.hazelcast.jet.core.processor.SinkProcessors.writeCacheP) DAG(com.hazelcast.jet.core.DAG) WatermarkGenerationParams.noWatermarks(com.hazelcast.jet.core.WatermarkGenerationParams.noWatermarks) Projections(com.hazelcast.projection.Projections) WatermarkGenerationParams.wmGenParams(com.hazelcast.jet.core.WatermarkGenerationParams.wmGenParams) SourceProcessors.readCacheP(com.hazelcast.jet.core.processor.SourceProcessors.readCacheP) EventJournalMapEvent(com.hazelcast.map.journal.EventJournalMapEvent) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) START_FROM_OLDEST(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST) Collectors.joining(java.util.stream.Collectors.joining) PredicateTestUtils.entry(com.hazelcast.query.impl.predicates.PredicateTestUtils.entry) JetCacheManager(com.hazelcast.jet.JetCacheManager) Assert.assertFalse(org.junit.Assert.assertFalse) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) Entry(java.util.Map.Entry) SinkProcessors.writeMapP(com.hazelcast.jet.core.processor.SinkProcessors.writeMapP) IntStream(java.util.stream.IntStream) JetInstance(com.hazelcast.jet.JetInstance) SourceProcessors(com.hazelcast.jet.core.processor.SourceProcessors) RunWith(org.junit.runner.RunWith) Job(com.hazelcast.jet.Job) Before(org.junit.Before) EventJournalCacheEvent(com.hazelcast.cache.journal.EventJournalCacheEvent) Config(com.hazelcast.config.Config) JetConfig(com.hazelcast.jet.config.JetConfig) SourceProcessors.streamMapP(com.hazelcast.jet.core.processor.SourceProcessors.streamMapP) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IListJet(com.hazelcast.jet.IListJet) Vertex(com.hazelcast.jet.core.Vertex) TruePredicate(com.hazelcast.query.TruePredicate) Collectors.toList(java.util.stream.Collectors.toList) Predicates(com.hazelcast.query.Predicates) ICache(com.hazelcast.cache.ICache) Util.mapPutEvents(com.hazelcast.jet.Util.mapPutEvents) 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) Test(org.junit.Test)

Example 2 with EventJournalMapEvent

use of com.hazelcast.map.journal.EventJournalMapEvent in project hazelcast-jet by hazelcast.

the class HazelcastRemoteConnectorTest method when_streamRemoteMap_withPredicateAndProjection.

@Test
public void when_streamRemoteMap_withPredicateAndProjection() {
    DAG dag = new DAG();
    Vertex source = dag.newVertex(SOURCE_NAME, SourceProcessors.<Integer, Integer, Integer>streamRemoteMapP(SOURCE_NAME, clientConfig, event -> event.getKey() != 0, EventJournalMapEvent::getKey, START_FROM_OLDEST, wmGenParams(i -> i, limitingLag(0), noThrottling(), 10_000)));
    Vertex sink = dag.newVertex(SINK_NAME, writeListP(SINK_NAME));
    dag.edge(between(source, sink));
    Job job = jet.newJob(dag);
    populateMap(hz.getMap(SOURCE_NAME));
    assertSizeEventually(ITEM_COUNT - 1, jet.getList(SINK_NAME));
    assertFalse(jet.getList(SINK_NAME).contains(0));
    assertTrue(jet.getList(SINK_NAME).contains(1));
    job.cancel();
}
Also used : WatermarkPolicies.limitingLag(com.hazelcast.jet.core.WatermarkPolicies.limitingLag) EventJournalConfig(com.hazelcast.config.EventJournalConfig) Address(com.hazelcast.nio.Address) SourceProcessors.readMapP(com.hazelcast.jet.core.processor.SourceProcessors.readMapP) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) WatermarkEmissionPolicy.noThrottling(com.hazelcast.jet.core.WatermarkEmissionPolicy.noThrottling) SourceProcessors.readRemoteMapP(com.hazelcast.jet.core.processor.SourceProcessors.readRemoteMapP) DAG(com.hazelcast.jet.core.DAG) Projections(com.hazelcast.projection.Projections) WatermarkGenerationParams.wmGenParams(com.hazelcast.jet.core.WatermarkGenerationParams.wmGenParams) SourceProcessors.readCacheP(com.hazelcast.jet.core.processor.SourceProcessors.readCacheP) EventJournalMapEvent(com.hazelcast.map.journal.EventJournalMapEvent) AfterClass(org.junit.AfterClass) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) START_FROM_OLDEST(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST) Hazelcast(com.hazelcast.core.Hazelcast) Assert.assertFalse(org.junit.Assert.assertFalse) Entry(java.util.Map.Entry) IntStream(java.util.stream.IntStream) JetInstance(com.hazelcast.jet.JetInstance) BeforeClass(org.junit.BeforeClass) SourceProcessors.readRemoteCacheP(com.hazelcast.jet.core.processor.SourceProcessors.readRemoteCacheP) SourceProcessors(com.hazelcast.jet.core.processor.SourceProcessors) RunWith(org.junit.runner.RunWith) JetTestInstanceFactory(com.hazelcast.jet.JetTestInstanceFactory) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) ClientConfig(com.hazelcast.client.config.ClientConfig) SinkProcessors.writeRemoteMapP(com.hazelcast.jet.core.processor.SinkProcessors.writeRemoteMapP) Job(com.hazelcast.jet.Job) Before(org.junit.Before) EventJournalCacheEvent(com.hazelcast.cache.journal.EventJournalCacheEvent) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JetConfig(com.hazelcast.jet.config.JetConfig) SourceProcessors.streamRemoteMapP(com.hazelcast.jet.core.processor.SourceProcessors.streamRemoteMapP) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IListJet(com.hazelcast.jet.IListJet) Vertex(com.hazelcast.jet.core.Vertex) DistributedObject(com.hazelcast.core.DistributedObject) Predicates(com.hazelcast.query.Predicates) ICache(com.hazelcast.cache.ICache) 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) Test(org.junit.Test)

Example 3 with EventJournalMapEvent

use of com.hazelcast.map.journal.EventJournalMapEvent in project hazelcast-jet by hazelcast.

the class StreamEventJournalPTest method setUp.

@Before
public void setUp() {
    JetConfig config = new JetConfig();
    EventJournalConfig journalConfig = new EventJournalConfig().setMapName("*").setCapacity(JOURNAL_CAPACITY).setEnabled(true);
    config.getHazelcastConfig().setProperty(PARTITION_COUNT.getName(), String.valueOf(NUM_PARTITIONS));
    config.getHazelcastConfig().addEventJournalConfig(journalConfig);
    instance = this.createJetMember(config);
    map = (MapProxyImpl<String, Integer>) instance.getHazelcastInstance().<String, Integer>getMap("test");
    List<Integer> allPartitions = IntStream.range(0, NUM_PARTITIONS).boxed().collect(toList());
    supplier = () -> new StreamEventJournalP<>(map, allPartitions, e -> true, EventJournalMapEvent::getNewValue, START_FROM_OLDEST, false, wmGenParams(Integer::intValue, limitingLag(0), suppressAll(), -1));
    key0 = generateKeyForPartition(instance.getHazelcastInstance(), 0);
    key1 = generateKeyForPartition(instance.getHazelcastInstance(), 1);
}
Also used : IntStream(java.util.stream.IntStream) PARTITION_COUNT(com.hazelcast.spi.properties.GroupProperty.PARTITION_COUNT) Arrays(java.util.Arrays) WatermarkPolicies.limitingLag(com.hazelcast.jet.core.WatermarkPolicies.limitingLag) JetInstance(com.hazelcast.jet.JetInstance) RunWith(org.junit.runner.RunWith) EventJournalConfig(com.hazelcast.config.EventJournalConfig) Processor(com.hazelcast.jet.core.Processor) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) WatermarkGenerationParams.wmGenParams(com.hazelcast.jet.core.WatermarkGenerationParams.wmGenParams) EventJournalMapEvent(com.hazelcast.map.journal.EventJournalMapEvent) Before(org.junit.Before) TestInbox(com.hazelcast.jet.core.test.TestInbox) DistributedSupplier(com.hazelcast.jet.function.DistributedSupplier) JetConfig(com.hazelcast.jet.config.JetConfig) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) WatermarkEmissionPolicy(com.hazelcast.jet.core.WatermarkEmissionPolicy) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) START_FROM_OLDEST(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST) Collectors(java.util.stream.Collectors) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) SAME_ITEMS_ANY_ORDER(com.hazelcast.jet.core.test.TestSupport.SAME_ITEMS_ANY_ORDER) TestSupport(com.hazelcast.jet.core.test.TestSupport) Assert.assertFalse(org.junit.Assert.assertFalse) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) Entry(java.util.Map.Entry) Assert.assertEquals(org.junit.Assert.assertEquals) JetConfig(com.hazelcast.jet.config.JetConfig) EventJournalConfig(com.hazelcast.config.EventJournalConfig) Before(org.junit.Before)

Example 4 with EventJournalMapEvent

use of com.hazelcast.map.journal.EventJournalMapEvent in project hazelcast-jet by hazelcast.

the class SnapshotFailureTest method when_snapshotFails_then_jobShouldNotFail.

@Test
public void when_snapshotFails_then_jobShouldNotFail() {
    int numPartitions = 2;
    int numElements = 10;
    IMapJet<Object, Object> results = instance1.getMap("results");
    DAG dag = new DAG();
    SequencesInPartitionsMetaSupplier sup = new SequencesInPartitionsMetaSupplier(numPartitions, numElements);
    Vertex generator = dag.newVertex("generator", peekOutputP(throttle(sup, 2))).localParallelism(1);
    Vertex writeMap = dag.newVertex("writeMap", writeMapP(results.getName())).localParallelism(1);
    dag.edge(between(generator, writeMap));
    JobConfig config = new JobConfig();
    config.setProcessingGuarantee(ProcessingGuarantee.EXACTLY_ONCE);
    config.setSnapshotIntervalMillis(100);
    Job job = instance1.newJob(dag, config);
    // let's start a second job that will watch the snapshots map and write failed
    // SnapshotRecords to a list, which we will check for presence of failed snapshot
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.mapJournal(snapshotsMapName(job.getId()), event -> event.getNewValue() instanceof SnapshotRecord && ((SnapshotRecord) event.getNewValue()).status() == SnapshotStatus.FAILED, EventJournalMapEvent::getNewValue, JournalInitialPosition.START_FROM_OLDEST)).peek().drainTo(Sinks.list("failed_snapshot_records"));
    instance1.newJob(p);
    job.join();
    assertEquals("numPartitions", numPartitions, results.size());
    assertEquals("offset partition 0", numElements - 1, results.get(0));
    assertEquals("offset partition 1", numElements - 1, results.get(1));
    assertTrue("no failure occurred in store", storeFailed);
    assertFalse("no failed snapshot appeared in snapshotsMap", instance1.getList("failed_snapshot_records").isEmpty());
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) SnapshotRecord(com.hazelcast.jet.impl.execution.SnapshotRecord) RunWith(org.junit.runner.RunWith) EventJournalConfig(com.hazelcast.config.EventJournalConfig) IMapJet(com.hazelcast.jet.IMapJet) SequencesInPartitionsMetaSupplier(com.hazelcast.jet.core.JobRestartWithSnapshotTest.SequencesInPartitionsMetaSupplier) SnapshotStatus(com.hazelcast.jet.impl.execution.SnapshotRecord.SnapshotStatus) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) MapConfig(com.hazelcast.config.MapConfig) TestUtil.throttle(com.hazelcast.jet.core.TestUtil.throttle) ExpectedException(org.junit.rules.ExpectedException) Job(com.hazelcast.jet.Job) EventJournalMapEvent(com.hazelcast.map.journal.EventJournalMapEvent) Before(org.junit.Before) JetConfig(com.hazelcast.jet.config.JetConfig) SnapshotRepository(com.hazelcast.jet.impl.SnapshotRepository) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JobConfig(com.hazelcast.jet.config.JobConfig) Sinks(com.hazelcast.jet.pipeline.Sinks) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) DiagnosticProcessors.peekOutputP(com.hazelcast.jet.core.processor.DiagnosticProcessors.peekOutputP) AMapStore(com.hazelcast.client.map.helpers.AMapStore) Serializable(java.io.Serializable) Sources(com.hazelcast.jet.pipeline.Sources) Rule(org.junit.Rule) JournalInitialPosition(com.hazelcast.jet.pipeline.JournalInitialPosition) Assert.assertFalse(org.junit.Assert.assertFalse) MapStoreConfig(com.hazelcast.config.MapStoreConfig) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) SnapshotRepository.snapshotsMapName(com.hazelcast.jet.impl.SnapshotRepository.snapshotsMapName) Assert.assertEquals(org.junit.Assert.assertEquals) Edge.between(com.hazelcast.jet.core.Edge.between) SinkProcessors.writeMapP(com.hazelcast.jet.core.processor.SinkProcessors.writeMapP) SnapshotRecord(com.hazelcast.jet.impl.execution.SnapshotRecord) Job(com.hazelcast.jet.Job) SequencesInPartitionsMetaSupplier(com.hazelcast.jet.core.JobRestartWithSnapshotTest.SequencesInPartitionsMetaSupplier) JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 5 with EventJournalMapEvent

use of com.hazelcast.map.journal.EventJournalMapEvent in project hazelcast-jet-reference-manual by hazelcast.

the class ImdgConnectors method s12.

static void s12() {
    // tag::s12[]
    Pipeline p = Pipeline.create();
    StreamStage<EventJournalMapEvent<String, Long>> allFromMap = p.drawFrom(Sources.<EventJournalMapEvent<String, Long>, String, Long>mapJournal("inputMap", DistributedFunctions.alwaysTrue(), DistributedFunction.identity(), START_FROM_CURRENT));
    StreamStage<EventJournalCacheEvent<String, Long>> allFromCache = p.drawFrom(Sources.<EventJournalCacheEvent<String, Long>, String, Long>cacheJournal("inputMap", DistributedFunctions.alwaysTrue(), DistributedFunction.identity(), START_FROM_CURRENT));
// end::s12[]
}
Also used : EventJournalCacheEvent(com.hazelcast.cache.journal.EventJournalCacheEvent) EventJournalMapEvent(com.hazelcast.map.journal.EventJournalMapEvent) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Aggregations

EventJournalMapEvent (com.hazelcast.map.journal.EventJournalMapEvent)5 EventJournalConfig (com.hazelcast.config.EventJournalConfig)4 JetInstance (com.hazelcast.jet.JetInstance)4 JetConfig (com.hazelcast.jet.config.JetConfig)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.assertFalse (org.junit.Assert.assertFalse)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 Before (org.junit.Before)4 Test (org.junit.Test)4 RunWith (org.junit.runner.RunWith)4 EventJournalCacheEvent (com.hazelcast.cache.journal.EventJournalCacheEvent)3 Job (com.hazelcast.jet.Job)3 Edge.between (com.hazelcast.jet.core.Edge.between)3 JetTestSupport (com.hazelcast.jet.core.JetTestSupport)3 WatermarkGenerationParams.wmGenParams (com.hazelcast.jet.core.WatermarkGenerationParams.wmGenParams)3 WatermarkPolicies.limitingLag (com.hazelcast.jet.core.WatermarkPolicies.limitingLag)3 START_FROM_OLDEST (com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST)3 Entry (java.util.Map.Entry)3 IntStream (java.util.stream.IntStream)3 ICache (com.hazelcast.cache.ICache)2