Search in sources :

Example 6 with Traverser

use of com.hazelcast.jet.Traverser in project hazelcast by hazelcast.

the class AsyncTransformUsingServiceBatchedPTest method test_futuresCompletedInSeparateThread.

@Test
public void test_futuresCompletedInSeparateThread() {
    TestSupport.verifyProcessor(getSupplier((ctx, items) -> {
        CompletableFuture<Traverser<String>> f = new CompletableFuture<>();
        spawn(() -> f.complete(traverseIterable(items).flatMap(item -> traverseItems(item + "-1", item + "-2"))));
        return f;
    })).hazelcastInstance(instance()).input(asList("a", "b", new Watermark(10))).outputChecker((expected, actual) -> actual.equals(asList("a-1", "a-2", "b-1", "b-2", wm(10)))).disableProgressAssertion().expectOutput(singletonList("<see code>"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Traverser(com.hazelcast.jet.Traverser) Watermark(com.hazelcast.jet.core.Watermark) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with Traverser

use of com.hazelcast.jet.Traverser in project hazelcast by hazelcast.

the class AsyncTransformUsingServiceP_IntegrationTest method stressTestInt.

private void stressTestInt(boolean restart) {
    /*
        This is a stress test of the cooperative emission using the DAG api. Only through DAG
        API we can configure edge queue sizes, which we use to cause more trouble for the
        cooperative emission.
         */
    // add more input to the source map
    int numItems = 10_000;
    journaledMap.putAll(IntStream.range(NUM_ITEMS, numItems).boxed().collect(toMap(i -> i, i -> i)));
    DAG dag = new DAG();
    Vertex source = dag.newVertex("source", throttle(streamMapP(journaledMap.getName(), alwaysTrue(), EventJournalMapEvent::getNewValue, START_FROM_OLDEST, eventTimePolicy(i -> (long) ((Integer) i), WatermarkPolicy.limitingLag(10), 10, 0, 0)), 5000));
    BiFunctionEx<ExecutorService, Integer, CompletableFuture<Traverser<String>>> flatMapAsyncFn = transformNotPartitionedFn(i -> traverseItems(i + "-1", i + "-2", i + "-3", i + "-4", i + "-5"));
    ProcessorSupplier processorSupplier = ordered ? AsyncTransformUsingServiceOrderedP.supplier(serviceFactory, DEFAULT_MAX_CONCURRENT_OPS, flatMapAsyncFn) : AsyncTransformUsingServiceUnorderedP.supplier(serviceFactory, DEFAULT_MAX_CONCURRENT_OPS, flatMapAsyncFn, identity());
    Vertex map = dag.newVertex("map", processorSupplier).localParallelism(2);
    Vertex sink = dag.newVertex("sink", SinkProcessors.writeListP(sinkList.getName()));
    // Use a shorter queue to not block the barrier from the source for too long due to
    // the backpressure from the slow mapper
    EdgeConfig edgeToMapperConfig = new EdgeConfig().setQueueSize(128);
    // Use a shorter queue on output from the mapper so that we experience backpressure
    // from the sink
    EdgeConfig edgeFromMapperConfig = new EdgeConfig().setQueueSize(10);
    dag.edge(between(source, map).setConfig(edgeToMapperConfig)).edge(between(map, sink).setConfig(edgeFromMapperConfig));
    Job job = instance().getJet().newJob(dag, jobConfig);
    for (int i = 0; restart && i < 5; i++) {
        assertJobStatusEventually(job, RUNNING);
        sleepMillis(100);
        job.restart();
    }
    assertResultEventually(i -> Stream.of(i + "-1", i + "-2", i + "-3", i + "-4", i + "-5"), numItems);
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Traverser(com.hazelcast.jet.Traverser) ServiceFactories.sharedService(com.hazelcast.jet.pipeline.ServiceFactories.sharedService) QuickTest(com.hazelcast.test.annotation.QuickTest) BiFunctionEx(com.hazelcast.function.BiFunctionEx) Collectors.toMap(java.util.stream.Collectors.toMap) Arrays.asList(java.util.Arrays.asList) DAG(com.hazelcast.jet.core.DAG) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) FunctionEx(com.hazelcast.function.FunctionEx) WatermarkPolicy(com.hazelcast.jet.core.WatermarkPolicy) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Collection(java.util.Collection) JobConfig(com.hazelcast.jet.config.JobConfig) START_FROM_OLDEST(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST) Category(org.junit.experimental.categories.Category) Executors(java.util.concurrent.Executors) Collectors.joining(java.util.stream.Collectors.joining) Sources(com.hazelcast.jet.pipeline.Sources) Stream(java.util.stream.Stream) EventJournalMapEvent(com.hazelcast.map.EventJournalMapEvent) SinkProcessors(com.hazelcast.jet.core.processor.SinkProcessors) IntStream(java.util.stream.IntStream) PredicateEx.alwaysTrue(com.hazelcast.function.PredicateEx.alwaysTrue) EdgeConfig(com.hazelcast.jet.config.EdgeConfig) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) CompletableFuture(java.util.concurrent.CompletableFuture) HazelcastSerialParametersRunnerFactory(com.hazelcast.test.HazelcastSerialParametersRunnerFactory) Function(java.util.function.Function) DEFAULT_MAX_CONCURRENT_OPS(com.hazelcast.jet.pipeline.GeneralStage.DEFAULT_MAX_CONCURRENT_OPS) TestUtil.throttle(com.hazelcast.jet.core.TestUtil.throttle) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ServiceFactory(com.hazelcast.jet.pipeline.ServiceFactory) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) ExecutorService(java.util.concurrent.ExecutorService) Job(com.hazelcast.jet.Job) Before(org.junit.Before) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) IList(com.hazelcast.collection.IList) Config(com.hazelcast.config.Config) SourceProcessors.streamMapP(com.hazelcast.jet.core.processor.SourceProcessors.streamMapP) Parameter(org.junit.runners.Parameterized.Parameter) EXACTLY_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE) Sinks(com.hazelcast.jet.pipeline.Sinks) Traversers.traverseItems(com.hazelcast.jet.Traversers.traverseItems) Test(org.junit.Test) Vertex(com.hazelcast.jet.core.Vertex) FunctionEx.identity(com.hazelcast.function.FunctionEx.identity) EventTimePolicy.eventTimePolicy(com.hazelcast.jet.core.EventTimePolicy.eventTimePolicy) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) TriFunction(com.hazelcast.jet.function.TriFunction) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) Edge.between(com.hazelcast.jet.core.Edge.between) Vertex(com.hazelcast.jet.core.Vertex) EdgeConfig(com.hazelcast.jet.config.EdgeConfig) EventJournalMapEvent(com.hazelcast.map.EventJournalMapEvent) DAG(com.hazelcast.jet.core.DAG) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutorService(java.util.concurrent.ExecutorService) Job(com.hazelcast.jet.Job)

