diff --git a/facade/src/main/java/com/redhat/lightblue/migrator/facade/ConsistencyChecker.java b/facade/src/main/java/com/redhat/lightblue/migrator/facade/ConsistencyChecker.java index 3b9b787..0681028 100644 --- a/facade/src/main/java/com/redhat/lightblue/migrator/facade/ConsistencyChecker.java +++ b/facade/src/main/java/com/redhat/lightblue/migrator/facade/ConsistencyChecker.java @@ -28,8 +28,8 @@ public class ConsistencyChecker { // using non-static slf4j loggers for easy unit testing - private Logger log = LoggerFactory.getLogger(this.getClass()); - private Logger inconsistencyLog = LoggerFactory.getLogger("Inconsistency"); + private Logger inconsistencyLog = LoggerFactory.getLogger(this.getClass()); + private Logger hugeInconsistencyLog = LoggerFactory.getLogger(this.getClass()+"Huge"); private final String implementationName; protected int maxInconsistencyLogLength = 65536; // 64KB @@ -79,22 +79,22 @@ private void logInconsistency(String callToLogInCaseOfInconsistency, String lega String logMessage = String.format("Inconsistency found in %s.%s - diff: %s - legacyJson: %s, lightblueJson: %s", implementationName, callToLogInCaseOfInconsistency, diff, legacyJson, lightblueJson); if (logResponseDataEnabled) { if (logMessage.length()<=maxInconsistencyLogLength) { - log.warn(logMessage); + inconsistencyLog.warn(logMessage); } else if (diff!=null&&diff.length()<=maxInconsistencyLogLength) { - log.warn(String.format("Inconsistency found in %s.%s - diff: %s", implementationName, callToLogInCaseOfInconsistency, diff)); - inconsistencyLog.debug(logMessage); + inconsistencyLog.warn(String.format("Inconsistency found in %s.%s - diff: %s", implementationName, callToLogInCaseOfInconsistency, diff)); + hugeInconsistencyLog.debug(logMessage); } else { - log.warn(String.format("Inconsistency found in %s.%s - payload and diff is greater than %d bytes!", implementationName, callToLogInCaseOfInconsistency, maxInconsistencyLogLength)); - inconsistencyLog.debug(logMessage); + inconsistencyLog.warn(String.format("Inconsistency found in %s.%s - payload and diff is greater than %d bytes!", implementationName, callToLogInCaseOfInconsistency, maxInconsistencyLogLength)); + hugeInconsistencyLog.debug(logMessage); } } else { if (diff!=null&&diff.length()<=maxInconsistencyLogLength) { - log.warn(String.format("Inconsistency found in %s.%s - diff: %s", implementationName, callToLogInCaseOfInconsistency, diff)); + inconsistencyLog.warn(String.format("Inconsistency found in %s.%s - diff: %s", implementationName, callToLogInCaseOfInconsistency, diff)); } else { - log.warn(String.format("Inconsistency found in %s.%s - diff is greater than %d bytes!", implementationName, callToLogInCaseOfInconsistency, maxInconsistencyLogLength)); + inconsistencyLog.warn(String.format("Inconsistency found in %s.%s - diff is greater than %d bytes!", implementationName, callToLogInCaseOfInconsistency, maxInconsistencyLogLength)); } // logData is turned off, log in inconsistency.log for debugging - inconsistencyLog.debug(logMessage); + hugeInconsistencyLog.debug(logMessage); } } @@ -131,9 +131,9 @@ protected boolean checkConsistency(final Object legacyEntity, final Object light JSONCompareResult result = JSONCompare.compareJSON(legacyJson, lightblueJson, JSONCompareMode.LENIENT); long t2 = System.currentTimeMillis(); - if (log.isDebugEnabled()) { - log.debug("Consistency check took: " + (t2-t1)+" ms"); - log.debug("Consistency check passed: "+ result.passed()); + if (inconsistencyLog.isDebugEnabled()) { + inconsistencyLog.debug("Consistency check took: " + (t2-t1)+" ms"); + inconsistencyLog.debug("Consistency check passed: "+ result.passed()); } if (!result.passed()) { logInconsistency(callToLogInCaseOfInconsistency.toString(), legacyJson, lightblueJson, result.getMessage().replaceAll("\n", ",")); @@ -146,7 +146,7 @@ protected boolean checkConsistency(final Object legacyEntity, final Object light logInconsistency(callToLogInCaseOfInconsistency.toString(), legacyJson, lightblueJson, null); } } catch (JsonProcessingException e) { - log.error("Consistency check failed in "+implementationName+"."+callToLogInCaseOfInconsistency+"! Invalid JSON: legacyJson="+legacyJson+", lightblueJson="+lightblueJson, e); + inconsistencyLog.error("Consistency check failed in "+implementationName+"."+callToLogInCaseOfInconsistency+"! Invalid JSON: legacyJson="+legacyJson+", lightblueJson="+lightblueJson, e); } return false; } diff --git a/facade/src/test/java/com/redhat/lightblue/migrator/facade/ConsistencyLoggerTest.java b/facade/src/test/java/com/redhat/lightblue/migrator/facade/ConsistencyLoggerTest.java index aa77df4..52c453b 100644 --- a/facade/src/test/java/com/redhat/lightblue/migrator/facade/ConsistencyLoggerTest.java +++ b/facade/src/test/java/com/redhat/lightblue/migrator/facade/ConsistencyLoggerTest.java @@ -28,10 +28,10 @@ public class ConsistencyLoggerTest { @Mock - private Logger log; + private Logger inconsitencyLog; @Mock - private Logger inconsistencyLog; + private Logger hugeInconsistencyLog; @InjectMocks private ConsistencyChecker consistencyChecker = new ConsistencyChecker(CountryDAO.class.getSimpleName()); @@ -72,9 +72,9 @@ public void logTest_logResponsesEnabled_logLessThanLogLimit() throws Exception { List lightblue = getDummyMessage("Test", 12); boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", new LazyMethodCallStringifier("testMethod(param1, param2)")); assertFalse(result); - verify(log).warn(logStmt.capture()); + verify(inconsitencyLog).warn(logStmt.capture()); assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - diff: []: Expected 2 values but got 1 - legacyJson: [\"Test10000\",\"Test10001\"], lightblueJson: [\"Test10000\"]", logStmt.getValue()); - verify(inconsistencyLog, never()).debug(anyString()); + verify(hugeInconsistencyLog, never()).debug(anyString()); } @Test @@ -90,9 +90,9 @@ public void logTest_logResponsesEnabled_logGreaterThanLogLimit() throws Exceptio List lightblue = getDummyMessage("Test", 24); boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", new LazyMethodCallStringifier("testMethod(param1, param2)")); assertFalse(result); - verify(log).warn(logStmt.capture()); + verify(inconsitencyLog).warn(logStmt.capture()); assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - diff: []: Expected 3 values but got 2", logStmt.getValue()); - verify(inconsistencyLog).debug(inconsistencyLogStmt.capture()); + verify(hugeInconsistencyLog).debug(inconsistencyLogStmt.capture()); assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - diff: []: Expected 3 values but got 2 - legacyJson: [\"Test10000\",\"Test10001\",\"Test10002\"], lightblueJson: [\"Test10000\",\"Test10001\"]", inconsistencyLogStmt.getValue()); } @@ -109,9 +109,9 @@ public void logTest_logResponsesEnabled_diffGreaterThanLogLimit() throws Excepti List lightblue = getDummyMessage("Fooo", 40); boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", new LazyMethodCallStringifier("testMethod(param1, param2)")); assertFalse(result); - verify(log).warn(logStmt.capture()); + verify(inconsitencyLog).warn(logStmt.capture()); assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - payload and diff is greater than 175 bytes!", logStmt.getValue()); - verify(inconsistencyLog).debug(inconsistencyLogStmt.capture()); + verify(hugeInconsistencyLog).debug(inconsistencyLogStmt.capture()); assertTrue(inconsistencyLogStmt.getValue().contains("diff")); assertTrue(inconsistencyLogStmt.getValue().contains("legacyJson")); assertTrue(inconsistencyLogStmt.getValue().contains("lightblueJson")); @@ -130,9 +130,9 @@ public void logTest_logResponsesDisabled_logLessThanLogLimit() throws Exception List lightblue = getDummyMessage("Test", 12); boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", new LazyMethodCallStringifier("testMethod(param1, param2)")); assertFalse(result); - verify(log).warn(logStmt.capture()); + verify(inconsitencyLog).warn(logStmt.capture()); assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - diff: []: Expected 2 values but got 1", logStmt.getValue()); - verify(inconsistencyLog).debug(inconsistencyLogStmt.capture()); + verify(hugeInconsistencyLog).debug(inconsistencyLogStmt.capture()); assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - diff: []: Expected 2 values but got 1 - legacyJson: [\"Test10000\",\"Test10001\"], lightblueJson: [\"Test10000\"]", inconsistencyLogStmt.getValue()); } @@ -149,9 +149,9 @@ public void logTest_logResponsesDisabled_diffGreaterThanLogLimit() throws Except List lightblue = getDummyMessage("Fooo", 40); boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", new LazyMethodCallStringifier("testMethod(param1, param2)")); assertFalse(result); - verify(log).warn(logStmt.capture()); + verify(inconsitencyLog).warn(logStmt.capture()); assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - diff is greater than 175 bytes!", logStmt.getValue()); - verify(inconsistencyLog).debug(inconsistencyLogStmt.capture()); + verify(hugeInconsistencyLog).debug(inconsistencyLogStmt.capture()); assertTrue(inconsistencyLogStmt.getValue().contains("diff")); assertTrue(inconsistencyLogStmt.getValue().contains("legacyJson")); assertTrue(inconsistencyLogStmt.getValue().contains("lightblueJson"));