Search in sources :

Example 1 with CircuitBreakerService

use of org.opensearch.indices.breaker.CircuitBreakerService in project OpenSearch by opensearch-project.

the class BroadcastReplicationTests method setUp.

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

Example 2 with CircuitBreakerService

use of org.opensearch.indices.breaker.CircuitBreakerService in project OpenSearch by opensearch-project.

the class BitArrayTests method testClearingDoesntAllocate.

public void testClearingDoesntAllocate() {
    CircuitBreakerService breaker = mock(CircuitBreakerService.class);
    ByteSizeValue max = new ByteSizeValue(1, ByteSizeUnit.KB);
    when(breaker.getBreaker(CircuitBreaker.REQUEST)).thenReturn(new NoopCircuitBreaker(CircuitBreaker.REQUEST) {

        private long total = 0;

        @Override
        public double addEstimateBytesAndMaybeBreak(long bytes, String label) throws CircuitBreakingException {
            total += bytes;
            if (total > max.getBytes()) {
                throw new CircuitBreakingException("test error", bytes, max.getBytes(), Durability.TRANSIENT);
            }
            return total;
        }

        @Override
        public long addWithoutBreaking(long bytes) {
            total += bytes;
            return total;
        }
    });
    BigArrays bigArrays = new BigArrays(null, breaker, CircuitBreaker.REQUEST, true);
    try (BitArray bitArray = new BitArray(1, bigArrays)) {
        bitArray.clear(100000000);
    }
}
Also used : CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) NoopCircuitBreaker(org.opensearch.common.breaker.NoopCircuitBreaker) CircuitBreakerService(org.opensearch.indices.breaker.CircuitBreakerService)

Example 3 with CircuitBreakerService

use of org.opensearch.indices.breaker.CircuitBreakerService in project OpenSearch by opensearch-project.

the class NetworkModuleTests method testRegisterTransport.

public void testRegisterTransport() {
    Settings settings = Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, "custom").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, PageCacheRecycler pageCacheRecycler, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NetworkService networkService) {
            return Collections.singletonMap("custom", custom);
        }
    };
    NetworkModule module = newNetworkModule(settings, plugin);
    assertSame(custom, module.getTransportSupplier());
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) NetworkPlugin(org.opensearch.plugins.NetworkPlugin) PageCacheRecycler(org.opensearch.common.util.PageCacheRecycler) ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Supplier(java.util.function.Supplier) Transport(org.opensearch.transport.Transport) HttpServerTransport(org.opensearch.http.HttpServerTransport) CircuitBreakerService(org.opensearch.indices.breaker.CircuitBreakerService) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings)

Example 4 with CircuitBreakerService

use of org.opensearch.indices.breaker.CircuitBreakerService in project OpenSearch by opensearch-project.

the class NetworkModuleTests method testOverrideDefault.

public void testOverrideDefault() {
    Settings settings = Settings.builder().put(NetworkModule.HTTP_TYPE_SETTING.getKey(), "custom").put(NetworkModule.HTTP_DEFAULT_TYPE_SETTING.getKey(), "default_custom").put(NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING.getKey(), "local").put(NetworkModule.TRANSPORT_TYPE_KEY, "default_custom").build();
    // content doesn't matter we check reference equality
    Supplier<Transport> customTransport = () -> null;
    Supplier<HttpServerTransport> custom = FakeHttpTransport::new;
    Supplier<HttpServerTransport> def = FakeHttpTransport::new;
    NetworkModule module = newNetworkModule(settings, new NetworkPlugin() {

        @Override
        public Map<String, Supplier<Transport>> getTransports(Settings settings, ThreadPool threadPool, PageCacheRecycler pageCacheRecycler, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NetworkService networkService) {
            return Collections.singletonMap("default_custom", customTransport);
        }

        @Override
        public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, PageCacheRecycler pageCacheRecycler, CircuitBreakerService circuitBreakerService, NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher requestDispatcher, ClusterSettings clusterSettings) {
            Map<String, Supplier<HttpServerTransport>> supplierMap = new HashMap<>();
            supplierMap.put("custom", custom);
            supplierMap.put("default_custom", def);
            return supplierMap;
        }
    });
    assertSame(custom, module.getHttpServerTransportSupplier());
    assertSame(customTransport, module.getTransportSupplier());
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) NetworkPlugin(org.opensearch.plugins.NetworkPlugin) ClusterSettings(org.opensearch.common.settings.ClusterSettings) ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) HttpServerTransport(org.opensearch.http.HttpServerTransport) BigArrays(org.opensearch.common.util.BigArrays) PageCacheRecycler(org.opensearch.common.util.PageCacheRecycler) Transport(org.opensearch.transport.Transport) HttpServerTransport(org.opensearch.http.HttpServerTransport) CircuitBreakerService(org.opensearch.indices.breaker.CircuitBreakerService) HashMap(java.util.HashMap) Map(java.util.Map) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings)

Example 5 with CircuitBreakerService

use of org.opensearch.indices.breaker.CircuitBreakerService in project OpenSearch by opensearch-project.

the class NetworkModuleTests method testRegisterHttpTransport.

public void testRegisterHttpTransport() {
    Settings settings = Settings.builder().put(NetworkModule.HTTP_TYPE_SETTING.getKey(), "custom").put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build();
    Supplier<HttpServerTransport> custom = FakeHttpTransport::new;
    NetworkModule module = newNetworkModule(settings, new NetworkPlugin() {

        @Override
        public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, PageCacheRecycler pageCacheRecycler, CircuitBreakerService circuitBreakerService, NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher requestDispatcher, ClusterSettings clusterSettings) {
            return Collections.singletonMap("custom", custom);
        }
    });
    assertSame(custom, module.getHttpServerTransportSupplier());
    settings = Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build();
    NetworkModule newModule = newNetworkModule(settings);
    expectThrows(IllegalStateException.class, () -> newModule.getHttpServerTransportSupplier());
}
Also used : NetworkPlugin(org.opensearch.plugins.NetworkPlugin) ClusterSettings(org.opensearch.common.settings.ClusterSettings) ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) HttpServerTransport(org.opensearch.http.HttpServerTransport) BigArrays(org.opensearch.common.util.BigArrays) PageCacheRecycler(org.opensearch.common.util.PageCacheRecycler) CircuitBreakerService(org.opensearch.indices.breaker.CircuitBreakerService) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) HashMap(java.util.HashMap) Map(java.util.Map) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings)

Aggregations

CircuitBreakerService (org.opensearch.indices.breaker.CircuitBreakerService)17 Settings (org.opensearch.common.settings.Settings)10 BigArrays (org.opensearch.common.util.BigArrays)8 ThreadPool (org.opensearch.threadpool.ThreadPool)7 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)6 ClusterSettings (org.opensearch.common.settings.ClusterSettings)6 IOException (java.io.IOException)5 Map (java.util.Map)5 NamedXContentRegistry (org.opensearch.common.xcontent.NamedXContentRegistry)5 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Supplier (java.util.function.Supplier)4 PageCacheRecycler (org.opensearch.common.util.PageCacheRecycler)4 MapperService (org.opensearch.index.mapper.MapperService)4 TestThreadPool (org.opensearch.threadpool.TestThreadPool)4 ArrayList (java.util.ArrayList)3 Objects (java.util.Objects)3 Set (java.util.Set)3 TimeUnit (java.util.concurrent.TimeUnit)3