Skip to content

Commit

Permalink
Handle serialization issues with UpdateReplicationStateDetailsRequest (
Browse files Browse the repository at this point in the history
…#866)

Signed-off-by: Ankit Kala <[email protected]>
  • Loading branch information
ankitkala authored May 23, 2023
1 parent e3256eb commit 3e3787d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class UpdateReplicationStateDetailsRequest: AcknowledgedRequest<UpdateReplicatio
override fun writeTo(out: StreamOutput) {
super.writeTo(out)
out.writeString(followIndexName)
out.writeMap(replicationStateParams)
out.writeMap(replicationStateParams, StreamOutput::writeString, StreamOutput::writeString)
out.writeEnum(updateType)
}
}
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"]))
}
}

0 comments on commit 3e3787d

Please sign in to comment.