Add full cluster restart base class (#33577)
This commit adds a base class for full cluster restart tests.
This commit is contained in:
parent
6075e159e5
commit
ea3fdc90c6
|
@ -68,10 +68,8 @@ import static org.hamcrest.Matchers.notNullValue;
|
||||||
* version is started with the same data directories and then this is rerun
|
* version is started with the same data directories and then this is rerun
|
||||||
* with {@code tests.is_old_cluster} set to {@code false}.
|
* with {@code tests.is_old_cluster} set to {@code false}.
|
||||||
*/
|
*/
|
||||||
public class FullClusterRestartIT extends ESRestTestCase {
|
public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
|
||||||
private final boolean runningAgainstOldCluster = Booleans.parseBoolean(System.getProperty("tests.is_old_cluster"));
|
private final boolean supportsLenientBooleans = getOldClusterVersion().before(Version.V_6_0_0_alpha1);
|
||||||
private final Version oldClusterVersion = Version.fromString(System.getProperty("tests.old_cluster_version"));
|
|
||||||
private final boolean supportsLenientBooleans = oldClusterVersion.before(Version.V_6_0_0_alpha1);
|
|
||||||
private static final Version VERSION_5_1_0_UNRELEASED = Version.fromString("5.1.0");
|
private static final Version VERSION_5_1_0_UNRELEASED = Version.fromString("5.1.0");
|
||||||
|
|
||||||
private String index;
|
private String index;
|
||||||
|
@ -81,29 +79,9 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
index = getTestName().toLowerCase(Locale.ROOT);
|
index = getTestName().toLowerCase(Locale.ROOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean preserveIndicesUponCompletion() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean preserveSnapshotsUponCompletion() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean preserveReposUponCompletion() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean preserveTemplatesUponCompletion() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSearch() throws Exception {
|
public void testSearch() throws Exception {
|
||||||
int count;
|
int count;
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
XContentBuilder mappingsAndSettings = jsonBuilder();
|
XContentBuilder mappingsAndSettings = jsonBuilder();
|
||||||
mappingsAndSettings.startObject();
|
mappingsAndSettings.startObject();
|
||||||
{
|
{
|
||||||
|
@ -169,7 +147,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNewReplicasWork() throws Exception {
|
public void testNewReplicasWork() throws Exception {
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
XContentBuilder mappingsAndSettings = jsonBuilder();
|
XContentBuilder mappingsAndSettings = jsonBuilder();
|
||||||
mappingsAndSettings.startObject();
|
mappingsAndSettings.startObject();
|
||||||
{
|
{
|
||||||
|
@ -237,10 +215,10 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
*/
|
*/
|
||||||
public void testAliasWithBadName() throws Exception {
|
public void testAliasWithBadName() throws Exception {
|
||||||
assumeTrue("Can only test bad alias name if old cluster is on 5.1.0 or before",
|
assumeTrue("Can only test bad alias name if old cluster is on 5.1.0 or before",
|
||||||
oldClusterVersion.before(VERSION_5_1_0_UNRELEASED));
|
getOldClusterVersion().before(VERSION_5_1_0_UNRELEASED));
|
||||||
|
|
||||||
int count;
|
int count;
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
XContentBuilder mappingsAndSettings = jsonBuilder();
|
XContentBuilder mappingsAndSettings = jsonBuilder();
|
||||||
mappingsAndSettings.startObject();
|
mappingsAndSettings.startObject();
|
||||||
{
|
{
|
||||||
|
@ -291,7 +269,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
Map<String, Object> searchRsp = entityAsMap(client().performRequest(new Request("GET", "/" + aliasName + "/_search")));
|
Map<String, Object> searchRsp = entityAsMap(client().performRequest(new Request("GET", "/" + aliasName + "/_search")));
|
||||||
int totalHits = (int) XContentMapValues.extractValue("hits.total", searchRsp);
|
int totalHits = (int) XContentMapValues.extractValue("hits.total", searchRsp);
|
||||||
assertEquals(count, totalHits);
|
assertEquals(count, totalHits);
|
||||||
if (runningAgainstOldCluster == false) {
|
if (isRunningAgainstOldCluster() == false) {
|
||||||
// We can remove the alias.
|
// We can remove the alias.
|
||||||
Response response = client().performRequest(new Request("DELETE", "/" + index + "/_alias/" + aliasName));
|
Response response = client().performRequest(new Request("DELETE", "/" + index + "/_alias/" + aliasName));
|
||||||
assertEquals(200, response.getStatusLine().getStatusCode());
|
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||||
|
@ -302,7 +280,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClusterState() throws Exception {
|
public void testClusterState() throws Exception {
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
XContentBuilder mappingsAndSettings = jsonBuilder();
|
XContentBuilder mappingsAndSettings = jsonBuilder();
|
||||||
mappingsAndSettings.startObject();
|
mappingsAndSettings.startObject();
|
||||||
mappingsAndSettings.field("template", index);
|
mappingsAndSettings.field("template", index);
|
||||||
|
@ -341,14 +319,14 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
assertEquals("0", numberOfReplicas);
|
assertEquals("0", numberOfReplicas);
|
||||||
Version version = Version.fromId(Integer.valueOf((String) XContentMapValues.extractValue("metadata.indices." + index +
|
Version version = Version.fromId(Integer.valueOf((String) XContentMapValues.extractValue("metadata.indices." + index +
|
||||||
".settings.index.version.created", clusterState)));
|
".settings.index.version.created", clusterState)));
|
||||||
assertEquals(oldClusterVersion, version);
|
assertEquals(getOldClusterVersion(), version);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShrink() throws IOException {
|
public void testShrink() throws IOException {
|
||||||
String shrunkenIndex = index + "_shrunk";
|
String shrunkenIndex = index + "_shrunk";
|
||||||
int numDocs;
|
int numDocs;
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
XContentBuilder mappingsAndSettings = jsonBuilder();
|
XContentBuilder mappingsAndSettings = jsonBuilder();
|
||||||
mappingsAndSettings.startObject();
|
mappingsAndSettings.startObject();
|
||||||
{
|
{
|
||||||
|
@ -413,7 +391,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
public void testShrinkAfterUpgrade() throws IOException {
|
public void testShrinkAfterUpgrade() throws IOException {
|
||||||
String shrunkenIndex = index + "_shrunk";
|
String shrunkenIndex = index + "_shrunk";
|
||||||
int numDocs;
|
int numDocs;
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
XContentBuilder mappingsAndSettings = jsonBuilder();
|
XContentBuilder mappingsAndSettings = jsonBuilder();
|
||||||
mappingsAndSettings.startObject();
|
mappingsAndSettings.startObject();
|
||||||
{
|
{
|
||||||
|
@ -465,7 +443,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
int totalHits = (int) XContentMapValues.extractValue("hits.total", response);
|
int totalHits = (int) XContentMapValues.extractValue("hits.total", response);
|
||||||
assertEquals(numDocs, totalHits);
|
assertEquals(numDocs, totalHits);
|
||||||
|
|
||||||
if (runningAgainstOldCluster == false) {
|
if (isRunningAgainstOldCluster() == false) {
|
||||||
response = entityAsMap(client().performRequest(new Request("GET", "/" + shrunkenIndex + "/_search")));
|
response = entityAsMap(client().performRequest(new Request("GET", "/" + shrunkenIndex + "/_search")));
|
||||||
assertNoFailures(response);
|
assertNoFailures(response);
|
||||||
totalShards = (int) XContentMapValues.extractValue("_shards.total", response);
|
totalShards = (int) XContentMapValues.extractValue("_shards.total", response);
|
||||||
|
@ -490,7 +468,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
* </ol>
|
* </ol>
|
||||||
*/
|
*/
|
||||||
public void testRollover() throws IOException {
|
public void testRollover() throws IOException {
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
Request createIndex = new Request("PUT", "/" + index + "-000001");
|
Request createIndex = new Request("PUT", "/" + index + "-000001");
|
||||||
createIndex.setJsonEntity("{"
|
createIndex.setJsonEntity("{"
|
||||||
+ " \"aliases\": {"
|
+ " \"aliases\": {"
|
||||||
|
@ -511,7 +489,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
bulkRequest.addParameter("refresh", "");
|
bulkRequest.addParameter("refresh", "");
|
||||||
assertThat(EntityUtils.toString(client().performRequest(bulkRequest).getEntity()), containsString("\"errors\":false"));
|
assertThat(EntityUtils.toString(client().performRequest(bulkRequest).getEntity()), containsString("\"errors\":false"));
|
||||||
|
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
Request rolloverRequest = new Request("POST", "/" + index + "_write/_rollover");
|
Request rolloverRequest = new Request("POST", "/" + index + "_write/_rollover");
|
||||||
rolloverRequest.setJsonEntity("{"
|
rolloverRequest.setJsonEntity("{"
|
||||||
+ " \"conditions\": {"
|
+ " \"conditions\": {"
|
||||||
|
@ -529,7 +507,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
Map<String, Object> count = entityAsMap(client().performRequest(countRequest));
|
Map<String, Object> count = entityAsMap(client().performRequest(countRequest));
|
||||||
assertNoFailures(count);
|
assertNoFailures(count);
|
||||||
|
|
||||||
int expectedCount = bulkCount + (runningAgainstOldCluster ? 0 : bulkCount);
|
int expectedCount = bulkCount + (isRunningAgainstOldCluster() ? 0 : bulkCount);
|
||||||
assertEquals(expectedCount, (int) XContentMapValues.extractValue("hits.total", count));
|
assertEquals(expectedCount, (int) XContentMapValues.extractValue("hits.total", count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -688,7 +666,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
String docLocation = "/" + index + "/doc/1";
|
String docLocation = "/" + index + "/doc/1";
|
||||||
String doc = "{\"test\": \"test\"}";
|
String doc = "{\"test\": \"test\"}";
|
||||||
|
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
Request createDoc = new Request("PUT", docLocation);
|
Request createDoc = new Request("PUT", docLocation);
|
||||||
createDoc.setJsonEntity(doc);
|
createDoc.setJsonEntity(doc);
|
||||||
client().performRequest(createDoc);
|
client().performRequest(createDoc);
|
||||||
|
@ -703,7 +681,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
public void testEmptyShard() throws IOException {
|
public void testEmptyShard() throws IOException {
|
||||||
final String index = "test_empty_shard";
|
final String index = "test_empty_shard";
|
||||||
|
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
Settings.Builder settings = Settings.builder()
|
Settings.Builder settings = Settings.builder()
|
||||||
.put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
|
.put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
|
||||||
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 1)
|
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 1)
|
||||||
|
@ -726,7 +704,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
public void testRecovery() throws Exception {
|
public void testRecovery() throws Exception {
|
||||||
int count;
|
int count;
|
||||||
boolean shouldHaveTranslog;
|
boolean shouldHaveTranslog;
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
count = between(200, 300);
|
count = between(200, 300);
|
||||||
/* We've had bugs in the past where we couldn't restore
|
/* We've had bugs in the past where we couldn't restore
|
||||||
* an index without a translog so we randomize whether
|
* an index without a translog so we randomize whether
|
||||||
|
@ -772,7 +750,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
String countResponse = toStr(client().performRequest(countRequest));
|
String countResponse = toStr(client().performRequest(countRequest));
|
||||||
assertThat(countResponse, containsString("\"total\":" + count));
|
assertThat(countResponse, containsString("\"total\":" + count));
|
||||||
|
|
||||||
if (false == runningAgainstOldCluster) {
|
if (false == isRunningAgainstOldCluster()) {
|
||||||
boolean restoredFromTranslog = false;
|
boolean restoredFromTranslog = false;
|
||||||
boolean foundPrimary = false;
|
boolean foundPrimary = false;
|
||||||
Request recoveryRequest = new Request("GET", "/_cat/recovery/" + index);
|
Request recoveryRequest = new Request("GET", "/_cat/recovery/" + index);
|
||||||
|
@ -800,7 +778,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
assertEquals("mismatch while checking for translog recovery\n" + recoveryResponse, shouldHaveTranslog, restoredFromTranslog);
|
assertEquals("mismatch while checking for translog recovery\n" + recoveryResponse, shouldHaveTranslog, restoredFromTranslog);
|
||||||
|
|
||||||
String currentLuceneVersion = Version.CURRENT.luceneVersion.toString();
|
String currentLuceneVersion = Version.CURRENT.luceneVersion.toString();
|
||||||
String bwcLuceneVersion = oldClusterVersion.luceneVersion.toString();
|
String bwcLuceneVersion = getOldClusterVersion().luceneVersion.toString();
|
||||||
if (shouldHaveTranslog && false == currentLuceneVersion.equals(bwcLuceneVersion)) {
|
if (shouldHaveTranslog && false == currentLuceneVersion.equals(bwcLuceneVersion)) {
|
||||||
int numCurrentVersion = 0;
|
int numCurrentVersion = 0;
|
||||||
int numBwcVersion = 0;
|
int numBwcVersion = 0;
|
||||||
|
@ -840,7 +818,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
*/
|
*/
|
||||||
public void testSnapshotRestore() throws IOException {
|
public void testSnapshotRestore() throws IOException {
|
||||||
int count;
|
int count;
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
// Create the index
|
// Create the index
|
||||||
count = between(200, 300);
|
count = between(200, 300);
|
||||||
indexRandomDocuments(count, true, true, i -> jsonBuilder().startObject().field("field", "value").endObject());
|
indexRandomDocuments(count, true, true, i -> jsonBuilder().startObject().field("field", "value").endObject());
|
||||||
|
@ -860,7 +838,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
// Stick a routing attribute into to cluster settings so we can see it after the restore
|
// Stick a routing attribute into to cluster settings so we can see it after the restore
|
||||||
Request addRoutingSettings = new Request("PUT", "/_cluster/settings");
|
Request addRoutingSettings = new Request("PUT", "/_cluster/settings");
|
||||||
addRoutingSettings.setJsonEntity(
|
addRoutingSettings.setJsonEntity(
|
||||||
"{\"persistent\": {\"cluster.routing.allocation.exclude.test_attr\": \"" + oldClusterVersion + "\"}}");
|
"{\"persistent\": {\"cluster.routing.allocation.exclude.test_attr\": \"" + getOldClusterVersion() + "\"}}");
|
||||||
client().performRequest(addRoutingSettings);
|
client().performRequest(addRoutingSettings);
|
||||||
|
|
||||||
// Stick a template into the cluster so we can see it after the restore
|
// Stick a template into the cluster so we can see it after the restore
|
||||||
|
@ -885,7 +863,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
templateBuilder.startObject("alias2"); {
|
templateBuilder.startObject("alias2"); {
|
||||||
templateBuilder.startObject("filter"); {
|
templateBuilder.startObject("filter"); {
|
||||||
templateBuilder.startObject("term"); {
|
templateBuilder.startObject("term"); {
|
||||||
templateBuilder.field("version", runningAgainstOldCluster ? oldClusterVersion : Version.CURRENT);
|
templateBuilder.field("version", isRunningAgainstOldCluster() ? getOldClusterVersion() : Version.CURRENT);
|
||||||
}
|
}
|
||||||
templateBuilder.endObject();
|
templateBuilder.endObject();
|
||||||
}
|
}
|
||||||
|
@ -898,7 +876,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
createTemplateRequest.setJsonEntity(Strings.toString(templateBuilder));
|
createTemplateRequest.setJsonEntity(Strings.toString(templateBuilder));
|
||||||
client().performRequest(createTemplateRequest);
|
client().performRequest(createTemplateRequest);
|
||||||
|
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
// Create the repo
|
// Create the repo
|
||||||
XContentBuilder repoConfig = JsonXContent.contentBuilder().startObject(); {
|
XContentBuilder repoConfig = JsonXContent.contentBuilder().startObject(); {
|
||||||
repoConfig.field("type", "fs");
|
repoConfig.field("type", "fs");
|
||||||
|
@ -914,19 +892,19 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
client().performRequest(createRepoRequest);
|
client().performRequest(createRepoRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
Request createSnapshot = new Request("PUT", "/_snapshot/repo/" + (runningAgainstOldCluster ? "old_snap" : "new_snap"));
|
Request createSnapshot = new Request("PUT", "/_snapshot/repo/" + (isRunningAgainstOldCluster() ? "old_snap" : "new_snap"));
|
||||||
createSnapshot.addParameter("wait_for_completion", "true");
|
createSnapshot.addParameter("wait_for_completion", "true");
|
||||||
createSnapshot.setJsonEntity("{\"indices\": \"" + index + "\"}");
|
createSnapshot.setJsonEntity("{\"indices\": \"" + index + "\"}");
|
||||||
client().performRequest(createSnapshot);
|
client().performRequest(createSnapshot);
|
||||||
|
|
||||||
checkSnapshot("old_snap", count, oldClusterVersion);
|
checkSnapshot("old_snap", count, getOldClusterVersion());
|
||||||
if (false == runningAgainstOldCluster) {
|
if (false == isRunningAgainstOldCluster()) {
|
||||||
checkSnapshot("new_snap", count, Version.CURRENT);
|
checkSnapshot("new_snap", count, Version.CURRENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHistoryUUIDIsAdded() throws Exception {
|
public void testHistoryUUIDIsAdded() throws Exception {
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
XContentBuilder mappingsAndSettings = jsonBuilder();
|
XContentBuilder mappingsAndSettings = jsonBuilder();
|
||||||
mappingsAndSettings.startObject();
|
mappingsAndSettings.startObject();
|
||||||
{
|
{
|
||||||
|
@ -1022,7 +1000,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
Map<String, Object> expectedClusterSettings = new HashMap<>();
|
Map<String, Object> expectedClusterSettings = new HashMap<>();
|
||||||
expectedClusterSettings.put("transient", emptyMap());
|
expectedClusterSettings.put("transient", emptyMap());
|
||||||
expectedClusterSettings.put("persistent",
|
expectedClusterSettings.put("persistent",
|
||||||
singletonMap("cluster.routing.allocation.exclude.test_attr", oldClusterVersion.toString()));
|
singletonMap("cluster.routing.allocation.exclude.test_attr", getOldClusterVersion().toString()));
|
||||||
if (expectedClusterSettings.equals(clusterSettingsResponse) == false) {
|
if (expectedClusterSettings.equals(clusterSettingsResponse) == false) {
|
||||||
NotEqualMessageBuilder builder = new NotEqualMessageBuilder();
|
NotEqualMessageBuilder builder = new NotEqualMessageBuilder();
|
||||||
builder.compareMaps(clusterSettingsResponse, expectedClusterSettings);
|
builder.compareMaps(clusterSettingsResponse, expectedClusterSettings);
|
||||||
|
@ -1032,7 +1010,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
// Check that the template was restored successfully
|
// Check that the template was restored successfully
|
||||||
Map<String, Object> getTemplateResponse = entityAsMap(client().performRequest(new Request("GET", "/_template/test_template")));
|
Map<String, Object> getTemplateResponse = entityAsMap(client().performRequest(new Request("GET", "/_template/test_template")));
|
||||||
Map<String, Object> expectedTemplate = new HashMap<>();
|
Map<String, Object> expectedTemplate = new HashMap<>();
|
||||||
if (runningAgainstOldCluster && oldClusterVersion.before(Version.V_6_0_0_beta1)) {
|
if (isRunningAgainstOldCluster() && getOldClusterVersion().before(Version.V_6_0_0_beta1)) {
|
||||||
expectedTemplate.put("template", "evil_*");
|
expectedTemplate.put("template", "evil_*");
|
||||||
} else {
|
} else {
|
||||||
expectedTemplate.put("index_patterns", singletonList("evil_*"));
|
expectedTemplate.put("index_patterns", singletonList("evil_*"));
|
||||||
|
|
|
@ -20,10 +20,8 @@
|
||||||
package org.elasticsearch.upgrades;
|
package org.elasticsearch.upgrades;
|
||||||
|
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.elasticsearch.Version;
|
|
||||||
import org.elasticsearch.client.Request;
|
import org.elasticsearch.client.Request;
|
||||||
import org.elasticsearch.client.Response;
|
import org.elasticsearch.client.Response;
|
||||||
import org.elasticsearch.common.Booleans;
|
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.io.stream.InputStreamStreamInput;
|
import org.elasticsearch.common.io.stream.InputStreamStreamInput;
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
|
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
|
||||||
|
@ -48,7 +46,6 @@ import org.elasticsearch.index.query.SpanTermQueryBuilder;
|
||||||
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
|
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
|
||||||
import org.elasticsearch.index.query.functionscore.RandomScoreFunctionBuilder;
|
import org.elasticsearch.index.query.functionscore.RandomScoreFunctionBuilder;
|
||||||
import org.elasticsearch.search.SearchModule;
|
import org.elasticsearch.search.SearchModule;
|
||||||
import org.elasticsearch.test.rest.ESRestTestCase;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -71,7 +68,7 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
* The queries to test are specified in json format, which turns out to work because we tend break here rarely. If the
|
* The queries to test are specified in json format, which turns out to work because we tend break here rarely. If the
|
||||||
* json format of a query being tested here then feel free to change this.
|
* json format of a query being tested here then feel free to change this.
|
||||||
*/
|
*/
|
||||||
public class QueryBuilderBWCIT extends ESRestTestCase {
|
public class QueryBuilderBWCIT extends AbstractFullClusterRestartTestCase {
|
||||||
|
|
||||||
private static final List<Object[]> CANDIDATES = new ArrayList<>();
|
private static final List<Object[]> CANDIDATES = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -145,32 +142,9 @@ public class QueryBuilderBWCIT extends ESRestTestCase {
|
||||||
CANDIDATES.add(new Object[]{"{\"query\": {" + querySource + "}}", expectedQb});
|
CANDIDATES.add(new Object[]{"{\"query\": {" + querySource + "}}", expectedQb});
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Version oldClusterVersion = Version.fromString(System.getProperty("tests.old_cluster_version"));
|
|
||||||
private final boolean runningAgainstOldCluster = Booleans.parseBoolean(System.getProperty("tests.is_old_cluster"));
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean preserveIndicesUponCompletion() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean preserveSnapshotsUponCompletion() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean preserveReposUponCompletion() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean preserveTemplatesUponCompletion() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testQueryBuilderBWC() throws Exception {
|
public void testQueryBuilderBWC() throws Exception {
|
||||||
String index = "queries";
|
String index = "queries";
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
XContentBuilder mappingsAndSettings = jsonBuilder();
|
XContentBuilder mappingsAndSettings = jsonBuilder();
|
||||||
mappingsAndSettings.startObject();
|
mappingsAndSettings.startObject();
|
||||||
{
|
{
|
||||||
|
@ -230,7 +204,7 @@ public class QueryBuilderBWCIT extends ESRestTestCase {
|
||||||
byte[] qbSource = Base64.getDecoder().decode(queryBuilderStr);
|
byte[] qbSource = Base64.getDecoder().decode(queryBuilderStr);
|
||||||
try (InputStream in = new ByteArrayInputStream(qbSource, 0, qbSource.length)) {
|
try (InputStream in = new ByteArrayInputStream(qbSource, 0, qbSource.length)) {
|
||||||
try (StreamInput input = new NamedWriteableAwareStreamInput(new InputStreamStreamInput(in), registry)) {
|
try (StreamInput input = new NamedWriteableAwareStreamInput(new InputStreamStreamInput(in), registry)) {
|
||||||
input.setVersion(oldClusterVersion);
|
input.setVersion(getOldClusterVersion());
|
||||||
QueryBuilder queryBuilder = input.readNamedWriteable(QueryBuilder.class);
|
QueryBuilder queryBuilder = input.readNamedWriteable(QueryBuilder.class);
|
||||||
assert in.read() == -1;
|
assert in.read() == -1;
|
||||||
assertEquals(expectedQueryBuilder, queryBuilder);
|
assertEquals(expectedQueryBuilder, queryBuilder);
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Elasticsearch under one or more contributor
|
||||||
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright
|
||||||
|
* ownership. Elasticsearch licenses this file to you under
|
||||||
|
* the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.upgrades;
|
||||||
|
|
||||||
|
import org.elasticsearch.Version;
|
||||||
|
import org.elasticsearch.common.Booleans;
|
||||||
|
import org.elasticsearch.test.rest.ESRestTestCase;
|
||||||
|
|
||||||
|
public abstract class AbstractFullClusterRestartTestCase extends ESRestTestCase {
|
||||||
|
|
||||||
|
private final boolean runningAgainstOldCluster = Booleans.parseBoolean(System.getProperty("tests.is_old_cluster"));
|
||||||
|
|
||||||
|
public final boolean isRunningAgainstOldCluster() {
|
||||||
|
return runningAgainstOldCluster;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Version oldClusterVersion = Version.fromString(System.getProperty("tests.old_cluster_version"));
|
||||||
|
|
||||||
|
public final Version getOldClusterVersion() {
|
||||||
|
return oldClusterVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean preserveIndicesUponCompletion() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean preserveSnapshotsUponCompletion() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean preserveReposUponCompletion() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean preserveTemplatesUponCompletion() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,7 +10,6 @@ import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.client.Request;
|
import org.elasticsearch.client.Request;
|
||||||
import org.elasticsearch.client.Response;
|
import org.elasticsearch.client.Response;
|
||||||
import org.elasticsearch.client.ResponseException;
|
import org.elasticsearch.client.ResponseException;
|
||||||
import org.elasticsearch.common.Booleans;
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
|
@ -18,6 +17,7 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
||||||
import org.elasticsearch.rest.RestStatus;
|
import org.elasticsearch.rest.RestStatus;
|
||||||
import org.elasticsearch.test.StreamsUtils;
|
import org.elasticsearch.test.StreamsUtils;
|
||||||
import org.elasticsearch.test.rest.ESRestTestCase;
|
import org.elasticsearch.test.rest.ESRestTestCase;
|
||||||
|
import org.elasticsearch.upgrades.AbstractFullClusterRestartTestCase;
|
||||||
import org.elasticsearch.xpack.core.watcher.client.WatchSourceBuilder;
|
import org.elasticsearch.xpack.core.watcher.client.WatchSourceBuilder;
|
||||||
import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath;
|
import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath;
|
||||||
import org.elasticsearch.xpack.security.support.SecurityIndexManager;
|
import org.elasticsearch.xpack.security.support.SecurityIndexManager;
|
||||||
|
@ -54,35 +54,13 @@ import static org.hamcrest.Matchers.not;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
import static org.hamcrest.Matchers.startsWith;
|
import static org.hamcrest.Matchers.startsWith;
|
||||||
|
|
||||||
public class FullClusterRestartIT extends ESRestTestCase {
|
public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
|
||||||
private final boolean runningAgainstOldCluster = Booleans.parseBoolean(System.getProperty("tests.is_old_cluster"));
|
|
||||||
private final Version oldClusterVersion = Version.fromString(System.getProperty("tests.old_cluster_version"));
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void waitForMlTemplates() throws Exception {
|
public void waitForMlTemplates() throws Exception {
|
||||||
XPackRestTestHelper.waitForMlTemplates(client());
|
XPackRestTestHelper.waitForMlTemplates(client());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean preserveIndicesUponCompletion() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean preserveSnapshotsUponCompletion() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean preserveReposUponCompletion() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean preserveTemplatesUponCompletion() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Settings restClientSettings() {
|
protected Settings restClientSettings() {
|
||||||
String token = "Basic " + Base64.getEncoder().encodeToString("test_user:x-pack-test-password".getBytes(StandardCharsets.UTF_8));
|
String token = "Basic " + Base64.getEncoder().encodeToString("test_user:x-pack-test-password".getBytes(StandardCharsets.UTF_8));
|
||||||
|
@ -103,7 +81,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
String docLocation = "/testsingledoc/doc/1";
|
String docLocation = "/testsingledoc/doc/1";
|
||||||
String doc = "{\"test\": \"test\"}";
|
String doc = "{\"test\": \"test\"}";
|
||||||
|
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
Request createDoc = new Request("PUT", docLocation);
|
Request createDoc = new Request("PUT", docLocation);
|
||||||
createDoc.addParameter("refresh", "true");
|
createDoc.addParameter("refresh", "true");
|
||||||
createDoc.setJsonEntity(doc);
|
createDoc.setJsonEntity(doc);
|
||||||
|
@ -115,7 +93,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testSecurityNativeRealm() throws Exception {
|
public void testSecurityNativeRealm() throws Exception {
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
createUser("preupgrade_user");
|
createUser("preupgrade_user");
|
||||||
createRole("preupgrade_role");
|
createRole("preupgrade_role");
|
||||||
} else {
|
} else {
|
||||||
|
@ -165,15 +143,15 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
|
|
||||||
assertUserInfo("preupgrade_user");
|
assertUserInfo("preupgrade_user");
|
||||||
assertRoleInfo("preupgrade_role");
|
assertRoleInfo("preupgrade_role");
|
||||||
if (!runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster() == false) {
|
||||||
assertUserInfo("postupgrade_user");
|
assertUserInfo("postupgrade_user");
|
||||||
assertRoleInfo("postupgrade_role");
|
assertRoleInfo("postupgrade_role");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWatcher() throws Exception {
|
public void testWatcher() throws Exception {
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
logger.info("Adding a watch on old cluster {}", oldClusterVersion);
|
logger.info("Adding a watch on old cluster {}", getOldClusterVersion());
|
||||||
Request createBwcWatch = new Request("PUT", "_xpack/watcher/watch/bwc_watch");
|
Request createBwcWatch = new Request("PUT", "_xpack/watcher/watch/bwc_watch");
|
||||||
createBwcWatch.setJsonEntity(loadWatch("simple-watch.json"));
|
createBwcWatch.setJsonEntity(loadWatch("simple-watch.json"));
|
||||||
client().performRequest(createBwcWatch);
|
client().performRequest(createBwcWatch);
|
||||||
|
@ -194,7 +172,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
waitForHits(".watcher-history*", 2);
|
waitForHits(".watcher-history*", 2);
|
||||||
logger.info("Done creating watcher-related indices");
|
logger.info("Done creating watcher-related indices");
|
||||||
} else {
|
} else {
|
||||||
logger.info("testing against {}", oldClusterVersion);
|
logger.info("testing against {}", getOldClusterVersion());
|
||||||
waitForYellow(".watches,bwc_watch_index,.watcher-history*");
|
waitForYellow(".watches,bwc_watch_index,.watcher-history*");
|
||||||
|
|
||||||
logger.info("checking if the upgrade procedure on the new cluster is required");
|
logger.info("checking if the upgrade procedure on the new cluster is required");
|
||||||
|
@ -264,8 +242,8 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
* Tests that a RollUp job created on a old cluster is correctly restarted after the upgrade.
|
* Tests that a RollUp job created on a old cluster is correctly restarted after the upgrade.
|
||||||
*/
|
*/
|
||||||
public void testRollupAfterRestart() throws Exception {
|
public void testRollupAfterRestart() throws Exception {
|
||||||
assumeTrue("Rollup can be tested with 6.3.0 and onwards", oldClusterVersion.onOrAfter(Version.V_6_3_0));
|
assumeTrue("Rollup can be tested with 6.3.0 and onwards", getOldClusterVersion().onOrAfter(Version.V_6_3_0));
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
final int numDocs = 59;
|
final int numDocs = 59;
|
||||||
final int year = randomIntBetween(1970, 2018);
|
final int year = randomIntBetween(1970, 2018);
|
||||||
|
|
||||||
|
@ -315,7 +293,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
final Request clusterHealthRequest = new Request("GET", "/_cluster/health");
|
final Request clusterHealthRequest = new Request("GET", "/_cluster/health");
|
||||||
clusterHealthRequest.addParameter("wait_for_status", "yellow");
|
clusterHealthRequest.addParameter("wait_for_status", "yellow");
|
||||||
clusterHealthRequest.addParameter("wait_for_no_relocating_shards", "true");
|
clusterHealthRequest.addParameter("wait_for_no_relocating_shards", "true");
|
||||||
if (oldClusterVersion.onOrAfter(Version.V_6_2_0)) {
|
if (getOldClusterVersion().onOrAfter(Version.V_6_2_0)) {
|
||||||
clusterHealthRequest.addParameter("wait_for_no_initializing_shards", "true");
|
clusterHealthRequest.addParameter("wait_for_no_initializing_shards", "true");
|
||||||
}
|
}
|
||||||
Map<String, Object> clusterHealthResponse = entityAsMap(client().performRequest(clusterHealthRequest));
|
Map<String, Object> clusterHealthResponse = entityAsMap(client().performRequest(clusterHealthRequest));
|
||||||
|
@ -326,9 +304,9 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRollupIDSchemeAfterRestart() throws Exception {
|
public void testRollupIDSchemeAfterRestart() throws Exception {
|
||||||
assumeTrue("Rollup can be tested with 6.3.0 and onwards", oldClusterVersion.onOrAfter(Version.V_6_3_0));
|
assumeTrue("Rollup can be tested with 6.3.0 and onwards", getOldClusterVersion().onOrAfter(Version.V_6_3_0));
|
||||||
assumeTrue("Rollup ID scheme changed in 6.4", oldClusterVersion.before(Version.V_6_4_0));
|
assumeTrue("Rollup ID scheme changed in 6.4", getOldClusterVersion().before(Version.V_6_4_0));
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
|
|
||||||
final Request indexRequest = new Request("POST", "/id-test-rollup/_doc/1");
|
final Request indexRequest = new Request("POST", "/id-test-rollup/_doc/1");
|
||||||
indexRequest.setJsonEntity("{\"timestamp\":\"2018-01-01T00:00:01\",\"value\":123}");
|
indexRequest.setJsonEntity("{\"timestamp\":\"2018-01-01T00:00:01\",\"value\":123}");
|
||||||
|
@ -439,8 +417,8 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
public void testSqlFailsOnIndexWithTwoTypes() throws IOException {
|
public void testSqlFailsOnIndexWithTwoTypes() throws IOException {
|
||||||
// TODO this isn't going to trigger until we backport to 6.1
|
// TODO this isn't going to trigger until we backport to 6.1
|
||||||
assumeTrue("It is only possible to build an index that sql doesn't like before 6.0.0",
|
assumeTrue("It is only possible to build an index that sql doesn't like before 6.0.0",
|
||||||
oldClusterVersion.before(Version.V_6_0_0_alpha1));
|
getOldClusterVersion().before(Version.V_6_0_0_alpha1));
|
||||||
if (runningAgainstOldCluster) {
|
if (isRunningAgainstOldCluster()) {
|
||||||
Request doc1 = new Request("POST", "/testsqlfailsonindexwithtwotypes/type1");
|
Request doc1 = new Request("POST", "/testsqlfailsonindexwithtwotypes/type1");
|
||||||
doc1.setJsonEntity("{}");
|
doc1.setJsonEntity("{}");
|
||||||
client().performRequest(doc1);
|
client().performRequest(doc1);
|
||||||
|
@ -550,7 +528,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
request.addParameter("wait_for_status", "yellow");
|
request.addParameter("wait_for_status", "yellow");
|
||||||
request.addParameter("timeout", "30s");
|
request.addParameter("timeout", "30s");
|
||||||
request.addParameter("wait_for_no_relocating_shards", "true");
|
request.addParameter("wait_for_no_relocating_shards", "true");
|
||||||
if (oldClusterVersion.onOrAfter(Version.V_6_2_0)) {
|
if (getOldClusterVersion().onOrAfter(Version.V_6_2_0)) {
|
||||||
request.addParameter("wait_for_no_initializing_shards", "true");
|
request.addParameter("wait_for_no_initializing_shards", "true");
|
||||||
}
|
}
|
||||||
Map<String, Object> response = entityAsMap(client().performRequest(request));
|
Map<String, Object> response = entityAsMap(client().performRequest(request));
|
||||||
|
@ -668,7 +646,7 @@ public class FullClusterRestartIT extends ESRestTestCase {
|
||||||
|
|
||||||
// Persistent task state field has been renamed in 6.4.0 from "status" to "state"
|
// Persistent task state field has been renamed in 6.4.0 from "status" to "state"
|
||||||
final String stateFieldName
|
final String stateFieldName
|
||||||
= (runningAgainstOldCluster && oldClusterVersion.before(Version.V_6_4_0)) ? "status" : "state";
|
= (isRunningAgainstOldCluster() && getOldClusterVersion().before(Version.V_6_4_0)) ? "status" : "state";
|
||||||
|
|
||||||
final String jobStateField = "task.xpack/rollup/job." + stateFieldName + ".job_state";
|
final String jobStateField = "task.xpack/rollup/job." + stateFieldName + ".job_state";
|
||||||
assertThat("Expected field [" + jobStateField + "] to be started or indexing in " + task.get("id"),
|
assertThat("Expected field [" + jobStateField + "] to be started or indexing in " + task.get("id"),
|
||||||
|
|
Loading…
Reference in New Issue