Search in sources :

Example 1 with JUnitCollector

use of org.opennms.core.collection.test.JUnitCollector in project opennms by OpenNMS.

the class SnmpCollectorIT method collectionTimedOutExceptionOnAgentTimeout.

@Transactional
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/datacollection-persistTest-config.xml", datacollectionType = "snmp")
public void collectionTimedOutExceptionOnAgentTimeout() throws CollectionInitializationException, CollectionException {
    // There is no @JUnitSnmpAgent annotation on this method, so
    // we don't actually start the SNMP agent, which should
    // generate a CollectionTimedOut exception
    CollectionException caught = null;
    try {
        m_collectionSpecification.collect(m_collectionAgent);
    } catch (final CollectionException e) {
        caught = e;
    }
    assertNotNull(caught);
    assertEquals(CollectionTimedOut.class, caught.getCause().getClass());
}
Also used : CollectionException(org.opennms.netmgt.collection.api.CollectionException) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with JUnitCollector

use of org.opennms.core.collection.test.JUnitCollector in project opennms by OpenNMS.

the class HttpCollectorIT method testCollect.

/**
 * Test method for {@link org.opennms.netmgt.collectd.HttpCollector#collect(
 *   org.opennms.netmgt.collection.api.CollectionAgent, org.opennms.netmgt.model.events.EventProxy, Map)}.
 */
@Test
@JUnitHttpServer(port = 10342, vhosts = { "127.0.0.1" })
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/http-datacollection-config.xml", datacollectionType = "http", anticipateRrds = { "1/documentCount", "1/greatAnswer", "1/someNumber" }, anticipateFiles = { "1/strings.properties" })
public final void testCollect() throws Exception {
    CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
    assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
}
Also used : CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 3 with JUnitCollector

use of org.opennms.core.collection.test.JUnitCollector in project opennms by OpenNMS.

the class SnmpCollectorIT method testPersist.

@Test
@Transactional
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/datacollection-persistTest-config.xml", datacollectionType = "snmp", anticipateFiles = { "1", "1/fw0" }, anticipateRrds = { "1/tcpCurrEstab", "1/fw0/ifInOctets" })
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/snmpTestData1.properties")
public void testPersist() throws Exception {
    File snmpRrdDirectory = (File) m_context.getAttribute("rrdDirectory");
    // node level collection
    File nodeDir = new File(snmpRrdDirectory, "1");
    File rrdFile = new File(nodeDir, rrd("tcpCurrEstab"));
    // interface level collection
    File ifDir = new File(nodeDir, "fw0");
    File ifRrdFile = new File(ifDir, rrd("ifInOctets"));
    int numUpdates = 2;
    int stepSizeInSecs = 1;
    int stepSizeInMillis = stepSizeInSecs * 1000;
    final int rangeSizeInMillis = stepSizeInMillis + 20000;
    CollectorTestUtils.collectNTimes(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, m_collectionAgent, numUpdates);
    // This is the value from snmpTestData1.properties
    // .1.3.6.1.2.1.6.9.0 = Gauge32: 123
    assertEquals(Double.valueOf(123.0), m_rrdStrategy.fetchLastValueInRange(rrdFile.getAbsolutePath(), "tcpCurrEstab", stepSizeInMillis, rangeSizeInMillis));
    // This is the value from snmpTestData1.properties
    // .1.3.6.1.2.1.2.2.1.10.6 = Counter32: 1234567
    assertEquals(Double.valueOf(1234567.0), m_rrdStrategy.fetchLastValueInRange(ifRrdFile.getAbsolutePath(), "ifInOctets", stepSizeInMillis, rangeSizeInMillis));
    // now update the data in the agent
    SnmpUtils.set(m_agentConfig, SnmpObjId.get(".1.3.6.1.2.1.6.9.0"), SnmpUtils.getValueFactory().getInt32(456));
    SnmpUtils.set(m_agentConfig, SnmpObjId.get(".1.3.6.1.2.1.2.2.1.10.6"), SnmpUtils.getValueFactory().getCounter32(7654321));
    CollectorTestUtils.collectNTimes(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, m_collectionAgent, numUpdates);
    // by now the values should be the new values
    assertEquals(Double.valueOf(456.0), m_rrdStrategy.fetchLastValueInRange(rrdFile.getAbsolutePath(), "tcpCurrEstab", stepSizeInMillis, rangeSizeInMillis));
    assertEquals(Double.valueOf(7654321.0), m_rrdStrategy.fetchLastValueInRange(ifRrdFile.getAbsolutePath(), "ifInOctets", stepSizeInMillis, rangeSizeInMillis));
}
Also used : File(java.io.File) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with JUnitCollector

use of org.opennms.core.collection.test.JUnitCollector in project opennms by OpenNMS.

the class SnmpCollectorIT method testBrocadeCollect.

