use of com.datatorrent.stram.engine.TestGeneratorInputOperator 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.TestGeneratorInputOperator in project apex-core by apache.
the class LogicalPlanTest method testInvalidInputPortConnection.
@Test
public void testInvalidInputPortConnection() {
TestGeneratorInputOperator input1 = dag.addOperator("input1", TestGeneratorInputOperator.class);
Operator1 operator1 = dag.addOperator("operator3", new Operator3());
dag.addStream("Stream1", input1.outport, operator1.input);
try {
dag.validate();
} catch (ValidationException ex) {
Assert.assertTrue("validation message", ex.getMessage().startsWith("Invalid port connected"));
return;
}
Assert.fail();
}
use of com.datatorrent.stram.engine.TestGeneratorInputOperator 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.TestGeneratorInputOperator in project apex-core by apache.
the class LogicalPlanTest method testAtMostOnceProcessingModeValidation.
@Test
public void testAtMostOnceProcessingModeValidation() {
TestGeneratorInputOperator input1 = dag.addOperator("input1", TestGeneratorInputOperator.class);
TestGeneratorInputOperator input2 = dag.addOperator("input2", TestGeneratorInputOperator.class);
GenericTestOperator amoOper = dag.addOperator("amoOper", GenericTestOperator.class);
dag.setOperatorAttribute(amoOper, OperatorContext.PROCESSING_MODE, Operator.ProcessingMode.AT_MOST_ONCE);
dag.addStream("input1.outport", input1.outport, amoOper.inport1);
dag.addStream("input2.outport", input2.outport, amoOper.inport2);
GenericTestOperator outputOper = dag.addOperator("outputOper", GenericTestOperator.class);
dag.setOperatorAttribute(outputOper, OperatorContext.PROCESSING_MODE, Operator.ProcessingMode.AT_LEAST_ONCE);
dag.addStream("aloOper.outport1", amoOper.outport1, outputOper.inport1);
try {
dag.validate();
Assert.fail("Exception expected for " + outputOper);
} catch (ValidationException ve) {
Assert.assertEquals("", ve.getMessage(), "Processing mode outputOper/AT_LEAST_ONCE not valid for source amoOper/AT_MOST_ONCE");
}
dag.setOperatorAttribute(outputOper, OperatorContext.PROCESSING_MODE, null);
dag.validate();
OperatorMeta outputOperOm = dag.getMeta(outputOper);
Assert.assertEquals("" + outputOperOm.getAttributes(), Operator.ProcessingMode.AT_MOST_ONCE, outputOperOm.getValue(OperatorContext.PROCESSING_MODE));
}
use of com.datatorrent.stram.engine.TestGeneratorInputOperator in project apex-core by apache.
the class LogicalPlanTest method testCheckpointableWithinAppWindowAnnotation.
/*
@Test
public void testStreamCodec() throws Exception {
TestGeneratorInputOperator input = dag.addOperator("input", TestGeneratorInputOperator.class);
GenericTestOperator gto1 = dag.addOperator("gto1", GenericTestOperator.class);
StreamMeta stream1 = dag.addStream("s1", input.outport, gto1.inport1);
StreamCodec<?> codec1 = new TestStreamCodec();
dag.setInputPortAttribute(gto1.inport1, PortContext.STREAM_CODEC, codec1);
dag.validate();
//Assert.assertEquals("Stream codec not set", stream1.getStreamCodec(), codec1);
GenericTestOperator gto2 = dag.addOperator("gto2", GenericTestOperator.class);
GenericTestOperator gto3 = dag.addOperator("gto3", GenericTestOperator.class);
StreamMeta stream2 = dag.addStream("s2", gto1.outport1, gto2.inport1, gto3.inport1);
dag.setInputPortAttribute(gto2.inport1, PortContext.STREAM_CODEC, codec1);
try {
dag.validate();
} catch (ValidationException e) {
String msg = e.getMessage();
if (!msg.startsWith("Stream codec not set on input port") || !msg.contains("gto3")
|| !msg.contains(codec1.toString()) || !msg.endsWith("was specified on another port")) {
Assert.fail(String.format("LogicalPlan validation error msg: %s", msg));
}
}
dag.setInputPortAttribute(gto3.inport1, PortContext.STREAM_CODEC, codec1);
dag.validate();
//Assert.assertEquals("Stream codec not set", stream2.getStreamCodec(), codec1);
StreamCodec<?> codec2 = new TestStreamCodec();
dag.setInputPortAttribute(gto3.inport1, PortContext.STREAM_CODEC, codec2);
try {
dag.validate();
} catch (ValidationException e) {
String msg = e.getMessage();
if (!msg.startsWith("Conflicting stream codec set on input port") || !msg.contains("gto3")
|| !msg.contains(codec2.toString()) || !msg.endsWith("was specified on another port")) {
Assert.fail(String.format("LogicalPlan validation error msg: %s", msg));
}
}
dag.setInputPortAttribute(gto3.inport1, PortContext.STREAM_CODEC, codec1);
TestPortCodecOperator pco = dag.addOperator("pco", TestPortCodecOperator.class);
StreamMeta stream3 = dag.addStream("s3", gto2.outport1, pco.inport1);
dag.validate();
//Assert.assertEquals("Stream codec class not set", stream3.getCodecClass(), TestStreamCodec.class);
dag.setInputPortAttribute(pco.inport1, PortContext.STREAM_CODEC, codec2);
dag.validate();
//Assert.assertEquals("Stream codec not set", stream3.getStreamCodec(), codec2);
}
*/
@Test
public void testCheckpointableWithinAppWindowAnnotation() {
TestGeneratorInputOperator input1 = dag.addOperator("input1", TestGeneratorInputOperator.class);
GenericTestOperator x = dag.addOperator("x", new GenericTestOperator());
dag.addStream("Stream1", input1.outport, x.inport1);
dag.setOperatorAttribute(x, OperatorContext.CHECKPOINT_WINDOW_COUNT, 15);
dag.setOperatorAttribute(x, OperatorContext.APPLICATION_WINDOW_COUNT, 30);
dag.validate();
TestGeneratorInputOperator input2 = dag.addOperator("input2", TestGeneratorInputOperator.class);
CheckpointableWithinAppWindowOperator y = dag.addOperator("y", new CheckpointableWithinAppWindowOperator());
dag.addStream("Stream2", input2.outport, y.inport1);
dag.setOperatorAttribute(y, OperatorContext.CHECKPOINT_WINDOW_COUNT, 15);
dag.setOperatorAttribute(y, OperatorContext.APPLICATION_WINDOW_COUNT, 30);
dag.validate();
TestGeneratorInputOperator input3 = dag.addOperator("input3", TestGeneratorInputOperator.class);
NotCheckpointableWithinAppWindowOperator z = dag.addOperator("z", new NotCheckpointableWithinAppWindowOperator());
dag.addStream("Stream3", input3.outport, z.inport1);
dag.setOperatorAttribute(z, OperatorContext.CHECKPOINT_WINDOW_COUNT, 15);
dag.setOperatorAttribute(z, OperatorContext.APPLICATION_WINDOW_COUNT, 30);
try {
dag.validate();
Assert.fail("should fail because chekpoint window count is not a factor of application window count");
} catch (ValidationException e) {
// expected
}
dag.setOperatorAttribute(z, OperatorContext.CHECKPOINT_WINDOW_COUNT, 30);
dag.validate();
dag.setOperatorAttribute(z, OperatorContext.CHECKPOINT_WINDOW_COUNT, 45);
try {
dag.validate();
Assert.fail("should fail because chekpoint window count is not a factor of application window count");
} catch (ValidationException e) {
// expected
}
}
Aggregations