Search in sources :

Example 26 with ClusterSettings

use of org.elasticsearch.common.settings.ClusterSettings in project elasticsearch by elastic.

the class SimpleNetty4TransportTests method testBindUnavailableAddress.

public void testBindUnavailableAddress() {
    // this is on a lower level since it needs access to the TransportService before it's started
    int port = serviceA.boundAddress().publishAddress().getPort();
    Settings settings = Settings.builder().put(Node.NODE_NAME_SETTING.getKey(), "foobar").put(TransportService.TRACE_LOG_INCLUDE_SETTING.getKey(), "").put(TransportService.TRACE_LOG_EXCLUDE_SETTING.getKey(), "NOTHING").put("transport.tcp.port", port).build();
    ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    BindTransportException bindTransportException = expectThrows(BindTransportException.class, () -> {
        MockTransportService transportService = nettyFromThreadPool(settings, threadPool, Version.CURRENT, clusterSettings, true);
        try {
            transportService.start();
        } finally {
            transportService.stop();
            transportService.close();
        }
    });
    assertEquals("Failed to bind to [" + port + "]", bindTransportException.getMessage());
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) MockTransportService(org.elasticsearch.test.transport.MockTransportService) BindTransportException(org.elasticsearch.transport.BindTransportException) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) TransportSettings(org.elasticsearch.transport.TransportSettings)

Example 27 with ClusterSettings

use of org.elasticsearch.common.settings.ClusterSettings in project elasticsearch by elastic.

the class DiscoveryModuleTests method setupDummyServices.

@Before
public void setupDummyServices() {
    transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, null, null);
    clusterService = mock(ClusterService.class);
    namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
    ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
    threadPool = mock(ThreadPool.class);
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) ClusterService(org.elasticsearch.cluster.service.ClusterService) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 28 with ClusterSettings

use of org.elasticsearch.common.settings.ClusterSettings in project elasticsearch by elastic.

the class ZenFaultDetectionTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    Settings settings = Settings.builder().put(HierarchyCircuitBreakerService.IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), new ByteSizeValue(0)).build();
    ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    threadPool = new TestThreadPool(getClass().getName());
    circuitBreakerService = new HierarchyCircuitBreakerService(settings, clusterSettings);
    settingsA = Settings.builder().put("node.name", "TS_A").put(settings).build();
    serviceA = build(settingsA, version0);
    nodeA = serviceA.getLocalDiscoNode();
    settingsB = Settings.builder().put("node.name", "TS_B").put(settings).build();
    serviceB = build(settingsB, version1);
    nodeB = serviceB.getLocalDiscoNode();
    clusterServiceA = createClusterService(settingsA, threadPool, nodeA);
    clusterServiceB = createClusterService(settingsB, threadPool, nodeB);
    // wait till all nodes are properly connected and the event has been sent, so tests in this class
    // will not get this callback called on the connections done in this setup
    final CountDownLatch latch = new CountDownLatch(2);
    TransportConnectionListener waitForConnection = new TransportConnectionListener() {

        @Override
        public void onNodeConnected(DiscoveryNode node) {
            latch.countDown();
        }

        @Override
        public void onNodeDisconnected(DiscoveryNode node) {
            fail("disconnect should not be called " + node);
        }
    };
    serviceA.addConnectionListener(waitForConnection);
    serviceB.addConnectionListener(waitForConnection);
    serviceA.connectToNode(nodeB);
    serviceA.connectToNode(nodeA);
    serviceB.connectToNode(nodeA);
    serviceB.connectToNode(nodeB);
    assertThat("failed to wait for all nodes to connect", latch.await(5, TimeUnit.SECONDS), equalTo(true));
    serviceA.removeConnectionListener(waitForConnection);
    serviceB.removeConnectionListener(waitForConnection);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) CountDownLatch(java.util.concurrent.CountDownLatch) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) TransportConnectionListener(org.elasticsearch.transport.TransportConnectionListener) Before(org.junit.Before)

Example 29 with ClusterSettings

use of org.elasticsearch.common.settings.ClusterSettings in project elasticsearch by elastic.

the class ClusterServiceUtils method createClusterService.

