[seam-commits] Seam SVN: r9561 - in trunk/src: test/unit/org/jboss/seam/test/unit and 1 other directory.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Nov 13 22:26:13 EST 2008
Author: dan.j.allen
Date: 2008-11-13 22:26:13 -0500 (Thu, 13 Nov 2008)
New Revision: 9561
Added:
trunk/src/test/unit/org/jboss/seam/test/unit/InvocationControl.java
Modified:
trunk/src/main/org/jboss/seam/core/BijectionInterceptor.java
trunk/src/test/unit/org/jboss/seam/test/unit/FooBar.java
trunk/src/test/unit/org/jboss/seam/test/unit/InterceptorTest.java
Log:
JBSEAM-3652
Also, fixed the bijection reentry test so that it actually tests the injection correctly
Modified: trunk/src/main/org/jboss/seam/core/BijectionInterceptor.java
===================================================================
--- trunk/src/main/org/jboss/seam/core/BijectionInterceptor.java 2008-11-14 00:47:05 UTC (rev 9560)
+++ trunk/src/main/org/jboss/seam/core/BijectionInterceptor.java 2008-11-14 03:26:13 UTC (rev 9561)
@@ -27,7 +27,7 @@
private boolean injecting;
- private int counter = 0;
+ private int clients = 0;
private ReentrantLock lock = new ReentrantLock();
@@ -67,7 +67,7 @@
injected = true;
}
- counter++;
+ clients++;
}
finally
{
@@ -79,9 +79,7 @@
lock.lock();
try
{
- counter--;
-
- if (counter == 0)
+ if (clients == 1)
{
try
{
@@ -93,6 +91,7 @@
if (injected)
{
injected = false;
+ clients--;
component.disinject( invocation.getTarget() );
}
}
@@ -126,9 +125,9 @@
lock.lock();
try
{
- counter--;
+ clients--;
- if (counter == 0)
+ if (clients == 0)
{
injected = false;
component.disinject( invocation.getTarget() );
Modified: trunk/src/test/unit/org/jboss/seam/test/unit/FooBar.java
===================================================================
--- trunk/src/test/unit/org/jboss/seam/test/unit/FooBar.java 2008-11-14 00:47:05 UTC (rev 9560)
+++ trunk/src/test/unit/org/jboss/seam/test/unit/FooBar.java 2008-11-14 03:26:13 UTC (rev 9561)
@@ -1,7 +1,5 @@
package org.jboss.seam.test.unit;
-import java.util.concurrent.CountDownLatch;
-
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
@@ -13,14 +11,12 @@
{
@In Foo foo;
- public Foo delayedGetFoo(CountDownLatch latch)
+ public Foo delayedGetFoo(InvocationControl invocationControl)
{
- try
- {
- latch.await();
- }
- catch (InterruptedException ex) {}
-
+ //System.out.println("enter: " + invocationControl.getName() + " " + foo);
+ invocationControl.init();
+ invocationControl.markStarted();
+ //System.out.println("exit: " + invocationControl.getName() + " " + foo);
return foo;
}
}
Modified: trunk/src/test/unit/org/jboss/seam/test/unit/InterceptorTest.java
===================================================================
--- trunk/src/test/unit/org/jboss/seam/test/unit/InterceptorTest.java 2008-11-14 00:47:05 UTC (rev 9560)
+++ trunk/src/test/unit/org/jboss/seam/test/unit/InterceptorTest.java 2008-11-14 03:26:13 UTC (rev 9561)
@@ -2,7 +2,8 @@
package org.jboss.seam.test.unit;
import java.lang.reflect.Method;
-import java.util.concurrent.CountDownLatch;
+import java.util.HashMap;
+import java.util.Map;
import javax.faces.context.ExternalContext;
import javax.faces.event.PhaseId;
@@ -33,6 +34,8 @@
import org.jboss.seam.mock.MockFacesContext;
import org.jboss.seam.mock.MockServletContext;
import org.jboss.seam.persistence.PersistenceContexts;
+import org.jboss.seam.util.Reflections;
+import org.testng.Assert;
import org.testng.annotations.Test;
public class InterceptorTest
@@ -275,27 +278,38 @@
final BijectionInterceptor bi = new BijectionInterceptor();
bi.setComponent( new Component(FooBar.class, appContext) );
- final Method m = FooBar.class.getMethod("delayedGetFoo", CountDownLatch.class);
+ final Method m = FooBar.class.getMethod("delayedGetFoo", InvocationControl.class);
- final CountDownLatch latchA = new CountDownLatch(1);
- final CountDownLatch latchB = new CountDownLatch(1);
- final CountDownLatch latchC = new CountDownLatch(1);
- final CountDownLatch latchD = new CountDownLatch(1);
+ final InvocationControl invocationAControl = new InvocationControl("A");
+ final InvocationControl invocationBControl = new InvocationControl("B");
+ final InvocationControl invocationCControl = new InvocationControl("C");
+ final Map<String, Foo> invocationResults = new HashMap<String, Foo>();
+
final InvocationContext invocationA = new MockInvocationContext() {
@Override public Object getTarget() { return fooBar; }
@Override public Method getMethod() { return m; }
- @Override public Object[] getParameters() { return new Object[] { latchA }; }
+ @Override public Object[] getParameters() { return new Object[] { invocationAControl }; }
+ @Override public Object proceed() throws Exception { return Reflections.invoke(getMethod(), getTarget(), getParameters()); }
};
final InvocationContext invocationB = new MockInvocationContext() {
@Override public Object getTarget() { return fooBar; }
@Override public Method getMethod() { return m; }
- @Override public Object[] getParameters() { return new Object[] { latchB }; }
- };
+ @Override public Object[] getParameters() { return new Object[] { invocationBControl }; }
+ @Override public Object proceed() throws Exception { return Reflections.invoke(getMethod(), getTarget(), getParameters()); }
+ };
+ final InvocationContext invocationC = new MockInvocationContext() {
+ @Override public Object getTarget() { return fooBar; }
+ @Override public Method getMethod() { return m; }
+ @Override public Object[] getParameters() { return new Object[] { invocationCControl }; }
+ @Override public Object proceed() throws Exception { return Reflections.invoke(getMethod(), getTarget(), getParameters()); }
+ };
+
final WrappedException thread1Exception = new WrappedException();
final WrappedException thread2Exception = new WrappedException();
+ final WrappedException thread3Exception = new WrappedException();
new Thread(new Runnable() {
public void run() {
@@ -306,10 +320,9 @@
FacesLifecycle.resumeConversation(externalContext);
FacesLifecycle.setPhaseId(PhaseId.RENDER_RESPONSE);
- Contexts.getSessionContext().set("foo", foo);
-
+ Contexts.getSessionContext().set("foo", foo);
Foo result = (Foo) bi.aroundInvoke( invocationA );
- assert result == foo;
+ invocationResults.put("A", result);
}
catch (Exception ex)
{
@@ -317,7 +330,7 @@
}
finally
{
- latchC.countDown();
+ invocationAControl.markFinished();
}
}
}).start();
@@ -334,7 +347,7 @@
Contexts.getSessionContext().set("foo", foo);
Foo result = (Foo) bi.aroundInvoke( invocationB );
- assert result == foo;
+ invocationResults.put("B", result);
}
catch (Exception ex)
{
@@ -342,25 +355,51 @@
}
finally
{
- latchD.countDown();
+ invocationBControl.markFinished();
}
}
- }).start();
+ }).start();
- // Allow invocationA to complete
- latchA.countDown();
+ new Thread(new Runnable() {
+ public void run() {
+ try
+ {
+ FacesLifecycle.beginRequest(externalContext);
+ Manager.instance().setCurrentConversationId("1");
+ FacesLifecycle.resumeConversation(externalContext);
+ FacesLifecycle.setPhaseId(PhaseId.RENDER_RESPONSE);
+
+ Contexts.getSessionContext().set("foo", foo);
+
+ Foo result = (Foo) bi.aroundInvoke( invocationC );
+ invocationResults.put("C", result);
+ }
+ catch (Exception ex)
+ {
+ thread3Exception.exception = ex;
+ }
+ finally
+ {
+ invocationCControl.markFinished();
+ }
+ }
+ }).start();
- // Wait for invocationA to finalise
- latchC.await();
+ invocationAControl.start();
+ invocationBControl.start();
+ invocationCControl.start();
- // Allow invocationB to proceed
- latchB.countDown();
+ invocationAControl.finish();
+ invocationBControl.finish();
+ invocationCControl.finish();
- // Wait for invocationB
- latchD.await();
-
if (thread1Exception.exception != null) throw thread1Exception.exception;
if (thread2Exception.exception != null) throw thread2Exception.exception;
+ if (thread3Exception.exception != null) throw thread3Exception.exception;
+
+ Assert.assertEquals(invocationResults.get("A"), foo, "Injected value not accurate at end of method invocation A.");
+ Assert.assertEquals(invocationResults.get("B"), foo, "Injected value not accurate at end of method invocation B.");
+ Assert.assertEquals(invocationResults.get("C"), foo, "Injected value not accurate at end of method invocation C.");
}
@Test
Added: trunk/src/test/unit/org/jboss/seam/test/unit/InvocationControl.java
===================================================================
--- trunk/src/test/unit/org/jboss/seam/test/unit/InvocationControl.java (rev 0)
+++ trunk/src/test/unit/org/jboss/seam/test/unit/InvocationControl.java 2008-11-14 03:26:13 UTC (rev 9561)
@@ -0,0 +1,53 @@
+package org.jboss.seam.test.unit;
+
+import java.util.concurrent.CountDownLatch;
+
+public class InvocationControl
+{
+ private String name;
+ private CountDownLatch start = new CountDownLatch(1);
+ private CountDownLatch started = new CountDownLatch(1);
+ private CountDownLatch finish = new CountDownLatch(1);
+ private CountDownLatch finished = new CountDownLatch(1);
+
+ public InvocationControl(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void init() {
+ await(start);
+ }
+
+ public void start() {
+ start.countDown();
+ await(started);
+ }
+
+ public void markStarted() {
+ started.countDown();
+ await(finish);
+ }
+
+ public void finish() {
+ finish.countDown();
+ await(finished);
+ }
+
+ public void markFinished() {
+ finished.countDown();
+ }
+
+ private void await(CountDownLatch l) {
+ try
+ {
+ l.await();
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+}
\ No newline at end of file
More information about the seam-commits
mailing list