Search in sources :

Example 11 with AsyncFSStorageAgent

use of com.datatorrent.common.util.AsyncFSStorageAgent in project apex-core by apache.

the class StatsTest method baseTestForQueueSize.

@SuppressWarnings("SleepWhileInLoop")
private void baseTestForQueueSize(int maxTuples, TestCollectorStatsListener statsListener, DAG.Locality locality) throws Exception {
    LogicalPlan dag = new LogicalPlan();
    String workingDir = new File("target/baseTestForQueueSize").getAbsolutePath();
    dag.setAttribute(Context.OperatorContext.STORAGE_AGENT, new AsyncFSStorageAgent(workingDir, null));
    dag.getAttributes().put(LogicalPlan.STREAMING_WINDOW_SIZE_MILLIS, 200);
    TestOperator testOper = dag.addOperator("TestOperator", TestOperator.class);
    testOper.setMaxTuples(maxTuples);
    TestCollector collector = dag.addOperator("Collector", new TestCollector());
    if (statsListener != null) {
        dag.setOperatorAttribute(collector, OperatorContext.STATS_LISTENERS, Arrays.asList(new StatsListener[] { statsListener }));
    }
    dag.addStream("TestTuples", testOper.outport, collector.inport1).setLocality(locality);
    StramLocalCluster lc = new StramLocalCluster(dag);
    lc.runAsync();
    StreamingContainerManager dnmgr = lc.getStreamingContainerManager();
    Map<Integer, PTOperator> operatorMap = dnmgr.getPhysicalPlan().getAllOperators();
    for (PTOperator p : operatorMap.values()) {
        StramTestSupport.waitForActivation(lc, p);
    }
    long startTms = System.currentTimeMillis();
    if (statsListener != null) {
        while (statsListener.collectorOperatorStats.isEmpty() && (StramTestSupport.DEFAULT_TIMEOUT_MILLIS > System.currentTimeMillis() - startTms)) {
            Thread.sleep(300);
            LOG.debug("Waiting for stats");
        }
    } else {
        while (collector.collectorOperatorStats.isEmpty() && (StramTestSupport.DEFAULT_TIMEOUT_MILLIS > System.currentTimeMillis() - startTms)) {
            Thread.sleep(300);
            LOG.debug("Waiting for stats");
        }
    }
    if (statsListener != null) {
        statsListener.validateStats();
    } else {
        collector.validateStats();
    }
    lc.shutdown();
}
Also used : StreamingContainerManager(com.datatorrent.stram.StreamingContainerManager) PTOperator(com.datatorrent.stram.plan.physical.PTOperator) AsyncFSStorageAgent(com.datatorrent.common.util.AsyncFSStorageAgent) StatsListener(com.datatorrent.api.StatsListener) TestInputStatsListener(com.datatorrent.stram.engine.StatsTest.TestOperator.TestInputStatsListener) TestCollectorStatsListener(com.datatorrent.stram.engine.StatsTest.TestCollector.TestCollectorStatsListener) StramLocalCluster(com.datatorrent.stram.StramLocalCluster) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) File(java.io.File)

Example 12 with AsyncFSStorageAgent

use of com.datatorrent.common.util.AsyncFSStorageAgent in project apex-core by apache.

the class TupleRecorderTest method testRecordingFlow.

