Source:
<code>public void test() throws Exception { LocalMode lma = LocalMode.newInstance(); StreamingApplication app = new StreamingApplication() { @Override public void populateDAG(DAG dag, Configuration conf) { } }; DAG dag = lma.getDAG(); 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); TupleCacheOutputOperator output = dag.addOperator(OPERATOR.OUTPUT.name(), TupleCacheOutputOperator.class); 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); final LocalMode.Controller lc = lma.getController(); lc.runAsync(); while(true) { try { Thread.sleep(1000); } catch( Exception e ){} logger.info("Tuple row key: ", output.getReceivedTuples()); logger.info( "Received tuple number {}, instance is {}.", output.getReceivedTuples() == null ? 0 : output.getReceivedTuples().size(), System.identityHashCode( output ) ); <START> if( output.getReceivedTuples() != null && output.getReceivedTuples().size() == TUPLE_NUM ) <END> break; } lc.shutdown(); validate( generator.getTuples(), output.getReceivedTuples() ); }</code><technical_language>If this condition is met, unit test case run forever. Need some timeout based failure of test case</technical_language>

Target:
public void test() throws Exception { LocalMode lma = LocalMode.newInstance(); StreamingApplication app = new StreamingApplication() { @Override public void populateDAG(DAG dag, Configuration conf) { } }; DAG dag = lma.getDAG(); 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); TupleCacheOutputOperator output = dag.addOperator(OPERATOR.OUTPUT.name(), TupleCacheOutputOperator.class); 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); final LocalMode.Controller lc = lma.getController(); lc.runAsync(); long start = System.currentTimeMillis(); while(true) { try { Thread.sleep(1000); } catch( Exception e ){} 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() ); }