From 7ab8271692f7d08a54be110b22eed02f8318ab03 Mon Sep 17 00:00:00 2001 From: uboness Date: Wed, 25 Feb 2015 15:22:59 +0200 Subject: [PATCH] [test] introduced AlertsSingleNodeTests - changed SearchTransformTests to extend it Original commit: elastic/x-pack-elasticsearch@19d1d32d1a83cdaaf286d2edcf4f7e6cdfe8ca1b --- .../test/AbstractAlertsSingleNodeTests.java | 74 +++++++++++++++++++ .../transform/SearchTransformTests.java | 4 +- 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/elasticsearch/alerts/test/AbstractAlertsSingleNodeTests.java diff --git a/src/test/java/org/elasticsearch/alerts/test/AbstractAlertsSingleNodeTests.java b/src/test/java/org/elasticsearch/alerts/test/AbstractAlertsSingleNodeTests.java new file mode 100644 index 00000000000..cc8ec85edc1 --- /dev/null +++ b/src/test/java/org/elasticsearch/alerts/test/AbstractAlertsSingleNodeTests.java @@ -0,0 +1,74 @@ +/* + * 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.alerts.test; + +import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; +import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; +import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.alerts.support.init.proxy.ClientProxy; +import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.client.Requests; +import org.elasticsearch.common.Priority; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.test.ElasticsearchSingleNodeTest; +import org.junit.AfterClass; + +import java.util.Collections; +import java.util.Map; + +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; +import static org.hamcrest.Matchers.equalTo; + +/** + * + */ +public abstract class AbstractAlertsSingleNodeTests extends ElasticsearchSingleNodeTest { + + @AfterClass + public static void cleaupSuite() throws Exception { + node().stop(); + } + + @Override + protected boolean resetNodeAfterTest() { + return true; + } + + protected IndexResponse index(String index, String type, String id) { + return index(index, type, id, Collections.EMPTY_MAP); + } + + protected IndexResponse index(String index, String type, String id, Map doc) { + return client().prepareIndex("idx", "type", "1").setSource(doc).get(); + } + + protected ClusterHealthStatus ensureGreen(String... indices) { + ClusterHealthResponse actionGet = client().admin().cluster() + .health(Requests.clusterHealthRequest(indices).timeout(TimeValue.timeValueSeconds(30)).waitForGreenStatus().waitForEvents(Priority.LANGUID).waitForRelocatingShards(0)).actionGet(); + if (actionGet.isTimedOut()) { + logger.info("ensureGreen timed out, cluster state:\n{}\n{}", client().admin().cluster().prepareState().get().getState().prettyPrint(), client().admin().cluster().preparePendingClusterTasks().get().prettyPrint()); + assertThat("timed out waiting for green state", actionGet.isTimedOut(), equalTo(false)); + } + assertThat(actionGet.getStatus(), equalTo(ClusterHealthStatus.GREEN)); + logger.debug("indices {} are green", indices.length == 0 ? "[_all]" : indices); + return actionGet.getStatus(); + } + + protected RefreshResponse refresh() { + RefreshResponse actionGet = client().admin().indices().prepareRefresh().execute().actionGet(); + assertNoFailures(actionGet); + return actionGet; + } + + protected ClientProxy clientProxy() { + return ClientProxy.of(client()); + } + + protected ScriptServiceProxy scriptService() { + return getInstanceFromNode(ScriptServiceProxy.class); + } +} diff --git a/src/test/java/org/elasticsearch/alerts/transform/SearchTransformTests.java b/src/test/java/org/elasticsearch/alerts/transform/SearchTransformTests.java index f311cd75f53..769e87e6987 100644 --- a/src/test/java/org/elasticsearch/alerts/transform/SearchTransformTests.java +++ b/src/test/java/org/elasticsearch/alerts/transform/SearchTransformTests.java @@ -8,11 +8,11 @@ package org.elasticsearch.alerts.transform; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.alerts.AbstractAlertingTests; import org.elasticsearch.alerts.ExecutionContext; import org.elasticsearch.alerts.Payload; import org.elasticsearch.alerts.support.Variables; import org.elasticsearch.alerts.support.init.proxy.ClientProxy; +import org.elasticsearch.alerts.test.AbstractAlertsSingleNodeTests; import org.elasticsearch.client.Requests; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.collect.ImmutableList; @@ -43,7 +43,7 @@ import static org.mockito.Mockito.when; /** * */ -public class SearchTransformTests extends AbstractAlertingTests { +public class SearchTransformTests extends AbstractAlertsSingleNodeTests { @Test public void testApply() throws Exception {