How to remove non-transactional database logging after running integration tests?

83 views Asked by At

I'm working on a Java/Spring app that requires audit logs to be written to a database. All services are currently marked as @Transactional - so if there is a failure, the changes are rolled back.

But audit logging is the exception to this - it should always succeed - so have been considering marking the AuditLogService as either Propagation.NOT_SUPPORTED or Propagation.REQUIRES_NEW.

The question is how to craft the integration tests. Ideally these should not leave log entries in the database. Would prefer not to have to manually delete this at the end of the test. Is there perhaps a way of marking a test as transactional that would include all transactions including ones that have started via Propagation.REQUIRES_NEW?

1

There are 1 answers

0
Steve Chambers On BEST ANSWER

I ended up doing exactly what I said I didn't want to do and deleting all the operational data at the end of each test. (This actually worked better as the tests were no longer run in an overarching transaction, which masked some bugs, e.g. relating to Hibernate lazy loading.)