Search in sources :

Example 6 with CircuitBreakerService

use of org.elasticsearch.indices.breaker.CircuitBreakerService in project elasticsearch by elastic.

the class NetworkModuleTests method testRegisterTransport.

public void testRegisterTransport() {
    Settings settings = Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, "custom").put(NetworkModule.HTTP_ENABLED.getKey(), false).build();
    // content doesn't matter we check reference equality
    Supplier<Transport> custom = () -> null;
    NetworkPlugin plugin = new NetworkPlugin() {

        @Override
        public Map<String, Supplier<Transport>> getTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NetworkService networkService) {
            return Collections.singletonMap("custom", custom);
        }
    };
    NetworkModule module = newNetworkModule(settings, false, plugin);
    assertFalse(module.isTransportClient());
    assertFalse(module.isHttpEnabled());
    assertSame(custom, module.getTransportSupplier());
    // check it works with transport only as well
    module = newNetworkModule(settings, true, plugin);
    assertSame(custom, module.getTransportSupplier());
    assertTrue(module.isTransportClient());
    assertFalse(module.isHttpEnabled());
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) NetworkPlugin(org.elasticsearch.plugins.NetworkPlugin) BigArrays(org.elasticsearch.common.util.BigArrays) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Supplier(java.util.function.Supplier) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) Transport(org.elasticsearch.transport.Transport) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) Settings(org.elasticsearch.common.settings.Settings)

Example 7 with CircuitBreakerService

use of org.elasticsearch.indices.breaker.CircuitBreakerService in project elasticsearch by elastic.

the class BroadcastReplicationTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    MockTcpTransport transport = new MockTcpTransport(Settings.EMPTY, threadPool, BigArrays.NON_RECYCLING_INSTANCE, circuitBreakerService, new NamedWriteableRegistry(Collections.emptyList()), new NetworkService(Settings.EMPTY, Collections.emptyList()));
    clusterService = createClusterService(threadPool);
    transportService = new TransportService(clusterService.getSettings(), transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null);
    transportService.start();
    transportService.acceptIncomingRequests();
    broadcastReplicationAction = new TestBroadcastReplicationAction(Settings.EMPTY, threadPool, clusterService, transportService, new ActionFilters(new HashSet<>()), new IndexNameExpressionResolver(Settings.EMPTY), null);
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) ShardId(org.elasticsearch.index.shard.ShardId) BigArrays(org.elasticsearch.common.util.BigArrays) Date(java.util.Date) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) ConcurrentCollections(org.elasticsearch.common.util.concurrent.ConcurrentCollections) ClusterState(org.elasticsearch.cluster.ClusterState) Future(java.util.concurrent.Future) Settings(org.elasticsearch.common.settings.Settings) After(org.junit.After) BroadcastRequest(org.elasticsearch.action.support.broadcast.BroadcastRequest) ThreadPool(org.elasticsearch.threadpool.ThreadPool) AfterClass(org.junit.AfterClass) ActionFilters(org.elasticsearch.action.support.ActionFilters) BroadcastResponse(org.elasticsearch.action.support.broadcast.BroadcastResponse) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) Set(java.util.Set) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) RestStatus(org.elasticsearch.rest.RestStatus) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Task(org.elasticsearch.tasks.Task) ClusterStateCreationUtils.stateWithNoShard(org.elasticsearch.action.support.replication.ClusterStateCreationUtils.stateWithNoShard) ClusterStateCreationUtils.state(org.elasticsearch.action.support.replication.ClusterStateCreationUtils.state) BeforeClass(org.junit.BeforeClass) ClusterService(org.elasticsearch.cluster.service.ClusterService) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) HashSet(java.util.HashSet) NetworkService(org.elasticsearch.common.network.NetworkService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) ClusterStateCreationUtils.stateWithAssignedPrimariesAndOneReplica(org.elasticsearch.action.support.replication.ClusterStateCreationUtils.stateWithAssignedPrimariesAndOneReplica) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) FlushResponse(org.elasticsearch.action.admin.indices.flush.FlushResponse) Before(org.junit.Before) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) TransportFlushAction(org.elasticsearch.action.admin.indices.flush.TransportFlushAction) IOUtils(org.apache.lucene.util.IOUtils) NoShardAvailableActionException(org.elasticsearch.action.NoShardAvailableActionException) IOException(java.io.IOException) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException) UnavailableShardsException(org.elasticsearch.action.UnavailableShardsException) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) FlushRequest(org.elasticsearch.action.admin.indices.flush.FlushRequest) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Tuple(org.elasticsearch.common.collect.Tuple) Collections(java.util.Collections) ClusterServiceUtils.setState(org.elasticsearch.test.ClusterServiceUtils.setState) ActionListener(org.elasticsearch.action.ActionListener) TransportService(org.elasticsearch.transport.TransportService) NetworkService(org.elasticsearch.common.network.NetworkService) ActionFilters(org.elasticsearch.action.support.ActionFilters) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) Before(org.junit.Before)

