use of com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap in project apex-malhar by apache.
the class WindowUtilsTest method createOperatorContext.
public static OperatorContext createOperatorContext(int streamingWindowMillis, int appWindowCount) {
DefaultAttributeMap attributeMap = new DefaultAttributeMap();
attributeMap.put(DAGContext.STREAMING_WINDOW_SIZE_MILLIS, streamingWindowMillis);
attributeMap.put(OperatorContext.APPLICATION_WINDOW_COUNT, appWindowCount);
return mockOperatorContext(1, attributeMap);
}
use of com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap in project apex-core by apache.
the class InputNodeTest method emitTestHelper.
private void emitTestHelper(boolean trueEmitTuplesFalseHandleIdleTime) throws Exception {
TestInputOperator tio = new TestInputOperator();
tio.trueEmitTuplesFalseHandleIdleTime = trueEmitTuplesFalseHandleIdleTime;
DefaultAttributeMap dam = new DefaultAttributeMap();
dam.put(OperatorContext.APPLICATION_WINDOW_COUNT, 10);
dam.put(OperatorContext.CHECKPOINT_WINDOW_COUNT, 10);
final InputNode in = new InputNode(tio, new OperatorContext(0, "operator", dam, null));
TestSink testSink = new TestSink();
in.connectInputPort(Node.INPUT, new TestWindowGenerator());
in.connectOutputPort("output", testSink);
Thread t = new Thread() {
@Override
public void run() {
in.activate();
in.run();
in.deactivate();
}
};
t.start();
Thread.sleep(3000);
in.shutdown();
t.join();
Assert.assertTrue("Should have emitted some tuples", testSink.collectedTuples.size() > 0);
boolean insideWindow = false;
for (Object tuple : testSink.collectedTuples) {
if (tuple instanceof Tuple) {
Tuple controlTuple = (Tuple) tuple;
MessageType tupleType = controlTuple.getType();
if (tupleType == MessageType.RESET_WINDOW) {
Assert.assertFalse(insideWindow);
} else if (tupleType == MessageType.BEGIN_WINDOW) {
Assert.assertFalse(insideWindow);
insideWindow = true;
} else if (tupleType == MessageType.END_WINDOW) {
Assert.assertTrue(insideWindow);
insideWindow = false;
}
} else {
Assert.assertTrue(insideWindow);
}
}
}
use of com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap in project apex-core by apache.
the class NodeTest method testOperatorCheckpointing.
@Test
public void testOperatorCheckpointing() {
DefaultAttributeMap attributeMap = new DefaultAttributeMap();
attributeMap.put(OperatorContext.STORAGE_AGENT, new StorageAgentImpl());
Node<TestGenericOperator> node = new Node<TestGenericOperator>(new TestGenericOperator(), new com.datatorrent.stram.engine.OperatorContext(0, "operator", attributeMap, null)) {
@Override
public void connectInputPort(String port, SweepableReservoir reservoir) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void run() {
throw new UnsupportedOperationException("Not supported yet.");
}
};
node.activate();
synchronized (StorageAgentImpl.calls) {
StorageAgentImpl.calls.clear();
node.checkpoint(0);
Assert.assertEquals("Calls to StorageAgent", 1, StorageAgentImpl.calls.size());
}
node.deactivate();
}
use of com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap in project apex-core by apache.
the class GenericNodeTest method testControlTuplesDeliveryOiONode.
@Test
public void testControlTuplesDeliveryOiONode() throws InterruptedException {
GenericOperator go = new GenericOperator();
final OiONode oioNode = new OiONode(go, new com.datatorrent.stram.engine.OperatorContext(0, "operator", new DefaultAttributeMap(), null));
oioNode.setId(1);
OiOStream stream = new OiOStream();
SweepableReservoir reservoir = stream.getReservoir();
((OiOStream.OiOReservoir) reservoir).setControlSink((oioNode).getControlSink(reservoir));
oioNode.connectInputPort("ip1", reservoir);
Sink controlSink = oioNode.getControlSink(reservoir);
TestSink testSink = new TestSink();
oioNode.connectOutputPort("op", testSink);
oioNode.firstWindowMillis = 0;
oioNode.windowWidthMillis = 100;
oioNode.activate();
Tuple beginWindow = new Tuple(MessageType.BEGIN_WINDOW, 0x1L);
controlSink.put(beginWindow);
Assert.assertTrue("Begin window", testSink.getResultCount() == 1);
CustomControlTuple t1 = new CustomControlTuple(new CustomControlTupleTest.TestControlTuple(1, false));
CustomControlTuple t2 = new CustomControlTuple(new CustomControlTupleTest.TestControlTuple(2, true));
CustomControlTuple t3 = new CustomControlTuple(new CustomControlTupleTest.TestControlTuple(3, false));
CustomControlTuple t4 = new CustomControlTuple(new CustomControlTupleTest.TestControlTuple(4, true));
controlSink.put(t1);
controlSink.put(t2);
controlSink.put(t3);
controlSink.put(t4);
Assert.assertTrue("Custom control tuples emitted immediately", testSink.getResultCount() == 3);
Tuple endWindow = new Tuple(MessageType.END_WINDOW, 0x1L);
controlSink.put(endWindow);
oioNode.deactivate();
oioNode.shutdown();
Assert.assertTrue("Total control tuples", testSink.getResultCount() == 6);
long expected = 0;
for (Object o : testSink.collectedTuples) {
if (o instanceof CustomControlTuple) {
expected++;
}
}
Assert.assertTrue("Number of Custom control tuples", expected == 4);
}
use of com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap in project apex-core by apache.
the class GenericNodeTest method testReservoirPortMapping.
@Test
public void testReservoirPortMapping() throws InterruptedException {
long maxSleep = 5000;
long sleeptime = 25L;
GenericOperator go = new GenericOperator();
final GenericNode gn = new GenericNode(go, new com.datatorrent.stram.engine.OperatorContext(0, "operator", new DefaultAttributeMap(), null));
gn.setId(1);
AbstractReservoir reservoir1 = AbstractReservoir.newReservoir("ip1Res", 1024);
AbstractReservoir reservoir2 = AbstractReservoir.newReservoir("ip2Res", 1024);
gn.connectInputPort("ip1", reservoir1);
gn.connectInputPort("ip2", reservoir2);
gn.connectOutputPort("op", Sink.BLACKHOLE);
gn.firstWindowMillis = 0;
gn.windowWidthMillis = 100;
final AtomicBoolean ab = new AtomicBoolean(false);
Thread t = new Thread() {
@Override
public void run() {
ab.set(true);
gn.activate();
gn.run();
gn.deactivate();
}
};
t.start();
long interval = 0;
do {
Thread.sleep(sleeptime);
interval += sleeptime;
} while ((ab.get() == false) && (interval < maxSleep));
gn.populateReservoirInputPortMap();
gn.shutdown();
t.join();
Assert.assertTrue("Port Mapping Size", gn.reservoirPortMap.size() == 2);
Assert.assertTrue("Sink 1 is not a port", gn.reservoirPortMap.get(reservoir1) instanceof Operator.InputPort);
Assert.assertTrue("Sink 2 is not a port", gn.reservoirPortMap.get(reservoir2) instanceof Operator.InputPort);
}
Aggregations