Search in sources :

Example 46 with MockTransportService

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

the class SrvUnicastHostsProviderTest method mockTransportService.

@Before
public void mockTransportService() throws Exception {
    String localHostName = InetAddress.getLocalHost().getCanonicalHostName();
    isLocalHost = anyOf(is(localHostName), is("localhost"));
    threadPool = new TestThreadPool("dummy", Settings.EMPTY);
    TransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool, null);
    srvUnicastHostsProvider = new SrvUnicastHostsProvider(Settings.EMPTY, transportService);
}
Also used : MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 47 with MockTransportService

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

the class DiscoveryDisruptionIT method testNodeNotReachableFromMaster.

/**
 * Adds an asymmetric break between a master and one of the nodes and makes
 * sure that the node is removed form the cluster, that the node start pinging and that
 * the cluster reforms when healed.
 */
@Test
public void testNodeNotReachableFromMaster() throws Exception {
    startCluster(3);
    String masterNode = internalCluster().getMasterName();
    String nonMasterNode = null;
    while (nonMasterNode == null) {
        nonMasterNode = randomFrom(internalCluster().getNodeNames());
        if (nonMasterNode.equals(masterNode)) {
            nonMasterNode = null;
        }
    }
    logger.info("blocking request from master [{}] to [{}]", masterNode, nonMasterNode);
    MockTransportService masterTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, masterNode);
    if (randomBoolean()) {
        masterTransportService.addUnresponsiveRule(internalCluster().getInstance(TransportService.class, nonMasterNode));
    } else {
        masterTransportService.addFailToSendNoConnectRule(internalCluster().getInstance(TransportService.class, nonMasterNode));
    }
    logger.info("waiting for [{}] to be removed from cluster", nonMasterNode);
    ensureStableCluster(2, masterNode);
    logger.info("waiting for [{}] to have no master", nonMasterNode);
    assertNoMaster(nonMasterNode);
    logger.info("healing partition and checking cluster reforms");
    masterTransportService.clearAllRules();
    ensureStableCluster(3);
}
Also used : MockTransportService(org.elasticsearch.test.transport.MockTransportService) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) Test(org.junit.Test)

Example 48 with MockTransportService

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

the class DiscoveryDisruptionIT method testClusterJoinDespiteOfPublishingIssues.

/**
 * Test cluster join with issues in cluster state publishing *
 */
@Test
public void testClusterJoinDespiteOfPublishingIssues() throws Exception {
    String masterNode = internalCluster().startMasterOnlyNode();
    String nonMasterNode = internalCluster().startDataOnlyNode();
    DiscoveryNodes discoveryNodes = internalCluster().getInstance(ClusterService.class, nonMasterNode).state().nodes();
    TransportService masterTranspotService = internalCluster().getInstance(TransportService.class, discoveryNodes.getMasterNode().getName());
    logger.info("blocking requests from non master [{}] to master [{}]", nonMasterNode, masterNode);
    MockTransportService nonMasterTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, nonMasterNode);
    nonMasterTransportService.addFailToSendNoConnectRule(masterTranspotService);
    assertNoMaster(nonMasterNode);
    logger.info("blocking cluster state publishing from master [{}] to non master [{}]", masterNode, nonMasterNode);
    MockTransportService masterTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, masterNode);
    TransportService localTransportService = internalCluster().getInstance(TransportService.class, discoveryNodes.getLocalNode().getName());
    if (randomBoolean()) {
        masterTransportService.addFailToSendNoConnectRule(localTransportService, PublicationTransportHandler.PUBLISH_STATE_ACTION_NAME);
    } else {
        masterTransportService.addFailToSendNoConnectRule(localTransportService, PublicationTransportHandler.COMMIT_STATE_ACTION_NAME);
    }
    logger.info("allowing requests from non master [{}] to master [{}], waiting for two join request", nonMasterNode, masterNode);
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    nonMasterTransportService.addSendBehavior(masterTransportService, (connection, requestId, action, request, options) -> {
        if (action.equals(JoinHelper.JOIN_ACTION_NAME)) {
            countDownLatch.countDown();
        }
        connection.sendRequest(requestId, action, request, options);
    });
    nonMasterTransportService.addConnectBehavior(masterTransportService, Transport::openConnection);
    countDownLatch.await();
    logger.info("waiting for cluster to reform");
    masterTransportService.clearOutboundRules(localTransportService);
    nonMasterTransportService.clearOutboundRules(localTransportService);
    ensureStableCluster(2);
    // shutting down the nodes, to avoid the leakage check tripping
    // on the states associated with the commit requests we may have dropped
    internalCluster().stopRandomNonMasterNode();
}
Also used : MockTransportService(org.elasticsearch.test.transport.MockTransportService) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) CountDownLatch(java.util.concurrent.CountDownLatch) Transport(org.elasticsearch.transport.Transport) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Test(org.junit.Test)

