Search in sources :

Example 6 with Datapoint

use of org.openkilda.messaging.info.Datapoint in project open-kilda by telstra.

the class OpenTSDBTopologyTest method shouldSendDatapointRequestsOnlyOnce.

@Ignore
@Test
public void shouldSendDatapointRequestsOnlyOnce() throws Exception {
    Datapoint datapoint = new Datapoint("metric", timestamp, Collections.emptyMap(), 123);
    String jsonDatapoint = MAPPER.writeValueAsString(datapoint);
    MockedSources sources = new MockedSources();
    sources.addMockData(Topic.OTSDB + "-spout", new Values(jsonDatapoint), new Values(jsonDatapoint));
    completeTopologyParam.setMockedSources(sources);
    Testing.withTrackedCluster(clusterParam, (cluster) -> {
        OpenTSDBTopology topology = new TestingTargetTopology(new TestingKafkaBolt());
        StormTopology stormTopology = topology.createTopology();
        Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
    });
    // verify that request is sent to OpenTSDB server once
    mockServer.verify(HttpRequest.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) TestingKafkaBolt(org.openkilda.wfm.topology.TestingKafkaBolt) Ignore(org.junit.Ignore) StableAbstractStormTest(org.openkilda.wfm.StableAbstractStormTest) Test(org.junit.Test)

Example 7 with Datapoint

use of org.openkilda.messaging.info.Datapoint 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));
}
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) TestingKafkaBolt(org.openkilda.wfm.topology.TestingKafkaBolt) Map(java.util.Map) Ignore(org.junit.Ignore) StableAbstractStormTest(org.openkilda.wfm.StableAbstractStormTest) Test(org.junit.Test)

Example 8 with Datapoint

use of org.openkilda.messaging.info.Datapoint in project open-kilda by telstra.

the class OpenTSDBFilterBoltTest method mockTuple.

private void mockTuple(long timestamp) throws Exception {
    InfoData infoData = new Datapoint(METRIC, timestamp, Collections.emptyMap(), VALUE);
    when(tuple.contains(eq("datapoint"))).thenReturn(true);
    when(tuple.getValueByField(eq("datapoint"))).thenReturn(infoData);
}
Also used : Datapoint(org.openkilda.messaging.info.Datapoint) InfoData(org.openkilda.messaging.info.InfoData)

Example 9 with Datapoint

use of org.openkilda.messaging.info.Datapoint 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

Datapoint (org.openkilda.messaging.info.Datapoint)9 Test (org.junit.Test)5 StormTopology (org.apache.storm.generated.StormTopology)4 MockedSources (org.apache.storm.testing.MockedSources)4 Values (org.apache.storm.tuple.Values)4 Ignore (org.junit.Ignore)4 StableAbstractStormTest (org.openkilda.wfm.StableAbstractStormTest)4 TestingKafkaBolt (org.openkilda.wfm.topology.TestingKafkaBolt)4 File (java.io.File)1 IOException (java.io.IOException)1 java.util (java.util)1 Map (java.util.Map)1 Collectors.toList (java.util.stream.Collectors.toList)1 IntStream (java.util.stream.IntStream)1 Testing (org.apache.storm.Testing)1 KafkaBolt (org.apache.storm.kafka.bolt.KafkaBolt)1 FixedTuple (org.apache.storm.testing.FixedTuple)1 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1