use of org.apache.apex.malhar.lib.appdata.schemas.ResultFormatter in project apex-malhar by apache.
the class QueryManagerAsynchronousTest method stressTest.
@Test
public void stressTest() throws Exception {
final int totalTuples = 100000;
final int batchSize = 100;
final double waitMillisProb = .01;
AppDataWindowEndQueueManager<MockQuery, Void> queueManager = new AppDataWindowEndQueueManager<MockQuery, Void>();
DefaultOutputPort<String> outputPort = new DefaultOutputPort<String>();
CollectorTestSink<MockResult> sink = new CollectorTestSink<MockResult>();
TestUtils.setSink(outputPort, sink);
MessageSerializerFactory msf = new MessageSerializerFactory(new ResultFormatter());
QueryManagerAsynchronous<MockQuery, Void, MutableLong, MockResult> queryManagerAsynch = new QueryManagerAsynchronous<>(outputPort, queueManager, new NOPQueryExecutor(waitMillisProb), msf, Thread.currentThread());
Thread producerThread = new Thread(new ProducerThread(queueManager, totalTuples, batchSize, waitMillisProb));
producerThread.start();
producerThread.setName("Producer Thread");
long startTime = System.currentTimeMillis();
queryManagerAsynch.setup(null);
int numWindows = 0;
for (; sink.collectedTuples.size() < totalTuples && ((System.currentTimeMillis() - startTime) < 60000); numWindows++) {
queryManagerAsynch.beginWindow(numWindows);
Thread.sleep(100);
queryManagerAsynch.endWindow();
}
producerThread.stop();
queryManagerAsynch.teardown();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// Do Nothing
}
Assert.assertEquals(totalTuples, sink.collectedTuples.size());
}
Aggregations