Search in sources :

Example 1 with TestOutputOperator

use of com.datatorrent.stram.engine.TestOutputOperator in project apex-core by apache.

the class LogicalPlanTest method testOutputPortAnnotation.

@Test
public void testOutputPortAnnotation() {
    TestAnnotationsOperator ta1 = dag.addOperator("testAnnotationsOperator", new TestAnnotationsOperator());
    try {
        dag.validate();
        Assert.fail("should raise: port connection required");
    } catch (ValidationException e) {
        Assert.assertEquals("", "Output port connection required: testAnnotationsOperator.outport2", e.getMessage());
    }
    TestOutputOperator o2 = dag.addOperator("sink", new TestOutputOperator());
    dag.addStream("s1", ta1.outport2, o2.inport);
    dag.validate();
    TestAnnotationsOperator2 ta2 = dag.addOperator("multiOutputPorts1", new TestAnnotationsOperator2());
    dag.validate();
    TestOutputOperator o3 = dag.addOperator("o3", new TestOutputOperator());
    dag.addStream("s2", ta2.outport1, o3.inport);
    dag.addOperator("multiOutputPorts3", new TestAnnotationsOperator3());
    dag.validate();
}
Also used : ValidationException(javax.validation.ValidationException) TestOutputOperator(com.datatorrent.stram.engine.TestOutputOperator) Test(org.junit.Test)

Example 2 with TestOutputOperator

use of com.datatorrent.stram.engine.TestOutputOperator in project apex-core by apache.

the class OutputUnifiedTest method testManyToOnePartition.

@Test
public void testManyToOnePartition() throws Exception {
    TestInputOperator i1 = new TestInputOperator();
    dag.addOperator("i1", i1);
    GenericTestOperator op1 = new GenericTestOperator();
    dag.addOperator("op1", op1);
    dag.setOperatorAttribute(op1, OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(3));
    TestOutputOperator op2 = new TestOutputOperator();
    dag.addOperator("op2", op2);
    dag.addStream("s1", i1.output, op1.inport1);
    dag.addStream("s2", op1.outport1, op2.inport);
    StreamingContainerManager scm = new StreamingContainerManager(dag);
    PhysicalPlan physicalPlan = scm.getPhysicalPlan();
    List<PTContainer> containers = physicalPlan.getContainers();
    Assert.assertEquals("Number of containers", 5, containers.size());
    assignContainers(scm, containers);
    testOutputAttribute(dag, i1, scm, physicalPlan, false);
    testOutputAttribute(dag, op1, scm, physicalPlan, true);
}
Also used : PhysicalPlan(com.datatorrent.stram.plan.physical.PhysicalPlan) GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) PTContainer(com.datatorrent.stram.plan.physical.PTContainer) TestOutputOperator(com.datatorrent.stram.engine.TestOutputOperator) TestInputOperator(com.datatorrent.stram.stream.OiOEndWindowTest.TestInputOperator) Test(org.junit.Test)

Example 3 with TestOutputOperator

use of com.datatorrent.stram.engine.TestOutputOperator in project apex-core by apache.

the class OutputUnifiedTest method testMxNPartition.

@Test
public void testMxNPartition() throws Exception {
    TestInputOperator i1 = new TestInputOperator();
    dag.addOperator("i1", i1);
    GenericTestOperator op1 = new GenericTestOperator();
    dag.addOperator("op1", op1);
    dag.setOperatorAttribute(op1, OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(3));
    TestOutputOperator op2 = new TestOutputOperator();
    dag.addOperator("op2", op2);
    dag.setOperatorAttribute(op2, OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(2));
    dag.addStream("s1", i1.output, op1.inport1);
    dag.addStream("s2", op1.outport1, op2.inport);
    StreamingContainerManager scm = new StreamingContainerManager(dag);
    PhysicalPlan physicalPlan = scm.getPhysicalPlan();
    List<PTContainer> containers = physicalPlan.getContainers();
    Assert.assertEquals("Number of containers", 6, containers.size());
    assignContainers(scm, containers);
    testOutputAttribute(dag, i1, scm, physicalPlan, false);
    testOutputAttribute(dag, op1, scm, physicalPlan, true);
}
Also used : PhysicalPlan(com.datatorrent.stram.plan.physical.PhysicalPlan) GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) PTContainer(com.datatorrent.stram.plan.physical.PTContainer) TestOutputOperator(com.datatorrent.stram.engine.TestOutputOperator) TestInputOperator(com.datatorrent.stram.stream.OiOEndWindowTest.TestInputOperator) Test(org.junit.Test)

Example 4 with TestOutputOperator

