Using AbstractIntegrationTest in SimpleTTLTests and FunctionScorePluginTests
This commit is contained in:
parent
30d7faeba2
commit
2624c90efb
|
@ -24,18 +24,16 @@ import org.apache.lucene.search.Explanation;
|
||||||
import org.elasticsearch.action.ActionFuture;
|
import org.elasticsearch.action.ActionFuture;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.action.search.SearchType;
|
import org.elasticsearch.action.search.SearchType;
|
||||||
import org.elasticsearch.client.Client;
|
|
||||||
import org.elasticsearch.common.Priority;
|
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.DecayFunction;
|
||||||
import org.elasticsearch.index.query.functionscore.DecayFunctionBuilder;
|
import org.elasticsearch.index.query.functionscore.DecayFunctionBuilder;
|
||||||
import org.elasticsearch.index.query.functionscore.DecayFunctionParser;
|
import org.elasticsearch.index.query.functionscore.DecayFunctionParser;
|
||||||
import org.elasticsearch.index.query.functionscore.FunctionScoreModule;
|
import org.elasticsearch.index.query.functionscore.FunctionScoreModule;
|
||||||
import org.elasticsearch.plugins.AbstractPlugin;
|
import org.elasticsearch.plugins.AbstractPlugin;
|
||||||
import org.elasticsearch.search.SearchHits;
|
import org.elasticsearch.search.SearchHits;
|
||||||
import org.elasticsearch.test.AbstractNodesTests;
|
import org.elasticsearch.test.AbstractIntegrationTest;
|
||||||
import org.elasticsearch.test.hamcrest.ElasticSearchAssertions;
|
import org.elasticsearch.test.hamcrest.ElasticSearchAssertions;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.elasticsearch.client.Requests.indexRequest;
|
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.functionScoreQuery;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
||||||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
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;
|
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;
|
@Override
|
||||||
|
protected Settings nodeSettings(int nodeOrdinal) {
|
||||||
@After
|
return settingsBuilder()
|
||||||
public void closeNodes() {
|
.put("plugin.types", CustomDistanceScorePlugin.class.getName())
|
||||||
client.close();
|
.put(super.nodeSettings(nodeOrdinal))
|
||||||
closeAllNodes();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlugin() throws Exception {
|
public void testPlugin() throws Exception {
|
||||||
ImmutableSettings.Builder settings = settingsBuilder().put("plugin.types", CustomDistanceScorePlugin.class.getName());
|
client().admin()
|
||||||
startNode("server1", settings);
|
|
||||||
client = client("server1");
|
|
||||||
client.admin()
|
|
||||||
.indices()
|
.indices()
|
||||||
.prepareCreate("test")
|
.prepareCreate("test")
|
||||||
.addMapping(
|
.addMapping(
|
||||||
|
@ -73,19 +71,19 @@ public class FunctionScorePluginTests extends AbstractNodesTests {
|
||||||
jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("test")
|
jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("test")
|
||||||
.field("type", "string").endObject().startObject("num1").field("type", "date").endObject().endObject()
|
.field("type", "string").endObject().startObject("num1").field("type", "date").endObject().endObject()
|
||||||
.endObject().endObject()).execute().actionGet();
|
.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")
|
indexRequest("test").type("type1").id("1")
|
||||||
.source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-26").endObject())).actionGet();
|
.source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-26").endObject())).actionGet();
|
||||||
client.index(
|
client().index(
|
||||||
indexRequest("test").type("type1").id("2")
|
indexRequest("test").type("type1").id("2")
|
||||||
.source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-27").endObject())).actionGet();
|
.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");
|
DecayFunctionBuilder gfb = new CustomDistanceScoreBuilder("num1", "2013-05-28", "+1d");
|
||||||
|
|
||||||
ActionFuture<SearchResponse> response = client.search(searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
|
ActionFuture<SearchResponse> response = client().search(searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
|
||||||
searchSource().explain(false).query(functionScoreQuery(termQuery("test", "value")).add(gfb))));
|
searchSource().explain(false).query(functionScoreQuery(termQuery("test", "value")).add(gfb))));
|
||||||
|
|
||||||
SearchResponse sr = response.actionGet();
|
SearchResponse sr = response.actionGet();
|
||||||
|
|
|
@ -24,26 +24,26 @@ import org.elasticsearch.action.get.GetResponse;
|
||||||
import org.elasticsearch.common.Priority;
|
import org.elasticsearch.common.Priority;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
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 org.junit.Test;
|
||||||
|
|
||||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
public class SimpleTTLTests extends AbstractNodesTests {
|
public class SimpleTTLTests extends AbstractIntegrationTest {
|
||||||
|
|
||||||
static private final long purgeInterval = 200;
|
static private final long purgeInterval = 200;
|
||||||
|
private final Settings settings = settingsBuilder()
|
||||||
@Override
|
|
||||||
protected void beforeClass() {
|
|
||||||
Settings settings = settingsBuilder()
|
|
||||||
.put("indices.ttl.interval", purgeInterval)
|
.put("indices.ttl.interval", purgeInterval)
|
||||||
.put("index.number_of_shards", 2) // 2 shards to test TTL purge with routing properly
|
.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.use_type", false) // make sure we control the shard computation
|
||||||
.put("cluster.routing.operation.hash.type", "djb")
|
.put("cluster.routing.operation.hash.type", "djb")
|
||||||
.build();
|
.build();
|
||||||
startNode("node1", settings);
|
|
||||||
startNode("node2", settings);
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
updateClusterSettings(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue