From 3745305ffb785a331843e4bb94878efcb99c051f Mon Sep 17 00:00:00 2001 From: javanna Date: Mon, 30 May 2016 10:07:34 +0200 Subject: [PATCH] [TEST] be more specific around http method used for sniffing --- .../client/sniff/HostsSnifferTests.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/client-sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java b/client-sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java index e2b7a6d7c10..9d9c054fd06 100644 --- a/client-sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java +++ b/client-sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java @@ -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,18 +124,19 @@ public class HostsSnifferTests extends LuceneTestCase { final Dispatcher dispatcher = new Dispatcher() { @Override public MockResponse dispatch(RecordedRequest request) throws InterruptedException { - String decodedUrl; - try { - decodedUrl = URLDecoder.decode(request.getPath(), StandardCharsets.UTF_8.name()); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - 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); + if (request.getMethod().equals(HttpGet.METHOD_NAME)) { + String decodedUrl; + try { + decodedUrl = URLDecoder.decode(request.getPath(), StandardCharsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + String sniffUrl = "/_nodes/http?timeout=" + sniffTimeout + "ms"; + if (sniffUrl.equals(decodedUrl)) { + return new MockResponse().setBody(sniffResponse.nodesInfoBody).setResponseCode(sniffResponse.nodesInfoResponseCode); + } } + return new MockResponse().setResponseCode(404); } }; server.setDispatcher(dispatcher);