Fork me on GitHub

Hi there, is there any way to test/mock a transaction rollback with or with Jdbc in general?


It depends on what you really mean. If you mean “I want to run a test that should rollback a transaction and verify the operations in the transaction were rolled back” then you should just be able to query the system afterward to verify what you expect. If you mean “I want to force a transaction to rollback so I can verify how the system behaves in that situation” then you can probably mock something called inside the TX and have it throw an exception (which will rollback the TX).


thank you right it makes sense - I think I want the latter and try to understand if the code actually catches the right exceptions and so handles retries correctly


ok the latter approach would not work because I would have to either mock with-db-transaction or the connection...I guess I will have to go for an integration test


(if so, it might even be a good idea to add an API for testing, similar to


Oh well there db-set-rollback-only! after all 😄


Pretty much everything you’re doing at this level is “not a good idea”. This is the wrong level to be trying to mock anything. And I’ve said that before.


You should not be trying to mock database methods in at all.


yeah agree, and the above would be akin to throw inside the transaction block


(but of course separating business logic from DB updates means you pretty much don’t need to test that “JDBC works” 🙂 )

👍 1

;; Embedded postgres
                    [com.opentable.components/otj-pg-embedded "0.13.3"]

👍 1

@richiardiandrea relatedly, I highly encourage using the a "real" db inside your unit tests


using clj-test-containers here 😄


thats new to me - looking at it now


let me know if you need some code for give it a go, I have come up with my own fixtures for duct systems


this is what ive used in my personal projects for postgres if you happen to use that


we used to use that at work but it’s no longer maintained, so it doesn’t support newer PG versions


we switched to the PG module in, it works alright

👍 1

@schmee For next.jdbc I use the Zonky version: and it seems fairly well-maintained /cc @emccue

👍 1
🙏 1

lovely. I dig embedded pg, but have an issue during unit tests on jenkins, and the error message is obscure (“closed by admin” or something to that effect. Nice to see a maintained alternative


It has PG 13.1.0 support (I’m a bit behind there with next.jdbc).

John Conti14:03:29

Anyone play with the new reactive async driver Postgres stuff?