From 2ebf34b93ea04a4a3aafd6882c6c6538832a727e Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Fri, 31 Oct 2014 14:57:27 -0700 Subject: [PATCH] Tests: Move logSegmentsState to shared location, and remove no longer needed verbose logging from upgrade test. --- .../admin/indices/upgrade/UpgradeTest.java | 36 ++++--------------- .../test/ElasticsearchIntegrationTest.java | 14 +++++++- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/test/java/org/elasticsearch/rest/action/admin/indices/upgrade/UpgradeTest.java b/src/test/java/org/elasticsearch/rest/action/admin/indices/upgrade/UpgradeTest.java index eb2326d813f..1ffbba781f8 100644 --- a/src/test/java/org/elasticsearch/rest/action/admin/indices/upgrade/UpgradeTest.java +++ b/src/test/java/org/elasticsearch/rest/action/admin/indices/upgrade/UpgradeTest.java @@ -124,8 +124,6 @@ public class UpgradeTest extends ElasticsearchBackwardsCompatIntegrationTest { ensureGreen(indexName); } logger.debug("--> Upgrading nodes"); - logClusterState(); - logSegmentsState(null); backwardsCluster().allowOnAllNodes(indexNames); ensureGreen(); // disable allocation entirely until all nodes are upgraded @@ -139,18 +137,15 @@ public class UpgradeTest extends ElasticsearchBackwardsCompatIntegrationTest { builder.put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE, EnableAllocationDecider.Allocation.ALL); client().admin().cluster().prepareUpdateSettings().setTransientSettings(builder).get(); ensureGreen(); - logger.debug("--> Nodes upgrade complete"); - logClusterState(); - logSegmentsState(null); + logger.info("--> Nodes upgrade complete"); + logSegmentsState(); final HttpRequestBuilder httpClient = httpClient(); assertNotUpgraded(httpClient, null); final String indexToUpgrade = "test" + randomInt(numIndexes - 1); - logger.debug("--> Running upgrade on index " + indexToUpgrade); - logClusterState(); - logSegmentsState(indexToUpgrade); + logger.info("--> Running upgrade on index " + indexToUpgrade); runUpgrade(httpClient, indexToUpgrade); awaitBusy(new Predicate() { @Override @@ -162,31 +157,14 @@ public class UpgradeTest extends ElasticsearchBackwardsCompatIntegrationTest { } } }); - logger.debug("--> Single index upgrade complete"); - logClusterState(); - logSegmentsState(indexToUpgrade); + logger.info("--> Single index upgrade complete"); - logger.debug("--> Running upgrade on the rest of the indexes"); - logClusterState(); - logSegmentsState(null); + logger.info("--> Running upgrade on the rest of the indexes"); runUpgrade(httpClient, null, "wait_for_completion", "true"); - logger.debug("--> Full upgrade complete"); - logClusterState(); - logSegmentsState(null); + logSegmentsState(); + logger.info("--> Full upgrade complete"); assertUpgraded(httpClient, null); } - - void logSegmentsState(String index) throws Exception { - // double check using the segments api that all segments are actually upgraded - IndicesSegmentResponse segsRsp; - if (index == null) { - segsRsp = client().admin().indices().prepareSegments().get(); - } else { - segsRsp = client().admin().indices().prepareSegments(index).get(); - } - XContentBuilder builder = JsonXContent.contentBuilder(); - logger.debug("Segments State: \n\n" + segsRsp.toXContent(builder.prettyPrint(), ToXContent.EMPTY_PARAMS).string()); - } static String upgradePath(String index) { String path = "/_upgrade"; diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java index 7a1b072d480..5da2d061b59 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java @@ -44,6 +44,7 @@ import org.elasticsearch.action.admin.indices.flush.FlushResponse; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; +import org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse; import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder; import org.elasticsearch.action.bulk.BulkRequestBuilder; import org.elasticsearch.action.bulk.BulkResponse; @@ -77,8 +78,10 @@ import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; +import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.discovery.zen.elect.ElectMasterService; import org.elasticsearch.index.codec.CodecService; @@ -1064,12 +1067,21 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase } /** - * Prints the current cluster state as info logging. + * Prints the current cluster state as debug logging. */ public void logClusterState() { logger.debug("cluster state:\n{}\n{}", client().admin().cluster().prepareState().get().getState().prettyPrint(), client().admin().cluster().preparePendingClusterTasks().get().prettyPrint()); } + /** + * Prints the segments info for the given indices as debug logging. + */ + public void logSegmentsState(String... indices) throws Exception { + IndicesSegmentResponse segsRsp = client().admin().indices().prepareSegments(indices).get(); + logger.debug("segments {} state: \n{}", indices.length == 0 ? "[_all]" : indices, + segsRsp.toXContent(JsonXContent.contentBuilder().prettyPrint(), ToXContent.EMPTY_PARAMS).string()); + } + void ensureClusterSizeConsistency() { if (cluster() != null) { // if static init fails the cluster can be null logger.trace("Check consistency for [{}] nodes", cluster().size());