@Test public void instantiate() throws InvocationTargetException { Map<String, String> empty = Collections.emptyMap(); ConnectionInfo ci = new ConnectionInfo(JdbcConnection.class, "jrds.probe.jdbc.JdbcConnection", Collections.emptyList(), empty); HostInfo hi = new HostInfo("localhost"); hi.addConnection(ci); HostStarter hs = new HostStarter(hi); ci.register(hs); Assert.assertEquals("connection not found", "jrds.probe.jdbc.JdbcConnection@localhost", hs.find(JdbcConnection.class).toString()); }
@Test public void testStart() throws Exception { MockHttpServer server = new MockHttpServer(false); server.addResourceHandler(staticFiles); server.start(); HttpClientStarter cnx = new HttpClientStarter(); HostStarter localhost = addConnection(cnx); localhost.find(SSLStarter.class).doStart(); localhost.find(Resolver.class).doStart(); logger.debug("resolver started for localhost:" + localhost.find(Resolver.class).isStarted()); cnx.doStart(); Assert.assertTrue("Apache HttpClient failed to start", cnx.isStarted()); cnx.stop(); server.stop(); }
@Test public void testConnectSSL() throws Exception { MockHttpServer server = new MockHttpServer(true); server.addResourceHandler(staticFiles); server.start(); HttpClientStarter cnx = new HttpClientStarter(); HostStarter localhost = addConnection(cnx); localhost.find(Resolver.class).doStart(); localhost.find(SSLStarter.class).doStart(); cnx.doStart(); TestHttpProbe p = new TestHttpProbe(); p.setMainStore(new RrdDbStoreFactory(), empty); p.setHost(localhost); p.setPort(server.getURI().toURL().getPort()); p.setScheme("https"); p.configure(); p.checkStore(); localhost.addProbe(p); localhost.getParent().startCollect(); Assert.assertTrue(p.find(SSLStarter.class).isStarted()); shouldFail = false; localhost.collectAll(); Assert.assertTrue("Didn't try to collect", p.collected); server.stop(); }
@Test public void testConnectTwice() throws Exception { MockHttpServer server = new MockHttpServer(false); server.addResourceHandler(staticFiles); server.start(); HttpClientStarter cnx = new HttpClientStarter(); HostStarter localhost = addConnection(cnx); localhost.find(Resolver.class).doStart(); cnx.doStart(); TestHttpProbe p = new TestHttpProbe(); p.setMainStore(new RrdDbStoreFactory(), empty); p.setHost(localhost); p.setPort(server.getURI().toURL().getPort()); p.configure(); p.checkStore(); localhost.addProbe(p); localhost.getParent().startCollect(); // Run twice, to detect failure management in the probe localhost.collectAll(); shouldFail = false; Thread.sleep(1500); localhost.collectAll(); Assert.assertTrue("Didn't try to collect", p.collected); server.stop(); }