Search in sources :

Example 11 with ClusterService

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

the class DocIndexMetaDataTest method getDocIndexMetaDataFromStatement.

private DocIndexMetaData getDocIndexMetaDataFromStatement(String stmt) throws IOException {
    Statement statement = SqlParser.createStatement(stmt);
    ClusterService clusterService = new NoopClusterService();
    final TransportPutIndexTemplateAction transportPutIndexTemplateAction = mock(TransportPutIndexTemplateAction.class);
    Provider<TransportPutIndexTemplateAction> indexTemplateActionProvider = new Provider<TransportPutIndexTemplateAction>() {

        @Override
        public TransportPutIndexTemplateAction get() {
            return transportPutIndexTemplateAction;
        }
    };
    DocTableInfoFactory docTableInfoFactory = new InternalDocTableInfoFactory(functions, new IndexNameExpressionResolver(Settings.EMPTY), indexTemplateActionProvider, executorService);
    DocSchemaInfo docSchemaInfo = new DocSchemaInfo(Schemas.DEFAULT_SCHEMA_NAME, clusterService, docTableInfoFactory);
    CreateTableStatementAnalyzer analyzer = new CreateTableStatementAnalyzer(new Schemas(Settings.EMPTY, ImmutableMap.<String, SchemaInfo>of("doc", docSchemaInfo), clusterService, new DocSchemaInfoFactory(docTableInfoFactory)), new FulltextAnalyzerResolver(clusterService, new IndicesAnalysisService(Settings.EMPTY)), functions, new NumberOfShards(clusterService));
    Analysis analysis = new Analysis(SessionContext.SYSTEM_SESSION, ParameterContext.EMPTY, ParamTypeHints.EMPTY);
    CreateTableAnalyzedStatement analyzedStatement = analyzer.analyze((CreateTable) statement, analysis.parameterContext(), analysis.sessionContext());
    Settings.Builder settingsBuilder = Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put("index.version.created", org.elasticsearch.Version.CURRENT).put(analyzedStatement.tableParameter().settings());
    IndexMetaData indexMetaData = IndexMetaData.builder(analyzedStatement.tableIdent().name()).settings(settingsBuilder).putMapping(new MappingMetaData(Constants.DEFAULT_MAPPING_TYPE, analyzedStatement.mapping())).build();
    return newMeta(indexMetaData, analyzedStatement.tableIdent().name());
}
Also used : IndicesAnalysisService(org.elasticsearch.indices.analysis.IndicesAnalysisService) Statement(io.crate.sql.tree.Statement) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) Provider(org.elasticsearch.common.inject.Provider) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) TransportPutIndexTemplateAction(org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Settings(org.elasticsearch.common.settings.Settings) SchemaInfo(io.crate.metadata.table.SchemaInfo)

Example 12 with ClusterService

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

the class RepositoryServiceTest method testRepositoryIsDroppedOnFailure.

@Test
public void testRepositoryIsDroppedOnFailure() throws Throwable {
    expectedException.expect(RepositoryException.class);
    // add repo to cluster service so that it exists..
    RepositoriesMetaData repos = new RepositoriesMetaData(new RepositoryMetaData("repo1", "fs", Settings.EMPTY));
    ClusterState state = ClusterState.builder(new ClusterName("dummy")).metaData(MetaData.builder().putCustom(RepositoriesMetaData.TYPE, repos)).build();
    ClusterService clusterService = new NoopClusterService(state);
    final ActionFilters actionFilters = mock(ActionFilters.class, Answers.RETURNS_MOCKS.get());
    IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(Settings.EMPTY);
    final AtomicBoolean deleteRepoCalled = new AtomicBoolean(false);
    TransportDeleteRepositoryAction deleteRepositoryAction = new TransportDeleteRepositoryAction(Settings.EMPTY, mock(TransportService.class, Answers.RETURNS_MOCKS.get()), clusterService, mock(RepositoriesService.class), threadPool, actionFilters, indexNameExpressionResolver) {

        @Override
        protected void doExecute(Task task, DeleteRepositoryRequest request, ActionListener<DeleteRepositoryResponse> listener) {
            deleteRepoCalled.set(true);
            listener.onResponse(mock(DeleteRepositoryResponse.class));
        }
    };
    TransportPutRepositoryAction putRepo = new TransportPutRepositoryAction(Settings.EMPTY, mock(TransportService.class, Answers.RETURNS_MOCKS.get()), clusterService, mock(RepositoriesService.class), threadPool, actionFilters, indexNameExpressionResolver) {

        @Override
        protected void doExecute(Task task, PutRepositoryRequest request, ActionListener<PutRepositoryResponse> listener) {
            listener.onFailure(new RepositoryException(request.name(), "failure"));
        }
    };
    RepositoryService repositoryService = new RepositoryService(clusterService, deleteRepositoryAction, putRepo);
    try {
        repositoryService.execute(new CreateRepositoryAnalyzedStatement("repo1", "fs", Settings.EMPTY)).get(10, TimeUnit.SECONDS);
    } catch (ExecutionException e) {
        assertThat(deleteRepoCalled.get(), is(true));
        throw e.getCause();
    }
}
Also used : RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) ClusterState(org.elasticsearch.cluster.ClusterState) Task(org.elasticsearch.tasks.Task) TransportDeleteRepositoryAction(org.elasticsearch.action.admin.cluster.repositories.delete.TransportDeleteRepositoryAction) DeleteRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest) RepositoryException(org.elasticsearch.repositories.RepositoryException) ActionFilters(org.elasticsearch.action.support.ActionFilters) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CreateRepositoryAnalyzedStatement(io.crate.analyze.CreateRepositoryAnalyzedStatement) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) DeleteRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryResponse) ActionListener(org.elasticsearch.action.ActionListener) TransportService(org.elasticsearch.transport.TransportService) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) TransportPutRepositoryAction(org.elasticsearch.action.admin.cluster.repositories.put.TransportPutRepositoryAction) ExecutionException(java.util.concurrent.ExecutionException) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 13 with ClusterService

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

