From a56d3929f2387252525577fb36f9e03933064b8f Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 3 Apr 2020 09:44:26 -0400 Subject: Address sonar issues in common Addressed the following sonar issues: - missing assertion in junit test case - disable sonars about setAccessible() as it's required for jackson emulation - sleep in junit - don't use wild-cards (e.g., "*") with java.util Pattern - use re2j instead of java.util Pattern - use String methods (e.g., startsWith()) - duplicate method bodies - duplicate code in Coder classes - string concatenation in logger calls - UTF-8 encoding - return primitive instead of boxed primitive - add assertion to tests - renamed support methods from doTestXxx to verifyXxx - cognitive complexity - use AtomicRef instead of volatile - use specific Functionals (e.g., IntConsumer) - function always returns the same value - serializable vs transient Issue-ID: POLICY-2305 Change-Id: I08eb7aa495a80bdc1d26827ba17a7946c83b9828 Signed-off-by: Jim Hahn --- .../java/org/onap/policy/common/ia/DbAudit.java | 55 +++++++++------------- 1 file changed, 22 insertions(+), 33 deletions(-) (limited to 'integrity-audit/src/main/java/org/onap') 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 a7b7fd89..f69173f8 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 @@ -174,22 +174,8 @@ public class DbAudit { compareMineWithTheirs(persistenceUnit, iaeList, myIae, misMatchedMap, clazzName, myEntries); // Time check - if ((AuditorTime.getInstance().getMillis() - startTime) >= DB_AUDIT_UPDATE_MS) { - // update the timestamp - dbDao.setLastUpdated(); - // reset the startTime - startTime = AuditorTime.getInstance().getMillis(); - } else { - // sleep a couple seconds to break up the activity - if (logger.isDebugEnabled()) { - logger.debug("dbAudit: Sleeping " + DB_AUDIT_SLEEP_MS + "ms"); - } - sleep(); - if (logger.isDebugEnabled()) { - logger.debug("dbAudit: Waking from sleep"); - } - } - } // end: for(String clazzName: classNameList) + startTime = timeCheck("First", startTime); + } // check if misMatchedMap is empty if (misMatchedMap.isEmpty()) { @@ -197,8 +183,6 @@ public class DbAudit { if (logger.isDebugEnabled()) { logger.debug("dbAudit: Exiting, misMatchedMap is empty"); } - // we are done - return; } else { if (logger.isDebugEnabled()) { logger.debug("dbAudit: Doing another comparison; misMatchedMap.size()=" + misMatchedMap.size()); @@ -258,6 +242,25 @@ public class DbAudit { } } + private long timeCheck(String type, long startTime) throws IntegrityAuditException { + if ((AuditorTime.getInstance().getMillis() - startTime) >= DB_AUDIT_UPDATE_MS) { + // update the timestamp + dbDao.setLastUpdated(); + // reset the startTime + return AuditorTime.getInstance().getMillis(); + } else { + // sleep a couple seconds to break up the activity + if (logger.isDebugEnabled()) { + logger.debug("dbAudit: " + type + " comparison; sleeping " + DB_AUDIT_SLEEP_MS + "ms"); + } + sleep(); + if (logger.isDebugEnabled()) { + logger.debug("dbAudit: " + type + " comparison; waking from sleep"); + } + return startTime; + } + } + /** * Creates properties for the other db node. * @param iae target DB node @@ -310,21 +313,7 @@ public class DbAudit { errorCount += recompareMineWithTheirs(resourceName, persistenceUnit, iaeList, myIae, clazzName, keySet, myEntries); // Time check - if ((AuditorTime.getInstance().getMillis() - startTime) >= DB_AUDIT_UPDATE_MS) { - // update the timestamp - dbDao.setLastUpdated(); - // reset the startTime - startTime = AuditorTime.getInstance().getMillis(); - } else { - // sleep a couple seconds to break up the activity - if (logger.isDebugEnabled()) { - logger.debug("dbAudit: Second comparison; sleeping " + DB_AUDIT_SLEEP_MS + "ms"); - } - sleep(); - if (logger.isDebugEnabled()) { - logger.debug("dbAudit: Second comparison; waking from sleep"); - } - } + startTime = timeCheck("Second", startTime); } if (errorCount != 0) { -- cgit 1.2.3-korg