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();
}
}
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));
}
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));
}
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());
}
Aggregations