@Test
public void runInTransactionWithRetriesShouldCallFunctionAndRollbackOnPreCommitConflict() throws Exception {

  var expectedException = new DatastoreIOException(new DatastoreException(1, "", ""));
  when(transactionFunction.apply(any())).thenThrow(expectedException);
  var transaction = spy(datastore.newTransaction());
  when(datastore.newTransaction()).thenReturn(transaction);
  try {
    storage.runInTransactionWithRetries(transactionFunction);
    fail("Expected exception!");
  } catch (DatastoreIOException e) {
    assertThat(e, is(expectedException));
  }
  verify(transactionFunction).apply(any());
  verify(transaction, never()).commit();
  verify(transaction).rollback();
}