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.
This commit is contained in:
Nik Everett 2017-05-31 13:24:03 -04:00
parent b5d62ae747
commit 4a90bd2317
1 changed files with 14 additions and 11 deletions

View File

@ -71,6 +71,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
} }
public void testSearch() throws Exception { public void testSearch() throws Exception {
String index = getTestName().toLowerCase(Locale.ROOT);
if (runningAgainstOldCluster) { if (runningAgainstOldCluster) {
XContentBuilder mappingsAndSettings = jsonBuilder(); XContentBuilder mappingsAndSettings = jsonBuilder();
mappingsAndSettings.startObject(); mappingsAndSettings.startObject();
@ -99,11 +100,11 @@ public class FullClusterRestartIT extends ESRestTestCase {
mappingsAndSettings.endObject(); mappingsAndSettings.endObject();
} }
mappingsAndSettings.endObject(); mappingsAndSettings.endObject();
client().performRequest("PUT", "/index", Collections.emptyMap(), client().performRequest("PUT", "/" + index, Collections.emptyMap(),
new StringEntity(mappingsAndSettings.string(), ContentType.APPLICATION_JSON)); new StringEntity(mappingsAndSettings.string(), ContentType.APPLICATION_JSON));
int numDocs = randomIntBetween(2000, 3000); int numDocs = randomIntBetween(2000, 3000);
indexRandomDocuments("index", numDocs, true, i -> { indexRandomDocuments(index, numDocs, true, i -> {
return JsonXContent.contentBuilder().startObject() return JsonXContent.contentBuilder().startObject()
.field("string", randomAlphaOfLength(10)) .field("string", randomAlphaOfLength(10))
.field("int", randomInt(100)) .field("int", randomInt(100))
@ -114,21 +115,20 @@ public class FullClusterRestartIT extends ESRestTestCase {
// TODO a binary field // TODO a binary field
.endObject(); .endObject();
}); });
client().performRequest("POST", "/_flush");
} }
assertBasicSearchWorks(); assertBasicSearchWorks(index);
} }
void assertBasicSearchWorks() throws IOException { void assertBasicSearchWorks(String index) throws IOException {
logger.info("--> testing basic search"); logger.info("--> testing basic search");
Map<String, Object> response = toMap(client().performRequest("GET", "/index/_search")); Map<String, Object> response = toMap(client().performRequest("GET", "/" + index + "/_search"));
assertNoFailures(response); assertNoFailures(response);
int numDocs1 = (int) XContentMapValues.extractValue("hits.total", response); int numDocs1 = (int) XContentMapValues.extractValue("hits.total", response);
logger.info("Found {} in old index", numDocs1); logger.info("Found {} in old index", numDocs1);
logger.info("--> testing basic search with sort"); logger.info("--> testing basic search with sort");
String searchRequestBody = "{ \"sort\": [{ \"int\" : \"asc\" }]}"; 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))); new StringEntity(searchRequestBody, ContentType.APPLICATION_JSON)));
assertNoFailures(response); assertNoFailures(response);
int numDocs2 = (int) XContentMapValues.extractValue("hits.total", response); int numDocs2 = (int) XContentMapValues.extractValue("hits.total", response);
@ -136,14 +136,14 @@ public class FullClusterRestartIT extends ESRestTestCase {
logger.info("--> testing exists filter"); logger.info("--> testing exists filter");
searchRequestBody = "{ \"query\": { \"exists\" : {\"field\": \"string\"} }}"; 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))); new StringEntity(searchRequestBody, ContentType.APPLICATION_JSON)));
assertNoFailures(response); assertNoFailures(response);
numDocs2 = (int) XContentMapValues.extractValue("hits.total", response); numDocs2 = (int) XContentMapValues.extractValue("hits.total", response);
assertEquals(numDocs1, numDocs2); assertEquals(numDocs1, numDocs2);
searchRequestBody = "{ \"query\": { \"exists\" : {\"field\": \"field.with.dots\"} }}"; 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))); new StringEntity(searchRequestBody, ContentType.APPLICATION_JSON)));
assertNoFailures(response); assertNoFailures(response);
numDocs2 = (int) XContentMapValues.extractValue("hits.total", 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, private void indexRandomDocuments(String index, int count, boolean flushAllowed,
CheckedFunction<Integer, XContentBuilder, IOException> docSupplier) throws IOException { CheckedFunction<Integer, XContentBuilder, IOException> docSupplier) throws IOException {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
logger.debug("Indexing document [{}]", i);
client().performRequest("POST", "/" + index + "/doc/" + i, emptyMap(), client().performRequest("POST", "/" + index + "/doc/" + i, emptyMap(),
new StringEntity(docSupplier.apply(i).string(), ContentType.APPLICATION_JSON)); new StringEntity(docSupplier.apply(i).string(), ContentType.APPLICATION_JSON));
if (rarely()) { if (rarely()) {
client().performRequest("POST", "/_refresh"); logger.info("Refreshing [{}]", index);
client().performRequest("POST", "/" + index + "/_refresh");
} }
if (flushAllowed && rarely()) { if (flushAllowed && rarely()) {
client().performRequest("POST", "/_flush"); logger.info("Flushing [{}]", index);
client().performRequest("POST", "/" + index + "/_flush");
} }
} }
} }