Skip to content

Commit 131a05f

Browse files
committed
modify tests
correct docs remove tags disabling auto formatting
1 parent dda7951 commit 131a05f

File tree

5 files changed

+11
-18
lines changed

5 files changed

+11
-18
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ClusterClientDocumentationIT.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public void testClusterPutSettings() throws IOException {
6363
ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest();
6464
// end::put-settings-request
6565

66-
// @formatter:off
6766
// tag::put-settings-create-settings
6867
String transientSettingKey =
6968
RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey();
@@ -82,41 +81,34 @@ public void testClusterPutSettings() throws IOException {
8281
.put(persistentSettingKey, persistentSettingValue)
8382
.build(); // <2>
8483
// end::put-settings-create-settings
85-
// @formatter:on
8684

8785
// tag::put-settings-request-cluster-settings
8886
request.transientSettings(transientSettings); // <1>
8987
request.persistentSettings(persistentSettings); // <2>
9088
// end::put-settings-request-cluster-settings
9189

9290
{
93-
// @formatter:off
9491
// tag::put-settings-settings-builder
9592
Settings.Builder transientSettingsBuilder =
9693
Settings.builder()
9794
.put(transientSettingKey, transientSettingValue, ByteSizeUnit.BYTES);
9895
request.transientSettings(transientSettingsBuilder); // <1>
9996
// end::put-settings-settings-builder
100-
// @formatter:on
10197
}
10298
{
103-
// @formatter:off
10499
// tag::put-settings-settings-map
105100
Map<String, Object> map = new HashMap<>();
106101
map.put(transientSettingKey
107102
, transientSettingValue + ByteSizeUnit.BYTES.getSuffix());
108103
request.transientSettings(map); // <1>
109104
// end::put-settings-settings-map
110-
// @formatter:on
111105
}
112106
{
113-
// @formatter:off
114107
// tag::put-settings-settings-source
115108
request.transientSettings(
116109
"{\"indices.recovery.max_bytes_per_sec\": \"10b\"}"
117110
, XContentType.JSON); // <1>
118111
// end::put-settings-settings-source
119-
// @formatter:on
120112
}
121113

122114
// tag::put-settings-request-timeout
@@ -159,7 +151,6 @@ public void testClusterUpdateSettingsAsync() throws Exception {
159151
{
160152
ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest();
161153

162-
//@formatter:off
163154
// tag::put-settings-execute-listener
164155
ActionListener<ClusterUpdateSettingsResponse> listener =
165156
new ActionListener<ClusterUpdateSettingsResponse>() {
@@ -174,7 +165,6 @@ public void onFailure(Exception e) {
174165
}
175166
};
176167
// end::put-settings-execute-listener
177-
//@formatter:on
178168

179169
// Replace the empty listener by a blocking listener in test
180170
final CountDownLatch latch = new CountDownLatch(1);

docs/java-rest/high-level/cluster/put_settings.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[java-rest-high-cluster-put-settings]]
22
=== Cluster Update Settings API
33

4-
The Cluster Put Settings API allows to update cluster wide settings.
4+
The Cluster Update Settings API allows to update cluster wide settings.
55

66
[[java-rest-high-cluster-put-settings-request]]
77
==== Cluster Update Settings Request

server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestTests.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
import org.elasticsearch.common.xcontent.XContentParser;
2525
import org.elasticsearch.common.xcontent.XContentType;
2626
import org.elasticsearch.test.ESTestCase;
27+
import org.elasticsearch.test.XContentTestUtils;
2728

2829
import java.io.IOException;
30+
import java.util.Collections;
2931

30-
import static org.elasticsearch.test.XContentTestUtils.insertRandomFields;
3132
import static org.hamcrest.CoreMatchers.equalTo;
3233

3334
public class ClusterUpdateSettingsRequestTests extends ESTestCase {
@@ -47,11 +48,13 @@ private void doFromXContentTestWithRandomFields(boolean addRandomFields) throws
4748
BytesReference originalBytes = toShuffledXContent(request, xContentType, ToXContent.EMPTY_PARAMS, humanReadable);
4849

4950
if (addRandomFields) {
50-
BytesReference mutated = insertRandomFields(xContentType, originalBytes,
51-
p -> p.startsWith("transient") || p.startsWith("persistent"), random());
52-
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
51+
String unsupportedField = "unsupported_field";
52+
BytesReference mutated = XContentTestUtils.insertIntoXContent(xContentType.xContent(), originalBytes,
53+
Collections.singletonList(""), () -> unsupportedField, () -> randomAlphaOfLengthBetween(3, 10)).bytes();
54+
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class,
5355
() -> ClusterUpdateSettingsRequest.fromXContent(createParser(xContentType.xContent(), mutated)));
54-
assertTrue(e.getMessage().matches("\\[cluster_update_settings_request\\] unknown field \\[\\w*\\], parser not found"));
56+
assertThat(iae.getMessage(),
57+
equalTo("[cluster_update_settings_request] unknown field [" + unsupportedField + "], parser not found"));
5558
} else {
5659
XContentParser parser = createParser(xContentType.xContent(), originalBytes);
5760
ClusterUpdateSettingsRequest parsedRequest = ClusterUpdateSettingsRequest.fromXContent(parser);

test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
3030
import com.carrotsearch.randomizedtesting.generators.RandomStrings;
3131
import com.carrotsearch.randomizedtesting.rules.TestRuleAdapter;
32+
3233
import org.apache.logging.log4j.Level;
3334
import org.apache.logging.log4j.LogManager;
3435
import org.apache.logging.log4j.Logger;
@@ -146,7 +147,6 @@
146147
import static java.util.Collections.emptyMap;
147148
import static java.util.Collections.singletonList;
148149
import static org.elasticsearch.common.util.CollectionUtils.arrayAsArrayList;
149-
import static org.elasticsearch.test.XContentTestUtils.insertRandomFields;
150150
import static org.hamcrest.Matchers.empty;
151151
import static org.hamcrest.Matchers.equalTo;
152152
import static org.hamcrest.Matchers.hasItem;

test/framework/src/main/java/org/elasticsearch/test/XContentTestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static List<String> getInsertPaths(XContentParser parser, Stack<String> currentP
286286
* {@link ObjectPath}.
287287
* The key/value arguments can suppliers that either return fixed or random values.
288288
*/
289-
static XContentBuilder insertIntoXContent(XContent xContent, BytesReference original, List<String> paths, Supplier<String> key,
289+
public static XContentBuilder insertIntoXContent(XContent xContent, BytesReference original, List<String> paths, Supplier<String> key,
290290
Supplier<Object> value) throws IOException {
291291
ObjectPath object = ObjectPath.createFromXContent(xContent, original);
292292
for (String path : paths) {

0 commit comments

Comments
 (0)