[TEST] Remove usage of @SuppressForbidden due to sun HttpServer usage, resolve some violations that were hidden by it
This commit is contained in:
parent
432efc75fb
commit
6db90da25e
|
@ -54,6 +54,9 @@ forbiddenApisMain {
|
|||
}
|
||||
|
||||
forbiddenApisTest {
|
||||
//we are excluding jdk-non-portable to allow for com.sun.net.httpserver.* usage
|
||||
//TODO remove this line once https://github.com/policeman-tools/forbidden-apis/issues/103 gets solved
|
||||
bundledSignatures = ['jdk-unsafe', 'jdk-deprecated', 'jdk-system-out']
|
||||
//client does not depend on core, so only jdk signatures should be checked
|
||||
signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')]
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.apache.http.Consts;
|
|||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util.SuppressForbidden;
|
||||
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
|
@ -42,6 +41,7 @@ import org.junit.Before;
|
|||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -57,7 +57,6 @@ import static org.hamcrest.CoreMatchers.containsString;
|
|||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
@IgnoreJRERequirement
|
||||
@SuppressForbidden(reason = "uses sun HttpServer")
|
||||
public class HostsSnifferTests extends LuceneTestCase {
|
||||
|
||||
private int sniffRequestTimeout;
|
||||
|
@ -84,7 +83,7 @@ public class HostsSnifferTests extends LuceneTestCase {
|
|||
}
|
||||
|
||||
public void testSniffNodes() throws IOException, URISyntaxException {
|
||||
HttpHost httpHost = new HttpHost(httpServer.getAddress().getHostName(), httpServer.getAddress().getPort());
|
||||
HttpHost httpHost = new HttpHost(httpServer.getAddress().getHostString(), httpServer.getAddress().getPort());
|
||||
try (RestClient restClient = RestClient.builder(httpHost).build()) {
|
||||
HostsSniffer sniffer = new HostsSniffer(restClient, sniffRequestTimeout, scheme);
|
||||
try {
|
||||
|
@ -114,13 +113,12 @@ public class HostsSnifferTests extends LuceneTestCase {
|
|||
}
|
||||
|
||||
private static HttpServer createHttpServer(final SniffResponse sniffResponse, final int sniffTimeoutMillis) throws IOException {
|
||||
HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0);
|
||||
HttpServer httpServer = HttpServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);
|
||||
httpServer.createContext("/_nodes/http", new ResponseHandler(sniffTimeoutMillis, sniffResponse));
|
||||
return httpServer;
|
||||
}
|
||||
|
||||
@IgnoreJRERequirement
|
||||
@SuppressForbidden(reason = "uses sun HttpServer")
|
||||
private static class ResponseHandler implements HttpHandler {
|
||||
private final int sniffTimeoutMillis;
|
||||
private final SniffResponse sniffResponse;
|
||||
|
|
|
@ -52,6 +52,9 @@ forbiddenApisMain {
|
|||
}
|
||||
|
||||
forbiddenApisTest {
|
||||
//we are excluding jdk-non-portable to allow for com.sun.net.httpserver.* usage
|
||||
//TODO remove this line once https://github.com/policeman-tools/forbidden-apis/issues/103 gets solved
|
||||
bundledSignatures = ['jdk-unsafe', 'jdk-deprecated', 'jdk-system-out']
|
||||
//client does not depend on core, so only jdk signatures should be checked
|
||||
signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')]
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.apache.http.entity.StringEntity;
|
|||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util.SuppressForbidden;
|
||||
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -40,6 +39,7 @@ import org.junit.BeforeClass;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -59,7 +59,6 @@ import static org.hamcrest.CoreMatchers.equalTo;
|
|||
* Works against a real http server, one single host.
|
||||
*/
|
||||
@IgnoreJRERequirement
|
||||
@SuppressForbidden(reason = "uses sun HttpServer")
|
||||
public class RestClientIntegTests extends LuceneTestCase {
|
||||
|
||||
private static HttpServer httpServer;
|
||||
|
@ -68,7 +67,7 @@ public class RestClientIntegTests extends LuceneTestCase {
|
|||
|
||||
@BeforeClass
|
||||
public static void startHttpServer() throws Exception {
|
||||
httpServer = HttpServer.create(new InetSocketAddress(0), 0);
|
||||
httpServer = HttpServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);
|
||||
httpServer.start();
|
||||
//returns a different status code depending on the path
|
||||
for (int statusCode : getAllStatusCodes()) {
|
||||
|
@ -81,7 +80,7 @@ public class RestClientIntegTests extends LuceneTestCase {
|
|||
String headerValue = RandomStrings.randomAsciiOfLengthBetween(random(), 3, 10);
|
||||
defaultHeaders[i] = new BasicHeader(headerName, headerValue);
|
||||
}
|
||||
restClient = RestClient.builder(new HttpHost(httpServer.getAddress().getHostName(), httpServer.getAddress().getPort()))
|
||||
restClient = RestClient.builder(new HttpHost(httpServer.getAddress().getHostString(), httpServer.getAddress().getPort()))
|
||||
.setDefaultHeaders(defaultHeaders).build();
|
||||
}
|
||||
|
||||
|
@ -90,7 +89,6 @@ public class RestClientIntegTests extends LuceneTestCase {
|
|||
}
|
||||
|
||||
@IgnoreJRERequirement
|
||||
@SuppressForbidden(reason = "uses sun HttpServer")
|
||||
private static class ResponseHandler implements HttpHandler {
|
||||
private final int statusCode;
|
||||
|
||||
|
|
Loading…
Reference in New Issue