From d19214ad0c7719d9f56d1cc25f5ba0a6e46fe940 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 5 Aug 2019 12:00:18 +0200 Subject: [PATCH 1/2] Add description to force-merge tasks (#41365) This is static information that is part of the force merge request. Relates to #15975 --- .../elasticsearch/client/IndicesClientIT.java | 4 ++ .../indices/forcemerge/ForceMergeRequest.java | 9 +++ .../forcemerge/ForceMergeRequestTests.java | 68 +++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java index 17b3121cd0b62..c880c859dccdc 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java @@ -1045,6 +1045,8 @@ public void testForceMerge() throws IOException { assertThat(forceMergeResponse.getSuccessfulShards(), equalTo(1)); assertThat(forceMergeResponse.getFailedShards(), equalTo(0)); assertThat(forceMergeResponse.getShardFailures(), equalTo(BroadcastResponse.EMPTY)); + + assertThat(forceMergeRequest.getDescription(), containsString(index)); } { String nonExistentIndex = "non_existent_index"; @@ -1053,6 +1055,8 @@ public void testForceMerge() throws IOException { ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(forceMergeRequest, highLevelClient().indices()::forcemerge, highLevelClient().indices()::forcemergeAsync)); assertEquals(RestStatus.NOT_FOUND, exception.status()); + + assertThat(forceMergeRequest.getDescription(), containsString(nonExistentIndex)); } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequest.java index b7fa9094540a7..20480c45f10a5 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequest.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import java.io.IOException; +import java.util.Arrays; /** * A request to force merging the segments of one or more indices. In order to @@ -114,6 +115,14 @@ public ForceMergeRequest flush(boolean flush) { return this; } + @Override + public String getDescription() { + return "Force-merge indices " + Arrays.toString(indices()) + + ", maxSegments[" + maxNumSegments + + "], onlyExpungeDeletes[" + onlyExpungeDeletes + + "], flush[" + flush + "]"; + } + @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java new file mode 100644 index 0000000000000..a4e6c581d1966 --- /dev/null +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java @@ -0,0 +1,68 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.action.admin.indices.forcemerge; + +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.test.ESTestCase; + +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; + +public class ForceMergeRequestTests extends ESTestCase { + + public void testValidate() { + final boolean flush = randomBoolean(); + final boolean onlyExpungeDeletes = randomBoolean(); + final int maxNumSegments = randomIntBetween(ForceMergeRequest.Defaults.MAX_NUM_SEGMENTS, 100); + + final ForceMergeRequest request = new ForceMergeRequest(); + request.flush(flush); + request.onlyExpungeDeletes(onlyExpungeDeletes); + request.maxNumSegments(maxNumSegments); + + assertThat(request.flush(), equalTo(flush)); + assertThat(request.onlyExpungeDeletes(), equalTo(onlyExpungeDeletes)); + assertThat(request.maxNumSegments(), equalTo(maxNumSegments)); + + ActionRequestValidationException validation = request.validate(); + if (onlyExpungeDeletes && maxNumSegments != ForceMergeRequest.Defaults.MAX_NUM_SEGMENTS) { + assertThat(validation, notNullValue()); + assertThat(validation.validationErrors(), contains("cannot set only_expunge_deletes and max_num_segments at the " + + "same time, those two parameters are mutually exclusive")); + } else { + assertThat(validation, nullValue()); + } + } + + public void testDescription() { + ForceMergeRequest request = new ForceMergeRequest(); + assertEquals("Force-merge indices [], maxSegments[-1], onlyExpungeDeletes[false], flush[true]", request.getDescription()); + + request = new ForceMergeRequest("shop", "blog"); + assertEquals("Force-merge indices [shop, blog], maxSegments[-1], onlyExpungeDeletes[false], flush[true]", request.getDescription()); + + request = new ForceMergeRequest(); + request.maxNumSegments(12); + request.onlyExpungeDeletes(true); + request.flush(false); + assertEquals("Force-merge indices [], maxSegments[12], onlyExpungeDeletes[true], flush[false]", request.getDescription()); + } +} From 5a329d17bd40406ad10540cc5fa9df16811d9aba Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 5 Aug 2019 17:27:44 +0700 Subject: [PATCH 2/2] removed test that snuck in when cherry-picking --- .../forcemerge/ForceMergeRequestTests.java | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java index a4e6c581d1966..1054f814105bb 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java @@ -18,40 +18,10 @@ */ package org.elasticsearch.action.admin.indices.forcemerge; -import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.test.ESTestCase; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; - public class ForceMergeRequestTests extends ESTestCase { - public void testValidate() { - final boolean flush = randomBoolean(); - final boolean onlyExpungeDeletes = randomBoolean(); - final int maxNumSegments = randomIntBetween(ForceMergeRequest.Defaults.MAX_NUM_SEGMENTS, 100); - - final ForceMergeRequest request = new ForceMergeRequest(); - request.flush(flush); - request.onlyExpungeDeletes(onlyExpungeDeletes); - request.maxNumSegments(maxNumSegments); - - assertThat(request.flush(), equalTo(flush)); - assertThat(request.onlyExpungeDeletes(), equalTo(onlyExpungeDeletes)); - assertThat(request.maxNumSegments(), equalTo(maxNumSegments)); - - ActionRequestValidationException validation = request.validate(); - if (onlyExpungeDeletes && maxNumSegments != ForceMergeRequest.Defaults.MAX_NUM_SEGMENTS) { - assertThat(validation, notNullValue()); - assertThat(validation.validationErrors(), contains("cannot set only_expunge_deletes and max_num_segments at the " - + "same time, those two parameters are mutually exclusive")); - } else { - assertThat(validation, nullValue()); - } - } - public void testDescription() { ForceMergeRequest request = new ForceMergeRequest(); assertEquals("Force-merge indices [], maxSegments[-1], onlyExpungeDeletes[false], flush[true]", request.getDescription());