Search in sources :

Example 11 with StreamingApplication

use of com.datatorrent.api.StreamingApplication in project apex-malhar by apache.

the class TestNiFiInputApplication method main.

public static void main(String[] args) throws Exception {
    StreamingApplication app = new TestNiFiInputApplication();
    LocalMode.runApp(app, new Configuration(false), 10000);
    Thread.sleep(2000);
    System.exit(0);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) StreamingApplication(com.datatorrent.api.StreamingApplication)

Example 12 with StreamingApplication

use of com.datatorrent.api.StreamingApplication in project apex-malhar by apache.

the class SpillableBenchmarkAppTester method test.

@Test
public void test() throws Exception {
    Configuration conf = new Configuration(false);
    LocalMode lma = LocalMode.newInstance();
    DAG dag = lma.getDAG();
    super.populateDAG(dag, conf);
    StreamingApplication app = new StreamingApplication() {

        @Override
        public void populateDAG(DAG dag, Configuration conf) {
        }
    };
    lma.prepareDAG(app, conf);
    // Create local cluster
    final LocalMode.Controller lc = lma.getController();
    lc.run(600000);
    lc.shutdown();
    if (SpillableTestOperator.errorTrace != null) {
        logger.error("Error.", SpillableTestOperator.errorTrace);
        Assert.assertNull(SpillableTestOperator.errorTrace.getMessage(), SpillableTestOperator.errorTrace);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) LocalMode(com.datatorrent.api.LocalMode) DAG(com.datatorrent.api.DAG) StreamingApplication(com.datatorrent.api.StreamingApplication) Test(org.junit.Test)

Example 13 with StreamingApplication

use of com.datatorrent.api.StreamingApplication in project apex-malhar by apache.

the class ManagedStateBenchmarkAppTest method test.

public void test(ExecMode exeMode) throws Exception {
    Configuration conf = new Configuration(false);
    LocalMode lma = LocalMode.newInstance();
    DAG dag = lma.getDAG();
    super.populateDAG(dag, conf);
    storeOperator.setExecMode(exeMode);
    StreamingApplication app = new StreamingApplication() {

        @Override
        public void populateDAG(DAG dag, Configuration conf) {
        }
    };
    lma.prepareDAG(app, conf);
    // Create local cluster
    final LocalMode.Controller lc = lma.getController();
    lc.run(3000000);
    lc.shutdown();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) LocalMode(com.datatorrent.api.LocalMode) DAG(com.datatorrent.api.DAG) StreamingApplication(com.datatorrent.api.StreamingApplication)

Example 14 with StreamingApplication

use of com.datatorrent.api.StreamingApplication in project apex-malhar by apache.

the class KinesisOutputOperatorTest method testKinesisOutputOperator.

/**
 * Test AbstractKinesisOutputOperator (i.e. an output adapter for Kinesis, aka producer).
 * This module sends data into an ActiveMQ message bus.
 *
 * [Generate tuple] ==> [send tuple through Kinesis output adapter(i.e. producer) into Kinesis message bus]
 * ==> [receive data in outside Kinesis listener (i.e consumer)]
 *
 * @throws Exception
 */
@Test
@SuppressWarnings({ "unchecked" })
public void testKinesisOutputOperator() throws Exception {
    // Setup a message listener to receive the message
    KinesisTestConsumer listener = null;
    if (enableConsumer) {
        listener = createConsumerListener(streamName);
        if (listener != null) {
            // initialize the latch to synchronize the threads
            doneLatch = new CountDownLatch(maxTuple);
            listener.setDoneLatch(doneLatch);
            listenerThread = new Thread(listener);
            listenerThread.start();
        }
    }
    // 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
    G generator = addGenerateOperator(dag);
    O node = addTestingOperator(dag);
    configureTestingOperator(node);
    // Connect ports
    dag.addStream("Kinesis message", getOutputPortOfGenerator(generator), node.inputPort).setLocality(Locality.CONTAINER_LOCAL);
    Configuration conf = new Configuration(false);
    lma.prepareDAG(app, conf);
    // Create local cluster
    final LocalMode.Controller lc = lma.getController();
    lc.runAsync();
    int waitTime = 300000;
    if (doneLatch != null) {
        doneLatch.await(waitTime, TimeUnit.MILLISECONDS);
    } else {
        try {
            Thread.sleep(waitTime);
        } catch (Exception e) {
        // 
        }
    }
    if (listener != null) {
        listener.setIsAlive(false);
    }
    if (listenerThread != null) {
        listenerThread.join(1000);
    }
    lc.shutdown();
    // Check values send vs received
    if (listener != null) {
        Assert.assertEquals("Number of emitted tuples", maxTuple, listener.holdingBuffer.size());
        logger.debug(String.format("Number of emitted tuples: %d", listener.holdingBuffer.size()));
    }
    if (listener != null) {
        listener.close();
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) LocalMode(com.datatorrent.api.LocalMode) DAG(com.datatorrent.api.DAG) StreamingApplication(com.datatorrent.api.StreamingApplication) DAG(com.datatorrent.api.DAG) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 15 with StreamingApplication

use of com.datatorrent.api.StreamingApplication in project apex-malhar by apache.

the class KafkaOutputOperatorTest method testKafkaOutputOperator.

// End of StringGeneratorInputOperator
/**
 * Test AbstractKafkaOutputOperator (i.e. an output adapter for Kafka, aka producer).
 * This module sends data into an ActiveMQ message bus.
 *
 * [Generate tuple] ==> [send tuple through Kafka output adapter(i.e. producer) into Kafka message bus]
 * ==> [receive data in outside Kaka listener (i.e consumer)]
 *
 * @throws Exception
 */
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testKafkaOutputOperator() throws Exception {
    // initialize the latch to synchronize the threads
    latch = new CountDownLatch(maxTuple);
    // Setup a message listener to receive the message
    KafkaTestConsumer listener = new KafkaTestConsumer("topic1");
    listener.setLatch(latch);
    new Thread(listener).start();
    // 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
    StringGeneratorInputOperator generator = dag.addOperator("TestStringGenerator", StringGeneratorInputOperator.class);
    KafkaSinglePortOutputOperator node = dag.addOperator("KafkaMessageProducer", KafkaSinglePortOutputOperator.class);
    Properties props = new Properties();
    props.setProperty("serializer.class", "kafka.serializer.StringEncoder");
    props.put("metadata.broker.list", "invalidhost:9092");
    props.setProperty("producer.type", "async");
    props.setProperty("queue.buffering.max.ms", "200");
    props.setProperty("queue.buffering.max.messages", "10");
    props.setProperty("batch.num.messages", "5");
    node.setConfigProperties(props);
    node.setTopic("topic1");
    // Connect ports
    dag.addStream("Kafka message", generator.outputPort, node.inputPort).setLocality(Locality.CONTAINER_LOCAL);
    // MLHR-1143: verify we can set broker list (and other properties) through configuration
    Configuration conf = new Configuration(false);
    conf.set("dt.operator.KafkaMessageProducer.prop.configProperties(metadata.broker.list)", "localhost:9092");
    lma.prepareDAG(app, conf);
    // Create local cluster
    final LocalMode.Controller lc = lma.getController();
    lc.runAsync();
    // Immediately return unless latch timeout in 5 seconds
    latch.await(15, TimeUnit.SECONDS);
    lc.shutdown();
    // Check values send vs received
    Assert.assertEquals("Number of emitted tuples", tupleCount, listener.holdingBuffer.size());
    logger.debug(String.format("Number of emitted tuples: %d", listener.holdingBuffer.size()));
    Assert.assertEquals("First tuple", "testString 1", listener.getMessage(listener.holdingBuffer.peek()));
    listener.close();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) LocalMode(com.datatorrent.api.LocalMode) StreamingApplication(com.datatorrent.api.StreamingApplication) DAG(com.datatorrent.api.DAG) CountDownLatch(java.util.concurrent.CountDownLatch) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

StreamingApplication (com.datatorrent.api.StreamingApplication)29 Configuration (org.apache.hadoop.conf.Configuration)28 Test (org.junit.Test)23 DAG (com.datatorrent.api.DAG)21 LocalMode (com.datatorrent.api.LocalMode)11 Properties (java.util.Properties)10 Integer2String (com.datatorrent.api.StringCodec.Integer2String)8 AttributeMap (com.datatorrent.api.Attribute.AttributeMap)3 GenericTestOperator (com.datatorrent.stram.engine.GenericTestOperator)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Attribute (com.datatorrent.api.Attribute)2 OperatorMeta (com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta)2 OutputPortMeta (com.datatorrent.stram.plan.logical.LogicalPlan.OutputPortMeta)2 StreamMeta (com.datatorrent.stram.plan.logical.LogicalPlan.StreamMeta)2 LogicalPlanConfiguration (com.datatorrent.stram.plan.logical.LogicalPlanConfiguration)2 File (java.io.File)2 Map (java.util.Map)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 AppHandle (org.apache.apex.api.Launcher.AppHandle)2 StreamingAppFactory (org.apache.apex.engine.util.StreamingAppFactory)2