use of org.elasticsearch.node.settings.NodeSettingsService 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.node.settings.NodeSettingsService in project crate by crate.
the class DecommissioningServiceTest method setUp.
@Before
public void setUp() throws Exception {
NodeSettingsService settingsService = new NodeSettingsService(Settings.EMPTY);
threadPool = mock(ThreadPool.class, Answers.RETURNS_MOCKS.get());
jobsLogs = new JobsLogs(() -> true);
sqlOperations = mock(SQLOperations.class, Answers.RETURNS_MOCKS.get());
decommissioningService = new TestableDecommissioningService(Settings.EMPTY, new NoopClusterService(), jobsLogs, threadPool, settingsService, sqlOperations, mock(TransportClusterHealthAction.class), mock(TransportClusterUpdateSettingsAction.class));
}
use of org.elasticsearch.node.settings.NodeSettingsService 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.node.settings.NodeSettingsService in project crate by crate.
the class TableStatsServiceTest method testStatsQueriesCorrectly.
@Test
public void testStatsQueriesCorrectly() throws Throwable {
ClusterService clusterService = mock(ClusterService.class);
when(clusterService.localNode()).thenReturn(mock(DiscoveryNode.class));
final SQLOperations sqlOperations = mock(SQLOperations.class);
SQLOperations.SQLDirectExecutor sqlDirectExecutor = mock(SQLOperations.SQLDirectExecutor.class);
when(sqlOperations.createSQLDirectExecutor(eq("sys"), eq(TableStatsService.TABLE_STATS), eq(TableStatsService.STMT), eq(TableStatsService.DEFAULT_SOFT_LIMIT))).thenReturn(sqlDirectExecutor);
TableStatsService statsService = new TableStatsService(Settings.EMPTY, threadPool, clusterService, new TableStats(), new NodeSettingsService(Settings.EMPTY), sqlOperations);
statsService.run();
verify(sqlDirectExecutor, times(1)).execute(any(TableStatsService.TableStatsResultReceiver.class), eq(Collections.emptyList()));
}
use of org.elasticsearch.node.settings.NodeSettingsService in project crate by crate.
the class TableStatsServiceTest method testSettingsChanges.
@Test
public void testSettingsChanges() {
ClusterService clusterService = mock(ClusterService.class);
// Initially disabled
TableStatsService statsService = new TableStatsService(Settings.builder().put(CrateSettings.STATS_SERVICE_REFRESH_INTERVAL.settingName(), 0).build(), threadPool, clusterService, new TableStats(), new NodeSettingsService(Settings.EMPTY), mock(SQLOperations.class, Answers.RETURNS_MOCKS.get()));
assertThat(statsService.lastRefreshInterval, is(TimeValue.timeValueMinutes(0)));
assertThat(statsService.refreshScheduledTask, is(nullValue()));
// Default setting
statsService = new TableStatsService(Settings.EMPTY, threadPool, clusterService, new TableStats(), new NodeSettingsService(Settings.EMPTY), mock(SQLOperations.class, Answers.RETURNS_MOCKS.get()));
assertThat(statsService.lastRefreshInterval, is(CrateSettings.STATS_SERVICE_REFRESH_INTERVAL.defaultValue()));
assertThat(statsService.refreshScheduledTask, is(notNullValue()));
// Update setting
statsService.onRefreshSettings(Settings.builder().put(CrateSettings.STATS_SERVICE_REFRESH_INTERVAL.settingName(), "10m").build());
assertThat(statsService.lastRefreshInterval, is(TimeValue.timeValueMinutes(10)));
assertThat(statsService.refreshScheduledTask, is(notNullValue()));
// Disable
statsService.onRefreshSettings(Settings.builder().put(CrateSettings.STATS_SERVICE_REFRESH_INTERVAL.settingName(), 0).build());
assertThat(statsService.lastRefreshInterval, is(TimeValue.timeValueMillis(0)));
assertThat(statsService.refreshScheduledTask, is(nullValue()));
// Reset setting
statsService.onRefreshSettings(Settings.builder().build());
assertThat(statsService.lastRefreshInterval, is(CrateSettings.STATS_SERVICE_REFRESH_INTERVAL.defaultValue()));
assertThat(statsService.refreshScheduledTask, is(notNullValue()));
}
Aggregations