Example 49 with MockTransportService

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

the class RepositoryServiceTest method testRepositoryIsDroppedOnFailure.

@Test
public void testRepositoryIsDroppedOnFailure() throws Throwable {
    expectedException.expect(RepositoryException.class);
    // add repo to cluster service so that it exists..
    RepositoriesMetadata repos = new RepositoriesMetadata(Collections.singletonList(new RepositoryMetadata("repo1", "fs", Settings.EMPTY)));
    ClusterState state = ClusterState.builder(new ClusterName("dummy")).metadata(Metadata.builder().putCustom(RepositoriesMetadata.TYPE, repos)).build();
    ClusterServiceUtils.setState(clusterService, state);
    IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver();
    final AtomicBoolean deleteRepoCalled = new AtomicBoolean(false);
    MockTransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, THREAD_POOL, clusterService.getClusterSettings());
    TransportDeleteRepositoryAction deleteRepositoryAction = new TransportDeleteRepositoryAction(transportService, clusterService, mock(RepositoriesService.class), THREAD_POOL, indexNameExpressionResolver) {

        @Override
        protected void doExecute(DeleteRepositoryRequest request, ActionListener<AcknowledgedResponse> listener) {
            deleteRepoCalled.set(true);
            listener.onResponse(mock(AcknowledgedResponse.class));
        }
    };
    TransportPutRepositoryAction putRepo = new TransportPutRepositoryAction(transportService, clusterService, mock(RepositoriesService.class), THREAD_POOL, indexNameExpressionResolver) {

        @Override
        protected void doExecute(PutRepositoryRequest request, ActionListener<AcknowledgedResponse> listener) {
            listener.onFailure(new RepositoryException(request.name(), "failure"));
        }
    };
    RepositoryService repositoryService = new RepositoryService(clusterService, deleteRepositoryAction, putRepo);
    try {
        PutRepositoryRequest request = new PutRepositoryRequest("repo1");
        request.type("fs");
        repositoryService.execute(request).get(10, TimeUnit.SECONDS);
    } catch (ExecutionException e) {
        assertThat(deleteRepoCalled.get(), is(true));
        throw e.getCause();
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportDeleteRepositoryAction(org.elasticsearch.action.admin.cluster.repositories.delete.TransportDeleteRepositoryAction) DeleteRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RepositoryException(org.elasticsearch.repositories.RepositoryException) RepositoriesMetadata(org.elasticsearch.cluster.metadata.RepositoriesMetadata) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ActionListener(org.elasticsearch.action.ActionListener) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) TransportPutRepositoryAction(org.elasticsearch.action.admin.cluster.repositories.put.TransportPutRepositoryAction) ExecutionException(java.util.concurrent.ExecutionException) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 50 with MockTransportService

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

the class TransportClusterStateActionDisruptionIT method runRepeatedlyWhileChangingMaster.

