use of com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent in project apex-core by apache.
the class OiOStreamTest method validateOiOiODiamondImplementation.
@Test
public void validateOiOiODiamondImplementation() throws Exception {
LogicalPlan lp = new LogicalPlan();
lp.setAttribute(com.datatorrent.api.Context.OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
ThreadIdValidatingInputOperator inputOperator = lp.addOperator("inputOperator", new ThreadIdValidatingInputOperator());
ThreadIdValidatingGenericIntermediateOperator intermediateOperator1 = lp.addOperator("intermediateOperator1", new ThreadIdValidatingGenericIntermediateOperator());
ThreadIdValidatingGenericIntermediateOperator intermediateOperator2 = lp.addOperator("intermediateOperator2", new ThreadIdValidatingGenericIntermediateOperator());
ThreadIdValidatingGenericOperatorWithTwoInputPorts outputOperator = lp.addOperator("outputOperator", new ThreadIdValidatingGenericOperatorWithTwoInputPorts());
StreamMeta stream1 = lp.addStream("OiOinput", inputOperator.output, intermediateOperator1.input, intermediateOperator2.input);
StreamMeta stream2 = lp.addStream("OiOintermediateToOutput1", intermediateOperator1.output, outputOperator.input);
StreamMeta stream3 = lp.addStream("OiOintermediateToOutput2", intermediateOperator2.output, outputOperator.input2);
StramLocalCluster slc;
/*
* The first test makes sure that when they are not ThreadLocal they use different threads
*/
ThreadIdValidatingGenericIntermediateOperator.threadList.clear();
ThreadIdValidatingOutputOperator.threadList.clear();
lp.validate();
slc = new StramLocalCluster(lp);
slc.run();
Assert.assertEquals("nonOIO: Number of threads", 2, ThreadIdValidatingGenericIntermediateOperator.threadList.size());
Assert.assertFalse("nonOIO: Thread Ids of input operator and intermediate operator1", ThreadIdValidatingInputOperator.threadId == ThreadIdValidatingGenericIntermediateOperator.threadList.get(0));
Assert.assertFalse("nonOIO: Thread Ids of input operator and intermediate operator2", ThreadIdValidatingInputOperator.threadId == ThreadIdValidatingGenericIntermediateOperator.threadList.get(1));
Assert.assertNotEquals("nonOIO: Thread Ids of two intermediate operators", ThreadIdValidatingGenericIntermediateOperator.threadList.get(0), ThreadIdValidatingGenericIntermediateOperator.threadList.get(1));
Assert.assertNotEquals("nonOIO: Thread Ids of input and output operators", ThreadIdValidatingInputOperator.threadId, ThreadIdValidatingGenericOperatorWithTwoInputPorts.threadId);
/*
* This test makes sure that since all operators in diamond are ThreadLocal, they indeed share a thread
*/
ThreadIdValidatingGenericIntermediateOperator.threadList.clear();
ThreadIdValidatingOutputOperator.threadList.clear();
stream1.setLocality(Locality.THREAD_LOCAL);
stream2.setLocality(Locality.THREAD_LOCAL);
stream3.setLocality(Locality.THREAD_LOCAL);
lp.validate();
slc = new StramLocalCluster(lp);
slc.run();
Assert.assertEquals("OIO: Number of threads", 2, ThreadIdValidatingGenericIntermediateOperator.threadList.size());
Assert.assertEquals("OIO: Thread Ids of input operator and intermediate operator1", ThreadIdValidatingInputOperator.threadId, (long) ThreadIdValidatingGenericIntermediateOperator.threadList.get(0));
Assert.assertEquals("OIO: Thread Ids of input operator and intermediate operator2", ThreadIdValidatingInputOperator.threadId, (long) ThreadIdValidatingGenericIntermediateOperator.threadList.get(1));
Assert.assertEquals("OIO: Thread Ids of two intermediate operators", ThreadIdValidatingGenericIntermediateOperator.threadList.get(0), ThreadIdValidatingGenericIntermediateOperator.threadList.get(1));
Assert.assertEquals("OIO: Thread Ids of input and output operators", ThreadIdValidatingInputOperator.threadId, ThreadIdValidatingGenericOperatorWithTwoInputPorts.threadId);
}
use of com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent in project apex-core by apache.
the class OutputUnifiedTest method setup.
@Before
public void setup() {
dag = StramTestSupport.createDAG(testMeta);
dag.setAttribute(OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
}
use of com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent in project apex-core by apache.
the class StreamingContainerManagerTest method testShutdownOperatorTimeout.
@Test
public void testShutdownOperatorTimeout() throws Exception {
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
dag.addStream("s1", o1.outport1, o2.inport1);
dag.setAttribute(OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
dag.setAttribute(Context.DAGContext.STREAMING_WINDOW_SIZE_MILLIS, 50);
dag.setAttribute(OperatorContext.TIMEOUT_WINDOW_COUNT, 1);
StreamingContainerManager scm = new StreamingContainerManager(dag);
PhysicalPlan plan = scm.getPhysicalPlan();
PTOperator p1 = plan.getOperators(dag.getMeta(o1)).get(0);
PTOperator p2 = plan.getOperators(dag.getMeta(o2)).get(0);
shutdownOperator(scm, p1, p2);
scm.monitorHeartbeat(false);
Assert.assertTrue(scm.containerStopRequests.isEmpty());
Thread.sleep(100);
scm.monitorHeartbeat(false);
Assert.assertFalse(scm.containerStopRequests.containsKey(p1.getContainer().getExternalId()));
Assert.assertTrue(scm.containerStopRequests.containsKey(p2.getContainer().getExternalId()));
}
use of com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent in project apex-core by apache.
the class StreamingContainerManagerTest method testGenerateDeployInfo.
@Test
public void testGenerateDeployInfo() {
TestGeneratorInputOperator o1 = dag.addOperator("o1", TestGeneratorInputOperator.class);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
GenericTestOperator o3 = dag.addOperator("o3", GenericTestOperator.class);
GenericTestOperator o4 = dag.addOperator("o4", GenericTestOperator.class);
dag.setOutputPortAttribute(o1.outport, PortContext.BUFFER_MEMORY_MB, 256);
dag.addStream("o1.outport", o1.outport, o2.inport1);
dag.setOutputPortAttribute(o1.outport, PortContext.SPIN_MILLIS, 99);
dag.addStream("o2.outport1", o2.outport1, o3.inport1).setLocality(Locality.CONTAINER_LOCAL);
dag.addStream("o3.outport1", o3.outport1, o4.inport1).setLocality(Locality.THREAD_LOCAL);
dag.getAttributes().put(LogicalPlan.CONTAINERS_MAX_COUNT, 2);
dag.setAttribute(OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
Assert.assertEquals("number operators", 4, dag.getAllOperators().size());
Assert.assertEquals("number root operators", 1, dag.getRootOperators().size());
StreamingContainerManager dnm = new StreamingContainerManager(dag);
Assert.assertEquals("number containers", 2, dnm.getPhysicalPlan().getContainers().size());
dnm.assignContainer(new ContainerResource(0, "container1Id", "host1", 1024, 0, null), InetSocketAddress.createUnresolved("host1", 9001));
dnm.assignContainer(new ContainerResource(0, "container2Id", "host2", 1024, 0, null), InetSocketAddress.createUnresolved("host2", 9002));
StreamingContainerAgent sca1 = dnm.getContainerAgent(dnm.getPhysicalPlan().getContainers().get(0).getExternalId());
StreamingContainerAgent sca2 = dnm.getContainerAgent(dnm.getPhysicalPlan().getContainers().get(1).getExternalId());
Assert.assertEquals("", dnm.getPhysicalPlan().getContainers().get(0), sca1.container);
Assert.assertEquals("", PTContainer.State.ALLOCATED, sca1.container.getState());
List<OperatorDeployInfo> c1 = sca1.getDeployInfoList(sca1.container.getOperators());
Assert.assertEquals("number operators assigned to c1", 1, c1.size());
OperatorDeployInfo o1DI = getNodeDeployInfo(c1, dag.getMeta(o1));
Assert.assertNotNull(o1 + " assigned to " + sca1.container.getExternalId(), o1DI);
Assert.assertEquals("type " + o1DI, OperatorDeployInfo.OperatorType.INPUT, o1DI.type);
Assert.assertEquals("inputs " + o1DI.name, 0, o1DI.inputs.size());
Assert.assertEquals("outputs " + o1DI.name, 1, o1DI.outputs.size());
Assert.assertNotNull("contextAttributes " + o1DI.name, o1DI.contextAttributes);
OutputDeployInfo c1o1outport = o1DI.outputs.get(0);
Assert.assertNotNull("stream connection for container1", c1o1outport);
Assert.assertEquals("stream connection for container1", "o1.outport", c1o1outport.declaredStreamId);
Assert.assertEquals("stream connects to upstream host", sca1.container.host, c1o1outport.bufferServerHost);
Assert.assertEquals("stream connects to upstream port", sca1.container.bufferServerAddress.getPort(), c1o1outport.bufferServerPort);
Assert.assertNotNull("contextAttributes " + c1o1outport, c1o1outport.contextAttributes);
Assert.assertEquals("contextAttributes " + c1o1outport, Integer.valueOf(99), c1o1outport.contextAttributes.get(PortContext.SPIN_MILLIS));
List<OperatorDeployInfo> c2 = sca2.getDeployInfoList(sca2.container.getOperators());
Assert.assertEquals("number operators assigned to container", 3, c2.size());
OperatorDeployInfo o2DI = getNodeDeployInfo(c2, dag.getMeta(o2));
OperatorDeployInfo o3DI = getNodeDeployInfo(c2, dag.getMeta(o3));
Assert.assertNotNull(dag.getMeta(o2) + " assigned to " + sca2.container.getExternalId(), o2DI);
Assert.assertNotNull(dag.getMeta(o3) + " assigned to " + sca2.container.getExternalId(), o3DI);
Assert.assertTrue("The buffer server memory for container 1", 256 == sca1.getInitContext().getValue(ContainerContext.BUFFER_SERVER_MB));
Assert.assertTrue("The buffer server memory for container 2", 0 == sca2.getInitContext().getValue(ContainerContext.BUFFER_SERVER_MB));
// buffer server input o2 from o1
InputDeployInfo c2o2i1 = getInputDeployInfo(o2DI, "o1.outport");
Assert.assertNotNull("stream connection for container2", c2o2i1);
Assert.assertEquals("stream connects to upstream host", sca1.container.host, c2o2i1.bufferServerHost);
Assert.assertEquals("stream connects to upstream port", sca1.container.bufferServerAddress.getPort(), c2o2i1.bufferServerPort);
Assert.assertEquals("portName " + c2o2i1, dag.getMeta(o2).getMeta(o2.inport1).getPortName(), c2o2i1.portName);
Assert.assertNull("partitionKeys " + c2o2i1, c2o2i1.partitionKeys);
Assert.assertEquals("sourceNodeId " + c2o2i1, o1DI.id, c2o2i1.sourceNodeId);
Assert.assertEquals("sourcePortName " + c2o2i1, TestGeneratorInputOperator.OUTPUT_PORT, c2o2i1.sourcePortName);
Assert.assertNotNull("contextAttributes " + c2o2i1, c2o2i1.contextAttributes);
// inline input o3 from o2
InputDeployInfo c2o3i1 = getInputDeployInfo(o3DI, "o2.outport1");
Assert.assertNotNull("input from o2.outport1", c2o3i1);
Assert.assertEquals("portName " + c2o3i1, GenericTestOperator.IPORT1, c2o3i1.portName);
Assert.assertNotNull("stream connection for container2", c2o3i1);
Assert.assertNull("bufferServerHost " + c2o3i1, c2o3i1.bufferServerHost);
Assert.assertEquals("bufferServerPort " + c2o3i1, 0, c2o3i1.bufferServerPort);
Assert.assertNull("partitionKeys " + c2o3i1, c2o3i1.partitionKeys);
Assert.assertEquals("sourceNodeId " + c2o3i1, o2DI.id, c2o3i1.sourceNodeId);
Assert.assertEquals("sourcePortName " + c2o3i1, GenericTestOperator.OPORT1, c2o3i1.sourcePortName);
Assert.assertEquals("locality " + c2o3i1, Locality.CONTAINER_LOCAL, c2o3i1.locality);
// THREAD_LOCAL o4.inport1
OperatorDeployInfo o4DI = getNodeDeployInfo(c2, dag.getMeta(o4));
Assert.assertNotNull(dag.getMeta(o4) + " assigned to " + sca2.container.getExternalId(), o4DI);
InputDeployInfo c2o4i1 = getInputDeployInfo(o4DI, "o3.outport1");
Assert.assertNotNull("input from o3.outport1", c2o4i1);
Assert.assertEquals("portName " + c2o4i1, GenericTestOperator.IPORT1, c2o4i1.portName);
Assert.assertNotNull("stream connection for container2", c2o4i1);
Assert.assertNull("bufferServerHost " + c2o4i1, c2o4i1.bufferServerHost);
Assert.assertEquals("bufferServerPort " + c2o4i1, 0, c2o4i1.bufferServerPort);
Assert.assertNull("partitionKeys " + c2o4i1, c2o4i1.partitionKeys);
Assert.assertEquals("sourceNodeId " + c2o4i1, o3DI.id, c2o4i1.sourceNodeId);
Assert.assertEquals("sourcePortName " + c2o4i1, GenericTestOperator.OPORT1, c2o4i1.sourcePortName);
Assert.assertEquals("locality " + c2o4i1, Locality.THREAD_LOCAL, c2o4i1.locality);
}
use of com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent in project apex-core by apache.
the class StreamingContainerManagerTest method testRecoveryUpstreamInline.
@Test
public void testRecoveryUpstreamInline() throws Exception {
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
GenericTestOperator o3 = dag.addOperator("o3", GenericTestOperator.class);
dag.addStream("o1o3", o1.outport1, o3.inport1);
dag.addStream("o2o3", o2.outport1, o3.inport2);
dag.getAttributes().put(LogicalPlan.CONTAINERS_MAX_COUNT, 2);
dag.setAttribute(OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
StreamingContainerManager scm = new StreamingContainerManager(dag);
PhysicalPlan plan = scm.getPhysicalPlan();
Assert.assertEquals(2, plan.getContainers().size());
plan.getOperators(dag.getMeta(o1)).get(0);
Assert.assertEquals(2, plan.getContainers().size());
PTContainer c1 = plan.getContainers().get(0);
Assert.assertEquals(Sets.newHashSet(plan.getOperators(dag.getMeta(o1)).get(0), plan.getOperators(dag.getMeta(o3)).get(0)), Sets.newHashSet(c1.getOperators()));
PTContainer c2 = plan.getContainers().get(1);
assignContainer(scm, "c1");
assignContainer(scm, "c2");
for (PTOperator oper : c1.getOperators()) {
Assert.assertEquals("state " + oper, PTOperator.State.PENDING_DEPLOY, oper.getState());
}
scm.scheduleContainerRestart(c2.getExternalId());
for (PTOperator oper : c1.getOperators()) {
Assert.assertEquals("state " + oper, PTOperator.State.PENDING_UNDEPLOY, oper.getState());
}
}
Aggregations