-
Notifications
You must be signed in to change notification settings - Fork 24.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add delete API to the High Level Rest Client #23187
Merged
dadoonet
merged 12 commits into
elastic:master
from
dadoonet:hlclient/add-delete-method
Feb 24, 2017
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7df1df2
Add delete API to the High Level Rest Client
dadoonet 0bbcd94
Merge branch 'master' into hlclient/add-delete-method
dadoonet 14f0490
Merge with master
dadoonet 5aa2ab3
Fix after 1st review
dadoonet b2ec4c1
Remove a non needed comment
dadoonet efa28e0
Check that we correctly propagate delete request parameters
dadoonet 0ee74f9
Remove createSampleIndexRequest method and provide ids
dadoonet bf8241e
Remove createSampleDocument method and use the sync'ed index method
dadoonet 9bde68e
delete and index tests can share some part of the code
dadoonet b680e62
Merge branch 'master' into hlclient/add-delete-method
dadoonet 4ebc6dd
Fix after last merge with master and apply last comments
dadoonet 3e4b917
Merge branch 'master' into hlclient/add-delete-method
dadoonet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
import org.elasticsearch.action.get.GetRequest; | ||
import org.elasticsearch.action.index.IndexRequest; | ||
import org.elasticsearch.action.support.WriteRequest; | ||
import org.elasticsearch.action.support.replication.ReplicatedWriteRequest; | ||
import org.elasticsearch.action.support.replication.ReplicationRequest; | ||
import org.elasticsearch.action.update.UpdateRequest; | ||
import org.elasticsearch.common.Strings; | ||
|
@@ -69,6 +70,39 @@ public void testGet() { | |
getAndExistsTest(Request::get, "GET"); | ||
} | ||
|
||
public void testDelete() throws IOException { | ||
String index = randomAsciiOfLengthBetween(3, 10); | ||
String type = randomAsciiOfLengthBetween(3, 10); | ||
String id = randomAsciiOfLengthBetween(3, 10); | ||
DeleteRequest deleteRequest = new DeleteRequest(index, type, id); | ||
|
||
Map<String, String> expectedParams = new HashMap<>(); | ||
|
||
setRandomTimeout(deleteRequest, expectedParams); | ||
setRandomRefreshPolicy(deleteRequest, expectedParams); | ||
setRandomVersion(deleteRequest, expectedParams); | ||
setRandomVersionType(deleteRequest, expectedParams); | ||
|
||
if (frequently()) { | ||
if (randomBoolean()) { | ||
String routing = randomAsciiOfLengthBetween(3, 10); | ||
deleteRequest.routing(routing); | ||
expectedParams.put("routing", routing); | ||
} | ||
if (randomBoolean()) { | ||
String parent = randomAsciiOfLengthBetween(3, 10); | ||
deleteRequest.parent(parent); | ||
expectedParams.put("parent", parent); | ||
} | ||
} | ||
|
||
Request request = Request.delete(deleteRequest); | ||
assertEquals("/" + index + "/" + type + "/" + id, request.endpoint); | ||
assertEquals(expectedParams, request.params); | ||
assertEquals("DELETE", request.method); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you check that the request entity is null as well? |
||
assertNull(request.entity); | ||
} | ||
|
||
public void testExists() { | ||
getAndExistsTest(Request::exists, "HEAD"); | ||
} | ||
|
@@ -163,33 +197,16 @@ public void testIndex() throws IOException { | |
} | ||
} | ||
|
||
setRandomTimeout(indexRequest, expectedParams); | ||
setRandomRefreshPolicy(indexRequest, expectedParams); | ||
|
||
// There is some logic around _create endpoint and version/version type | ||
if (indexRequest.opType() == DocWriteRequest.OpType.CREATE) { | ||
indexRequest.version(randomFrom(Versions.MATCH_ANY, Versions.MATCH_DELETED)); | ||
expectedParams.put("version", Long.toString(Versions.MATCH_DELETED)); | ||
} else { | ||
if (randomBoolean()) { | ||
long version = randomFrom(Versions.MATCH_ANY, Versions.MATCH_DELETED, Versions.NOT_FOUND, randomNonNegativeLong()); | ||
indexRequest.version(version); | ||
if (version != Versions.MATCH_ANY) { | ||
expectedParams.put("version", Long.toString(version)); | ||
} | ||
} | ||
if (randomBoolean()) { | ||
VersionType versionType = randomFrom(VersionType.values()); | ||
indexRequest.versionType(versionType); | ||
if (versionType != VersionType.INTERNAL) { | ||
expectedParams.put("version_type", versionType.name().toLowerCase(Locale.ROOT)); | ||
} | ||
} | ||
} | ||
|
||
if (randomBoolean()) { | ||
String timeout = randomTimeValue(); | ||
indexRequest.timeout(timeout); | ||
expectedParams.put("timeout", timeout); | ||
} else { | ||
expectedParams.put("timeout", ReplicationRequest.DEFAULT_TIMEOUT.getStringRep()); | ||
setRandomVersion(indexRequest, expectedParams); | ||
setRandomVersionType(indexRequest, expectedParams); | ||
} | ||
|
||
if (frequently()) { | ||
|
@@ -208,14 +225,6 @@ public void testIndex() throws IOException { | |
indexRequest.setPipeline(pipeline); | ||
expectedParams.put("pipeline", pipeline); | ||
} | ||
|
||
if (randomBoolean()) { | ||
WriteRequest.RefreshPolicy refreshPolicy = randomFrom(WriteRequest.RefreshPolicy.values()); | ||
indexRequest.setRefreshPolicy(refreshPolicy); | ||
if (refreshPolicy != WriteRequest.RefreshPolicy.NONE) { | ||
expectedParams.put("refresh", refreshPolicy.getValue()); | ||
} | ||
} | ||
} | ||
|
||
XContentType xContentType = randomFrom(XContentType.values()); | ||
|
@@ -676,4 +685,44 @@ private static void randomizeFetchSourceContextParams(Consumer<FetchSourceContex | |
} | ||
} | ||
} | ||
} | ||
|
||
private static void setRandomTimeout(ReplicationRequest<?> request, Map<String, String> expectedParams) { | ||
if (randomBoolean()) { | ||
String timeout = randomTimeValue(); | ||
request.timeout(timeout); | ||
expectedParams.put("timeout", timeout); | ||
} else { | ||
expectedParams.put("timeout", ReplicationRequest.DEFAULT_TIMEOUT.getStringRep()); | ||
} | ||
} | ||
|
||
private static void setRandomRefreshPolicy(ReplicatedWriteRequest<?> request, Map<String, String> expectedParams) { | ||
if (randomBoolean()) { | ||
WriteRequest.RefreshPolicy refreshPolicy = randomFrom(WriteRequest.RefreshPolicy.values()); | ||
request.setRefreshPolicy(refreshPolicy); | ||
if (refreshPolicy != WriteRequest.RefreshPolicy.NONE) { | ||
expectedParams.put("refresh", refreshPolicy.getValue()); | ||
} | ||
} | ||
} | ||
|
||
private static void setRandomVersion(DocWriteRequest<?> request, Map<String, String> expectedParams) { | ||
if (randomBoolean()) { | ||
long version = randomFrom(Versions.MATCH_ANY, Versions.MATCH_DELETED, Versions.NOT_FOUND, randomNonNegativeLong()); | ||
request.version(version); | ||
if (version != Versions.MATCH_ANY) { | ||
expectedParams.put("version", Long.toString(version)); | ||
} | ||
} | ||
} | ||
|
||
private static void setRandomVersionType(DocWriteRequest<?> request, Map<String, String> expectedParams) { | ||
if (randomBoolean()) { | ||
VersionType versionType = randomFrom(VersionType.values()); | ||
request.versionType(versionType); | ||
if (versionType != VersionType.INTERNAL) { | ||
expectedParams.put("version_type", versionType.name().toLowerCase(Locale.ROOT)); | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should test this in RequestTests and have unit tests to make sure that all supported parameters are propagated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to test the Params builder actually?
Something like:
I can add it in the PR or later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the above is that useful, I would rather like to make sure that the new method to generate a request calls all of the with* methods that need to be called and the params from map to request are all propagated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand. So test something like the following?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes something along those lines. we have existing tests for this in RequestTests, see e.g. testIndex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pointer. I did that in RequestTests.