use of org.elasticsearch.common.breaker.CircuitBreaker in project crate by crate.
the class RamAccountingQueueSinkTest method breaker.
public static CircuitBreaker breaker() {
CircuitBreaker circuitBreaker = mock(CircuitBreaker.class);
// mocked CircuitBreaker has unlimited memory (⌐■_■)
when(circuitBreaker.getLimit()).thenReturn(Long.MAX_VALUE);
return circuitBreaker;
}
use of org.elasticsearch.common.breaker.CircuitBreaker in project crate by crate.
the class CrateCircuitBreakerServiceTest method testBreakerSettingsAssignment.
@Test
public void testBreakerSettingsAssignment() throws Exception {
Settings settings = Settings.builder().put(CrateCircuitBreakerService.QUERY_CIRCUIT_BREAKER_LIMIT_SETTING, "10m").put(CrateCircuitBreakerService.QUERY_CIRCUIT_BREAKER_OVERHEAD_SETTING, 1.0).build();
final NodeSettingsService.Listener[] listeners = new NodeSettingsService.Listener[1];
NodeSettingsService settingsService = new NodeSettingsService(settings) {
@Override
public void addListener(Listener listener) {
listeners[0] = listener;
}
};
CircuitBreakerService esBreakerService = spy(new HierarchyCircuitBreakerService(Settings.EMPTY, settingsService));
CrateCircuitBreakerService breakerService = new CrateCircuitBreakerService(settings, settingsService, esBreakerService);
CircuitBreaker breaker = breakerService.getBreaker(CrateCircuitBreakerService.QUERY);
assertThat(breaker.getLimit(), is(10_485_760L));
assertThat(breaker.getOverhead(), is(1.0));
Settings newSettings = Settings.settingsBuilder().put(CrateCircuitBreakerService.QUERY_CIRCUIT_BREAKER_LIMIT_SETTING, "100m").put(CrateCircuitBreakerService.QUERY_CIRCUIT_BREAKER_OVERHEAD_SETTING, 2.0).build();
listeners[0].onRefreshSettings(newSettings);
// expecting 4 times because registerBreaker() is also called from constructor of CrateCircuitBreakerService 3 times
verify(esBreakerService, times(4)).registerBreaker(Matchers.any());
breaker = breakerService.getBreaker(CrateCircuitBreakerService.QUERY);
assertThat(breaker.getLimit(), is(104_857_600L));
assertThat(breaker.getOverhead(), is(2.0));
// updating with same settings should not register a new breaker
listeners[0].onRefreshSettings(newSettings);
verify(esBreakerService, times(4)).registerBreaker(Matchers.any());
}
use of org.elasticsearch.common.breaker.CircuitBreaker in project crate by crate.
the class CrateCircuitBreakerServiceTest method testQueryCircuitBreakerDynamicSettings.
@Test
public void testQueryCircuitBreakerDynamicSettings() throws Exception {
final NodeSettingsService.Listener[] listeners = new NodeSettingsService.Listener[1];
NodeSettingsService settingsService = new NodeSettingsService(Settings.EMPTY) {
@Override
public void addListener(Listener listener) {
listeners[0] = listener;
}
};
CircuitBreakerService esBreakerService = new HierarchyCircuitBreakerService(Settings.EMPTY, settingsService);
CrateCircuitBreakerService breakerService = new CrateCircuitBreakerService(Settings.EMPTY, settingsService, esBreakerService);
Settings newSettings = Settings.settingsBuilder().put(CrateCircuitBreakerService.QUERY_CIRCUIT_BREAKER_OVERHEAD_SETTING, 2.0).build();
listeners[0].onRefreshSettings(newSettings);
CircuitBreaker breaker = breakerService.getBreaker(CrateCircuitBreakerService.QUERY);
assertThat(breaker, notNullValue());
assertThat(breaker, instanceOf(CircuitBreaker.class));
assertThat(breaker.getOverhead(), is(2.0));
}
use of org.elasticsearch.common.breaker.CircuitBreaker in project elasticsearch by elastic.
the class InternalTestCluster method assertRequestsFinished.
private void assertRequestsFinished() {
if (size() > 0) {
for (NodeAndClient nodeAndClient : nodes.values()) {
CircuitBreaker inFlightRequestsBreaker = getInstance(CircuitBreakerService.class, nodeAndClient.name).getBreaker(CircuitBreaker.IN_FLIGHT_REQUESTS);
try {
// see #ensureEstimatedStats()
assertBusy(() -> {
// ensure that our size accounting on transport level is reset properly
long bytesUsed = inFlightRequestsBreaker.getUsed();
assertThat("All incoming requests on node [" + nodeAndClient.name + "] should have finished. Expected 0 but got " + bytesUsed, bytesUsed, equalTo(0L));
});
} catch (Exception e) {
logger.error("Could not assert finished requests within timeout", e);
fail("Could not assert finished requests within timeout on node [" + nodeAndClient.name + "]");
}
}
}
}
use of org.elasticsearch.common.breaker.CircuitBreaker in project elasticsearch by elastic.
the class HierarchyCircuitBreakerService method stats.
@Override
public AllCircuitBreakerStats stats() {
long parentEstimated = 0;
List<CircuitBreakerStats> allStats = new ArrayList<>();
// estimations for each individual breaker
for (CircuitBreaker breaker : this.breakers.values()) {
allStats.add(stats(breaker.getName()));
parentEstimated += breaker.getUsed();
}
// Manually add the parent breaker settings since they aren't part of the breaker map
allStats.add(new CircuitBreakerStats(CircuitBreaker.PARENT, parentSettings.getLimit(), parentEstimated, 1.0, parentTripCount.get()));
return new AllCircuitBreakerStats(allStats.toArray(new CircuitBreakerStats[allStats.size()]));
}
Aggregations