use of org.elasticsearch.action.admin.cluster.repositories.put.TransportPutRepositoryAction 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.action.admin.cluster.repositories.put.TransportPutRepositoryAction 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(Collections.singletonList(new RepositoryMetadata("repo1", "fs", Settings.EMPTY)));
ClusterState state = ClusterState.builder(new ClusterName("dummy")).metadata(Metadata.builder().putCustom(RepositoriesMetadata.TYPE, repos)).build();
ClusterServiceUtils.setState(clusterService, state);
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver();
final AtomicBoolean deleteRepoCalled = new AtomicBoolean(false);
MockTransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, THREAD_POOL, clusterService.getClusterSettings());
TransportDeleteRepositoryAction deleteRepositoryAction = new TransportDeleteRepositoryAction(transportService, clusterService, mock(RepositoriesService.class), THREAD_POOL, indexNameExpressionResolver) {
@Override
protected void doExecute(DeleteRepositoryRequest request, ActionListener<AcknowledgedResponse> listener) {
deleteRepoCalled.set(true);
listener.onResponse(mock(AcknowledgedResponse.class));
}
};
TransportPutRepositoryAction putRepo = new TransportPutRepositoryAction(transportService, clusterService, mock(RepositoriesService.class), THREAD_POOL, indexNameExpressionResolver) {
@Override
protected void doExecute(PutRepositoryRequest request, ActionListener<AcknowledgedResponse> listener) {
listener.onFailure(new RepositoryException(request.name(), "failure"));
}
};
RepositoryService repositoryService = new RepositoryService(clusterService, deleteRepositoryAction, putRepo);
try {
PutRepositoryRequest request = new PutRepositoryRequest("repo1");
request.type("fs");
repositoryService.execute(request).get(10, TimeUnit.SECONDS);
} catch (ExecutionException e) {
assertThat(deleteRepoCalled.get(), is(true));
throw e.getCause();
}
}
Aggregations