Search in sources :

Example 1 with CreateRepositoryAnalyzedStatement

use of io.crate.analyze.CreateRepositoryAnalyzedStatement 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)

Aggregations

CreateRepositoryAnalyzedStatement (io.crate.analyze.CreateRepositoryAnalyzedStatement)1 CrateUnitTest (io.crate.test.integration.CrateUnitTest)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ActionListener (org.elasticsearch.action.ActionListener)1 DeleteRepositoryRequest (org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest)1 DeleteRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryResponse)1 TransportDeleteRepositoryAction (org.elasticsearch.action.admin.cluster.repositories.delete.TransportDeleteRepositoryAction)1 PutRepositoryRequest (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest)1 TransportPutRepositoryAction (org.elasticsearch.action.admin.cluster.repositories.put.TransportPutRepositoryAction)1 ActionFilters (org.elasticsearch.action.support.ActionFilters)1 ClusterName (org.elasticsearch.cluster.ClusterName)1 ClusterService (org.elasticsearch.cluster.ClusterService)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)1 RepositoriesMetaData (org.elasticsearch.cluster.metadata.RepositoriesMetaData)1 RepositoryMetaData (org.elasticsearch.cluster.metadata.RepositoryMetaData)1 RepositoriesService (org.elasticsearch.repositories.RepositoriesService)1 RepositoryException (org.elasticsearch.repositories.RepositoryException)1 Task (org.elasticsearch.tasks.Task)1