Search in sources :

Example 11 with CapturingTransport

use of org.opensearch.test.transport.CapturingTransport in project OpenSearch by opensearch-project.

the class LeaderCheckerTests method testLeaderBehaviour.

public void testLeaderBehaviour() {
    final DiscoveryNode localNode = new DiscoveryNode("local-node", buildNewFakeTransportAddress(), Version.CURRENT);
    final DiscoveryNode otherNode = new DiscoveryNode("other-node", buildNewFakeTransportAddress(), Version.CURRENT);
    final Settings settings = Settings.builder().put(NODE_NAME_SETTING.getKey(), localNode.getId()).build();
    final DeterministicTaskQueue deterministicTaskQueue = new DeterministicTaskQueue(settings, random());
    final CapturingTransport capturingTransport = new CapturingTransport();
    AtomicReference<StatusInfo> nodeHealthServiceStatus = new AtomicReference<>(new StatusInfo(UNHEALTHY, "unhealthy-info"));
    final TransportService transportService = capturingTransport.createTransportService(settings, deterministicTaskQueue.getThreadPool(), NOOP_TRANSPORT_INTERCEPTOR, boundTransportAddress -> localNode, null, emptySet());
    transportService.start();
    transportService.acceptIncomingRequests();
    final LeaderChecker leaderChecker = new LeaderChecker(settings, transportService, e -> fail("shouldn't be checking anything"), () -> nodeHealthServiceStatus.get());
    final DiscoveryNodes discoveryNodes = DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId()).masterNodeId(localNode.getId()).build();
    {
        leaderChecker.setCurrentNodes(discoveryNodes);
        final CapturingTransportResponseHandler handler = new CapturingTransportResponseHandler();
        transportService.sendRequest(localNode, LEADER_CHECK_ACTION_NAME, new LeaderCheckRequest(otherNode), handler);
        deterministicTaskQueue.runAllTasks();
        assertFalse(handler.successfulResponseReceived);
        assertThat(handler.transportException.getRootCause(), instanceOf(NodeHealthCheckFailureException.class));
        NodeHealthCheckFailureException cause = (NodeHealthCheckFailureException) handler.transportException.getRootCause();
        assertThat(cause.getMessage(), equalTo("rejecting leader check from [" + otherNode + "] since node is unhealthy [unhealthy-info]"));
    }
    nodeHealthServiceStatus.getAndSet(new StatusInfo(HEALTHY, "healthy-info"));
    {
        leaderChecker.setCurrentNodes(discoveryNodes);
        final CapturingTransportResponseHandler handler = new CapturingTransportResponseHandler();
        transportService.sendRequest(localNode, LEADER_CHECK_ACTION_NAME, new LeaderCheckRequest(otherNode), handler);
        deterministicTaskQueue.runAllTasks();
        assertFalse(handler.successfulResponseReceived);
        assertThat(handler.transportException.getRootCause(), instanceOf(CoordinationStateRejectedException.class));
        CoordinationStateRejectedException cause = (CoordinationStateRejectedException) handler.transportException.getRootCause();
        assertThat(cause.getMessage(), equalTo("rejecting leader check since [" + otherNode + "] has been removed from the cluster"));
    }
    {
        leaderChecker.setCurrentNodes(DiscoveryNodes.builder(discoveryNodes).add(otherNode).build());
        final CapturingTransportResponseHandler handler = new CapturingTransportResponseHandler();
        transportService.sendRequest(localNode, LEADER_CHECK_ACTION_NAME, new LeaderCheckRequest(otherNode), handler);
        deterministicTaskQueue.runAllTasks();
        assertTrue(handler.successfulResponseReceived);
        assertThat(handler.transportException, nullValue());
    }
    {
        leaderChecker.setCurrentNodes(DiscoveryNodes.builder(discoveryNodes).add(otherNode).masterNodeId(null).build());
        final CapturingTransportResponseHandler handler = new CapturingTransportResponseHandler();
        transportService.sendRequest(localNode, LEADER_CHECK_ACTION_NAME, new LeaderCheckRequest(otherNode), handler);
        deterministicTaskQueue.runAllTasks();
        assertFalse(handler.successfulResponseReceived);
        assertThat(handler.transportException.getRootCause(), instanceOf(CoordinationStateRejectedException.class));
        CoordinationStateRejectedException cause = (CoordinationStateRejectedException) handler.transportException.getRootCause();
        assertThat(cause.getMessage(), equalTo("rejecting leader check from [" + otherNode + "] sent to a node that is no longer the cluster-manager"));
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) CapturingTransport(org.opensearch.test.transport.CapturingTransport) AtomicReference(java.util.concurrent.atomic.AtomicReference) LeaderCheckRequest(org.opensearch.cluster.coordination.LeaderChecker.LeaderCheckRequest) StatusInfo(org.opensearch.monitor.StatusInfo) TransportService(org.opensearch.transport.TransportService) Settings(org.opensearch.common.settings.Settings) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes)

