use of org.apache.storm.testing.MockedSources in project storm by apache.
the class TopologyIntegrationTest method testHooks.
@Test
public void testHooks() throws Exception {
try (LocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().build()) {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("1", new TestPlannerSpout(new Fields("conf")));
builder.setBolt("2", new HooksBolt()).shuffleGrouping("1");
StormTopology topology = builder.createTopology();
List<FixedTuple> testTuples = Arrays.asList(1, 1, 1, 1).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);
Map<String, List<FixedTuple>> results = Testing.completeTopology(cluster, topology, completeTopologyParams);
List<List<Object>> expectedTuples = Arrays.asList(Arrays.asList(0, 0, 0, 0), Arrays.asList(2, 1, 0, 1), Arrays.asList(4, 1, 1, 2), Arrays.asList(6, 2, 1, 3));
assertThat(Testing.readTuples(results, "2"), is(expectedTuples));
}
}
use of org.apache.storm.testing.MockedSources in project storm by apache.
the class TopologyIntegrationTest method testMultiTasksPerCluster.
@Test
public void testMultiTasksPerCluster() throws Exception {
try (LocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().withSupervisors(4).build()) {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("1", new TestWordSpout(true));
builder.setBolt("2", new EmitTaskIdBolt(), 3).allGrouping("1").addConfigurations(Collections.singletonMap(Config.TOPOLOGY_TASKS, 6));
StormTopology topology = builder.createTopology();
MockedSources mockedSources = new MockedSources(Collections.singletonMap("1", Collections.singletonList(new FixedTuple(new Values("a")))));
CompleteTopologyParam completeTopologyParams = new CompleteTopologyParam();
completeTopologyParams.setMockedSources(mockedSources);
Map<String, List<FixedTuple>> results = Testing.completeTopology(cluster, topology, completeTopologyParams);
assertThat(Testing.readTuples(results, "2"), containsInAnyOrder(new Values(0), new Values(1), new Values(2), new Values(3), new Values(4), new Values(5)));
}
}
use of org.apache.storm.testing.MockedSources in project open-kilda by telstra.
the class OpenTsdbTopologyTest method shouldSendDatapointRequestsOnlyOnce.
@Test
public void shouldSendDatapointRequestsOnlyOnce() throws Exception {
Datapoint datapoint = new Datapoint("metric", timestamp, Collections.emptyMap(), 123);
MockedSources sources = new MockedSources();
Testing.withTrackedCluster(clusterParam, (cluster) -> {
OpenTsdbTopology topology = new OpenTsdbTopology(makeLaunchEnvironment(getProperties()));
sources.addMockData(ZooKeeperSpout.SPOUT_ID, new Values(LifecycleEvent.builder().signal(Signal.NONE).build(), null));
sources.addMockData(OpenTsdbTopology.OTSDB_SPOUT_ID, new Values(null, datapoint), new Values(null, datapoint));
completeTopologyParam.setMockedSources(sources);
StormTopology stormTopology = topology.createTopology();
stormTopology.get_bolts().remove(ZooKeeperBolt.BOLT_ID);
activateDatapointParserBolt(stormTopology);
Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
});
// verify that request is sent to OpenTSDB server once
mockServer.verify(REQUEST, VerificationTimes.exactly(1));
}
use of org.apache.storm.testing.MockedSources in project open-kilda by telstra.
the class OpenTsdbTopologyTest method shouldSendDatapointRequestsTwice.
@Test
public void shouldSendDatapointRequestsTwice() throws Exception {
Datapoint datapoint1 = new Datapoint("metric", timestamp, Collections.emptyMap(), 123);
Datapoint datapoint2 = new Datapoint("metric", timestamp, Collections.emptyMap(), 456);
MockedSources sources = new MockedSources();
Testing.withTrackedCluster(clusterParam, (cluster) -> {
// This test expects to see 2 POST requests to OpenTsdb, but if batch.size > 1 OtsdbBolt will send
// 1 request with 2 metrics instead of 2 requests with 1 metric.
// So next property forces OtsdbBolt to send 2 requests.
Properties properties = getProperties();
properties.put("opentsdb.batch.size", "1");
OpenTsdbTopology topology = new OpenTsdbTopology(makeLaunchEnvironment(properties));
sources.addMockData(ZooKeeperSpout.SPOUT_ID, new Values(LifecycleEvent.builder().signal(Signal.NONE).build(), null));
sources.addMockData(OpenTsdbTopology.OTSDB_SPOUT_ID, new Values(null, datapoint1), new Values(null, datapoint2));
completeTopologyParam.setMockedSources(sources);
StormTopology stormTopology = topology.createTopology();
stormTopology.get_bolts().remove(ZooKeeperBolt.BOLT_ID);
activateDatapointParserBolt(stormTopology);
Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
});
// verify that request is sent to OpenTSDB server once
mockServer.verify(REQUEST, VerificationTimes.exactly(2));
}
Aggregations