Search in sources :

Example 1 with ProcessorSupplier

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

the class TransformUsingContextPTest method testSharing.

private void testSharing(boolean share) {
    int[] createCounter = { 0 };
    int[] destroyCounter = { 0 };
    ContextFactory<String> contextFactory = ContextFactory.withCreateFn(jet -> "context-" + createCounter[0]++).withDestroyFn(ctx -> destroyCounter[0]++);
    if (share) {
        contextFactory = contextFactory.shareLocally();
    }
    ProcessorSupplier supplier = supplier(contextFactory, mapToContext());
    TestOutbox outbox1 = new TestOutbox(1);
    TestOutbox outbox2 = new TestOutbox(1);
    supplier.init(new TestProcessorSupplierContext());
    assertEquals(share ? 1 : 0, createCounter[0]);
    // noinspection SuspiciousToArrayCall
    TransformUsingContextP[] processors = supplier.get(2).toArray(new TransformUsingContextP[0]);
    processors[0].init(outbox1, new TestProcessorContext());
    assertEquals(1, createCounter[0]);
    processors[1].init(outbox2, new TestProcessorContext());
    assertEquals(share ? 1 : 2, createCounter[0]);
    assertEquals(share, processors[0].contextObject == processors[1].contextObject);
    processors[0].tryProcess(0, "foo");
    processors[1].tryProcess(0, "foo");
    assertEquals("context-0", outbox1.queue(0).poll());
    assertEquals(share ? "context-0" : "context-1", outbox2.queue(0).poll());
    processors[0].close(null);
    assertEquals(share ? 0 : 1, destroyCounter[0]);
    processors[1].close(null);
    assertEquals(share ? 0 : 2, destroyCounter[0]);
    supplier.close(null);
    assertEquals(share ? 1 : 2, destroyCounter[0]);
}
Also used : Traverser(com.hazelcast.jet.Traverser) TestProcessorSupplierContext(com.hazelcast.jet.core.test.TestProcessorSupplierContext) ContextFactory(com.hazelcast.jet.pipeline.ContextFactory) TransformUsingContextP.supplier(com.hazelcast.jet.impl.processor.TransformUsingContextP.supplier) ResettableSingletonTraverser(com.hazelcast.jet.core.ResettableSingletonTraverser) Test(org.junit.Test) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) DistributedTriFunction(com.hazelcast.jet.function.DistributedTriFunction) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Assert.assertEquals(org.junit.Assert.assertEquals) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) TestProcessorSupplierContext(com.hazelcast.jet.core.test.TestProcessorSupplierContext)

Example 2 with ProcessorSupplier

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

the class TransformUsingContextPTest method testEqualCooperativity.

private void testEqualCooperativity(boolean cooperative) {
    ContextFactory<String> contextFactory = ContextFactory.withCreateFn(jet -> "foo");
    if (!cooperative) {
        contextFactory = contextFactory.nonCooperative();
    }
    ProcessorSupplier supplier = supplier(contextFactory, mapToContext());
    supplier.init(new TestProcessorSupplierContext());
    assertEquals(cooperative, supplier.get(1).iterator().next().isCooperative());
}
Also used : ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) TestProcessorSupplierContext(com.hazelcast.jet.core.test.TestProcessorSupplierContext)

Example 3 with ProcessorSupplier

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

the class ExecutionPlan method initProcSuppliers.

// End implementation of IdentifiedDataSerializable
private void initProcSuppliers() {
    JetService service = nodeEngine.getService(JetService.SERVICE_NAME);
    for (VertexDef vertex : vertices) {
        ProcessorSupplier supplier = vertex.processorSupplier();
        ILogger logger = nodeEngine.getLogger(supplier.getClass().getName() + '.' + vertex.name() + "#ProcessorSupplier");
        supplier.init(new ProcSupplierCtx(service.getJetInstance(), logger, vertex.name(), vertex.localParallelism(), vertex.totalParallelism()));
    }
}
Also used : ProcSupplierCtx(com.hazelcast.jet.impl.execution.init.Contexts.ProcSupplierCtx) JetService(com.hazelcast.jet.impl.JetService) ILogger(com.hazelcast.logging.ILogger) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier)

Example 4 with ProcessorSupplier

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

the class ExecutionContext method completeExecution.

/**
 * Complete local execution. If local execution was started, it should be
 * called after execution has completed.
 */
public void completeExecution(Throwable error) {
    assert executionFuture == null || executionFuture.isDone() : "If execution was begun, then completeExecution() should not be called before execution is done.";
    for (Processor processor : processors) {
        try {
            processor.close(error);
        } catch (Throwable e) {
            logger.severe(jobAndExecutionId(jobId, executionId) + " encountered an exception in Processor.close(), ignoring it", e);
        }
    }
    for (ProcessorSupplier s : procSuppliers) {
        try {
            s.close(error);
        } catch (Throwable e) {
            logger.severe(jobAndExecutionId(jobId, executionId) + " encountered an exception in ProcessorSupplier.complete(), ignoring it", e);
        }
    }
    MetricsRegistry metricsRegistry = ((NodeEngineImpl) nodeEngine).getMetricsRegistry();
    processors.forEach(metricsRegistry::deregister);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) Processor(com.hazelcast.jet.core.Processor) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier)

Example 5 with ProcessorSupplier

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

the class JoinByPrimitiveKeyProcessorTest method runTest.

private void runTest(Expression<Boolean> rowProjectorCondition, Expression<?> rowProjectorProjection, Expression<Boolean> joinCondition, boolean inner, List<JetSqlRow> input, List<JetSqlRow> output) {
    KvRowProjector.Supplier projectorSupplier = KvRowProjector.supplier(new QueryPath[] { QueryPath.KEY_PATH, QueryPath.VALUE_PATH }, new QueryDataType[] { QueryDataType.INT, VARCHAR }, GenericQueryTargetDescriptor.DEFAULT, GenericQueryTargetDescriptor.DEFAULT, rowProjectorCondition, singletonList(rowProjectorProjection));
    ProcessorSupplier processor = new JoinByPrimitiveKeyProcessorSupplier(inner, 0, joinCondition, MAP_NAME, projectorSupplier);
    TestSupport.verifyProcessor(adaptSupplier(processor)).jobConfig(new JobConfig().setArgument(SQL_ARGUMENTS_KEY_NAME, emptyList())).input(input).hazelcastInstance(instance()).outputChecker(SqlTestSupport::compareRowLists).disableProgressAssertion().expectOutput(output);
}
Also used : KvRowProjector(com.hazelcast.jet.sql.impl.connector.keyvalue.KvRowProjector) SqlTestSupport(com.hazelcast.jet.sql.SqlTestSupport) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) JobConfig(com.hazelcast.jet.config.JobConfig)

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