use of org.apache.storm.testing.MockedSources in project open-kilda by telstra.
the class OpenTSDBTopologyTest method shouldSuccessfulSendDatapoint.
@Ignore
@Test
public void shouldSuccessfulSendDatapoint() throws Exception {
Datapoint datapoint = new Datapoint("metric", timestamp, Collections.emptyMap(), 123);
MockedSources sources = new MockedSources();
// TODO: rather than use Topic.OTSDB, grab it from the TopologyConfig object (which does
// not exist at this point in the code.
sources.addMockData(Topic.OTSDB + "-spout", new Values(MAPPER.writeValueAsString(datapoint)));
completeTopologyParam.setMockedSources(sources);
Testing.withTrackedCluster(clusterParam, (cluster) -> {
OpenTSDBTopology topology = new TestingTargetTopology(new TestingKafkaBolt());
StormTopology stormTopology = topology.createTopology();
Map result = Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
});
// verify that request is sent to OpenTSDB server
mockServer.verify(HttpRequest.request(), VerificationTimes.exactly(1));
}
use of org.apache.storm.testing.MockedSources in project storm by apache.
the class MessagingTest method testRemoteTransportWithManyTasksInReceivingExecutor.
@Test
public void testRemoteTransportWithManyTasksInReceivingExecutor() throws Exception {
// STORM-3141 regression test
// Verify that remote worker can handle many tasks in one executor
Config topoConf = new Config();
topoConf.put(Config.TOPOLOGY_WORKERS, 2);
topoConf.put(Config.STORM_MESSAGING_TRANSPORT, "org.apache.storm.messaging.netty.Context");
try (ILocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().withSupervisors(1).withPortsPerSupervisor(2).withDaemonConf(topoConf).build()) {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("1", new TestWordSpout(true), 1);
builder.setBolt("2", new TestGlobalCount(), 1).setNumTasks(10).shuffleGrouping("1");
StormTopology stormTopology = builder.createTopology();
List<FixedTuple> fixedTuples = new ArrayList<>();
for (int i = 0; i < 12; i++) {
fixedTuples.add(new FixedTuple(Collections.singletonList("a")));
fixedTuples.add(new FixedTuple(Collections.singletonList("b")));
}
Map<String, List<FixedTuple>> data = new HashMap<>();
data.put("1", fixedTuples);
MockedSources mockedSources = new MockedSources(data);
CompleteTopologyParam completeTopologyParam = new CompleteTopologyParam();
completeTopologyParam.setMockedSources(mockedSources);
Map<String, List<FixedTuple>> results = Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
Assert.assertEquals(6 * 4, Testing.readTuples(results, "2").size());
}
}
use of org.apache.storm.testing.MockedSources in project storm by apache.
the class TopologyIntegrationTest method tryCompleteWordCountTopology.
private boolean tryCompleteWordCountTopology(LocalCluster cluster, StormTopology topology) throws Exception {
try {
List<FixedTuple> testTuples = Arrays.asList("nathan", "bob", "joey", "nathan").stream().map(value -> new FixedTuple(new Values(value))).collect(Collectors.toList());
MockedSources mockedSources = new MockedSources(Collections.singletonMap("1", testTuples));
CompleteTopologyParam completeTopologyParam = new CompleteTopologyParam();
completeTopologyParam.setMockedSources(mockedSources);
completeTopologyParam.setStormConf(Collections.singletonMap(Config.TOPOLOGY_WORKERS, 2));
Testing.completeTopology(cluster, topology, completeTopologyParam);
return false;
} catch (InvalidTopologyException e) {
return true;
}
}
use of org.apache.storm.testing.MockedSources in project storm by apache.
the class TopologyIntegrationTest method testKryoDecoratorsConfig.
@Test
public void testKryoDecoratorsConfig() throws Exception {
Map<String, Object> daemonConf = new HashMap<>();
daemonConf.put(Config.TOPOLOGY_SKIP_MISSING_KRYO_REGISTRATIONS, true);
daemonConf.put(Config.TOPOLOGY_KRYO_DECORATORS, "this-is-overridden");
try (LocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().withDaemonConf(daemonConf).build()) {
TopologyBuilder topologyBuilder = new TopologyBuilder();
topologyBuilder.setSpout("1", new TestPlannerSpout(new Fields("conf")));
topologyBuilder.setBolt("2", new TestConfBolt(Collections.singletonMap(Config.TOPOLOGY_KRYO_DECORATORS, Arrays.asList("one", "two")))).shuffleGrouping("1");
List<FixedTuple> testTuples = Arrays.asList(new Values(Config.TOPOLOGY_KRYO_DECORATORS)).stream().map(value -> new FixedTuple(value)).collect(Collectors.toList());
MockedSources mockedSources = new MockedSources(Collections.singletonMap("1", testTuples));
CompleteTopologyParam completeTopologyParams = new CompleteTopologyParam();
completeTopologyParams.setMockedSources(mockedSources);
completeTopologyParams.setStormConf(Collections.singletonMap(Config.TOPOLOGY_KRYO_DECORATORS, Arrays.asList("one", "three")));
Map<String, List<FixedTuple>> results = Testing.completeTopology(cluster, topologyBuilder.createTopology(), completeTopologyParams);
List<Object> concatValues = Testing.readTuples(results, "2").stream().flatMap(values -> values.stream()).collect(Collectors.toList());
assertThat(concatValues.get(0), is(Config.TOPOLOGY_KRYO_DECORATORS));
assertThat(concatValues.get(1), is(Arrays.asList("one", "two", "three")));
}
}
use of org.apache.storm.testing.MockedSources in project storm by apache.
the class NettyIntegrationTest method testIntegration.
@Test
public void testIntegration() throws Exception {
Map<String, Object> daemonConf = new HashMap<>();
daemonConf.put(Config.STORM_LOCAL_MODE_ZMQ, true);
daemonConf.put(Config.STORM_MESSAGING_TRANSPORT, "org.apache.storm.messaging.netty.Context");
daemonConf.put(Config.STORM_MESSAGING_NETTY_AUTHENTICATION, false);
daemonConf.put(Config.STORM_MESSAGING_NETTY_BUFFER_SIZE, 1024000);
daemonConf.put(Config.STORM_MESSAGING_NETTY_MIN_SLEEP_MS, 1000);
daemonConf.put(Config.STORM_MESSAGING_NETTY_MAX_SLEEP_MS, 5000);
daemonConf.put(Config.STORM_MESSAGING_NETTY_CLIENT_WORKER_THREADS, 1);
daemonConf.put(Config.STORM_MESSAGING_NETTY_SERVER_WORKER_THREADS, 1);
Builder builder = new Builder().withSimulatedTime().withSupervisors(4).withSupervisorSlotPortMin(6710).withDaemonConf(daemonConf);
try (LocalCluster cluster = builder.build()) {
TopologyBuilder topologyBuilder = new TopologyBuilder();
topologyBuilder.setSpout("1", new TestWordSpout(true), 4);
topologyBuilder.setBolt("2", new TestGlobalCount(), 6).shuffleGrouping("1");
StormTopology topology = topologyBuilder.createTopology();
// important for test that tuples = multiple of 4 and 6
List<FixedTuple> testTuples = Stream.of("a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b").map(value -> new FixedTuple(new Values(value))).collect(Collectors.toList());
MockedSources mockedSources = new MockedSources(Collections.singletonMap("1", testTuples));
CompleteTopologyParam completeTopologyParams = new CompleteTopologyParam();
completeTopologyParams.setStormConf(Collections.singletonMap(Config.TOPOLOGY_WORKERS, 3));
completeTopologyParams.setMockedSources(mockedSources);
Map<String, List<FixedTuple>> results = Testing.completeTopology(cluster, topology, completeTopologyParams);
assertEquals(6 * 4, Testing.readTuples(results, "2").size());
}
}
Aggregations