com.datatorrent.ApplicationTest.java Source code

Java tutorial

Introduction

Here is the source code for com.datatorrent.ApplicationTest.java

Source

/**
 * Put your copyright and license info here.
 */
package com.datatorrent;

import java.io.IOException;

import javax.validation.ConstraintViolationException;

import org.junit.Assert;

import org.apache.hadoop.conf.Configuration;
import org.junit.Test;

import com.datatorrent.api.LocalMode;
import com.datatorrent.app.Application1;
import com.datatorrent.app.Application2;

/**
 * Test the DAG declaration in local mode.
 */
public class ApplicationTest {

    @Test
    public void testApplication1() throws IOException, Exception {
        try {
            LocalMode lma = LocalMode.newInstance();
            Configuration conf = new Configuration(false);
            conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
            lma.prepareDAG(new Application1(), conf);
            LocalMode.Controller lc = lma.getController();
            lc.run(10000); // runs for 10 seconds and quits
        } catch (ConstraintViolationException e) {
            Assert.fail("constraint violations: " + e.getConstraintViolations());
        }
    }

    @Test
    public void testApplication2() throws IOException, Exception {
        try {
            LocalMode lma = LocalMode.newInstance();
            Configuration conf = new Configuration(false);
            conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
            lma.prepareDAG(new Application2(), conf);
            LocalMode.Controller lc = lma.getController();
            lc.run(10000); // runs for 10 seconds and quits
        } catch (ConstraintViolationException e) {
            Assert.fail("constraint violations: " + e.getConstraintViolations());
        }
    }
}