-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tyler Ohlsen <[email protected]>
- Loading branch information
Showing
5 changed files
with
116 additions
and
0 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
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
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/org/opensearch/commons/alerting/action/SearchMonitorRequest.kt
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,38 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.commons.alerting.action | ||
|
||
import org.opensearch.action.ActionRequest | ||
import org.opensearch.action.ActionRequestValidationException | ||
import org.opensearch.action.search.SearchRequest | ||
import org.opensearch.core.common.io.stream.StreamInput | ||
import org.opensearch.core.common.io.stream.StreamOutput | ||
import java.io.IOException | ||
|
||
class SearchMonitorRequest : ActionRequest { | ||
|
||
val searchRequest: SearchRequest | ||
|
||
constructor( | ||
searchRequest: SearchRequest | ||
) : super() { | ||
this.searchRequest = searchRequest | ||
Check warning on line 22 in src/main/kotlin/org/opensearch/commons/alerting/action/SearchMonitorRequest.kt Codecov / codecov/patchsrc/main/kotlin/org/opensearch/commons/alerting/action/SearchMonitorRequest.kt#L21-L22
|
||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
searchRequest = SearchRequest(sin) | ||
) | ||
Check warning on line 28 in src/main/kotlin/org/opensearch/commons/alerting/action/SearchMonitorRequest.kt Codecov / codecov/patchsrc/main/kotlin/org/opensearch/commons/alerting/action/SearchMonitorRequest.kt#L26-L28
|
||
|
||
override fun validate(): ActionRequestValidationException? { | ||
return null | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
searchRequest.writeTo(out) | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
src/test/kotlin/org/opensearch/commons/alerting/action/SearchMonitorRequestTests.kt
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,33 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.commons.alerting.action | ||
|
||
import org.opensearch.action.search.SearchRequest | ||
import org.opensearch.common.io.stream.BytesStreamOutput | ||
import org.opensearch.common.unit.TimeValue | ||
import org.opensearch.core.common.io.stream.StreamInput | ||
import org.opensearch.search.builder.SearchSourceBuilder | ||
import org.opensearch.test.OpenSearchTestCase | ||
import org.opensearch.test.rest.OpenSearchRestTestCase | ||
import java.util.concurrent.TimeUnit | ||
|
||
class SearchMonitorRequestTests : OpenSearchTestCase() { | ||
|
||
fun `test search monitors request`() { | ||
val searchSourceBuilder = SearchSourceBuilder().from(0).size(100).timeout(TimeValue(60, TimeUnit.SECONDS)) | ||
val searchRequest = SearchRequest().indices(OpenSearchRestTestCase.randomAlphaOfLength(10)).source(searchSourceBuilder) | ||
val searchMonitorRequest = SearchMonitorRequest(searchRequest) | ||
assertNotNull(searchMonitorRequest) | ||
|
||
val out = BytesStreamOutput() | ||
searchMonitorRequest.writeTo(out) | ||
val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) | ||
val newReq = SearchMonitorRequest(sin) | ||
|
||
assertNotNull(newReq.searchRequest) | ||
assertEquals(1, newReq.searchRequest.indices().size) | ||
} | ||
} |