[TEST] be more specific around http method used for sniffing

This commit is contained in:
javanna 2016-05-30 10:07:34 +02:00 committed by Luca Cavanna
parent 044a97c740
commit 3745305ffb
1 changed files with 13 additions and 11 deletions

View File

@ -29,6 +29,7 @@ import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.apache.http.HttpHost;
import org.apache.http.client.methods.HttpGet;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.client.ElasticsearchResponse;
import org.elasticsearch.client.ElasticsearchResponseException;
@ -123,6 +124,7 @@ public class HostsSnifferTests extends LuceneTestCase {
final Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
if (request.getMethod().equals(HttpGet.METHOD_NAME)) {
String decodedUrl;
try {
decodedUrl = URLDecoder.decode(request.getPath(), StandardCharsets.UTF_8.name());
@ -132,10 +134,10 @@ public class HostsSnifferTests extends LuceneTestCase {
String sniffUrl = "/_nodes/http?timeout=" + sniffTimeout + "ms";
if (sniffUrl.equals(decodedUrl)) {
return new MockResponse().setBody(sniffResponse.nodesInfoBody).setResponseCode(sniffResponse.nodesInfoResponseCode);
} else {
return new MockResponse().setResponseCode(404);
}
}
return new MockResponse().setResponseCode(404);
}
};
server.setDispatcher(dispatcher);
return server;