test: Remove WatcherBackwardsCompatibilityTests as it was specifically build for testing upgrade from 2.x to 5.x and to verify the scripts and template work/serialize as expected. On the master this is test is no longer relevant.
The OldWatcherIndicesBackwardsCompatibilityIT covers a major upgrade too. Original commit: elastic/x-pack-elasticsearch@657881916b
This commit is contained in:
parent
67f7da18da
commit
3b97936587
|
@ -1,129 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.xpack.watcher.test.integration;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util.TestUtil;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.script.MockScriptPlugin;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.xpack.watcher.support.xcontent.ObjectPath;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.get.GetWatchResponse;
|
||||
import org.elasticsearch.xpack.watcher.watch.WatchStore;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0, transportClientRatio = 0)
|
||||
@LuceneTestCase.SuppressFileSystems("ExtrasFS")
|
||||
public class WatcherBackwardsCompatibilityTests extends AbstractWatcherIntegrationTestCase {
|
||||
|
||||
private static final String INDEX_NAME = WatchStore.INDEX;
|
||||
private static final String TYPE_NAME = WatchStore.DOC_TYPE;
|
||||
|
||||
@Override
|
||||
protected boolean enableSecurity() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean timeWarped() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Class<? extends Plugin>> pluginTypes() {
|
||||
List<Class<? extends Plugin>> plugins = super.pluginTypes();
|
||||
plugins.add(FoolMeScriptLang.class);
|
||||
return plugins;
|
||||
}
|
||||
|
||||
public void testWatchLoadedSuccessfullyAfterUpgrade() throws Exception {
|
||||
// setup node
|
||||
Path dataDir = createTempDir();
|
||||
Path clusterDir = Files.createDirectory(dataDir.resolve(cluster().getClusterName()));
|
||||
try (InputStream stream = WatcherBackwardsCompatibilityTests.class.
|
||||
getResourceAsStream("/bwc_indices/bwc_index_2_3_5.zip")) {
|
||||
TestUtil.unzip(stream, clusterDir);
|
||||
}
|
||||
|
||||
Settings.Builder nodeSettings = Settings.builder()
|
||||
.put(super.nodeSettings(0))
|
||||
.put(Environment.PATH_DATA_SETTING.getKey(), dataDir);
|
||||
internalCluster().startNode(nodeSettings.build());
|
||||
ensureYellow();
|
||||
|
||||
// verify cluster state:
|
||||
assertBusy(() -> {
|
||||
ClusterState state = client().admin().cluster().prepareState().get().getState();
|
||||
assertThat(state.metaData().indices().size(), equalTo(1)); // only the .watches index
|
||||
// (the watch has a very high interval (99 weeks))
|
||||
assertThat(state.metaData().indices().get(INDEX_NAME), notNullValue());
|
||||
assertThat(state.metaData().indices().get(INDEX_NAME).getCreationVersion(), equalTo(Version.V_2_3_5));
|
||||
assertThat(state.metaData().indices().get(INDEX_NAME).getUpgradedVersion(), equalTo(Version.CURRENT));
|
||||
assertThat(state.metaData().indices().get(INDEX_NAME).getMappings().size(), equalTo(1));
|
||||
assertThat(state.metaData().indices().get(INDEX_NAME).getMappings().get(TYPE_NAME), notNullValue());
|
||||
});
|
||||
|
||||
// verify existing watcher documents:
|
||||
SearchResponse searchResponse = client().prepareSearch(INDEX_NAME)
|
||||
.setTypes(TYPE_NAME)
|
||||
.get();
|
||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
|
||||
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("log_error_watch"));
|
||||
|
||||
// Verify that we can get the watch, which means the watch stored in ES 2.3.5 cluster has been successfully
|
||||
// loaded with the current version of ES:
|
||||
ensureWatcherStarted();
|
||||
assertThat(watcherClient().prepareWatcherStats().get().getWatchesCount(), equalTo(1L));
|
||||
GetWatchResponse getWatchResponse = watcherClient().prepareGetWatch("log_error_watch").get();
|
||||
assertThat(getWatchResponse.isFound(), is(true));
|
||||
Map<String, Object> watchSourceAsMap = getWatchResponse.getSource().getAsMap();
|
||||
assertThat(ObjectPath.eval("trigger.schedule.interval", watchSourceAsMap), equalTo("99w"));
|
||||
assertThat(ObjectPath.eval("input.search.request.body.query.bool.filter.1.range.date.to", watchSourceAsMap),
|
||||
equalTo("{{ctx.trigger.scheduled_time}}"));
|
||||
assertThat(ObjectPath.eval("actions.log_error.logging.text", watchSourceAsMap),
|
||||
equalTo("Found {{ctx.payload.hits.total}} errors in the logs"));
|
||||
|
||||
// Check that all scripts have been upgraded, so that the language has been set to groovy (legacy language default):
|
||||
assertThat(ObjectPath.eval("input.search.request.body.query.bool.filter.2.script.script.lang", watchSourceAsMap),
|
||||
equalTo("groovy"));
|
||||
assertThat(ObjectPath.eval("input.search.request.body.aggregations.avg_grade.avg.script.lang", watchSourceAsMap),
|
||||
equalTo("groovy"));
|
||||
assertThat(ObjectPath.eval("condition.script.lang", watchSourceAsMap), equalTo("groovy"));
|
||||
}
|
||||
|
||||
// Fool the script service that this is the groovy script language, so that we can just load the watch upon startup
|
||||
// and verify that the lang options on scripts have been set.
|
||||
public static class FoolMeScriptLang extends MockScriptPlugin{
|
||||
|
||||
@Override
|
||||
protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
|
||||
return Collections.singletonMap("ctx.payload.hits.total > 0", (vars) -> true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String pluginScriptLang() {
|
||||
return "groovy";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue