Skip to content

Commit

Permalink
Backport: Add description to force-merge tasks (#41365) (#45191)
Browse files Browse the repository at this point in the history
* Add description to force-merge tasks (#41365)

This is static information that is part of the force merge request.

Relates to #15975
  • Loading branch information
martijnvg authored Aug 8, 2019
1 parent fca458f commit fb959d1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.test.ESTestCase;

public class ForceMergeRequestTests extends ESTestCase {

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

0 comments on commit fb959d1

Please sign in to comment.