diff options
Diffstat (limited to 'integrity-audit/src')
-rw-r--r-- | integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java | 55 | ||||
-rw-r--r-- | integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java | 3 |
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); } |