Refreshing after green so also recovering replicas will be refreshed.

This commit is contained in:
Boaz Leskes 2013-08-28 08:44:10 +02:00
parent e6dcd137a6
commit 45d4864021
1 changed files with 29 additions and 30 deletions

View File

@ -30,8 +30,7 @@ import org.junit.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.rangeQuery; import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
public class SimpleSearchTests extends AbstractSharedClusterTest { public class SimpleSearchTests extends AbstractSharedClusterTest {
@ -39,14 +38,14 @@ public class SimpleSearchTests extends AbstractSharedClusterTest {
@Test @Test
public void testSearchNullIndex() { public void testSearchNullIndex() {
try { try {
client().prepareSearch((String)null).setQuery(QueryBuilders.termQuery("_id", "XXX1")).execute().actionGet(); client().prepareSearch((String) null).setQuery(QueryBuilders.termQuery("_id", "XXX1")).execute().actionGet();
assert false; assert false;
} catch (ElasticSearchIllegalArgumentException e) { } catch (ElasticSearchIllegalArgumentException e) {
} }
try { try {
client().prepareSearch((String[])null).setQuery(QueryBuilders.termQuery("_id", "XXX1")).execute().actionGet(); client().prepareSearch((String[]) null).setQuery(QueryBuilders.termQuery("_id", "XXX1")).execute().actionGet();
assert false; assert false;
} catch (ElasticSearchIllegalArgumentException e) { } catch (ElasticSearchIllegalArgumentException e) {
@ -115,8 +114,8 @@ public class SimpleSearchTests extends AbstractSharedClusterTest {
prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.mapping.date.parse_upper_inclusive", false)).execute().actionGet(); prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.mapping.date.parse_upper_inclusive", false)).execute().actionGet();
client().prepareIndex("test", "type1", "1").setSource("field", "2010-01-05T02:00").execute().actionGet(); client().prepareIndex("test", "type1", "1").setSource("field", "2010-01-05T02:00").execute().actionGet();
client().prepareIndex("test", "type1", "2").setSource("field", "2010-01-06T02:00").execute().actionGet(); client().prepareIndex("test", "type1", "2").setSource("field", "2010-01-06T02:00").execute().actionGet();
refresh();
ensureGreen(); ensureGreen();
refresh();
// test include upper on ranges to include the full day on the upper bound (disabled here though...) // test include upper on ranges to include the full day on the upper bound (disabled here though...)
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.rangeQuery("field").gte("2010-01-05").lte("2010-01-06")).execute().actionGet(); SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.rangeQuery("field").gte("2010-01-05").lte("2010-01-06")).execute().actionGet();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
@ -130,8 +129,8 @@ public class SimpleSearchTests extends AbstractSharedClusterTest {
prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder()).execute().actionGet(); prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder()).execute().actionGet();
client().prepareIndex("test", "type1", "1").setSource("field", "2010-01-05T02:00").execute().actionGet(); client().prepareIndex("test", "type1", "1").setSource("field", "2010-01-05T02:00").execute().actionGet();
client().prepareIndex("test", "type1", "2").setSource("field", "2010-01-06T02:00").execute().actionGet(); client().prepareIndex("test", "type1", "2").setSource("field", "2010-01-06T02:00").execute().actionGet();
refresh();
ensureGreen(); ensureGreen();
refresh();
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.rangeQuery("field").gte("2010-01-03||+2d").lte("2010-01-04||+2d")).execute().actionGet(); SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.rangeQuery("field").gte("2010-01-03||+2d").lte("2010-01-04||+2d")).execute().actionGet();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().totalHits(), equalTo(2l)); assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
@ -158,8 +157,8 @@ public class SimpleSearchTests extends AbstractSharedClusterTest {
.execute().actionGet(); .execute().actionGet();
ensureGreen(); ensureGreen();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
client().prepareIndex("test", "type1", ""+i).setSource("date_field", "Mi, 06 Dez 2000 02:55:00 -0800").execute().actionGet(); client().prepareIndex("test", "type1", "" + i).setSource("date_field", "Mi, 06 Dez 2000 02:55:00 -0800").execute().actionGet();
client().prepareIndex("test", "type1", ""+(10+i)).setSource("date_field", "Do, 07 Dez 2000 02:55:00 -0800").execute().actionGet(); client().prepareIndex("test", "type1", "" + (10 + i)).setSource("date_field", "Do, 07 Dez 2000 02:55:00 -0800").execute().actionGet();
} }
client().admin().indices().prepareRefresh().execute().actionGet(); client().admin().indices().prepareRefresh().execute().actionGet();
@ -170,7 +169,7 @@ public class SimpleSearchTests extends AbstractSharedClusterTest {
assertThat(searchResponse.getHits().totalHits(), equalTo(10l)); assertThat(searchResponse.getHits().totalHits(), equalTo(10l));
searchResponse = client().prepareSearch("test") searchResponse = client().prepareSearch("test")
.setQuery(QueryBuilders.rangeQuery("date_field").gte( "Di, 05 Dez 2000 02:55:00 -0800").lte("Fr, 08 Dez 2000 00:00:00 -0800")) .setQuery(QueryBuilders.rangeQuery("date_field").gte("Di, 05 Dez 2000 02:55:00 -0800").lte("Fr, 08 Dez 2000 00:00:00 -0800"))
.execute().actionGet(); .execute().actionGet();
assertThat(searchResponse.getHits().totalHits(), equalTo(20l)); assertThat(searchResponse.getHits().totalHits(), equalTo(20l));
} }