public void runRepeatedlyWhileChangingMaster(Runnable runnable) throws Exception {
    internalCluster().startNodes(3);
    assertBusy(() -> assertThat(client().admin().cluster().prepareState().clear().setMetadata(true).get().getState().getLastCommittedConfiguration().getNodeIds().stream().filter(n -> ClusterBootstrapService.isBootstrapPlaceholder(n) == false).collect(Collectors.toSet()), hasSize(3)));
    final String masterName = internalCluster().getMasterName();
    final AtomicBoolean shutdown = new AtomicBoolean();
    final Thread assertingThread = new Thread(() -> {
        while (shutdown.get() == false) {
            runnable.run();
        }
    }, "asserting thread");
    final Thread updatingThread = new Thread(() -> {
        String value = "none";
        while (shutdown.get() == false) {
            value = "none".equals(value) ? "all" : "none";
            final String nonMasterNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames()));
            assertAcked(client(nonMasterNode).admin().cluster().prepareUpdateSettings().setPersistentSettings(Settings.builder().put(CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), value)));
        }
    }, "updating thread");
    final List<MockTransportService> mockTransportServices = StreamSupport.stream(internalCluster().getInstances(TransportService.class).spliterator(), false).map(ts -> (MockTransportService) ts).collect(Collectors.toList());
    assertingThread.start();
    updatingThread.start();
    final MockTransportService masterTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, masterName);
    for (MockTransportService mockTransportService : mockTransportServices) {
        if (masterTransportService != mockTransportService) {
            masterTransportService.addFailToSendNoConnectRule(mockTransportService);
            mockTransportService.addFailToSendNoConnectRule(masterTransportService);
        }
    }
    assertBusy(() -> {
        final String nonMasterNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames()));
        final String claimedMasterName = internalCluster().getMasterName(nonMasterNode);
        assertThat(claimedMasterName, not(equalTo(masterName)));
    });
    shutdown.set(true);
    assertingThread.join();
    updatingThread.join();
    internalCluster().close();
}
Also used : MasterNotDiscoveredException(org.elasticsearch.discovery.MasterNotDiscoveredException) ClusterService(org.elasticsearch.cluster.service.ClusterService) Matchers.not(org.hamcrest.Matchers.not) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterBootstrapService(org.elasticsearch.cluster.coordination.ClusterBootstrapService) ClusterState(org.elasticsearch.cluster.ClusterState) Metadata(org.elasticsearch.cluster.metadata.Metadata) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) Matchers.hasSize(org.hamcrest.Matchers.hasSize) StreamSupport(java.util.stream.StreamSupport) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING(org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Collection(java.util.Collection) Plugin(org.elasticsearch.plugins.Plugin) Collectors(java.util.stream.Collectors) List(java.util.List) ESIntegTestCase(org.elasticsearch.test.ESIntegTestCase) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TimeValue(io.crate.common.unit.TimeValue) Collections(java.util.Collections) ElasticsearchAssertions.assertAcked(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MockTransportService(org.elasticsearch.test.transport.MockTransportService) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService)

Aggregations

MockTransportService (org.elasticsearch.test.transport.MockTransportService)59 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)32 TransportService (org.elasticsearch.transport.TransportService)30 Settings (org.elasticsearch.common.settings.Settings)24 IOException (java.io.IOException)23 CountDownLatch (java.util.concurrent.CountDownLatch)21 ArrayList (java.util.ArrayList)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)12 TransportRequest (org.elasticsearch.transport.TransportRequest)11 TransportRequestOptions (org.elasticsearch.transport.TransportRequestOptions)11 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)10 NetworkService (org.elasticsearch.common.network.NetworkService)10 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)10 ClusterState (org.elasticsearch.cluster.ClusterState)9 NoneCircuitBreakerService (org.elasticsearch.indices.breaker.NoneCircuitBreakerService)9 ThreadPool (org.elasticsearch.threadpool.ThreadPool)9 Test (org.junit.Test)9 List (java.util.List)8 Collections (java.util.Collections)7