use of org.neo4j.kernel.api.TransactionHook in project neo4j by neo4j.
the class TransactionHookIT method shouldRecieveTxStateOnCommit.
@Test
public void shouldRecieveTxStateOnCommit() throws Exception {
// Given
TransactionHook hook = mock(TransactionHook.class);
kernel.registerTransactionHook(hook);
// When
DataWriteOperations ops = dataWriteOperationsInNewTransaction();
ops.nodeCreate();
commit();
// Then
verify(hook).beforeCommit(any(ReadableTransactionState.class), any(KernelTransaction.class), any(StoreReadLayer.class), any(StorageStatement.class));
verify(hook).afterCommit(any(ReadableTransactionState.class), any(KernelTransaction.class), any(TransactionHook.Outcome.class));
verifyNoMoreInteractions(hook);
}
use of org.neo4j.kernel.api.TransactionHook in project neo4j by neo4j.
the class TransactionHookIT method shouldRollbackOnFailureInBeforeCommit.
@Test
public void shouldRollbackOnFailureInBeforeCommit() throws Exception {
// Given
TransactionHook hook = mock(TransactionHook.class);
final String message = "Original";
when(hook.beforeCommit(any(ReadableTransactionState.class), any(KernelTransaction.class), any(StoreReadLayer.class), any(StorageStatement.class))).thenReturn(new TransactionHook.Outcome() {
@Override
public boolean isSuccessful() {
return false;
}
@Override
public Throwable failure() {
return new Throwable(message);
}
});
kernel.registerTransactionHook(hook);
// When
DataWriteOperations ops = dataWriteOperationsInNewTransaction();
ops.nodeCreate();
try {
commit();
fail("Expected this to fail.");
} catch (org.neo4j.kernel.api.exceptions.TransactionFailureException e) {
assertThat(e.getCause().getMessage(), equalTo("Transaction handler failed."));
assertThat(e.getCause().getCause().getMessage(), equalTo(message));
}
// Then
verify(hook).beforeCommit(any(ReadableTransactionState.class), any(KernelTransaction.class), any(StoreReadLayer.class), any(StorageStatement.class));
verify(hook).afterRollback(any(ReadableTransactionState.class), any(KernelTransaction.class), any(TransactionHook.Outcome.class));
verifyNoMoreInteractions(hook);
}
Aggregations