-
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
HLRC: Deactivate Watch API #34192
HLRC: Deactivate Watch API #34192
Changes from 1 commit
6a6df68
cb92865
22ebecb
f52c5fa
be75157
590ae61
e829881
6efaed5
476dc7b
b0c977a
b616452
8c3d516
0214d1b
eb1be97
3d1b605
2076f94
4bc9bcb
5cdb181
707434a
e441b66
febaee0
61a9388
f7b7b16
345cecc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,25 +28,27 @@ public class DeactivateWatchRequest implements Validatable { | |
private final String watchId; | ||
|
||
public DeactivateWatchRequest(String watchId) { | ||
|
||
if (watchId == null) { | ||
ValidationException exception = new ValidationException(); | ||
exception.addValidationError("watch id is missing"); | ||
throw exception; | ||
} else if (PutWatchRequest.isValidId(watchId) == false) { | ||
ValidationException exception = new ValidationException(); | ||
exception.addValidationError("watch id contains whitespace"); | ||
throw exception; | ||
} | ||
|
||
this.watchId = watchId; | ||
} | ||
|
||
public String getWatchId() { | ||
return watchId; | ||
} | ||
|
||
// as per discussion https://github.com/elastic/elasticsearch/pull/34192/files#r221994527, keeping validate method as a no-op relic | ||
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. Feel free to just remove the comment here and the whole method instead of just returning empty since the default does this already. |
||
@Override | ||
public Optional<ValidationException> validate() { | ||
ValidationException exception = new ValidationException(); | ||
|
||
if (watchId == null) { | ||
exception.addValidationError("watch id is missing"); | ||
} else if (PutWatchRequest.isValidId(watchId) == false) { | ||
exception.addValidationError("watch id contains whitespace"); | ||
} | ||
|
||
return exception.validationErrors().isEmpty() | ||
? Optional.empty() // empty indicates no validation errors | ||
: Optional.of(exception); | ||
return Optional.empty(); // empty indicates no validation errors | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,21 +55,19 @@ private PutWatchResponse createWatch(String watchId) throws Exception { | |
|
||
public void testDeactivateWatch() throws Exception { | ||
// Deactivate a watch that exists | ||
{ | ||
String watchId = randomAlphaOfLength(10); | ||
createWatch(watchId); | ||
DeactivateWatchResponse response = highLevelClient().watcher().deactivateWatch( | ||
new DeactivateWatchRequest(watchId), RequestOptions.DEFAULT); | ||
assertThat(response.getStatus().state().isActive(), is(false)); | ||
} | ||
String watchId = randomAlphaOfLength(10); | ||
createWatch(watchId); | ||
DeactivateWatchResponse response = highLevelClient().watcher().deactivateWatch( | ||
new DeactivateWatchRequest(watchId), RequestOptions.DEFAULT); | ||
assertThat(response.getStatus().state().isActive(), is(false)); | ||
} | ||
public void testDeactivateWatch404() throws Exception { | ||
// Deactivate a watch that does not exist | ||
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. worth adding a second test case for imho |
||
{ | ||
String watchId = randomAlphaOfLength(10); | ||
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, | ||
() -> highLevelClient().watcher().deactivateWatch(new DeactivateWatchRequest(watchId), RequestOptions.DEFAULT)); | ||
assertEquals(RestStatus.NOT_FOUND, exception.status()); | ||
String watchId = randomAlphaOfLength(10); | ||
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, | ||
() -> highLevelClient().watcher().deactivateWatch(new DeactivateWatchRequest(watchId), RequestOptions.DEFAULT)); | ||
assertEquals(RestStatus.NOT_FOUND, exception.status()); | ||
|
||
} | ||
} | ||
|
||
public void testDeleteWatch() throws Exception { | ||
|
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.
Sorry I did not explain myself well enuf. This is good, but we dont need the ValidationException here at all, really. You can instead just use
Objects.requireNotNull(obj, msg)
and it will throw exceptions for you. its more concise.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.
so does that mean we don't need to check for white space in the watch id (via
PutWatchRequest.isValidId()
)?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.
You should also validate this as well in the constructor.