aboutsummaryrefslogtreecommitdiffstats
path: root/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2018-02-13 14:16:47 -0500
committerJim Hahn <jrh3@att.com>2018-02-13 14:26:22 -0500
commite871132b09476d7772fb8dbc597fb82248b89f6b (patch)
treec78deaa56f3c6af84b8a7362c6066e5f6ce18f10 /integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java
parent86664073b5a778c56e831d64b3a1883818af0ffe (diff)
Speed up integrity-audit tests
Added additional DbDAO constructors to facilitate JUnit testing. Added DbDAO destroy() method to close the EntityManagerFactory. Pulled out common code into IntegrityAuditTestBase and subclassed the tests from there. Added hooks to IntegrityAudit so that the AuditThread timers could be set to smaller values so that all of the junit tests could be run in much less time. Added similar hooks to DbAudit. Modified integrity-audit tests to use new utility classes to auto-close JPA managers. Modified integrity-audit tests to use new utility class to scan logger items without the need to scan the actual log file. Added code to new test superclass to truncate the four ONAP logs. Modified hooks in IntegrityAuditEntity to adjust serialization so that dates are not serialized/de-serialized when used in junit tests. Deleted TestingUtils. Added a test for invalid nodeType property. Fixed issue wherein AuditThread doesn't stop when interrupted. Change-Id: I5101995b6b68655b2810777bc4d2ec80c7cbc363 Issue-ID: POLICY-582 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java')
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java55
1 files changed, 40 insertions, 15 deletions
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java
index b30c7730..f34b24d5 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java
@@ -69,27 +69,49 @@ public class DbDAO {
*/
private static final Object lock = new Object();
-
/**
* DbDAO Constructor
- * @param resourceName
- * @param persistenceUnit
- * @param properties
- * @throws Exception
- */
+ *
+ * @param resourceName
+ * @param persistenceUnit
+ * @param properties
+ * @throws Exception
+ */
public DbDAO(String resourceName, String persistenceUnit, Properties properties) throws Exception {
+ this(resourceName, persistenceUnit, properties, null);
+ }
+
+ /**
+ * DbDAO Constructor
+ *
+ * @param resourceName
+ * @param persistenceUnit
+ * @param properties
+ * @param lastUpdateDate may be {@code null}
+ * @param altDbUrl may be {@code null}
+ * @throws Exception
+ */
+ protected DbDAO(String resourceName, String persistenceUnit, Properties properties, String altDbUrl)
+ throws Exception {
logger.debug("DbDAO contructor: enter");
-
+
validateProperties(resourceName, persistenceUnit, properties);
-
+
emf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
-
- register();
-
+
+ register(altDbUrl);
+
logger.debug("DbDAO contructor: exit");
}
/**
+ * Release resources (i.e., the EntityManagerFactory).
+ */
+ public void destroy() {
+ emf.close();
+ }
+
+ /**
* validateProperties will validate the properties
* @param resourceName
* @param persistenceUnit
@@ -207,6 +229,7 @@ public class DbDAO {
logger.error("getAllEntries encountered exception:", e);
}
em.close();
+ theEmf.close();
logger.debug("getAllEntries: Returning resultMap, size=" + resultMap.size());
@@ -240,6 +263,7 @@ public class DbDAO {
logger.error(msg, e);
}
em.close();
+ theEmf.close();
logger.debug("getAllEntries: Exit, resultMap, size=" + resultMap.size());
return resultMap;
}
@@ -282,7 +306,7 @@ public class DbDAO {
}
}
-
+
/**
* getMyIntegrityAuditEntity() gets my IntegrityAuditEntity
* @return
@@ -382,8 +406,10 @@ public class DbDAO {
/**
* Register the IntegrityAudit instance
+ * @param altDbUrl alternate DB URL to be placed into the record,
+ * or {@code null} to use the default
*/
- private void register() throws DbDaoTransactionException {
+ private void register(String altDbUrl) throws DbDaoTransactionException {
try{
EntityManager em = emf.createEntityManager();
@@ -421,10 +447,9 @@ public class DbDAO {
//update/set properties in entry
iae.setSite(this.siteName);
iae.setNodeType(this.nodeType);
- iae.setLastUpdated(new Date());
iae.setJdbcDriver(this.dbDriver);
iae.setJdbcPassword(properties.getProperty(IntegrityAuditProperties.DB_PWD).trim());
- iae.setJdbcUrl(dbUrl);
+ iae.setJdbcUrl(altDbUrl == null ? this.dbUrl : altDbUrl);
iae.setJdbcUser(dbUser);
em.persist(iae);