/** * Asserts that gets back any "valid" response - i.e. not an exception. This could be an unauthorized, * a redirect, a 404, or anything else that implies there is web-server listening on that port. */ public static void assertUrlReachable(String url) { try { getHttpStatusCode(url); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException("Interrupted for "+url+" (in assertion that is reachable)", e); } catch (Exception e) { throw new IllegalStateException("Server at "+url+" failed to respond (in assertion that is reachable): "+e, e); } }
public static void assertHttpStatusCodeEquals(String url, int... acceptableReturnCodes) { List<Integer> acceptableCodes = Lists.newArrayList(); for (int code : acceptableReturnCodes) { acceptableCodes.add(code); } try { int actualCode = getHttpStatusCode(url); assertTrue(acceptableCodes.contains(actualCode), "code="+actualCode+"; expected="+acceptableCodes+"; url="+url); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException("Interrupted for "+url+" (in assertion that result code is "+acceptableCodes+")", e); } catch (Exception e) { throw new IllegalStateException("Server at "+url+" failed to respond (in assertion that result code is "+acceptableCodes+"): "+e, e); } }
public static void assertUrlUnreachable(String url) { try { int statusCode = getHttpStatusCode(url); fail("Expected url "+url+" unreachable, but got status code "+statusCode); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException("Interrupted for "+url+" (in assertion that unreachable)", e); } catch (Exception e) { IOException cause = Exceptions.getFirstThrowableOfType(e, IOException.class); if (cause != null) { // success; clean shutdown transitioning from 400 to error } else { Throwables.propagate(e); } } }
try { if (preAttempt()) { int code = HttpTestUtils.getHttpStatusCode(url); lastTime.set(System.currentTimeMillis() - startTime); lastStatus.set(code);
@Override public void run() { long lastReportTime = System.currentTimeMillis(); int num = 0; while (true) { try { num++; int code = HttpTestUtils.getHttpStatusCode(nginxUrl); if (code!=200) log.info("NGINX GOT: "+code); else log.debug("NGINX GOT: "+code); if (System.currentTimeMillis()>=lastReportTime+1000) { log.info("NGINX DID "+num+" requests in last "+(System.currentTimeMillis()-lastReportTime)+"ms"); num=0; lastReportTime = System.currentTimeMillis(); } } catch (Exception e) { log.info("NGINX GOT: "+e); } } }}); t.start();
@Override public void run() { long lastReportTime = System.currentTimeMillis(); int num = 0; while (true) { try { num++; int code = HttpTestUtils.getHttpStatusCode(jbossUrl); if (code!=200) log.info("JBOSS GOT: "+code); else log.debug("JBOSS GOT: "+code); if (System.currentTimeMillis()>=1000+lastReportTime) { log.info("JBOSS DID "+num+" requests in last "+(System.currentTimeMillis()-lastReportTime)+"ms"); num=0; lastReportTime = System.currentTimeMillis(); } } catch (Exception e) { log.info("JBOSS GOT: "+e); } } }}); t2.start();