Example 8 with Traverser

use of com.hazelcast.jet.Traverser in project hazelcast by hazelcast.

the class KinesisSourceP method runReaders.

private void runReaders() {
    if (!shardReaders.isEmpty()) {
        long currentTime = System.nanoTime();
        for (int i = 0; i < shardReaders.size(); i++) {
            int currentReader = nextReader;
            ShardReader reader = shardReaders.get(currentReader);
            nextReader = incrementCircular(currentReader, shardReaders.size());
            ShardReader.Result result = reader.probe(currentTime);
            if (ShardReader.Result.HAS_DATA.equals(result)) {
                Shard shard = reader.getShard();
                traverser = reader.clearData().flatMap(record -> {
                    T payload = projectionFn.apply(record, shard);
                    return eventTimeMapper.flatMapEvent(payload, currentReader, record.getApproximateArrivalTimestamp().getTime());
                });
                Long watermark = eventTimeMapper.getWatermark(currentReader);
                watermark = watermark < 0 ? null : watermark;
                shardStates.update(shard, reader.getLastSeenSeqNo(), watermark);
                emitFromTraverser(traverser);
                return;
            } else if (ShardReader.Result.CLOSED.equals(result)) {
                Shard shard = reader.getShard();
                logger.info("Shard " + shard.getShardId() + " of stream " + stream + " closed");
                shardStates.close(shard);
                nextReader = 0;
                traverser = removeShardReader(currentReader);
                emitFromTraverser(traverser);
                return;
            }
        }
    }
    traverser = eventTimeMapper.flatMapIdle();
    emitFromTraverser(traverser);
}
Also used : Shard(com.amazonaws.services.kinesis.model.Shard) AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) Traverser(com.hazelcast.jet.Traverser) Record(com.amazonaws.services.kinesis.model.Record) Traversers.traverseStream(com.hazelcast.jet.Traversers.traverseStream) HashMap(java.util.HashMap) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) AmazonKinesisAsync(com.amazonaws.services.kinesis.AmazonKinesisAsync) ArrayList(java.util.ArrayList) JetException(com.hazelcast.jet.JetException) BiFunctionEx(com.hazelcast.function.BiFunctionEx) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ILogger(com.hazelcast.logging.ILogger) Util.entry(com.hazelcast.jet.Util.entry) Map(java.util.Map) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) BigInteger(java.math.BigInteger) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) Nonnull(javax.annotation.Nonnull) KinesisUtil.shardBelongsToRange(com.hazelcast.jet.kinesis.impl.KinesisUtil.shardBelongsToRange) Nullable(javax.annotation.Nullable) EventTimeMapper(com.hazelcast.jet.core.EventTimeMapper) MetricsCollectionContext(com.hazelcast.internal.metrics.MetricsCollectionContext) IOException(java.io.IOException) Traversers(com.hazelcast.jet.Traversers) Collectors(java.util.stream.Collectors) BroadcastKey(com.hazelcast.jet.core.BroadcastKey) Util.toLocalTime(com.hazelcast.jet.impl.util.Util.toLocalTime) Objects(java.util.Objects) List(java.util.List) BroadcastKey.broadcastKey(com.hazelcast.jet.core.BroadcastKey.broadcastKey) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) RetryStrategy(com.hazelcast.jet.retry.RetryStrategy) Shard(com.amazonaws.services.kinesis.model.Shard)

