Skip to content

Commit

Permalink
Merge branch 'master' into replicated-closed-indices
Browse files Browse the repository at this point in the history
  • Loading branch information
tlrx committed Feb 25, 2019
2 parents 4db7fd9 + 222dc3e commit d0cf376
Show file tree
Hide file tree
Showing 74 changed files with 1,295 additions and 361 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*
* 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.client;

import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.ccr.CcrStatsRequest;
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.FollowConfig;
import org.elasticsearch.client.ccr.FollowInfoRequest;
import org.elasticsearch.client.ccr.FollowStatsRequest;
import org.elasticsearch.client.ccr.GetAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.PauseFollowRequest;
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.PutFollowRequest;
import org.elasticsearch.client.ccr.ResumeFollowRequest;
import org.elasticsearch.client.ccr.UnfollowRequest;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.test.ESTestCase;

import java.util.Arrays;
import java.util.Locale;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;

public class CcrRequestConvertersTests extends ESTestCase {

public void testPutFollow() throws Exception {
PutFollowRequest putFollowRequest = new PutFollowRequest(randomAlphaOfLength(4), randomAlphaOfLength(4), randomAlphaOfLength(4),
randomBoolean() ? randomFrom(ActiveShardCount.NONE, ActiveShardCount.ONE, ActiveShardCount.DEFAULT, ActiveShardCount.ALL) : null
);
randomizeRequest(putFollowRequest);
Request result = CcrRequestConverters.putFollow(putFollowRequest);
assertThat(result.getMethod(), equalTo(HttpPut.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/" + putFollowRequest.getFollowerIndex() + "/_ccr/follow"));
if (putFollowRequest.waitForActiveShards() != null && putFollowRequest.waitForActiveShards() != ActiveShardCount.DEFAULT) {
String expectedValue = putFollowRequest.waitForActiveShards().toString().toLowerCase(Locale.ROOT);
assertThat(result.getParameters().get("wait_for_active_shards"), equalTo(expectedValue));
} else {
assertThat(result.getParameters().size(), equalTo(0));
}
RequestConvertersTests.assertToXContentBody(putFollowRequest, result.getEntity());
}

public void testPauseFollow() {
PauseFollowRequest pauseFollowRequest = new PauseFollowRequest(randomAlphaOfLength(4));
Request result = CcrRequestConverters.pauseFollow(pauseFollowRequest);
assertThat(result.getMethod(), equalTo(HttpPost.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/" + pauseFollowRequest.getFollowerIndex() + "/_ccr/pause_follow"));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}

public void testResumeFollow() throws Exception {
ResumeFollowRequest resumeFollowRequest = new ResumeFollowRequest(randomAlphaOfLength(4));
Request result = CcrRequestConverters.resumeFollow(resumeFollowRequest);
assertThat(result.getMethod(), equalTo(HttpPost.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/" + resumeFollowRequest.getFollowerIndex() + "/_ccr/resume_follow"));
assertThat(result.getParameters().size(), equalTo(0));
RequestConvertersTests.assertToXContentBody(resumeFollowRequest, result.getEntity());
}

public void testUnfollow() {
UnfollowRequest pauseFollowRequest = new UnfollowRequest(randomAlphaOfLength(4));
Request result = CcrRequestConverters.unfollow(pauseFollowRequest);
assertThat(result.getMethod(), equalTo(HttpPost.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/" + pauseFollowRequest.getFollowerIndex() + "/_ccr/unfollow"));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}

public void testPutAutofollowPattern() throws Exception {
PutAutoFollowPatternRequest putAutoFollowPatternRequest = new PutAutoFollowPatternRequest(randomAlphaOfLength(4),
randomAlphaOfLength(4), Arrays.asList(generateRandomStringArray(4, 4, false)));
if (randomBoolean()) {
putAutoFollowPatternRequest.setFollowIndexNamePattern(randomAlphaOfLength(4));
}
randomizeRequest(putAutoFollowPatternRequest);

Request result = CcrRequestConverters.putAutoFollowPattern(putAutoFollowPatternRequest);
assertThat(result.getMethod(), equalTo(HttpPut.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/_ccr/auto_follow/" + putAutoFollowPatternRequest.getName()));
assertThat(result.getParameters().size(), equalTo(0));
RequestConvertersTests.assertToXContentBody(putAutoFollowPatternRequest, result.getEntity());
}

public void testDeleteAutofollowPattern() throws Exception {
DeleteAutoFollowPatternRequest deleteAutoFollowPatternRequest = new DeleteAutoFollowPatternRequest(randomAlphaOfLength(4));

Request result = CcrRequestConverters.deleteAutoFollowPattern(deleteAutoFollowPatternRequest);
assertThat(result.getMethod(), equalTo(HttpDelete.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/_ccr/auto_follow/" + deleteAutoFollowPatternRequest.getName()));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}

public void testGetAutofollowPattern() throws Exception {
GetAutoFollowPatternRequest deleteAutoFollowPatternRequest = new GetAutoFollowPatternRequest(randomAlphaOfLength(4));

Request result = CcrRequestConverters.getAutoFollowPattern(deleteAutoFollowPatternRequest);
assertThat(result.getMethod(), equalTo(HttpGet.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/_ccr/auto_follow/" + deleteAutoFollowPatternRequest.getName()));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}

public void testGetCcrStats() throws Exception {
CcrStatsRequest ccrStatsRequest = new CcrStatsRequest();
Request result = CcrRequestConverters.getCcrStats(ccrStatsRequest);
assertThat(result.getMethod(), equalTo(HttpGet.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/_ccr/stats"));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}

public void testGetFollowStats() throws Exception {
FollowStatsRequest followStatsRequest = new FollowStatsRequest(randomAlphaOfLength(4));
Request result = CcrRequestConverters.getFollowStats(followStatsRequest);
assertThat(result.getMethod(), equalTo(HttpGet.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/" + followStatsRequest.getFollowerIndex() + "/_ccr/stats"));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}

public void testGetFollowInfo() throws Exception {
FollowInfoRequest followInfoRequest = new FollowInfoRequest(randomAlphaOfLength(4));
Request result = CcrRequestConverters.getFollowInfo(followInfoRequest);
assertThat(result.getMethod(), equalTo(HttpGet.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/" + followInfoRequest.getFollowerIndex() + "/_ccr/info"));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}

private static void randomizeRequest(FollowConfig request) {
if (randomBoolean()) {
request.setMaxOutstandingReadRequests(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
request.setMaxOutstandingWriteRequests(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
request.setMaxReadRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
request.setMaxReadRequestSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
request.setMaxWriteBufferCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
request.setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
request.setMaxWriteRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
request.setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
request.setMaxRetryDelay(new TimeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
request.setReadPollTimeout(new TimeValue(randomNonNegativeLong()));
}
}

}
4 changes: 2 additions & 2 deletions dev-tools/es_release_notes.pl
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ sub dump_issues {
:pull: https://github.com/${User_Repo}pull/
[[release-notes-$version]]
== $version Release Notes
== {es} version $version
coming[$version]
Also see <<breaking-changes-$branch>>.
Also see <<breaking-changes-$branch,Breaking changes in $branch>>.
ASCIIDOC

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import org.elasticsearch.test.ESTestCase;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
import org.mockito.internal.util.collections.Sets;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -112,7 +112,7 @@ public void testBasicMatch() {
String delimiterFirstInput = "";
String delimiterFirstPattern = "";
//parallel arrays
List<String> expectedKeys = Arrays.asList(generateRandomStringArray(100, 10, false, false));
List<String> expectedKeys = new ArrayList<>(Sets.newSet(generateRandomStringArray(100, 10, false, false)));
List<String> expectedValues = new ArrayList<>(expectedKeys.size());
for (String key : expectedKeys) {
String value = randomAsciiAlphanumOfLengthBetween(1, 100);
Expand All @@ -127,7 +127,6 @@ public void testBasicMatch() {
assertMatch(delimiterFirstPattern, delimiterFirstInput, expectedKeys, expectedValues);
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/39244")
public void testBasicMatchUnicode() {
String valueFirstInput = "";
String keyFirstPattern = "";
Expand All @@ -138,6 +137,9 @@ public void testBasicMatchUnicode() {
List<String> expectedValues = new ArrayList<>();
for (int i = 0; i < randomIntBetween(1, 100); i++) {
String key = randomAsciiAlphanumOfLengthBetween(1, 100);
while (expectedKeys.contains(key)) { // keys should be unique in this test
key = randomAsciiAlphanumOfLengthBetween(1, 100);
}
String value = randomRealisticUnicodeOfCodepointLengthBetween(1, 100);
String delimiter = Integer.toString(randomInt()); //int to ensures values and delimiters don't overlap, else validation can fail
keyFirstPattern += "%{" + key + "}" + delimiter;
Expand Down Expand Up @@ -375,13 +377,11 @@ private void assertMatch(String pattern, String input, List<String> expectedKeys

private void assertMatch(String pattern, String input, List<String> expectedKeys, List<String> expectedValues, String appendSeperator) {
Map<String, String> results = new DissectParser(pattern, appendSeperator).parse(input);
List<String> foundKeys = new ArrayList<>(results.keySet());
List<String> foundValues = new ArrayList<>(results.values());
Collections.sort(foundKeys);
Collections.sort(foundValues);
Collections.sort(expectedKeys);
Collections.sort(expectedValues);
assertThat(foundKeys, Matchers.equalTo(expectedKeys));
assertThat(foundValues, Matchers.equalTo(expectedValues));
assertThat(results.size(), Matchers.equalTo(expectedKeys.size()));
assertThat(results.size(), Matchers.equalTo(expectedValues.size()));
for (int i = 0; i < results.size(); i++) {
final String key = expectedKeys.get(i);
assertThat(results.get(key), Matchers.equalTo(expectedValues.get(i)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ setup:
body:
settings:
number_of_replicas: 0
# we need to have 1 shard to get request failure in test "Dense vectors should error with sparse vector functions"
number_of_shards: 1
mappings:
properties:
my_dense_vector:
Expand Down Expand Up @@ -125,10 +127,6 @@ setup:
---
"Dense vectors should error with sparse vector functions":

- skip:
version: "all"
reason: "awaits fix in #39218"

- do:
index:
index: test-index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ setup:
body:
settings:
number_of_replicas: 0
# we need to have 1 shard to get request failure in test "Sparse vectors should error with dense vector functions"
number_of_shards: 1
mappings:
properties:
my_sparse_vector:
Expand Down Expand Up @@ -176,10 +178,6 @@ setup:
---
"Sparse vectors should error with dense vector functions":

- skip:
version: "all"
reason: "awaits fix in #39218"

- do:
index:
index: test-index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public Settings onNodeStopped(String nodeName) throws IOException {
public void testClearVotingTombstonesNotWaitingForRemoval() throws Exception {
internalCluster().setBootstrapMasterNodeIndex(2);
List<String> nodes = internalCluster().startNodes(3);
ensureStableCluster(3);
RestClient restClient = getRestClient();
Response response = restClient.performRequest(new Request("POST", "/_cluster/voting_config_exclusions/" + nodes.get(2)));
assertThat(response.getStatusLine().getStatusCode(), is(200));
Expand All @@ -131,6 +132,7 @@ public void testClearVotingTombstonesNotWaitingForRemoval() throws Exception {
public void testClearVotingTombstonesWaitingForRemoval() throws Exception {
internalCluster().setBootstrapMasterNodeIndex(2);
List<String> nodes = internalCluster().startNodes(3);
ensureStableCluster(3);
RestClient restClient = getRestClient();
String nodeToWithdraw = nodes.get(randomIntBetween(0, 2));
Response response = restClient.performRequest(new Request("POST", "/_cluster/voting_config_exclusions/" + nodeToWithdraw));
Expand All @@ -145,6 +147,7 @@ public void testClearVotingTombstonesWaitingForRemoval() throws Exception {
public void testFailsOnUnknownNode() throws Exception {
internalCluster().setBootstrapMasterNodeIndex(2);
internalCluster().startNodes(3);
ensureStableCluster(3);
RestClient restClient = getRestClient();
try {
restClient.performRequest(new Request("POST", "/_cluster/voting_config_exclusions/invalid"));
Expand Down
Loading

0 comments on commit d0cf376

Please sign in to comment.