-
Notifications
You must be signed in to change notification settings - Fork 116
Added function for request recreation that considers the writeable re… #303
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -4,10 +4,16 @@ import org.junit.jupiter.api.Assertions | |
| import org.junit.jupiter.api.Test | ||
| import org.opensearch.action.support.WriteRequest | ||
| import org.opensearch.common.io.stream.BytesStreamOutput | ||
| import org.opensearch.common.io.stream.NamedWriteableAwareStreamInput | ||
| import org.opensearch.common.io.stream.NamedWriteableRegistry | ||
| import org.opensearch.common.io.stream.StreamInput | ||
| import org.opensearch.common.settings.Settings | ||
| import org.opensearch.commons.alerting.model.SearchInput | ||
| import org.opensearch.commons.alerting.randomBucketLevelMonitor | ||
| import org.opensearch.commons.alerting.randomQueryLevelMonitor | ||
| import org.opensearch.commons.utils.recreateObject | ||
| import org.opensearch.rest.RestRequest | ||
| import org.opensearch.search.SearchModule | ||
| import org.opensearch.search.builder.SearchSourceBuilder | ||
|
|
||
| class IndexMonitorRequestTests { | ||
|
|
@@ -32,6 +38,42 @@ class IndexMonitorRequestTests { | |
| Assertions.assertNotNull(newReq.monitor) | ||
| } | ||
|
|
||
| @Test | ||
| fun `test index bucket monitor post request`() { | ||
| val req = IndexMonitorRequest( | ||
| "1234", 1L, 2L, WriteRequest.RefreshPolicy.IMMEDIATE, RestRequest.Method.POST, | ||
| randomBucketLevelMonitor() | ||
| ) | ||
| Assertions.assertNotNull(req) | ||
|
|
||
| val out = BytesStreamOutput() | ||
| req.writeTo(out) | ||
| val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) | ||
| val namedWriteableRegistry = NamedWriteableRegistry(SearchModule(Settings.EMPTY, emptyList()).namedWriteables) | ||
| val newReq = IndexMonitorRequest(NamedWriteableAwareStreamInput(sin, namedWriteableRegistry)) | ||
| Assertions.assertEquals("1234", newReq.monitorId) | ||
| Assertions.assertEquals(1L, newReq.seqNo) | ||
| Assertions.assertEquals(2L, newReq.primaryTerm) | ||
| Assertions.assertEquals(RestRequest.Method.POST, newReq.method) | ||
| Assertions.assertNotNull(newReq.monitor) | ||
| } | ||
|
|
||
| @Test | ||
| fun `Index bucket monitor serialize and deserialize transport object should be equal`() { | ||
| val req = IndexMonitorRequest( | ||
| "1234", 1L, 2L, WriteRequest.RefreshPolicy.IMMEDIATE, RestRequest.Method.POST, | ||
| randomBucketLevelMonitor() | ||
| ) | ||
|
|
||
| val recreatedObject = recreateObject(req, NamedWriteableRegistry(SearchModule(Settings.EMPTY, emptyList()).namedWriteables)) { IndexMonitorRequest(it) } | ||
|
Member
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. let's have a test method where recreate object method WITHOUT NamedWriteableRegistry fails and in the same method let's verify that recreate Object WITH NamedWriteableRegistry passes using an actual aggregation in IndexMonitorRequest.
Contributor
Author
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. Good point. Let me try to do that |
||
| Assertions.assertEquals(req.monitorId, recreatedObject.monitorId) | ||
| Assertions.assertEquals(req.seqNo, recreatedObject.seqNo) | ||
| Assertions.assertEquals(req.primaryTerm, recreatedObject.primaryTerm) | ||
| Assertions.assertEquals(req.method, recreatedObject.method) | ||
| Assertions.assertNotNull(recreatedObject.monitor) | ||
| Assertions.assertEquals(req.monitor, recreatedObject.monitor) | ||
| } | ||
|
|
||
| @Test | ||
| fun `test index monitor put request`() { | ||
|
|
||
|
|
||
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.
let's not overload index monitor method. Let's change the original method's signature
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.
Yeah sure. Tnx