Skip to content

Commit

Permalink
modify tests
Browse files Browse the repository at this point in the history
correct docs
remove tags disabling auto formatting
  • Loading branch information
olcbean committed Feb 15, 2018
1 parent dda7951 commit 131a05f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public void testClusterPutSettings() throws IOException {
ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest();
// end::put-settings-request

// @formatter:off
// tag::put-settings-create-settings
String transientSettingKey =
RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey();
Expand All @@ -82,41 +81,34 @@ public void testClusterPutSettings() throws IOException {
.put(persistentSettingKey, persistentSettingValue)
.build(); // <2>
// end::put-settings-create-settings
// @formatter:on

// tag::put-settings-request-cluster-settings
request.transientSettings(transientSettings); // <1>
request.persistentSettings(persistentSettings); // <2>
// end::put-settings-request-cluster-settings

{
// @formatter:off
// tag::put-settings-settings-builder
Settings.Builder transientSettingsBuilder =
Settings.builder()
.put(transientSettingKey, transientSettingValue, ByteSizeUnit.BYTES);
request.transientSettings(transientSettingsBuilder); // <1>
// end::put-settings-settings-builder
// @formatter:on
}
{
// @formatter:off
// tag::put-settings-settings-map
Map<String, Object> map = new HashMap<>();
map.put(transientSettingKey
, transientSettingValue + ByteSizeUnit.BYTES.getSuffix());
request.transientSettings(map); // <1>
// end::put-settings-settings-map
// @formatter:on
}
{
// @formatter:off
// tag::put-settings-settings-source
request.transientSettings(
"{\"indices.recovery.max_bytes_per_sec\": \"10b\"}"
, XContentType.JSON); // <1>
// end::put-settings-settings-source
// @formatter:on
}

// tag::put-settings-request-timeout
Expand Down Expand Up @@ -159,7 +151,6 @@ public void testClusterUpdateSettingsAsync() throws Exception {
{
ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest();

//@formatter:off
// tag::put-settings-execute-listener
ActionListener<ClusterUpdateSettingsResponse> listener =
new ActionListener<ClusterUpdateSettingsResponse>() {
Expand All @@ -174,7 +165,6 @@ public void onFailure(Exception e) {
}
};
// end::put-settings-execute-listener
//@formatter:on

// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
Expand Down
2 changes: 1 addition & 1 deletion docs/java-rest/high-level/cluster/put_settings.asciidoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[[java-rest-high-cluster-put-settings]]
=== Cluster Update Settings API

The Cluster Put Settings API allows to update cluster wide settings.
The Cluster Update Settings API allows to update cluster wide settings.

[[java-rest-high-cluster-put-settings-request]]
==== Cluster Update Settings Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.XContentTestUtils;

import java.io.IOException;
import java.util.Collections;

import static org.elasticsearch.test.XContentTestUtils.insertRandomFields;
import static org.hamcrest.CoreMatchers.equalTo;

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

if (addRandomFields) {
BytesReference mutated = insertRandomFields(xContentType, originalBytes,
p -> p.startsWith("transient") || p.startsWith("persistent"), random());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
String unsupportedField = "unsupported_field";
BytesReference mutated = XContentTestUtils.insertIntoXContent(xContentType.xContent(), originalBytes,
Collections.singletonList(""), () -> unsupportedField, () -> randomAlphaOfLengthBetween(3, 10)).bytes();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class,
() -> ClusterUpdateSettingsRequest.fromXContent(createParser(xContentType.xContent(), mutated)));
assertTrue(e.getMessage().matches("\\[cluster_update_settings_request\\] unknown field \\[\\w*\\], parser not found"));
assertThat(iae.getMessage(),
equalTo("[cluster_update_settings_request] unknown field [" + unsupportedField + "], parser not found"));
} else {
XContentParser parser = createParser(xContentType.xContent(), originalBytes);
ClusterUpdateSettingsRequest parsedRequest = ClusterUpdateSettingsRequest.fromXContent(parser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
import com.carrotsearch.randomizedtesting.generators.RandomStrings;
import com.carrotsearch.randomizedtesting.rules.TestRuleAdapter;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -146,7 +147,6 @@
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static org.elasticsearch.common.util.CollectionUtils.arrayAsArrayList;
import static org.elasticsearch.test.XContentTestUtils.insertRandomFields;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ static List<String> getInsertPaths(XContentParser parser, Stack<String> currentP
* {@link ObjectPath}.
* The key/value arguments can suppliers that either return fixed or random values.
*/
static XContentBuilder insertIntoXContent(XContent xContent, BytesReference original, List<String> paths, Supplier<String> key,
public static XContentBuilder insertIntoXContent(XContent xContent, BytesReference original, List<String> paths, Supplier<String> key,
Supplier<Object> value) throws IOException {
ObjectPath object = ObjectPath.createFromXContent(xContent, original);
for (String path : paths) {
Expand Down

0 comments on commit 131a05f

Please sign in to comment.