public static ClusterService createClusterService(Settings settings, ThreadPool threadPool, DiscoveryNode localNode) {
    ClusterService clusterService = new ClusterService(Settings.builder().put("cluster.name", "ClusterServiceTests").put(settings).build(), new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), threadPool, () -> localNode);
    clusterService.setNodeConnectionsService(new NodeConnectionsService(Settings.EMPTY, null, null) {

        @Override
        public void connectToNodes(DiscoveryNodes discoveryNodes) {
        // skip
        }

        @Override
        public void disconnectFromNodesExcept(DiscoveryNodes nodesToKeep) {
        // skip
        }
    });
    clusterService.setClusterStatePublisher((event, ackListener) -> {
    });
    clusterService.setDiscoverySettings(new DiscoverySettings(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)));
    clusterService.start();
    final DiscoveryNodes.Builder nodes = DiscoveryNodes.builder(clusterService.state().nodes());
    nodes.masterNodeId(clusterService.localNode().getId());
    setState(clusterService, ClusterState.builder(clusterService.state()).nodes(nodes));
    return clusterService;
}
Also used : ClusterService(org.elasticsearch.cluster.service.ClusterService) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) NodeConnectionsService(org.elasticsearch.cluster.NodeConnectionsService) DiscoverySettings(org.elasticsearch.discovery.DiscoverySettings) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 30 with ClusterSettings

use of org.elasticsearch.common.settings.ClusterSettings in project elasticsearch by elastic.

the class MemoryCircuitBreakerTests method testThreadedUpdatesToChildBreaker.

public void testThreadedUpdatesToChildBreaker() throws Exception {
    final int NUM_THREADS = scaledRandomIntBetween(3, 15);
    final int BYTES_PER_THREAD = scaledRandomIntBetween(500, 4500);
    final Thread[] threads = new Thread[NUM_THREADS];
    final AtomicBoolean tripped = new AtomicBoolean(false);
    final AtomicReference<Throwable> lastException = new AtomicReference<>(null);
    final AtomicReference<ChildMemoryCircuitBreaker> breakerRef = new AtomicReference<>(null);
    final CircuitBreakerService service = new HierarchyCircuitBreakerService(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)) {

        @Override
        public CircuitBreaker getBreaker(String name) {
            return breakerRef.get();
        }

        @Override
        public void checkParentLimit(String label) throws CircuitBreakingException {
        // never trip
        }
    };
    final BreakerSettings settings = new BreakerSettings(CircuitBreaker.REQUEST, (BYTES_PER_THREAD * NUM_THREADS) - 1, 1.0);
    final ChildMemoryCircuitBreaker breaker = new ChildMemoryCircuitBreaker(settings, logger, (HierarchyCircuitBreakerService) service, CircuitBreaker.REQUEST);
    breakerRef.set(breaker);
    for (int i = 0; i < NUM_THREADS; i++) {
        threads[i] = new Thread(new Runnable() {

            @Override
            public void run() {
                for (int j = 0; j < BYTES_PER_THREAD; j++) {
                    try {
                        breaker.addEstimateBytesAndMaybeBreak(1L, "test");
                    } catch (CircuitBreakingException e) {
                        if (tripped.get()) {
                            assertThat("tripped too many times", true, equalTo(false));
                        } else {
                            assertThat(tripped.compareAndSet(false, true), equalTo(true));
                        }
                    } catch (Exception e) {
                        lastException.set(e);
                    }
                }
            }
        });
        threads[i].start();
    }
    for (Thread t : threads) {
        t.join();
    }
    assertThat("no other exceptions were thrown", lastException.get(), equalTo(null));
    assertThat("breaker was tripped", tripped.get(), equalTo(true));
    assertThat("breaker was tripped at least once", breaker.getTrippedCount(), greaterThanOrEqualTo(1L));
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BreakerSettings(org.elasticsearch.indices.breaker.BreakerSettings) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService)

Aggregations

ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)109 Settings (org.elasticsearch.common.settings.Settings)58 ClusterState (org.elasticsearch.cluster.ClusterState)50 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)30 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)25 Matchers.containsString (org.hamcrest.Matchers.containsString)25 Test (org.junit.Test)25 MetaData (org.elasticsearch.cluster.metadata.MetaData)21 BalancedShardsAllocator (org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator)21 AllocationService (org.elasticsearch.cluster.routing.allocation.AllocationService)20 ClusterInfo (org.elasticsearch.cluster.ClusterInfo)18 DiskUsage (org.elasticsearch.cluster.DiskUsage)18 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)18 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)18 TestGatewayAllocator (org.elasticsearch.test.gateway.TestGatewayAllocator)18 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)17 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)15 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)14 HashSet (java.util.HashSet)13 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)13