Example 12 with CapturingTransport

use of org.opensearch.test.transport.CapturingTransport in project OpenSearch by opensearch-project.

the class TransportWriteActionTests method testReplicaProxy.

public void testReplicaProxy() throws InterruptedException, ExecutionException {
    CapturingTransport transport = new CapturingTransport();
    TransportService transportService = transport.createTransportService(clusterService.getSettings(), threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null, Collections.emptySet());
    transportService.start();
    transportService.acceptIncomingRequests();
    ShardStateAction shardStateAction = new ShardStateAction(clusterService, transportService, null, null, threadPool);
    TestAction action = new TestAction(Settings.EMPTY, "internal:testAction", transportService, clusterService, shardStateAction, threadPool);
    final String index = "test";
    final ShardId shardId = new ShardId(index, "_na_", 0);
    ClusterState state = ClusterStateCreationUtils.stateWithActivePrimary(index, true, 1 + randomInt(3), randomInt(2));
    logger.info("using state: {}", state);
    ClusterServiceUtils.setState(clusterService, state);
    final long primaryTerm = state.metadata().index(index).primaryTerm(0);
    ReplicationOperation.Replicas<TestRequest> proxy = action.newReplicasProxy();
    // check that at unknown node fails
    PlainActionFuture<ReplicaResponse> listener = new PlainActionFuture<>();
    ShardRoutingState routingState = randomFrom(ShardRoutingState.INITIALIZING, ShardRoutingState.STARTED, ShardRoutingState.RELOCATING);
    proxy.performOn(TestShardRouting.newShardRouting(shardId, "NOT THERE", routingState == ShardRoutingState.RELOCATING ? state.nodes().iterator().next().getId() : null, false, routingState), new TestRequest(), primaryTerm, randomNonNegativeLong(), randomNonNegativeLong(), listener);
    assertTrue(listener.isDone());
    assertListenerThrows("non existent node should throw a NoNodeAvailableException", listener, NoNodeAvailableException.class);
    final IndexShardRoutingTable shardRoutings = state.routingTable().shardRoutingTable(shardId);
    final ShardRouting replica = randomFrom(shardRoutings.replicaShards().stream().filter(ShardRouting::assignedToNode).collect(Collectors.toList()));
    listener = new PlainActionFuture<>();
    proxy.performOn(replica, new TestRequest(), primaryTerm, randomNonNegativeLong(), randomNonNegativeLong(), listener);
    assertFalse(listener.isDone());
    CapturingTransport.CapturedRequest[] captures = transport.getCapturedRequestsAndClear();
    assertThat(captures, arrayWithSize(1));
    if (randomBoolean()) {
        final TransportReplicationAction.ReplicaResponse response = new TransportReplicationAction.ReplicaResponse(randomLong(), randomLong());
        transport.handleResponse(captures[0].requestId, response);
        assertTrue(listener.isDone());
        assertThat(listener.get(), equalTo(response));
    } else if (randomBoolean()) {
        transport.handleRemoteError(captures[0].requestId, new OpenSearchException("simulated"));
        assertTrue(listener.isDone());
        assertListenerThrows("listener should reflect remote error", listener, OpenSearchException.class);
    } else {
        transport.handleError(captures[0].requestId, new TransportException("simulated"));
        assertTrue(listener.isDone());
        assertListenerThrows("listener should reflect remote error", listener, TransportException.class);
    }
    AtomicReference<Object> failure = new AtomicReference<>();
    AtomicBoolean success = new AtomicBoolean();
    proxy.failShardIfNeeded(replica, primaryTerm, "test", new OpenSearchException("simulated"), ActionListener.wrap(r -> success.set(true), failure::set));
    CapturingTransport.CapturedRequest[] shardFailedRequests = transport.getCapturedRequestsAndClear();
    // A write replication action proxy should fail the shard
    assertEquals(1, shardFailedRequests.length);
    CapturingTransport.CapturedRequest shardFailedRequest = shardFailedRequests[0];
    ShardStateAction.FailedShardEntry shardEntry = (ShardStateAction.FailedShardEntry) shardFailedRequest.request;
    // the shard the request was sent to and the shard to be failed should be the same
    assertEquals(shardEntry.getShardId(), replica.shardId());
    assertEquals(shardEntry.getAllocationId(), replica.allocationId().getId());
    if (randomBoolean()) {
        // simulate success
        transport.handleResponse(shardFailedRequest.requestId, TransportResponse.Empty.INSTANCE);
        assertTrue(success.get());
        assertNull(failure.get());
    } else if (randomBoolean()) {
        // simulate the primary has been demoted
        transport.handleRemoteError(shardFailedRequest.requestId, new ShardStateAction.NoLongerPrimaryShardException(replica.shardId(), "shard-failed-test"));
        assertFalse(success.get());
        assertNotNull(failure.get());
    } else {
        // simulated a node closing exception
        transport.handleRemoteError(shardFailedRequest.requestId, new NodeClosedException(state.nodes().getLocalNode()));
        assertFalse(success.get());
        assertNotNull(failure.get());
    }
}
Also used : TestThreadPool(org.opensearch.threadpool.TestThreadPool) OpenSearchException(org.opensearch.OpenSearchException) NoNodeAvailableException(org.opensearch.client.transport.NoNodeAvailableException) Transport(org.opensearch.transport.Transport) ReplicaResponse(org.opensearch.action.support.replication.ReplicationOperation.ReplicaResponse) Mockito.doThrow(org.mockito.Mockito.doThrow) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) WriteResponse(org.opensearch.action.support.WriteResponse) After(org.junit.After) Mockito.doAnswer(org.mockito.Mockito.doAnswer) NodeClosedException(org.opensearch.node.NodeClosedException) ActionListener(org.opensearch.action.ActionListener) ShardStateAction(org.opensearch.cluster.action.shard.ShardStateAction) IndexShardRoutingTable(org.opensearch.cluster.routing.IndexShardRoutingTable) AfterClass(org.junit.AfterClass) Index(org.opensearch.index.Index) IndexingPressureService(org.opensearch.index.IndexingPressureService) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) IndicesService(org.opensearch.indices.IndicesService) Settings(org.opensearch.common.settings.Settings) TransportResponse(org.opensearch.transport.TransportResponse) TransportService(org.opensearch.transport.TransportService) Collectors(java.util.stream.Collectors) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ActionFilters(org.opensearch.action.support.ActionFilters) ActionTestUtils(org.opensearch.action.support.ActionTestUtils) Matchers.equalTo(org.hamcrest.Matchers.equalTo) RoutingNode(org.opensearch.cluster.routing.RoutingNode) Mockito.any(org.mockito.Mockito.any) ClusterServiceUtils(org.opensearch.test.ClusterServiceUtils) TransportException(org.opensearch.transport.TransportException) RefreshPolicy(org.opensearch.action.support.WriteRequest.RefreshPolicy) Mockito.mock(org.mockito.Mockito.mock) Matchers.arrayWithSize(org.hamcrest.Matchers.arrayWithSize) BeforeClass(org.junit.BeforeClass) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ThreadPool(org.opensearch.threadpool.ThreadPool) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Releasable(org.opensearch.common.lease.Releasable) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) IndexShard(org.opensearch.index.shard.IndexShard) ArgumentCaptor(org.mockito.ArgumentCaptor) ShardRoutingState(org.opensearch.cluster.routing.ShardRoutingState) Translog(org.opensearch.index.translog.Translog) Mockito.anyLong(org.mockito.Mockito.anyLong) Mockito.anyString(org.mockito.Mockito.anyString) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) Collections.emptyMap(java.util.Collections.emptyMap) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) IOException(java.io.IOException) ShardNotFoundException(org.opensearch.index.shard.ShardNotFoundException) Mockito.when(org.mockito.Mockito.when) IndexService(org.opensearch.index.IndexService) Mockito.verify(org.mockito.Mockito.verify) ShardRouting(org.opensearch.cluster.routing.ShardRouting) ShardId(org.opensearch.index.shard.ShardId) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) TestShardRouting(org.opensearch.cluster.routing.TestShardRouting) SystemIndices(org.opensearch.indices.SystemIndices) Mockito.never(org.mockito.Mockito.never) ClusterService(org.opensearch.cluster.service.ClusterService) Mockito.anyInt(org.mockito.Mockito.anyInt) CapturingTransport(org.opensearch.test.transport.CapturingTransport) Collections(java.util.Collections) IndexShardRoutingTable(org.opensearch.cluster.routing.IndexShardRoutingTable) ShardStateAction(org.opensearch.cluster.action.shard.ShardStateAction) Mockito.anyString(org.mockito.Mockito.anyString) ShardId(org.opensearch.index.shard.ShardId) NodeClosedException(org.opensearch.node.NodeClosedException) ClusterState(org.opensearch.cluster.ClusterState) CapturingTransport(org.opensearch.test.transport.CapturingTransport) AtomicReference(java.util.concurrent.atomic.AtomicReference) ShardRoutingState(org.opensearch.cluster.routing.ShardRoutingState) TransportException(org.opensearch.transport.TransportException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransportService(org.opensearch.transport.TransportService) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) ReplicaResponse(org.opensearch.action.support.replication.ReplicationOperation.ReplicaResponse) OpenSearchException(org.opensearch.OpenSearchException) ShardRouting(org.opensearch.cluster.routing.ShardRouting) TestShardRouting(org.opensearch.cluster.routing.TestShardRouting)

Example 13 with CapturingTransport

use of org.opensearch.test.transport.CapturingTransport in project OpenSearch by opensearch-project.

the class FollowersCheckerTests method testPreferMasterNodes.

public void testPreferMasterNodes() {
    List<DiscoveryNode> nodes = randomNodes(10);
    DiscoveryNodes.Builder discoNodesBuilder = DiscoveryNodes.builder();
    nodes.forEach(dn -> discoNodesBuilder.add(dn));
    DiscoveryNodes discoveryNodes = discoNodesBuilder.localNodeId(nodes.get(0).getId()).build();
    CapturingTransport capturingTransport = new CapturingTransport();
    final Settings settings = Settings.builder().put(NODE_NAME_SETTING.getKey(), nodes.get(0).getName()).build();
    final DeterministicTaskQueue deterministicTaskQueue = new DeterministicTaskQueue(settings, random());
    TransportService transportService = capturingTransport.createTransportService(Settings.EMPTY, deterministicTaskQueue.getThreadPool(), TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> nodes.get(0), null, emptySet());
    final FollowersChecker followersChecker = new FollowersChecker(Settings.EMPTY, transportService, fcr -> {
        assert false : fcr;
    }, (node, reason) -> {
        assert false : node;
    }, () -> new StatusInfo(HEALTHY, "healthy-info"));
    followersChecker.setCurrentNodes(discoveryNodes);
    List<DiscoveryNode> followerTargets = Stream.of(capturingTransport.getCapturedRequestsAndClear()).map(cr -> cr.node).collect(Collectors.toList());
    List<DiscoveryNode> sortedFollowerTargets = new ArrayList<>(followerTargets);
    Collections.sort(sortedFollowerTargets, Comparator.comparing(n -> n.isMasterNode() == false));
    assertEquals(sortedFollowerTargets, followerTargets);
}
Also used : FOLLOWER_CHECK_INTERVAL_SETTING(org.opensearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_INTERVAL_SETTING) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) FOLLOWER_CHECK_TIMEOUT_SETTING(org.opensearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_TIMEOUT_SETTING) HANDSHAKE_ACTION_NAME(org.opensearch.transport.TransportService.HANDSHAKE_ACTION_NAME) Matchers.not(org.hamcrest.Matchers.not) Version(org.opensearch.Version) OpenSearchException(org.opensearch.OpenSearchException) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) EqualsHashCodeTestUtils(org.opensearch.test.EqualsHashCodeTestUtils) UNHEALTHY(org.opensearch.monitor.StatusInfo.Status.UNHEALTHY) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) NodeHealthService(org.opensearch.monitor.NodeHealthService) Set(java.util.Set) HEALTHY(org.opensearch.monitor.StatusInfo.Status.HEALTHY) Settings(org.opensearch.common.settings.Settings) TransportResponse(org.opensearch.transport.TransportResponse) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) TransportService(org.opensearch.transport.TransportService) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) FOLLOWER_CHECK_ACTION_NAME(org.opensearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_ACTION_NAME) StatusInfo(org.opensearch.monitor.StatusInfo) ConnectTransportException(org.opensearch.transport.ConnectTransportException) FOLLOWER_CHECK_RETRY_COUNT_SETTING(org.opensearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_RETRY_COUNT_SETTING) Builder(org.opensearch.common.settings.Settings.Builder) TransportException(org.opensearch.transport.TransportException) Names(org.opensearch.threadpool.ThreadPool.Names) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MockTransport(org.opensearch.test.transport.MockTransport) StreamInput(org.opensearch.common.io.stream.StreamInput) Empty(org.opensearch.transport.TransportResponse.Empty) Matchers.empty(org.hamcrest.Matchers.empty) TransportRequest(org.opensearch.transport.TransportRequest) Collections.emptySet(java.util.Collections.emptySet) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) FollowerCheckRequest(org.opensearch.cluster.coordination.FollowersChecker.FollowerCheckRequest) NODE_NAME_SETTING(org.opensearch.node.Node.NODE_NAME_SETTING) ClusterName(org.opensearch.cluster.ClusterName) Mode(org.opensearch.cluster.coordination.Coordinator.Mode) CopyFunction(org.opensearch.test.EqualsHashCodeTestUtils.CopyFunction) Comparator(java.util.Comparator) CapturingTransport(org.opensearch.test.transport.CapturingTransport) Collections(java.util.Collections) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) TransportService(org.opensearch.transport.TransportService) StatusInfo(org.opensearch.monitor.StatusInfo) CapturingTransport(org.opensearch.test.transport.CapturingTransport) ArrayList(java.util.ArrayList) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) Settings(org.opensearch.common.settings.Settings)

