From efa8ac1eb6a3f0f03abb1af01d614b1929caec47 Mon Sep 17 00:00:00 2001 From: Marek Paterczyk Date: Thu, 4 Feb 2016 14:24:23 -0500 Subject: [PATCH] Generating method call string only when needed (i.e. when there is an inconsistency to log) --- .../migrator/facade/ConsistencyChecker.java | 12 +- .../migrator/facade/DAOFacadeBase.java | 59 ++-------- .../migrator/facade/ServiceFacade.java | 66 +---------- .../EagerMethodCallStringifier.java | 84 ++++++++++++++ .../LazyMethodCallStringifier.java | 105 ++++++++++++++++++ .../MethodCallStringifier.java | 14 +++ .../facade/ConsistencyLoggerTest.java | 11 +- .../migrator/facade/DAOFacadeTest.java | 49 ++++---- .../migrator/facade/ServiceFacadeTest.java | 49 ++++---- .../MethodCallStringifierTest.java | 15 +-- 10 files changed, 291 insertions(+), 173 deletions(-) create mode 100644 facade/src/main/java/com/redhat/lightblue/migrator/facade/methodcallstringifier/EagerMethodCallStringifier.java create mode 100644 facade/src/main/java/com/redhat/lightblue/migrator/facade/methodcallstringifier/LazyMethodCallStringifier.java create mode 100644 facade/src/main/java/com/redhat/lightblue/migrator/facade/methodcallstringifier/MethodCallStringifier.java rename facade/src/test/java/com/redhat/lightblue/migrator/facade/{ => methodcallstringifier}/MethodCallStringifierTest.java (64%) 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 db1ad22..3b9b787 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 @@ -16,6 +16,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; +import com.redhat.lightblue.migrator.facade.methodcallstringifier.LazyMethodCallStringifier; +import com.redhat.lightblue.migrator.facade.methodcallstringifier.MethodCallStringifier; /** * This class checks for data inconsistencies and handles logging. @@ -110,13 +112,17 @@ protected boolean checkConsistency(Object o1, Object o2) { * @param callToLogInCaseOfInconsistency the call including parameters * @return */ - protected boolean checkConsistency(final Object legacyEntity, final Object lightblueEntity, String methodName, String callToLogInCaseOfInconsistency) { + protected boolean checkConsistency(final Object legacyEntity, final Object lightblueEntity, String methodName, MethodCallStringifier callToLogInCaseOfInconsistency) { if (legacyEntity==null&&lightblueEntity==null) { return true; } String legacyJson=null; String lightblueJson=null; + + if (callToLogInCaseOfInconsistency == null) + callToLogInCaseOfInconsistency = new LazyMethodCallStringifier(); + try { long t1 = System.currentTimeMillis(); legacyJson = getObjectWriter(methodName).writeValueAsString(legacyEntity); @@ -130,14 +136,14 @@ protected boolean checkConsistency(final Object legacyEntity, final Object light log.debug("Consistency check passed: "+ result.passed()); } if (!result.passed()) { - logInconsistency(callToLogInCaseOfInconsistency, legacyJson, lightblueJson, result.getMessage().replaceAll("\n", ",")); + logInconsistency(callToLogInCaseOfInconsistency.toString(), legacyJson, lightblueJson, result.getMessage().replaceAll("\n", ",")); } return result.passed(); } catch (JSONException e) { if (legacyEntity!=null&&legacyEntity.equals(lightblueEntity)) { return true; } else { - logInconsistency(callToLogInCaseOfInconsistency, legacyJson, lightblueJson, null); + logInconsistency(callToLogInCaseOfInconsistency.toString(), legacyJson, lightblueJson, null); } } catch (JsonProcessingException e) { log.error("Consistency check failed in "+implementationName+"."+callToLogInCaseOfInconsistency+"! Invalid JSON: legacyJson="+legacyJson+", lightblueJson="+lightblueJson, e); diff --git a/facade/src/main/java/com/redhat/lightblue/migrator/facade/DAOFacadeBase.java b/facade/src/main/java/com/redhat/lightblue/migrator/facade/DAOFacadeBase.java index dd1db73..d09db14 100644 --- a/facade/src/main/java/com/redhat/lightblue/migrator/facade/DAOFacadeBase.java +++ b/facade/src/main/java/com/redhat/lightblue/migrator/facade/DAOFacadeBase.java @@ -21,6 +21,7 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; +import com.redhat.lightblue.migrator.facade.methodcallstringifier.EagerMethodCallStringifier; import com.redhat.lightblue.migrator.features.LightblueMigration; import com.redhat.lightblue.migrator.features.TogglzRandomUsername; @@ -114,44 +115,6 @@ private Class[] toClasses(Object[] objects) { return classes.toArray(new Class[]{}); } - static String methodCallToString(String methodName, Object[] values) { - try { - StringBuilder str = new StringBuilder(); - str.append(methodName).append("("); - Iterator it = Arrays.asList(values).iterator(); - while(it.hasNext()) { - Object value = it.next(); - if (value != null && value.getClass().isArray()) - if (value.getClass().getComponentType().isPrimitive()) { - // this is an array of primitives, convert to a meaningful string using reflection - String primitiveArrayType = value.getClass().getComponentType().getName(); - - StringBuilder pStr = new StringBuilder(); - for (int i = 0; i < Array.getLength(value); i ++) { - pStr.append(Array.get(value, i)); - if (i != Array.getLength(value)-1) { - pStr.append(", "); - } - } - str.append(primitiveArrayType).append("[").append(pStr.toString()).append("]"); - } - else { - str.append(Arrays.deepToString((Object[])value)); - } - else - str.append(value); - if (it.hasNext()) { - str.append(", "); - } - } - str.append(")"); - return str.toString(); - } catch (Exception e) { - log.error("Creating method call string failed", e); - return ""; - } - } - private ListenableFuture callLightblueDAO(final boolean passIds, final Method method, final Object[] values) { ListeningExecutorService executor = createExecutor(); try { @@ -204,7 +167,7 @@ private Throwable extractUnderlyingException(Throwable t) { */ public T callDAOReadMethod(final Class returnedType, final String methodName, final Class[] types, final Object ... values) throws Throwable { if (log.isDebugEnabled()) - log.debug("Calling {}.{} ({} {})", implementationName, methodCallToString(methodName, values), "parallel", "READ"); + log.debug("Calling {}.{} ({} {})", implementationName, EagerMethodCallStringifier.stringifyMethodCall(methodName, values), "parallel", "READ"); TogglzRandomUsername.init(); T legacyEntity = null, lightblueEntity = null; @@ -236,7 +199,7 @@ public T callDAOReadMethod(final Class returnedType, final String methodN lightblueEntity = getWithTimeout(listenableFuture, methodName, LightblueMigration.shouldReadSourceEntity()); } catch (TimeoutException te) { if (LightblueMigration.shouldReadSourceEntity()) { - log.warn("Lightblue call "+implementationName+"."+methodCallToString(methodName, values)+" is taking too long (longer than "+timeoutConfiguration.getTimeoutMS(methodName)+"s). Returning data from legacy."); + log.warn("Lightblue call "+implementationName+"."+EagerMethodCallStringifier.stringifyMethodCall(methodName, values)+" is taking too long (longer than "+timeoutConfiguration.getTimeoutMS(methodName)+"s). Returning data from legacy."); return legacyEntity; } else { throw te; @@ -254,7 +217,7 @@ public T callDAOReadMethod(final Class returnedType, final String methodN if (LightblueMigration.shouldCheckReadConsistency() && LightblueMigration.shouldReadSourceEntity() && LightblueMigration.shouldReadDestinationEntity()) { // make sure that response from lightblue and oracle are the same log.debug("."+methodName+" checking returned entity's consistency"); - if (getConsistencyChecker().checkConsistency(legacyEntity, lightblueEntity, methodName, methodCallToString(methodName, values))) { + if (getConsistencyChecker().checkConsistency(legacyEntity, lightblueEntity, methodName, new EagerMethodCallStringifier(methodName, values))) { // return lightblue data if they are return lightblueEntity; } else { @@ -296,7 +259,7 @@ public T callDAOReadMethod(final Class returnedType, final String methodN */ public T callDAOUpdateMethod(final Class returnedType, final String methodName, final Class[] types, final Object ... values) throws Throwable { if (log.isDebugEnabled()) - log.debug("Calling {}.{} ({} {})", implementationName, methodCallToString(methodName, values), "parallel", "WRITE"); + log.debug("Calling {}.{} ({} {})", implementationName, EagerMethodCallStringifier.stringifyMethodCall(methodName, values), "parallel", "WRITE"); TogglzRandomUsername.init(); T legacyEntity = null, lightblueEntity = null; @@ -328,7 +291,7 @@ public T callDAOUpdateMethod(final Class returnedType, final String metho lightblueEntity = getWithTimeout(listenableFuture, methodName, LightblueMigration.shouldWriteSourceEntity()); } catch (TimeoutException te) { if (LightblueMigration.shouldReadSourceEntity()) { - log.warn("Lightblue call "+implementationName+"."+methodCallToString(methodName, values)+" is taking too long (longer than "+timeoutConfiguration.getTimeoutMS(methodName)+"s). Returning data from legacy."); + log.warn("Lightblue call "+implementationName+"."+EagerMethodCallStringifier.stringifyMethodCall(methodName, values)+" is taking too long (longer than "+timeoutConfiguration.getTimeoutMS(methodName)+"s). Returning data from legacy."); return legacyEntity; } else { throw te; @@ -346,7 +309,7 @@ public T callDAOUpdateMethod(final Class returnedType, final String metho if (LightblueMigration.shouldCheckWriteConsistency() && LightblueMigration.shouldWriteSourceEntity() && LightblueMigration.shouldWriteDestinationEntity()) { // make sure that response from lightblue and oracle are the same log.debug("."+methodName+" checking returned entity's consistency"); - if (getConsistencyChecker().checkConsistency(legacyEntity, lightblueEntity, methodName, methodCallToString(methodName, values))) { + if (getConsistencyChecker().checkConsistency(legacyEntity, lightblueEntity, methodName, new EagerMethodCallStringifier(methodName, values))) { // return lightblue data if they are return lightblueEntity; } else { @@ -383,7 +346,7 @@ public T callDAOUpdateMethod(final Class returnedType, final String metho */ public T callDAOCreateSingleMethod(final EntityIdExtractor entityIdExtractor, final Class returnedType, final String methodName, final Class[] types, final Object ... values) throws Throwable { if (log.isDebugEnabled()) - log.debug("Calling {}.{} ({} {})", implementationName, methodCallToString(methodName, values), "serial", "WRITE"); + log.debug("Calling {}.{} ({} {})", implementationName, EagerMethodCallStringifier.stringifyMethodCall(methodName, values), "serial", "WRITE"); TogglzRandomUsername.init(); if (entityIdStore != null) @@ -432,7 +395,7 @@ public T callDAOCreateSingleMethod(final EntityIdExtractor entityIdExtrac EntityIdStoreException se = extractEntityIdStoreExceptionIfExists(ee); if (se != null && !passIds) { log.warn("Possible data inconsistency in a create-if-not-exists scenario (entity exists in legacy, but does not in lightblue). Method called: " - + methodCallToString(methodName, values), se); + + EagerMethodCallStringifier.stringifyMethodCall(methodName, values), se); return legacyEntity; } @@ -443,7 +406,7 @@ public T callDAOCreateSingleMethod(final EntityIdExtractor entityIdExtrac } } catch (TimeoutException te) { if (LightblueMigration.shouldReadSourceEntity()) { - log.warn("Lightblue call "+implementationName+"."+methodCallToString(methodName, values)+" is taking too long (longer than "+timeoutConfiguration.getTimeoutMS(methodName)+"s). Returning data from legacy."); + log.warn("Lightblue call "+implementationName+"."+EagerMethodCallStringifier.stringifyMethodCall(methodName, values)+" is taking too long (longer than "+timeoutConfiguration.getTimeoutMS(methodName)+"s). Returning data from legacy."); return legacyEntity; } else { throw te; @@ -464,7 +427,7 @@ public T callDAOCreateSingleMethod(final EntityIdExtractor entityIdExtrac log.debug("."+methodName+" checking returned entity's consistency"); // check if entities match - if (getConsistencyChecker().checkConsistency(legacyEntity, lightblueEntity, methodName, methodCallToString(methodName, values))) { + if (getConsistencyChecker().checkConsistency(legacyEntity, lightblueEntity, methodName, new EagerMethodCallStringifier(methodName, values))) { // return lightblue data if they are return lightblueEntity; } else { diff --git a/facade/src/main/java/com/redhat/lightblue/migrator/facade/ServiceFacade.java b/facade/src/main/java/com/redhat/lightblue/migrator/facade/ServiceFacade.java index db47d04..7907488 100644 --- a/facade/src/main/java/com/redhat/lightblue/migrator/facade/ServiceFacade.java +++ b/facade/src/main/java/com/redhat/lightblue/migrator/facade/ServiceFacade.java @@ -22,6 +22,7 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; +import com.redhat.lightblue.migrator.facade.methodcallstringifier.LazyMethodCallStringifier; import com.redhat.lightblue.migrator.facade.proxy.FacadeProxyFactory.Secret; import com.redhat.lightblue.migrator.facade.sharedstore.SharedStore; import com.redhat.lightblue.migrator.facade.sharedstore.SharedStoreException; @@ -123,65 +124,6 @@ private Class[] toClasses(Object[] objects) { return classes.toArray(new Class[]{}); } - /** - * Return a pretty printed method call. - * - * @param methodName - * @param values - * @return - */ - static String methodCallToString(Method method, Object[] values) { - try { - StringBuilder str = new StringBuilder(); - str.append(method.getName()).append("("); - Iterator it = Arrays.asList(values).iterator(); - Iterator annotations = Arrays.asList(method.getParameterAnnotations()).iterator(); - while(it.hasNext()) { - Object value = it.next(); - boolean isSecret = false; - for (Annotation a: annotations.next()) { - if (a instanceof Secret) { - isSecret=true; - break; - } - } - - if (isSecret) { - str.append("****"); - } else { - if (value != null && value.getClass().isArray()) - if (value.getClass().getComponentType().isPrimitive()) { - // this is an array of primitives, convert to a meaningful string using reflection - String primitiveArrayType = value.getClass().getComponentType().getName(); - - StringBuilder pStr = new StringBuilder(); - for (int i = 0; i < Array.getLength(value); i ++) { - pStr.append(Array.get(value, i)); - if (i != Array.getLength(value)-1) { - pStr.append(", "); - } - } - str.append(primitiveArrayType).append("[").append(pStr.toString()).append("]"); - } - else { - str.append(Arrays.deepToString((Object[])value)); - } - else - str.append(value); - } - - if (it.hasNext()) { - str.append(", "); - } - } - str.append(")"); - return str.toString(); - } catch (Exception e) { - log.error("Creating method call string failed", e); - return ""; - } - } - private ListenableFuture callLightblueSvc(final boolean passIds, final Method method, final Object[] values) { ListeningExecutorService executor = createExecutor(); try { @@ -282,7 +224,7 @@ public T callSvcMethod(final FacadeOperation facadeOperation, final boolean final Class[] types = methodCalled.getParameterTypes(); if (log.isDebugEnabled()) { - log.debug("Calling {}.{} ({} {})", implementationName, methodCallToString(methodCalled, values), callInParallel ? "parallel": "serial", facadeOperation); + log.debug("Calling {}.{} ({} {})", implementationName, LazyMethodCallStringifier.stringifyMethodCall(methodCalled, values), callInParallel ? "parallel": "serial", facadeOperation); } TogglzRandomUsername.init(); @@ -336,7 +278,7 @@ public T callSvcMethod(final FacadeOperation facadeOperation, final boolean } } catch (TimeoutException te) { if (shouldSource(facadeOperation)) { - log.warn("Lightblue call "+implementationName+"."+methodCallToString(methodCalled, values)+" is taking too long (longer than "+timeoutConfiguration.getTimeoutMS(methodName)+"s). Returning data from legacy."); + log.warn("Lightblue call "+implementationName+"."+LazyMethodCallStringifier.stringifyMethodCall(methodCalled, values)+" is taking too long (longer than "+timeoutConfiguration.getTimeoutMS(methodName)+"s). Returning data from legacy."); return legacyEntity; } else { throw te; @@ -356,7 +298,7 @@ public T callSvcMethod(final FacadeOperation facadeOperation, final boolean log.debug("."+methodName+" checking returned entity's consistency"); // check if entities match - if (getConsistencyChecker().checkConsistency(legacyEntity, lightblueEntity, methodName, methodCallToString(methodCalled, values))) { + if (getConsistencyChecker().checkConsistency(legacyEntity, lightblueEntity, methodName, new LazyMethodCallStringifier(methodCalled, values))) { // return lightblue data if they are return lightblueEntity; } else { diff --git a/facade/src/main/java/com/redhat/lightblue/migrator/facade/methodcallstringifier/EagerMethodCallStringifier.java b/facade/src/main/java/com/redhat/lightblue/migrator/facade/methodcallstringifier/EagerMethodCallStringifier.java new file mode 100644 index 0000000..3336d7f --- /dev/null +++ b/facade/src/main/java/com/redhat/lightblue/migrator/facade/methodcallstringifier/EagerMethodCallStringifier.java @@ -0,0 +1,84 @@ +package com.redhat.lightblue.migrator.facade.methodcallstringifier; + +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.Iterator; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.redhat.lightblue.migrator.facade.proxy.FacadeProxyFactory.Secret; + +/** + * Use ${link {@link LazyMethodCallStringifier} instead. This @{link {@link MethodCallStringifier} does not + * support the {@link Secret} annotations. + * + * @author mpatercz + * + */ +@Deprecated +public class EagerMethodCallStringifier implements MethodCallStringifier { + + private static final Logger log = LoggerFactory.getLogger(EagerMethodCallStringifier.class); + + private final String methodCallString; + + public EagerMethodCallStringifier(String methodName, Object[] values) { + this.methodCallString = methodCallToString(methodName, values); + } + + public EagerMethodCallStringifier(String methodCallString) { + this.methodCallString = methodCallString; + } + + private String methodCallToString(String methodName, Object[] values) { + try { + StringBuilder str = new StringBuilder(); + str.append(methodName).append("("); + Iterator it = Arrays.asList(values).iterator(); + while(it.hasNext()) { + Object value = it.next(); + if (value != null && value.getClass().isArray()) + if (value.getClass().getComponentType().isPrimitive()) { + // this is an array of primitives, convert to a meaningful string using reflection + String primitiveArrayType = value.getClass().getComponentType().getName(); + + StringBuilder pStr = new StringBuilder(); + for (int i = 0; i < Array.getLength(value); i ++) { + pStr.append(Array.get(value, i)); + if (i != Array.getLength(value)-1) { + pStr.append(", "); + } + } + str.append(primitiveArrayType).append("[").append(pStr.toString()).append("]"); + } + else { + str.append(Arrays.deepToString((Object[])value)); + } + else + str.append(value); + if (it.hasNext()) { + str.append(", "); + } + } + str.append(")"); + return str.toString(); + } catch (Exception e) { + log.error("Creating method call string failed", e); + return ""; + } + } + + /* (non-Javadoc) + * @see com.redhat.lightblue.migrator.facade.MethodCallStringifier#toString() + */ + @Override + public String toString() { + return methodCallString; + } + + public static String stringifyMethodCall(final String methodName, final Object[] values) { + return new EagerMethodCallStringifier(methodName, values).toString(); + } + +} diff --git a/facade/src/main/java/com/redhat/lightblue/migrator/facade/methodcallstringifier/LazyMethodCallStringifier.java b/facade/src/main/java/com/redhat/lightblue/migrator/facade/methodcallstringifier/LazyMethodCallStringifier.java new file mode 100644 index 0000000..e97fb34 --- /dev/null +++ b/facade/src/main/java/com/redhat/lightblue/migrator/facade/methodcallstringifier/LazyMethodCallStringifier.java @@ -0,0 +1,105 @@ +package com.redhat.lightblue.migrator.facade.methodcallstringifier; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Array; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Iterator; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.redhat.lightblue.migrator.facade.proxy.FacadeProxyFactory.Secret; + +/* (non-Javadoc) + * @see com.redhat.lightblue.migrator.facade.MethodCallStringifier + */ +public class LazyMethodCallStringifier implements MethodCallStringifier { + + private static final Logger log = LoggerFactory.getLogger(LazyMethodCallStringifier.class); + + private final Method method; + private final Object[] values; + private final String stringifiedMethodCall; + + public LazyMethodCallStringifier(Method method, Object[] values) { + this.method = method; + this.values = values; + this.stringifiedMethodCall = null; + } + + public LazyMethodCallStringifier(String stringifiedMethodCall) { + this.method = null; + this.values = null; + this.stringifiedMethodCall = stringifiedMethodCall; + } + + public LazyMethodCallStringifier() { + this(""); + } + + /* (non-Javadoc) + * @see com.redhat.lightblue.migrator.facade.MethodCallStringifier#toString() + */ + @Override + public String toString() { + + if (stringifiedMethodCall != null) + return stringifiedMethodCall; + + try { + StringBuilder str = new StringBuilder(); + str.append(method.getName()).append("("); + Iterator it = Arrays.asList(values).iterator(); + Iterator annotations = Arrays.asList(method.getParameterAnnotations()).iterator(); + while(it.hasNext()) { + Object value = it.next(); + boolean isSecret = false; + for (Annotation a: annotations.next()) { + if (a instanceof Secret) { + isSecret=true; + break; + } + } + + if (isSecret) { + str.append("****"); + } else { + if (value != null && value.getClass().isArray()) + if (value.getClass().getComponentType().isPrimitive()) { + // this is an array of primitives, convert to a meaningful string using reflection + String primitiveArrayType = value.getClass().getComponentType().getName(); + + StringBuilder pStr = new StringBuilder(); + for (int i = 0; i < Array.getLength(value); i ++) { + pStr.append(Array.get(value, i)); + if (i != Array.getLength(value)-1) { + pStr.append(", "); + } + } + str.append(primitiveArrayType).append("[").append(pStr.toString()).append("]"); + } + else { + str.append(Arrays.deepToString((Object[])value)); + } + else + str.append(value); + } + + if (it.hasNext()) { + str.append(", "); + } + } + str.append(")"); + return str.toString(); + } catch (Exception e) { + log.error("Creating method call string failed", e); + return ""; + } + } + + public static String stringifyMethodCall(final Method method, final Object[] values) { + return new LazyMethodCallStringifier(method, values).toString(); + } + +} diff --git a/facade/src/main/java/com/redhat/lightblue/migrator/facade/methodcallstringifier/MethodCallStringifier.java b/facade/src/main/java/com/redhat/lightblue/migrator/facade/methodcallstringifier/MethodCallStringifier.java new file mode 100644 index 0000000..f0ffb46 --- /dev/null +++ b/facade/src/main/java/com/redhat/lightblue/migrator/facade/methodcallstringifier/MethodCallStringifier.java @@ -0,0 +1,14 @@ +package com.redhat.lightblue.migrator.facade.methodcallstringifier; + +/** + * Generates method(arg1, arg2, ...) string used to trace errors and data inconsistency warnings to particular + * method call. + * + * @author mpatercz + * + */ +public interface MethodCallStringifier { + + public abstract String toString(); + +} \ No newline at end of file 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 a7fcb63..aa77df4 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 @@ -22,6 +22,7 @@ import org.slf4j.Logger; import com.fasterxml.jackson.core.JsonProcessingException; +import com.redhat.lightblue.migrator.facade.methodcallstringifier.LazyMethodCallStringifier; @RunWith(MockitoJUnitRunner.class) public class ConsistencyLoggerTest { @@ -69,7 +70,7 @@ public void logTest_logResponsesEnabled_logLessThanLogLimit() throws Exception { List legacy = getDummyMessage("Test", 24); List lightblue = getDummyMessage("Test", 12); - boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", "testMethod(param1, param2)"); + boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", new LazyMethodCallStringifier("testMethod(param1, param2)")); assertFalse(result); verify(log).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()); @@ -87,7 +88,7 @@ public void logTest_logResponsesEnabled_logGreaterThanLogLimit() throws Exceptio List legacy = getDummyMessage("Test", 36); List lightblue = getDummyMessage("Test", 24); - boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", "testMethod(param1, param2)"); + boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", new LazyMethodCallStringifier("testMethod(param1, param2)")); assertFalse(result); verify(log).warn(logStmt.capture()); assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - diff: []: Expected 3 values but got 2", logStmt.getValue()); @@ -106,7 +107,7 @@ public void logTest_logResponsesEnabled_diffGreaterThanLogLimit() throws Excepti List legacy = getDummyMessage("Test", 40); List lightblue = getDummyMessage("Fooo", 40); - boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", "testMethod(param1, param2)"); + boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", new LazyMethodCallStringifier("testMethod(param1, param2)")); assertFalse(result); verify(log).warn(logStmt.capture()); assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - payload and diff is greater than 175 bytes!", logStmt.getValue()); @@ -127,7 +128,7 @@ public void logTest_logResponsesDisabled_logLessThanLogLimit() throws Exception List legacy = getDummyMessage("Test", 24); List lightblue = getDummyMessage("Test", 12); - boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", "testMethod(param1, param2)"); + boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", new LazyMethodCallStringifier("testMethod(param1, param2)")); assertFalse(result); verify(log).warn(logStmt.capture()); assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - diff: []: Expected 2 values but got 1", logStmt.getValue()); @@ -146,7 +147,7 @@ public void logTest_logResponsesDisabled_diffGreaterThanLogLimit() throws Except List legacy = getDummyMessage("Test", 40); List lightblue = getDummyMessage("Fooo", 40); - boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", "testMethod(param1, param2)"); + boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", new LazyMethodCallStringifier("testMethod(param1, param2)")); assertFalse(result); verify(log).warn(logStmt.capture()); assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - diff is greater than 175 bytes!", logStmt.getValue()); diff --git a/facade/src/test/java/com/redhat/lightblue/migrator/facade/DAOFacadeTest.java b/facade/src/test/java/com/redhat/lightblue/migrator/facade/DAOFacadeTest.java index 90c8e91..44f8cbd 100644 --- a/facade/src/test/java/com/redhat/lightblue/migrator/facade/DAOFacadeTest.java +++ b/facade/src/test/java/com/redhat/lightblue/migrator/facade/DAOFacadeTest.java @@ -16,6 +16,7 @@ import org.mockito.stubbing.Answer; import org.togglz.junit.TogglzRule; +import com.redhat.lightblue.migrator.facade.methodcallstringifier.MethodCallStringifier; import com.redhat.lightblue.migrator.facade.model.Country; import com.redhat.lightblue.migrator.features.LightblueMigrationFeatures; import com.redhat.lightblue.migrator.test.LightblueMigrationPhase; @@ -58,7 +59,7 @@ public void initialPhaseRead() throws CountryException { facade.getCountry("PL"); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Mockito.verifyNoMoreInteractions(lightblueDAO); Mockito.verify(legacyDAO).getCountry("PL"); } @@ -74,7 +75,7 @@ public void dualReadPhaseReadConsistentTest() throws CountryException { facade.getCountry("PL"); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Mockito.verify(legacyDAO).getCountry("PL"); Mockito.verify(lightblueDAO).getCountry("PL"); } @@ -91,7 +92,7 @@ public void dualReadPhaseReadInconsistentTest() throws CountryException { Country returnedCountry = facade.getCountry("PL"); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Mockito.verify(legacyDAO).getCountry("PL"); Mockito.verify(lightblueDAO).getCountry("PL"); @@ -113,7 +114,7 @@ public void dualReadPhaseReadInconsistentPrimitiveArrayTest() throws CountryExce Country returnedCountry = facade.getCountries(ids).get(0); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Mockito.verify(legacyDAO).getCountries(ids); Mockito.verify(lightblueDAO).getCountries(ids); @@ -127,7 +128,7 @@ public void lightblueProxyTest() throws CountryException { facade.getCountry("PL"); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Mockito.verifyZeroInteractions(legacyDAO); Mockito.verify(lightblueDAO).getCountry("PL"); } @@ -144,7 +145,7 @@ public void initialPhaseUpdate() throws CountryException { Mockito.verifyNoMoreInteractions(lightblueDAO); Mockito.verify(legacyDAO).updateCountry(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } @Test @@ -157,7 +158,7 @@ public void dualWritePhaseUpdateConsistentTest() throws CountryException { Mockito.verify(legacyDAO).updateCountry(pl); Mockito.verify(lightblueDAO).updateCountry(pl); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } @Test @@ -174,7 +175,7 @@ public void dualWritePhaseUpdateInconsistentTest() throws CountryException { Mockito.verify(legacyDAO).updateCountry(pl); Mockito.verify(lightblueDAO).updateCountry(pl); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); // when there is a conflict, facade will return what legacy dao returned Assert.assertEquals(ca, updatedEntity); @@ -190,7 +191,7 @@ public void ligtblueProxyPhaseUpdateTest() throws CountryException { Mockito.verifyZeroInteractions(legacyDAO); Mockito.verify(lightblueDAO).updateCountry(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } /* insert tests */ @@ -205,7 +206,7 @@ public void initialPhaseCreate() throws CountryException { Mockito.verifyZeroInteractions(lightblueDAO); Mockito.verify(legacyDAO).createCountry(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } @Test @@ -223,7 +224,7 @@ public void dualWritePhaseCreateConsistentTest() throws CountryException { Mockito.verify(legacyDAO).createCountry(pl); Mockito.verify(lightblueDAO).createCountry(pl); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); // CountryDAOLightblue should set the id. Since it's just a mock, I'm checking what's in the cache. Assert.assertTrue(101l == ((DAOFacadeBase)facade).getEntityIdStore().pop()); @@ -243,7 +244,7 @@ public void dualWritePhaseCreateInconsistentTest() throws CountryException { Mockito.verify(legacyDAO).createCountry(pl); Mockito.verify(lightblueDAO).createCountry(pl); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); // CountryDAOLightblue should set the id. Since it's just a mock, I'm checking what's in the cache. Assert.assertTrue(101l == ((DAOFacadeBase) facade).getEntityIdStore().pop()); @@ -265,7 +266,7 @@ public void ligtblueProxyPhaseCreateTest() throws CountryException { Mockito.verifyZeroInteractions(legacyDAO); Mockito.verify(lightblueDAO).createCountry(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } /* insert tests when method also does a read */ @@ -280,7 +281,7 @@ public void initialPhaseCreateWithRead() throws CountryException { Mockito.verifyZeroInteractions(lightblueDAO); Mockito.verify(legacyDAO).createCountryIfNotExists(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } @Test @@ -298,7 +299,7 @@ public void dualReadPhaseCreateWithReadTest() throws CountryException { Mockito.verify(legacyDAO).createCountryIfNotExists(pl); Mockito.verify(lightblueDAO).createCountryIfNotExists(pl); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); // CountryDAOLightblue should set the id. Since it's just a mock, I'm checking what's in the cache. Assert.assertTrue(101l == ((DAOFacadeBase)facade).getEntityIdStore().pop()); @@ -314,7 +315,7 @@ public void ligtblueProxyPhaseCreateWithReadTest() throws CountryException { Mockito.verifyZeroInteractions(legacyDAO); Mockito.verify(lightblueDAO).createCountryIfNotExists(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } /* lightblue failure tests */ @@ -475,7 +476,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Mockito.verify(lightblueDAO).createCountry(pl); Mockito.verify(legacyDAO).createCountry(pl); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Assert.assertEquals(pl, returnedCountry); } @@ -504,7 +505,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Mockito.verify(lightblueDAO).createCountry(pl); Mockito.verify(legacyDAO).createCountry(pl); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Assert.assertEquals(pl, returnedCountry); } @@ -533,7 +534,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Mockito.verify(lightblueDAO).createCountry(pl); Mockito.verify(legacyDAO).createCountry(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Assert.assertEquals(pl, returnedCountry); } @@ -562,7 +563,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Mockito.verify(lightblueDAO).getCountry("PL"); Mockito.verify(legacyDAO).getCountry("PL"); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Assert.assertEquals(pl, returnedCountry); } @@ -591,7 +592,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Mockito.verify(lightblueDAO).updateCountry(pl); Mockito.verify(legacyDAO).updateCountry(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Assert.assertEquals(pl, returnedCountry); } @@ -623,7 +624,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Mockito.verify(lightblueDAO).getCountry("PL"); Mockito.verify(legacyDAO).getCountry("PL"); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Assert.assertEquals(pl, returnedCountry); } @@ -655,7 +656,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Mockito.verify(lightblueDAO).createCountry(pl); Mockito.verify(legacyDAO).createCountry(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Assert.assertEquals(pl, returnedCountry); } @@ -883,7 +884,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Assert.assertEquals((Long)13l, returned.getId()); // the id pushed into shared store during first, failed call, is cleared, expecting no inconsistency - Mockito.verify(consistencyChecker).checkConsistency(Mockito.eq(new Country(13l, "PL")), Mockito.eq(new Country(13l, "PL")), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.eq(new Country(13l, "PL")), Mockito.eq(new Country(13l, "PL")), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Mockito.verify(legacyDAO).createCountry(pl); Mockito.verify(legacyDAO).createCountry(ca); diff --git a/facade/src/test/java/com/redhat/lightblue/migrator/facade/ServiceFacadeTest.java b/facade/src/test/java/com/redhat/lightblue/migrator/facade/ServiceFacadeTest.java index be0dd0c..e06866c 100644 --- a/facade/src/test/java/com/redhat/lightblue/migrator/facade/ServiceFacadeTest.java +++ b/facade/src/test/java/com/redhat/lightblue/migrator/facade/ServiceFacadeTest.java @@ -16,6 +16,7 @@ import org.mockito.stubbing.Answer; import org.togglz.junit.TogglzRule; +import com.redhat.lightblue.migrator.facade.methodcallstringifier.MethodCallStringifier; import com.redhat.lightblue.migrator.facade.model.Country; import com.redhat.lightblue.migrator.facade.proxy.FacadeProxyFactory; import com.redhat.lightblue.migrator.facade.sharedstore.SharedStoreSetter; @@ -99,7 +100,7 @@ public void initialPhaseRead() throws CountryException { countryDAOProxy.getCountry("PL"); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Mockito.verifyNoMoreInteractions(lightblueDAO); Mockito.verify(legacyDAO).getCountry("PL"); } @@ -115,7 +116,7 @@ public void dualReadPhaseReadConsistentTest() throws CountryException { countryDAOProxy.getCountry("PL"); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Mockito.verify(legacyDAO).getCountry("PL"); Mockito.verify(lightblueDAO).getCountry("PL"); } @@ -132,7 +133,7 @@ public void dualReadPhaseReadInconsistentTest() throws CountryException { Country returnedCountry = countryDAOProxy.getCountry("PL"); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Mockito.verify(legacyDAO).getCountry("PL"); Mockito.verify(lightblueDAO).getCountry("PL"); @@ -154,7 +155,7 @@ public void dualReadPhaseReadInconsistentPrimitiveArrayTest() throws CountryExce Country returnedCountry = countryDAOProxy.getCountries(ids).get(0); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Mockito.verify(legacyDAO).getCountries(ids); Mockito.verify(lightblueDAO).getCountries(ids); @@ -168,7 +169,7 @@ public void lightblueProxyTest() throws CountryException { countryDAOProxy.getCountry("PL"); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Mockito.verifyZeroInteractions(legacyDAO); Mockito.verify(lightblueDAO).getCountry("PL"); } @@ -185,7 +186,7 @@ public void initialPhaseUpdate() throws CountryException { Mockito.verifyNoMoreInteractions(lightblueDAO); Mockito.verify(legacyDAO).updateCountry(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } @Test @@ -198,7 +199,7 @@ public void dualWritePhaseUpdateConsistentTest() throws CountryException { Mockito.verify(legacyDAO).updateCountry(pl); Mockito.verify(lightblueDAO).updateCountry(pl); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } @Test @@ -215,7 +216,7 @@ public void dualWritePhaseUpdateInconsistentTest() throws CountryException { Mockito.verify(legacyDAO).updateCountry(pl); Mockito.verify(lightblueDAO).updateCountry(pl); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); // when there is a conflict, facade will return what legacy dao returned Assert.assertEquals(ca, updatedEntity); @@ -231,7 +232,7 @@ public void ligtblueProxyPhaseUpdateTest() throws CountryException { Mockito.verifyZeroInteractions(legacyDAO); Mockito.verify(lightblueDAO).updateCountry(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } /* insert tests */ @@ -246,7 +247,7 @@ public void initialPhaseCreate() throws CountryException { Mockito.verifyZeroInteractions(lightblueDAO); Mockito.verify(legacyDAO).createCountry(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } @Test @@ -264,7 +265,7 @@ public void dualWritePhaseCreateConsistentTest() throws CountryException { Mockito.verify(legacyDAO).createCountry(pl); Mockito.verify(lightblueDAO).createCountry(pl); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } @Test @@ -281,7 +282,7 @@ public void dualWritePhaseCreateInconsistentTest() throws CountryException { Mockito.verify(legacyDAO).createCountry(pl); Mockito.verify(lightblueDAO).createCountry(pl); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Assert.assertEquals(pl.getIso2Code(), "PL"); } @@ -301,7 +302,7 @@ public void ligtblueProxyPhaseCreateTest() throws CountryException { Mockito.verifyZeroInteractions(legacyDAO); Mockito.verify(lightblueDAO).createCountry(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } /* insert tests when method also does a read */ @@ -316,7 +317,7 @@ public void initialPhaseCreateWithRead() throws CountryException { Mockito.verifyZeroInteractions(lightblueDAO); Mockito.verify(legacyDAO).createCountryIfNotExists(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } @Test @@ -334,7 +335,7 @@ public void dualReadPhaseCreateWithReadTest() throws CountryException { Mockito.verify(legacyDAO).createCountryIfNotExists(pl); Mockito.verify(lightblueDAO).createCountryIfNotExists(pl); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } @Test @@ -347,7 +348,7 @@ public void ligtblueProxyPhaseCreateWithReadTest() throws CountryException { Mockito.verifyZeroInteractions(legacyDAO); Mockito.verify(lightblueDAO).createCountryIfNotExists(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); } /* lightblue failure tests */ @@ -508,7 +509,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Mockito.verify(lightblueDAO).createCountry(pl); Mockito.verify(legacyDAO).createCountry(pl); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Assert.assertEquals(pl, returnedCountry); } @@ -537,7 +538,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Mockito.verify(lightblueDAO).createCountry(pl); Mockito.verify(legacyDAO).createCountry(pl); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Assert.assertEquals(pl, returnedCountry); } @@ -566,7 +567,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Mockito.verify(lightblueDAO).createCountry(pl); Mockito.verify(legacyDAO).createCountry(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Assert.assertEquals(pl, returnedCountry); } @@ -595,7 +596,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Mockito.verify(lightblueDAO).getCountry("PL"); Mockito.verify(legacyDAO).getCountry("PL"); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Assert.assertEquals(pl, returnedCountry); } @@ -624,7 +625,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Mockito.verify(lightblueDAO).updateCountry(pl); Mockito.verify(legacyDAO).updateCountry(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Assert.assertEquals(pl, returnedCountry); } @@ -656,7 +657,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Mockito.verify(lightblueDAO).getCountry("PL"); Mockito.verify(legacyDAO).getCountry("PL"); - Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Assert.assertEquals(pl, returnedCountry); } @@ -688,7 +689,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Mockito.verify(lightblueDAO).createCountry(pl); Mockito.verify(legacyDAO).createCountry(pl); - Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker, Mockito.never()).checkConsistency(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Assert.assertEquals(pl, returnedCountry); } @@ -895,7 +896,7 @@ public Country answer(InvocationOnMock invocation) throws Throwable { Assert.assertEquals((Long)13l, returned.getId()); // the id pushed into shared store during first, failed call, is cleared, expecting no inconsistency - Mockito.verify(consistencyChecker).checkConsistency(Mockito.eq(new Country(13l, "PL")), Mockito.eq(new Country(13l, "PL")), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(consistencyChecker).checkConsistency(Mockito.eq(new Country(13l, "PL")), Mockito.eq(new Country(13l, "PL")), Mockito.anyString(), Mockito.any(MethodCallStringifier.class)); Mockito.verify(legacyDAO).createCountry(pl); Mockito.verify(legacyDAO).createCountry(ca); diff --git a/facade/src/test/java/com/redhat/lightblue/migrator/facade/MethodCallStringifierTest.java b/facade/src/test/java/com/redhat/lightblue/migrator/facade/methodcallstringifier/MethodCallStringifierTest.java similarity index 64% rename from facade/src/test/java/com/redhat/lightblue/migrator/facade/MethodCallStringifierTest.java rename to facade/src/test/java/com/redhat/lightblue/migrator/facade/methodcallstringifier/MethodCallStringifierTest.java index 25e7c0b..c361505 100644 --- a/facade/src/test/java/com/redhat/lightblue/migrator/facade/MethodCallStringifierTest.java +++ b/facade/src/test/java/com/redhat/lightblue/migrator/facade/methodcallstringifier/MethodCallStringifierTest.java @@ -1,4 +1,4 @@ -package com.redhat.lightblue.migrator.facade; +package com.redhat.lightblue.migrator.facade.methodcallstringifier; import java.lang.reflect.Method; import java.util.ArrayList; @@ -7,6 +7,7 @@ import org.junit.Assert; import org.junit.Test; +import com.redhat.lightblue.migrator.facade.methodcallstringifier.LazyMethodCallStringifier; import com.redhat.lightblue.migrator.facade.model.Country; import com.redhat.lightblue.migrator.facade.proxy.FacadeProxyFactory.Secret; @@ -33,7 +34,7 @@ private Method getMethod(String name, Class ... types) { @Test public void testSimple() { Assert.assertEquals("foo(12, string)", - ServiceFacade.methodCallToString(getMethod("foo", int.class, String.class), new Object[]{12, "string"})); + LazyMethodCallStringifier.stringifyMethodCall(getMethod("foo", int.class, String.class), new Object[]{12, "string"})); } @Test @@ -43,7 +44,7 @@ public void testListOfObjects() { l.add(new Country(2l, "CA")); Assert.assertEquals("foo([PL id=1, CA id=2], 12, string)", - ServiceFacade.methodCallToString(getMethod("foo", List.class, int.class, String.class), new Object[]{l, 12, "string"})); + LazyMethodCallStringifier.stringifyMethodCall(getMethod("foo", List.class, int.class, String.class), new Object[]{l, 12, "string"})); } @Test @@ -53,7 +54,7 @@ public void testListOfPrimitives() { l.add(2l); Assert.assertEquals("foo2([1, 2], 12, string)", - ServiceFacade.methodCallToString(getMethod("foo2", List.class, int.class, String.class), new Object[]{l, 12, "string"})); + LazyMethodCallStringifier.stringifyMethodCall(getMethod("foo2", List.class, int.class, String.class), new Object[]{l, 12, "string"})); } @Test @@ -61,7 +62,7 @@ public void testArrayOfPrimitives() { Long[] arr = new Long[]{1l, 2l}; Assert.assertEquals("foo([1, 2], 12, string)", - ServiceFacade.methodCallToString(getMethod("foo", long[].class, int.class, String.class), new Object[]{arr, 12, "string"})); + LazyMethodCallStringifier.stringifyMethodCall(getMethod("foo", long[].class, int.class, String.class), new Object[]{arr, 12, "string"})); } @Test @@ -69,13 +70,13 @@ public void testArrayOfObjects() { Country[] arr = new Country[]{new Country(1l, "PL"), new Country(2l, "CA")}; Assert.assertEquals("foo([PL id=1, CA id=2], 12, string)", - ServiceFacade.methodCallToString(getMethod("foo", Country[].class, int.class, String.class), new Object[]{arr, 12, "string"})); + LazyMethodCallStringifier.stringifyMethodCall(getMethod("foo", Country[].class, int.class, String.class), new Object[]{arr, 12, "string"})); } @Test public void testSecret() { Assert.assertEquals("foo(login, ****)", - ServiceFacade.methodCallToString(getMethod("foo", String.class, String.class), new Object[]{"login", "password"})); + LazyMethodCallStringifier.stringifyMethodCall(getMethod("foo", String.class, String.class), new Object[]{"login", "password"})); } }