@@ -936,23 +936,16 @@ public void onFinalReduce(List<SearchShard> shards, TotalHits totalHits, Interna
936
936
}
937
937
}
938
938
939
- public void testPartialReduce () throws Exception {
940
- for (int i = 0 ; i < 10 ; i ++) {
941
- testReduceCase (false );
942
- }
943
- }
944
-
945
- public void testPartialReduceWithFailure () throws Exception {
946
- for (int i = 0 ; i < 10 ; i ++) {
947
- testReduceCase (true );
948
- }
939
+ public void testCoordCircuitBreaker () throws Exception {
940
+ int numShards = randomIntBetween (20 , 200 );
941
+ testReduceCase (numShards , numShards , true );
942
+ testReduceCase (numShards , numShards , false );
943
+ testReduceCase (numShards , randomIntBetween (2 , numShards -1 ), true );
944
+ testReduceCase (numShards , randomIntBetween (2 , numShards -1 ), false );
949
945
}
950
946
951
- private void testReduceCase (boolean shouldFail ) throws Exception {
952
- int expectedNumResults = randomIntBetween (20 , 200 );
953
- int bufferSize = randomIntBetween (2 , expectedNumResults - 1 );
947
+ private void testReduceCase (int numShards , int bufferSize , boolean shouldFail ) throws Exception {
954
948
SearchRequest request = new SearchRequest ();
955
-
956
949
request .source (new SearchSourceBuilder ().aggregation (AggregationBuilders .avg ("foo" )).size (0 ));
957
950
request .setBatchedReduceSize (bufferSize );
958
951
AtomicBoolean hasConsumedFailure = new AtomicBoolean ();
@@ -963,10 +956,10 @@ private void testReduceCase(boolean shouldFail) throws Exception {
963
956
}
964
957
QueryPhaseResultConsumer consumer = searchPhaseController .newSearchPhaseResults (fixedExecutor ,
965
958
circuitBreaker , SearchProgressListener .NOOP ,
966
- request , expectedNumResults , exc -> hasConsumedFailure .set (true ));
967
- CountDownLatch latch = new CountDownLatch (expectedNumResults );
968
- Thread [] threads = new Thread [expectedNumResults ];
969
- for (int i = 0 ; i < expectedNumResults ; i ++) {
959
+ request , numShards , exc -> hasConsumedFailure .set (true ));
960
+ CountDownLatch latch = new CountDownLatch (numShards );
961
+ Thread [] threads = new Thread [numShards ];
962
+ for (int i = 0 ; i < numShards ; i ++) {
970
963
final int index = i ;
971
964
threads [index ] = new Thread (() -> {
972
965
QuerySearchResult result = new QuerySearchResult (new ShardSearchContextId (UUIDs .randomBase64UUID (), index ),
@@ -985,13 +978,15 @@ private void testReduceCase(boolean shouldFail) throws Exception {
985
978
});
986
979
threads [index ].start ();
987
980
}
988
- for (int i = 0 ; i < expectedNumResults ; i ++) {
981
+ for (int i = 0 ; i < numShards ; i ++) {
989
982
threads [i ].join ();
990
983
}
991
984
latch .await ();
992
985
if (shouldFail ) {
993
986
if (shouldFailPartial == false ) {
994
987
circuitBreaker .shouldBreak .set (true );
988
+ } else {
989
+ circuitBreaker .shouldBreak .set (false );
995
990
}
996
991
CircuitBreakingException exc = expectThrows (CircuitBreakingException .class , () -> consumer .reduce ());
997
992
assertEquals (shouldFailPartial , hasConsumedFailure .get ());
0 commit comments