Example 14 with CapturingTransport

use of org.opensearch.test.transport.CapturingTransport in project OpenSearch by opensearch-project.

the class TransportWriteActionForIndexingPressureTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    transport = new CapturingTransport();
    clusterService = createClusterService(threadPool);
    transportService = transport.createTransportService(clusterService.getSettings(), threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null, Collections.emptySet());
    transportService.start();
    transportService.acceptIncomingRequests();
    shardStateAction = new ShardStateAction(clusterService, transportService, null, null, threadPool);
    releasable = mock(Releasable.class);
    location = mock(Translog.Location.class);
}
Also used : TestThreadPool(org.opensearch.threadpool.TestThreadPool) ClusterServiceUtils.setState(org.opensearch.test.ClusterServiceUtils.setState) CommonStatsFlags(org.opensearch.action.admin.indices.stats.CommonStatsFlags) Mockito.doThrow(org.mockito.Mockito.doThrow) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) WriteResponse(org.opensearch.action.support.WriteResponse) After(org.junit.After) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ActionListener(org.opensearch.action.ActionListener) ShardStateAction(org.opensearch.cluster.action.shard.ShardStateAction) AfterClass(org.junit.AfterClass) TransportChannel(org.opensearch.transport.TransportChannel) Index(org.opensearch.index.Index) IndexingPressureService(org.opensearch.index.IndexingPressureService) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) ShardIndexingPressureSettings(org.opensearch.index.ShardIndexingPressureSettings) IndicesService(org.opensearch.indices.IndicesService) Settings(org.opensearch.common.settings.Settings) TransportResponse(org.opensearch.transport.TransportResponse) ClusterStateCreationUtils.state(org.opensearch.action.support.replication.ClusterStateCreationUtils.state) TransportService(org.opensearch.transport.TransportService) Nullable(org.opensearch.common.Nullable) Objects(java.util.Objects) ActionFilters(org.opensearch.action.support.ActionFilters) Matchers.equalTo(org.hamcrest.Matchers.equalTo) RoutingNode(org.opensearch.cluster.routing.RoutingNode) Mockito.any(org.mockito.Mockito.any) Mockito.mock(org.mockito.Mockito.mock) IndexShardState(org.opensearch.index.shard.IndexShardState) BeforeClass(org.junit.BeforeClass) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ThreadPool(org.opensearch.threadpool.ThreadPool) ShardNotInPrimaryModeException(org.opensearch.index.shard.ShardNotInPrimaryModeException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Releasable(org.opensearch.common.lease.Releasable) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) IndexShard(org.opensearch.index.shard.IndexShard) ShardRoutingState(org.opensearch.cluster.routing.ShardRoutingState) Translog(org.opensearch.index.translog.Translog) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Mockito.anyLong(org.mockito.Mockito.anyLong) Mockito.anyString(org.mockito.Mockito.anyString) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) Collections.emptyMap(java.util.Collections.emptyMap) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) IOException(java.io.IOException) ShardNotFoundException(org.opensearch.index.shard.ShardNotFoundException) Mockito.when(org.mockito.Mockito.when) IndexService(org.opensearch.index.IndexService) ShardRouting(org.opensearch.cluster.routing.ShardRouting) ShardId(org.opensearch.index.shard.ShardId) TimeUnit(java.util.concurrent.TimeUnit) SystemIndices(org.opensearch.indices.SystemIndices) Matcher(org.hamcrest.Matcher) ClusterService(org.opensearch.cluster.service.ClusterService) Mockito.anyInt(org.mockito.Mockito.anyInt) IndexingPressurePerShardStats(org.opensearch.index.stats.IndexingPressurePerShardStats) ReplicationGroup(org.opensearch.index.shard.ReplicationGroup) CapturingTransport(org.opensearch.test.transport.CapturingTransport) Collections(java.util.Collections) CapturingTransport(org.opensearch.test.transport.CapturingTransport) Releasable(org.opensearch.common.lease.Releasable) ShardStateAction(org.opensearch.cluster.action.shard.ShardStateAction) Before(org.junit.Before)

