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());
}
}
};
}
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);
}
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");
}
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());
}
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);
}
}
Aggregations