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]);
}
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());
}
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()));
}
}
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);
}
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);
}
Aggregations