use of com.hazelcast.jet.core.test.TestProcessorSupplierContext 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.test.TestProcessorSupplierContext 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.test.TestProcessorSupplierContext 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"));
}
Aggregations