Example 8 with CircuitBreakerService

use of org.elasticsearch.indices.breaker.CircuitBreakerService in project elasticsearch by elastic.

the class CircuitBreakerUnitTests method testRegisterCustomBreaker.

public void testRegisterCustomBreaker() throws Exception {
    CircuitBreakerService service = new HierarchyCircuitBreakerService(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
    String customName = "custom";
    BreakerSettings settings = new BreakerSettings(customName, 20, 1.0);
    service.registerBreaker(settings);
    CircuitBreaker breaker = service.getBreaker(customName);
    assertThat(breaker, notNullValue());
    assertThat(breaker, instanceOf(CircuitBreaker.class));
    assertThat(breaker.getName(), is(customName));
}
Also used : BreakerSettings(org.elasticsearch.indices.breaker.BreakerSettings) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService)

Example 9 with CircuitBreakerService

use of org.elasticsearch.indices.breaker.CircuitBreakerService in project elasticsearch by elastic.

the class CircuitBreakerServiceIT method testCustomCircuitBreakerRegistration.

public void testCustomCircuitBreakerRegistration() throws Exception {
    Iterable<CircuitBreakerService> serviceIter = internalCluster().getInstances(CircuitBreakerService.class);
    final String breakerName = "customBreaker";
    BreakerSettings breakerSettings = new BreakerSettings(breakerName, 8, 1.03);
    CircuitBreaker breaker = null;
    for (CircuitBreakerService s : serviceIter) {
        s.registerBreaker(breakerSettings);
        breaker = s.getBreaker(breakerSettings.getName());
    }
    if (breaker != null) {
        try {
            breaker.addEstimateBytesAndMaybeBreak(16, "test");
        } catch (CircuitBreakingException e) {
        // ignore, we forced a circuit break
        }
    }
    NodesStatsResponse stats = client().admin().cluster().prepareNodesStats().clear().setBreaker(true).get();
    int breaks = 0;
    for (NodeStats stat : stats.getNodes()) {
        CircuitBreakerStats breakerStats = stat.getBreaker().getStats(breakerName);
        breaks += breakerStats.getTrippedCount();
    }
    assertThat(breaks, greaterThanOrEqualTo(1));
}
Also used : NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) BreakerSettings(org.elasticsearch.indices.breaker.BreakerSettings) NoopCircuitBreaker(org.elasticsearch.common.breaker.NoopCircuitBreaker) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) CircuitBreakerStats(org.elasticsearch.indices.breaker.CircuitBreakerStats) CircuitBreakingException(org.elasticsearch.common.breaker.CircuitBreakingException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService)

Example 10 with CircuitBreakerService

use of org.elasticsearch.indices.breaker.CircuitBreakerService in project crate by crate.

the class CrateCircuitBreakerServiceTest method testQueryCircuitBreakerRegistration.

@Test
public void testQueryCircuitBreakerRegistration() throws Exception {
    NodeSettingsService settingsService = new NodeSettingsService(Settings.EMPTY);
    CircuitBreakerService esBreakerService = new HierarchyCircuitBreakerService(Settings.EMPTY, settingsService);
    CrateCircuitBreakerService breakerService = new CrateCircuitBreakerService(Settings.EMPTY, settingsService, esBreakerService);
    CircuitBreaker breaker = breakerService.getBreaker(CrateCircuitBreakerService.QUERY);
    assertThat(breaker, notNullValue());
    assertThat(breaker, instanceOf(CircuitBreaker.class));
    assertThat(breaker.getName(), is(CrateCircuitBreakerService.QUERY));
}
Also used : CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) NodeSettingsService(org.elasticsearch.node.settings.NodeSettingsService) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

CircuitBreakerService (org.elasticsearch.indices.breaker.CircuitBreakerService)18 HierarchyCircuitBreakerService (org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService)10 Settings (org.elasticsearch.common.settings.Settings)9 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)7 ThreadPool (org.elasticsearch.threadpool.ThreadPool)7 CircuitBreaker (org.elasticsearch.common.breaker.CircuitBreaker)6 BigArrays (org.elasticsearch.common.util.BigArrays)6 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)6 NetworkPlugin (org.elasticsearch.plugins.NetworkPlugin)5 CrateUnitTest (io.crate.test.integration.CrateUnitTest)4 HttpServerTransport (org.elasticsearch.http.HttpServerTransport)4 NodeSettingsService (org.elasticsearch.node.settings.NodeSettingsService)4 Transport (org.elasticsearch.transport.Transport)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 NamedXContentRegistry (org.elasticsearch.common.xcontent.NamedXContentRegistry)3 BreakerSettings (org.elasticsearch.indices.breaker.BreakerSettings)3 Collections (java.util.Collections)2