|
| 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