Search in sources :

Example 1 with TransportVerifyShardBeforeCloseAction

use of org.opensearch.action.admin.indices.close.TransportVerifyShardBeforeCloseAction in project OpenSearch by opensearch-project.

the class ReopenWhileClosingIT method interceptVerifyShardBeforeCloseActions.

/**
 * Intercepts and blocks the {@link TransportVerifyShardBeforeCloseAction} executed for the given index pattern.
 */
private Releasable interceptVerifyShardBeforeCloseActions(final String indexPattern, final Runnable onIntercept) {
    final MockTransportService mockTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, internalCluster().getMasterName());
    final CountDownLatch release = new CountDownLatch(1);
    for (DiscoveryNode node : internalCluster().clusterService().state().getNodes()) {
        mockTransportService.addSendBehavior(internalCluster().getInstance(TransportService.class, node.getName()), (connection, requestId, action, request, options) -> {
            if (action.startsWith(TransportVerifyShardBeforeCloseAction.NAME)) {
                if (request instanceof TransportVerifyShardBeforeCloseAction.ShardRequest) {
                    final String index = ((TransportVerifyShardBeforeCloseAction.ShardRequest) request).shardId().getIndexName();
                    if (Glob.globMatch(indexPattern, index)) {
                        logger.info("request {} intercepted for index {}", requestId, index);
                        onIntercept.run();
                        try {
                            release.await();
                            logger.info("request {} released for index {}", requestId, index);
                        } catch (final InterruptedException e) {
                            throw new AssertionError(e);
                        }
                    }
                }
            }
            connection.sendRequest(requestId, action, request, options);
        });
    }
    final RunOnce releaseOnce = new RunOnce(release::countDown);
    return releaseOnce::run;
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockTransportService(org.opensearch.test.transport.MockTransportService) MockTransportService(org.opensearch.test.transport.MockTransportService) TransportService(org.opensearch.transport.TransportService) RunOnce(org.opensearch.common.util.concurrent.RunOnce) TransportVerifyShardBeforeCloseAction(org.opensearch.action.admin.indices.close.TransportVerifyShardBeforeCloseAction) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 TransportVerifyShardBeforeCloseAction (org.opensearch.action.admin.indices.close.TransportVerifyShardBeforeCloseAction)1 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)1 RunOnce (org.opensearch.common.util.concurrent.RunOnce)1 MockTransportService (org.opensearch.test.transport.MockTransportService)1 TransportService (org.opensearch.transport.TransportService)1