summaryrefslogtreecommitdiffstats
path: root/integrity-audit
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-04-03 09:44:26 -0400
committerJim Hahn <jrh3@att.com>2020-04-06 09:41:59 -0400
commita56d3929f2387252525577fb36f9e03933064b8f (patch)
tree4b671549b5f1c0513c31d77baa19821e422f41e7 /integrity-audit
parent7da3ddfa40de2f683a2d423d62b78a8d001108eb (diff)
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 <jrh3@att.com>
Diffstat (limited to 'integrity-audit')
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java55
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java3
2 files changed, 24 insertions, 34 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 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) {
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java
index 959a4e7c..fda7e4a2 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
@@ -95,7 +96,7 @@ public class DefaultLoggingPatternTest {
TextFileUtils.getTextFileAsString("testingLogs/common-modules/integrity-audit/logging-pattern-test.log")
.substring(23);
String expectedLoggedString = TextFileUtils
- .getTextFileAsString("src/test/resources/" + loggerString + "-test.expectedlog").substring(23);
+ .getTextFileAsString("src/test/resources/" + loggerString + "-test.expectedlog").substring(23).trim();
assertThat(actualLoggedString).contains(expectedLoggedString);
}