Skip to content

Commit

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

Signed-off-by: Ankit Kala <[email protected]>
  • Loading branch information
ankitkala committed May 25, 2023
1 parent dc5cd13 commit f727632
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.elasticsearch.action.support.master.AcknowledgedRequest
import org.elasticsearch.common.io.stream.StreamInput
import org.elasticsearch.common.io.stream.StreamOutput


class UpdateReplicationStateDetailsRequest: AcknowledgedRequest<UpdateReplicationStateDetailsRequest> {

val followIndexName : String
Expand Down Expand Up @@ -52,6 +53,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 com.amazon.elasticsearch.replication.action.replicationstatedetails

import org.assertj.core.api.Assertions
import org.elasticsearch.common.io.stream.BytesStreamOutput
import org.elasticsearch.test.ESTestCase

class UpdateReplicationStateDetailsRequestTests: ESTestCase() {
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 f727632

Please sign in to comment.