the class SysNodeChecksTest method testRecoveryAfterNodesCheckWithLessThanQuorum.

@Test
public void testRecoveryAfterNodesCheckWithLessThanQuorum() {
    ClusterService clusterService = mock(ClusterService.class, Answers.RETURNS_DEEP_STUBS.get());
    RecoveryAfterNodesSysCheck recoveryAfterNodesCheck = new RecoveryAfterNodesSysCheck(clusterService, Settings.EMPTY);
    when(clusterService.state().nodes().getSize()).thenReturn(8);
    assertThat(recoveryAfterNodesCheck.id(), is(2));
    assertThat(recoveryAfterNodesCheck.severity(), is(SysCheck.Severity.HIGH));
    assertThat(recoveryAfterNodesCheck.validate(4, 8), is(false));
}
Also used : NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 14 with ClusterService

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

the class SysNodeChecksTest method testRecoveryAfterNodesCheckWithCorrectSetting.

@Test
public void testRecoveryAfterNodesCheckWithCorrectSetting() {
    ClusterService clusterService = mock(ClusterService.class, Answers.RETURNS_DEEP_STUBS.get());
    RecoveryAfterNodesSysCheck recoveryAfterNodesCheck = applyAndAssertNodeId(new RecoveryAfterNodesSysCheck(clusterService, Settings.EMPTY));
    when(clusterService.state().nodes().getSize()).thenReturn(8);
    assertThat(recoveryAfterNodesCheck.id(), is(2));
    assertThat(recoveryAfterNodesCheck.severity(), is(SysCheck.Severity.HIGH));
    assertThat(recoveryAfterNodesCheck.validate(8, 8), is(true));
}
Also used : NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 15 with ClusterService

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

the class ClusterMasterNodeExpressionTest method testMasterNodeIdIsNull.

@Test
public void testMasterNodeIdIsNull() throws Exception {
    ClusterService clusterService = mock(ClusterService.class);
    ClusterState state = mock(ClusterState.class);
    DiscoveryNodes nodes = mock(DiscoveryNodes.class);
    when(clusterService.state()).thenReturn(state);
    when(state.nodes()).thenReturn(nodes);
    when(nodes.masterNodeId()).thenReturn(null);
    ClusterMasterNodeExpression clusterMasterNodeExpression = new ClusterMasterNodeExpression(clusterService);
    assertThat(clusterMasterNodeExpression.value(), Matchers.nullValue());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterService(org.elasticsearch.cluster.ClusterService) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) 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