use of com.datatorrent.stram.engine.GenericTestOperator in project apex-core by apache.
the class StreamPersistanceTests method testPersistStreamOperatorIsAddedPerSink.
@Test
public void testPersistStreamOperatorIsAddedPerSink() {
TestGeneratorInputOperator input1 = dag.addOperator("input1", TestGeneratorInputOperator.class);
GenericTestOperator x1 = dag.addOperator("x1", new GenericTestOperator());
GenericTestOperator x2 = dag.addOperator("x2", new GenericTestOperator());
GenericTestOperator x3 = dag.addOperator("x3", new GenericTestOperator());
TestReceiverOperator persister = new TestReceiverOperator();
TestReceiverOperator persister1 = new TestReceiverOperator();
TestReceiverOperator persister2 = new TestReceiverOperator();
StreamMeta stream = dag.addStream("Stream1", input1.outport, x1.inport1, x2.inport1, x3.inport1);
stream.persistUsing("Stream1_persister", persister, persister.inport);
stream.persistUsing("Stream1_x1_persister", persister1, persister1.inport, x1.inport1);
stream.persistUsing("Stream1_x2_persister", persister2, persister2.inport, x2.inport1);
// Check 3 persist operators are added to dag
OperatorMeta persistOperatorMeta = dag.getOperatorMeta("Stream1_persister");
assertEquals("Persist operator not added to dag ", persister, persistOperatorMeta.getOperator());
persistOperatorMeta = dag.getOperatorMeta("Stream1_x1_persister");
assertEquals("Persist operator not added to dag ", persister1, persistOperatorMeta.getOperator());
persistOperatorMeta = dag.getOperatorMeta("Stream1_x2_persister");
assertEquals("Persist operator not added to dag ", persister2, persistOperatorMeta.getOperator());
dag.validate();
}
use of com.datatorrent.stram.engine.GenericTestOperator in project apex-core by apache.
the class StreamPersistanceTests method testPersistStreamOperatorIsRemovedWhenSinkIsRemoved.
@Test
public void testPersistStreamOperatorIsRemovedWhenSinkIsRemoved() {
// Remove sink and check if corresponding persist operator is removed
TestGeneratorInputOperator input1 = dag.addOperator("input1", TestGeneratorInputOperator.class);
GenericTestOperator x1 = dag.addOperator("x1", new GenericTestOperator());
GenericTestOperator x2 = dag.addOperator("x2", new GenericTestOperator());
GenericTestOperator x3 = dag.addOperator("x3", new GenericTestOperator());
TestReceiverOperator persister = new TestReceiverOperator();
TestReceiverOperator persister1 = new TestReceiverOperator();
TestReceiverOperator persister2 = new TestReceiverOperator();
StreamMeta stream = dag.addStream("Stream1", input1.outport, x1.inport1, x2.inport1, x3.inport1);
stream.persistUsing("Stream1_persister", persister, persister.inport);
stream.persistUsing("Stream1_x1_persister", persister1, persister1.inport, x1.inport1);
stream.persistUsing("Stream1_x2_persister", persister2, persister2.inport, x2.inport1);
// Check 3 persist operators are added to dag
OperatorMeta persistOperatorMeta = dag.getOperatorMeta("Stream1_persister");
assertEquals("Persist operator not added to dag ", persister, persistOperatorMeta.getOperator());
persistOperatorMeta = dag.getOperatorMeta("Stream1_x1_persister");
assertEquals("Persist operator not added to dag ", persister1, persistOperatorMeta.getOperator());
persistOperatorMeta = dag.getOperatorMeta("Stream1_x2_persister");
assertEquals("Persist operator not added to dag ", persister2, persistOperatorMeta.getOperator());
dag.removeOperator(x1);
// Check persister for x1 is removed
persistOperatorMeta = dag.getOperatorMeta("Stream1_x1_persister");
assertEquals("Persist operator should be removed from dag after sink is removed", null, persistOperatorMeta);
// Check other persisters are unchanged
persistOperatorMeta = dag.getOperatorMeta("Stream1_persister");
assertEquals("Persist operator not added to dag ", persister, persistOperatorMeta.getOperator());
persistOperatorMeta = dag.getOperatorMeta("Stream1_x2_persister");
assertEquals("Persist operator not added to dag ", persister2, persistOperatorMeta.getOperator());
}
use of com.datatorrent.stram.engine.GenericTestOperator in project apex-core by apache.
the class CheckpointTest method testBackup.
/**
* Test saving of operator state at window boundary.
* @throws Exception
*/
@Test
public void testBackup() throws Exception {
AsyncFSStorageAgent storageAgent = new AsyncFSStorageAgent(testMeta.getPath(), null);
storageAgent.setSyncCheckpoint(true);
dag.setAttribute(OperatorContext.STORAGE_AGENT, storageAgent);
dag.setAttribute(LogicalPlan.CHECKPOINT_WINDOW_COUNT, 1);
dag.setAttribute(LogicalPlan.HEARTBEAT_INTERVAL_MILLIS, 50);
dag.setAttribute(LogicalPlan.CONTAINERS_MAX_COUNT, 1);
dag.setAttribute(LogicalPlan.STREAMING_WINDOW_SIZE_MILLIS, 50);
MockInputOperator o1 = dag.addOperator("o1", new MockInputOperator());
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
dag.setOperatorAttribute(o2, OperatorContext.STATELESS, true);
dag.addStream("o1.outport", o1.outport, o2.inport1).setLocality(Locality.CONTAINER_LOCAL);
StramLocalCluster sc = new StramLocalCluster(dag);
sc.setHeartbeatMonitoringEnabled(false);
sc.run();
StreamingContainerManager dnm = sc.dnmgr;
PhysicalPlan plan = dnm.getPhysicalPlan();
Assert.assertEquals("number required containers", 1, dnm.getPhysicalPlan().getContainers().size());
PTOperator o1p1 = plan.getOperators(dag.getMeta(o1)).get(0);
Set<Long> checkpoints = Sets.newHashSet();
for (long windowId : storageAgent.getWindowIds(o1p1.getId())) {
checkpoints.add(windowId);
}
Assert.assertEquals("number checkpoints " + checkpoints, 3, checkpoints.size());
Assert.assertTrue("contains " + checkpoints + " " + Stateless.WINDOW_ID, checkpoints.contains(Stateless.WINDOW_ID));
PTOperator o2p1 = plan.getOperators(dag.getMeta(o2)).get(0);
checkpoints = Sets.newHashSet();
for (long windowId : storageAgent.getWindowIds(o2p1.getId())) {
checkpoints.add(windowId);
}
Assert.assertEquals("number checkpoints " + checkpoints, 1, checkpoints.size());
Assert.assertEquals("checkpoints " + o2p1, Sets.newHashSet(Stateless.WINDOW_ID), checkpoints);
Assert.assertEquals("checkpoints " + o1p1 + " " + o1p1.checkpoints, 2, o1p1.checkpoints.size());
Assert.assertNotNull("checkpoint not null for statefull operator " + o1p1, o1p1.stats.checkpointStats);
for (Checkpoint cp : o1p1.checkpoints) {
Object load = storageAgent.load(o1p1.getId(), cp.windowId);
Assert.assertEquals("Stored Operator and Saved State", load.getClass(), o1p1.getOperatorMeta().getOperator().getClass());
}
}
use of com.datatorrent.stram.engine.GenericTestOperator 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()));
}
use of com.datatorrent.stram.engine.GenericTestOperator 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