Search in sources :

Example 1 with TupleCacheOutputOperator

use of org.apache.apex.malhar.contrib.util.TupleCacheOutputOperator in project apex-malhar by apache.

the class HBasePOJOInputOperatorTest method test.

@Test
public void test() throws Exception {
    // Create DAG for testing.
    LocalMode lma = LocalMode.newInstance();
    StreamingApplication app = new StreamingApplication() {

        @Override
        public void populateDAG(DAG dag, Configuration conf) {
        }
    };
    DAG dag = lma.getDAG();
    // Create ActiveMQStringSinglePortOutputOperator
    MyGenerator generator = dag.addOperator(OPERATOR.GENERATOR.name(), MyGenerator.class);
    generator.setTupleNum(TUPLE_NUM);
    hbaseOutputOperator = dag.addOperator(OPERATOR.HBASEOUTPUT.name(), hbaseOutputOperator);
    hbaseInputOperator = dag.addOperator(OPERATOR.HBASEINPUT.name(), hbaseInputOperator);
    dag.setOutputPortAttribute(hbaseInputOperator.outputPort, Context.PortContext.TUPLE_CLASS, TestPOJO.class);
    TupleCacheOutputOperator output = dag.addOperator(OPERATOR.OUTPUT.name(), TupleCacheOutputOperator.class);
    // Connect ports
    dag.addStream("queue1", generator.outputPort, hbaseOutputOperator.input).setLocality(DAG.Locality.NODE_LOCAL);
    dag.addStream("queue2", hbaseInputOperator.outputPort, output.inputPort).setLocality(DAG.Locality.NODE_LOCAL);
    Configuration conf = new Configuration(false);
    lma.prepareDAG(app, conf);
    // Create local cluster
    final LocalMode.Controller lc = lma.getController();
    lc.runAsync();
    long start = System.currentTimeMillis();
    // generator.doneLatch.await();
    while (true) {
        Thread.sleep(1000);
        logger.info("Tuple row key: ", output.getReceivedTuples());
        logger.info("Received tuple number {}, instance is {}.", output.getReceivedTuples() == null ? 0 : output.getReceivedTuples().size(), System.identityHashCode(output));
        if (output.getReceivedTuples() != null && output.getReceivedTuples().size() == TUPLE_NUM) {
            break;
        }
        if (System.currentTimeMillis() - start > RUN_DURATION) {
            throw new RuntimeException("Testcase taking too long");
        }
    }
    lc.shutdown();
    validate(generator.getTuples(), output.getReceivedTuples());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) TupleCacheOutputOperator(org.apache.apex.malhar.contrib.util.TupleCacheOutputOperator) LocalMode(com.datatorrent.api.LocalMode) StreamingApplication(com.datatorrent.api.StreamingApplication) DAG(com.datatorrent.api.DAG) Test(org.junit.Test)

Aggregations

DAG (com.datatorrent.api.DAG)1 LocalMode (com.datatorrent.api.LocalMode)1 StreamingApplication (com.datatorrent.api.StreamingApplication)1 TupleCacheOutputOperator (org.apache.apex.malhar.contrib.util.TupleCacheOutputOperator)1 Configuration (org.apache.hadoop.conf.Configuration)1 Test (org.junit.Test)1