Search in sources :

Example 11 with FileAnticipator

use of org.opennms.test.FileAnticipator in project opennms by OpenNMS.

the class TcpRrdStrategyTest method setUp.

@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    //m_strategy = RrdUtils.getStrategy();
    TcpRrdStrategy strategy = new TcpRrdStrategy();
    strategy.setHost("127.0.0.1");
    strategy.setPort(m_listenPort);
    m_strategy = new QueuingTcpRrdStrategy(strategy, 44444);
    // Don't initialize by default since not all tests need it.
    m_fileAnticipator = new FileAnticipator(false);
}
Also used : FileAnticipator(org.opennms.test.FileAnticipator) Before(org.junit.Before)

Example 12 with FileAnticipator

use of org.opennms.test.FileAnticipator in project opennms by OpenNMS.

the class AccessPointMonitorConfigTest method setUp.

@Before
public void setUp() throws Exception {
    fa = new FileAnticipator();
    ServiceTemplate svcTemplate = new ServiceTemplate();
    svcTemplate.setName("IsAPAdoptedOnController-Template");
    svcTemplate.setInterval(120000L);
    svcTemplate.setStatus("off");
    svcTemplate.addParameter(new Parameter("retry", "2"));
    svcTemplate.addParameter(new Parameter("oid", ".1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.19"));
    svcTemplate.addParameter(new Parameter("operator", "="));
    svcTemplate.addParameter(new Parameter("operand", "1"));
    svcTemplate.addParameter(new Parameter("match", "true"));
    Service svc = new Service();
    svc.setName("IsAPAdoptedOnController");
    svc.setTemplateName("IsAPAdoptedOnController-Template");
    svc.setStatus("on");
    svc.addParameter(new Parameter("retry", "3"));
    Package pkg = new Package();
    pkg.setName("default");
    pkg.setFilter("IPADDR != '0.0.0.0'");
    pkg.addSpecific("172.23.1.1");
    pkg.addIncludeRange(new IpRange("192.168.0.0", "192.168.255.255"));
    pkg.addExcludeRange(new IpRange("192.168.1.0", "192.168.1.255"));
    pkg.setService(svc);
    Monitor monitor = new Monitor();
    monitor.setService("IsAPAdoptedOnController");
    monitor.setClassName("org.opennms.netmgt.accesspointmonitor.poller.InstanceStrategy");
    apmc = new AccessPointMonitorConfig();
    apmc.setThreads(30);
    apmc.setPackageScanInterval(1800000L);
    apmc.addServiceTemplate(svcTemplate);
    apmc.addPackage(pkg);
    apmc.addMonitor(monitor);
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setIgnoreAttributeOrder(true);
    XMLUnit.setNormalize(true);
}
Also used : FileAnticipator(org.opennms.test.FileAnticipator) Before(org.junit.Before)

Example 13 with FileAnticipator

use of org.opennms.test.FileAnticipator in project opennms by OpenNMS.

the class JUnitCollectorExecutionListener method beforeTestMethod.

@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
    m_fileAnticipator = new FileAnticipator();
    JUnitCollector config = findCollectorAnnotation(testContext);
    if (config == null) {
        return;
    }
    // make a fake database schema with hibernate
    InputStream is = ConfigurationTestUtils.getInputStreamForResource(testContext.getTestInstance(), config.schemaConfig());
    DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(is));
    is.close();
    // set up temporary directories for RRD files
    m_snmpRrdDirectory = m_fileAnticipator.tempDir("snmp");
    m_snmpRrdDirectory.mkdirs();
    testContext.setAttribute("fileAnticipator", m_fileAnticipator);
    testContext.setAttribute("rrdDirectory", m_snmpRrdDirectory);
    // set up the collection configuration factory
    if ("http".equalsIgnoreCase(config.datacollectionType()) || "https".equalsIgnoreCase(config.datacollectionType())) {
        is = ConfigurationTestUtils.getInputStreamForResourceWithReplacements(testContext.getTestInstance(), config.datacollectionConfig(), new String[] { "%rrdRepository%", m_snmpRrdDirectory.getAbsolutePath() });
        HttpCollectionConfigFactory factory = new HttpCollectionConfigFactory(is);
        HttpCollectionConfigFactory.setInstance(factory);
        HttpCollectionConfigFactory.init();
    } else if ("snmp".equalsIgnoreCase(config.datacollectionType())) {
        Resource r = ConfigurationTestUtils.getSpringResourceForResourceWithReplacements(testContext.getTestInstance(), config.datacollectionConfig(), new String[] { "%rrdRepository%", m_snmpRrdDirectory.getAbsolutePath() });
        DefaultDataCollectionConfigDao dataCollectionDao = new DefaultDataCollectionConfigDao();
        dataCollectionDao.setConfigResource(r);
        dataCollectionDao.afterPropertiesSet();
        DataCollectionConfigFactory.setInstance(dataCollectionDao);
    } else {
        throw new UnsupportedOperationException("data collection type '" + config.datacollectionType() + "' not supported");
    }
    IOUtils.closeQuietly(is);
}
Also used : HttpCollectionConfigFactory(org.opennms.netmgt.config.HttpCollectionConfigFactory) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) DatabaseSchemaConfigFactory(org.opennms.netmgt.config.DatabaseSchemaConfigFactory) FileAnticipator(org.opennms.test.FileAnticipator) DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao)

