Search in sources :

Example 1 with NodeSettingsService

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());
}
Also used : CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) NodeSettingsService(org.elasticsearch.node.settings.NodeSettingsService) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with NodeSettingsService

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));
}
Also used : ThreadPool(org.elasticsearch.threadpool.ThreadPool) JobsLogs(io.crate.operation.collect.stats.JobsLogs) NodeSettingsService(org.elasticsearch.node.settings.NodeSettingsService) SQLOperations(io.crate.action.sql.SQLOperations) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Before(org.junit.Before)

Example 3 with NodeSettingsService

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));
}
Also used : CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) NodeSettingsService(org.elasticsearch.node.settings.NodeSettingsService) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 4 with NodeSettingsService

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()));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterService(org.elasticsearch.cluster.ClusterService) NodeSettingsService(org.elasticsearch.node.settings.NodeSettingsService) SQLOperations(io.crate.action.sql.SQLOperations) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 5 with NodeSettingsService

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()));
}
Also used : ClusterService(org.elasticsearch.cluster.ClusterService) NodeSettingsService(org.elasticsearch.node.settings.NodeSettingsService) SQLOperations(io.crate.action.sql.SQLOperations) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

NodeSettingsService (org.elasticsearch.node.settings.NodeSettingsService)6 CrateUnitTest (io.crate.test.integration.CrateUnitTest)5 Test (org.junit.Test)5 SQLOperations (io.crate.action.sql.SQLOperations)4 ClusterService (org.elasticsearch.cluster.ClusterService)3 CircuitBreaker (org.elasticsearch.common.breaker.CircuitBreaker)2 Settings (org.elasticsearch.common.settings.Settings)2 CircuitBreakerService (org.elasticsearch.indices.breaker.CircuitBreakerService)2 HierarchyCircuitBreakerService (org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService)2 JobsLogs (io.crate.operation.collect.stats.JobsLogs)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 NoopClusterService (org.elasticsearch.test.cluster.NoopClusterService)1 ThreadPool (org.elasticsearch.threadpool.ThreadPool)1 Before (org.junit.Before)1