use of org.opensearch.indices.breaker.NoneCircuitBreakerService in project OpenSearch by opensearch-project.
the class GatewayMetaStatePersistedStateTests method setUp.
@Override
public void setUp() throws Exception {
bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
nodeEnvironment = newNodeEnvironment();
localNode = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Collections.emptyMap(), Sets.newHashSet(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
clusterName = new ClusterName(randomAlphaOfLength(10));
settings = Settings.builder().put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName.value()).build();
super.setUp();
}
use of org.opensearch.indices.breaker.NoneCircuitBreakerService in project OpenSearch by opensearch-project.
the class BucketsAggregatorTests method buildMergeAggregator.
public BucketsAggregator buildMergeAggregator() throws IOException {
try (Directory directory = newDirectory()) {
try (RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) {
Document document = new Document();
document.add(new SortedNumericDocValuesField("numeric", 0));
indexWriter.addDocument(document);
}
try (IndexReader indexReader = DirectoryReader.open(directory)) {
IndexSearcher indexSearcher = new IndexSearcher(indexReader);
SearchContext searchContext = createSearchContext(indexSearcher, createIndexSettings(), null, new MultiBucketConsumerService.MultiBucketConsumer(DEFAULT_MAX_BUCKETS, new NoneCircuitBreakerService().getBreaker(CircuitBreaker.REQUEST)), new NumberFieldMapper.NumberFieldType("test", NumberFieldMapper.NumberType.INTEGER));
return new BucketsAggregator("test", AggregatorFactories.EMPTY, searchContext, null, null, null) {
@Override
protected LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub) throws IOException {
return null;
}
@Override
public InternalAggregation[] buildAggregations(long[] owningBucketOrds) throws IOException {
return new InternalAggregation[0];
}
@Override
public InternalAggregation buildEmptyAggregation() {
return null;
}
};
}
}
}
use of org.opensearch.indices.breaker.NoneCircuitBreakerService in project OpenSearch by opensearch-project.
the class BestDocsDeferringCollectorTests method testReplay.
public void testReplay() throws Exception {
Directory directory = newDirectory();
RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
int numDocs = randomIntBetween(1, 128);
int maxNumValues = randomInt(16);
for (int i = 0; i < numDocs; i++) {
Document document = new Document();
document.add(new StringField("field", String.valueOf(randomInt(maxNumValues)), Field.Store.NO));
indexWriter.addDocument(document);
}
indexWriter.close();
IndexReader indexReader = DirectoryReader.open(directory);
IndexSearcher indexSearcher = new IndexSearcher(indexReader);
TermQuery termQuery = new TermQuery(new Term("field", String.valueOf(randomInt(maxNumValues))));
TopDocs topDocs = indexSearcher.search(termQuery, numDocs);
final AtomicLong bytes = new AtomicLong(0);
BestDocsDeferringCollector collector = new BestDocsDeferringCollector(numDocs, new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService()), bytes::addAndGet);
Set<Integer> deferredCollectedDocIds = new HashSet<>();
collector.setDeferredCollector(Collections.singleton(testCollector(deferredCollectedDocIds)));
collector.preCollection();
indexSearcher.search(termQuery, collector);
collector.postCollection();
collector.prepareSelectedBuckets(0);
assertEquals(topDocs.scoreDocs.length, deferredCollectedDocIds.size());
for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
assertTrue("expected docid [" + scoreDoc.doc + "] is missing", deferredCollectedDocIds.contains(scoreDoc.doc));
}
collector.close();
indexReader.close();
directory.close();
}
use of org.opensearch.indices.breaker.NoneCircuitBreakerService in project OpenSearch by opensearch-project.
the class InternalVariableWidthHistogramTests method testSingleShardReduceLong.
public void testSingleShardReduceLong() {
InternalVariableWidthHistogram dummy_histogram = createEmptyTestInstance();
List<InternalVariableWidthHistogram.Bucket> buckets = new ArrayList<>();
for (long value : new long[] { 1, 2, 5, 10, 12, 200 }) {
InternalVariableWidthHistogram.Bucket.BucketBounds bounds = new InternalVariableWidthHistogram.Bucket.BucketBounds(value, value + 1);
InternalVariableWidthHistogram.Bucket bucket = new InternalVariableWidthHistogram.Bucket(value, bounds, 3, 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();
// Final clusters should be [ (1,2,5), (10,12), 200) ]
// Final centroids should be [ 3, 11, 200 ]
// Final keys should be [ 1, 5, 200 ]
double double_error = 1d / 10000d;
assertEquals(1d, reduced_buckets.get(0).min(), double_error);
assertEquals((8d / 3d), (double) reduced_buckets.get(0).getKey(), double_error);
assertEquals(9, reduced_buckets.get(0).getDocCount());
assertEquals(10d, reduced_buckets.get(1).min(), double_error);
assertEquals(11d, (double) reduced_buckets.get(1).getKey(), double_error);
assertEquals(6, reduced_buckets.get(1).getDocCount());
assertEquals(200d, reduced_buckets.get(2).min(), double_error);
assertEquals(200d, (double) reduced_buckets.get(2).getKey(), double_error);
assertEquals(3, reduced_buckets.get(2).getDocCount());
}
use of org.opensearch.indices.breaker.NoneCircuitBreakerService in project OpenSearch by opensearch-project.
the class InternalVariableWidthHistogramTests method testSingleShardReduceDouble.
public void testSingleShardReduceDouble() {
InternalVariableWidthHistogram dummy_histogram = createEmptyTestInstance();
List<InternalVariableWidthHistogram.Bucket> buckets = new ArrayList<>();
for (double value : new double[] { -1.3, -1.3, 12.0, 13.0, 20.0, 21.5, 23.0, 24.5 }) {
InternalVariableWidthHistogram.Bucket.BucketBounds bounds = new InternalVariableWidthHistogram.Bucket.BucketBounds(value - 0.7, value + 1);
InternalVariableWidthHistogram.Bucket bucket = new InternalVariableWidthHistogram.Bucket(value, bounds, 1, 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();
// Final clusters should be [ (-1.3,-1.3), (12.0,13.0), (20.0, 21.5, 23.0, 24.5) ]
// Final centroids should be [ -1.3, 12.5, 22.25 ]
// Final keys should be [ -1.3, 11.7, 19.7 ]
double double_error = 1d / 10000d;
assertEquals(-2.0, reduced_buckets.get(0).min(), double_error);
assertEquals(-1.3, (double) reduced_buckets.get(0).getKey(), double_error);
assertEquals(2, reduced_buckets.get(0).getDocCount());
assertEquals(11.3, reduced_buckets.get(1).min(), double_error);
assertEquals(12.5, (double) reduced_buckets.get(1).getKey(), double_error);
assertEquals(2, reduced_buckets.get(1).getDocCount());
assertEquals(19.3, reduced_buckets.get(2).min(), double_error);
assertEquals(22.25, (double) reduced_buckets.get(2).getKey(), double_error);
assertEquals(4, reduced_buckets.get(2).getDocCount());
}
Aggregations