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());
}
Aggregations