use of org.apache.storm.topology.TopologyBuilder in project storm by apache.
the class TopologyIntegrationTest method testResetTimeout.
@Test
public void testResetTimeout() throws Exception {
try (LocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().withDaemonConf(Collections.singletonMap(Config.TOPOLOGY_ENABLE_MESSAGE_TIMEOUTS, true)).build()) {
FeederSpout feeder = new FeederSpout(new Fields("field1"));
AckFailMapTracker tracker = new AckFailMapTracker();
feeder.setAckFailDelegate(tracker);
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("1", feeder);
builder.setBolt("2", new ResetTimeoutBolt()).globalGrouping("1");
StormTopology topology = builder.createTopology();
cluster.submitTopology("reset-timeout-tester", Collections.singletonMap(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS, 10), topology);
// The first tuple wil be used to check timeout reset
feeder.feed(new Values("a"), 1);
// The second tuple is used to wait for the spout to rotate its pending map
feeder.feed(new Values("b"), 2);
cluster.advanceClusterTime(9);
// The other tuples are used to reset the first tuple's timeout,
// and to wait for the message to get through to the spout (acks use the same path as timeout resets)
feeder.feed(new Values("c"), 3);
assertAcked(tracker, 3);
cluster.advanceClusterTime(9);
feeder.feed(new Values("d"), 4);
assertAcked(tracker, 4);
cluster.advanceClusterTime(2);
// The time is now twice the message timeout, the second tuple should expire since it was not acked
// Waiting for this also ensures that the first tuple gets failed if reset-timeout doesn't work
assertFailed(tracker, 2);
// Put in a tuple to cause the first tuple to be acked
feeder.feed(new Values("e"), 5);
assertAcked(tracker, 5);
// The first tuple should be acked, and should not have failed
assertThat(tracker.isFailed(1), is(false));
assertAcked(tracker, 1);
}
}
use of org.apache.storm.topology.TopologyBuilder in project storm by apache.
the class TopologyIntegrationTest method mkInvalidateTopology3.
private StormTopology mkInvalidateTopology3() {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("1", new TestWordSpout(true), 3);
builder.setBolt("2", new TestWordCounter(), 4).fieldsGrouping("1", "non-exists-stream", new Fields("word"));
return builder.createTopology();
}
use of org.apache.storm.topology.TopologyBuilder in project storm by apache.
the class TopologyIntegrationTest method testSystemStream.
@Test
public void testSystemStream() throws Exception {
// this test works because mocking a spout splits up the tuples evenly among the tasks
try (LocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().build()) {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("1", new TestWordSpout(true), 3);
builder.setBolt("2", new IdentityBolt(), 1).fieldsGrouping("1", new Fields("word")).globalGrouping("1", "__system");
StormTopology topology = builder.createTopology();
Map<String, Object> stormConf = new HashMap<>();
stormConf.put(Config.TOPOLOGY_WORKERS, 2);
List<FixedTuple> testTuples = Arrays.asList("a", "b", "c").stream().map(value -> new FixedTuple(new Values(value))).collect(Collectors.toList());
MockedSources mockedSources = new MockedSources(Collections.singletonMap("1", testTuples));
CompleteTopologyParam completeTopologyParams = new CompleteTopologyParam();
completeTopologyParams.setMockedSources(mockedSources);
completeTopologyParams.setStormConf(stormConf);
Map<String, List<FixedTuple>> results = Testing.completeTopology(cluster, topology, completeTopologyParams);
assertThat(Testing.readTuples(results, "2"), containsInAnyOrder(new Values("a"), new Values("b"), new Values("c")));
}
}
use of org.apache.storm.topology.TopologyBuilder in project storm by apache.
the class TopologyIntegrationTest method testAckingSelfAnchor.
@Test
public void testAckingSelfAnchor() throws Exception {
try (LocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().withTracked().build()) {
AckTrackingFeeder feeder = new AckTrackingFeeder("num");
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("1", feeder.getSpout());
builder.setBolt("2", new DupAnchorBolt()).shuffleGrouping("1");
builder.setBolt("3", new AckBolt()).shuffleGrouping("2");
TrackedTopology tracked = new TrackedTopology(builder.createTopology(), cluster);
cluster.submitTopology("test", Collections.emptyMap(), tracked);
cluster.advanceClusterTime(11);
feeder.feed(new Values(1));
Testing.trackedWait(tracked, 1);
feeder.assertNumAcks(1);
feeder.feed(new Values(1));
feeder.feed(new Values(1));
feeder.feed(new Values(1));
Testing.trackedWait(tracked, 3);
feeder.assertNumAcks(3);
}
}
use of org.apache.storm.topology.TopologyBuilder in project storm by apache.
the class TopologyIntegrationTest method testAckBranching.
@Test
public void testAckBranching() throws Exception {
try (LocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().withTracked().build()) {
AckTrackingFeeder feeder = new AckTrackingFeeder("num");
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("1", feeder.getSpout());
builder.setBolt("2", new IdentityBolt()).shuffleGrouping("1");
builder.setBolt("3", new IdentityBolt()).shuffleGrouping("1");
builder.setBolt("4", new AggBolt(4)).shuffleGrouping("2").shuffleGrouping("3");
TrackedTopology tracked = new TrackedTopology(builder.createTopology(), cluster);
cluster.submitTopology("test-acking2", Collections.emptyMap(), tracked);
cluster.advanceClusterTime(11);
feeder.feed(new Values(1));
Testing.trackedWait(tracked, 1);
feeder.assertNumAcks(0);
feeder.feed(new Values(1));
Testing.trackedWait(tracked, 1);
feeder.assertNumAcks(2);
}
}
Aggregations