Example 15 with CapturingTransport

use of org.opensearch.test.transport.CapturingTransport in project OpenSearch by opensearch-project.

the class TransportInstanceSingleOperationActionTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    transport = new CapturingTransport();
    clusterService = createClusterService(THREAD_POOL);
    transportService = transport.createTransportService(clusterService.getSettings(), THREAD_POOL, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null, Collections.emptySet());
    transportService.start();
    transportService.acceptIncomingRequests();
    action = new TestTransportInstanceSingleOperationAction("indices:admin/test", transportService, new ActionFilters(new HashSet<>()), new MyResolver(), Request::new);
}
Also used : BeforeClass(org.junit.BeforeClass) ShardIterator(org.opensearch.cluster.routing.ShardIterator) ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) TimeoutException(java.util.concurrent.TimeoutException) StreamOutput(org.opensearch.common.io.stream.StreamOutput) HashMap(java.util.HashMap) ClusterServiceUtils.setState(org.opensearch.test.ClusterServiceUtils.setState) Writeable(org.opensearch.common.io.stream.Writeable) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ClusterStateCreationUtils(org.opensearch.action.support.replication.ClusterStateCreationUtils) HashSet(java.util.HashSet) IndicesRequest(org.opensearch.action.IndicesRequest) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ClusterBlock(org.opensearch.cluster.block.ClusterBlock) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) After(org.junit.After) Map(java.util.Map) ShardRoutingState(org.opensearch.cluster.routing.ShardRoutingState) ActionListener(org.opensearch.action.ActionListener) ActionResponse(org.opensearch.action.ActionResponse) ClusterBlocks(org.opensearch.cluster.block.ClusterBlocks) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) AfterClass(org.junit.AfterClass) TimeValue(org.opensearch.common.unit.TimeValue) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) ClusterBlockLevel(org.opensearch.cluster.block.ClusterBlockLevel) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) ExceptionsHelper(org.opensearch.ExceptionsHelper) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) RestStatus(org.opensearch.rest.RestStatus) TransportService(org.opensearch.transport.TransportService) ShardId(org.opensearch.index.shard.ShardId) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ActionFilters(org.opensearch.action.support.ActionFilters) ClusterService(org.opensearch.cluster.service.ClusterService) ConnectTransportException(org.opensearch.transport.ConnectTransportException) CapturingTransport(org.opensearch.test.transport.CapturingTransport) Collections(java.util.Collections) TransportException(org.opensearch.transport.TransportException) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) CapturingTransport(org.opensearch.test.transport.CapturingTransport) ActionFilters(org.opensearch.action.support.ActionFilters) Before(org.junit.Before)

Aggregations

CapturingTransport (org.opensearch.test.transport.CapturingTransport)29 TransportService (org.opensearch.transport.TransportService)29 Collections (java.util.Collections)21 Settings (org.opensearch.common.settings.Settings)21 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)20 TestThreadPool (org.opensearch.threadpool.TestThreadPool)18 ThreadPool (org.opensearch.threadpool.ThreadPool)18 ActionListener (org.opensearch.action.ActionListener)17 ActionFilters (org.opensearch.action.support.ActionFilters)16 ClusterService (org.opensearch.cluster.service.ClusterService)16 ClusterState (org.opensearch.cluster.ClusterState)15 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)15 TimeUnit (java.util.concurrent.TimeUnit)14 After (org.junit.After)14 Before (org.junit.Before)14 ClusterServiceUtils.createClusterService (org.opensearch.test.ClusterServiceUtils.createClusterService)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 Version (org.opensearch.Version)12 StreamInput (org.opensearch.common.io.stream.StreamInput)12 IOException (java.io.IOException)11