stabelize more tests

This commit is contained in:
Simon Willnauer 2013-06-20 17:04:00 +02:00
parent 178629382c
commit 7206c60019
2 changed files with 21 additions and 11 deletions

View File

@ -35,12 +35,17 @@ import org.testng.annotations.Test;
public class SearchWhileCreatingIndexTests extends AbstractSharedClusterTest { public class SearchWhileCreatingIndexTests extends AbstractSharedClusterTest {
protected int numberOfNodes() {
return 1;
}
/** /**
* This test basically verifies that search with a single shard active (cause we indexed to it) and other * This test basically verifies that search with a single shard active (cause we indexed to it) and other
* shards possibly not active at all (cause they haven't allocated) will still work. * shards possibly not active at all (cause they haven't allocated) will still work.
*/ */
@Test @Test
public void searchWhileCreatingIndex() { public void searchWhileCreatingIndex() {
cluster().ensureAtMostNumNodes(1); // this test is very fragile with more than one node...
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
run(prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 10))); run(prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 10)));
run(client().prepareIndex("test", "type1", "id:" + i).setSource("field", "test")); run(client().prepareIndex("test", "type1", "id:" + i).setSource("field", "test"));

View File

@ -1,5 +1,9 @@
package org.elasticsearch.test.integration.search.msearch; package org.elasticsearch.test.integration.search.msearch;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFirstHit;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -15,24 +19,25 @@ public class SimpleMultiSearchTests extends AbstractSharedClusterTest {
@Test @Test
public void simpleMultiSearch() { public void simpleMultiSearch() {
client().admin().indices().prepareDelete().execute().actionGet(); createIndex("test");
ensureGreen();
client().prepareIndex("test", "type", "1").setSource("field", "xxx").execute().actionGet(); client().prepareIndex("test", "type", "1").setSource("field", "xxx").execute().actionGet();
client().prepareIndex("test", "type", "2").setSource("field", "yyy").execute().actionGet(); client().prepareIndex("test", "type", "2").setSource("field", "yyy").execute().actionGet();
refresh();
client().admin().indices().prepareRefresh().execute().actionGet();
MultiSearchResponse response = client().prepareMultiSearch() MultiSearchResponse response = client().prepareMultiSearch()
.add(client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "xxx"))) .add(client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "xxx")))
.add(client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "yyy"))) .add(client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "yyy")))
.add(client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery())) .add(client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery()))
.execute().actionGet(); .execute().actionGet();
for (MultiSearchResponse.Item item : response) {
assertNoFailures(item.getResponse());
}
assertThat(response.getResponses().length, equalTo(3)); assertThat(response.getResponses().length, equalTo(3));
assertThat(response.getResponses()[0].getResponse().getHits().totalHits(), equalTo(1l)); assertHitCount(response.getResponses()[0].getResponse(), 1l);
assertThat(response.getResponses()[1].getResponse().getHits().totalHits(), equalTo(1l)); assertHitCount(response.getResponses()[1].getResponse(), 1l);
assertThat(response.getResponses()[2].getResponse().getHits().totalHits(), equalTo(2l)); assertHitCount(response.getResponses()[2].getResponse(), 2l);
assertFirstHit(response.getResponses()[0].getResponse(), hasId("1"));
assertThat(response.getResponses()[0].getResponse().getHits().getAt(0).id(), equalTo("1")); assertFirstHit(response.getResponses()[1].getResponse(), hasId("2"));
assertThat(response.getResponses()[1].getResponse().getHits().getAt(0).id(), equalTo("2"));
} }
} }