Search in sources :

Example 11 with NoopClusterService

use of org.elasticsearch.test.cluster.NoopClusterService in project crate by crate.

the class RemoteCollectorTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 0, "remoteCollect", new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of("remoteNode", ImmutableMap.of("dummyTable", Collections.singletonList(1)))), RowGranularity.DOC, Collections.<Symbol>singletonList(createReference("name", DataTypes.STRING)), Collections.<Projection>emptyList(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
    transportJobAction = mock(TransportJobAction.class);
    transportKillJobsNodeAction = mock(TransportKillJobsNodeAction.class);
    consumer = new TestingBatchConsumer();
    JobsLogs jobsLogs = new JobsLogs(() -> true);
    JobContextService jobContextService = new JobContextService(Settings.EMPTY, new NoopClusterService(), jobsLogs);
    remoteCollector = new RemoteCollector(jobId, "localNode", "remoteNode", transportJobAction, transportKillJobsNodeAction, jobContextService, mock(RamAccountingContext.class), consumer, collectPhase);
}
Also used : TransportJobAction(io.crate.action.job.TransportJobAction) TransportKillJobsNodeAction(io.crate.executor.transport.kill.TransportKillJobsNodeAction) Routing(io.crate.metadata.Routing) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) JobsLogs(io.crate.operation.collect.stats.JobsLogs) UUID(java.util.UUID) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) JobContextService(io.crate.jobs.JobContextService) Before(org.junit.Before)

Example 12 with NoopClusterService

use of org.elasticsearch.test.cluster.NoopClusterService 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 13 with NoopClusterService

use of org.elasticsearch.test.cluster.NoopClusterService in project crate by crate.

the class TransportKillAllNodeActionTest method testKillIsCalledOnJobContextService.

@Test
public void testKillIsCalledOnJobContextService() throws Exception {
    TransportService transportService = mock(TransportService.class);
    JobContextService jobContextService = mock(JobContextService.class, Answers.RETURNS_MOCKS.get());
    NoopClusterService noopClusterService = new NoopClusterService();
    TransportKillAllNodeAction transportKillAllNodeAction = new TransportKillAllNodeAction(Settings.EMPTY, jobContextService, noopClusterService, transportService);
    final CountDownLatch latch = new CountDownLatch(1);
    transportKillAllNodeAction.nodeOperation(new KillAllRequest(), new ActionListener<KillResponse>() {

        @Override
        public void onResponse(KillResponse killResponse) {
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable throwable) {
            latch.countDown();
        }
    });
    latch.await(1, TimeUnit.SECONDS);
    verify(jobContextService, times(1)).killAll();
}
Also used : TransportService(org.elasticsearch.transport.TransportService) CountDownLatch(java.util.concurrent.CountDownLatch) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) JobContextService(io.crate.jobs.JobContextService) Test(org.junit.Test)

Example 14 with NoopClusterService

use of org.elasticsearch.test.cluster.NoopClusterService 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 15 with NoopClusterService

use of org.elasticsearch.test.cluster.NoopClusterService in project crate by crate.

the class TransportsTest method testOnFailureOnListenerIsCalledIfNodeIsNotInClusterState.

@Test
public void testOnFailureOnListenerIsCalledIfNodeIsNotInClusterState() throws Exception {
    Transports transports = new Transports(new NoopClusterService(), mock(TransportService.class));
    ActionListener actionListener = mock(ActionListener.class);
    transports.sendRequest("actionName", "invalid", mock(TransportRequest.class), actionListener, mock(TransportResponseHandler.class));
    verify(actionListener, times(1)).onFailure(any(Throwable.class));
}
Also used : TransportRequest(org.elasticsearch.transport.TransportRequest) ActionListener(org.elasticsearch.action.ActionListener) TransportService(org.elasticsearch.transport.TransportService) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

NoopClusterService (org.elasticsearch.test.cluster.NoopClusterService)27 Before (org.junit.Before)19 ClusterService (org.elasticsearch.cluster.ClusterService)8 TableIdent (io.crate.metadata.TableIdent)7 Test (org.junit.Test)7 ClusterState (org.elasticsearch.cluster.ClusterState)6 CrateUnitTest (io.crate.test.integration.CrateUnitTest)5 TestingTableInfo (io.crate.metadata.table.TestingTableInfo)4 SQLExecutor (io.crate.testing.SQLExecutor)4 ClusterName (org.elasticsearch.cluster.ClusterName)4 MetaData (org.elasticsearch.cluster.metadata.MetaData)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 JobContextService (io.crate.jobs.JobContextService)3 JobsLogs (io.crate.operation.collect.stats.JobsLogs)3 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)3 TransportService (org.elasticsearch.transport.TransportService)3 PartitionName (io.crate.metadata.PartitionName)2 Routing (io.crate.metadata.Routing)2 TestingDocTableInfoFactory (io.crate.metadata.doc.TestingDocTableInfoFactory)2 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)2