summaryrefslogtreecommitdiffstats
path: root/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.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/DbAudit.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/DbAudit.java')
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java62
1 files changed, 47 insertions, 15 deletions
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java
index 21bf5c8d..00b79917 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,6 +53,9 @@ public class DbAudit {
private static final Logger logger = FlexLogger.getLogger(DbAudit.class);
+ private static long dbAuditUpdateMillis = 5000l;
+ private static long dbAuditSleepMillis = 2000l;
+
DbDAO dbDAO = null;
public DbAudit(DbDAO dbDAO) {
@@ -212,7 +215,7 @@ public class DbAudit {
}
} //end for (IntegrityAuditEntity iae : iaeList)
//Time check
- if((System.currentTimeMillis() - startTime) >= 5000){ //5 seconds
+ if((System.currentTimeMillis() - startTime) >= dbAuditUpdateMillis){
//update the timestamp
dbDAO.setLastUpdated();
//reset the startTime
@@ -220,9 +223,9 @@ public class DbAudit {
}else{
//sleep a couple seconds to break up the activity
if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Sleeping 2 seconds");
+ logger.debug("dbAudit: Sleeping " + dbAuditSleepMillis + "ms");
}
- Thread.sleep(2000);
+ Thread.sleep(dbAuditSleepMillis);
if (logger.isDebugEnabled()) {
logger.debug("dbAudit: Waking from sleep");
}
@@ -315,7 +318,7 @@ public class DbAudit {
}
}
//Time check
- if((System.currentTimeMillis() - startTime) >= 5000){ //5 seconds
+ if((System.currentTimeMillis() - startTime) >= dbAuditUpdateMillis){
//update the timestamp
dbDAO.setLastUpdated();
//reset the startTime
@@ -323,9 +326,9 @@ public class DbAudit {
}else{
//sleep a couple seconds to break up the activity
if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Second comparison; sleeping 2 seconds");
+ logger.debug("dbAudit: Second comparison; sleeping " + dbAuditSleepMillis + "ms");
}
- Thread.sleep(2000);
+ Thread.sleep(dbAuditSleepMillis);
if (logger.isDebugEnabled()) {
logger.debug("dbAudit: Second comparison; waking from sleep");
}
@@ -347,22 +350,23 @@ public class DbAudit {
/**
* dbAuditSimulate simulates the DB audit
* @param resourceName
- * @param persistenceUnit
+ * @param persistenceUnit
+ * @param simulationIterations
+ * @param simulationIntervalMs
* @param nodeType
- * @throws InterruptedException
- * @throws DbDaoTransactionException
+ * @throws DbAuditException
*/
- public void dbAuditSimulate(String resourceName, String persistenceUnit) throws DbAuditException {
+ public void dbAuditSimulate(String resourceName, String persistenceUnit, long simulationIterations, long simulationIntervalMs) throws DbAuditException {
try {
logger.info("dbAuditSimulate: Starting audit simulation for resourceName="
+ resourceName + ", persistenceUnit=" + persistenceUnit);
- for (int i = 0; i < AuditThread.AUDIT_SIMULATION_ITERATIONS; i++) {
+ for (int i = 0; i < simulationIterations; i++) {
dbDAO.setLastUpdated();
logger.info("dbAuditSimulate: i=" + i + ", sleeping "
- + AuditThread.AUDIT_SIMULATION_SLEEP_INTERVAL + "ms");
- Thread.sleep(AuditThread.AUDIT_SIMULATION_SLEEP_INTERVAL);
+ + simulationIntervalMs + "ms");
+ Thread.sleep(simulationIntervalMs);
}
logger.info("dbAuditSimulate: Finished audit simulation for resourceName="
@@ -465,8 +469,36 @@ public class DbAudit {
logger.info(msg);
}
+ /**
+ * Gets the audit-update time.
+ * @return the audit-update time, in milliseconds
+ */
+ protected static long getDbAuditUpdateMillis() {
+ return dbAuditUpdateMillis;
+ }
+
+ /**
+ * Sets the audit-update time.
+ * @param dbAuditUpdateMillis the new audit update time, in milliseconds
+ */
+ protected static void setDbAuditUpdateMillis(long dbAuditUpdateMillis) {
+ DbAudit.dbAuditUpdateMillis = dbAuditUpdateMillis;
+ }
+ /**
+ * Gets the audit-sleep time.
+ * @return the audit-sleep time, in milliseconds
+ */
+ protected static long getDbAuditSleepMillis() {
+ return dbAuditSleepMillis;
+ }
-
+ /**
+ * Sets the audit-sleep time.
+ * @param dbAuditSleepMillis the new audit sleep time, in milliseconds
+ */
+ protected static void setDbAuditSleepMillis(long dbAuditSleepMillis) {
+ DbAudit.dbAuditSleepMillis = dbAuditSleepMillis;
+ }
}