-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
3 changed files
with
109 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/XPackIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* 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.apache.http.HttpEntity; | ||
import org.apache.http.entity.ContentType; | ||
import org.apache.http.nio.entity.NStringEntity; | ||
import org.apache.http.util.EntityUtils; | ||
import org.junit.Before; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.junit.Assume.assumeThat; | ||
import static java.util.Collections.emptyMap; | ||
import static java.util.Collections.singletonMap; | ||
|
||
/** | ||
* Basic tests for simple xpack functionality that are only run if the | ||
* cluster is the on the "zip" distribution. | ||
*/ | ||
public class XPackIT extends AbstractRollingTestCase { | ||
@Before | ||
public void skipIfNotXPack() { | ||
assumeThat("test is only supported if the distribution contains xpack", | ||
System.getProperty("tests.distribution"), equalTo("zip")); | ||
assumeThat("running this on the unupgraded cluster would change its state and it wouldn't work prior to 6.3 anyway", | ||
CLUSTER_TYPE, equalTo(ClusterType.UPGRADED)); | ||
/* | ||
* *Mostly* we want this for when we're upgrading from pre-6.3's | ||
* zip distribution which doesn't contain xpack to post 6.3's zip | ||
* distribution which *does* contain xpack. But we'll also run it | ||
* on all upgrades for completeness's sake. | ||
*/ | ||
} | ||
|
||
/** | ||
* Test a basic feature (SQL) which doesn't require any trial license. | ||
* Note that the test methods on this class can run in any order so we | ||
* <strong>might</strong> have already installed a trial license. | ||
*/ | ||
public void testBasicFeature() throws IOException { | ||
client().performRequest("POST", "/sql_test/doc/_bulk", singletonMap("refresh", "true"), | ||
new NStringEntity("{\"index\":{}}\n" | ||
+ "{\"f\": \"1\"}\n" | ||
+ "{\"index\":{}}\n" | ||
+ "{\"f\": \"2\"}\n", | ||
ContentType.APPLICATION_JSON)); | ||
|
||
HttpEntity sql = new NStringEntity( | ||
"{\"query\": \"SELECT * FROM sql_test WHERE f > 1 ORDER BY f ASC\"}", | ||
ContentType.APPLICATION_JSON); | ||
String response = EntityUtils.toString(client().performRequest( | ||
"POST", "/_xpack/sql", emptyMap(), sql).getEntity()); | ||
assertEquals("{\"columns\":[{\"name\":\"f\",\"type\":\"text\"}],\"rows\":[[\"2\"]]}", response); | ||
} | ||
|
||
/** | ||
* Test creating a trial license and using it. This is interesting because | ||
* our other tests test cover starting a new cluster with the default | ||
* distribution and enabling the trial license but this test is the only | ||
* one that can upgrade from the oss distribution to the default | ||
* distribution with xpack and the create a trial license. We don't | ||
* <strong>do</strong> a lot with the trial license because for the most | ||
* part those things are tested elsewhere, off in xpack. But we do use the | ||
* trial license a little bit to make sure that it works. | ||
*/ | ||
public void testTrialLicense() throws IOException { | ||
client().performRequest("POST", "/_xpack/license/start_trial", singletonMap("acknowledge", "true")); | ||
|
||
String noJobs = EntityUtils.toString( | ||
client().performRequest("GET", "/_xpack/ml/anomaly_detectors").getEntity()); | ||
assertEquals("{\"count\":0,\"jobs\":[]}", noJobs); | ||
|
||
HttpEntity createJob = new NStringEntity( | ||
"{\n" | ||
+ " \"analysis_config\" : {\n" | ||
+ " \"bucket_span\": \"10m\",\n" | ||
+ " \"detectors\": [\n" | ||
+ " {\n" | ||
+ " \"function\": \"sum\",\n" | ||
+ " \"field_name\": \"total\"\n" | ||
+ " }\n" | ||
+ " ]\n" | ||
+ " },\n" | ||
+ " \"data_description\": {\n" | ||
+ " \"time_field\": \"timestamp\",\n" | ||
+ " \"time_format\": \"epoch_ms\"\n" | ||
+ " }\n" | ||
+ "}\n", ContentType.APPLICATION_JSON); | ||
client().performRequest("PUT", "/_xpack/ml/anomaly_detectors/test_job", emptyMap(), createJob); | ||
} | ||
} |