@Test
public void runInTransactionWithRetriesShouldHandleRollbackFailure() throws Exception {

  var transaction = spy(datastore.newTransaction());
  doReturn(transaction).when(datastore).newTransaction();
  var rollbackFailure = new DatastoreIOException(new DatastoreException(1, "fail", "error"));
  doThrow(rollbackFailure).when(transaction).rollback();
  var cause = new RuntimeException("foobar");
  // Run a failing transaction and verify that the rollback failure does not suppress our exception
  try {
    storage.runInTransactionWithRetries(tx -> {
      throw cause;
    });
  } catch (RuntimeException e) {
    assertThat(e, is(cause));
  }
  verify(transaction).rollback();
}