use of org.opensearch.common.util.MockPageCacheRecycler in project OpenSearch by opensearch-project.
the class AbstractHttpServerTransportTests 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());
}
use of org.opensearch.common.util.MockPageCacheRecycler in project OpenSearch by opensearch-project.
the class DefaultRestChannelTests method setup.
@Before
public void setup() {
httpChannel = mock(HttpChannel.class);
threadPool = new TestThreadPool("test");
bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
}
use of org.opensearch.common.util.MockPageCacheRecycler in project OpenSearch by opensearch-project.
the class DefaultRestChannelTests method testCloseOnException.
public void testCloseOnException() {
final boolean close = randomBoolean();
final HttpRequest.HttpVersion httpVersion = close ? HttpRequest.HttpVersion.HTTP_1_0 : HttpRequest.HttpVersion.HTTP_1_1;
final String httpConnectionHeaderValue = close ? DefaultRestChannel.CLOSE : DefaultRestChannel.KEEP_ALIVE;
final RestRequest request = RestRequest.request(xContentRegistry(), new TestHttpRequest(httpVersion, null, "/") {
@Override
public HttpResponse createResponse(RestStatus status, BytesReference content) {
throw new IllegalArgumentException("test");
}
}, httpChannel);
request.getHttpRequest().getHeaders().put(DefaultRestChannel.CONNECTION, Collections.singletonList(httpConnectionHeaderValue));
DefaultRestChannel channel = new DefaultRestChannel(httpChannel, request.getHttpRequest(), request, bigArrays, HttpHandlingSettings.fromSettings(Settings.EMPTY), threadPool.getThreadContext(), CorsHandler.fromSettings(Settings.EMPTY), null);
// OpenSearchTestCase#after will invoke ensureAllArraysAreReleased which will fail if the response content was not released
final BigArrays bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
final ByteArray byteArray = bigArrays.newByteArray(0, false);
final BytesReference content = new ReleasableBytesReference(BytesReference.fromByteArray(byteArray, 0), byteArray);
expectThrows(IllegalArgumentException.class, () -> channel.sendResponse(new TestRestResponse(RestStatus.OK, content)));
if (close) {
verify(httpChannel, times(1)).close();
} else {
verify(httpChannel, times(0)).close();
}
}
use of org.opensearch.common.util.MockPageCacheRecycler in project OpenSearch by opensearch-project.
the class DefaultRestChannelTests method testUnsupportedHttpMethod.
public void testUnsupportedHttpMethod() {
final boolean close = randomBoolean();
final HttpRequest.HttpVersion httpVersion = close ? HttpRequest.HttpVersion.HTTP_1_0 : HttpRequest.HttpVersion.HTTP_1_1;
final String httpConnectionHeaderValue = close ? DefaultRestChannel.CLOSE : DefaultRestChannel.KEEP_ALIVE;
final RestRequest request = RestRequest.request(xContentRegistry(), new TestHttpRequest(httpVersion, null, "/") {
@Override
public RestRequest.Method method() {
throw new IllegalArgumentException("test");
}
}, httpChannel);
request.getHttpRequest().getHeaders().put(DefaultRestChannel.CONNECTION, Collections.singletonList(httpConnectionHeaderValue));
DefaultRestChannel channel = new DefaultRestChannel(httpChannel, request.getHttpRequest(), request, bigArrays, HttpHandlingSettings.fromSettings(Settings.EMPTY), threadPool.getThreadContext(), CorsHandler.fromSettings(Settings.EMPTY), null);
// OpenSearchTestCase#after will invoke ensureAllArraysAreReleased which will fail if the response content was not released
final BigArrays bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
final ByteArray byteArray = bigArrays.newByteArray(0, false);
final BytesReference content = new ReleasableBytesReference(BytesReference.fromByteArray(byteArray, 0), byteArray);
channel.sendResponse(new TestRestResponse(RestStatus.METHOD_NOT_ALLOWED, content));
Class<ActionListener<Void>> listenerClass = (Class<ActionListener<Void>>) (Class) ActionListener.class;
ArgumentCaptor<ActionListener<Void>> listenerCaptor = ArgumentCaptor.forClass(listenerClass);
verify(httpChannel).sendResponse(any(), listenerCaptor.capture());
ActionListener<Void> listener = listenerCaptor.getValue();
if (randomBoolean()) {
listener.onResponse(null);
} else {
listener.onFailure(new ClosedChannelException());
}
if (close) {
verify(httpChannel, times(1)).close();
} else {
verify(httpChannel, times(0)).close();
}
}
use of org.opensearch.common.util.MockPageCacheRecycler in project OpenSearch by opensearch-project.
the class InternalVariableWidthHistogramTests method testOverlappingReduceResult.
public void testOverlappingReduceResult() {
InternalVariableWidthHistogram dummy_histogram = createEmptyTestInstance();
List<InternalVariableWidthHistogram.Bucket> buckets = new ArrayList<>();
for (long value : new long[] { 1, 2, 4, 10 }) {
InternalVariableWidthHistogram.Bucket.BucketBounds bounds = new InternalVariableWidthHistogram.Bucket.BucketBounds(value, value + 3);
InternalVariableWidthHistogram.Bucket bucket = new InternalVariableWidthHistogram.Bucket(value, bounds, 4, format, InternalAggregations.EMPTY);
buckets.add(bucket);
}
InternalVariableWidthHistogram histogram = dummy_histogram.create(buckets);
MockBigArrays bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
ScriptService mockScriptService = mockScriptService();
MultiBucketConsumerService.MultiBucketConsumer bucketConsumer = new MultiBucketConsumerService.MultiBucketConsumer(DEFAULT_MAX_BUCKETS, new NoneCircuitBreakerService().getBreaker(CircuitBreaker.REQUEST));
InternalAggregation.ReduceContext context = InternalAggregation.ReduceContext.forFinalReduction(bigArrays, mockScriptService, bucketConsumer, PipelineAggregator.PipelineTree.EMPTY);
ArrayList<InternalAggregation> aggs = new ArrayList<>();
aggs.add(histogram);
List<InternalVariableWidthHistogram.Bucket> reduced_buckets = ((InternalVariableWidthHistogram) histogram.reduce(aggs, context)).getBuckets();
// Expected clusters: [ (1, 2), (4), 10) ]
// Expected centroids: [ 1.5, 4, 10 ]
// Expected cluster (min, max): [ (1, 5), (4, 7), (10, 13) ]
// Expected keys: [ 1, 4.5, 10 ]
// Expected doc counts: [8, 4, 4]
double double_error = 1d / 10000d;
assertEquals(1d, reduced_buckets.get(0).min(), double_error);
assertEquals(1.5, (double) reduced_buckets.get(0).getKey(), double_error);
assertEquals(8, reduced_buckets.get(0).getDocCount());
assertEquals(4.5, reduced_buckets.get(1).min(), double_error);
assertEquals(4d, (double) reduced_buckets.get(1).getKey(), double_error);
assertEquals(4, reduced_buckets.get(1).getDocCount());
assertEquals(10d, reduced_buckets.get(2).min(), double_error);
assertEquals(10d, (double) reduced_buckets.get(2).getKey(), double_error);
assertEquals(4, reduced_buckets.get(2).getDocCount());
}
Aggregations