@Test
public void testRecordingFlow() throws Exception {
    LogicalPlan dag = new LogicalPlan();
    dag.setAttribute(Context.OperatorContext.STORAGE_AGENT, new AsyncFSStorageAgent(testWorkDir.getAbsolutePath(), null));
    dag.getAttributes().put(LogicalPlan.APPLICATION_PATH, "file://" + testWorkDir.getAbsolutePath());
    // 1KB per part
    dag.getAttributes().put(LogicalPlan.TUPLE_RECORDING_PART_FILE_SIZE, 1024);
    TestGeneratorInputOperator op1 = dag.addOperator("op1", TestGeneratorInputOperator.class);
    GenericTestOperator op2 = dag.addOperator("op2", GenericTestOperator.class);
    GenericTestOperator op3 = dag.addOperator("op3", GenericTestOperator.class);
    // emit every 100 msec
    op1.setEmitInterval(100);
    //.setInline(true);
    dag.addStream("stream1", op1.outport, op2.inport1);
    //.setInline(true);
    dag.addStream("stream2", op2.outport1, op3.inport1);
    final StramLocalCluster localCluster = new StramLocalCluster(dag);
    localCluster.runAsync();
    final PTOperator ptOp2 = localCluster.findByLogicalNode(dag.getMeta(op2));
    StramTestSupport.waitForActivation(localCluster, ptOp2);
    testRecordingOnOperator(localCluster, ptOp2);
    final PTOperator ptOp1 = localCluster.findByLogicalNode(dag.getMeta(op1));
    StramTestSupport.waitForActivation(localCluster, ptOp1);
    testRecordingOnOperator(localCluster, ptOp1);
    localCluster.shutdown();
}
Also used : PTOperator(com.datatorrent.stram.plan.physical.PTOperator) GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) AsyncFSStorageAgent(com.datatorrent.common.util.AsyncFSStorageAgent) TestGeneratorInputOperator(com.datatorrent.stram.engine.TestGeneratorInputOperator) StramLocalCluster(com.datatorrent.stram.StramLocalCluster) Test(org.junit.Test)

Example 13 with AsyncFSStorageAgent

use of com.datatorrent.common.util.AsyncFSStorageAgent in project apex-core by apache.

the class AtLeastOnceTest method testOperatorRecovery.

@Test
public void testOperatorRecovery() throws Exception {
    RecoverableInputOperator.initGenTuples();
    CollectorOperator.collection.clear();
    int maxTuples = 30;
    LogicalPlan dag = new LogicalPlan();
    String workingDir = new File("target/testOperatorRecovery").getAbsolutePath();
    AsyncFSStorageAgent asyncFSStorageAgent = new AsyncFSStorageAgent(workingDir, null);
    asyncFSStorageAgent.setSyncCheckpoint(true);
    dag.setAttribute(Context.OperatorContext.STORAGE_AGENT, asyncFSStorageAgent);
    dag.getAttributes().put(LogicalPlan.CHECKPOINT_WINDOW_COUNT, 2);
    dag.getAttributes().put(LogicalPlan.STREAMING_WINDOW_SIZE_MILLIS, 300);
    dag.getAttributes().put(LogicalPlan.CONTAINERS_MAX_COUNT, 1);
    RecoverableInputOperator rip = dag.addOperator("LongGenerator", RecoverableInputOperator.class);
    rip.setMaximumTuples(maxTuples);
    rip.setSimulateFailure(true);
    CollectorOperator cm = dag.addOperator("LongCollector", CollectorOperator.class);
    cm.setSimulateFailure(true);
    dag.addStream("connection", rip.output, cm.input);
    StramLocalCluster lc = new StramLocalCluster(dag);
    lc.run();
    Assert.assertEquals("Generated Outputs", maxTuples, CollectorOperator.collection.size());
}
Also used : CollectorOperator(com.datatorrent.stram.engine.ProcessingModeTests.CollectorOperator) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) AsyncFSStorageAgent(com.datatorrent.common.util.AsyncFSStorageAgent) File(java.io.File) StramLocalCluster(com.datatorrent.stram.StramLocalCluster) Test(org.junit.Test)

Example 14 with AsyncFSStorageAgent

use of com.datatorrent.common.util.AsyncFSStorageAgent in project apex-core by apache.

the class AtLeastOnceTest method testInputOperatorRecovery.

@Test
public void testInputOperatorRecovery() throws Exception {
    RecoverableInputOperator.initGenTuples();
    CollectorOperator.collection.clear();
    int maxTuples = 30;
    LogicalPlan dag = new LogicalPlan();
    String workingDir = new File("target/testInputOperatorRecovery").getAbsolutePath();
    AsyncFSStorageAgent asyncFSStorageAgent = new AsyncFSStorageAgent(workingDir, null);
    asyncFSStorageAgent.setSyncCheckpoint(true);
    dag.setAttribute(Context.OperatorContext.STORAGE_AGENT, asyncFSStorageAgent);
    dag.getAttributes().put(LogicalPlan.CHECKPOINT_WINDOW_COUNT, 2);
    dag.getAttributes().put(LogicalPlan.STREAMING_WINDOW_SIZE_MILLIS, 300);
    dag.getAttributes().put(LogicalPlan.CONTAINERS_MAX_COUNT, 1);
    RecoverableInputOperator rip = dag.addOperator("LongGenerator", RecoverableInputOperator.class);
    rip.setMaximumTuples(maxTuples);
    rip.setSimulateFailure(true);
    CollectorOperator cm = dag.addOperator("LongCollector", CollectorOperator.class);
    dag.addStream("connection", rip.output, cm.input);
    StramLocalCluster lc = new StramLocalCluster(dag);
    lc.run();
    Assert.assertEquals("Generated Outputs", maxTuples, CollectorOperator.collection.size());
}
Also used : CollectorOperator(com.datatorrent.stram.engine.ProcessingModeTests.CollectorOperator) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) AsyncFSStorageAgent(com.datatorrent.common.util.AsyncFSStorageAgent) File(java.io.File) StramLocalCluster(com.datatorrent.stram.StramLocalCluster) Test(org.junit.Test)

