Search in sources :

Example 21 with CapturingTransport

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

the class PeerFinderTests method setup.

@Before
public void setup() {
    capturingTransport = new CapturingTransport();
    transportAddressConnector = new MockTransportAddressConnector();
    providedAddresses = new ArrayList<>();
    addressResolveDelay = 0L;
    final Settings settings = Settings.builder().put(NODE_NAME_SETTING.getKey(), "node").build();
    deterministicTaskQueue = new DeterministicTaskQueue(settings, random());
    localNode = newDiscoveryNode("local-node");
    ConnectionManager innerConnectionManager = new ClusterConnectionManager(settings, capturingTransport);
    StubbableConnectionManager connectionManager = new StubbableConnectionManager(innerConnectionManager);
    connectionManager.setDefaultNodeConnectedBehavior((cm, discoveryNode) -> {
        final boolean isConnected = connectedNodes.contains(discoveryNode);
        final boolean isDisconnected = disconnectedNodes.contains(discoveryNode);
        assert isConnected != isDisconnected : discoveryNode + ": isConnected=" + isConnected + ", isDisconnected=" + isDisconnected;
        return isConnected;
    });
    connectionManager.setDefaultGetConnectionBehavior((cm, discoveryNode) -> capturingTransport.createConnection(discoveryNode));
    transportService = new TransportService(settings, capturingTransport, deterministicTaskQueue.getThreadPool(), TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundTransportAddress -> localNode, null, emptySet(), connectionManager);
    transportService.start();
    transportService.acceptIncomingRequests();
    lastAcceptedNodes = DiscoveryNodes.builder().localNodeId(localNode.getId()).add(localNode).build();
    peerFinder = new TestPeerFinder(settings, transportService, transportAddressConnector);
    foundPeersFromNotification = emptyList();
}
Also used : Arrays(java.util.Arrays) Matchers.emptyArray(org.hamcrest.Matchers.emptyArray) Version(org.opensearch.Version) OpenSearchException(org.opensearch.OpenSearchException) Collections.singletonList(java.util.Collections.singletonList) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) After(org.junit.After) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) ActionListener(org.opensearch.action.ActionListener) DeterministicTaskQueue(org.opensearch.cluster.coordination.DeterministicTaskQueue) Collections.emptyList(java.util.Collections.emptyList) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) StubbableConnectionManager(org.opensearch.test.transport.StubbableConnectionManager) TransportService(org.opensearch.transport.TransportService) Collectors(java.util.stream.Collectors) TransportAddress(org.opensearch.common.transport.TransportAddress) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) Stream(java.util.stream.Stream) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Builder(org.opensearch.cluster.node.DiscoveryNodes.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) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OptionalLong(java.util.OptionalLong) TransportAddressConnector(org.opensearch.discovery.PeerFinder.TransportAddressConnector) ConnectionManager(org.opensearch.transport.ConnectionManager) StreamSupport(java.util.stream.StreamSupport) PeersResponse(org.opensearch.cluster.coordination.PeersResponse) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) Collections.emptyMap(java.util.Collections.emptyMap) Matchers.empty(org.hamcrest.Matchers.empty) Collections.emptySet(java.util.Collections.emptySet) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) IOException(java.io.IOException) ClusterConnectionManager(org.opensearch.transport.ClusterConnectionManager) CapturedRequest(org.opensearch.test.transport.CapturingTransport.CapturedRequest) Consumer(java.util.function.Consumer) NODE_NAME_SETTING(org.opensearch.node.Node.NODE_NAME_SETTING) REQUEST_PEERS_ACTION_NAME(org.opensearch.discovery.PeerFinder.REQUEST_PEERS_ACTION_NAME) CapturingTransport(org.opensearch.test.transport.CapturingTransport) Collections(java.util.Collections) StubbableConnectionManager(org.opensearch.test.transport.StubbableConnectionManager) ConnectionManager(org.opensearch.transport.ConnectionManager) ClusterConnectionManager(org.opensearch.transport.ClusterConnectionManager) StubbableConnectionManager(org.opensearch.test.transport.StubbableConnectionManager) DeterministicTaskQueue(org.opensearch.cluster.coordination.DeterministicTaskQueue) TransportService(org.opensearch.transport.TransportService) CapturingTransport(org.opensearch.test.transport.CapturingTransport) Settings(org.opensearch.common.settings.Settings) ClusterConnectionManager(org.opensearch.transport.ClusterConnectionManager) Before(org.junit.Before)

Example 22 with CapturingTransport

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

the class RetentionLeaseSyncActionTests method setUp.

