Search in sources :

Example 1 with WriteStateException

use of org.opensearch.gateway.WriteStateException in project OpenSearch by opensearch-project.

the class RetentionLeaseBackgroundSyncActionTests method testRetentionLeaseBackgroundSyncActionOnReplica.

public void testRetentionLeaseBackgroundSyncActionOnReplica() throws WriteStateException {
    final IndicesService indicesService = mock(IndicesService.class);
    final Index index = new Index("index", "uuid");
    final IndexService indexService = mock(IndexService.class);
    when(indicesService.indexServiceSafe(index)).thenReturn(indexService);
    final int id = randomIntBetween(0, 4);
    final IndexShard indexShard = mock(IndexShard.class);
    when(indexService.getShard(id)).thenReturn(indexShard);
    final ShardId shardId = new ShardId(index, id);
    when(indexShard.shardId()).thenReturn(shardId);
    final RetentionLeaseBackgroundSyncAction action = new RetentionLeaseBackgroundSyncAction(Settings.EMPTY, transportService, clusterService, indicesService, threadPool, shardStateAction, new ActionFilters(Collections.emptySet()));
    final RetentionLeases retentionLeases = mock(RetentionLeases.class);
    final RetentionLeaseBackgroundSyncAction.Request request = new RetentionLeaseBackgroundSyncAction.Request(indexShard.shardId(), retentionLeases);
    final PlainActionFuture<TransportReplicationAction.ReplicaResult> listener = PlainActionFuture.newFuture();
    action.shardOperationOnReplica(request, indexShard, listener);
    final TransportReplicationAction.ReplicaResult result = listener.actionGet();
    // the retention leases on the shard should be updated
    verify(indexShard).updateRetentionLeasesOnReplica(retentionLeases);
    // the retention leases on the shard should be persisted
    verify(indexShard).persistRetentionLeases();
    // the result should indicate success
    final AtomicBoolean success = new AtomicBoolean();
    result.runPostReplicaActions(ActionListener.wrap(r -> success.set(true), e -> fail(e.toString())));
    assertTrue(success.get());
}
Also used : ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndexShard(org.opensearch.index.shard.IndexShard) WriteStateException(org.opensearch.gateway.WriteStateException) LatchedActionListener(org.opensearch.action.LatchedActionListener) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) ActionListener(org.opensearch.action.ActionListener) ShardStateAction(org.opensearch.cluster.action.shard.ShardStateAction) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) Index(org.opensearch.index.Index) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) IndicesService(org.opensearch.indices.IndicesService) Settings(org.opensearch.common.settings.Settings) Mockito.when(org.mockito.Mockito.when) TransportReplicationAction(org.opensearch.action.support.replication.TransportReplicationAction) IndexService(org.opensearch.index.IndexService) TransportService(org.opensearch.transport.TransportService) Mockito.verify(org.mockito.Mockito.verify) IOUtils(org.opensearch.core.internal.io.IOUtils) ShardId(org.opensearch.index.shard.ShardId) ActionFilters(org.opensearch.action.support.ActionFilters) CountDownLatch(java.util.concurrent.CountDownLatch) ActionTestUtils(org.opensearch.action.support.ActionTestUtils) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ClusterService(org.opensearch.cluster.service.ClusterService) CapturingTransport(org.opensearch.test.transport.CapturingTransport) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) IndexService(org.opensearch.index.IndexService) IndexShard(org.opensearch.index.shard.IndexShard) IndicesService(org.opensearch.indices.IndicesService) Index(org.opensearch.index.Index) ActionFilters(org.opensearch.action.support.ActionFilters) TransportReplicationAction(org.opensearch.action.support.replication.TransportReplicationAction) ShardId(org.opensearch.index.shard.ShardId) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Aggregations

Collections (java.util.Collections)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Matchers.sameInstance (org.hamcrest.Matchers.sameInstance)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.when (org.mockito.Mockito.when)1 ActionListener (org.opensearch.action.ActionListener)1 LatchedActionListener (org.opensearch.action.LatchedActionListener)1 ActionFilters (org.opensearch.action.support.ActionFilters)1 ActionTestUtils (org.opensearch.action.support.ActionTestUtils)1 PlainActionFuture (org.opensearch.action.support.PlainActionFuture)1 TransportReplicationAction (org.opensearch.action.support.replication.TransportReplicationAction)1 ShardStateAction (org.opensearch.cluster.action.shard.ShardStateAction)1 ClusterService (org.opensearch.cluster.service.ClusterService)1 Settings (org.opensearch.common.settings.Settings)1 IOUtils (org.opensearch.core.internal.io.IOUtils)1 WriteStateException (org.opensearch.gateway.WriteStateException)1 Index (org.opensearch.index.Index)1 IndexService (org.opensearch.index.IndexService)1