Search in sources :

Example 16 with CapturingTransport

use of org.elasticsearch.test.transport.CapturingTransport in project crate by crate.

the class PublicationTransportHandlerTests method testDiffSerializationFailure.

public void testDiffSerializationFailure() {
    DeterministicTaskQueue deterministicTaskQueue = new DeterministicTaskQueue(Settings.builder().put(Node.NODE_NAME_SETTING.getKey(), "test").build(), random());
    final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    final DiscoveryNode localNode = new DiscoveryNode("localNode", buildNewFakeTransportAddress(), Version.CURRENT);
    final TransportService transportService = new CapturingTransport().createTransportService(Settings.EMPTY, deterministicTaskQueue.getThreadPool(), x -> localNode, clusterSettings);
    final PublicationTransportHandler handler = new PublicationTransportHandler(transportService, writableRegistry(), pu -> null, (pu, l) -> {
    });
    transportService.start();
    transportService.acceptIncomingRequests();
    final DiscoveryNode otherNode = new DiscoveryNode("otherNode", buildNewFakeTransportAddress(), Version.CURRENT);
    final ClusterState clusterState = CoordinationStateTests.clusterState(2L, 1L, DiscoveryNodes.builder().add(localNode).add(otherNode).localNodeId(localNode.getId()).build(), VotingConfiguration.EMPTY_CONFIG, VotingConfiguration.EMPTY_CONFIG, 0L);
    final ClusterState unserializableClusterState = new ClusterState(clusterState.version(), clusterState.stateUUID(), clusterState) {

        @Override
        public Diff<ClusterState> diff(ClusterState previousState) {
            return new Diff<ClusterState>() {

                @Override
                public ClusterState apply(ClusterState part) {
                    fail("this diff shouldn't be applied");
                    return part;
                }

                @Override
                public void writeTo(StreamOutput out) throws IOException {
                    throw new IOException("Simulated failure of diff serialization");
                }
            };
        }
    };
    ElasticsearchException e = expectThrows(ElasticsearchException.class, () -> handler.newPublicationContext(new ClusterChangedEvent("test", unserializableClusterState, clusterState)));
    assertNotNull(e.getCause());
    assertThat(e.getCause(), instanceOf(IOException.class));
    assertThat(e.getCause().getMessage(), containsString("Simulated failure of diff serialization"));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) TransportService(org.elasticsearch.transport.TransportService) Diff(org.elasticsearch.cluster.Diff) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput)

Example 17 with CapturingTransport

use of org.elasticsearch.test.transport.CapturingTransport in project crate by crate.

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 ConnectionManager(settings, capturingTransport);
    StubbableConnectionManager connectionManager = new StubbableConnectionManager(innerConnectionManager, settings, capturingTransport, deterministicTaskQueue.getThreadPool());
    connectionManager.setDefaultNodeConnectedBehavior(cm -> {
        assertTrue(Sets.haveEmptyIntersection(connectedNodes, disconnectedNodes));
        return connectedNodes;
    });
    connectionManager.setDefaultGetConnectionBehavior((cm, discoveryNode) -> capturingTransport.createConnection(discoveryNode));
    transportService = new TransportService(settings, capturingTransport, deterministicTaskQueue.getThreadPool(), boundTransportAddress -> localNode, null, connectionManager);
    transportService.start();
    transportService.acceptIncomingRequests();
    lastAcceptedNodes = DiscoveryNodes.builder().localNodeId(localNode.getId()).add(localNode).build();
    peerFinder = new TestPeerFinder(settings, transportService, transportAddressConnector);
    foundPeersFromNotification = emptyList();
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) Arrays(java.util.Arrays) Builder(org.elasticsearch.cluster.node.DiscoveryNodes.Builder) Matchers.emptyArray(org.hamcrest.Matchers.emptyArray) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) Collections.singletonList(java.util.Collections.singletonList) Sets(io.crate.common.collections.Sets) Settings(org.elasticsearch.common.settings.Settings) After(org.junit.After) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) DeterministicTaskQueue(org.elasticsearch.cluster.coordination.DeterministicTaskQueue) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) ConnectionManager(org.elasticsearch.transport.ConnectionManager) Collectors(java.util.stream.Collectors) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) Version(org.elasticsearch.Version) Stream(java.util.stream.Stream) TransportAddress(org.elasticsearch.common.transport.TransportAddress) NODE_NAME_SETTING(org.elasticsearch.node.Node.NODE_NAME_SETTING) Matchers.contains(org.hamcrest.Matchers.contains) PeersResponse(org.elasticsearch.cluster.coordination.PeersResponse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) REQUEST_PEERS_ACTION_NAME(org.elasticsearch.discovery.PeerFinder.REQUEST_PEERS_ACTION_NAME) TransportException(org.elasticsearch.transport.TransportException) CapturedRequest(org.elasticsearch.test.transport.CapturingTransport.CapturedRequest) TransportAddressConnector(org.elasticsearch.discovery.PeerFinder.TransportAddressConnector) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Names(org.elasticsearch.threadpool.ThreadPool.Names) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OptionalLong(java.util.OptionalLong) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) StreamSupport(java.util.stream.StreamSupport) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) Before(org.junit.Before) StubbableConnectionManager(org.elasticsearch.test.transport.StubbableConnectionManager) Collections.emptyMap(java.util.Collections.emptyMap) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Matchers.empty(org.hamcrest.Matchers.empty) Collections.emptySet(java.util.Collections.emptySet) IOException(java.io.IOException) Consumer(java.util.function.Consumer) StreamInput(org.elasticsearch.common.io.stream.StreamInput) Collections(java.util.Collections) ActionListener(org.elasticsearch.action.ActionListener) ConnectionManager(org.elasticsearch.transport.ConnectionManager) StubbableConnectionManager(org.elasticsearch.test.transport.StubbableConnectionManager) StubbableConnectionManager(org.elasticsearch.test.transport.StubbableConnectionManager) DeterministicTaskQueue(org.elasticsearch.cluster.coordination.DeterministicTaskQueue) TransportService(org.elasticsearch.transport.TransportService) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) Settings(org.elasticsearch.common.settings.Settings) Before(org.junit.Before)

