Add RamUsageEstimator assertion to ElasticsearchIntegrationTest

This commit is contained in:
Simon Willnauer 2014-02-27 11:25:54 +01:00 committed by Martijn van Groningen
parent 9052838656
commit aacc169007
3 changed files with 31 additions and 1 deletions

View File

@ -47,6 +47,7 @@ import java.util.Random;
import java.util.concurrent.ExecutionException;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSuccessful;
import static org.hamcrest.Matchers.equalTo;
/**
@ -57,6 +58,10 @@ public class RandomExceptionCircuitBreakerTests extends ElasticsearchIntegration
@Test
@TestLogging("org.elasticsearch.indices.fielddata.breaker:TRACE,org.elasticsearch.index.fielddata:TRACE,org.elasticsearch.common.breaker:TRACE")
public void testBreakerWithRandomExceptions() throws IOException, InterruptedException, ExecutionException {
for (NodeStats node : client().admin().cluster().prepareNodesStats()
.clear().setBreaker(true).execute().actionGet().getNodes()) {
assertThat("Breaker is not set to 0", node.getBreaker().getEstimated(), equalTo(0L));
}
final int numShards = between(1, 5);
final int numReplicas = randomIntBetween(0, 1);
String mapping = XContentFactory.jsonBuilder()
@ -174,7 +179,7 @@ public class RandomExceptionCircuitBreakerTests extends ElasticsearchIntegration
// successfully set back to zero. If there is a bug in the circuit
// breaker adjustment code, it should show up here by the breaker
// estimate being either positive or negative.
client().admin().indices().prepareClearCache("test").setFieldDataCache(true).execute().actionGet();
assertAllSuccessful(client().admin().indices().prepareClearCache("test").setFieldDataCache(true).execute().actionGet());
NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats()
.clear().setBreaker(true).execute().actionGet();
for (NodeStats stats : nodeStats.getNodes()) {
@ -184,6 +189,8 @@ public class RandomExceptionCircuitBreakerTests extends ElasticsearchIntegration
}
}
public static final String EXCEPTION_TOP_LEVEL_RATIO_KEY = "index.engine.exception.ratio.top";
public static final String EXCEPTION_LOW_LEVEL_RATIO_KEY = "index.engine.exception.ratio.low";

View File

@ -30,7 +30,10 @@ import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.action.admin.indices.flush.FlushResponse;
@ -248,6 +251,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
.transientSettings().getAsMap().size(), equalTo(0));
}
ensureEstimatedStats();
wipeIndices("_all"); // wipe after to make sure we fail in the test that
// didn't ack the delete
wipeTemplates();
@ -339,6 +343,18 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
return ImmutableSettings.EMPTY;
}
public static void ensureEstimatedStats() {
if (cluster().size() > 0) {
ClearIndicesCacheResponse all = client().admin().indices().prepareClearCache("_all").setFieldDataCache(true).execute().actionGet();
assertNoFailures(all);
NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats()
.clear().setBreaker(true).execute().actionGet();
for (NodeStats stats : nodeStats.getNodes()) {
assertThat("Breaker reset to 0 ", stats.getBreaker().getEstimated(), equalTo(0L));
}
}
}
/**
* Deletes the given indices from the tests cluster. If no index name is passed to this method
* all indices are removed.

View File

@ -193,6 +193,13 @@ public class ElasticsearchAssertions {
assertVersionSerializable(response);
}
public static void assertAllSuccessful(BroadcastOperationResponse response) {
assertNoFailures(response);
assertThat("Expected all shards successful but got successful [" + response.getSuccessfulShards() + "] total [" + response.getTotalShards() + "]",
response.getTotalShards(), equalTo(response.getSuccessfulShards()));
assertVersionSerializable(response);
}
public static void assertSearchHit(SearchHit searchHit, Matcher<SearchHit> matcher) {
assertThat(searchHit, matcher);
assertVersionSerializable(searchHit);