Example 9 with Traverser

use of com.hazelcast.jet.Traverser in project hazelcast by hazelcast.

the class ReadFilesP method init.

@Override
protected void init(@Nonnull Context context) {
    ILogger logger = context.logger();
    int processorIndex = sharedFileSystem ? context.globalProcessorIndex() : context.localProcessorIndex();
    int parallelism = sharedFileSystem ? context.totalParallelism() : context.localParallelism();
    traverser = new LocalFileTraverser<>(logger, directory, glob, ignoreFileNotFound, path -> shouldProcessEvent(path, parallelism, processorIndex), readFileFn);
}
Also used : Address(com.hazelcast.cluster.Address) AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) Traverser(com.hazelcast.jet.Traverser) Util.checkSerializable(com.hazelcast.jet.impl.util.Util.checkSerializable) SourceProcessors(com.hazelcast.jet.core.processor.SourceProcessors) Traversers.traverseStream(com.hazelcast.jet.Traversers.traverseStream) ACTION_READ(com.hazelcast.security.permission.ActionConstants.ACTION_READ) Function(java.util.function.Function) JetException(com.hazelcast.jet.JetException) DirectoryStream(java.nio.file.DirectoryStream) ILogger(com.hazelcast.logging.ILogger) Traversers.traverseIterator(com.hazelcast.jet.Traversers.traverseIterator) Nonnull(javax.annotation.Nonnull) Path(java.nio.file.Path) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) FunctionEx(com.hazelcast.function.FunctionEx) Logger(com.hazelcast.logging.Logger) Iterator(java.util.Iterator) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) ConnectorPermission(com.hazelcast.security.permission.ConnectorPermission) IOException(java.io.IOException) FileProcessorMetaSupplier(com.hazelcast.jet.pipeline.file.impl.FileProcessorMetaSupplier) File(java.io.File) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) Permission(java.security.Permission) Util.uncheckCall(com.hazelcast.jet.impl.util.Util.uncheckCall) FileTraverser(com.hazelcast.jet.pipeline.file.impl.FileTraverser) ILogger(com.hazelcast.logging.ILogger)

Example 10 with Traverser

use of com.hazelcast.jet.Traverser in project hazelcast by hazelcast.

the class ComputeStageImplBase method attachMapUsingPartitionedServiceAsync.

