fix percolate stats tests failures

This commit is contained in:
Shay Banon 2013-07-21 14:25:26 +02:00
parent 09362f47e9
commit 6a25395c97
2 changed files with 119 additions and 112 deletions

View File

@ -19,11 +19,6 @@
package org.elasticsearch.test.integration.indices.stats; package org.elasticsearch.test.integration.indices.stats;
import java.io.IOException;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.Random;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.stats.CommonStats; import org.elasticsearch.action.admin.indices.stats.CommonStats;
import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags; import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags;
@ -36,12 +31,15 @@ import org.elasticsearch.common.Priority;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.BytesStreamInput; import org.elasticsearch.common.io.stream.BytesStreamInput;
import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.test.integration.AbstractNodesTests; import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.io.IOException;
import java.util.EnumSet;
import java.util.Random;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
@ -328,8 +326,8 @@ public class SimpleIndexStatsTests extends AbstractNodesTests {
@Test @Test
public void testFlagOrdinalOrder() { public void testFlagOrdinalOrder() {
Flag[] flags = new Flag[] { Flag.Store, Flag.Indexing, Flag.Get, Flag.Search, Flag.Merge, Flag.Flush, Flag.Refresh, Flag[] flags = new Flag[]{Flag.Store, Flag.Indexing, Flag.Get, Flag.Search, Flag.Merge, Flag.Flush, Flag.Refresh,
Flag.FilterCache, Flag.IdCache, Flag.FieldData, Flag.Docs, Flag.Warmer }; Flag.FilterCache, Flag.IdCache, Flag.FieldData, Flag.Docs, Flag.Warmer, Flag.Percolate};
assertThat(flags.length, equalTo(Flag.values().length)); assertThat(flags.length, equalTo(Flag.values().length));
for (int i = 0; i < flags.length; i++) { for (int i = 0; i < flags.length; i++) {
@ -338,78 +336,83 @@ public class SimpleIndexStatsTests extends AbstractNodesTests {
} }
private static void set(Flag flag, IndicesStatsRequestBuilder builder, boolean set) { private static void set(Flag flag, IndicesStatsRequestBuilder builder, boolean set) {
switch(flag) { switch (flag) {
case Docs: case Docs:
builder.setDocs(set); builder.setDocs(set);
break; break;
case FieldData: case FieldData:
builder.setFieldData(set); builder.setFieldData(set);
break; break;
case FilterCache: case FilterCache:
builder.setFilterCache(set); builder.setFilterCache(set);
break; break;
case Flush: case Flush:
builder.setFlush(set); builder.setFlush(set);
break; break;
case Get: case Get:
builder.setGet(set); builder.setGet(set);
break; break;
case IdCache: case IdCache:
builder.setIdCache(set); builder.setIdCache(set);
break; break;
case Indexing: case Indexing:
builder.setIndexing(set); builder.setIndexing(set);
break; break;
case Merge: case Merge:
builder.setMerge(set); builder.setMerge(set);
break; break;
case Refresh: case Refresh:
builder.setRefresh(set); builder.setRefresh(set);
break; break;
case Search: case Search:
builder.setSearch(set); builder.setSearch(set);
break; break;
case Store: case Store:
builder.setStore(set); builder.setStore(set);
break; break;
case Warmer: case Warmer:
builder.setWarmer(set); builder.setWarmer(set);
break; break;
default: case Percolate:
assert false : "new flag? " + flag; builder.setPercolate(set);
break; break;
default:
assert false : "new flag? " + flag;
break;
} }
} }
private static boolean isSet(Flag flag, CommonStats response) { private static boolean isSet(Flag flag, CommonStats response) {
switch(flag) { switch (flag) {
case Docs: case Docs:
return response.getDocs() != null; return response.getDocs() != null;
case FieldData: case FieldData:
return response.getFieldData() != null; return response.getFieldData() != null;
case FilterCache: case FilterCache:
return response.getFilterCache() != null; return response.getFilterCache() != null;
case Flush: case Flush:
return response.getFlush() != null; return response.getFlush() != null;
case Get: case Get:
return response.getGet() != null; return response.getGet() != null;
case IdCache: case IdCache:
return response.getIdCache() != null; return response.getIdCache() != null;
case Indexing: case Indexing:
return response.getIndexing() != null; return response.getIndexing() != null;
case Merge: case Merge:
return response.getMerge() != null; return response.getMerge() != null;
case Refresh: case Refresh:
return response.getRefresh() != null; return response.getRefresh() != null;
case Search: case Search:
return response.getSearch() != null; return response.getSearch() != null;
case Store: case Store:
return response.getStore() != null; return response.getStore() != null;
case Warmer: case Warmer:
return response.getWarmer() != null; return response.getWarmer() != null;
default: case Percolate:
assert false : "new flag? " + flag; return response.getPercolate() != null;
return false; default:
assert false : "new flag? " + flag;
return false;
} }
} }

View File

@ -266,15 +266,15 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
builder.put("index.analysis.tokenizer.whitespacecomma.pattern", "(,|\\s+)"); builder.put("index.analysis.tokenizer.whitespacecomma.pattern", "(,|\\s+)");
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("doc") XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("doc")
.startObject("properties") .startObject("properties")
.startObject("filingcategory").field("type", "string").field("analyzer", "lwhitespacecomma").endObject() .startObject("filingcategory").field("type", "string").field("analyzer", "lwhitespacecomma").endObject()
.endObject() .endObject()
.endObject().endObject(); .endObject().endObject();
client().admin().indices().prepareCreate("test") client().admin().indices().prepareCreate("test")
.addMapping("doc", mapping) .addMapping("doc", mapping)
.setSettings(builder.put("index.number_of_shards", 1)) .setSettings(builder.put("index.number_of_shards", 1))
.execute().actionGet(); .execute().actionGet();
ensureGreen(); ensureGreen();
logger.info("--> register a query"); logger.info("--> register a query");
@ -514,7 +514,8 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
IndicesStatsResponse indicesResponse = client().admin().indices().prepareStats("test").execute().actionGet(); IndicesStatsResponse indicesResponse = client().admin().indices().prepareStats("test").execute().actionGet();
assertThat(indicesResponse.getTotal().getPercolate().getCount(), equalTo(5l)); // We have 5 partitions assertThat(indicesResponse.getTotal().getPercolate().getCount(), equalTo(5l)); // We have 5 partitions
assertThat(indicesResponse.getTotal().getPercolate().getTimeInMillis(), greaterThan(0l)); // it might be too fast to be counted in milliseconds...
//assertThat(indicesResponse.getTotal().getPercolate().getTimeInMillis(), greaterThan(0l));
assertThat(indicesResponse.getTotal().getPercolate().getCurrent(), equalTo(0l)); assertThat(indicesResponse.getTotal().getPercolate().getCurrent(), equalTo(0l));
NodesStatsResponse nodesResponse = client().admin().cluster().prepareNodesStats().execute().actionGet(); NodesStatsResponse nodesResponse = client().admin().cluster().prepareNodesStats().execute().actionGet();
@ -525,7 +526,8 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
percolateSumTime += nodeStats.getIndices().getPercolate().getTimeInMillis(); percolateSumTime += nodeStats.getIndices().getPercolate().getTimeInMillis();
} }
assertThat(percolateCount, equalTo(5l)); // We have 5 partitions assertThat(percolateCount, equalTo(5l)); // We have 5 partitions
assertThat(percolateSumTime, greaterThan(0l)); // it might be too fast to be counted in milliseconds...
//assertThat(percolateSumTime, greaterThan(0l));
logger.info("--> Second percolate request"); logger.info("--> Second percolate request");
response = client().preparePercolate("test", "type") response = client().preparePercolate("test", "type")
@ -536,7 +538,8 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
indicesResponse = client().admin().indices().prepareStats().setPercolate(true).execute().actionGet(); indicesResponse = client().admin().indices().prepareStats().setPercolate(true).execute().actionGet();
assertThat(indicesResponse.getTotal().getPercolate().getCount(), equalTo(10l)); assertThat(indicesResponse.getTotal().getPercolate().getCount(), equalTo(10l));
assertThat(indicesResponse.getTotal().getPercolate().getTimeInMillis(), greaterThan(0l)); // it might be too fast to be counted in milliseconds...
//assertThat(indicesResponse.getTotal().getPercolate().getTimeInMillis(), greaterThan(0l));
assertThat(indicesResponse.getTotal().getPercolate().getCurrent(), equalTo(0l)); assertThat(indicesResponse.getTotal().getPercolate().getCurrent(), equalTo(0l));
nodesResponse = client().admin().cluster().prepareNodesStats().execute().actionGet(); nodesResponse = client().admin().cluster().prepareNodesStats().execute().actionGet();
@ -547,7 +550,8 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
percolateSumTime += nodeStats.getIndices().getPercolate().getTimeInMillis(); percolateSumTime += nodeStats.getIndices().getPercolate().getTimeInMillis();
} }
assertThat(percolateCount, equalTo(10l)); assertThat(percolateCount, equalTo(10l));
assertThat(percolateSumTime, greaterThan(0l)); // it might be too fast to be counted in milliseconds...
//assertThat(percolateSumTime, greaterThan(0l));
} }
public static String[] convertFromTextArray(Text[] texts) { public static String[] convertFromTextArray(Text[] texts) {