Search in sources :

Example 21 with ProcessorSupplier

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

the class TestSupportTest method test_processorMetaSupplierHasJetInstance.

@Test
public void test_processorMetaSupplierHasJetInstance() {
    HazelcastInstance hazelcastInstance = mockHazelcastInstance();
    boolean[] called = { false };
    verifyProcessor(new ProcessorMetaSupplier() {

        @Override
        public void init(@Nonnull Context context) {
            assertSame(context.hazelcastInstance(), hazelcastInstance);
            called[0] = true;
        }

        @Nonnull
        @Override
        public Function<? super Address, ? extends ProcessorSupplier> get(@Nonnull List<Address> addresses) {
            return a -> ProcessorSupplier.of(MockP::new);
        }
    }).hazelcastInstance(hazelcastInstance).expectOutput(emptyList());
    assertTrue(called[0]);
}
Also used : Function(java.util.function.Function) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) Nonnull(javax.annotation.Nonnull) 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 22 with ProcessorSupplier

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

the class TestSupportTest method when_processorSupplierTested_then_completeCalled.

@Test
public void when_processorSupplierTested_then_completeCalled() {
    boolean[] completeCalled = { false };
    ProcessorSupplier supplier = new ProcessorSupplier() {

        @Nonnull
        @Override
        public Collection<? extends Processor> get(int count) {
            assertEquals(1, count);
            return singletonList(noopP().get());
        }

        @Override
        public void close(Throwable error) {
            completeCalled[0] = true;
        }
    };
    TestSupport.verifyProcessor(supplier).expectOutput(emptyList());
    assertTrue("PS.complete not called", completeCalled[0]);
    // test once more with PMS
    completeCalled[0] = false;
    TestSupport.verifyProcessor(ProcessorMetaSupplier.of(supplier)).expectOutput(emptyList());
    assertTrue("PS.complete not called when using PMS", completeCalled[0]);
}
Also used : ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with ProcessorSupplier

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

the class SqlHashJoinPTest method runTest.

private void runTest(JoinRelType joinType, Expression<Boolean> nonEquiCondition, int rightInputColumnCount, int[] leftEquiJoinIndices, int[] rightEquiJoinIndices, List<JetSqlRow> leftInput, List<JetSqlRow> rightInput, List<JetSqlRow> output) {
    ProcessorSupplier processor = SqlHashJoinP.supplier(new JetJoinInfo(joinType, leftEquiJoinIndices, rightEquiJoinIndices, nonEquiCondition, null), rightInputColumnCount);
    TestSupport.verifyProcessor(adaptSupplier(processor)).jobConfig(new JobConfig().setArgument(SQL_ARGUMENTS_KEY_NAME, emptyList())).inputs(asList(leftInput, rightInput), new int[] { LOW_PRIORITY, HIGH_PRIORITY }).hazelcastInstance(instance()).outputChecker(SqlTestSupport::compareRowLists).disableSnapshots().expectOutput(output);
}
Also used : JetJoinInfo(com.hazelcast.jet.sql.impl.JetJoinInfo) SqlTestSupport(com.hazelcast.jet.sql.SqlTestSupport) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) JobConfig(com.hazelcast.jet.config.JobConfig)

Example 24 with ProcessorSupplier

use of com.hazelcast.jet.core.ProcessorSupplier 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 25 with ProcessorSupplier

use of com.hazelcast.jet.core.ProcessorSupplier 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

ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)29 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)14 Nonnull (javax.annotation.Nonnull)10 Test (org.junit.Test)9 List (java.util.List)8 Function (java.util.function.Function)8 JobConfig (com.hazelcast.jet.config.JobConfig)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Traverser (com.hazelcast.jet.Traverser)5 DAG (com.hazelcast.jet.core.DAG)5 Processor (com.hazelcast.jet.core.Processor)5 Vertex (com.hazelcast.jet.core.Vertex)5 EdgeConfig (com.hazelcast.jet.config.EdgeConfig)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 FunctionEx (com.hazelcast.function.FunctionEx)3 Edge (com.hazelcast.jet.core.Edge)3 Address (com.hazelcast.nio.Address)3 Map (java.util.Map)3 Assert.assertEquals (org.junit.Assert.assertEquals)3