Skip to content

Commit 67182f9

Browse files
committed
QA: Add xpack tests to rolling upgrade (#30795)
A rolling upgrade from oss Elasticsearch to the default distribution of Elasticsearch is significantly different than a full cluster restart to install a plugin and is again different from starting a new cluster with xpack installed. So this adds some basic tests to make sure that the rolling upgrade that enables xpack works at all. This also removes some unused imports from the tests that I modified in PR #30728. I didn't mean to leave them.
1 parent b8f2f62 commit 67182f9

File tree

3 files changed

+111
-26
lines changed

3 files changed

+111
-26
lines changed

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/AbstractRollingTestCase.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,8 @@
1818
*/
1919
package org.elasticsearch.upgrades;
2020

21-
import org.apache.http.entity.ContentType;
22-
import org.apache.http.entity.StringEntity;
23-
import org.elasticsearch.Version;
24-
import org.elasticsearch.action.support.PlainActionFuture;
25-
import org.elasticsearch.client.Response;
26-
import org.elasticsearch.cluster.metadata.IndexMetaData;
2721
import org.elasticsearch.common.settings.Settings;
28-
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
2922
import org.elasticsearch.test.rest.ESRestTestCase;
30-
import org.elasticsearch.test.rest.yaml.ObjectPath;
31-
32-
import java.io.IOException;
33-
import java.util.ArrayList;
34-
import java.util.Collections;
35-
import java.util.List;
36-
import java.util.Map;
37-
import java.util.concurrent.Future;
38-
import java.util.function.Predicate;
39-
40-
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiOfLength;
41-
import static java.util.Collections.emptyMap;
42-
import static org.elasticsearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING;
43-
import static org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider.INDEX_ROUTING_ALLOCATION_ENABLE_SETTING;
44-
import static org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY;
45-
import static org.hamcrest.Matchers.equalTo;
46-
import static org.hamcrest.Matchers.hasSize;
47-
import static org.hamcrest.Matchers.notNullValue;
4823

4924
public abstract class AbstractRollingTestCase extends ESRestTestCase {
5025
protected enum ClusterType {

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.elasticsearch.cluster.metadata.IndexMetaData;
2727
import org.elasticsearch.common.settings.Settings;
2828
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
29-
import org.elasticsearch.test.rest.ESRestTestCase;
3029
import org.elasticsearch.test.rest.yaml.ObjectPath;
3130

3231
import java.io.IOException;
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.elasticsearch.upgrades;
20+
21+
import org.apache.http.util.EntityUtils;
22+
import org.elasticsearch.common.Booleans;
23+
import org.junit.Before;
24+
import org.elasticsearch.client.Request;
25+
import org.elasticsearch.client.Response;
26+
27+
import java.io.IOException;
28+
import java.nio.charset.StandardCharsets;
29+
30+
import static org.hamcrest.Matchers.equalTo;
31+
import static org.junit.Assume.assumeThat;
32+
33+
/**
34+
* Basic tests for simple xpack functionality that are only run if the
35+
* cluster is the on the "zip" distribution.
36+
*/
37+
public class XPackIT extends AbstractRollingTestCase {
38+
@Before
39+
public void skipIfNotXPack() {
40+
assumeThat("test is only supported if the distribution contains xpack",
41+
System.getProperty("tests.distribution"), equalTo("zip"));
42+
assumeThat("running this on the unupgraded cluster would change its state and it wouldn't work prior to 6.3 anyway",
43+
CLUSTER_TYPE, equalTo(ClusterType.UPGRADED));
44+
/*
45+
* *Mostly* we want this for when we're upgrading from pre-6.3's
46+
* zip distribution which doesn't contain xpack to post 6.3's zip
47+
* distribution which *does* contain xpack. But we'll also run it
48+
* on all upgrades for completeness's sake.
49+
*/
50+
}
51+
52+
/**
53+
* Test a basic feature (SQL) which doesn't require any trial license.
54+
* Note that the test methods on this class can run in any order so we
55+
* <strong>might</strong> have already installed a trial license.
56+
*/
57+
public void testBasicFeature() throws IOException {
58+
Request bulk = new Request("POST", "/sql_test/doc/_bulk");
59+
bulk.setJsonEntity(
60+
"{\"index\":{}}\n"
61+
+ "{\"f\": \"1\"}\n"
62+
+ "{\"index\":{}}\n"
63+
+ "{\"f\": \"2\"}\n");
64+
bulk.addParameter("refresh", "true");
65+
client().performRequest(bulk);
66+
67+
Request sql = new Request("POST", "/_xpack/sql");
68+
sql.setJsonEntity("{\"query\": \"SELECT * FROM sql_test WHERE f > 1 ORDER BY f ASC\"}");
69+
String response = EntityUtils.toString(client().performRequest(sql).getEntity());
70+
assertEquals("{\"columns\":[{\"name\":\"f\",\"type\":\"text\"}],\"rows\":[[\"2\"]]}", response);
71+
}
72+
73+
/**
74+
* Test creating a trial license and using it. This is interesting because
75+
* our other tests test cover starting a new cluster with the default
76+
* distribution and enabling the trial license but this test is the only
77+
* one that can upgrade from the oss distribution to the default
78+
* distribution with xpack and the create a trial license. We don't
79+
* <strong>do</strong> a lot with the trial license because for the most
80+
* part those things are tested elsewhere, off in xpack. But we do use the
81+
* trial license a little bit to make sure that it works.
82+
*/
83+
public void testTrialLicense() throws IOException {
84+
Request startTrial = new Request("POST", "/_xpack/license/start_trial");
85+
startTrial.addParameter("acknowledge", "true");
86+
client().performRequest(startTrial);
87+
88+
String noJobs = EntityUtils.toString(
89+
client().performRequest(new Request("GET", "/_xpack/ml/anomaly_detectors")).getEntity());
90+
assertEquals("{\"count\":0,\"jobs\":[]}", noJobs);
91+
92+
Request createJob = new Request("PUT", "/_xpack/ml/anomaly_detectors/test_job");
93+
createJob.setJsonEntity(
94+
"{\n"
95+
+ " \"analysis_config\" : {\n"
96+
+ " \"bucket_span\": \"10m\",\n"
97+
+ " \"detectors\": [\n"
98+
+ " {\n"
99+
+ " \"function\": \"sum\",\n"
100+
+ " \"field_name\": \"total\"\n"
101+
+ " }\n"
102+
+ " ]\n"
103+
+ " },\n"
104+
+ " \"data_description\": {\n"
105+
+ " \"time_field\": \"timestamp\",\n"
106+
+ " \"time_format\": \"epoch_ms\"\n"
107+
+ " }\n"
108+
+ "}\n");
109+
client().performRequest(createJob);
110+
}
111+
}

0 commit comments

Comments
 (0)