@Nonnull
@SuppressWarnings({ "unchecked", "rawtypes" })
<S, K, R, RET> RET attachMapUsingPartitionedServiceAsync(@Nonnull ServiceFactory<?, S> serviceFactory, int maxConcurrentOps, boolean preserveOrder, @Nonnull FunctionEx<? super T, ? extends K> partitionKeyFn, @Nonnull BiFunctionEx<? super S, ? super T, ? extends CompletableFuture<R>> mapAsyncFn) {
    checkSerializable(mapAsyncFn, "mapAsyncFn");
    checkSerializable(partitionKeyFn, "partitionKeyFn");
    serviceFactory = moveAttachedFilesToPipeline(serviceFactory);
    BiFunctionEx<? super S, ? super T, ? extends CompletableFuture<Traverser<R>>> flatMapAsyncFn = (s, t) -> mapAsyncFn.apply(s, t).thenApply(Traversers::singleton);
    BiFunctionEx adaptedFlatMapFn = fnAdapter.adaptFlatMapUsingServiceAsyncFn(flatMapAsyncFn);
    FunctionEx adaptedPartitionKeyFn = fnAdapter.adaptKeyFn(partitionKeyFn);
    PartitionedProcessorTransform processorTransform = flatMapUsingServiceAsyncPartitionedTransform(transform, "map", serviceFactory, maxConcurrentOps, preserveOrder, adaptedFlatMapFn, adaptedPartitionKeyFn);
    return attach(processorTransform, fnAdapter);
}
Also used : Traverser(com.hazelcast.jet.Traverser) PartitionedProcessorTransform.partitionedCustomProcessorTransform(com.hazelcast.jet.impl.pipeline.transform.PartitionedProcessorTransform.partitionedCustomProcessorTransform) PartitionedProcessorTransform.flatMapUsingServiceAsyncBatchedPartitionedTransform(com.hazelcast.jet.impl.pipeline.transform.PartitionedProcessorTransform.flatMapUsingServiceAsyncBatchedPartitionedTransform) ProcessorTransform.flatMapUsingServiceTransform(com.hazelcast.jet.impl.pipeline.transform.ProcessorTransform.flatMapUsingServiceTransform) ProcessorTransform.mapUsingServiceTransform(com.hazelcast.jet.impl.pipeline.transform.ProcessorTransform.mapUsingServiceTransform) Collections.singletonList(java.util.Collections.singletonList) BiFunctionEx(com.hazelcast.function.BiFunctionEx) JoinClause(com.hazelcast.jet.pipeline.JoinClause) Traversers.traverseIterable(com.hazelcast.jet.Traversers.traverseIterable) Arrays.asList(java.util.Arrays.asList) ProcessorTransform.flatMapUsingServiceAsyncTransform(com.hazelcast.jet.impl.pipeline.transform.ProcessorTransform.flatMapUsingServiceAsyncTransform) Preconditions.checkTrue(com.hazelcast.internal.util.Preconditions.checkTrue) PredicateEx(com.hazelcast.function.PredicateEx) GlobalMapStatefulTransform(com.hazelcast.jet.impl.pipeline.transform.GlobalMapStatefulTransform) PeekTransform(com.hazelcast.jet.impl.pipeline.transform.PeekTransform) GeneralStage(com.hazelcast.jet.pipeline.GeneralStage) FunctionEx(com.hazelcast.function.FunctionEx) PartitionedProcessorTransform.flatMapUsingServiceAsyncPartitionedTransform(com.hazelcast.jet.impl.pipeline.transform.PartitionedProcessorTransform.flatMapUsingServiceAsyncPartitionedTransform) Collections.emptyList(java.util.Collections.emptyList) SupplierEx(com.hazelcast.function.SupplierEx) List(java.util.List) JetEvent.jetEvent(com.hazelcast.jet.impl.JetEvent.jetEvent) ProcessorTransform(com.hazelcast.jet.impl.pipeline.transform.ProcessorTransform) MergeTransform(com.hazelcast.jet.impl.pipeline.transform.MergeTransform) PartitionedProcessorTransform(com.hazelcast.jet.impl.pipeline.transform.PartitionedProcessorTransform) Sink(com.hazelcast.jet.pipeline.Sink) MapStatefulTransform(com.hazelcast.jet.impl.pipeline.transform.MapStatefulTransform) ComparatorEx(com.hazelcast.function.ComparatorEx) Util.checkSerializable(com.hazelcast.jet.impl.util.Util.checkSerializable) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) JetException(com.hazelcast.jet.JetException) BatchStage(com.hazelcast.jet.pipeline.BatchStage) GlobalFlatMapStatefulTransform(com.hazelcast.jet.impl.pipeline.transform.GlobalFlatMapStatefulTransform) SinkTransform(com.hazelcast.jet.impl.pipeline.transform.SinkTransform) ProcessorTransform.filterUsingServiceTransform(com.hazelcast.jet.impl.pipeline.transform.ProcessorTransform.filterUsingServiceTransform) PartitionedProcessorTransform.flatMapUsingServicePartitionedTransform(com.hazelcast.jet.impl.pipeline.transform.PartitionedProcessorTransform.flatMapUsingServicePartitionedTransform) DEFAULT_IDLE_TIMEOUT(com.hazelcast.jet.core.EventTimePolicy.DEFAULT_IDLE_TIMEOUT) MapTransform(com.hazelcast.jet.impl.pipeline.transform.MapTransform) TimestampTransform(com.hazelcast.jet.impl.pipeline.transform.TimestampTransform) ServiceFactory(com.hazelcast.jet.pipeline.ServiceFactory) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) BiPredicateEx(com.hazelcast.function.BiPredicateEx) FlatMapStatefulTransform(com.hazelcast.jet.impl.pipeline.transform.FlatMapStatefulTransform) StreamStage(com.hazelcast.jet.pipeline.StreamStage) ProcessorTransform.flatMapUsingServiceAsyncBatchedTransform(com.hazelcast.jet.impl.pipeline.transform.ProcessorTransform.flatMapUsingServiceAsyncBatchedTransform) Util.toList(com.hazelcast.jet.impl.util.Util.toList) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) PartitionedProcessorTransform.filterUsingServicePartitionedTransform(com.hazelcast.jet.impl.pipeline.transform.PartitionedProcessorTransform.filterUsingServicePartitionedTransform) WatermarkPolicy.limitingLag(com.hazelcast.jet.core.WatermarkPolicy.limitingLag) Traversers(com.hazelcast.jet.Traversers) ProcessorTransform.customProcessorTransform(com.hazelcast.jet.impl.pipeline.transform.ProcessorTransform.customProcessorTransform) AbstractTransform(com.hazelcast.jet.impl.pipeline.transform.AbstractTransform) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) PartitionedProcessorTransform.mapUsingServicePartitionedTransform(com.hazelcast.jet.impl.pipeline.transform.PartitionedProcessorTransform.mapUsingServicePartitionedTransform) SinkStage(com.hazelcast.jet.pipeline.SinkStage) ToLongFunctionEx(com.hazelcast.function.ToLongFunctionEx) HashJoinTransform(com.hazelcast.jet.impl.pipeline.transform.HashJoinTransform) SortTransform(com.hazelcast.jet.impl.pipeline.transform.SortTransform) EventTimePolicy.eventTimePolicy(com.hazelcast.jet.core.EventTimePolicy.eventTimePolicy) FlatMapTransform(com.hazelcast.jet.impl.pipeline.transform.FlatMapTransform) TriFunction(com.hazelcast.jet.function.TriFunction) Traverser(com.hazelcast.jet.Traverser) PartitionedProcessorTransform(com.hazelcast.jet.impl.pipeline.transform.PartitionedProcessorTransform) BiFunctionEx(com.hazelcast.function.BiFunctionEx) FunctionEx(com.hazelcast.function.FunctionEx) ToLongFunctionEx(com.hazelcast.function.ToLongFunctionEx) Traversers(com.hazelcast.jet.Traversers) BiFunctionEx(com.hazelcast.function.BiFunctionEx) Nonnull(javax.annotation.Nonnull)

Aggregations

Traverser (com.hazelcast.jet.Traverser)18 List (java.util.List)12 FunctionEx (com.hazelcast.function.FunctionEx)10 Nonnull (javax.annotation.Nonnull)10 Traversers (com.hazelcast.jet.Traversers)9 BiFunctionEx (com.hazelcast.function.BiFunctionEx)7 JetException (com.hazelcast.jet.JetException)7 Function (java.util.function.Function)7 Nullable (javax.annotation.Nullable)7 Traversers.traverseIterable (com.hazelcast.jet.Traversers.traverseIterable)6 EventTimePolicy.eventTimePolicy (com.hazelcast.jet.core.EventTimePolicy.eventTimePolicy)6 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 SupplierEx (com.hazelcast.function.SupplierEx)5 AbstractProcessor (com.hazelcast.jet.core.AbstractProcessor)5 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)5 ComparatorEx (com.hazelcast.function.ComparatorEx)4 ToLongFunctionEx (com.hazelcast.function.ToLongFunctionEx)4 Traversers.traverseStream (com.hazelcast.jet.Traversers.traverseStream)4 DAG (com.hazelcast.jet.core.DAG)4