-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle serialization issues with UpdateReplicationStateDetailsRequest (…
…#866) Signed-off-by: Ankit Kala <[email protected]>
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
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
42 changes: 42 additions & 0 deletions
42
...h/replication/action/replicationstatedetails/UpdateReplicationStateDetailsRequestTests.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,42 @@ | ||
package org.opensearch.replication.action.replicationstatedetails | ||
|
||
import org.assertj.core.api.Assertions | ||
import org.opensearch.common.io.stream.BytesStreamOutput | ||
import org.opensearch.test.OpenSearchTestCase | ||
|
||
class UpdateReplicationStateDetailsRequestTests: OpenSearchTestCase() { | ||
companion object { | ||
const val INDEX = "index" | ||
} | ||
|
||
fun `test serialization update type add`() { | ||
val state = mapOf(Pair("k1", "v1"), Pair("k2", "v2")) | ||
val request = UpdateReplicationStateDetailsRequest(INDEX, state, UpdateReplicationStateDetailsRequest.UpdateType.ADD) | ||
val output = BytesStreamOutput() | ||
request.writeTo(output) | ||
val deserialized = UpdateReplicationStateDetailsRequest(output.bytes().streamInput()) | ||
|
||
assertEquals(UpdateReplicationStateDetailsRequest.UpdateType.ADD, deserialized.updateType) | ||
assertEquals(INDEX, deserialized.followIndexName) | ||
Assertions.assertThat(deserialized.replicationStateParams.containsKey("k1")) | ||
Assertions.assertThat(deserialized.replicationStateParams.containsKey("k2")) | ||
Assertions.assertThat("v1".equals(deserialized.replicationStateParams["k1"])) | ||
Assertions.assertThat("v2".equals(deserialized.replicationStateParams["k2"])) | ||
} | ||
|
||
fun `test serialization update type delete`() { | ||
val state = mapOf(Pair("k1", "v1"), Pair("k2", "v2")) | ||
val request = UpdateReplicationStateDetailsRequest(INDEX, state, UpdateReplicationStateDetailsRequest.UpdateType.REMOVE) | ||
val output = BytesStreamOutput() | ||
request.writeTo(output) | ||
|
||
val deserialized = UpdateReplicationStateDetailsRequest(output.bytes().streamInput()) | ||
|
||
assertEquals(UpdateReplicationStateDetailsRequest.UpdateType.REMOVE, deserialized.updateType) | ||
assertEquals(INDEX, deserialized.followIndexName) | ||
Assertions.assertThat(deserialized.replicationStateParams.containsKey("k1")) | ||
Assertions.assertThat(deserialized.replicationStateParams.containsKey("k2")) | ||
Assertions.assertThat("v1".equals(deserialized.replicationStateParams["k1"])) | ||
Assertions.assertThat("v2".equals(deserialized.replicationStateParams["k2"])) | ||
} | ||
} |