Search in sources :

Example 1 with DistPollerDao

use of org.opennms.netmgt.dao.api.DistPollerDao in project opennms by OpenNMS.

the class SyslogdReceiverCamelNettyIT method testParallelismAndQueueing.

@Test(timeout = 3 * 60 * 1000)
public void testParallelismAndQueueing() throws UnknownHostException, InterruptedException, ExecutionException {
    final int NUM_GENERATORS = 3;
    final double MESSAGE_RATE_PER_GENERATOR = 1000.0;
    final int NUM_CONSUMER_THREADS = 8;
    final int MESSAGE_QUEUE_SIZE = 529;
    ThreadLockingDispatcherFactory<SyslogConnection> threadLockingDispatcherFactory = new ThreadLockingDispatcherFactory<>();
    ThreadLockingSyncDispatcher<SyslogConnection> syncDispatcher = threadLockingDispatcherFactory.getThreadLockingSyncDispatcher();
    CompletableFuture<Integer> future = syncDispatcher.waitForThreads(NUM_CONSUMER_THREADS);
    SyslogdConfig syslogdConfig = mock(SyslogdConfig.class);
    when(syslogdConfig.getSyslogPort()).thenReturn(SyslogClient.PORT);
    when(syslogdConfig.getNumThreads()).thenReturn(NUM_CONSUMER_THREADS);
    when(syslogdConfig.getQueueSize()).thenReturn(MESSAGE_QUEUE_SIZE);
    DistPollerDao distPollerDao = mock(DistPollerDao.class, Mockito.RETURNS_DEEP_STUBS);
    when(distPollerDao.whoami().getId()).thenReturn("");
    when(distPollerDao.whoami().getLocation()).thenReturn("");
    SyslogReceiverCamelNettyImpl syslogReceiver = new SyslogReceiverCamelNettyImpl(syslogdConfig);
    syslogReceiver.setMessageDispatcherFactory(threadLockingDispatcherFactory);
    syslogReceiver.setDistPollerDao(distPollerDao);
    syslogReceiver.run();
    // Fire up the syslog generators
    List<SyslogGenerator> generators = new ArrayList<>(NUM_GENERATORS);
    for (int k = 0; k < NUM_GENERATORS; k++) {
        SyslogGenerator generator = new SyslogGenerator(addr("127.0.0.1"), k, MESSAGE_RATE_PER_GENERATOR);
        generator.start();
        generators.add(generator);
    }
    // Wait until we have NUM_CONSUMER_THREADS locked
    future.get();
    // Now all of the threads are locked, and the queue is full
    // Let's continue generating traffic for a few seconds
    Thread.sleep(SECONDS.toMillis(10));
    // Verify that there aren't more than NUM_CONSUMER_THREADS waiting
    assertEquals(0, syncDispatcher.getNumExtraThreadsWaiting());
    // Release the producer threads
    syncDispatcher.release();
    // Stop the receiver
    syslogReceiver.stop();
    // Stop the generators
    for (int k = 0; k < NUM_GENERATORS; k++) {
        generators.get(k).stop();
    }
}
Also used : DistPollerDao(org.opennms.netmgt.dao.api.DistPollerDao) ArrayList(java.util.ArrayList) SyslogdConfig(org.opennms.netmgt.config.SyslogdConfig) ThreadLockingDispatcherFactory(org.opennms.core.ipc.sink.common.ThreadLockingDispatcherFactory) SyslogConnection(org.opennms.netmgt.syslogd.api.SyslogConnection) Test(org.junit.Test)

Example 2 with DistPollerDao

use of org.opennms.netmgt.dao.api.DistPollerDao in project opennms by OpenNMS.

the class TrapdConfigReloadIT method addServicesOnStartup.