Example 18 with CapturingTransport

use of org.elasticsearch.test.transport.CapturingTransport in project crate by crate.

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, boundAddress -> clusterService.localNode(), null);
    transportService.start();
    transportService.acceptIncomingRequests();
    shardStateAction = new ShardStateAction(clusterService, transportService, null, null);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) ClusterService(org.elasticsearch.cluster.service.ClusterService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Index(org.elasticsearch.index.Index) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) WriteStateException(org.elasticsearch.gateway.WriteStateException) ThreadPool(org.elasticsearch.threadpool.ThreadPool) LatchedActionListener(org.elasticsearch.action.LatchedActionListener) IndicesService(org.elasticsearch.indices.IndicesService) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IOUtils(io.crate.common.io.IOUtils) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) TransportReplicationAction(org.elasticsearch.action.support.replication.TransportReplicationAction) Mockito.verify(org.mockito.Mockito.verify) CountDownLatch(java.util.concurrent.CountDownLatch) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ActionTestUtils(org.elasticsearch.action.support.ActionTestUtils) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) ActionListener(org.elasticsearch.action.ActionListener) Mockito.mock(org.mockito.Mockito.mock) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool)

Example 19 with CapturingTransport

use of org.elasticsearch.test.transport.CapturingTransport in project crate by crate.

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, boundAddress -> clusterService.localNode(), null);
    transportService.start();
    transportService.acceptIncomingRequests();
    shardStateAction = new ShardStateAction(clusterService, transportService, null, null);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) ClusterService(org.elasticsearch.cluster.service.ClusterService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Index(org.elasticsearch.index.Index) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) Settings(org.elasticsearch.common.settings.Settings) WriteStateException(org.elasticsearch.gateway.WriteStateException) ThreadPool(org.elasticsearch.threadpool.ThreadPool) IndicesService(org.elasticsearch.indices.IndicesService) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) IOUtils(io.crate.common.io.IOUtils) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ActionTestUtils(org.elasticsearch.action.support.ActionTestUtils) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) ActionListener(org.elasticsearch.action.ActionListener) TransportWriteAction(org.elasticsearch.action.support.replication.TransportWriteAction) Mockito.mock(org.mockito.Mockito.mock) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool)

Example 20 with CapturingTransport

use of org.elasticsearch.test.transport.CapturingTransport in project crate by crate.

the class JoinHelperTests method testJoinDeduplication.

