From 121e70662f53fe0820823a23784794021fbc7920 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Fri, 21 Oct 2016 10:26:15 +0200 Subject: fix possible multi-threading problem with database connections --- .../moa/id/monitoring/DatabaseTestModule.java | 52 +++++----------------- .../egovernment/moa/id/monitoring/TestManager.java | 10 ++--- 2 files changed, 16 insertions(+), 46 deletions(-) (limited to 'id/server/modules/module-monitoring') diff --git a/id/server/modules/module-monitoring/src/main/java/at/gv/egovernment/moa/id/monitoring/DatabaseTestModule.java b/id/server/modules/module-monitoring/src/main/java/at/gv/egovernment/moa/id/monitoring/DatabaseTestModule.java index 8ae1850ce..b21c5e93f 100644 --- a/id/server/modules/module-monitoring/src/main/java/at/gv/egovernment/moa/id/monitoring/DatabaseTestModule.java +++ b/id/server/modules/module-monitoring/src/main/java/at/gv/egovernment/moa/id/monitoring/DatabaseTestModule.java @@ -23,29 +23,23 @@ package at.gv.egovernment.moa.id.monitoring; import java.util.ArrayList; -import java.util.Date; import java.util.List; -import org.hibernate.Query; -import org.hibernate.Session; - +import at.gv.egovernment.moa.id.advancedlogging.IStatisticLogger; import at.gv.egovernment.moa.id.commons.api.AuthConfiguration; -import at.gv.egovernment.moa.id.commons.db.MOASessionDBUtils; -import at.gv.egovernment.moa.id.commons.db.StatisticLogDBUtils; -import at.gv.egovernment.moa.id.commons.db.dao.session.AssertionStore; -import at.gv.egovernment.moa.id.commons.db.dao.statistic.StatisticLog; import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProviderFactory; +import at.gv.egovernment.moa.id.storage.ITransactionStorage; import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.util.MiscUtil; public class DatabaseTestModule implements TestModuleInterface{ - private MOASessionDBUtils dbUtils; - private StatisticLogDBUtils statLogUtils; + private ITransactionStorage transactionStorage; + private IStatisticLogger statLogUtils; - public DatabaseTestModule(MOASessionDBUtils dbUtils, StatisticLogDBUtils statLogUtils){ + public DatabaseTestModule(ITransactionStorage transactionStorage, IStatisticLogger statLogUtils){ this.statLogUtils = statLogUtils; - this.dbUtils = dbUtils; + this.transactionStorage = transactionStorage; } public List performTests() throws Exception { @@ -75,21 +69,9 @@ public class DatabaseTestModule implements TestModuleInterface{ private String testMOASessionDatabase() throws Exception{ Logger.trace("Start Test: MOASessionDatabase"); - - Date expioredate = new Date(new Date().getTime() - 120); - - - try { - List results; - Session session = dbUtils.getCurrentSession(); - - synchronized (session) { - session.beginTransaction(); - Query query = session.getNamedQuery("getAssertionWithTimeOut"); - query.setTimestamp("timeout", expioredate); - results = query.list(); - session.getTransaction().commit(); - } + + try { + transactionStorage.get("testKey"); Logger.trace("Finish Test: MOASessionDatabase"); return null; @@ -110,21 +92,9 @@ public class DatabaseTestModule implements TestModuleInterface{ return null; } - private String testMOAAdvancedLoggingDatabase() { - - Date expioredate = new Date(new Date().getTime() - 120); + private String testMOAAdvancedLoggingDatabase() { try { - Session session = statLogUtils.getCurrentSession(); - - List results; - - synchronized (session) { - session.beginTransaction(); - Query query = session.getNamedQuery("getAllEntriesNotBeforeTimeStamp"); - query.setTimestamp("timeout", expioredate); - results = query.list(); - session.getTransaction().commit(); - } + statLogUtils.testConnection(); Logger.trace("Finish Test: AdvancedLoggingDataBase"); return null; diff --git a/id/server/modules/module-monitoring/src/main/java/at/gv/egovernment/moa/id/monitoring/TestManager.java b/id/server/modules/module-monitoring/src/main/java/at/gv/egovernment/moa/id/monitoring/TestManager.java index 4224fae59..9f0083fb8 100644 --- a/id/server/modules/module-monitoring/src/main/java/at/gv/egovernment/moa/id/monitoring/TestManager.java +++ b/id/server/modules/module-monitoring/src/main/java/at/gv/egovernment/moa/id/monitoring/TestManager.java @@ -29,17 +29,17 @@ import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; +import at.gv.egovernment.moa.id.advancedlogging.IStatisticLogger; import at.gv.egovernment.moa.id.commons.api.AuthConfiguration; import at.gv.egovernment.moa.id.commons.api.exceptions.ConfigurationException; -import at.gv.egovernment.moa.id.commons.db.MOASessionDBUtils; -import at.gv.egovernment.moa.id.commons.db.StatisticLogDBUtils; +import at.gv.egovernment.moa.id.storage.ITransactionStorage; import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.util.FileUtils; public class TestManager{ - @Autowired private MOASessionDBUtils moaSessionDBUtils; - @Autowired(required=false) private StatisticLogDBUtils statisticLogDBUtils = null; + @Autowired private ITransactionStorage transactionStorage; + @Autowired(required=false) private IStatisticLogger statisticLogDBUtils = null; @Autowired private AuthConfiguration authConfig; private Map tests = new HashMap(); @@ -94,7 +94,7 @@ public class TestManager{ Logger.debug("Start initializing MOA-ID-Auth TestManager"); //add Database test - DatabaseTestModule test1 = new DatabaseTestModule(this.moaSessionDBUtils, this.statisticLogDBUtils); + DatabaseTestModule test1 = new DatabaseTestModule(this.transactionStorage, this.statisticLogDBUtils); tests.put(test1.getName(), test1); //add IdentityLink verification test -- cgit v1.2.3