use of com.datatorrent.stram.engine.GenericOperatorProperty in project apex-core by apache.
the class GenericOperatorPropertyCodecTest method testGenericOperatorPropertyCodec.
@Test
public void testGenericOperatorPropertyCodec() {
LogicalPlan dag = new LogicalPlan();
Map<Class<?>, Class<? extends StringCodec<?>>> codecs = new HashMap<>();
codecs.put(GenericOperatorProperty.class, GenericOperatorProperty.GenericOperatorPropertyStringCodec.class);
dag.setAttribute(com.datatorrent.api.Context.DAGContext.STRING_CODECS, codecs);
dag.setAttribute(com.datatorrent.api.Context.OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
OperatorMeta o1Meta = dag.getMeta(o1);
TestPlanContext ctx = new TestPlanContext();
PhysicalPlan plan = new PhysicalPlan(dag, ctx);
ctx.deploy.clear();
ctx.undeploy.clear();
PlanModifier pm = new PlanModifier(plan);
try {
pm.setOperatorProperty(o1Meta.getName(), "genericOperatorProperty", "xyz");
// cannot set properties on an operator that is already deployed.
Assert.fail("validation error expected");
} catch (javax.validation.ValidationException e) {
Assert.assertTrue(e.getMessage().contains(o1Meta.toString()));
}
GenericTestOperator newOperator = new GenericTestOperator();
pm.addOperator("newOperator", newOperator);
pm.setOperatorProperty("newOperator", "genericOperatorProperty", "xyz");
Assert.assertEquals("", "xyz", newOperator.getGenericOperatorProperty().obtainString());
}
Aggregations