WorkflowResource { private Response<ByteString> deleteWorkflow(String cid, String wfid, AuthContext ac) { final WorkflowId workflowId = WorkflowId.create(cid, wfid); try { var deletedWorkflow = storage.runInTransactionWithRetries(tx -> { var workflowOpt = tx.workflow(workflowId); if (workflowOpt.isEmpty()) { var response = Response.forStatus(Status.NOT_FOUND.withReasonPhrase("Workflow does not exist")); throw new ResponseException(response); } var workflow = workflowOpt.orElseThrow(); workflowActionAuthorizer.authorizeWorkflowAction(ac, workflow); tx.deleteWorkflow(workflowId); return workflow; }); workflowConsumer.accept(Optional.of(deletedWorkflow), Optional.empty()); LOG.info("Workflow removed: {}", workflowId); return Response.forStatus(Status.NO_CONTENT); } catch (IOException e) { throw new RuntimeException("Failed to delete workflow: " + workflowId, e); } } WorkflowResource(Storage storage, WorkflowValidator workflowValidator,
                          WorkflowInitializer workflowInitializer,
                          BiConsumer<Optional<Workflow>, Optional<Workflow>> workflowConsumer,
                          WorkflowActionAuthorizer workflowActionAuthorizer); Stream<Route<AsyncHandler<Response<ByteString>>>> routes(RequestAuthenticator requestAuthenticator);  }
@Test public void shouldReturnErrorWhenFailedToDeleteWorkflow() throws Exception { sinceVersion(Api.Version.V3); doThrow(new IOException()).when(storage).delete(WORKFLOW.id()); doAnswer(a -> { TransactionFunction<Object, Exception> tf = a.getArgument(0); return rawStorage.runInTransactionWithRetries(tx -> { var spiedTx = spy(tx); when(spiedTx.deleteWorkflow(any())).thenThrow(new IOException()); return tf.apply(spiedTx); }); }).when(storage).runInTransactionWithRetries(any()); var response = awaitResponse(serviceHelper.request("DELETE", path("/foo/bar"))); assertThat(response, hasStatus(withCode(Status.INTERNAL_SERVER_ERROR))); }