Search in sources :

Example 1 with DefaultAttributeMap

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);
}
Also used : DefaultAttributeMap(com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap)

Example 2 with DefaultAttributeMap

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);
        }
    }
}
Also used : ResetWindowTuple(com.datatorrent.stram.tuple.ResetWindowTuple) EndWindowTuple(com.datatorrent.stram.tuple.EndWindowTuple) Tuple(com.datatorrent.stram.tuple.Tuple) MessageType(com.datatorrent.bufferserver.packet.MessageType) DefaultAttributeMap(com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap)

Example 3 with DefaultAttributeMap

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();
}
Also used : DefaultAttributeMap(com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap) Test(org.junit.Test)

Example 4 with DefaultAttributeMap

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);
}
Also used : DefaultAttributeMap(com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap) Sink(com.datatorrent.api.Sink) OiOStream(com.datatorrent.stram.stream.OiOStream) CustomControlTupleTest(com.datatorrent.stram.CustomControlTupleTest) CustomControlTuple(com.datatorrent.stram.tuple.CustomControlTuple) EndStreamTuple(com.datatorrent.stram.tuple.EndStreamTuple) EndWindowTuple(com.datatorrent.stram.tuple.EndWindowTuple) Tuple(com.datatorrent.stram.tuple.Tuple) CustomControlTuple(com.datatorrent.stram.tuple.CustomControlTuple) PayloadTuple(com.datatorrent.bufferserver.packet.PayloadTuple) CustomControlTupleTest(com.datatorrent.stram.CustomControlTupleTest) Test(org.junit.Test)

Example 5 with DefaultAttributeMap

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);
}
Also used : Operator(com.datatorrent.api.Operator) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultAttributeMap(com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap) CustomControlTupleTest(com.datatorrent.stram.CustomControlTupleTest) Test(org.junit.Test)

Aggregations

DefaultAttributeMap (com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap)14 Test (org.junit.Test)9 Tuple (com.datatorrent.stram.tuple.Tuple)7 CustomControlTupleTest (com.datatorrent.stram.CustomControlTupleTest)6 EndWindowTuple (com.datatorrent.stram.tuple.EndWindowTuple)6 PayloadTuple (com.datatorrent.bufferserver.packet.PayloadTuple)5 Checkpoint (com.datatorrent.stram.api.Checkpoint)5 CustomControlTuple (com.datatorrent.stram.tuple.CustomControlTuple)5 EndStreamTuple (com.datatorrent.stram.tuple.EndStreamTuple)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 Sink (com.datatorrent.api.Sink)4 ScheduledThreadPoolExecutor (com.datatorrent.common.util.ScheduledThreadPoolExecutor)3 ArrayList (java.util.ArrayList)3 Configuration (org.apache.hadoop.conf.Configuration)2 OperatorContext (com.datatorrent.api.Context.OperatorContext)1 Operator (com.datatorrent.api.Operator)1 MessageType (com.datatorrent.bufferserver.packet.MessageType)1 Server (com.datatorrent.bufferserver.server.Server)1 FSStorageAgent (com.datatorrent.common.util.FSStorageAgent)1 ScheduledExecutorService (com.datatorrent.common.util.ScheduledExecutorService)1