Use #assertAcked() for verification.

This commit is contained in:
Martijn van Groningen 2013-11-20 12:55:48 +01:00
parent 8257370415
commit 1608ccc373
2 changed files with 8 additions and 37 deletions

View File

@ -39,18 +39,14 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.engine.DocumentMissingException;
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.QueryBuilders;
import org.elasticsearch.index.query.functionscore.factor.FactorBuilder;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.search.highlight.HighlightBuilder;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.Test;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import static org.elasticsearch.action.percolate.PercolateSourceBuilder.docBuilder;
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.QueryBuilders.*;
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.hamcrest.Matchers.*;
@ -342,7 +339,7 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
@Test
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();
logger.info("--> register a query");
@ -1482,12 +1479,7 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
.execute().actionGet();
assertThat(response.getCount(), equalTo(2l));
CountDownLatch test1Latch = createCountDownLatch("test1");
CountDownLatch test2Latch = createCountDownLatch("test2");
client().admin().indices().prepareDeleteMapping("test1").setType(PercolatorService.TYPE_NAME).execute().actionGet();
test1Latch.await();
assertAcked(client().admin().indices().prepareDeleteMapping("test1").setType(PercolatorService.TYPE_NAME));
response = client().preparePercolate()
.setIndices("test1", "test2").setDocumentType("type").setOnlyCount(true)
.setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject()))
@ -1495,10 +1487,8 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
assertNoFailures(response);
assertThat(response.getCount(), equalTo(1l));
client().admin().indices().prepareDeleteMapping("test2").setType(PercolatorService.TYPE_NAME).execute().actionGet();
test2Latch.await();
// Percolate api should return 0 matches, because all _percolate types have been removed.
assertAcked(client().admin().indices().prepareDeleteMapping("test2").setType(PercolatorService.TYPE_NAME));
// Percolate api should return 0 matches, because all docs in _percolate type have been removed.
response = client().preparePercolate()
.setIndices("test1", "test2").setDocumentType("type").setOnlyCount(true)
.setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject()))
@ -1507,25 +1497,6 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
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) {
if (matches.length == 0) {
return Strings.EMPTY_ARRAY;

View File

@ -50,6 +50,7 @@ import static org.elasticsearch.index.query.QueryBuilders.*;
import static org.elasticsearch.percolator.PercolatorTests.convertFromTextArray;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
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.hamcrest.Matchers.*;
@ -223,9 +224,8 @@ public class RecoveryPercolatorTests extends ElasticsearchIntegrationTest {
assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("95", "96", "97", "98", "99", "100"));
logger.info("--> Close and open index to trigger percolate queries loading...");
client().admin().indices().prepareClose("test").execute().actionGet();
ensureGreen();
client().admin().indices().prepareOpen("test").execute().actionGet();
assertAcked(client().admin().indices().prepareClose("test"));
assertAcked(client().admin().indices().prepareOpen("test"));
ensureGreen();
logger.info("--> Percolate doc with field1=100");