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());
}
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();
}
}
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));
}
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));
}
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());
}
Aggregations