@Test
public void runInTransactionWithRetriesShouldPropagateCommitExceptionIfRollbackFails() throws Exception {

  var transaction = spy(datastore.newTransaction());
  doReturn(transaction).when(datastore).newTransaction();
  when(transactionFunction.apply(any())).thenReturn("");
  var commitException = new DatastoreIOException(new DatastoreException(1, "", ""));
  doThrow(commitException).when(transaction).commit();
  var rollbackException = new DatastoreIOException(new DatastoreException(2, "", ""));
  doThrow(rollbackException).when(transaction).rollback();
  try {
    storage.runInTransactionWithRetries(transactionFunction);
    fail("Expected exception!");
  } catch (DatastoreIOException e) {
    assertThat(e, is(commitException));
  }
  verify(transactionFunction).apply(any());
  verify(transaction).rollback();
  verify(logger).debug("Exception on rollback", rollbackException);
}