System Status - JDK 17 - SpringBoot -> 2.5.6 - DB -> PostgreSQL (13.3) - Connecting with JDBC driver
I'm trying to write Test for class which is annotated with @Transactional(isolation = Isolation.SERIALIZABLE)
For example (Original source code was written in Kotlin)
@Serivce
@Transactional(isolation = Isolation.SERIALIZABLE)
public class SomeUseCaseImpl implements SomeUseCase {
@Override
public void doSomething() {
// doing something with db which needs specific isolation level
}
}
And tests are like this (Original source code was written in Kotlin)
// Test Annotation for Database
@SpringBootTest(
properties = [
"spring.datasource.hikari.minimumIdle=1",
"spring.datasource.hikari.maximumPoolSize=1",
"spring.datasource.url=\${DATASOURCE_URL:jdbc:postgresql://localhost:5433/table_name}",
],
)
public @interface SpringBootDBTest {
}
// Test
@SpringBootDBTest
public class Test {
@Autowired
private SomeUseCaseImpl useCase;
@Test
public void some_test() {
// this will cause `org.postgresql.util.PSQLException` which says
// "Cannot change transaction isolation level in the middle of a transaction."
useCase.doSomething();
}
}
I understand from the doc (https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/context/transaction/TransactionalTestExecutionListener.html) that isolation levels are not supported during the test.
First of all is this expected behavior as document says are not supported during the test
? Since I wasn't clear what not supported
actually means.
In addition is there any plan for supporting to execute without exception ? or any updates that I'm missing ? If not, what will be a good practice of doing so. (I saw some of the Stackoverflow posts but none of them are discussing this problem.)
If this is a Question
and should be posted to a different source, just let me know.
Comment From: simonbasle
I don't think this has anything to do with TransactionalTestExecutionListener
as it only considers Transactional
annotations on test classes or test methods and is intended for unit tests (while you are doing integration tests).
Your snippet is not enough to reproduce and investigate the issue though, since as an integration test it depends on a concrete database, but I suspect it has something to do with how the database driver and pool are configured and used or with the actual code in doSomething
and not with Spring Framework test.
Can you try to investigate further about the root cause of the exception? (you might indeed need to ask question on StackOverflow).
If you get stuck, can you at least shed some more light on what you are actually doing and produce a self-contained reproducer (i.e. as a small project on github)?
One (unrelated?) thing that jumps out is the configuration of the HikariCP pool spring.datasource.hikari.maximumPoolSize
to 1
, which seems weird to me for an integration test as it would lead to connection starvation pretty quickly...
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.