From 2624c90efb1aa36026f44c461ffa8610c8780734 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Fri, 20 Sep 2013 13:36:26 +0200 Subject: [PATCH] Using AbstractIntegrationTest in SimpleTTLTests and FunctionScorePluginTests --- .../FunctionScorePluginTests.java | 38 +++++++++---------- .../org/elasticsearch/ttl/SimpleTTLTests.java | 24 ++++++------ 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/test/java/org/elasticsearch/search/functionscore/FunctionScorePluginTests.java b/src/test/java/org/elasticsearch/search/functionscore/FunctionScorePluginTests.java index fcf0f92a462..db96cee5089 100644 --- a/src/test/java/org/elasticsearch/search/functionscore/FunctionScorePluginTests.java +++ b/src/test/java/org/elasticsearch/search/functionscore/FunctionScorePluginTests.java @@ -24,18 +24,16 @@ import org.apache.lucene.search.Explanation; import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.client.Client; import org.elasticsearch.common.Priority; -import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.functionscore.DecayFunction; import org.elasticsearch.index.query.functionscore.DecayFunctionBuilder; import org.elasticsearch.index.query.functionscore.DecayFunctionParser; import org.elasticsearch.index.query.functionscore.FunctionScoreModule; import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.search.SearchHits; -import org.elasticsearch.test.AbstractNodesTests; +import org.elasticsearch.test.AbstractIntegrationTest; import org.elasticsearch.test.hamcrest.ElasticSearchAssertions; -import org.junit.After; import org.junit.Test; import static org.elasticsearch.client.Requests.indexRequest; @@ -45,27 +43,27 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.QueryBuilders.functionScoreQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; +import static org.elasticsearch.test.AbstractIntegrationTest.ClusterScope; +import static org.elasticsearch.test.AbstractIntegrationTest.Scope; import static org.hamcrest.Matchers.equalTo; /** * */ -public class FunctionScorePluginTests extends AbstractNodesTests { +@ClusterScope(scope = Scope.SUITE, numNodes = 1) +public class FunctionScorePluginTests extends AbstractIntegrationTest { - private Client client; - - @After - public void closeNodes() { - client.close(); - closeAllNodes(); + @Override + protected Settings nodeSettings(int nodeOrdinal) { + return settingsBuilder() + .put("plugin.types", CustomDistanceScorePlugin.class.getName()) + .put(super.nodeSettings(nodeOrdinal)) + .build(); } @Test public void testPlugin() throws Exception { - ImmutableSettings.Builder settings = settingsBuilder().put("plugin.types", CustomDistanceScorePlugin.class.getName()); - startNode("server1", settings); - client = client("server1"); - client.admin() + client().admin() .indices() .prepareCreate("test") .addMapping( @@ -73,19 +71,19 @@ public class FunctionScorePluginTests extends AbstractNodesTests { jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("test") .field("type", "string").endObject().startObject("num1").field("type", "date").endObject().endObject() .endObject().endObject()).execute().actionGet(); - client.admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet(); + client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet(); - client.index( + client().index( indexRequest("test").type("type1").id("1") .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-26").endObject())).actionGet(); - client.index( + client().index( indexRequest("test").type("type1").id("2") .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-27").endObject())).actionGet(); - client.admin().indices().prepareRefresh().execute().actionGet(); + client().admin().indices().prepareRefresh().execute().actionGet(); DecayFunctionBuilder gfb = new CustomDistanceScoreBuilder("num1", "2013-05-28", "+1d"); - ActionFuture response = client.search(searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source( + ActionFuture response = client().search(searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source( searchSource().explain(false).query(functionScoreQuery(termQuery("test", "value")).add(gfb)))); SearchResponse sr = response.actionGet(); diff --git a/src/test/java/org/elasticsearch/ttl/SimpleTTLTests.java b/src/test/java/org/elasticsearch/ttl/SimpleTTLTests.java index e46f10eb30d..eb22c968d2e 100644 --- a/src/test/java/org/elasticsearch/ttl/SimpleTTLTests.java +++ b/src/test/java/org/elasticsearch/ttl/SimpleTTLTests.java @@ -24,26 +24,26 @@ import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.common.Priority; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.test.AbstractNodesTests; +import org.elasticsearch.test.AbstractIntegrationTest; +import org.junit.Before; import org.junit.Test; import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; import static org.hamcrest.Matchers.*; -public class SimpleTTLTests extends AbstractNodesTests { +public class SimpleTTLTests extends AbstractIntegrationTest { static private final long purgeInterval = 200; + private final Settings settings = settingsBuilder() + .put("indices.ttl.interval", purgeInterval) + .put("index.number_of_shards", 2) // 2 shards to test TTL purge with routing properly + .put("cluster.routing.operation.use_type", false) // make sure we control the shard computation + .put("cluster.routing.operation.hash.type", "djb") + .build(); - @Override - protected void beforeClass() { - Settings settings = settingsBuilder() - .put("indices.ttl.interval", purgeInterval) - .put("index.number_of_shards", 2) // 2 shards to test TTL purge with routing properly - .put("cluster.routing.operation.use_type", false) // make sure we control the shard computation - .put("cluster.routing.operation.hash.type", "djb") - .build(); - startNode("node1", settings); - startNode("node2", settings); + @Before + public void setup() { + updateClusterSettings(settings); } @Test