use of com.datatorrent.api.DAG.StreamMeta in project apex-core by apache.
the class StreamPersistanceTests method testaddStreamThrowsExceptionOnInvalidLoggerType.
@Test
public void testaddStreamThrowsExceptionOnInvalidLoggerType() {
// Test Logger with non-optional output ports
TestGeneratorInputOperator input1 = dag.addOperator("input1", TestGeneratorInputOperator.class);
GenericTestOperator x = dag.addOperator("x", new GenericTestOperator());
StreamMeta stream = dag.addStream("Stream1", input1.outport, x.inport1);
TestOperatorWithOutputPorts persister = new TestOperatorWithOutputPorts();
try {
stream.persistUsing("persister", persister, persister.inputPort);
Assert.fail("should throw Illegal argument exception: Persist operator has non optional output ports");
} catch (IllegalArgumentException e) {
logger.debug(e.getMessage());
}
// Test already added operator passed
TestOperatorWithOutputPorts persister1 = new TestOperatorWithOutputPorts();
try {
stream.persistUsing("Stream1_persister", persister1, persister1.inputPort);
Assert.fail("should throw exception that Stream1_persister object was already added");
} catch (IllegalArgumentException e) {
logger.debug(e.getMessage());
}
// Test persist operator without any input ports
dag.removeOperator(dag.getOperatorMeta("Stream1_persister").getOperator());
TestOperatorWithoutInputPorts logger2 = new TestOperatorWithoutInputPorts();
try {
stream.persistUsing("Stream1_persister", logger2);
Assert.fail("should throw Illegal argument exception: persist operator should have input ports");
} catch (IllegalArgumentException e) {
logger.debug(e.getMessage());
}
// Test persist operator with more than one input port as non-optional
dag.removeOperator(dag.getOperatorMeta("Stream1_persister").getOperator());
TestOperatorWithMultipleNonOptionalInputPorts persister3 = new TestOperatorWithMultipleNonOptionalInputPorts();
try {
stream.persistUsing("Stream1_persister", persister3);
Assert.fail("should throw Illegal argument exception: persist operator should have at most 1 non-optional input port");
} catch (IllegalArgumentException e) {
logger.debug(e.getMessage());
}
}
use of com.datatorrent.api.DAG.StreamMeta in project apex-core by apache.
the class StreamPersistanceTests method testPersistStreamOnSingleSinkWithFiltering.
@Test
public void testPersistStreamOnSingleSinkWithFiltering() throws ClassNotFoundException, IOException, InterruptedException {
AscendingNumbersOperator ascend = dag.addOperator("ascend", new AscendingNumbersOperator());
PassThruOperatorWithCodec passThru = dag.addOperator("PassThrough", new PassThruOperatorWithCodec(2));
final TestReceiverOperator console = dag.addOperator("console", new TestReceiverOperator());
TestPersistanceOperator persister = new TestPersistanceOperator();
StreamMeta s = dag.addStream("Stream1", ascend.outputPort, passThru.input);
s.persistUsing("Stream1_persister", persister, persister.inport, passThru.input);
dag.addStream("Stream2", passThru.output, console.inport);
runLocalClusterAndValidate(dag, console, persister);
}
use of com.datatorrent.api.DAG.StreamMeta in project apex-core by apache.
the class StreamPersistanceTests method testPersistStreamOperatorIsAdded.
@Test
public void testPersistStreamOperatorIsAdded() {
TestGeneratorInputOperator input1 = dag.addOperator("input1", TestGeneratorInputOperator.class);
GenericTestOperator x = dag.addOperator("x", new GenericTestOperator());
TestReceiverOperator persister = new TestReceiverOperator();
StreamMeta stream = dag.addStream("Stream1", input1.outport, x.inport1);
stream.persistUsing("Stream1_persister", persister, persister.inport);
// Check operator is added to dag
OperatorMeta persistOperatorMeta = dag.getOperatorMeta("Stream1_persister");
assertEquals("Persist operator not added to dag ", persister, persistOperatorMeta.getOperator());
dag.validate();
}
use of com.datatorrent.api.DAG.StreamMeta in project apex-core by apache.
the class StreamPersistanceTests method testDynamicPartitioning.
@Test
public void testDynamicPartitioning() throws ClassNotFoundException, IOException {
AscendingNumbersOperator ascend = dag.addOperator("ascend", new AscendingNumbersOperator());
final TestReceiverOperator console = dag.addOperator("console", new TestReceiverOperator());
dag.setOperatorAttribute(console, Context.OperatorContext.PARTITIONER, new StatelessPartitioner<TestReceiverOperator>(2));
dag.setOperatorAttribute(console, Context.OperatorContext.STATS_LISTENERS, Lists.newArrayList((StatsListener) new PartitioningTest.PartitionLoadWatch()));
final PartitionedTestPersistanceOperator console1 = new PartitionedTestPersistanceOperator();
StreamMeta s = dag.addStream("Stream1", ascend.outputPort, console.inport);
dag.setInputPortAttribute(console.inport, PortContext.STREAM_CODEC, new TestPartitionCodec());
s.persistUsing("persister", console1, console1.inport);
dag.setAttribute(LogicalPlan.CONTAINERS_MAX_COUNT, Integer.MAX_VALUE);
StramTestSupport.MemoryStorageAgent msa = new StramTestSupport.MemoryStorageAgent();
dag.setAttribute(Context.OperatorContext.STORAGE_AGENT, msa);
StreamingContainerManager dnm = new StreamingContainerManager(dag);
PhysicalPlan plan = dnm.getPhysicalPlan();
List<PTContainer> containers = plan.getContainers();
Assert.assertEquals("number containers", 4, containers.size());
for (int i = 0; i < containers.size(); ++i) {
StreamingContainerManagerTest.assignContainer(dnm, "container" + (i + 1));
}
LogicalPlan.OperatorMeta passThruMeta = dag.getMeta(console);
List<PTOperator> ptos = plan.getOperators(passThruMeta);
PTOperator persistOperatorContainer = null;
for (PTContainer container : plan.getContainers()) {
for (PTOperator operator : container.getOperators()) {
operator.setState(PTOperator.State.ACTIVE);
if (operator.getName().equals("persister")) {
persistOperatorContainer = operator;
}
}
}
// Check that persist operator is part of dependents redeployed
Set<PTOperator> operators = plan.getDependents(ptos);
logger.debug("Operators to be re-deployed = {}", operators);
// Validate that persist operator is part of dependents
assertTrue("persist operator should be part of the operators to be redeployed", operators.contains(persistOperatorContainer));
LogicalPlan.StreamMeta s1 = (LogicalPlan.StreamMeta) s;
StreamCodec codec = s1.getPersistOperatorInputPort().getStreamCodec();
assertEquals("Codec should be instance of StreamCodecWrapper", codec instanceof StreamCodecWrapperForPersistance, true);
StreamCodecWrapperForPersistance wrapperCodec = (StreamCodecWrapperForPersistance) codec;
Entry<InputPortMeta, Collection<PartitionKeys>> keys = (Entry<InputPortMeta, Collection<PartitionKeys>>) wrapperCodec.inputPortToPartitionMap.entrySet().iterator().next();
logger.debug(keys.toString());
assertEquals("Size of partitions should be 2", 2, keys.getValue().size());
for (PTOperator ptOperator : ptos) {
PartitioningTest.PartitionLoadWatch.put(ptOperator, -1);
plan.onStatusUpdate(ptOperator);
}
dnm.processEvents();
assertEquals("Input port map", wrapperCodec.inputPortToPartitionMap.size(), 1);
keys = (Entry<InputPortMeta, Collection<PartitionKeys>>) wrapperCodec.inputPortToPartitionMap.entrySet().iterator().next();
assertEquals("Size of partitions should be 1 after repartition", 1, keys.getValue().size());
logger.debug(keys.toString());
}
use of com.datatorrent.api.DAG.StreamMeta in project apex-core by apache.
the class StreamPersistanceTests method testPersistStreamOperatorMultiplePhysicalOperatorsForSink.
@Test
public void testPersistStreamOperatorMultiplePhysicalOperatorsForSink() throws ClassNotFoundException, IOException {
AscendingNumbersOperator ascend = dag.addOperator("ascend", new AscendingNumbersOperator());
PartitionedTestOperatorWithFiltering passThru = dag.addOperator("partition", new PartitionedTestOperatorWithFiltering());
final TestReceiverOperator console = dag.addOperator("console", new TestReceiverOperator());
final TestPersistanceOperator console1 = new TestPersistanceOperator();
StreamMeta s = dag.addStream("Stream1", ascend.outputPort, passThru.input);
dag.setInputPortAttribute(passThru.input, PortContext.STREAM_CODEC, new TestPartitionCodec());
s.persistUsing("persister", console1, console1.inport);
dag.addStream("Stream2", passThru.output, console.inport);
final StramLocalCluster lc = new StramLocalCluster(dag);
new Thread("LocalClusterController") {
@Override
public void run() {
long startTms = System.currentTimeMillis();
long timeout = 100000L;
try {
while (System.currentTimeMillis() - startTms < timeout) {
if ((console.results.size() < 6) || (console1.results.size() < 6)) {
Thread.sleep(10);
} else {
break;
}
}
} catch (Exception ex) {
throw Throwables.propagate(ex);
} finally {
lc.shutdown();
}
}
}.start();
lc.run();
try {
Integer[] expectedResult = { 0, 1, 4, 5, 8, 9, 12, 13, 16 };
for (int i = 0; i < expectedResult.length; i++) {
logger.debug(console1.results.get(i) + " " + expectedResult[i]);
assertEquals("Mismatch observed for tuple ", expectedResult[i], console1.results.get(i));
}
} finally {
console1.results.clear();
console.results.clear();
}
}
Aggregations