public void setUp() throws Exception {
    super.setUp();
    threadPool = new TestThreadPool(getClass().getName());
    transport = new CapturingTransport();
    clusterService = createClusterService(threadPool);
    transportService = transport.createTransportService(clusterService.getSettings(), threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> clusterService.localNode(), null, Collections.emptySet());
    transportService.start();
    transportService.acceptIncomingRequests();
    shardStateAction = new ShardStateAction(clusterService, transportService, null, null, threadPool);
}
Also used : ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndexShard(org.opensearch.index.shard.IndexShard) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) ActionListener(org.opensearch.action.ActionListener) ShardStateAction(org.opensearch.cluster.action.shard.ShardStateAction) Collections.emptyMap(java.util.Collections.emptyMap) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) 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) 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) SystemIndices(org.opensearch.indices.SystemIndices) 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) CapturingTransport(org.opensearch.test.transport.CapturingTransport) ShardStateAction(org.opensearch.cluster.action.shard.ShardStateAction) TestThreadPool(org.opensearch.threadpool.TestThreadPool)

Example 23 with CapturingTransport

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

the class RetentionLeaseBackgroundSyncActionTests method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    threadPool = new TestThreadPool(getClass().getName());
    transport = new CapturingTransport();
    clusterService = createClusterService(threadPool);
    transportService = transport.createTransportService(clusterService.getSettings(), threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> clusterService.localNode(), null, Collections.emptySet());
    transportService.start();
    transportService.acceptIncomingRequests();
    shardStateAction = new ShardStateAction(clusterService, transportService, null, null, threadPool);
}
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) CapturingTransport(org.opensearch.test.transport.CapturingTransport) ShardStateAction(org.opensearch.cluster.action.shard.ShardStateAction) TestThreadPool(org.opensearch.threadpool.TestThreadPool)

Example 24 with CapturingTransport

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

the class GlobalCheckpointSyncActionTests method setUp.

public void setUp() throws Exception {
    super.setUp();
    threadPool = new TestThreadPool(getClass().getName());
    transport = new CapturingTransport();
    clusterService = createClusterService(threadPool);
    transportService = transport.createTransportService(clusterService.getSettings(), threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> clusterService.localNode(), null, Collections.emptySet());
    transportService.start();
    transportService.acceptIncomingRequests();
    shardStateAction = new ShardStateAction(clusterService, transportService, null, null, threadPool);
}
Also used : ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) Index(org.opensearch.index.Index) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) ThreadPool(org.opensearch.threadpool.ThreadPool) IndicesService(org.opensearch.indices.IndicesService) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Settings(org.opensearch.common.settings.Settings) Mockito.when(org.mockito.Mockito.when) 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) IndexShard(org.opensearch.index.shard.IndexShard) Mockito.never(org.mockito.Mockito.never) ActionTestUtils(org.opensearch.action.support.ActionTestUtils) ClusterService(org.opensearch.cluster.service.ClusterService) Translog(org.opensearch.index.translog.Translog) CapturingTransport(org.opensearch.test.transport.CapturingTransport) Collections(java.util.Collections) ShardStateAction(org.opensearch.cluster.action.shard.ShardStateAction) Mockito.mock(org.mockito.Mockito.mock) CapturingTransport(org.opensearch.test.transport.CapturingTransport) ShardStateAction(org.opensearch.cluster.action.shard.ShardStateAction) TestThreadPool(org.opensearch.threadpool.TestThreadPool)

Aggregations

CapturingTransport (org.opensearch.test.transport.CapturingTransport)24 TransportService (org.opensearch.transport.TransportService)24 Collections (java.util.Collections)16 Settings (org.opensearch.common.settings.Settings)16 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)16 ActionFilters (org.opensearch.action.support.ActionFilters)15 TestThreadPool (org.opensearch.threadpool.TestThreadPool)15 ThreadPool (org.opensearch.threadpool.ThreadPool)15 Before (org.junit.Before)14 ActionListener (org.opensearch.action.ActionListener)14 ClusterState (org.opensearch.cluster.ClusterState)14 ClusterService (org.opensearch.cluster.service.ClusterService)14 After (org.junit.After)13 ClusterServiceUtils.createClusterService (org.opensearch.test.ClusterServiceUtils.createClusterService)13 TimeUnit (java.util.concurrent.TimeUnit)12 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)11 IOException (java.io.IOException)10 PlainActionFuture (org.opensearch.action.support.PlainActionFuture)10 StreamInput (org.opensearch.common.io.stream.StreamInput)10 HashSet (java.util.HashSet)9