use of com.datatorrent.stram.engine.GenericTestOperator in project apex-core by apache.
the class LogicalPlanConfigurationTest method testLoadFromJson.
@Test
public void testLoadFromJson() throws Exception {
String resourcePath = "/testTopology.json";
InputStream is = this.getClass().getResourceAsStream(resourcePath);
if (is == null) {
fail("Could not load " + resourcePath);
}
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer);
JSONObject json = new JSONObject(writer.toString());
Configuration conf = new Configuration(false);
conf.set(StreamingApplication.APEX_PREFIX + "operator.operator3.prop.myStringProperty", "o3StringFromConf");
LogicalPlanConfiguration planConf = new LogicalPlanConfiguration(conf);
LogicalPlan dag = planConf.createFromJson(json, "testLoadFromJson");
dag.validate();
assertEquals("DAG attribute CONTAINER_JVM_OPTIONS ", dag.getAttributes().get(DAGContext.CONTAINER_JVM_OPTIONS), "-Xmx16m");
Map<Class<?>, Class<? extends StringCodec<?>>> stringCodecsMap = Maps.newHashMap();
stringCodecsMap.put(Integer.class, Integer2String.class);
assertEquals("DAG attribute STRING_CODECS ", stringCodecsMap, dag.getAttributes().get(DAGContext.STRING_CODECS));
assertEquals("DAG attribute CONTAINER_OPTS_CONFIGURATOR ", BasicContainerOptConfigurator.class, dag.getAttributes().get(DAGContext.CONTAINER_OPTS_CONFIGURATOR).getClass());
assertEquals("number of operator confs", 5, dag.getAllOperators().size());
assertEquals("number of root operators", 1, dag.getRootOperators().size());
StreamMeta s1 = dag.getStream("n1n2");
assertNotNull(s1);
assertTrue("n1n2 inline", DAG.Locality.CONTAINER_LOCAL == s1.getLocality());
OperatorMeta input = dag.getOperatorMeta("inputOperator");
TestStatsListener tsl = new TestStatsListener();
tsl.setIntProp(222);
List<StatsListener> sll = Lists.<StatsListener>newArrayList(tsl);
assertEquals("inputOperator STATS_LISTENERS attribute ", sll, input.getAttributes().get(OperatorContext.STATS_LISTENERS));
for (OutputPortMeta opm : input.getOutputStreams().keySet()) {
assertTrue("output port of input Operator attribute is JsonStreamCodec ", opm.getAttributes().get(PortContext.STREAM_CODEC) instanceof JsonStreamCodec<?>);
}
OperatorMeta operator3 = dag.getOperatorMeta("operator3");
assertEquals("operator3.classname", GenericTestOperator.class, operator3.getOperator().getClass());
GenericTestOperator doperator3 = (GenericTestOperator) operator3.getOperator();
assertEquals("myStringProperty " + doperator3, "o3StringFromConf", doperator3.getMyStringProperty());
assertFalse("booleanProperty " + doperator3, doperator3.booleanProperty);
OperatorMeta operator4 = dag.getOperatorMeta("operator4");
GenericTestOperator doperator4 = (GenericTestOperator) operator4.getOperator();
assertEquals("myStringProperty " + doperator4, "overrideOperator4", doperator4.getMyStringProperty());
assertEquals("setterOnlyOperator4 " + doperator4, "setterOnlyOperator4", doperator4.propertySetterOnly);
assertTrue("booleanProperty " + doperator4, doperator4.booleanProperty);
StreamMeta input1 = dag.getStream("inputStream");
assertNotNull(input1);
OperatorMeta inputOperator = dag.getOperatorMeta("inputOperator");
Assert.assertEquals("input1 source", inputOperator, input1.getSource().getOperatorMeta());
Set<OperatorMeta> targetNodes = Sets.newHashSet();
for (LogicalPlan.InputPortMeta targetPort : input1.getSinks()) {
targetNodes.add(targetPort.getOperatorMeta());
}
Assert.assertEquals("operator attribute " + inputOperator, 64, (int) inputOperator.getValue(OperatorContext.MEMORY_MB));
Assert.assertEquals("port attribute " + inputOperator, 8, (int) input1.getSource().getValue(PortContext.UNIFIER_LIMIT));
Assert.assertEquals("input1 target ", Sets.newHashSet(dag.getOperatorMeta("operator1"), operator3, operator4), targetNodes);
}
use of com.datatorrent.stram.engine.GenericTestOperator in project apex-core by apache.
the class LogicalPlanConfigurationTest method testLoadFromConfigXml.
/**
* Test read from configuration file in Hadoop configuration format.
*/
@Test
public void testLoadFromConfigXml() {
Configuration conf = new Configuration(false);
conf.addResource(StramClientUtils.DT_SITE_XML_FILE);
LogicalPlanConfiguration builder = new LogicalPlanConfiguration(conf);
LogicalPlan dag = new LogicalPlan();
builder.populateDAG(dag);
dag.validate();
assertEquals("number of operator confs", 6, dag.getAllOperators().size());
OperatorMeta operator1 = assertNode(dag, "operator1");
OperatorMeta operator2 = assertNode(dag, "operator2");
OperatorMeta operator3 = assertNode(dag, "operator3");
OperatorMeta operator4 = assertNode(dag, "operator4");
assertNotNull("operatorConf for root", operator1);
assertEquals("operatorId set", "operator1", operator1.getName());
// verify operator instantiation
assertEquals(operator1.getOperator().getClass(), TestGeneratorInputOperator.class);
TestGeneratorInputOperator GenericTestNode = (TestGeneratorInputOperator) operator1.getOperator();
assertEquals("myStringPropertyValue", GenericTestNode.getMyStringProperty());
// check links
assertEquals("operator1 inputs", 0, operator1.getInputStreams().size());
assertEquals("operator1 outputs", 1, operator1.getOutputStreams().size());
StreamMeta n1n2 = operator2.getInputStreams().get(operator2.getMeta(((GenericTestOperator) operator2.getOperator()).inport1));
assertNotNull("n1n2", n1n2);
// output/input stream object same
assertEquals("rootNode out is operator2 in", n1n2, operator1.getOutputStreams().get(operator1.getMeta(((TestGeneratorInputOperator) operator1.getOperator()).outport)));
assertEquals("n1n2 source", operator1, n1n2.getSource().getOperatorMeta());
Assert.assertEquals("n1n2 targets", 1, n1n2.getSinks().size());
Assert.assertEquals("n1n2 target", operator2, n1n2.getSinks().iterator().next().getOperatorMeta());
assertEquals("stream name", "n1n2", n1n2.getName());
Assert.assertEquals("n1n2 not inline (default)", null, n1n2.getLocality());
// operator 2 streams to operator 3 and operator 4
assertEquals("operator 2 number of outputs", 1, operator2.getOutputStreams().size());
StreamMeta fromNode2 = operator2.getOutputStreams().values().iterator().next();
Set<OperatorMeta> targetNodes = Sets.newHashSet();
for (LogicalPlan.InputPortMeta ip : fromNode2.getSinks()) {
targetNodes.add(ip.getOperatorMeta());
}
Assert.assertEquals("outputs " + fromNode2, Sets.newHashSet(operator3, operator4), targetNodes);
OperatorMeta operator6 = assertNode(dag, "operator6");
List<OperatorMeta> rootNodes = dag.getRootOperators();
assertEquals("number root operators", 2, rootNodes.size());
assertTrue("root operator2", rootNodes.contains(operator1));
assertTrue("root operator6", rootNodes.contains(operator6));
for (OperatorMeta n : rootNodes) {
printTopology(n, dag, 0);
}
}
use of com.datatorrent.stram.engine.GenericTestOperator in project apex-core by apache.
the class StreamingContainerManagerTest method testLatency.
@Test
public void testLatency() throws Exception {
TestGeneratorInputOperator o1 = dag.addOperator("o1", TestGeneratorInputOperator.class);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
HighLatencyTestOperator o3 = dag.addOperator("o3", HighLatencyTestOperator.class);
GenericTestOperator o4 = dag.addOperator("o4", GenericTestOperator.class);
// 5 seconds
long latency = 5000;
o3.setLatency(latency);
dag.addStream("o1.outport", o1.outport, o2.inport1, o3.inport1);
dag.addStream("o2.outport1", o2.outport1, o4.inport1);
dag.addStream("o3.outport1", o3.outport1, o4.inport2);
// 1 second
dag.setAttribute(Context.DAGContext.STATS_MAX_ALLOWABLE_WINDOWS_LAG, 2);
StramLocalCluster lc = new StramLocalCluster(dag);
StreamingContainerManager dnmgr = lc.dnmgr;
lc.runAsync();
Thread.sleep(10000);
LogicalOperatorInfo o1Info = dnmgr.getLogicalOperatorInfo("o1");
LogicalOperatorInfo o2Info = dnmgr.getLogicalOperatorInfo("o2");
LogicalOperatorInfo o3Info = dnmgr.getLogicalOperatorInfo("o3");
LogicalOperatorInfo o4Info = dnmgr.getLogicalOperatorInfo("o4");
Assert.assertEquals("Input operator latency must be zero", 0, o1Info.latencyMA);
Assert.assertTrue("Latency must be greater than or equal to zero", o2Info.latencyMA >= 0);
Assert.assertTrue("Actual latency must be greater than the artificially introduced latency", o3Info.latencyMA > latency);
Assert.assertTrue("Latency must be greater than or equal to zero", o4Info.latencyMA >= 0);
StreamingContainerManager.CriticalPathInfo criticalPathInfo = dnmgr.getCriticalPathInfo();
Assert.assertArrayEquals("Critical Path must be the path in the DAG that includes the HighLatencyTestOperator", new Integer[] { o1Info.partitions.iterator().next(), o3Info.partitions.iterator().next(), o4Info.partitions.iterator().next() }, criticalPathInfo.path.toArray());
Assert.assertTrue("Whole DAG latency must be greater than the artificially introduced latency", criticalPathInfo.latency > latency);
lc.shutdown();
}
use of com.datatorrent.stram.engine.GenericTestOperator in project apex-core by apache.
the class LogicalPlanConfigurationTest method testApplicationLevelParameter.
@Test
public void testApplicationLevelParameter() {
String appName = "app1";
final GenericTestOperator operator1 = new GenericTestOperator();
final GenericTestOperator operator2 = new GenericTestOperator();
StreamingApplication app = new StreamingApplication() {
@Override
public void populateDAG(DAG dag, Configuration conf) {
dag.addOperator("operator1", operator1);
dag.addOperator("operator2", operator2);
}
};
Properties props = new Properties();
props.put(StreamingApplication.APEX_PREFIX + "application." + appName + ".class", app.getClass().getName());
props.put(StreamingApplication.APEX_PREFIX + "operator.*.myStringProperty", "foo ${xyz} bar ${zzz} baz");
props.put(StreamingApplication.APEX_PREFIX + "operator.*.booleanProperty", Boolean.TRUE.toString());
props.put(StreamingApplication.APEX_PREFIX + "application." + appName + ".operator.operator1.myStringProperty", "apv1");
LogicalPlanConfiguration dagBuilder = new LogicalPlanConfiguration(new Configuration(false));
Configuration vars = new Configuration(false);
vars.set("xyz", "123");
vars.set("zzz", "456");
dagBuilder.addFromProperties(props, vars);
String appPath = app.getClass().getName().replace(".", "/") + ".class";
LogicalPlan dag = new LogicalPlan();
dagBuilder.prepareDAG(dag, app, appPath);
Assert.assertEquals("apv1", operator1.getMyStringProperty());
Assert.assertEquals("foo 123 bar 456 baz", operator2.getMyStringProperty());
Assert.assertEquals(true, operator2.isBooleanProperty());
}
use of com.datatorrent.stram.engine.GenericTestOperator in project apex-core by apache.
the class LogicalPlanConfigurationTest method testSetOperatorProperties.
@Test
public void testSetOperatorProperties() {
Configuration conf = new Configuration(false);
conf.set(StreamingApplication.APEX_PREFIX + "operator.o1.prop.myStringProperty", "myStringPropertyValue");
conf.set(StreamingApplication.APEX_PREFIX + "operator.o2.prop.stringArrayField", "a,b,c");
conf.set(StreamingApplication.APEX_PREFIX + "operator.o2.prop.mapProperty.key1", "key1Val");
conf.set(StreamingApplication.APEX_PREFIX + "operator.o2.prop.mapProperty(key1.dot)", "key1dotVal");
conf.set(StreamingApplication.APEX_PREFIX + "operator.o2.prop.mapProperty(key2.dot)", "key2dotVal");
LogicalPlan dag = new LogicalPlan();
GenericTestOperator o1 = dag.addOperator("o1", new GenericTestOperator());
ValidationTestOperator o2 = dag.addOperator("o2", new ValidationTestOperator());
LogicalPlanConfiguration pb = new LogicalPlanConfiguration(conf);
pb.setOperatorProperties(dag, "testSetOperatorProperties");
Assert.assertEquals("o1.myStringProperty", "myStringPropertyValue", o1.getMyStringProperty());
Assert.assertArrayEquals("o2.stringArrayField", new String[] { "a", "b", "c" }, o2.getStringArrayField());
Assert.assertEquals("o2.mapProperty.key1", "key1Val", o2.getMapProperty().get("key1"));
Assert.assertEquals("o2.mapProperty(key1.dot)", "key1dotVal", o2.getMapProperty().get("key1.dot"));
Assert.assertEquals("o2.mapProperty(key2.dot)", "key2dotVal", o2.getMapProperty().get("key2.dot"));
}
Aggregations