@Override
protected void addServicesOnStartup(Map<String, KeyValueHolder<Object, Dictionary>> services) {
    final RestClient client;
    try {
        client = mock(RestClient.class);
        when(client.getSnmpV3Users()).thenReturn("<?xml version='1.0'?>" + "<trapd-configuration xmlns='http://xmlns.opennms.org/xsd/config/trapd' snmp-trap-address='127.0.0.1' snmp-trap-port='10500' new-suspect-on-trap='true'>" + "     <snmpv3-user security-name='opennms' security-level='0' auth-protocol='MD5' auth-passphrase='0p3nNMSv3' privacy-protocol='DES' privacy-passphrase='0p3nNMSv3' />" + "</trapd-configuration>");
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    // add mocked services to osgi mocked container (Felix Connect)
    services.put(RestClient.class.getName(), asService(client, null, null));
    services.put(MessageConsumerManager.class.getName(), asService(new MockMessageConsumerManager(), null, null));
    services.put(MessageDispatcherFactory.class.getName(), asService(new MockMessageDispatcherFactory<>(), null, null));
    services.put(DistPollerDao.class.getName(), asService(distPollerDao, null, null));
}
Also used : DistPollerDao(org.opennms.netmgt.dao.api.DistPollerDao) MockMessageDispatcherFactory(org.opennms.core.ipc.sink.mock.MockMessageDispatcherFactory) RestClient(org.opennms.minion.core.api.RestClient) MockMessageConsumerManager(org.opennms.core.ipc.sink.mock.MockMessageConsumerManager) MessageDispatcherFactory(org.opennms.core.ipc.sink.api.MessageDispatcherFactory) MockMessageDispatcherFactory(org.opennms.core.ipc.sink.mock.MockMessageDispatcherFactory) MockMessageConsumerManager(org.opennms.core.ipc.sink.mock.MockMessageConsumerManager) MessageConsumerManager(org.opennms.core.ipc.sink.api.MessageConsumerManager)

Example 3 with DistPollerDao

use of org.opennms.netmgt.dao.api.DistPollerDao in project opennms by OpenNMS.

the class TrapdSinkPatternWiringIT method addServicesOnStartup.

@Override
protected void addServicesOnStartup(Map<String, KeyValueHolder<Object, Dictionary>> services) {
    final MessageDispatcherFactory mockMessageDispatcherFactory = mock(MessageDispatcherFactory.class);
    when(mockMessageDispatcherFactory.createAsyncDispatcher(Mockito.any(TrapSinkModule.class))).thenAnswer(invocation -> {
        messageProcessedLatch.countDown();
        return mock(MessageProducer.class);
    });
    // add mocked services to osgi mocked container (Felix Connect)
    services.put(MessageConsumerManager.class.getName(), asService(new MockMessageConsumerManager(), null, null));
    services.put(MessageDispatcherFactory.class.getName(), asService(mockMessageDispatcherFactory, null, null));
    services.put(RestClient.class.getName(), asService(mock(RestClient.class), null, null));
    services.put(DistPollerDao.class.getName(), asService(distPollerDao, null, null));
}
Also used : DistPollerDao(org.opennms.netmgt.dao.api.DistPollerDao) RestClient(org.opennms.minion.core.api.RestClient) MockMessageConsumerManager(org.opennms.core.ipc.sink.mock.MockMessageConsumerManager) MessageDispatcherFactory(org.opennms.core.ipc.sink.api.MessageDispatcherFactory) MessageConsumerManager(org.opennms.core.ipc.sink.api.MessageConsumerManager) MockMessageConsumerManager(org.opennms.core.ipc.sink.mock.MockMessageConsumerManager)

Example 4 with DistPollerDao

use of org.opennms.netmgt.dao.api.DistPollerDao in project opennms by OpenNMS.

the class BlueprintDistPollerDaoMinionIT method testDistPollerDao.

@Test
public void testDistPollerDao() throws Exception {
    DistPollerDao dao = getOsgiService(DistPollerDao.class);
    assertEquals(1, dao.countAll());
    // Test get()
    OnmsDistPoller poller = dao.get(DistPollerDao.DEFAULT_DIST_POLLER_ID);
    assertNotNull(poller);
    assertEquals(DistPollerDao.DEFAULT_DIST_POLLER_ID, poller.getId());
    assertEquals(DistPollerDao.DEFAULT_DIST_POLLER_ID, poller.getLabel());
    assertEquals(LOCATION, poller.getLocation());
    assertEquals(OnmsMonitoringSystem.TYPE_MINION, poller.getType());
    // Test whoami()
    poller = dao.whoami();
    assertNotNull(poller);
    assertEquals(DistPollerDao.DEFAULT_DIST_POLLER_ID, poller.getId());
    assertEquals(DistPollerDao.DEFAULT_DIST_POLLER_ID, poller.getLabel());
    assertEquals(LOCATION, poller.getLocation());
    assertEquals(OnmsMonitoringSystem.TYPE_MINION, poller.getType());
}
Also used : DistPollerDao(org.opennms.netmgt.dao.api.DistPollerDao) OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) Test(org.junit.Test) CamelBlueprintTest(org.opennms.core.test.camel.CamelBlueprintTest)

Aggregations

DistPollerDao (org.opennms.netmgt.dao.api.DistPollerDao)4 Test (org.junit.Test)2 MessageConsumerManager (org.opennms.core.ipc.sink.api.MessageConsumerManager)2 MessageDispatcherFactory (org.opennms.core.ipc.sink.api.MessageDispatcherFactory)2 MockMessageConsumerManager (org.opennms.core.ipc.sink.mock.MockMessageConsumerManager)2 RestClient (org.opennms.minion.core.api.RestClient)2 ArrayList (java.util.ArrayList)1 ThreadLockingDispatcherFactory (org.opennms.core.ipc.sink.common.ThreadLockingDispatcherFactory)1 MockMessageDispatcherFactory (org.opennms.core.ipc.sink.mock.MockMessageDispatcherFactory)1 CamelBlueprintTest (org.opennms.core.test.camel.CamelBlueprintTest)1 SyslogdConfig (org.opennms.netmgt.config.SyslogdConfig)1 OnmsDistPoller (org.opennms.netmgt.model.OnmsDistPoller)1 SyslogConnection (org.opennms.netmgt.syslogd.api.SyslogConnection)1