use of com.datatorrent.stram.engine.TestOutputOperator in project apex-core by apache.

the class OutputUnifiedTest method testParallelPartition.

@Test
public void testParallelPartition() throws Exception {
    TestInputOperator i1 = new TestInputOperator();
    dag.addOperator("i1", i1);
    dag.setOperatorAttribute(i1, OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(2));
    GenericTestOperator op1 = new GenericTestOperator();
    dag.addOperator("op1", op1);
    dag.setInputPortAttribute(op1.inport1, PortContext.PARTITION_PARALLEL, true);
    TestOutputOperator op2 = new TestOutputOperator();
    dag.addOperator("op2", op2);
    dag.addStream("s1", i1.output, op1.inport1);
    dag.addStream("s2", op1.outport1, op2.inport);
    StreamingContainerManager scm = new StreamingContainerManager(dag);
    PhysicalPlan physicalPlan = scm.getPhysicalPlan();
    List<PTContainer> containers = physicalPlan.getContainers();
    Assert.assertEquals("Number of containers", 5, containers.size());
    assignContainers(scm, containers);
    testOutputAttribute(dag, i1, scm, physicalPlan, false);
    testOutputAttribute(dag, op1, scm, physicalPlan, true);
}
Also used : PhysicalPlan(com.datatorrent.stram.plan.physical.PhysicalPlan) GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) PTContainer(com.datatorrent.stram.plan.physical.PTContainer) TestOutputOperator(com.datatorrent.stram.engine.TestOutputOperator) TestInputOperator(com.datatorrent.stram.stream.OiOEndWindowTest.TestInputOperator) Test(org.junit.Test)

Example 5 with TestOutputOperator

use of com.datatorrent.stram.engine.TestOutputOperator in project apex-core by apache.

the class StramLocalClusterTest method testLocalClusterInitShutdown.

/**
   * Verify test configuration launches and stops after input terminates.
   * Test validates expected output end to end.
   *
   * @throws Exception
   */
@Test
public void testLocalClusterInitShutdown() throws Exception {
    TestGeneratorInputOperator genNode = dag.addOperator("genNode", TestGeneratorInputOperator.class);
    genNode.setMaxTuples(2);
    GenericTestOperator node1 = dag.addOperator("node1", GenericTestOperator.class);
    node1.setEmitFormat("%s >> node1");
    File outFile = new File("./target/" + StramLocalClusterTest.class.getName() + "-testLocalClusterInitShutdown.out");
    outFile.delete();
    TestOutputOperator outNode = dag.addOperator("outNode", TestOutputOperator.class);
    outNode.pathSpec = outFile.toURI().toString();
    dag.addStream("fromGenNode", genNode.outport, node1.inport1);
    dag.addStream("fromNode1", node1.outport1, outNode.inport);
    dag.getAttributes().put(LogicalPlan.CONTAINERS_MAX_COUNT, 2);
    StramLocalCluster localCluster = new StramLocalCluster(dag);
    localCluster.setHeartbeatMonitoringEnabled(false);
    localCluster.run();
    Assert.assertTrue(outFile + " exists", outFile.exists());
    LineNumberReader lnr = new LineNumberReader(new FileReader(outFile));
    String line;
    while ((line = lnr.readLine()) != null) {
        Assert.assertTrue("line match " + line, line.matches("" + lnr.getLineNumber() + " >> node1"));
    }
    Assert.assertEquals("number lines", 2, lnr.getLineNumber());
    lnr.close();
}
Also used : GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) TestGeneratorInputOperator(com.datatorrent.stram.engine.TestGeneratorInputOperator) TestOutputOperator(com.datatorrent.stram.engine.TestOutputOperator) FileReader(java.io.FileReader) File(java.io.File) LineNumberReader(java.io.LineNumberReader) Test(org.junit.Test)

Aggregations

TestOutputOperator (com.datatorrent.stram.engine.TestOutputOperator)5 Test (org.junit.Test)5 GenericTestOperator (com.datatorrent.stram.engine.GenericTestOperator)4 PTContainer (com.datatorrent.stram.plan.physical.PTContainer)3 PhysicalPlan (com.datatorrent.stram.plan.physical.PhysicalPlan)3 TestInputOperator (com.datatorrent.stram.stream.OiOEndWindowTest.TestInputOperator)3 TestGeneratorInputOperator (com.datatorrent.stram.engine.TestGeneratorInputOperator)1 File (java.io.File)1 FileReader (java.io.FileReader)1 LineNumberReader (java.io.LineNumberReader)1 ValidationException (javax.validation.ValidationException)1