Remove closeAgg
This commit is contained in:
parent
d9c37ce195
commit
0dee1f85e6
|
@ -54,16 +54,6 @@ public abstract class DeferringBucketCollector extends BucketCollector {
|
||||||
return new WrappedAggregator(in);
|
return new WrappedAggregator(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Unwrap an aggregator. Used for testing.
|
|
||||||
*/
|
|
||||||
public static Aggregator unwrap(Aggregator in) {
|
|
||||||
if (in instanceof WrappedAggregator) {
|
|
||||||
return ((WrappedAggregator) in).in;
|
|
||||||
}
|
|
||||||
return in;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class WrappedAggregator extends Aggregator {
|
protected class WrappedAggregator extends Aggregator {
|
||||||
private Aggregator in;
|
private Aggregator in;
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,8 @@ import org.apache.lucene.search.QueryCachingPolicy;
|
||||||
import org.apache.lucene.search.Weight;
|
import org.apache.lucene.search.Weight;
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
|
import org.elasticsearch.common.lease.Releasable;
|
||||||
|
import org.elasticsearch.common.lease.Releasables;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.util.MockBigArrays;
|
import org.elasticsearch.common.util.MockBigArrays;
|
||||||
import org.elasticsearch.index.IndexSettings;
|
import org.elasticsearch.index.IndexSettings;
|
||||||
|
@ -41,7 +43,6 @@ import org.elasticsearch.index.mapper.MapperService;
|
||||||
import org.elasticsearch.index.query.QueryShardContext;
|
import org.elasticsearch.index.query.QueryShardContext;
|
||||||
import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
||||||
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
|
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
|
||||||
import org.elasticsearch.search.aggregations.bucket.DeferringBucketCollector;
|
|
||||||
import org.elasticsearch.search.fetch.FetchPhase;
|
import org.elasticsearch.search.fetch.FetchPhase;
|
||||||
import org.elasticsearch.search.fetch.subphase.DocValueFieldsFetchSubPhase;
|
import org.elasticsearch.search.fetch.subphase.DocValueFieldsFetchSubPhase;
|
||||||
import org.elasticsearch.search.fetch.subphase.FetchSourceSubPhase;
|
import org.elasticsearch.search.fetch.subphase.FetchSourceSubPhase;
|
||||||
|
@ -56,6 +57,8 @@ import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.mockito.Matchers.anyObject;
|
||||||
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@ -65,6 +68,8 @@ import static org.mockito.Mockito.when;
|
||||||
* {@link AggregationBuilder} instance.
|
* {@link AggregationBuilder} instance.
|
||||||
*/
|
*/
|
||||||
public abstract class AggregatorTestCase extends ESTestCase {
|
public abstract class AggregatorTestCase extends ESTestCase {
|
||||||
|
private List<Releasable> releasables = new ArrayList<>();
|
||||||
|
|
||||||
protected <A extends Aggregator, B extends AggregationBuilder> A createAggregator(B aggregationBuilder,
|
protected <A extends Aggregator, B extends AggregationBuilder> A createAggregator(B aggregationBuilder,
|
||||||
IndexSearcher indexSearcher,
|
IndexSearcher indexSearcher,
|
||||||
MappedFieldType... fieldTypes) throws IOException {
|
MappedFieldType... fieldTypes) throws IOException {
|
||||||
|
@ -99,6 +104,10 @@ public abstract class AggregatorTestCase extends ESTestCase {
|
||||||
when(searchContext.bigArrays()).thenReturn(new MockBigArrays(Settings.EMPTY, circuitBreakerService));
|
when(searchContext.bigArrays()).thenReturn(new MockBigArrays(Settings.EMPTY, circuitBreakerService));
|
||||||
when(searchContext.fetchPhase())
|
when(searchContext.fetchPhase())
|
||||||
.thenReturn(new FetchPhase(Arrays.asList(new FetchSourceSubPhase(), new DocValueFieldsFetchSubPhase())));
|
.thenReturn(new FetchPhase(Arrays.asList(new FetchSourceSubPhase(), new DocValueFieldsFetchSubPhase())));
|
||||||
|
doAnswer(invocation -> {
|
||||||
|
releasables.add((Releasable) invocation.getArguments()[0]);
|
||||||
|
return null;
|
||||||
|
}).when(searchContext).addReleasable(anyObject(), anyObject());
|
||||||
|
|
||||||
// TODO: now just needed for top_hits, this will need to be revised for other agg unit tests:
|
// TODO: now just needed for top_hits, this will need to be revised for other agg unit tests:
|
||||||
MapperService mapperService = mock(MapperService.class);
|
MapperService mapperService = mock(MapperService.class);
|
||||||
|
@ -134,7 +143,8 @@ public abstract class AggregatorTestCase extends ESTestCase {
|
||||||
A internalAgg = (A) a.buildAggregation(0L);
|
A internalAgg = (A) a.buildAggregation(0L);
|
||||||
return internalAgg;
|
return internalAgg;
|
||||||
} finally {
|
} finally {
|
||||||
closeAgg(a);
|
Releasables.close(releasables);
|
||||||
|
releasables.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,14 +180,10 @@ public abstract class AggregatorTestCase extends ESTestCase {
|
||||||
try {
|
try {
|
||||||
for (ShardSearcher subSearcher : subSearchers) {
|
for (ShardSearcher subSearcher : subSearchers) {
|
||||||
C a = createAggregator(builder, subSearcher, fieldTypes);
|
C a = createAggregator(builder, subSearcher, fieldTypes);
|
||||||
try {
|
a.preCollection();
|
||||||
a.preCollection();
|
subSearcher.search(weight, a);
|
||||||
subSearcher.search(weight, a);
|
a.postCollection();
|
||||||
a.postCollection();
|
aggs.add(a.buildAggregation(0L));
|
||||||
aggs.add(a.buildAggregation(0L));
|
|
||||||
} finally {
|
|
||||||
closeAgg(a);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (aggs.isEmpty()) {
|
if (aggs.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -187,15 +193,8 @@ public abstract class AggregatorTestCase extends ESTestCase {
|
||||||
return internalAgg;
|
return internalAgg;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
closeAgg(root);
|
Releasables.close(releasables);
|
||||||
}
|
releasables.clear();
|
||||||
}
|
|
||||||
|
|
||||||
private void closeAgg(Aggregator agg) {
|
|
||||||
agg = DeferringBucketCollector.unwrap(agg);
|
|
||||||
agg.close();
|
|
||||||
for (Aggregator sub : ((AggregatorBase) agg).subAggregators) {
|
|
||||||
closeAgg(sub);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class SamplerAggregatorTests extends AggregatorTestCase {
|
||||||
Sampler sampler = searchAndReduce(searcher, new TermQuery(new Term("text", "good")), aggBuilder, textFieldType,
|
Sampler sampler = searchAndReduce(searcher, new TermQuery(new Term("text", "good")), aggBuilder, textFieldType,
|
||||||
numericFieldType);
|
numericFieldType);
|
||||||
Min min = sampler.getAggregations().get("min");
|
Min min = sampler.getAggregations().get("min");
|
||||||
assertEquals(5.0, min.getValue(), Double.MIN_NORMAL);
|
assertEquals(5.0, min.getValue(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue