Search in sources :

Example 1 with PerformanceDataReading

use of org.opennms.netmgt.rrd.tcp.PerformanceDataProtos.PerformanceDataReading in project opennms by OpenNMS.

the class TcpOutputStrategyTest method peristAndReceiveProtobufMessages.

@Test
public void peristAndReceiveProtobufMessages() {
    // Build a collection set with both numeric and string attributes
    String owner = "192.168.1.1";
    MockCollectionAgent agent = new MockCollectionAgent(1, "n1", InetAddressUtils.addr(owner));
    CollectionSetBuilder builder = new CollectionSetBuilder(agent);
    NodeLevelResource node = new NodeLevelResource(agent.getNodeId());
    InterfaceLevelResource eth0 = new InterfaceLevelResource(node, "eth0");
    builder.withNumericAttribute(eth0, "mib2-interfaces", "ifInErrors", 0.0, AttributeType.COUNTER);
    builder.withStringAttribute(eth0, "mib2-interfaces", "ifSpeed", "10000000");
    builder.withStringAttribute(eth0, "mib2-interfaces", "ifHighSpeed", "10");
    CollectionSet collectionSet = builder.build();
    // Persist without storeByGroup
    persist(collectionSet, false);
    // Wait for the server to receive the readings
    await().until(() -> allReadings.size() == 1);
    PerformanceDataReadings readings = allReadings.get(0);
    // The reading should contain three messages
    assertEquals(3, readings.getMessageCount());
    PerformanceDataReading reading = readings.getMessage(0);
    assertEquals(PerformanceDataReading.newBuilder().setPath(Paths.get(tempFolder.getRoot().getAbsolutePath(), "1", "eth0", "ifInErrors").toString()).setOwner(owner).setTimestamp(reading.getTimestamp()).addAllDblValue(Arrays.asList(Double.valueOf(0.0))).addAllStrValue(Collections.emptyList()).build(), reading);
    reading = readings.getMessage(1);
    assertEquals(PerformanceDataReading.newBuilder().setPath(Paths.get(tempFolder.getRoot().getAbsolutePath(), "1", "eth0", "ifSpeed").toString()).setOwner(owner).setTimestamp(reading.getTimestamp()).addAllDblValue(Collections.emptyList()).addAllStrValue(Arrays.asList("10000000")).build(), reading);
    reading = readings.getMessage(2);
    assertEquals(PerformanceDataReading.newBuilder().setPath(Paths.get(tempFolder.getRoot().getAbsolutePath(), "1", "eth0", "ifHighSpeed").toString()).setOwner(owner).setTimestamp(reading.getTimestamp()).addAllDblValue(Collections.emptyList()).addAllStrValue(Arrays.asList("10")).build(), reading);
    // Persist with storeByGroup
    persist(collectionSet, true);
    // Wait for the server to receive the readings
    await().until(() -> allReadings.size() == 2);
    readings = allReadings.get(1);
    // The reading should contain 1 message
    assertEquals(1, readings.getMessageCount());
    reading = readings.getMessage(0);
    assertEquals(PerformanceDataReading.newBuilder().setPath(Paths.get(tempFolder.getRoot().getAbsolutePath(), "1", "eth0", "mib2-interfaces").toString()).setOwner(owner).setTimestamp(reading.getTimestamp()).addAllDblValue(Arrays.asList(Double.valueOf(0.0))).addAllStrValue(Arrays.asList("10", "10000000")).build(), reading);
}
Also used : PerformanceDataReading(org.opennms.netmgt.rrd.tcp.PerformanceDataProtos.PerformanceDataReading) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) PerformanceDataReadings(org.opennms.netmgt.rrd.tcp.PerformanceDataProtos.PerformanceDataReadings) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 MockCollectionAgent (org.opennms.core.collection.test.MockCollectionAgent)1 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)1 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)1 InterfaceLevelResource (org.opennms.netmgt.collection.support.builder.InterfaceLevelResource)1 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)1 PerformanceDataReading (org.opennms.netmgt.rrd.tcp.PerformanceDataProtos.PerformanceDataReading)1 PerformanceDataReadings (org.opennms.netmgt.rrd.tcp.PerformanceDataProtos.PerformanceDataReadings)1