Search in sources :

Example 6 with ClusterService

use of org.elasticsearch.cluster.ClusterService in project crate by crate.

the class PingTaskTest method prepare.

@Before
public void prepare() throws Exception {
    clusterService = mock(ClusterService.class);
    clusterIdService = mock(ClusterIdService.class);
    DiscoveryNode discoveryNode = mock(DiscoveryNode.class);
    SettableFuture<ClusterId> clusterIdFuture = SettableFuture.create();
    clusterIdFuture.set(new ClusterId());
    when(clusterIdService.clusterId()).thenReturn(clusterIdFuture);
    when(clusterService.localNode()).thenReturn(discoveryNode);
    when(discoveryNode.isMasterNode()).thenReturn(true);
    extendedNodeInfo = mock(ExtendedNodeInfo.class);
    when(extendedNodeInfo.networkInfo()).thenReturn(new ExtendedNetworkInfo(ExtendedNetworkInfo.NA_INTERFACE));
    when(extendedNodeInfo.osInfo()).thenReturn(new ExtendedOsInfo(Collections.emptyMap()));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterService(org.elasticsearch.cluster.ClusterService) ClusterId(io.crate.ClusterId) ExtendedNodeInfo(io.crate.monitor.ExtendedNodeInfo) ClusterIdService(io.crate.ClusterIdService) ExtendedOsInfo(io.crate.monitor.ExtendedOsInfo) ExtendedNetworkInfo(io.crate.monitor.ExtendedNetworkInfo) Before(org.junit.Before)

Example 7 with ClusterService

use of org.elasticsearch.cluster.ClusterService in project crate by crate.

the class SelectStatementAnalyzerTest method init.

@Before
public void init() throws Exception {
    DocTableInfo fooUserTableInfo = TestingTableInfo.builder(new TableIdent("foo", "users"), SHARD_ROUTING).add("id", DataTypes.LONG, null).add("name", DataTypes.STRING, null).addPrimaryKey("id").build();
    DocTableInfoFactory fooTableFactory = new TestingDocTableInfoFactory(ImmutableMap.of(fooUserTableInfo.ident(), fooUserTableInfo));
    ClusterService clusterService = new NoopClusterService();
    sqlExecutor = SQLExecutor.builder(clusterService).enableDefaultTables().addSchema(new DocSchemaInfo("foo", clusterService, fooTableFactory)).build();
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) TestingDocTableInfoFactory(io.crate.metadata.doc.TestingDocTableInfoFactory) TableIdent(io.crate.metadata.TableIdent) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) DocTableInfoFactory(io.crate.metadata.doc.DocTableInfoFactory) TestingDocTableInfoFactory(io.crate.metadata.doc.TestingDocTableInfoFactory) Before(org.junit.Before)

Example 8 with ClusterService

use of org.elasticsearch.cluster.ClusterService in project crate by crate.

the class SysShardsExpressionsTest method prepare.

@Before
public void prepare() throws Exception {
    ClusterService clusterService = new NoopClusterService();
    indexShard = mockIndexShard();
    schemas = new Schemas(Settings.EMPTY, ImmutableMap.of("sys", new SysSchemaInfo(clusterService)), clusterService, new DocSchemaInfoFactory(new TestingDocTableInfoFactory(Collections.emptyMap())));
    ShardReferenceResolver shardRefResolver = new ShardReferenceResolver(clusterService, schemas, indexShard);
    resolver = new RecoveryShardReferenceResolver(shardRefResolver, indexShard);
}
Also used : SysSchemaInfo(io.crate.metadata.sys.SysSchemaInfo) RecoveryShardReferenceResolver(io.crate.metadata.shard.RecoveryShardReferenceResolver) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) DocSchemaInfoFactory(io.crate.metadata.doc.DocSchemaInfoFactory) TestingDocTableInfoFactory(io.crate.metadata.doc.TestingDocTableInfoFactory) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ShardReferenceResolver(io.crate.metadata.shard.ShardReferenceResolver) RecoveryShardReferenceResolver(io.crate.metadata.shard.RecoveryShardReferenceResolver) Before(org.junit.Before)

Example 9 with ClusterService

use of org.elasticsearch.cluster.ClusterService 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 10 with ClusterService

use of org.elasticsearch.cluster.ClusterService 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

ClusterService (org.elasticsearch.cluster.ClusterService)19 Test (org.junit.Test)13 CrateUnitTest (io.crate.test.integration.CrateUnitTest)11 NoopClusterService (org.elasticsearch.test.cluster.NoopClusterService)9 ClusterState (org.elasticsearch.cluster.ClusterState)6 IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)5 TableIdent (io.crate.metadata.TableIdent)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 ActionListener (org.elasticsearch.action.ActionListener)4 Settings (org.elasticsearch.common.settings.Settings)4 ShardId (org.elasticsearch.index.shard.ShardId)4 Before (org.junit.Before)4 SQLOperations (io.crate.action.sql.SQLOperations)3 ShardResponse (io.crate.executor.transport.ShardResponse)3 ShardUpsertRequest (io.crate.executor.transport.ShardUpsertRequest)3 Reference (io.crate.metadata.Reference)3 ReferenceIdent (io.crate.metadata.ReferenceIdent)3 RowGranularity (io.crate.metadata.RowGranularity)3 DataTypes (io.crate.types.DataTypes)3