Tests: Move logSegmentsState to shared location, and remove no longer

needed verbose logging from upgrade test.
This commit is contained in:
Ryan Ernst 2014-10-31 14:57:27 -07:00
parent b4cad96597
commit 2ebf34b93e
2 changed files with 20 additions and 30 deletions

View File

@ -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<Object>() {
@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";

View File

@ -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());