@Test
@Transactional
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/datacollection-brocade-config.xml", datacollectionType = "snmp", anticipateRrds = { "1/brocadeFCPortIndex/1/swFCPortTxWords", "1/brocadeFCPortIndex/1/swFCPortRxWords", "1/brocadeFCPortIndex/2/swFCPortTxWords", "1/brocadeFCPortIndex/2/swFCPortRxWords", "1/brocadeFCPortIndex/3/swFCPortTxWords", "1/brocadeFCPortIndex/3/swFCPortRxWords", "1/brocadeFCPortIndex/4/swFCPortTxWords", "1/brocadeFCPortIndex/4/swFCPortRxWords", "1/brocadeFCPortIndex/5/swFCPortTxWords", "1/brocadeFCPortIndex/5/swFCPortRxWords", "1/brocadeFCPortIndex/6/swFCPortTxWords", "1/brocadeFCPortIndex/6/swFCPortRxWords", "1/brocadeFCPortIndex/7/swFCPortTxWords", "1/brocadeFCPortIndex/7/swFCPortRxWords", "1/brocadeFCPortIndex/8/swFCPortTxWords", "1/brocadeFCPortIndex/8/swFCPortRxWords" }, anticipateFiles = { "1", "1/brocadeFCPortIndex", "1/brocadeFCPortIndex/1/strings.properties", "1/brocadeFCPortIndex/1", "1/brocadeFCPortIndex/2/strings.properties", "1/brocadeFCPortIndex/2", "1/brocadeFCPortIndex/3/strings.properties", "1/brocadeFCPortIndex/3", "1/brocadeFCPortIndex/4/strings.properties", "1/brocadeFCPortIndex/4", "1/brocadeFCPortIndex/5/strings.properties", "1/brocadeFCPortIndex/5", "1/brocadeFCPortIndex/6/strings.properties", "1/brocadeFCPortIndex/6", "1/brocadeFCPortIndex/7/strings.properties", "1/brocadeFCPortIndex/7", "1/brocadeFCPortIndex/8/strings.properties", "1/brocadeFCPortIndex/8" })
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/brocadeTestData1.properties")
public void testBrocadeCollect() throws Exception {
    // now do the actual collection
    CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
    assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
    System.err.println("FIRST COLLECTION FINISHED");
    // need a one second time elapse to update the RRD
    Thread.sleep(1000);
    // try collecting again
    assertEquals("collection status", CollectionStatus.SUCCEEDED, m_collectionSpecification.collect(m_collectionAgent).getStatus());
    System.err.println("SECOND COLLECTION FINISHED");
}
Also used : CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with JUnitCollector

use of org.opennms.core.collection.test.JUnitCollector in project opennms by OpenNMS.

the class SnmpCollectorIT method testCollect.

@Test
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/datacollection-config.xml", datacollectionType = "snmp", anticipateFiles = { "1", "1/fw0" }, anticipateRrds = { "1/tcpActiveOpens", "1/tcpAttemptFails", "1/tcpPassiveOpens", "1/tcpRetransSegs", "1/tcpCurrEstab", "1/tcpEstabResets", "1/tcpInErrors", "1/tcpInSegs", "1/tcpOutRsts", "1/tcpOutSegs", "1/fw0/ifInDiscards", "1/fw0/ifInErrors", "1/fw0/ifInNUcastpkts", "1/fw0/ifInOctets", "1/fw0/ifInUcastpkts", "1/fw0/ifOutErrors", "1/fw0/ifOutNUcastPkts", "1/fw0/ifOutOctets", "1/fw0/ifOutUcastPkts" })
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/snmpTestData1.properties")
public void testCollect() throws Exception {
    System.setProperty("org.opennms.netmgt.collectd.SnmpCollector.limitCollectionToInstances", "true");
    // now do the actual collection
    CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
    assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
    System.err.println("FIRST COLLECTION FINISHED");
    // need a one second time elapse to update the RRD
    Thread.sleep(1000);
    // try collecting again
    assertEquals("collection status", CollectionStatus.SUCCEEDED, m_collectionSpecification.collect(m_collectionAgent).getStatus());
    System.err.println("SECOND COLLECTION FINISHED");
}
Also used : CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Aggregations

JUnitCollector (org.opennms.core.collection.test.JUnitCollector)12 Test (org.junit.Test)11 JUnitSnmpAgent (org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)8 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)7 Transactional (org.springframework.transaction.annotation.Transactional)6 File (java.io.File)4 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)2 HashMap (java.util.HashMap)1 RrdDb (org.jrobin.core.RrdDb)1 RrdDef (org.jrobin.core.RrdDef)1 CollectionException (org.opennms.netmgt.collection.api.CollectionException)1 RrdDataSource (org.opennms.netmgt.rrd.RrdDataSource)1 JRobinRrdStrategy (org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy)1 FileAnticipator (org.opennms.test.FileAnticipator)1