Use #assertAcked() for verification.
This commit is contained in:
parent
8257370415
commit
1608ccc373
|
@ -39,18 +39,14 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.index.engine.DocumentMissingException;
|
import org.elasticsearch.index.engine.DocumentMissingException;
|
||||||
import org.elasticsearch.index.engine.VersionConflictEngineException;
|
import org.elasticsearch.index.engine.VersionConflictEngineException;
|
||||||
import org.elasticsearch.index.mapper.DocumentTypeListener;
|
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
|
||||||
import org.elasticsearch.index.query.FilterBuilders;
|
import org.elasticsearch.index.query.FilterBuilders;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.elasticsearch.index.query.functionscore.factor.FactorBuilder;
|
import org.elasticsearch.index.query.functionscore.factor.FactorBuilder;
|
||||||
import org.elasticsearch.indices.IndicesService;
|
|
||||||
import org.elasticsearch.search.highlight.HighlightBuilder;
|
import org.elasticsearch.search.highlight.HighlightBuilder;
|
||||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
|
|
||||||
import static org.elasticsearch.action.percolate.PercolateSourceBuilder.docBuilder;
|
import static org.elasticsearch.action.percolate.PercolateSourceBuilder.docBuilder;
|
||||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||||
|
@ -58,6 +54,7 @@ import static org.elasticsearch.common.xcontent.XContentFactory.*;
|
||||||
import static org.elasticsearch.index.query.FilterBuilders.termFilter;
|
import static org.elasticsearch.index.query.FilterBuilders.termFilter;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||||
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.scriptFunction;
|
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.scriptFunction;
|
||||||
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
|
@ -342,7 +339,7 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createIndexAndThenRegisterPercolator() throws Exception {
|
public void createIndexAndThenRegisterPercolator() throws Exception {
|
||||||
client().admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
|
assertAcked(client().admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 1)));
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
logger.info("--> register a query");
|
logger.info("--> register a query");
|
||||||
|
@ -1482,12 +1479,7 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
assertThat(response.getCount(), equalTo(2l));
|
assertThat(response.getCount(), equalTo(2l));
|
||||||
|
|
||||||
CountDownLatch test1Latch = createCountDownLatch("test1");
|
assertAcked(client().admin().indices().prepareDeleteMapping("test1").setType(PercolatorService.TYPE_NAME));
|
||||||
CountDownLatch test2Latch = createCountDownLatch("test2");
|
|
||||||
|
|
||||||
client().admin().indices().prepareDeleteMapping("test1").setType(PercolatorService.TYPE_NAME).execute().actionGet();
|
|
||||||
test1Latch.await();
|
|
||||||
|
|
||||||
response = client().preparePercolate()
|
response = client().preparePercolate()
|
||||||
.setIndices("test1", "test2").setDocumentType("type").setOnlyCount(true)
|
.setIndices("test1", "test2").setDocumentType("type").setOnlyCount(true)
|
||||||
.setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject()))
|
.setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject()))
|
||||||
|
@ -1495,10 +1487,8 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
|
||||||
assertNoFailures(response);
|
assertNoFailures(response);
|
||||||
assertThat(response.getCount(), equalTo(1l));
|
assertThat(response.getCount(), equalTo(1l));
|
||||||
|
|
||||||
client().admin().indices().prepareDeleteMapping("test2").setType(PercolatorService.TYPE_NAME).execute().actionGet();
|
assertAcked(client().admin().indices().prepareDeleteMapping("test2").setType(PercolatorService.TYPE_NAME));
|
||||||
test2Latch.await();
|
// Percolate api should return 0 matches, because all docs in _percolate type have been removed.
|
||||||
|
|
||||||
// Percolate api should return 0 matches, because all _percolate types have been removed.
|
|
||||||
response = client().preparePercolate()
|
response = client().preparePercolate()
|
||||||
.setIndices("test1", "test2").setDocumentType("type").setOnlyCount(true)
|
.setIndices("test1", "test2").setDocumentType("type").setOnlyCount(true)
|
||||||
.setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject()))
|
.setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject()))
|
||||||
|
@ -1507,25 +1497,6 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
|
||||||
assertThat(response.getCount(), equalTo(0l));
|
assertThat(response.getCount(), equalTo(0l));
|
||||||
}
|
}
|
||||||
|
|
||||||
private CountDownLatch createCountDownLatch(String index) {
|
|
||||||
final CountDownLatch latch = new CountDownLatch(cluster().size());
|
|
||||||
Iterable<IndicesService> mapperServices = cluster().getInstances(IndicesService.class);
|
|
||||||
for (IndicesService indicesService : mapperServices) {
|
|
||||||
MapperService mapperService = indicesService.indexService(index).mapperService();
|
|
||||||
mapperService.addTypeListener(new DocumentTypeListener() {
|
|
||||||
@Override
|
|
||||||
public void created(String type) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removed(String type) {
|
|
||||||
latch.countDown();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return latch;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String[] convertFromTextArray(PercolateResponse.Match[] matches, String index) {
|
public static String[] convertFromTextArray(PercolateResponse.Match[] matches, String index) {
|
||||||
if (matches.length == 0) {
|
if (matches.length == 0) {
|
||||||
return Strings.EMPTY_ARRAY;
|
return Strings.EMPTY_ARRAY;
|
||||||
|
|
|
@ -50,6 +50,7 @@ import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||||
import static org.elasticsearch.percolator.PercolatorTests.convertFromTextArray;
|
import static org.elasticsearch.percolator.PercolatorTests.convertFromTextArray;
|
||||||
import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
|
import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
|
||||||
import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;
|
import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;
|
||||||
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
|
@ -223,9 +224,8 @@ public class RecoveryPercolatorTests extends ElasticsearchIntegrationTest {
|
||||||
assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("95", "96", "97", "98", "99", "100"));
|
assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("95", "96", "97", "98", "99", "100"));
|
||||||
|
|
||||||
logger.info("--> Close and open index to trigger percolate queries loading...");
|
logger.info("--> Close and open index to trigger percolate queries loading...");
|
||||||
client().admin().indices().prepareClose("test").execute().actionGet();
|
assertAcked(client().admin().indices().prepareClose("test"));
|
||||||
ensureGreen();
|
assertAcked(client().admin().indices().prepareOpen("test"));
|
||||||
client().admin().indices().prepareOpen("test").execute().actionGet();
|
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
logger.info("--> Percolate doc with field1=100");
|
logger.info("--> Percolate doc with field1=100");
|
||||||
|
|
Loading…
Reference in New Issue