Skip to content

Commit

Permalink
fix FCR bwc failures
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Walter Knize <[email protected]>
  • Loading branch information
nknize committed Feb 23, 2022
1 parent 525fb67 commit 68e1f0d
Showing 1 changed file with 5 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -491,15 +491,13 @@ public void testRollover() throws IOException {
bulk.append("{\"index\":{}}\n");
bulk.append("{\"test\":\"test\"}\n");
}
Request bulkRequest = new Request("POST", "/" + index + "_write/" + type + "/_bulk");
Request bulkRequest = new Request("POST", "/" + index + "_write/_bulk");
bulkRequest.setJsonEntity(bulk.toString());
bulkRequest.addParameter("refresh", "");
bulkRequest.setOptions(expectWarnings(TYPES_DEPRECATION_MESSAGE_BULK));
assertThat(EntityUtils.toString(client().performRequest(bulkRequest).getEntity()), containsString("\"errors\":false"));

if (isRunningAgainstOldCluster()) {
Request rolloverRequest = new Request("POST", "/" + index + "_write/_rollover");
rolloverRequest.setOptions(allowTypesRemovalWarnings());
rolloverRequest.setJsonEntity("{"
+ " \"conditions\": {"
+ " \"max_docs\": 5"
Expand Down Expand Up @@ -865,19 +863,13 @@ public void testSnapshotRestore() throws IOException {
}
templateBuilder.endObject();
templateBuilder.startObject("mappings"); {
if (isRunningAgainstAncientCluster()) {
templateBuilder.startObject(type);
}
{
templateBuilder.startObject("_source");
{
templateBuilder.field("enabled", true);
}
templateBuilder.endObject();
}
if (isRunningAgainstAncientCluster()) {
templateBuilder.endObject();
}
}
templateBuilder.endObject();
templateBuilder.startObject("aliases"); {
Expand All @@ -896,7 +888,6 @@ public void testSnapshotRestore() throws IOException {
templateBuilder.endObject().endObject();
Request createTemplateRequest = new Request("PUT", "/_template/test_template");
createTemplateRequest.setJsonEntity(Strings.toString(templateBuilder));
createTemplateRequest.setOptions(allowTypesRemovalWarnings());

client().performRequest(createTemplateRequest);

Expand Down Expand Up @@ -1145,18 +1136,17 @@ private void checkSnapshot(final String snapshotName, final int count, final Ver
bulk.append("{\"index\":{\"_id\":\"").append(count + i).append("\"}}\n");
bulk.append("{\"test\":\"test\"}\n");
}
Request writeToRestoredRequest = new Request("POST", "/restored_" + index + "/" + type + "/_bulk");
Request writeToRestoredRequest = new Request("POST", "/restored_" + index + "/_bulk");
writeToRestoredRequest.addParameter("refresh", "true");
writeToRestoredRequest.setJsonEntity(bulk.toString());
writeToRestoredRequest.setOptions(expectWarnings(TYPES_DEPRECATION_MESSAGE_BULK));
assertThat(EntityUtils.toString(client().performRequest(writeToRestoredRequest).getEntity()), containsString("\"errors\":false"));

// And count to make sure the add worked
// Make sure search finds all documents
Request countAfterWriteRequest = new Request("GET", "/restored_" + index + "/_search");
countAfterWriteRequest.addParameter("size", "0");
Map<String, Object> countAfterResponse = entityAsMap(client().performRequest(countRequest));
assertTotalHits(count+extras, countAfterResponse);
assertTotalHits(count + extras, countAfterResponse);

// Clean up the index for the next iteration
client().performRequest(new Request("DELETE", "/restored_*"));
Expand All @@ -1166,24 +1156,17 @@ private void checkSnapshot(final String snapshotName, final int count, final Ver
clusterSettingsRequest.addParameter("flat_settings", "true");
Map<String, Object> clusterSettingsResponse = entityAsMap(client().performRequest(clusterSettingsRequest));
@SuppressWarnings("unchecked") final Map<String, Object> persistentSettings =
(Map<String, Object>)clusterSettingsResponse.get("persistent");
(Map<String, Object>) clusterSettingsResponse.get("persistent");
assertThat(persistentSettings.get("cluster.routing.allocation.exclude.test_attr"), equalTo(getOldClusterVersion().toString()));

// Check that the template was restored successfully
Request getTemplateRequest = new Request("GET", "/_template/test_template");
getTemplateRequest.setOptions(allowTypesRemovalWarnings());

Map<String, Object> getTemplateResponse = entityAsMap(client().performRequest(getTemplateRequest));
Map<String, Object> expectedTemplate = new HashMap<>();
expectedTemplate.put("index_patterns", singletonList("evil_*"));
expectedTemplate.put("settings", singletonMap("index", singletonMap("number_of_shards", "1")));
// We don't have the type in the response starting with 7.0, but we won't have it on old cluster after upgrade
// either so look at the response to figure out the correct assertions
if (isTypeInTemplateResponse(getTemplateResponse)) {
expectedTemplate.put("mappings", singletonMap(type, singletonMap("_source", singletonMap("enabled", true))));
} else {
expectedTemplate.put("mappings", singletonMap("_source", singletonMap("enabled", true)));
}
expectedTemplate.put("mappings", singletonMap("_source", singletonMap("enabled", true)));

expectedTemplate.put("order", 0);
Map<String, Object> aliases = new HashMap<>();
Expand All @@ -1199,13 +1182,6 @@ private void checkSnapshot(final String snapshotName, final int count, final Ver
}
}

@SuppressWarnings("unchecked")
private boolean isTypeInTemplateResponse(Map<String, Object> getTemplateResponse) {
return ( (Map<String, Object>) (
(Map<String, Object>) getTemplateResponse.getOrDefault("test_template", emptyMap())
).get("mappings")).get("_source") == null;
}

// TODO tests for upgrades after shrink. We've had trouble with shrink in the past.

private void indexRandomDocuments(
Expand Down

0 comments on commit 68e1f0d

Please sign in to comment.