use of com.datatorrent.common.util.BaseOperator in project apex-core by apache.
the class LogicalPlanConfigurationTest method testModuleUnifierLevelAttributes.
@Test
@SuppressWarnings({ "UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes" })
public void testModuleUnifierLevelAttributes() {
class DummyOperator extends BaseOperator {
int prop;
public transient DefaultInputPort<Integer> input = new DefaultInputPort<Integer>() {
@Override
public void process(Integer tuple) {
LOG.debug(tuple.intValue() + " processed");
output.emit(tuple);
}
};
public transient DefaultOutputPort<Integer> output = new DefaultOutputPort<>();
}
class DummyOutputOperator extends BaseOperator {
int prop;
public transient DefaultInputPort<Integer> input = new DefaultInputPort<Integer>() {
@Override
public void process(Integer tuple) {
LOG.debug(tuple.intValue() + " processed");
}
};
}
class TestUnifierAttributeModule implements Module {
public transient ProxyInputPort<Integer> moduleInput = new ProxyInputPort<>();
public transient ProxyOutputPort<Integer> moduleOutput = new Module.ProxyOutputPort<>();
@Override
public void populateDAG(DAG dag, Configuration conf) {
DummyOperator dummyOperator = dag.addOperator("DummyOperator", new DummyOperator());
dag.setOperatorAttribute(dummyOperator, Context.OperatorContext.PARTITIONER, new StatelessPartitioner<DummyOperator>(3));
dag.setUnifierAttribute(dummyOperator.output, OperatorContext.TIMEOUT_WINDOW_COUNT, 2);
moduleInput.set(dummyOperator.input);
moduleOutput.set(dummyOperator.output);
}
}
StreamingApplication app = new StreamingApplication() {
@Override
public void populateDAG(DAG dag, Configuration conf) {
Module m1 = dag.addModule("TestModule", new TestUnifierAttributeModule());
DummyOutputOperator dummyOutputOperator = dag.addOperator("DummyOutputOperator", new DummyOutputOperator());
dag.addStream("Module To Operator", ((TestUnifierAttributeModule) m1).moduleOutput, dummyOutputOperator.input);
}
};
String appName = "UnifierApp";
LogicalPlanConfiguration dagBuilder = new LogicalPlanConfiguration(new Configuration(false));
LogicalPlan dag = new LogicalPlan();
dag.setAttribute(Context.OperatorContext.STORAGE_AGENT, new MockStorageAgent());
dagBuilder.prepareDAG(dag, app, appName);
LogicalPlan.OperatorMeta ometa = dag.getOperatorMeta("TestModule$DummyOperator");
LogicalPlan.OperatorMeta om = null;
for (Map.Entry<LogicalPlan.OutputPortMeta, LogicalPlan.StreamMeta> entry : ometa.getOutputStreams().entrySet()) {
if (entry.getKey().getPortName().equals("output")) {
om = entry.getKey().getUnifierMeta();
}
}
/*
* Verify the attribute value after preparing DAG.
*/
Assert.assertNotNull(om);
Assert.assertEquals("", Integer.valueOf(2), om.getValue(Context.OperatorContext.TIMEOUT_WINDOW_COUNT));
PhysicalPlan plan = new PhysicalPlan(dag, new TestPlanContext());
List<PTContainer> containers = plan.getContainers();
LogicalPlan.OperatorMeta operatorMeta = null;
for (PTContainer container : containers) {
List<PTOperator> operators = container.getOperators();
for (PTOperator operator : operators) {
if (operator.isUnifier()) {
operatorMeta = operator.getOperatorMeta();
}
}
}
/*
* Verify attribute after physical plan creation with partitioned operators.
*/
Assert.assertEquals("", Integer.valueOf(2), operatorMeta.getValue(OperatorContext.TIMEOUT_WINDOW_COUNT));
}
Aggregations