aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Marion <steve.marion@sonarsource.com>2024-07-31 11:28:32 +0200
committersonartech <sonartech@sonarsource.com>2024-08-12 20:02:46 +0000
commit706d8cba00c5b1d429f5484e535aeae4fbda2064 (patch)
tree77f69d1c72d92d6b39b8355a2da8c722b814e342
parentd989ded179b6997b5814459b2e57447a197c0ade (diff)
downloadsonarqube-706d8cba00c5b1d429f5484e535aeae4fbda2064.tar.gz
sonarqube-706d8cba00c5b1d429f5484e535aeae4fbda2064.zip
SONAR-22649 Add support for concurrent usage of dbTester.
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java15
1 files changed, 8 insertions, 7 deletions
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java
index c9e8783b46e..8e34db0f454 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java
@@ -66,7 +66,7 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
private final System2 system2;
private final AuditPersister auditPersister;
private DbClient client;
- private DbSession session = null;
+ ThreadLocal<DbSession> session = new ThreadLocal<>();
private final UserDbTester userTester;
private final ComponentDbTester componentTester;
private final ProjectLinkDbTester componentLinkTester;
@@ -250,18 +250,19 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
@Override
protected void after() {
- if (session != null) {
- session.rollback();
- session.close();
+ if (session.get() != null) {
+ session.get().rollback();
+ session.get().close();
+ session.remove();
}
db.stop();
}
public DbSession getSession() {
- if (session == null) {
- session = db.getMyBatis().openSession(false);
+ if (session.get() == null) {
+ session.set(db.getMyBatis().openSession(false));
}
- return session;
+ return session.get();
}
public void commit() {