Search in sources :

Example 11 with ProcessorMetaSupplier

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

the class SinksTest method mapWithMerging_when_multipleValuesForSingleKeyInABatch.

@Test
public void mapWithMerging_when_multipleValuesForSingleKeyInABatch() throws Exception {
    ProcessorMetaSupplier metaSupplier = adaptSupplier(SinkProcessors.<Entry<String, Integer>, String, Integer>mergeMapP(sinkName, Entry::getKey, Entry::getValue, Integer::sum));
    TestProcessorSupplierContext psContext = new TestProcessorSupplierContext().setHazelcastInstance(member);
    Processor p = TestSupport.supplierFrom(metaSupplier, psContext).get();
    TestOutbox outbox = new TestOutbox();
    p.init(outbox, new TestProcessorContext().setHazelcastInstance(member));
    TestInbox inbox = new TestInbox();
    inbox.add(entry("k", 1));
    inbox.add(entry("k", 2));
    p.process(0, inbox);
    assertTrue("inbox.isEmpty()", inbox.isEmpty());
    assertTrueEventually(() -> {
        assertTrue("p.complete()", p.complete());
    }, 10);
    p.close();
    // assert the output map contents
    IMap<Object, Object> actual = member.getMap(sinkName);
    assertEquals(1, actual.size());
    assertEquals(3, actual.get("k"));
}
Also used : Processor(com.hazelcast.jet.core.Processor) EntryProcessor(com.hazelcast.map.EntryProcessor) TestInbox(com.hazelcast.jet.core.test.TestInbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) TestProcessorSupplierContext(com.hazelcast.jet.core.test.TestProcessorSupplierContext) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 12 with ProcessorMetaSupplier

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

the class StreamJmsPTest method when_sharedConsumer_then_twoProcessorsUsed.

@Test
public void when_sharedConsumer_then_twoProcessorsUsed() throws Exception {
    String topicName = randomString();
    logger.info("using topic: " + topicName);
    StreamSource<Message> source = Sources.jmsTopicBuilder(StreamJmsPTest::getConnectionFactory).destinationName("foo").sharedConsumer(true).build();
    ProcessorMetaSupplier metaSupplier = ((StreamSourceTransform<Message>) source).metaSupplierFn.apply(noEventTime());
    Address address1 = new Address("127.0.0.1", 1);
    Address address2 = new Address("127.0.0.1", 2);
    Function<? super Address, ? extends ProcessorSupplier> function = metaSupplier.get(asList(address1, address2));
    // Then
    // assert that processors for both addresses are actually StreamJmsP, not a noopP
    assertInstanceOf(StreamJmsP.class, function.apply(address1).get(1).iterator().next());
    assertInstanceOf(StreamJmsP.class, function.apply(address2).get(1).iterator().next());
}
Also used : Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Address(com.hazelcast.cluster.Address) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with ProcessorMetaSupplier

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

the class StreamFilesPTest method when_metaSupplier_then_returnsCorrectProcessors.

@Test
public void when_metaSupplier_then_returnsCorrectProcessors() throws Exception {
    ProcessorMetaSupplier metaSupplier = streamFilesP(workDir.getAbsolutePath(), UTF_8, "*", false, Util::entry);
    Address a = new Address();
    ProcessorSupplier supplier = metaSupplier.get(singletonList(a)).apply(a);
    supplier.init(new TestProcessorContext());
    assertEquals(1, supplier.get(1).size());
    supplier.close(null);
}
Also used : Address(com.hazelcast.cluster.Address) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) IOUtil(com.hazelcast.internal.nio.IOUtil) Util(com.hazelcast.jet.Util) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with ProcessorMetaSupplier

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

the class PartitionedProcessorTransform method flatMapUsingServiceAsyncPartitionedTransform.

public static <S, T, K, R> PartitionedProcessorTransform<T, K> flatMapUsingServiceAsyncPartitionedTransform(@Nonnull Transform upstream, @Nonnull String operationName, @Nonnull ServiceFactory<?, S> serviceFactory, int maxConcurrentOps, boolean preserveOrder, @Nonnull BiFunctionEx<? super S, ? super T, CompletableFuture<Traverser<R>>> flatMapAsyncFn, @Nonnull FunctionEx<? super T, ? extends K> partitionKeyFn) {
    String name = operationName + "UsingPartitionedServiceAsync";
    ProcessorSupplier supplier = flatMapUsingServiceAsyncP(serviceFactory, maxConcurrentOps, preserveOrder, partitionKeyFn, flatMapAsyncFn);
    ProcessorMetaSupplier metaSupplier = ProcessorMetaSupplier.of(getPreferredLP(serviceFactory), serviceFactory.permission(), supplier);
    return new PartitionedProcessorTransform<>(name, upstream, metaSupplier, partitionKeyFn);
}
Also used : ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier)

Example 15 with ProcessorMetaSupplier

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

the class ProcessorTransform method flatMapUsingServiceAsyncTransform.

public static <S, T, R> ProcessorTransform flatMapUsingServiceAsyncTransform(@Nonnull Transform upstream, @Nonnull String operationName, @Nonnull ServiceFactory<?, S> serviceFactory, int maxConcurrentOps, boolean preserveOrder, @Nonnull BiFunctionEx<? super S, ? super T, ? extends CompletableFuture<Traverser<R>>> flatMapAsyncFn) {
    // TODO use better key so that snapshots are local. Currently they will
    // be sent to a random member. We keep it this way for simplicity:
    // the number of in-flight items is limited (maxConcurrentOps)
    ProcessorSupplier supplier = flatMapUsingServiceAsyncP(serviceFactory, maxConcurrentOps, preserveOrder, Object::hashCode, flatMapAsyncFn);
    ProcessorMetaSupplier metaSupplier = ProcessorMetaSupplier.of(getPreferredLP(serviceFactory), serviceFactory.permission(), supplier);
    return new ProcessorTransform(operationName + "UsingServiceAsync", upstream, metaSupplier);
}
Also used : ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier)

Aggregations

ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)21 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)11 Nonnull (javax.annotation.Nonnull)8 Test (org.junit.Test)6 Vertex (com.hazelcast.jet.core.Vertex)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 List (java.util.List)5 Address (com.hazelcast.cluster.Address)4 FunctionEx (com.hazelcast.function.FunctionEx)4 DAG (com.hazelcast.jet.core.DAG)4 TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)4 JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 Map (java.util.Map)4 EventTimePolicy (com.hazelcast.jet.core.EventTimePolicy)3 Function (java.util.function.Function)3 Nullable (javax.annotation.Nullable)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)2 EdgeConfig (com.hazelcast.jet.config.EdgeConfig)2