|
47 | 47 | import org.elasticsearch.cluster.routing.ShardRouting;
|
48 | 48 | import org.elasticsearch.cluster.routing.ShardRoutingState;
|
49 | 49 | import org.elasticsearch.cluster.routing.TestShardRouting;
|
| 50 | +import org.elasticsearch.cluster.service.ClusterService; |
50 | 51 | import org.elasticsearch.common.UUIDs;
|
| 52 | +import org.elasticsearch.common.breaker.CircuitBreakingException; |
| 53 | +import org.elasticsearch.common.breaker.NoopCircuitBreaker; |
51 | 54 | import org.elasticsearch.common.bytes.BytesArray;
|
52 | 55 | import org.elasticsearch.common.bytes.BytesReference;
|
53 | 56 | import org.elasticsearch.common.io.stream.StreamInput;
|
|
151 | 154 | import java.util.concurrent.atomic.AtomicInteger;
|
152 | 155 | import java.util.function.Consumer;
|
153 | 156 | import java.util.function.Function;
|
| 157 | +import java.util.function.IntConsumer; |
154 | 158 | import java.util.function.Supplier;
|
155 | 159 |
|
156 | 160 | import static java.util.Collections.emptyList;
|
@@ -1985,6 +1989,38 @@ public void testCreateReduceContext() {
|
1985 | 1989 | }
|
1986 | 1990 | }
|
1987 | 1991 |
|
| 1992 | + public void testMultiBucketConsumerServiceCB() { |
| 1993 | + MultiBucketConsumerService service = new MultiBucketConsumerService( |
| 1994 | + getInstanceFromNode(ClusterService.class), |
| 1995 | + Settings.EMPTY, |
| 1996 | + new NoopCircuitBreaker("test") { |
| 1997 | + |
| 1998 | + @Override |
| 1999 | + public void addEstimateBytesAndMaybeBreak(long bytes, String label) throws CircuitBreakingException { |
| 2000 | + throw new CircuitBreakingException("tripped", getDurability()); |
| 2001 | + } |
| 2002 | + } |
| 2003 | + ); |
| 2004 | + // for partial |
| 2005 | + { |
| 2006 | + IntConsumer consumer = service.createForPartial(); |
| 2007 | + for (int i = 0; i < 1023; i++) { |
| 2008 | + consumer.accept(0); |
| 2009 | + } |
| 2010 | + CircuitBreakingException ex = expectThrows(CircuitBreakingException.class, () -> consumer.accept(0)); |
| 2011 | + assertThat(ex.getMessage(), equalTo("tripped")); |
| 2012 | + } |
| 2013 | + // for final |
| 2014 | + { |
| 2015 | + IntConsumer consumer = service.createForFinal(); |
| 2016 | + for (int i = 0; i < 1023; i++) { |
| 2017 | + consumer.accept(0); |
| 2018 | + } |
| 2019 | + CircuitBreakingException ex = expectThrows(CircuitBreakingException.class, () -> consumer.accept(0)); |
| 2020 | + assertThat(ex.getMessage(), equalTo("tripped")); |
| 2021 | + } |
| 2022 | + } |
| 2023 | + |
1988 | 2024 | public void testCreateSearchContext() throws IOException {
|
1989 | 2025 | String index = randomAlphaOfLengthBetween(5, 10).toLowerCase(Locale.ROOT);
|
1990 | 2026 | IndexService indexService = createIndex(index);
|
|
0 commit comments