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