Example 14 with FileAnticipator

use of org.opennms.test.FileAnticipator in project opennms by OpenNMS.

the class HttpCollectorIT method testPersistApacheStats.

@Test
@JUnitHttpServer(port = 10342, vhosts = { "127.0.0.1" })
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/http-datacollection-persist-apache-stats.xml", datacollectionType = "http", anticipateRrds = { "1/TotalAccesses", "1/TotalkBytes", "1/CPULoad", "1/Uptime", "1/ReqPerSec", "1/BytesPerSec", "1/BytesPerReq", "1/BusyWorkers", "1/IdleWorkers" })
public final void testPersistApacheStats() throws Exception {
    File snmpRrdDirectory = (File) m_context.getAttribute("rrdDirectory");
    FileAnticipator anticipator = (FileAnticipator) m_context.getAttribute("fileAnticipator");
    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);
    // node level collection
    File nodeDir = CollectorTestUtils.anticipatePath(anticipator, snmpRrdDirectory, "1");
    File documentCountRrdFile = new File(nodeDir, CollectorTestUtils.rrd(m_rrdStrategy, "TotalAccesses"));
    File someNumberRrdFile = new File(nodeDir, CollectorTestUtils.rrd(m_rrdStrategy, "IdleWorkers"));
    File cpuLoadRrdFile = new File(nodeDir, CollectorTestUtils.rrd(m_rrdStrategy, "CPULoad"));
    // Total Accesses: 175483
    assertEquals("TotalAccesses", Double.valueOf(175483.0), m_rrdStrategy.fetchLastValueInRange(documentCountRrdFile.getAbsolutePath(), "TotalAccesses", stepSizeInMillis, rangeSizeInMillis));
    // IdleWorkers: 12
    assertEquals("IdleWorkers", Double.valueOf(12.0), m_rrdStrategy.fetchLastValueInRange(someNumberRrdFile.getAbsolutePath(), "IdleWorkers", stepSizeInMillis, rangeSizeInMillis));
    // CPU Load: .497069
    assertEquals("CPULoad", Double.valueOf(0.497069), m_rrdStrategy.fetchLastValueInRange(cpuLoadRrdFile.getAbsolutePath(), "CPULoad", stepSizeInMillis, rangeSizeInMillis));
}
Also used : File(java.io.File) FileAnticipator(org.opennms.test.FileAnticipator) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 15 with FileAnticipator

use of org.opennms.test.FileAnticipator in project opennms by OpenNMS.

the class HttpCollectorIT method doTestPersist.

public final void doTestPersist(CollectionSpecification spec) throws Exception {
    File snmpRrdDirectory = (File) m_context.getAttribute("rrdDirectory");
    FileAnticipator anticipator = (FileAnticipator) m_context.getAttribute("fileAnticipator");
    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);
    // node level collection
    File nodeDir = CollectorTestUtils.anticipatePath(anticipator, snmpRrdDirectory, "1");
    File documentCountRrdFile = new File(nodeDir, CollectorTestUtils.rrd(m_rrdStrategy, "documentCount"));
    File someNumberRrdFile = new File(nodeDir, CollectorTestUtils.rrd(m_rrdStrategy, "someNumber"));
    File greatAnswerRrdFile = new File(nodeDir, CollectorTestUtils.rrd(m_rrdStrategy, "greatAnswer"));
    // This is the value of documentCount from the first test page
    // documentCount = Gauge32: 5
    assertEquals("documentCount", Double.valueOf(5.0), m_rrdStrategy.fetchLastValueInRange(documentCountRrdFile.getAbsolutePath(), "documentCount", stepSizeInMillis, rangeSizeInMillis));
    // This is the value of documentType from the first test page
    // someNumber = Gauge32: 17
    assertEquals("documentType", Double.valueOf(17.0), m_rrdStrategy.fetchLastValueInRange(someNumberRrdFile.getAbsolutePath(), "someNumber", stepSizeInMillis, rangeSizeInMillis));
    // This is the value of greatAnswer from the second test page
    //someNumber = Gauge32: 42
    assertEquals("greatAnswer", Double.valueOf(42.0), m_rrdStrategy.fetchLastValueInRange(greatAnswerRrdFile.getAbsolutePath(), "greatAnswer", stepSizeInMillis, rangeSizeInMillis));
}
Also used : File(java.io.File) FileAnticipator(org.opennms.test.FileAnticipator)

Aggregations

FileAnticipator (org.opennms.test.FileAnticipator)24 Before (org.junit.Before)15 File (java.io.File)7 JRobinRrdStrategy (org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy)6 FilterDao (org.opennms.netmgt.filter.api.FilterDao)4 ArrayList (java.util.ArrayList)3 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)3 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)3 EasyMockUtils (org.opennms.test.mock.EasyMockUtils)3 FileSystemResource (org.springframework.core.io.FileSystemResource)3 FileWriter (java.io.FileWriter)2 InputStream (java.io.InputStream)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 PollOutagesConfigFactory (org.opennms.netmgt.config.PollOutagesConfigFactory)2 ResourceTypesDao (org.opennms.netmgt.config.api.ResourceTypesDao)2 LocationMonitorDao (org.opennms.netmgt.dao.api.LocationMonitorDao)2 NodeDao (org.opennms.netmgt.dao.api.NodeDao)2 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)2