Example 15 with AsyncFSStorageAgent

use of com.datatorrent.common.util.AsyncFSStorageAgent in project apex-core by apache.

the class OiOEndWindowTest method validateOiOImplementation.

@Test
public void validateOiOImplementation() throws Exception {
    LogicalPlan lp = new LogicalPlan();
    String workingDir = new File("target/validateOiOImplementation").getAbsolutePath();
    lp.setAttribute(Context.OperatorContext.STORAGE_AGENT, new AsyncFSStorageAgent(workingDir, null));
    TestInputOperator io = lp.addOperator("Input Operator", new TestInputOperator());
    FirstGenericOperator go = lp.addOperator("First Generic Operator", new FirstGenericOperator());
    SecondGenericOperator out = lp.addOperator("Second Generic Operator", new SecondGenericOperator());
    /*
     * This tests make sure that even if the application_window_count is different the endWindow() is called for
     * end_stream
     */
    lp.getOperatorMeta("Second Generic Operator").getAttributes().put(Context.OperatorContext.APPLICATION_WINDOW_COUNT, 2);
    StreamMeta stream = lp.addStream("Stream", io.output, go.input);
    StreamMeta stream1 = lp.addStream("Stream1", go.output, out.input);
    stream1.setLocality(Locality.THREAD_LOCAL);
    lp.validate();
    StramLocalCluster slc = new StramLocalCluster(lp);
    slc.run();
    Assert.assertEquals("End Window Count", FirstGenericOperator.endwindowCount, SecondGenericOperator.endwindowCount);
}
Also used : StreamMeta(com.datatorrent.stram.plan.logical.LogicalPlan.StreamMeta) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) AsyncFSStorageAgent(com.datatorrent.common.util.AsyncFSStorageAgent) File(java.io.File) StramLocalCluster(com.datatorrent.stram.StramLocalCluster) Test(org.junit.Test)

Aggregations

AsyncFSStorageAgent (com.datatorrent.common.util.AsyncFSStorageAgent)19 Test (org.junit.Test)16 LogicalPlan (com.datatorrent.stram.plan.logical.LogicalPlan)14 File (java.io.File)13 StramLocalCluster (com.datatorrent.stram.StramLocalCluster)12 PTOperator (com.datatorrent.stram.plan.physical.PTOperator)6 StatsListener (com.datatorrent.api.StatsListener)3 Checkpoint (com.datatorrent.stram.api.Checkpoint)3 GenericTestOperator (com.datatorrent.stram.engine.GenericTestOperator)3 CollectorOperator (com.datatorrent.stram.engine.ProcessingModeTests.CollectorOperator)3 LocalStreamingContainer (com.datatorrent.stram.StramLocalCluster.LocalStreamingContainer)2 Node (com.datatorrent.stram.engine.Node)2 TestCollectorStatsListener (com.datatorrent.stram.engine.StatsTest.TestCollector.TestCollectorStatsListener)2 TestInputStatsListener (com.datatorrent.stram.engine.StatsTest.TestOperator.TestInputStatsListener)2 TestGeneratorInputOperator (com.datatorrent.stram.engine.TestGeneratorInputOperator)2 ArrayList (java.util.ArrayList)2 OperatorStats (com.datatorrent.api.Stats.OperatorStats)1 PortStats (com.datatorrent.api.Stats.OperatorStats.PortStats)1 StorageAgent (com.datatorrent.api.StorageAgent)1 BasicContainerOptConfigurator (com.datatorrent.common.util.BasicContainerOptConfigurator)1