use of com.datatorrent.stram.engine.GenericTestOperator in project apex-core by apache.
the class DAGSetupPluginTests method validateProperties.
protected void validateProperties(LogicalPlan dag) {
String[] operators = new String[] { "operator1", "operator2", "operator3", "operator4" };
for (String name : operators) {
GenericTestOperator op = (GenericTestOperator) dag.getOperatorMeta(name).getOperator();
Assert.assertEquals("property set on operator ", op.getMyStringProperty(), "mynewstringvalue");
}
}
use of com.datatorrent.stram.engine.GenericTestOperator in project apex-core by apache.
the class LogicalPlanTest method testAttributeValuesSerializableCheck.
@Test
public void testAttributeValuesSerializableCheck() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
Attribute<Object> attr = new Attribute<>(new TestAttributeValue(), new Object2String());
Field nameField = Attribute.class.getDeclaredField("name");
nameField.setAccessible(true);
nameField.set(attr, "Test_Attribute");
nameField.setAccessible(false);
assertNotNull(attr);
// Dag attribute not serializable test
dag.setAttribute(attr, new TestAttributeValue());
try {
dag.validate();
Assert.fail("Setting not serializable attribute should throw exception");
} catch (ValidationException e) {
assertEquals("Validation Exception should match ", "Attribute value(s) for Test_Attribute in com.datatorrent.api.DAG are not serializable", e.getMessage());
}
// Operator attribute not serializable test
dag = new LogicalPlan();
TestGeneratorInputOperator operator = dag.addOperator("TestOperator", TestGeneratorInputOperator.class);
dag.setOperatorAttribute(operator, attr, new TestAttributeValue());
try {
dag.validate();
Assert.fail("Setting not serializable attribute should throw exception");
} catch (ValidationException e) {
assertEquals("Validation Exception should match ", "Attribute value(s) for Test_Attribute in TestOperator are not serializable", e.getMessage());
}
// Output Port attribute not serializable test
dag = new LogicalPlan();
operator = dag.addOperator("TestOperator", TestGeneratorInputOperator.class);
dag.setOutputPortAttribute(operator.outport, attr, new TestAttributeValue());
try {
dag.validate();
Assert.fail("Setting not serializable attribute should throw exception");
} catch (ValidationException e) {
assertEquals("Validation Exception should match ", "Attribute value(s) for Test_Attribute in TestOperator.outport are not serializable", e.getMessage());
}
// Input Port attribute not serializable test
dag = new LogicalPlan();
GenericTestOperator operator1 = dag.addOperator("TestOperator", GenericTestOperator.class);
dag.setInputPortAttribute(operator1.inport1, attr, new TestAttributeValue());
try {
dag.validate();
Assert.fail("Setting non serializable attribute should throw exception");
} catch (ValidationException e) {
assertEquals("Validation Exception should match ", "Attribute value(s) for Test_Attribute in TestOperator.inport1 are not serializable", e.getMessage());
}
}
use of com.datatorrent.stram.engine.GenericTestOperator in project apex-core by apache.
the class LogicalPlanTest method testNullStreamId.
@Test(expected = IllegalArgumentException.class)
public void testNullStreamId() {
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
dag.addStream(null, o1.outport1, o1.inport1, o1.inport2);
}
use of com.datatorrent.stram.engine.GenericTestOperator in project apex-core by apache.
the class LogicalPlanTest method testLocalityValidation.
@Test
public void testLocalityValidation() {
TestGeneratorInputOperator input1 = dag.addOperator("input1", TestGeneratorInputOperator.class);
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
StreamMeta s1 = dag.addStream("input1.outport", input1.outport, o1.inport1).setLocality(Locality.THREAD_LOCAL);
dag.validate();
TestGeneratorInputOperator input2 = dag.addOperator("input2", TestGeneratorInputOperator.class);
dag.addStream("input2.outport", input2.outport, o1.inport2);
try {
dag.validate();
Assert.fail("Exception expected for " + o1);
} catch (ValidationException ve) {
Assert.assertThat("", ve.getMessage(), RegexMatcher.matches("Locality THREAD_LOCAL invalid for operator .* with multiple input streams .*"));
}
s1.setLocality(null);
dag.validate();
}
use of com.datatorrent.stram.engine.GenericTestOperator in project apex-core by apache.
the class LogicalPlanModificationTest method testAddOperatorWithAffinityRules.
@Test
public void testAddOperatorWithAffinityRules() {
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
GenericTestOperator o3 = dag.addOperator("o3", GenericTestOperator.class);
dag.addStream("o1.outport1", o1.outport1, o2.inport1);
dag.addStream("o2.outport1", o2.outport1, o3.inport1);
TestPlanContext ctx = new TestPlanContext();
dag.setAttribute(OperatorContext.STORAGE_AGENT, ctx);
PhysicalPlan plan = new PhysicalPlan(dag, ctx);
ctx.deploy.clear();
ctx.undeploy.clear();
Assert.assertEquals("containers", 3, plan.getContainers().size());
AffinityRulesSet ruleSet = new AffinityRulesSet();
List<AffinityRule> rules = new ArrayList<>();
ruleSet.setAffinityRules(rules);
rules.add(new AffinityRule(Type.AFFINITY, Locality.CONTAINER_LOCAL, false, "o1", "added1"));
rules.add(new AffinityRule(Type.ANTI_AFFINITY, Locality.NODE_LOCAL, false, "o3", "added1"));
dag.setAttribute(DAGContext.AFFINITY_RULES_SET, ruleSet);
PlanModifier pm = new PlanModifier(plan);
GenericTestOperator added1 = new GenericTestOperator();
pm.addOperator("added1", added1);
pm.addStream("added1.outport1", added1.outport1, o3.inport2);
Assert.assertEquals("undeploy " + ctx.undeploy, 0, ctx.undeploy.size());
Assert.assertEquals("deploy " + ctx.deploy, 0, ctx.deploy.size());
pm.applyChanges(ctx);
Assert.assertEquals("containers post change", 4, plan.getContainers().size());
Assert.assertEquals("undeploy " + ctx.undeploy, 1, ctx.undeploy.size());
Assert.assertEquals("deploy " + ctx.deploy, 2, ctx.deploy.size());
// Validate affinity rules are applied
for (PTContainer c : plan.getContainers()) {
if (c.getOperators().contains("added1")) {
Assert.assertEquals("Operators O1 and added1 should be in the same container as per affinity rule", 2, c.getOperators().size());
Assert.assertEquals("Operators O1 and added1 should be in the same container as per affinity rule", "o1", c.getOperators().get(0).getOperatorMeta().getName());
Assert.assertEquals("Operators O1 and added1 should be in the same container as per affinity rule", "added1", c.getOperators().get(1).getOperatorMeta().getName());
Set<PTContainer> antiAffinityList = c.getStrictAntiPrefs();
Assert.assertEquals("There should be one container in antiaffinity list", 1, antiAffinityList.size());
List<PTOperator> antiAffinityOperators = antiAffinityList.iterator().next().getOperators();
Assert.assertEquals("AntiAffinity operators should containn operator O3", antiAffinityOperators.iterator().next().getOperatorMeta().getName(), "o3");
}
}
}
Aggregations