public void testJoinDeduplication() {
    DeterministicTaskQueue deterministicTaskQueue = new DeterministicTaskQueue(Settings.builder().put(NODE_NAME_SETTING.getKey(), "node0").build(), random());
    CapturingTransport capturingTransport = new CapturingTransport();
    DiscoveryNode localNode = new DiscoveryNode("node0", buildNewFakeTransportAddress(), Version.CURRENT);
    TransportService transportService = capturingTransport.createTransportService(Settings.EMPTY, deterministicTaskQueue.getThreadPool(), x -> localNode, null);
    JoinHelper joinHelper = new JoinHelper(Settings.EMPTY, null, null, transportService, () -> 0L, () -> null, (joinRequest, joinCallback) -> {
        throw new AssertionError();
    }, startJoinRequest -> {
        throw new AssertionError();
    }, Collections.emptyList(), (s, p, r) -> {
    });
    transportService.start();
    DiscoveryNode node1 = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Version.CURRENT);
    DiscoveryNode node2 = new DiscoveryNode("node2", buildNewFakeTransportAddress(), Version.CURRENT);
    assertFalse(joinHelper.isJoinPending());
    // check that sending a join to node1 works
    Optional<Join> optionalJoin1 = randomBoolean() ? Optional.empty() : Optional.of(new Join(localNode, node1, randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
    joinHelper.sendJoinRequest(node1, optionalJoin1);
    CapturedRequest[] capturedRequests1 = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests1.length, equalTo(1));
    CapturedRequest capturedRequest1 = capturedRequests1[0];
    assertEquals(node1, capturedRequest1.node);
    assertTrue(joinHelper.isJoinPending());
    // check that sending a join to node2 works
    Optional<Join> optionalJoin2 = randomBoolean() ? Optional.empty() : Optional.of(new Join(localNode, node2, randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
    joinHelper.sendJoinRequest(node2, optionalJoin2);
    CapturedRequest[] capturedRequests2 = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests2.length, equalTo(1));
    CapturedRequest capturedRequest2 = capturedRequests2[0];
    assertEquals(node2, capturedRequest2.node);
    // check that sending another join to node1 is a noop as the previous join is still in progress
    joinHelper.sendJoinRequest(node1, optionalJoin1);
    assertThat(capturingTransport.getCapturedRequestsAndClear().length, equalTo(0));
    // complete the previous join to node1
    if (randomBoolean()) {
        capturingTransport.handleResponse(capturedRequest1.requestId, TransportResponse.Empty.INSTANCE);
    } else {
        capturingTransport.handleRemoteError(capturedRequest1.requestId, new CoordinationStateRejectedException("dummy"));
    }
    // check that sending another join to node1 now works again
    joinHelper.sendJoinRequest(node1, optionalJoin1);
    CapturedRequest[] capturedRequests1a = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests1a.length, equalTo(1));
    CapturedRequest capturedRequest1a = capturedRequests1a[0];
    assertEquals(node1, capturedRequest1a.node);
    // check that sending another join to node2 works if the optionalJoin is different
    Optional<Join> optionalJoin2a = optionalJoin2.isPresent() && randomBoolean() ? Optional.empty() : Optional.of(new Join(localNode, node2, randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
    joinHelper.sendJoinRequest(node2, optionalJoin2a);
    CapturedRequest[] capturedRequests2a = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests2a.length, equalTo(1));
    CapturedRequest capturedRequest2a = capturedRequests2a[0];
    assertEquals(node2, capturedRequest2a.node);
    // complete all the joins and check that isJoinPending is updated
    assertTrue(joinHelper.isJoinPending());
    capturingTransport.handleRemoteError(capturedRequest2.requestId, new CoordinationStateRejectedException("dummy"));
    capturingTransport.handleRemoteError(capturedRequest1a.requestId, new CoordinationStateRejectedException("dummy"));
    capturingTransport.handleRemoteError(capturedRequest2a.requestId, new CoordinationStateRejectedException("dummy"));
    assertFalse(joinHelper.isJoinPending());
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportService(org.elasticsearch.transport.TransportService) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) CapturedRequest(org.elasticsearch.test.transport.CapturingTransport.CapturedRequest)

Aggregations

CapturingTransport (org.elasticsearch.test.transport.CapturingTransport)20 TransportService (org.elasticsearch.transport.TransportService)20 ESTestCase (org.elasticsearch.test.ESTestCase)13 Settings (org.elasticsearch.common.settings.Settings)12 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)11 ThreadPool (org.elasticsearch.threadpool.ThreadPool)11 ClusterState (org.elasticsearch.cluster.ClusterState)10 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)10 ClusterService (org.elasticsearch.cluster.service.ClusterService)10 Before (org.junit.Before)10 ClusterServiceUtils.createClusterService (org.elasticsearch.test.ClusterServiceUtils.createClusterService)9 After (org.junit.After)9 TimeUnit (java.util.concurrent.TimeUnit)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 ActionListener (org.elasticsearch.action.ActionListener)8 ActionFilters (org.elasticsearch.action.support.ActionFilters)8 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)8 Collections (java.util.Collections)7 HashSet (java.util.HashSet)7 Version (org.elasticsearch.Version)7