use of org.opennms.netmgt.config.poller.Service 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));
}
use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.
the class PollerConfigWithPSMIT method testPSM.
@Test
public void testPSM() throws Exception {
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);
ServiceMonitor monitor = PollerConfigFactory.getInstance().getServiceMonitor("MQ_API_DirectRte_v2");
Assert.assertNotNull(monitor);
Package pkg = PollerConfigFactory.getInstance().getPackage("MapQuest");
Assert.assertNotNull(pkg);
Service svc = PollerConfigFactory.getInstance().getServiceInPackage("MQ_API_DirectRte_v2", pkg);
Assert.assertNotNull(svc);
Map<String, Object> parameters = new HashMap<String, Object>();
for (Parameter p : svc.getParameters()) {
parameters.put(p.getKey(), p.getValue() == null ? p.getAnyObject() : p.getValue());
}
PollStatus status = monitor.poll(new MockMonitoredService(1, "www.mapquest.com", InetAddress.getByName("www.mapquest.com"), "MQ_API_DirectRte_v2"), parameters);
Assert.assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
}
use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.
the class DefaultPollerBackEndTest method canConvertServiceParametersToSerializableMap.
/**
* Verifies that the parameter map generated for a given
* service is serializable.
*/
@Test
public void canConvertServiceParametersToSerializableMap() {
Parameter paramWithStringValue = new Parameter();
paramWithStringValue.setKey("a");
paramWithStringValue.setValue("test");
Parameter paramWithNullValue = new Parameter();
paramWithNullValue.setKey("b");
paramWithNullValue.setAnyObject(null);
Parameter paramWithNonSerializableObject = new Parameter();
paramWithNonSerializableObject.setKey("c");
// This can be any object, provided that it does not implement the Serializable interface
paramWithNonSerializableObject.setAnyObject(new DefaultPollerBackEndTest());
Service svc = new Service();
svc.setParameters(Lists.newArrayList(paramWithStringValue, paramWithNullValue, paramWithNonSerializableObject));
// Expect no exception to be thrown
SerializationUtils.serialize(DefaultPollerBackEnd.getParameterMap(svc));
}
use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.
the class DefaultPollerBackEndTest method getParameterMapMarshallsPageSequenceParameters.
/**
* Verifies that {@link PageSequence} type parameters are marshalled to XML.
*/
@Test
public void getParameterMapMarshallsPageSequenceParameters() {
final PageSequence ps = new PageSequence();
Page page = new Page();
page.setMethod("GET");
page.setHttpVersion("1.1");
page.setScheme("http");
page.setHost("${ipaddr}");
page.setDisableSslVerification("true");
page.setPort(7080);
page.setPath("/Login.do");
page.setSuccessMatch("w00t");
page.setResponseRange("100-399");
ps.addPage(page);
Parameter paramWithPageSequenceValue = new Parameter();
paramWithPageSequenceValue.setKey("psm");
paramWithPageSequenceValue.setAnyObject(ps);
Service svc = new Service();
svc.setParameters(Lists.newArrayList(paramWithPageSequenceValue));
Map<String, Object> params = DefaultPollerBackEnd.getParameterMap(svc);
PageSequence unmarshalledPs = JaxbUtils.unmarshal(PageSequence.class, (String) params.get("psm"));
assertEquals(ps, unmarshalledPs);
}
use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.
the class PollableServiceConfigIT 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));
}
Aggregations