From: Steve Marion Date: Wed, 31 Jul 2024 09:28:32 +0000 (+0200) Subject: SONAR-22649 Add support for concurrent usage of dbTester. X-Git-Tag: 9.9.7.96285~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=706d8cba00c5b1d429f5484e535aeae4fbda2064;p=sonarqube.git SONAR-22649 Add support for concurrent usage of dbTester. --- 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 { private final System2 system2; private final AuditPersister auditPersister; private DbClient client; - private DbSession session = null; + ThreadLocal session = new ThreadLocal<>(); private final UserDbTester userTester; private final ComponentDbTester componentTester; private final ProjectLinkDbTester componentLinkTester; @@ -250,18 +250,19 @@ public class DbTester extends AbstractDbTester { @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() {