Search in sources :

Example 16 with MockPageCacheRecycler

use of org.opensearch.common.util.MockPageCacheRecycler in project OpenSearch by opensearch-project.

the class SimpleMockNioTransportTests method build.

@Override
protected Transport build(Settings settings, final Version version, ClusterSettings clusterSettings, boolean doHandshake) {
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
    NetworkService networkService = new NetworkService(Collections.emptyList());
    return new MockNioTransport(settings, version, threadPool, networkService, new MockPageCacheRecycler(settings), namedWriteableRegistry, new NoneCircuitBreakerService()) {

        @Override
        public void executeHandshake(DiscoveryNode node, TcpChannel channel, ConnectionProfile profile, ActionListener<Version> listener) {
            if (doHandshake) {
                super.executeHandshake(node, channel, profile, listener);
            } else {
                listener.onResponse(version.minimumCompatibilityVersion());
            }
        }
    };
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) ActionListener(org.opensearch.action.ActionListener) TcpChannel(org.opensearch.transport.TcpChannel) NetworkService(org.opensearch.common.network.NetworkService) ConnectionProfile(org.opensearch.transport.ConnectionProfile) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Example 17 with MockPageCacheRecycler

use of org.opensearch.common.util.MockPageCacheRecycler in project OpenSearch by opensearch-project.

the class Netty4HttpServerTransportTests method setup.

@Before
public void setup() throws Exception {
    networkService = new NetworkService(Collections.emptyList());
    threadPool = new TestThreadPool("test");
    bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
    clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
}
Also used : ClusterSettings(org.opensearch.common.settings.ClusterSettings) MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) NetworkService(org.opensearch.common.network.NetworkService) MockBigArrays(org.opensearch.common.util.MockBigArrays) TestThreadPool(org.opensearch.threadpool.TestThreadPool) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 18 with MockPageCacheRecycler

use of org.opensearch.common.util.MockPageCacheRecycler in project OpenSearch by opensearch-project.

the class Netty4BadRequestTests method setup.

@Before
public void setup() throws Exception {
    networkService = new NetworkService(Collections.emptyList());
    bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
    threadPool = new TestThreadPool("test");
}
Also used : MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) NetworkService(org.opensearch.common.network.NetworkService) MockBigArrays(org.opensearch.common.util.MockBigArrays) TestThreadPool(org.opensearch.threadpool.TestThreadPool) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 19 with MockPageCacheRecycler

use of org.opensearch.common.util.MockPageCacheRecycler in project OpenSearch by opensearch-project.

the class NioHttpServerTransportTests method setup.

@Before
public void setup() throws Exception {
    networkService = new NetworkService(Collections.emptyList());
    threadPool = new TestThreadPool("test");
    pageRecycler = new MockPageCacheRecycler(Settings.EMPTY);
    bigArrays = new MockBigArrays(pageRecycler, new NoneCircuitBreakerService());
}
Also used : MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) NetworkService(org.opensearch.common.network.NetworkService) MockBigArrays(org.opensearch.common.util.MockBigArrays) TestThreadPool(org.opensearch.threadpool.TestThreadPool) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 20 with MockPageCacheRecycler

use of org.opensearch.common.util.MockPageCacheRecycler in project OpenSearch by opensearch-project.

the class RecyclingBytesStreamOutputTests method testReturnsWrittenBytesAndRecyclesBufferIfPossible.

public void testReturnsWrittenBytesAndRecyclesBufferIfPossible() throws IOException {
    final byte[] source = randomUnicodeOfLength(scaledRandomIntBetween(0, 20000)).getBytes(StandardCharsets.UTF_8);
    final byte[] buffer = new byte[scaledRandomIntBetween(0, 20000)];
    final MockBigArrays bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
    try (RecyclingBytesStreamOutput output = new RecyclingBytesStreamOutput(buffer, bigArrays)) {
        int position = 0;
        while (position < source.length) {
            if (randomBoolean()) {
                output.writeByte(source[position++]);
            } else {
                final int length = randomIntBetween(1, source.length - position);
                final int sliceStart = randomIntBetween(0, position);
                final int sliceEnd = randomIntBetween(position + length, source.length);
                final byte[] slice = new byte[sliceEnd - sliceStart];
                System.arraycopy(source, sliceStart, slice, 0, slice.length);
                output.writeBytes(slice, position - sliceStart, length);
                position += length;
            }
        }
        final BytesRef bytesRef;
        if (randomBoolean()) {
            bytesRef = output.toBytesRef();
            assertThat(bytesRef.offset, equalTo(0));
            if (source.length <= buffer.length) {
                assertThat("should have re-used the same buffer", bytesRef.bytes, sameInstance(buffer));
            } else {
                assertThat("new buffer should be the right size", bytesRef.bytes.length, equalTo(source.length));
            }
        } else {
            bytesRef = output.bytes().toBytesRef();
        }
        assertThat(bytesRef.length, equalTo(source.length));
        final byte[] trimmed = new byte[source.length];
        System.arraycopy(bytesRef.bytes, bytesRef.offset, trimmed, 0, bytesRef.length);
        assertArrayEquals(source, trimmed);
    }
}
Also used : MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) MockBigArrays(org.opensearch.common.util.MockBigArrays) BytesRef(org.apache.lucene.util.BytesRef) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Aggregations

MockPageCacheRecycler (org.opensearch.common.util.MockPageCacheRecycler)31 NoneCircuitBreakerService (org.opensearch.indices.breaker.NoneCircuitBreakerService)30 MockBigArrays (org.opensearch.common.util.MockBigArrays)25 NetworkService (org.opensearch.common.network.NetworkService)11 TestThreadPool (org.opensearch.threadpool.TestThreadPool)9 ArrayList (java.util.ArrayList)8 InternalAggregation (org.opensearch.search.aggregations.InternalAggregation)8 Before (org.junit.Before)7 ScriptService (org.opensearch.script.ScriptService)7 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)5 BigArrays (org.opensearch.common.util.BigArrays)5 MultiBucketConsumerService (org.opensearch.search.aggregations.MultiBucketConsumerService)5 IndexReader (org.apache.lucene.index.IndexReader)4 IndexSearcher (org.apache.lucene.search.IndexSearcher)4 Directory (org.apache.lucene.store.Directory)4 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)3 QueryCachingPolicy (org.apache.lucene.search.QueryCachingPolicy)3 Mockito.anyString (org.mockito.Mockito.anyString)3 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)3 MappedFieldType (org.opensearch.index.mapper.MappedFieldType)3