use of org.apache.apex.malhar.contrib.helper.SourceModule in project apex-malhar by apache.
the class RabbitMQOutputOperatorTest method runTest.
protected void runTest(int testNum) throws IOException {
RabbitMQMessageReceiver receiver = new RabbitMQMessageReceiver();
receiver.setup();
LocalMode lma = LocalMode.newInstance();
DAG dag = lma.getDAG();
SourceModule source = dag.addOperator("source", new SourceModule());
source.setTestNum(testNum);
RabbitMQOutputOperator collector = dag.addOperator("generator", new RabbitMQOutputOperator());
collector.setWindowDataManager(new FSWindowDataManager());
collector.setExchange("testEx");
dag.addStream("Stream", source.outPort, collector.inputPort).setLocality(Locality.CONTAINER_LOCAL);
final LocalMode.Controller lc = lma.getController();
lc.setHeartbeatMonitoringEnabled(false);
lc.runAsync();
try {
Thread.sleep(1000);
long timeout = 10000L;
long startTms = System.currentTimeMillis();
while ((receiver.count < testNum * 3) && (System.currentTimeMillis() - startTms < timeout)) {
Thread.sleep(100);
}
} catch (InterruptedException ex) {
Assert.fail(ex.getMessage());
} finally {
lc.shutdown();
}
Assert.assertEquals("emitted value for testNum was ", testNum * 3, receiver.count);
for (Map.Entry<String, Integer> e : receiver.dataMap.entrySet()) {
if (e.getKey().equals("a")) {
Assert.assertEquals("emitted value for 'a' was ", new Integer(2), e.getValue());
} else if (e.getKey().equals("b")) {
Assert.assertEquals("emitted value for 'b' was ", new Integer(20), e.getValue());
} else if (e.getKey().equals("c")) {
Assert.assertEquals("emitted value for 'c' was ", new Integer(1000), e.getValue());
}
}
}
use of org.apache.apex.malhar.contrib.helper.SourceModule in project apex-malhar by apache.
the class ZeroMQOutputOperatorTest method runTest.
protected void runTest(final int testNum) {
LocalMode lma = LocalMode.newInstance();
DAG dag = lma.getDAG();
SourceModule source = dag.addOperator("source", new SourceModule());
source.setTestNum(testNum);
final ZeroMQOutputOperator collector = dag.addOperator("generator", new ZeroMQOutputOperator());
collector.setUrl("tcp://*:5556");
collector.setSyncUrl("tcp://*:5557");
collector.setSUBSCRIBERS_EXPECTED(1);
dag.addStream("Stream", source.outPort, collector.inputPort).setLocality(Locality.CONTAINER_LOCAL);
final LocalMode.Controller lc = lma.getController();
lc.setHeartbeatMonitoringEnabled(false);
final ZeroMQMessageReceiver receiver = new ZeroMQMessageReceiver();
receiver.setup();
final Thread t = new Thread(receiver);
t.start();
new Thread("LocalClusterController") {
@Override
public void run() {
try {
Thread.sleep(1000);
long timeout = 10000L;
long startTms = System.currentTimeMillis();
while (System.currentTimeMillis() - startTms < timeout) {
if (receiver.count < testNum * 3) {
Thread.sleep(10);
} else {
break;
}
}
} catch (InterruptedException ex) {
DTThrowable.rethrow(ex);
} finally {
logger.debug("done...");
lc.shutdown();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
DTThrowable.rethrow(e);
} finally {
t.interrupt();
receiver.teardown();
}
}
}
}.start();
lc.run();
Assert.assertEquals("emitted value for testNum was ", testNum * 3, receiver.count);
for (Map.Entry<String, Integer> e : receiver.dataMap.entrySet()) {
if (e.getKey().equals("a")) {
Assert.assertEquals("emitted value for 'a' was ", new Integer(2), e.getValue());
} else if (e.getKey().equals("b")) {
Assert.assertEquals("emitted value for 'b' was ", new Integer(20), e.getValue());
} else if (e.getKey().equals("c")) {
Assert.assertEquals("emitted value for 'c' was ", new Integer(1000), e.getValue());
}
}
}
Aggregations