forked from opensearch-project/cross-cluster-replication
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handled batch requests for replication metadata update under cluster …
…state (opensearch-project#772) (opensearch-project#785) Signed-off-by: Sai Kumar <[email protected]>
- Loading branch information
1 parent
981ddef
commit dc5cd13
Showing
2 changed files
with
89 additions
and
9 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
75 changes: 75 additions & 0 deletions
75
...lin/com/amazon/elasticsearch/replication/metadata/state/UpdateReplicationMetadataTests.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,75 @@ | ||
package com.amazon.elasticsearch.replication.metadata.state | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope | ||
import org.junit.Assert | ||
import org.elasticsearch.cluster.ClusterState | ||
import com.amazon.elasticsearch.replication.action.replicationstatedetails.UpdateReplicationStateDetailsRequest | ||
import com.amazon.elasticsearch.replication.metadata.ReplicationOverallState | ||
import com.amazon.elasticsearch.replication.metadata.UpdateReplicationStateDetailsTaskExecutor | ||
import org.elasticsearch.test.ClusterServiceUtils | ||
import org.elasticsearch.test.ESTestCase | ||
import org.elasticsearch.threadpool.TestThreadPool | ||
|
||
@ThreadLeakScope(ThreadLeakScope.Scope.NONE) | ||
class UpdateReplicationMetadataTests : ESTestCase() { | ||
|
||
var threadPool = TestThreadPool("ReplicationPluginTest") | ||
var clusterService = ClusterServiceUtils.createClusterService(threadPool) | ||
|
||
fun `test single task update`() { | ||
val currentState: ClusterState = clusterService.state() | ||
// single task | ||
val tasks = arrayListOf(UpdateReplicationStateDetailsRequest("test-index", | ||
hashMapOf("REPLICATION_LAST_KNOWN_OVERALL_STATE" to "RUNNING"), UpdateReplicationStateDetailsRequest.UpdateType.ADD)) | ||
val tasksResult = UpdateReplicationStateDetailsTaskExecutor.INSTANCE.execute(currentState, tasks) | ||
|
||
val updatedReplicationDetails = tasksResult.resultingState?.metadata | ||
?.custom<ReplicationStateMetadata>(ReplicationStateMetadata.NAME)?.replicationDetails | ||
|
||
Assert.assertNotNull(updatedReplicationDetails) | ||
Assert.assertNotNull(updatedReplicationDetails?.get("test-index")) | ||
val replicationStateParams = updatedReplicationDetails?.get("test-index") | ||
|
||
Assert.assertEquals(ReplicationOverallState.RUNNING.name, replicationStateParams?.get(REPLICATION_LAST_KNOWN_OVERALL_STATE)) | ||
} | ||
|
||
fun `test multiple tasks to add replication metadata`() { | ||
val currentState: ClusterState = clusterService.state() | ||
// multiple tasks | ||
val tasks = arrayListOf(UpdateReplicationStateDetailsRequest("test-index-1", | ||
hashMapOf("REPLICATION_LAST_KNOWN_OVERALL_STATE" to "RUNNING"), UpdateReplicationStateDetailsRequest.UpdateType.ADD), | ||
UpdateReplicationStateDetailsRequest("test-index-2", | ||
hashMapOf("REPLICATION_LAST_KNOWN_OVERALL_STATE" to "RUNNING"), UpdateReplicationStateDetailsRequest.UpdateType.ADD)) | ||
val tasksResult = UpdateReplicationStateDetailsTaskExecutor.INSTANCE.execute(currentState, tasks) | ||
|
||
val updatedReplicationDetails = tasksResult.resultingState?.metadata | ||
?.custom<ReplicationStateMetadata>(ReplicationStateMetadata.NAME)?.replicationDetails | ||
|
||
Assert.assertNotNull(updatedReplicationDetails) | ||
Assert.assertNotNull(updatedReplicationDetails?.get("test-index-1")) | ||
var replicationStateParams = updatedReplicationDetails?.get("test-index-1") | ||
Assert.assertEquals(ReplicationOverallState.RUNNING.name, replicationStateParams?.get(REPLICATION_LAST_KNOWN_OVERALL_STATE)) | ||
Assert.assertNotNull(updatedReplicationDetails?.get("test-index-2")) | ||
replicationStateParams = updatedReplicationDetails?.get("test-index-2") | ||
Assert.assertEquals(ReplicationOverallState.RUNNING.name, replicationStateParams?.get(REPLICATION_LAST_KNOWN_OVERALL_STATE)) | ||
} | ||
|
||
fun `test multiple tasks to add and delete replication metadata`() { | ||
val currentState: ClusterState = clusterService.state() | ||
// multiple tasks | ||
val tasks = arrayListOf(UpdateReplicationStateDetailsRequest("test-index-1", | ||
hashMapOf("REPLICATION_LAST_KNOWN_OVERALL_STATE" to "RUNNING"), UpdateReplicationStateDetailsRequest.UpdateType.ADD), | ||
UpdateReplicationStateDetailsRequest("test-index-2", | ||
hashMapOf("REPLICATION_LAST_KNOWN_OVERALL_STATE" to "RUNNING"), UpdateReplicationStateDetailsRequest.UpdateType.REMOVE)) | ||
val tasksResult = UpdateReplicationStateDetailsTaskExecutor.INSTANCE.execute(currentState, tasks) | ||
|
||
val updatedReplicationDetails = tasksResult.resultingState?.metadata | ||
?.custom<ReplicationStateMetadata>(ReplicationStateMetadata.NAME)?.replicationDetails | ||
|
||
Assert.assertNotNull(updatedReplicationDetails) | ||
Assert.assertNotNull(updatedReplicationDetails?.get("test-index-1")) | ||
var replicationStateParams = updatedReplicationDetails?.get("test-index-1") | ||
Assert.assertEquals(ReplicationOverallState.RUNNING.name, replicationStateParams?.get(REPLICATION_LAST_KNOWN_OVERALL_STATE)) | ||
Assert.assertNull(updatedReplicationDetails?.get("test-index-2")) | ||
} | ||
} |