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