Search in sources :

Example 21 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project opennms by OpenNMS.

the class HttpMonitorIT method callTestBasicAuthenticationWithHttps.

public void callTestBasicAuthenticationWithHttps(boolean preferIPv6) throws UnknownHostException {
    if (m_runTests == false)
        return;
    Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    PollStatus status = null;
    ServiceMonitor monitor = new HttpsMonitor();
    MonitoredService svc = MonitorTestUtils.getMonitoredService(1, "localhost", DnsUtils.resolveHostname("localhost", preferIPv6), "HTTPS");
    final int port = JUnitHttpServerExecutionListener.getPort();
    if (port > 0) {
        m.put("port", String.valueOf(port));
    } else {
        throw new IllegalStateException("Unable to determine what port the HTTP server started on!");
    }
    m.put("retry", "1");
    m.put("timeout", "500");
    m.put("response", "100-302");
    m.put("verbose", "true");
    m.put("host-name", "localhost");
    m.put("url", "/index.html");
    status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
    assertEquals("HTTP response value: 401. Expecting: 100-302./Ports: " + port, status.getReason());
    m.put("basic-authentication", "admin:istrator");
    status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
    assertNull(status.getReason());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) PollStatus(org.opennms.netmgt.poller.PollStatus) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService)

Example 22 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project opennms by OpenNMS.

the class HttpMonitorIT method callTestTimeout.

public void callTestTimeout(boolean preferIPv6) throws UnknownHostException {
    if (m_runTests == false)
        return;
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final ServiceMonitor monitor = new HttpMonitor();
    // We need a routable but unreachable address in order to simulate a timeout
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(3, preferIPv6 ? InetAddressUtils.UNPINGABLE_ADDRESS_IPV6 : InetAddressUtils.UNPINGABLE_ADDRESS, "HTTP");
    m.put("port", "12345");
    m.put("retry", "1");
    m.put("timeout", "500");
    m.put("response", "100-199");
    final PollStatus status = monitor.poll(svc, m);
    final String reason = status.getReason();
    MockUtil.println("Reason: " + reason);
    assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
    assertNotNull(reason);
    assertTrue(reason + "should be 'HTTP connection timeout', 'No route to host', or 'Network is unreachable'", reason.contains("HTTP connection timeout") || reason.contains("No route to host") || reason.contains("Network is unreachable"));
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService)

Example 23 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project opennms by OpenNMS.

the class DnsMonitorIT method testNotFoundWithCustomRcode.

@Test
public // type not found is still considered a valid response with the default response codes
void testNotFoundWithCustomRcode() throws UnknownHostException {
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final ServiceMonitor monitor = new DnsMonitor();
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, addr("127.0.0.1"), "DNS");
    m.put("port", "9153");
    m.put("retry", "2");
    m.put("timeout", "5000");
    m.put("lookup", "bogus.example.com");
    m.put("fatal-response-codes", "3");
    final PollStatus status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test)

Example 24 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project opennms by OpenNMS.

the class DnsMonitorIT method testTooFewAnswers.

@Test
public void testTooFewAnswers() throws UnknownHostException {
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final ServiceMonitor monitor = new DnsMonitor();
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, addr("127.0.0.1"), "DNS");
    m.put("port", "9153");
    m.put("retry", "1");
    m.put("timeout", "3000");
    m.put("lookup", "example.empty");
    m.put("min-answers", "1");
    final PollStatus status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test)

Example 25 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project opennms by OpenNMS.

the class DnsMonitorIT method testUnrecoverable.

@Test
public void testUnrecoverable() throws UnknownHostException {
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final ServiceMonitor monitor = new DnsMonitor();
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, addr("192.168.1.120"), "DNS");
    m.put("port", "9000");
    m.put("retry", "2");
    m.put("timeout", "500");
    final PollStatus status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test)

Aggregations

ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)183 Test (org.junit.Test)66 PollStatus (org.opennms.netmgt.poller.PollStatus)32 MonitoredService (org.opennms.netmgt.poller.MonitoredService)31 Map (java.util.Map)30 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)25 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)23 HashMap (java.util.HashMap)21 DeviceTwinMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage)17 NavigableMap (java.util.NavigableMap)14 Set (java.util.Set)12 Iterator (java.util.Iterator)11 NavigableSet (java.util.NavigableSet)11 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)11 IOException (java.io.IOException)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 ArrayList (java.util.ArrayList)9 BitSet (java.util.BitSet)9 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)8 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)8