/** * Two hosts are equals if they are equals and their parents too * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (!(obj instanceof HostStarter)) { return false; } HostStarter other = (HostStarter) obj; boolean parentEquals; if (getParent() != null) { parentEquals = getParent().equals(other.getParent()); } else { parentEquals = other.getParent() == null; } return host.equals(other.getHost()) && parentEquals; }
public void collectAll() { log(Level.DEBUG, "Starting collect"); Timer timer = (Timer) getParent(); long start = System.currentTimeMillis(); startCollect(); String oldThreadName = Thread.currentThread().getName(); for(Probe<?, ?> probe: allProbes) { if(!isCollectRunning()) break; long duration = (System.currentTimeMillis() - start) / 1000; if(duration > (probe.getStep() / 2)) { log(Level.ERROR, "Collect too slow: %ds for timer %s", duration, timer); break; } log(Level.TRACE, "Starting collect for %s", probe); log(Level.DEBUG, "Collect all stats for host " + host.getName()); setRunningname(oldThreadName + "/" + probe.getName()); probe.collect(); setRunningname(oldThreadName + ":finished"); } stopCollect(); long end = System.currentTimeMillis(); float elapsed = (end - start) / 1000f; log(Level.DEBUG, "Collect time for %s: %fs", host.getName(), elapsed); }
@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(); }
@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(); }