use of com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent in project apex-core by apache.
the class HostLocalTest method testPartitionLocality.
@Test
public void testPartitionLocality() {
int partitionCount = 3;
LogicalPlan dag = new LogicalPlan();
dag.getAttributes().put(com.datatorrent.api.Context.DAGContext.APPLICATION_PATH, new File("target", HostLocalTest.class.getName()).getAbsolutePath());
dag.setAttribute(OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
GenericTestOperator partitioned = dag.addOperator("partitioned", GenericTestOperator.class);
LocalityPartitioner partitioner = new LocalityPartitioner();
partitioner.setPartitionCount(partitionCount);
dag.getMeta(partitioned).getAttributes().put(OperatorContext.PARTITIONER, partitioner);
dag.addStream("o1_outport1", o1.outport1, partitioned.inport1);
StreamingContainerManager scm = new StreamingContainerManager(dag);
ResourceRequestHandler rr = new ResourceRequestHandler();
int containerMem = 1000;
Map<String, NodeReport> nodeReports = Maps.newHashMap();
for (int i = 0; i < partitionCount; i++) {
NodeReport nr = BuilderUtils.newNodeReport(BuilderUtils.newNodeId("host" + (i + 1), 0), NodeState.RUNNING, "httpAddress", "rackName", BuilderUtils.newResource(0, 0), BuilderUtils.newResource(containerMem * 2, 2), 0, null, 0);
nodeReports.put(nr.getNodeId().getHost(), nr);
}
// set resources
rr.updateNodeReports(Lists.newArrayList(nodeReports.values()));
Set<String> expectedHosts = Sets.newHashSet();
for (int i = 0; i < partitionCount; i++) {
expectedHosts.add("host" + (i + 1));
}
for (ContainerStartRequest csr : scm.containerStartRequests) {
String host = rr.getHost(csr, true);
if (host != null) {
expectedHosts.remove(host);
}
}
Assert.assertTrue("All the allocated hosts removed", expectedHosts.isEmpty());
}
use of com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent in project apex-core by apache.
the class HostLocalTest method testThreadLocal.
@Test
public void testThreadLocal() {
LogicalPlan dag = new LogicalPlan();
dag.getAttributes().put(com.datatorrent.api.Context.DAGContext.APPLICATION_PATH, new File("target", HostLocalTest.class.getName()).getAbsolutePath());
dag.setAttribute(OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
dag.getMeta(o1).getAttributes().put(OperatorContext.LOCALITY_HOST, "host2");
GenericTestOperator partitioned = dag.addOperator("partitioned", GenericTestOperator.class);
dag.addStream("o1_outport1", o1.outport1, partitioned.inport1).setLocality(Locality.THREAD_LOCAL);
dag.setOperatorAttribute(o1, OperatorContext.MEMORY_MB, 256);
dag.setOperatorAttribute(partitioned, OperatorContext.MEMORY_MB, 256);
StreamingContainerManager scm = new StreamingContainerManager(dag);
ResourceRequestHandler rr = new ResourceRequestHandler();
int containerMem = 1000;
Map<String, NodeReport> nodeReports = Maps.newHashMap();
NodeReport nr = BuilderUtils.newNodeReport(BuilderUtils.newNodeId("host1", 0), NodeState.RUNNING, "httpAddress", "rackName", BuilderUtils.newResource(0, 0), BuilderUtils.newResource(containerMem * 2, 2), 0, null, 0);
nodeReports.put(nr.getNodeId().getHost(), nr);
nr = BuilderUtils.newNodeReport(BuilderUtils.newNodeId("host2", 0), NodeState.RUNNING, "httpAddress", "rackName", BuilderUtils.newResource(0, 0), BuilderUtils.newResource(containerMem * 2, 2), 0, null, 0);
nodeReports.put(nr.getNodeId().getHost(), nr);
// set resources
rr.updateNodeReports(Lists.newArrayList(nodeReports.values()));
Assert.assertEquals("number of containers is 1", 1, scm.containerStartRequests.size());
for (ContainerStartRequest csr : scm.containerStartRequests) {
String host = rr.getHost(csr, true);
csr.container.host = host;
Assert.assertEquals("Hosts set to host2", "host2", host);
}
}
use of com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent in project apex-core by apache.
the class HostLocalTest method testContainerLocal.
@Test
public void testContainerLocal() {
LogicalPlan dag = new LogicalPlan();
dag.getAttributes().put(com.datatorrent.api.Context.DAGContext.APPLICATION_PATH, new File("target", HostLocalTest.class.getName()).getAbsolutePath());
dag.setAttribute(OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
dag.getMeta(o1).getAttributes().put(OperatorContext.LOCALITY_HOST, "host2");
GenericTestOperator partitioned = dag.addOperator("partitioned", GenericTestOperator.class);
dag.addStream("o1_outport1", o1.outport1, partitioned.inport1).setLocality(Locality.CONTAINER_LOCAL);
dag.setOperatorAttribute(o1, OperatorContext.MEMORY_MB, 256);
dag.setOperatorAttribute(partitioned, OperatorContext.MEMORY_MB, 256);
StreamingContainerManager scm = new StreamingContainerManager(dag);
ResourceRequestHandler rr = new ResourceRequestHandler();
int containerMem = 1000;
Map<String, NodeReport> nodeReports = Maps.newHashMap();
NodeReport nr = BuilderUtils.newNodeReport(BuilderUtils.newNodeId("host1", 0), NodeState.RUNNING, "httpAddress", "rackName", BuilderUtils.newResource(0, 0), BuilderUtils.newResource(containerMem * 2, 2), 0, null, 0);
nodeReports.put(nr.getNodeId().getHost(), nr);
nr = BuilderUtils.newNodeReport(BuilderUtils.newNodeId("host2", 0), NodeState.RUNNING, "httpAddress", "rackName", BuilderUtils.newResource(0, 0), BuilderUtils.newResource(containerMem * 2, 2), 0, null, 0);
nodeReports.put(nr.getNodeId().getHost(), nr);
// set resources
rr.updateNodeReports(Lists.newArrayList(nodeReports.values()));
Assert.assertEquals("number of containers is 1", 1, scm.containerStartRequests.size());
for (ContainerStartRequest csr : scm.containerStartRequests) {
String host = rr.getHost(csr, true);
csr.container.host = host;
Assert.assertEquals("Hosts set to host2", "host2", host);
}
}
use of com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent in project apex-core by apache.
the class HostLocalTest method testUnavailableResources.
@Test
public void testUnavailableResources() {
LogicalPlan dag = new LogicalPlan();
dag.getAttributes().put(com.datatorrent.api.Context.DAGContext.APPLICATION_PATH, new File("target", HostLocalTest.class.getName()).getAbsolutePath());
dag.setAttribute(OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
dag.getMeta(o1).getAttributes().put(OperatorContext.LOCALITY_HOST, "host2");
GenericTestOperator partitioned = dag.addOperator("partitioned", GenericTestOperator.class);
dag.addStream("o1_outport1", o1.outport1, partitioned.inport1).setLocality(Locality.CONTAINER_LOCAL);
dag.setOperatorAttribute(o1, OperatorContext.MEMORY_MB, 256);
dag.setOperatorAttribute(o1, OperatorContext.VCORES, 2);
dag.setOperatorAttribute(partitioned, OperatorContext.VCORES, 1);
StreamingContainerManager scm = new StreamingContainerManager(dag);
ResourceRequestHandler rr = new ResourceRequestHandler();
int containerMem = 1000;
Map<String, NodeReport> nodeReports = Maps.newHashMap();
NodeReport nr = BuilderUtils.newNodeReport(BuilderUtils.newNodeId("host1", 0), NodeState.RUNNING, "httpAddress", "rackName", BuilderUtils.newResource(0, 0), BuilderUtils.newResource(containerMem * 2, 2), 0, null, 0);
nodeReports.put(nr.getNodeId().getHost(), nr);
nr = BuilderUtils.newNodeReport(BuilderUtils.newNodeId("host2", 0), NodeState.RUNNING, "httpAddress", "rackName", BuilderUtils.newResource(0, 0), BuilderUtils.newResource(containerMem * 2, 2), 0, null, 0);
nodeReports.put(nr.getNodeId().getHost(), nr);
// set resources
rr.updateNodeReports(Lists.newArrayList(nodeReports.values()));
Assert.assertEquals("number of containers is 1", 1, scm.containerStartRequests.size());
for (ContainerStartRequest csr : scm.containerStartRequests) {
String host = rr.getHost(csr, true);
Assert.assertEquals("number of vcores", 3, csr.container.getRequiredVCores());
Assert.assertNull("Host is null", host);
}
}
use of com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent in project apex-core by apache.
the class CheckpointTest method testBlockedOperatorContainerRestart.
@Test
public void testBlockedOperatorContainerRestart() {
MockClock clock = new MockClock();
dag.setAttribute(com.datatorrent.api.Context.OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
dag.setOperatorAttribute(o1, OperatorContext.TIMEOUT_WINDOW_COUNT, 2);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
dag.addStream("o1.outport1", o1.outport1, o2.inport1);
StreamingContainerManager scm = new StreamingContainerManager(dag, false, clock);
PhysicalPlan plan = scm.getPhysicalPlan();
List<PTContainer> containers = plan.getContainers();
Assert.assertEquals("Number of containers", 2, containers.size());
Map<PTContainer, MockContainer> mockContainers = Maps.newHashMap();
// allocate/assign all containers
for (PTContainer c : containers) {
MockContainer mc = new MockContainer(scm, c);
mockContainers.put(c, mc);
}
// deploy all containers
for (MockContainer mc : mockContainers.values()) {
mc.deploy();
}
PTOperator o1p1 = plan.getOperators(dag.getMeta(o1)).get(0);
MockContainer mc1 = mockContainers.get(o1p1.getContainer());
MockOperatorStats o1p1mos = mockContainers.get(o1p1.getContainer()).stats(o1p1.getId());
o1p1mos.currentWindowId(1).deployState(DeployState.ACTIVE);
clock.time = 10;
mc1.sendHeartbeat();
Assert.assertEquals(clock.time, o1p1.stats.lastWindowIdChangeTms);
Assert.assertEquals(1, o1p1.stats.currentWindowId.get());
Assert.assertEquals(PTOperator.State.ACTIVE, o1p1.getState());
int timeoutMs = dag.getMeta(o1).getValue(OperatorContext.TIMEOUT_WINDOW_COUNT) * dag.getValue(DAG.STREAMING_WINDOW_SIZE_MILLIS);
Assert.assertEquals("processing timeout", timeoutMs, o1p1.stats.windowProcessingTimeoutMillis);
clock.time += timeoutMs;
mc1.sendHeartbeat();
Assert.assertEquals(PTOperator.State.ACTIVE, o1p1.getState());
Assert.assertEquals(10, o1p1.stats.lastWindowIdChangeTms);
scm.monitorHeartbeat(false);
Assert.assertTrue(scm.containerStopRequests.isEmpty());
clock.time++;
mc1.sendHeartbeat();
Assert.assertEquals(PTOperator.State.ACTIVE, o1p1.getState());
scm.monitorHeartbeat(false);
Assert.assertTrue(scm.containerStopRequests.containsKey(o1p1.getContainer().getExternalId()));
}
Aggregations