forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* master: Expose retention leases in shard stats (elastic#37991) Make primary terms fields private in index shard (elastic#38036) ML: Add reason field in JobTaskState (elastic#38029) Log flush_stats and commit_stats in testMaybeFlush HLRC: Fix strict setting exception handling (elastic#37247) Test: Enable strict deprecation on all tests (elastic#36558) Removes typed calls from YAML REST tests (elastic#37611) Switch default time format for ingest from Joda to Java for v7 (elastic#37934) Remove deprecated Plugin#onModule extension points (elastic#37866) Geo: Fix Empty Geometry Collection Handling (elastic#37978)
- Loading branch information
Showing
297 changed files
with
2,205 additions
and
2,657 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
client/rest-high-level/src/test/java/org/elasticsearch/client/MockRestHighLevelTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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.HttpHost; | ||
import org.apache.http.ProtocolVersion; | ||
import org.apache.http.RequestLine; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.message.BasicRequestLine; | ||
import org.apache.http.message.BasicStatusLine; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.junit.Before; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class MockRestHighLevelTests extends ESTestCase { | ||
private RestHighLevelClient client; | ||
private static final List<String> WARNINGS = Collections.singletonList("Some Warning"); | ||
|
||
@Before | ||
private void setupClient() throws IOException { | ||
final RestClient mockClient = mock(RestClient.class); | ||
final Response mockResponse = mock(Response.class); | ||
|
||
when(mockResponse.getHost()).thenReturn(new HttpHost("localhost", 9200)); | ||
when(mockResponse.getWarnings()).thenReturn(WARNINGS); | ||
|
||
ProtocolVersion protocol = new ProtocolVersion("HTTP", 1, 1); | ||
when(mockResponse.getStatusLine()).thenReturn(new BasicStatusLine(protocol, 200, "OK")); | ||
|
||
RequestLine requestLine = new BasicRequestLine(HttpGet.METHOD_NAME, "/_blah", protocol); | ||
when(mockResponse.getRequestLine()).thenReturn(requestLine); | ||
|
||
WarningFailureException expectedException = new WarningFailureException(mockResponse); | ||
doThrow(expectedException).when(mockClient).performRequest(any()); | ||
|
||
client = new RestHighLevelClient(mockClient, RestClient::close, Collections.emptyList()); | ||
} | ||
|
||
public void testWarningFailure() { | ||
WarningFailureException exception = expectThrows(WarningFailureException.class, | ||
() -> client.info(RequestOptions.DEFAULT)); | ||
assertThat(exception.getMessage(), equalTo("method [GET], host [http://localhost:9200], URI [/_blah], " + | ||
"status line [HTTP/1.1 200 OK]")); | ||
assertNull(exception.getCause()); | ||
assertThat(exception.getResponse().getWarnings(), equalTo(WARNINGS)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
client/rest/src/main/java/org/elasticsearch/client/WarningFailureException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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 java.io.IOException; | ||
|
||
import static org.elasticsearch.client.ResponseException.buildMessage; | ||
|
||
/** | ||
* This exception is used to indicate that one or more {@link Response#getWarnings()} exist | ||
* and is typically used when the {@link RestClient} is set to fail by setting | ||
* {@link RestClientBuilder#setStrictDeprecationMode(boolean)} to `true`. | ||
*/ | ||
// This class extends RuntimeException in order to deal with wrapping that is done in FutureUtils on exception. | ||
// if the exception is not of type ElasticsearchException or RuntimeException it will be wrapped in a UncategorizedExecutionException | ||
public final class WarningFailureException extends RuntimeException { | ||
|
||
private final Response response; | ||
|
||
public WarningFailureException(Response response) throws IOException { | ||
super(buildMessage(response)); | ||
this.response = response; | ||
} | ||
|
||
/** | ||
* Wrap a {@linkplain WarningFailureException} with another one with the current | ||
* stack trace. This is used during synchronous calls so that the caller | ||
* ends up in the stack trace of the exception thrown. | ||
*/ | ||
WarningFailureException(WarningFailureException e) { | ||
super(e.getMessage(), e); | ||
this.response = e.getResponse(); | ||
} | ||
|
||
/** | ||
* Returns the {@link Response} that caused this exception to be thrown. | ||
*/ | ||
public Response getResponse() { | ||
return response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.