Search in sources :

Example 16 with MockedSources

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));
    }
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) OutputFieldsDeclarer(org.apache.storm.topology.OutputFieldsDeclarer) BaseRichSpout(org.apache.storm.topology.base.BaseRichSpout) Arrays(java.util.Arrays) TopologyContext(org.apache.storm.task.TopologyContext) SubmitOptions(org.apache.storm.generated.SubmitOptions) AssertLoop.assertFailed(org.apache.storm.AssertLoop.assertFailed) Assert.assertThat(org.junit.Assert.assertThat) Map(java.util.Map) TestAggregatesCounter(org.apache.storm.testing.TestAggregatesCounter) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TestWordSpout(org.apache.storm.testing.TestWordSpout) MockedSources(org.apache.storm.testing.MockedSources) BaseRichBolt(org.apache.storm.topology.base.BaseRichBolt) EmitInfo(org.apache.storm.hooks.info.EmitInfo) FixedTuple(org.apache.storm.testing.FixedTuple) BoltAckInfo(org.apache.storm.hooks.info.BoltAckInfo) Fields(org.apache.storm.tuple.Fields) Collectors(java.util.stream.Collectors) TestWordCounter(org.apache.storm.testing.TestWordCounter) Test(org.junit.jupiter.api.Test) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) TrackedTopology(org.apache.storm.testing.TrackedTopology) Config(org.apache.storm.Config) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) TestGlobalCount(org.apache.storm.testing.TestGlobalCount) IntStream(java.util.stream.IntStream) TestConfBolt(org.apache.storm.testing.TestConfBolt) Testing(org.apache.storm.Testing) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FeederSpout(org.apache.storm.testing.FeederSpout) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) OutputCollector(org.apache.storm.task.OutputCollector) StormTopology(org.apache.storm.generated.StormTopology) BoltFailInfo(org.apache.storm.hooks.info.BoltFailInfo) CompleteTopologyParam(org.apache.storm.testing.CompleteTopologyParam) BoltExecuteInfo(org.apache.storm.hooks.info.BoltExecuteInfo) TestPlannerSpout(org.apache.storm.testing.TestPlannerSpout) ValueSource(org.junit.jupiter.params.provider.ValueSource) AssertLoop.assertAcked(org.apache.storm.AssertLoop.assertAcked) AckFailMapTracker(org.apache.storm.testing.AckFailMapTracker) TopologyInitialStatus(org.apache.storm.generated.TopologyInitialStatus) BaseTaskHook(org.apache.storm.hooks.BaseTaskHook) Consumer(java.util.function.Consumer) LocalCluster(org.apache.storm.LocalCluster) IntegrationTest(org.apache.storm.testing.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) Collections(java.util.Collections) LocalCluster(org.apache.storm.LocalCluster) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) FixedTuple(org.apache.storm.testing.FixedTuple) MockedSources(org.apache.storm.testing.MockedSources) Fields(org.apache.storm.tuple.Fields) CompleteTopologyParam(org.apache.storm.testing.CompleteTopologyParam) List(java.util.List) ArrayList(java.util.ArrayList) TestPlannerSpout(org.apache.storm.testing.TestPlannerSpout) Test(org.junit.jupiter.api.Test) IntegrationTest(org.apache.storm.testing.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with MockedSources

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)));
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) FixedTuple(org.apache.storm.testing.FixedTuple) MockedSources(org.apache.storm.testing.MockedSources) CompleteTopologyParam(org.apache.storm.testing.CompleteTopologyParam) TestWordSpout(org.apache.storm.testing.TestWordSpout) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) IntegrationTest(org.apache.storm.testing.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with MockedSources

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));
}
Also used : Datapoint(org.openkilda.messaging.info.Datapoint) MockedSources(org.apache.storm.testing.MockedSources) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) StableAbstractStormTest(org.openkilda.wfm.StableAbstractStormTest) Test(org.junit.Test)

Example 19 with MockedSources

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));
}
Also used : Datapoint(org.openkilda.messaging.info.Datapoint) MockedSources(org.apache.storm.testing.MockedSources) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) Properties(java.util.Properties) StableAbstractStormTest(org.openkilda.wfm.StableAbstractStormTest) Test(org.junit.Test)

Aggregations

MockedSources (org.apache.storm.testing.MockedSources)19 StormTopology (org.apache.storm.generated.StormTopology)18 Values (org.apache.storm.tuple.Values)15 CompleteTopologyParam (org.apache.storm.testing.CompleteTopologyParam)13 List (java.util.List)11 Map (java.util.Map)11 FixedTuple (org.apache.storm.testing.FixedTuple)11 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 TestWordSpout (org.apache.storm.testing.TestWordSpout)10 Config (org.apache.storm.Config)9 TestGlobalCount (org.apache.storm.testing.TestGlobalCount)9 Test (org.junit.Test)9 Collectors (java.util.stream.Collectors)8 LocalCluster (org.apache.storm.LocalCluster)8 IntegrationTest (org.apache.storm.testing.IntegrationTest)8 Collections (java.util.Collections)7 Testing (org.apache.storm.Testing)7 TopologyContext (org.apache.storm.task.TopologyContext)7