From 4a90bd2317a24efa198fe48ccddf7f2f3c56b2f4 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 31 May 2017 13:24:03 -0400 Subject: [PATCH] Test: be more careful while flushing We don't actually want to flush all the indices in the full cluster restart tests. Never. *Sometimes* we want to flush certain indices though. --- .../upgrades/FullClusterRestartIT.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java b/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java index 9c458d5c7a6..e845b638403 100644 --- a/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java +++ b/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java @@ -71,6 +71,7 @@ public class FullClusterRestartIT extends ESRestTestCase { } public void testSearch() throws Exception { + String index = getTestName().toLowerCase(Locale.ROOT); if (runningAgainstOldCluster) { XContentBuilder mappingsAndSettings = jsonBuilder(); mappingsAndSettings.startObject(); @@ -99,11 +100,11 @@ public class FullClusterRestartIT extends ESRestTestCase { mappingsAndSettings.endObject(); } mappingsAndSettings.endObject(); - client().performRequest("PUT", "/index", Collections.emptyMap(), + client().performRequest("PUT", "/" + index, Collections.emptyMap(), new StringEntity(mappingsAndSettings.string(), ContentType.APPLICATION_JSON)); int numDocs = randomIntBetween(2000, 3000); - indexRandomDocuments("index", numDocs, true, i -> { + indexRandomDocuments(index, numDocs, true, i -> { return JsonXContent.contentBuilder().startObject() .field("string", randomAlphaOfLength(10)) .field("int", randomInt(100)) @@ -114,21 +115,20 @@ public class FullClusterRestartIT extends ESRestTestCase { // TODO a binary field .endObject(); }); - client().performRequest("POST", "/_flush"); } - assertBasicSearchWorks(); + assertBasicSearchWorks(index); } - void assertBasicSearchWorks() throws IOException { + void assertBasicSearchWorks(String index) throws IOException { logger.info("--> testing basic search"); - Map response = toMap(client().performRequest("GET", "/index/_search")); + Map response = toMap(client().performRequest("GET", "/" + index + "/_search")); assertNoFailures(response); int numDocs1 = (int) XContentMapValues.extractValue("hits.total", response); logger.info("Found {} in old index", numDocs1); logger.info("--> testing basic search with sort"); String searchRequestBody = "{ \"sort\": [{ \"int\" : \"asc\" }]}"; - response = toMap(client().performRequest("GET", "/index/_search", Collections.emptyMap(), + response = toMap(client().performRequest("GET", "/" + index + "/_search", Collections.emptyMap(), new StringEntity(searchRequestBody, ContentType.APPLICATION_JSON))); assertNoFailures(response); int numDocs2 = (int) XContentMapValues.extractValue("hits.total", response); @@ -136,14 +136,14 @@ public class FullClusterRestartIT extends ESRestTestCase { logger.info("--> testing exists filter"); searchRequestBody = "{ \"query\": { \"exists\" : {\"field\": \"string\"} }}"; - response = toMap(client().performRequest("GET", "/index/_search", Collections.emptyMap(), + response = toMap(client().performRequest("GET", "/" + index + "/_search", Collections.emptyMap(), new StringEntity(searchRequestBody, ContentType.APPLICATION_JSON))); assertNoFailures(response); numDocs2 = (int) XContentMapValues.extractValue("hits.total", response); assertEquals(numDocs1, numDocs2); searchRequestBody = "{ \"query\": { \"exists\" : {\"field\": \"field.with.dots\"} }}"; - response = toMap(client().performRequest("GET", "/index/_search", Collections.emptyMap(), + response = toMap(client().performRequest("GET", "/" + index + "/_search", Collections.emptyMap(), new StringEntity(searchRequestBody, ContentType.APPLICATION_JSON))); assertNoFailures(response); numDocs2 = (int) XContentMapValues.extractValue("hits.total", response); @@ -236,13 +236,16 @@ public class FullClusterRestartIT extends ESRestTestCase { private void indexRandomDocuments(String index, int count, boolean flushAllowed, CheckedFunction docSupplier) throws IOException { for (int i = 0; i < count; i++) { + logger.debug("Indexing document [{}]", i); client().performRequest("POST", "/" + index + "/doc/" + i, emptyMap(), new StringEntity(docSupplier.apply(i).string(), ContentType.APPLICATION_JSON)); if (rarely()) { - client().performRequest("POST", "/_refresh"); + logger.info("Refreshing [{}]", index); + client().performRequest("POST", "/" + index + "/_refresh"); } if (flushAllowed && rarely()) { - client().performRequest("POST", "/_flush"); + logger.info("Flushing [{}]", index); + client().performRequest("POST", "/" + index + "/_flush"); } } }