You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/09/24 06:52:02 UTC
svn commit: r1175104 - in /tapestry/tapestry5/trunk/tapestry-ioc/src:
main/java/org/apache/tapestry5/ioc/internal/
main/java/org/apache/tapestry5/ioc/internal/util/
main/resources/org/apache/tapestry5/ioc/internal/
test/java/org/apache/tapestry5/ioc/ t...
Author: hlship
Date: Sat Sep 24 04:52:01 2011
New Revision: 1175104
URL: http://svn.apache.org/viewvc?rev=1175104&view=rev
Log:
TAP5-1665: Tapestry could create non-singleton services more efficiently
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/MethodInvoker.java
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AbstractMethodInvokingInstrumenter.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvoker.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvokerTest.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ServiceDecoratorImplTest.java
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AbstractMethodInvokingInstrumenter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AbstractMethodInvokingInstrumenter.java?rev=1175104&r1=1175103&r2=1175104&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AbstractMethodInvokingInstrumenter.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AbstractMethodInvokingInstrumenter.java Sat Sep 24 04:52:01 2011
@@ -21,12 +21,11 @@ import org.apache.tapestry5.ioc.internal
import org.apache.tapestry5.ioc.services.PlasticProxyFactory;
import org.slf4j.Logger;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
/**
- * Based class for service decorators and service advisors that work by invoking a module method.
+ * Base class for service decorators and service advisors that work by invoking a module method.
*
* @since 5.1.0.0
*/
@@ -83,43 +82,10 @@ public class AbstractMethodInvokingInstr
protected Object invoke(final InjectionResources injectionResources)
{
- final String methodId = toString();
+ String description = String.format("Invoking method %s", toString());
- String description = String.format("Invoking method %s", methodId);
-
- if (logger.isDebugEnabled())
- {
- logger.debug(description);
- }
-
- return resources.getTracker().invoke(description, new Invokable<Object>()
- {
- public Object invoke()
- {
- Object result = null;
- Throwable failure = null;
-
- try
- {
- Object[] parameters = InternalUtils.calculateParametersForMethod(method, resources,
- injectionResources, resources.getTracker());
-
- result = method.invoke(getModuleInstance(), parameters);
- } catch (InvocationTargetException ite)
- {
- failure = ite.getTargetException();
- } catch (Exception ex)
- {
- failure = ex;
- }
-
- if (failure != null)
- throw new RuntimeException(String.format("Exception invoking method %s: %s", methodId,
- InternalUtils.toMessage(failure)), failure);
-
- return result;
- }
- });
+ ObjectCreator<Object> plan = InternalUtils.createMethodInvocationPlan(resources.getTracker(), resources, injectionResources, logger, description, getModuleInstance(), method);
+ return plan.createObject();
}
}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java?rev=1175104&r1=1175103&r2=1175104&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java Sat Sep 24 04:52:01 2011
@@ -66,16 +66,6 @@ final class IOCMessages
return MESSAGES.format("instantiate-builder-error", builderClass.getName(), cause);
}
- static String builderMethodError(String methodId, String serviceId, Throwable cause)
- {
- return MESSAGES.format("builder-method-error", methodId, serviceId, cause);
- }
-
- static String builderMethodReturnedNull(String methodId, String serviceId)
- {
- return MESSAGES.format("builder-method-returned-null", methodId, serviceId);
- }
-
static String noServiceMatchesType(Class serviceInterface)
{
return MESSAGES.format("no-service-matches-type", serviceInterface.getName());
@@ -106,16 +96,6 @@ final class IOCMessages
serviceInterface.getName());
}
- static String invokingMethod(String methodId)
- {
- return MESSAGES.format("invoking-method", methodId);
- }
-
- static String invokingConstructor(String creatorDescription)
- {
- return MESSAGES.format("invoking-constructor", creatorDescription);
- }
-
static String invokingMethod(ContributionDef def)
{
// The toString() of a contribution def is the name of the method.
@@ -241,11 +221,6 @@ final class IOCMessages
return MESSAGES.format("no-autobuild-constructor", clazz.getName());
}
- static String autobuildConstructorError(String constructorDescription, Throwable cause)
- {
- return MESSAGES.format("autobuild-constructor-error", constructorDescription, cause);
- }
-
private static String toJavaClassNames(List<Class> classes)
{
List<String> names = CollectionFactory.newList();
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java?rev=1175104&r1=1175103&r2=1175104&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java Sat Sep 24 04:52:01 2011
@@ -284,7 +284,7 @@ public class ModuleImpl implements Modul
return creator.createObject();
}
- creator = new OperationTrackingObjectCreator(registry, String.format("Realizing service %s via %s", serviceId, creator), creator);
+ creator = new OperationTrackingObjectCreator(registry, String.format("Instantiating service %s implementation via %s", serviceId, creator), creator);
creator = new LifecycleWrappedServiceCreator(lifecycle, resources, creator);
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvoker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvoker.java?rev=1175104&r1=1175103&r2=1175104&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvoker.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvoker.java Sat Sep 24 04:52:01 2011
@@ -14,12 +14,10 @@
package org.apache.tapestry5.ioc.internal;
-import org.apache.tapestry5.ioc.Invokable;
-import org.apache.tapestry5.ioc.OperationTracker;
+import org.apache.tapestry5.ioc.ObjectCreator;
import org.apache.tapestry5.ioc.ServiceBuilderResources;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
@@ -37,55 +35,36 @@ public class ServiceBuilderMethodInvoker
builderMethod = method;
}
+ private ObjectCreator<Object> plan;
+
+ private synchronized ObjectCreator<Object> getPlan()
+ {
+ if (plan == null)
+ {
+ // Defer getting (and possibly instantiating) the module instance until the last possible
+ // moment. If the method is static, there's no need to even get the builder.
+
+ final Object moduleInstance = InternalUtils.isStatic(builderMethod) ? null : resources.getModuleBuilder();
+
+ plan = InternalUtils.createMethodInvocationPlan(resources.getTracker(), resources, createInjectionResources(), logger, "Constructing service implementation via " + creatorDescription, moduleInstance, builderMethod);
+ }
+
+ return plan;
+ }
+
/**
* Invoked from the proxy to create the actual service implementation.
*/
public Object createObject()
{
- // Defer getting (and possibly instantiating) the module instance until the last possible
- // moment. If the method is static, there's no need to even get the builder.
-
- final Object moduleInstance = InternalUtils.isStatic(builderMethod) ? null : resources.getModuleBuilder();
+ Object result = getPlan().createObject();
- final OperationTracker tracker = resources.getTracker();
-
- return tracker.invoke(String.format("Constructing service implementation via " + creatorDescription), new Invokable<Object>()
+ if (result == null)
{
- public Object invoke()
- {
- final OperationTracker tracker = resources.getTracker();
- Object result = null;
- Throwable failure = null;
-
- try
- {
- Object[] parameters = InternalUtils.calculateParametersForMethod(builderMethod, resources,
- createInjectionResources(), tracker);
-
- if (logger.isDebugEnabled())
- logger.debug(IOCMessages.invokingMethod(creatorDescription));
-
- result = builderMethod.invoke(moduleInstance, parameters);
- }
- catch (InvocationTargetException ite)
- {
- failure = ite.getTargetException();
- }
- catch (Exception ex)
- {
- failure = ex;
- }
-
- if (failure != null)
- throw new RuntimeException(IOCMessages.builderMethodError(creatorDescription, serviceId, failure),
- failure);
-
- if (result == null)
- throw new RuntimeException(IOCMessages.builderMethodReturnedNull(creatorDescription, serviceId));
-
- return result;
- }
- });
+ throw new RuntimeException(String.format("Builder method %s (for service '%s') returned null.", creatorDescription, serviceId));
+ }
+
+ return result;
}
@Override
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java?rev=1175104&r1=1175103&r2=1175104&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java Sat Sep 24 04:52:01 2011
@@ -243,14 +243,6 @@ public class InternalUtils
method.getParameterAnnotations(), tracker);
}
- public static Object[] calculateParametersForConstructor(Constructor constructor, ObjectLocator locator,
- InjectionResources resources, OperationTracker tracker)
- {
-
- return calculateParameters(locator, resources, constructor.getParameterTypes(),
- constructor.getGenericParameterTypes(), constructor.getParameterAnnotations(), tracker);
- }
-
public static Object[] calculateParameters(final ObjectLocator locator, final InjectionResources resources,
Class[] parameterTypes, final Type[] genericTypes, Annotation[][] parameterAnnotations,
OperationTracker tracker)
@@ -373,44 +365,6 @@ public class InternalUtils
}
}
- public static void invokePostInjectionMethods(final Object object, final ObjectLocator locator,
- final InjectionResources injectionResources, final OperationTracker tracker)
- {
- for (final Method m : object.getClass().getMethods())
- {
- if (m.getAnnotation(PostInjection.class) == null)
- continue;
-
- String description = String.format("Invoking post-inject method %s", m);
-
- tracker.run(description, new Runnable()
- {
- public void run()
- {
- Throwable fail = null;
-
- try
- {
- Object[] parameters = InternalUtils.calculateParametersForMethod(m, locator,
- injectionResources, tracker);
-
- m.invoke(object, parameters);
- } catch (InvocationTargetException ex)
- {
- fail = ex.getTargetException();
- } catch (Exception ex)
- {
- fail = ex;
- }
-
- if (fail != null)
- throw new RuntimeException(String
- .format("Exception invoking method %s: %s", m, toMessage(fail)), fail);
- }
- });
- }
- }
-
private synchronized static void inject(Object target, Field field, Object value)
{
try
@@ -1615,4 +1569,28 @@ public class InternalUtils
});
}
+
+ public static <T> ObjectCreator<T> createMethodInvocationPlan(final OperationTracker tracker, final ObjectLocator locator,
+ final InjectionResources resources,
+ final Logger logger,
+ final String description,
+ final Object instance,
+ final Method method)
+ {
+
+ return tracker.invoke("Creating plan to invoke " + method, new Invokable<ObjectCreator<T>>()
+ {
+ public ObjectCreator<T> invoke()
+ {
+ Object[] methodParameters = calculateParametersForMethod(method, locator, resources, tracker);
+
+ Invokable<T> core = new MethodInvoker<T>(instance, method, methodParameters);
+
+ Invokable<T> wrapped = logger == null ? core : new LoggingInvokableWrapper<T>(logger, description, core);
+
+ return new ConstructionPlan(tracker, description, wrapped);
+ }
+ });
+ }
+
}
Added: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/MethodInvoker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/MethodInvoker.java?rev=1175104&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/MethodInvoker.java (added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/MethodInvoker.java Sat Sep 24 04:52:01 2011
@@ -0,0 +1,61 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+
+package org.apache.tapestry5.ioc.internal.util;
+
+import org.apache.tapestry5.ioc.Invokable;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * @since 5.3
+ */
+public class MethodInvoker<T> implements Invokable<T>
+{
+ private final Object instance;
+
+ private final Method method;
+
+ private final Object[] methodParameters;
+
+ public MethodInvoker(Object instance, Method method, Object[] methodParameters)
+ {
+ this.instance = instance;
+ this.method = method;
+ this.methodParameters = methodParameters;
+ }
+
+ public T invoke()
+ {
+ Throwable fail;
+
+ try
+ {
+ Object result = method.invoke(instance, methodParameters);
+
+ return (T) result;
+ } catch (InvocationTargetException ex)
+ {
+ fail = ex.getTargetException();
+ } catch (Exception ex)
+ {
+ fail = ex;
+ }
+
+ throw new RuntimeException(String.format("Error invoking method %s: %s",
+ method, InternalUtils.toMessage(fail)), fail);
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties?rev=1175104&r1=1175103&r2=1175104&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties Sat Sep 24 04:52:01 2011
@@ -19,8 +19,6 @@ decorator-method-wrong-return-type=Metho
but the return type (%s) is not acceptable (try Object).
service-wrong-interface=Service '%s' implements interface %s, which is not compatible with the requested type %s.
instantiate-builder-error=Unable to instantiate class %s as a module: %s
-builder-method-error=Error invoking service builder method %s (for service '%s'): %s
-builder-method-returned-null=Builder method %s (for service '%s') returned null.
no-service-matches-type=No service implements the interface %s.
many-service-matches=Service interface %s is matched by %d services: %s. \
Automatic dependency resolution requires that exactly one service implement the interface.
@@ -30,8 +28,6 @@ many-services-match-marker=Unable to loc
unknown-scope=Unknown service scope '%s'.
decorator-returned-wrong-type=Decorator method %s (invoked for service '%s') returned %s, \
which is not assignable to the %s service interface.
-invoking-method=Invoking method %s.
-invoking-constructor=Invoking constructor %s.
recursive-service-build=Construction of service '%s' has failed due to recursion: \
the service depends on itself in some way. \
Please check %s for references to another service that is itself dependent on service '%1$s'.
@@ -69,7 +65,6 @@ no-constructor=Class %s (implementation
bind-method-must-be-static=Method %s appears to be a service binder method, but is an instance method, not a static method.
error-in-bind-method=Error invoking service binder method %s: %s
no-autobuild-constructor=Class %s does not contain a public constructor needed to autobuild.
-autobuild-constructor-error=Error invoking constructor %s: %s
overlapping-service-proxy-providers=Setting a new service proxy provider when there's already an existing provider. This may indicate that you have multiple IoC Registries.
unexpected-service-proxy-provider=Unexpected service proxy provider when clearing the provider. This may indicate that you have multiple IoC Registries.
no-proxy-provider=Service token for service '%s' can not be converted back into a proxy because no proxy provider has been registered. This may indicate that an IoC Registry has not been started yet.
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java?rev=1175104&r1=1175103&r2=1175104&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java Sat Sep 24 04:52:01 2011
@@ -542,10 +542,6 @@ public class IntegrationTest extends IOC
{
assertMessageContains(ex,
"Class org.apache.tapestry5.ioc.UnbuildablePingable does not contain a public constructor needed to autobuild.");
-
- // Like to check that the message includes the source location
-
- assertTrue(ex.getMessage().matches(".*\\(at ServiceBuilderAutobuilderModule.java:\\d+\\).*"));
}
r.shutdown();
@@ -716,7 +712,6 @@ public class IntegrationTest extends IOC
{
assertMessageContains(
ex,
- "Error invoking service builder method",
"Unable to locate a single service assignable to type org.apache.tapestry5.ioc.Greeter with marker annotation(s) org.apache.tapestry5.ioc.RedMarker",
"org.apache.tapestry5.ioc.GreeterModule.buildRedGreeter1()",
"org.apache.tapestry5.ioc.GreeterModule.buildRedGreeter2()");
@@ -740,8 +735,8 @@ public class IntegrationTest extends IOC
{
assertMessageContains(
ex,
- "Error invoking service builder method",
- " Unable to locate any service assignable to type org.apache.tapestry5.ioc.Greeter with marker annotation(s) org.apache.tapestry5.ioc.YellowMarker.");
+ "Exception constructing service",
+ "Unable to locate any service assignable to type org.apache.tapestry5.ioc.Greeter with marker annotation(s) org.apache.tapestry5.ioc.YellowMarker.");
}
r.shutdown();
@@ -1310,8 +1305,6 @@ public class IntegrationTest extends IOC
{
assertMessageContains(
ex,
- "Exception constructing service 'StringLookup'",
- "Error invoking service builder method org.apache.tapestry5.ioc.FredModule.buildStringLookup(Map) ",
"Override for key alley cat (at org.apache.tapestry5.ioc.util.NonmatchingMappedConfigurationOverrideModule.contributeStringLookup(MappedConfiguration)",
"does not match an existing key.");
}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvokerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvokerTest.java?rev=1175104&r1=1175103&r2=1175104&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvokerTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvokerTest.java Sat Sep 24 04:52:01 2011
@@ -18,9 +18,7 @@ import org.apache.tapestry5.ioc.Annotati
import org.apache.tapestry5.ioc.ObjectCreator;
import org.apache.tapestry5.ioc.OperationTracker;
import org.apache.tapestry5.ioc.ServiceBuilderResources;
-import static org.apache.tapestry5.ioc.internal.AbstractServiceCreator.findParameterizedTypeFromGenericType;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.isA;
+import org.easymock.EasyMock;
import org.slf4j.Logger;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -30,6 +28,10 @@ import java.lang.reflect.Type;
import java.util.Collection;
import java.util.List;
+import static org.apache.tapestry5.ioc.internal.AbstractServiceCreator.findParameterizedTypeFromGenericType;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.isA;
+
public class ServiceBuilderMethodInvokerTest extends IOCInternalTestCase
{
private static final String SERVICE_ID = "Fie";
@@ -38,6 +40,11 @@ public class ServiceBuilderMethodInvoker
private final OperationTracker tracker = new QuietOperationTracker();
+ private void ignoreDebug(Logger logger)
+ {
+ logger.debug(EasyMock.anyObject(String.class));
+ }
+
@Test
public void noargs_method()
{
@@ -51,7 +58,7 @@ public class ServiceBuilderMethodInvoker
train_getModuleBuilder(resources, fixture);
- train_isDebugEnabled(logger, false);
+ ignoreDebug(logger);
replay();
@@ -93,9 +100,7 @@ public class ServiceBuilderMethodInvoker
train_getModuleBuilder(resources, fixture);
- train_isDebugEnabled(logger, true);
-
- logger.debug(IOCMessages.invokingMethod(CREATOR_DESCRIPTION));
+ ignoreDebug(logger);
replay();
@@ -125,9 +130,7 @@ public class ServiceBuilderMethodInvoker
train_getModuleBuilder(resources, fixture);
- train_isDebugEnabled(logger, true);
-
- logger.debug(IOCMessages.invokingMethod(CREATOR_DESCRIPTION));
+ ignoreDebug(logger);
// This simulates what the real stack does when it sees @Value("Injected")
@@ -160,7 +163,7 @@ public class ServiceBuilderMethodInvoker
train_getService(resources, "Foe", FoeService.class, fixture.expectedFoe);
- train_isDebugEnabled(logger, false);
+ ignoreDebug(logger);
replay();
@@ -173,7 +176,7 @@ public class ServiceBuilderMethodInvoker
verify();
}
-
+
@Test
public void named_injected_service_method()
{
@@ -190,7 +193,7 @@ public class ServiceBuilderMethodInvoker
train_getService(resources, "Foe", FoeService.class, fixture.expectedFoe);
- train_isDebugEnabled(logger, false);
+ ignoreDebug(logger);
replay();
@@ -222,7 +225,7 @@ public class ServiceBuilderMethodInvoker
expect(resources.getOrderedConfiguration(Runnable.class)).andReturn(result);
- train_isDebugEnabled(logger, false);
+ ignoreDebug(logger);
replay();
@@ -254,7 +257,7 @@ public class ServiceBuilderMethodInvoker
expect(resources.getUnorderedConfiguration(Runnable.class)).andReturn(result);
- train_isDebugEnabled(logger, false);
+ ignoreDebug(logger);
replay();
@@ -286,7 +289,7 @@ public class ServiceBuilderMethodInvoker
train_getModuleBuilder(resources, fixture);
- train_isDebugEnabled(logger, false);
+ ignoreDebug(logger);
replay();
@@ -296,8 +299,7 @@ public class ServiceBuilderMethodInvoker
{
sc.createObject();
unreachable();
- }
- catch (RuntimeException ex)
+ } catch (RuntimeException ex)
{
Assert.assertEquals(ex.getMessage(), "Builder method " + CREATOR_DESCRIPTION
+ " (for service 'Fie') returned null.");
@@ -319,7 +321,7 @@ public class ServiceBuilderMethodInvoker
train_getModuleBuilder(resources, fixture);
- train_isDebugEnabled(logger, false);
+ ignoreDebug(logger);
replay();
@@ -329,11 +331,9 @@ public class ServiceBuilderMethodInvoker
{
sc.createObject();
unreachable();
- }
- catch (RuntimeException ex)
+ } catch (RuntimeException ex)
{
- assertEquals(ex.getMessage(), "Error invoking service builder method " + CREATOR_DESCRIPTION
- + " (for service 'Fie'): Method failed.");
+ assertMessageContains(ex, "build_fail()", "Method failed.");
Throwable cause = ex.getCause();
@@ -361,7 +361,7 @@ public class ServiceBuilderMethodInvoker
expect(resources.getObject(eq(FoeService.class), isA(AnnotationProvider.class))).andReturn(fixture.expectedFoe);
- train_isDebugEnabled(logger, false);
+ ignoreDebug(logger);
replay();
@@ -415,8 +415,7 @@ public class ServiceBuilderMethodInvoker
{
findParameterizedTypeFromGenericType(type);
unreachable();
- }
- catch (IllegalArgumentException ex)
+ } catch (IllegalArgumentException ex)
{
assertEquals(ex.getMessage(), IOCMessages.genericTypeNotSupported(type));
}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ServiceDecoratorImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ServiceDecoratorImplTest.java?rev=1175104&r1=1175103&r2=1175104&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ServiceDecoratorImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ServiceDecoratorImplTest.java Sat Sep 24 04:52:01 2011
@@ -42,7 +42,7 @@ public class ServiceDecoratorImplTest ex
/**
* Also, test logging of decorator method invocation.
- *
+ *
* @throws Exception
*/
@Test
@@ -59,8 +59,6 @@ public class ServiceDecoratorImplTest ex
trainForConstructor(resources, logger);
- train_isDebugEnabled(logger, true);
-
logger.debug(EasyMock
.contains("Invoking method org.apache.tapestry5.ioc.internal.ServiceDecoratorFixture.decoratorReturnsInterceptor(Class, Object)"));
@@ -89,7 +87,7 @@ public class ServiceDecoratorImplTest ex
trainForConstructor(resources, logger);
- train_isDebugEnabled(logger, false);
+ logger.debug(EasyMock.anyObject(String.class));
replay();
@@ -118,7 +116,7 @@ public class ServiceDecoratorImplTest ex
trainForConstructor(resources, logger);
- train_isDebugEnabled(logger, false);
+ logger.debug(EasyMock.anyObject(String.class));
replay();
@@ -128,8 +126,7 @@ public class ServiceDecoratorImplTest ex
{
decorator.createInterceptor(fixture.expectedDelegate);
unreachable();
- }
- catch (RuntimeException ex)
+ } catch (RuntimeException ex)
{
assertMessageContains(
ex,
@@ -153,7 +150,7 @@ public class ServiceDecoratorImplTest ex
trainForConstructor(resources, logger);
- train_isDebugEnabled(logger, false);
+ logger.debug(EasyMock.anyObject(String.class));
replay();
@@ -165,12 +162,12 @@ public class ServiceDecoratorImplTest ex
{
decorator.createInterceptor(delegate);
unreachable();
- }
- catch (RuntimeException ex)
+ } catch (RuntimeException ex)
{
assertMessageContains(
ex,
- "Exception invoking method org.apache.tapestry5.ioc.internal.ServiceDecoratorFixture.decoratorThrowsException(Object)",
+ "Error invoking",
+ "org.apache.tapestry5.ioc.internal.ServiceDecoratorFixture.decoratorThrowsException(java.lang.Object)",
"Ouch!");
Throwable cause = ex.getCause();