Search in sources :

Example 1 with CORRELATION_ID

use of org.openkilda.messaging.Utils.CORRELATION_ID in project open-kilda by telstra.

the class StatsTopologyTest method portStatsTest.

@Ignore
@Test
public void portStatsTest() throws Exception {
    final String switchId = "00:00:00:00:00:00:00:01";
    final List<PortStatsEntry> entries = IntStream.range(1, 53).boxed().map(port -> {
        int baseCount = port * 20;
        return new PortStatsEntry(port, baseCount, baseCount + 1, baseCount + 2, baseCount + 3, baseCount + 4, baseCount + 5, baseCount + 6, baseCount + 7, baseCount + 8, baseCount + 9, baseCount + 10, baseCount + 11);
    }).collect(toList());
    final List<PortStatsReply> replies = Collections.singletonList(new PortStatsReply(1, entries));
    InfoMessage message = new InfoMessage(new PortStatsData(switchId, replies), timestamp, CORRELATION_ID, Destination.WFM_STATS);
    // mock kafka spout
    MockedSources sources = new MockedSources();
    sources.addMockData(StatsComponentType.STATS_OFS_KAFKA_SPOUT.toString(), new Values(MAPPER.writeValueAsString(message)));
    completeTopologyParam.setMockedSources(sources);
    // execute topology
    Testing.withTrackedCluster(clusterParam, (cluster) -> {
        StatsTopology topology = new TestingTargetTopology(new TestingKafkaBolt());
        StormTopology stormTopology = topology.createTopology();
        // verify results
        Map result = Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
        ArrayList<FixedTuple> tuples = (ArrayList<FixedTuple>) result.get(StatsComponentType.PORT_STATS_METRIC_GEN.name());
        assertThat(tuples.size(), is(728));
        tuples.stream().map(this::readFromJson).forEach(datapoint -> {
            assertThat(datapoint.getTags().get("switchId"), is(switchId.replaceAll(":", "")));
            assertThat(datapoint.getTime(), is(timestamp));
            assertThat(datapoint.getMetric(), startsWith("pen.switch"));
        });
    });
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) InfoMessage(org.openkilda.messaging.info.InfoMessage) IntStream(java.util.stream.IntStream) StableAbstractStormTest(org.openkilda.wfm.StableAbstractStormTest) java.util(java.util) Testing(org.apache.storm.Testing) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) Values(org.apache.storm.tuple.Values) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) StormTopology(org.apache.storm.generated.StormTopology) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) MeterConfigReply(org.openkilda.messaging.info.stats.MeterConfigReply) MAPPER(org.openkilda.messaging.Utils.MAPPER) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Utils(org.openkilda.messaging.Utils) MockedSources(org.apache.storm.testing.MockedSources) PortStatsReply(org.openkilda.messaging.info.stats.PortStatsReply) KafkaBolt(org.apache.storm.kafka.bolt.KafkaBolt) FlowStatsEntry(org.openkilda.messaging.info.stats.FlowStatsEntry) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) PortStatsEntry(org.openkilda.messaging.info.stats.PortStatsEntry) FlowStatsReply(org.openkilda.messaging.info.stats.FlowStatsReply) TestFlowGenMetricsBolt(org.openkilda.wfm.topology.TestFlowGenMetricsBolt) TestingKafkaBolt(org.openkilda.wfm.topology.TestingKafkaBolt) FixedTuple(org.apache.storm.testing.FixedTuple) Test(org.junit.Test) IOException(java.io.IOException) MeterConfigStatsData(org.openkilda.messaging.info.stats.MeterConfigStatsData) Datapoint(org.openkilda.messaging.info.Datapoint) File(java.io.File) FlowMetricGenBolt(org.openkilda.wfm.topology.stats.metrics.FlowMetricGenBolt) CORRELATION_ID(org.openkilda.messaging.Utils.CORRELATION_ID) Collectors.toList(java.util.stream.Collectors.toList) Ignore(org.junit.Ignore) Destination(org.openkilda.messaging.Destination) FlowStatsData(org.openkilda.messaging.info.stats.FlowStatsData) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) TestingKafkaBolt(org.openkilda.wfm.topology.TestingKafkaBolt) PortStatsReply(org.openkilda.messaging.info.stats.PortStatsReply) FixedTuple(org.apache.storm.testing.FixedTuple) MockedSources(org.apache.storm.testing.MockedSources) InfoMessage(org.openkilda.messaging.info.InfoMessage) PortStatsEntry(org.openkilda.messaging.info.stats.PortStatsEntry) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) Ignore(org.junit.Ignore) StableAbstractStormTest(org.openkilda.wfm.StableAbstractStormTest) Test(org.junit.Test)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 java.util (java.util)1 Collectors.toList (java.util.stream.Collectors.toList)1 IntStream (java.util.stream.IntStream)1 Testing (org.apache.storm.Testing)1 StormTopology (org.apache.storm.generated.StormTopology)1 KafkaBolt (org.apache.storm.kafka.bolt.KafkaBolt)1 FixedTuple (org.apache.storm.testing.FixedTuple)1 MockedSources (org.apache.storm.testing.MockedSources)1 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)1 Values (org.apache.storm.tuple.Values)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 CoreMatchers.startsWith (org.hamcrest.CoreMatchers.startsWith)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Destination (org.openkilda.messaging.Destination)1 Utils (org.openkilda.messaging.Utils)1