@Test public void shouldPingServer() throws IOException { final HostnamePort hostURL = new HostnamePort( hostname, server.getLocalPort() ); final Map<String,String> udcFields = new HashMap<>(); udcFields.put( ID, EXPECTED_STORE_ID ); udcFields.put( UdcConstants.VERSION, EXPECTED_KERNEL_VERSION ); Pinger p = new Pinger( hostURL, new TestUdcCollector( udcFields ) ); p.ping(); Map<String,String> actualQueryMap = handler.getQueryMap(); assertThat( actualQueryMap, notNullValue() ); assertThat( actualQueryMap.get( ID ), is( EXPECTED_STORE_ID ) ); }
@Test public void shouldIncludePingCountInURI() throws IOException { final int EXPECTED_PING_COUNT = 16; final HostnamePort hostURL = new HostnamePort( hostname, server.getLocalPort() ); final Map<String,String> udcFields = new HashMap<>(); Pinger p = new Pinger( hostURL, new TestUdcCollector( udcFields ) ); for ( int i = 0; i < EXPECTED_PING_COUNT; i++ ) { p.ping(); } assertThat( p.getPingCount(), is( equalTo( EXPECTED_PING_COUNT ) ) ); Map<String,String> actualQueryMap = handler.getQueryMap(); assertThat( actualQueryMap.get( UdcConstants.PING ), is( Integer.toString( EXPECTED_PING_COUNT ) ) ); }
@Test public void normalPingSequenceShouldBeOneThenTwoThenThreeEtc() throws Exception { int[] expectedSequence = {1, 2, 3, 4}; final HostnamePort hostURL = new HostnamePort( hostname, server.getLocalPort() ); final Map<String,String> udcFields = new HashMap<>(); Pinger p = new Pinger( hostURL, new TestUdcCollector( udcFields ) ); for ( int s : expectedSequence ) { p.ping(); int count = Integer.parseInt( handler.getQueryMap().get( UdcConstants.PING ) ); assertEquals( s, count ); } }
public String getUrl() { try { if (server==null) { // guess the URL, in those cases where the server is not started yet return new URL("http", getLocalAddress().getHostAddress(), basePort, "").toExternalForm(); } return new URL("http", server.getInetAddress().getHostAddress(), server.getLocalPort(), "").toExternalForm(); } catch (MalformedURLException e) { throw Exceptions.propagate(e); } }
@Override public void close() throws IOException { if (original != null) { LOGGER.log(Level.INFO, () -> "stopping MockUpdateCenter on http://" + server.getInetAddress().getHostAddress() + ":" + server.getLocalPort() + "/update-center.json"); HttpServer s = server; server = null; // make sure this.server holds a server that is guaranteed to be up s.shutdown(5, TimeUnit.SECONDS); /* TODO only if RemoteController etc.: injector.getInstance(Jenkins.class).runScript("DownloadService.signatureCheck = true; Jenkins.instance.updateCenter.sites.replaceBy([new UpdateSite(UpdateCenter.ID_DEFAULT, '%s')])", original); */ original = null; } } }
private String getLocalServerHostAndPort() { return new StringBuilder() .append(localServer.getInetAddress().getHostName()) .append(":") .append(localServer.getLocalPort()) .toString(); }
String override = "http://" + server.getInetAddress().getHostAddress() + ":" + server.getLocalPort() + "/update-center.json"; LOGGER.log(Level.INFO, "replacing update site {0} with {1}", new Object[] {original, override}); jenkins.runScript("DownloadService.signatureCheck = false; Jenkins.instance.updateCenter.sites.replaceBy([new UpdateSite(UpdateCenter.ID_DEFAULT, '%s')])", override);