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 ZenFaultDetectionTests method testMasterFaultDetectionConnectOnDisconnect.
public void testMasterFaultDetectionConnectOnDisconnect() throws InterruptedException {
Settings.Builder settings = Settings.builder();
boolean shouldRetry = randomBoolean();
ClusterName clusterName = new ClusterName(randomAsciiOfLengthBetween(3, 20));
// make sure we don't ping
settings.put(FaultDetection.CONNECT_ON_NETWORK_DISCONNECT_SETTING.getKey(), shouldRetry).put(FaultDetection.PING_INTERVAL_SETTING.getKey(), "5m").put("cluster.name", clusterName.value());
final ClusterState state = ClusterState.builder(clusterName).nodes(buildNodesForA(false)).build();
setState(clusterServiceA, state);
MasterFaultDetection masterFD = new MasterFaultDetection(settings.build(), threadPool, serviceA, clusterServiceA);
masterFD.restart(nodeB, "test");
final String[] failureReason = new String[1];
final DiscoveryNode[] failureNode = new DiscoveryNode[1];
final CountDownLatch notified = new CountDownLatch(1);
masterFD.addListener((masterNode, cause, reason) -> {
failureNode[0] = masterNode;
failureReason[0] = reason;
notified.countDown();
});
// will raise a disconnect on A
serviceB.stop();
notified.await(30, TimeUnit.SECONDS);
CircuitBreaker inFlightRequestsBreaker = circuitBreakerService.getBreaker(CircuitBreaker.IN_FLIGHT_REQUESTS);
assertThat(inFlightRequestsBreaker.getTrippedCount(), equalTo(0L));
assertEquals(nodeB, failureNode[0]);
Matcher<String> matcher = Matchers.containsString("verified");
if (!shouldRetry) {
matcher = Matchers.not(matcher);
}
assertThat(failureReason[0], matcher);
}
Aggregations