Search in sources :

Example 1 with ResultFormatter

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());
}
Also used : ResultFormatter(org.apache.apex.malhar.lib.appdata.schemas.ResultFormatter) MessageSerializerFactory(org.apache.apex.malhar.lib.appdata.query.serde.MessageSerializerFactory) MutableLong(org.apache.commons.lang3.mutable.MutableLong) DefaultOutputPort(com.datatorrent.api.DefaultOutputPort) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) Test(org.junit.Test)

Aggregations

DefaultOutputPort (com.datatorrent.api.DefaultOutputPort)1 MessageSerializerFactory (org.apache.apex.malhar.lib.appdata.query.serde.MessageSerializerFactory)1 ResultFormatter (org.apache.apex.malhar.lib.appdata.schemas.ResultFormatter)1 CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)1 MutableLong (org.apache.commons.lang3.mutable.MutableLong)1 Test (org.junit.Test)1