Search in sources :

Example 1 with PersisterFactory

use of org.opennms.netmgt.collection.api.PersisterFactory in project opennms by OpenNMS.

the class PollableServiceConfigTest method returnsUnknownOnRequestTimedOutException.

/**
     * Verifies that <b>PollStatus.unknown()</b> is returned when the
     * {@link LocationAwarePollerClient} fails with a {@link RequestTimedOutException}.
     *
     * This can happen when no Minions at the given location are available to process
     * the request, or the request was not completed in time, in which case we cannot
     * ascertain that the service is UP or DOWN.
     */
@Test
public void returnsUnknownOnRequestTimedOutException() throws Exception {
    // Create a future that fails with a RequestTimedOutException
    CompletableFuture<PollerResponse> future = new CompletableFuture<>();
    future.completeExceptionally(new RequestTimedOutException(new Exception("Test")));
    // Now mock the client to always return the future we created above
    LocationAwarePollerClient client = mock(LocationAwarePollerClient.class, Mockito.RETURNS_DEEP_STUBS);
    Mockito.when(client.poll().withService(any()).withMonitor(any()).withTimeToLive(any()).withAttributes(any()).withAdaptor(any()).withAdaptor(any()).execute()).thenReturn(future);
    // Mock all of the required objects required to successfully initialize the PollableServiceConfig
    PollableService pollableSvc = mock(PollableService.class);
    when(pollableSvc.getSvcName()).thenReturn("SVC");
    Service configuredSvc = new Service();
    configuredSvc.setName("SVC");
    Package pkg = mock(Package.class);
    when(pkg.getServices()).thenReturn(Lists.newArrayList(configuredSvc));
    PollerConfig pollerConfig = mock(PollerConfig.class);
    PollOutagesConfig pollOutagesConfig = mock(PollOutagesConfig.class);
    Timer timer = mock(Timer.class);
    PersisterFactory persisterFactory = mock(PersisterFactory.class);
    ResourceStorageDao resourceStorageDao = mock(ResourceStorageDao.class);
    final PollableServiceConfig psc = new PollableServiceConfig(pollableSvc, pollerConfig, pollOutagesConfig, pkg, timer, persisterFactory, resourceStorageDao, client);
    // Trigger the poll
    PollStatus pollStatus = psc.poll();
    // Verify
    assertThat(pollStatus.isUnknown(), is(true));
}
Also used : RequestTimedOutException(org.opennms.core.rpc.api.RequestTimedOutException) LocationAwarePollerClient(org.opennms.netmgt.poller.LocationAwarePollerClient) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) PollStatus(org.opennms.netmgt.poller.PollStatus) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) PersisterFactory(org.opennms.netmgt.collection.api.PersisterFactory) PollerConfig(org.opennms.netmgt.config.PollerConfig) Service(org.opennms.netmgt.config.poller.Service) RequestTimedOutException(org.opennms.core.rpc.api.RequestTimedOutException) CompletableFuture(java.util.concurrent.CompletableFuture) Timer(org.opennms.netmgt.scheduler.Timer) Package(org.opennms.netmgt.config.poller.Package) PollerResponse(org.opennms.netmgt.poller.PollerResponse) PollOutagesConfig(org.opennms.netmgt.config.PollOutagesConfig) Test(org.junit.Test)

Example 2 with PersisterFactory

use of org.opennms.netmgt.collection.api.PersisterFactory in project opennms by OpenNMS.

the class PollableServiceConfigTest method testPollableServiceConfig.

@Test
public void testPollableServiceConfig() throws Exception {
    final FilterDao fd = mock(FilterDao.class);
    FilterDaoFactory.setInstance(fd);
    InputStream is = new FileInputStream(new File("src/test/resources/etc/psm-poller-configuration.xml"));
    PollerConfigFactory factory = new PollerConfigFactory(0, is, "localhost", false);
    PollerConfigFactory.setInstance(factory);
    IOUtils.closeQuietly(is);
    PersisterFactory persisterFactory = new MockPersisterFactory();
    ResourceStorageDao resourceStorageDao = new FilesystemResourceStorageDao();
    final PollContext context = mock(PollContext.class);
    final PollableNetwork network = new PollableNetwork(context);
    final PollableNode node = network.createNodeIfNecessary(1, "foo", null);
    final PollableInterface iface = new PollableInterface(node, InetAddressUtils.addr("127.0.0.1"));
    final PollableService svc = new PollableService(iface, "MQ_API_DirectRte_v2");
    final PollOutagesConfig pollOutagesConfig = mock(PollOutagesConfig.class);
    final Package pkg = factory.getPackage("MapQuest");
    final Timer timer = mock(Timer.class);
    final PollableServiceConfig psc = new PollableServiceConfig(svc, factory, pollOutagesConfig, pkg, timer, persisterFactory, resourceStorageDao, m_locationAwarePollerClient);
    PollStatus pollStatus = psc.poll();
    assertThat(pollStatus.getReason(), not(containsString("Unexpected exception")));
}
Also used : FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) PollStatus(org.opennms.netmgt.poller.PollStatus) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) PersisterFactory(org.opennms.netmgt.collection.api.PersisterFactory) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) FileInputStream(java.io.FileInputStream) FilterDao(org.opennms.netmgt.filter.api.FilterDao) PollerConfigFactory(org.opennms.netmgt.config.PollerConfigFactory) Timer(org.opennms.netmgt.scheduler.Timer) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) Package(org.opennms.netmgt.config.poller.Package) File(java.io.File) PollOutagesConfig(org.opennms.netmgt.config.PollOutagesConfig) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 PersisterFactory (org.opennms.netmgt.collection.api.PersisterFactory)2 PollOutagesConfig (org.opennms.netmgt.config.PollOutagesConfig)2 Package (org.opennms.netmgt.config.poller.Package)2 ResourceStorageDao (org.opennms.netmgt.dao.api.ResourceStorageDao)2 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)2 MockPersisterFactory (org.opennms.netmgt.mock.MockPersisterFactory)2 PollStatus (org.opennms.netmgt.poller.PollStatus)2 Timer (org.opennms.netmgt.scheduler.Timer)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 RequestTimedOutException (org.opennms.core.rpc.api.RequestTimedOutException)1 PollerConfig (org.opennms.netmgt.config.PollerConfig)1 PollerConfigFactory (org.opennms.netmgt.config.PollerConfigFactory)1 Service (org.opennms.netmgt.config.poller.Service)1 FilterDao (org.opennms.netmgt.filter.api.FilterDao)1 LocationAwarePollerClient (org.opennms.netmgt.poller.LocationAwarePollerClient)1 PollerResponse (org.opennms.netmgt.poller.PollerResponse)1