[seam-commits] Seam SVN: r12001 - in branches/enterprise/JBPAPP_5_0/src: test/integration/src/org/jboss/seam/test/integration and 1 other directory.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon Feb 1 11:33:41 EST 2010
Author: oskutka at redhat.com
Date: 2010-02-01 11:33:40 -0500 (Mon, 01 Feb 2010)
New Revision: 12001
Added:
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/ConcurrentFactoryTest.java
Modified:
branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/Component.java
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/testng.xml
Log:
JBSEAM-2419 IAE: factory method with defined scope outjected a value: guestRole
Modified: branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/Component.java
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/Component.java 2010-02-01 09:46:43 UTC (rev 12000)
+++ branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/Component.java 2010-02-01 16:33:40 UTC (rev 12001)
@@ -1980,7 +1980,7 @@
public static Object getInstance(String name, boolean create, boolean allowAutocreation)
{
Object result = Contexts.lookupInStatefulContexts(name);
- result = getInstance(name, create, allowAutocreation, result);
+ result = getInstance(name, create, allowAutocreation, result, null);
return result;
}
@@ -1997,18 +1997,18 @@
public static Object getInstance(String name, ScopeType scope, boolean create, boolean allowAutocreation)
{
Object result = scope==STATELESS ? null : scope.getContext().get(name);
- result = getInstance(name, create, allowAutocreation, result);
+ result = getInstance(name, create, allowAutocreation, result, scope);
return result;
}
- private static Object getInstance(String name, boolean create, boolean allowAutoCreation, Object result) {
+ private static Object getInstance(String name, boolean create, boolean allowAutoCreation, Object result, ScopeType scope) {
Component component = Component.forName(name);
create = create || (Init.instance().isAutocreateVariable(name) && allowAutoCreation);
if (result==null && create)
{
- result = getInstanceFromFactory(name);
+ result = getInstanceFromFactory(name, scope);
if (result==null)
{
if (component==null)
@@ -2046,7 +2046,12 @@
}
- public static Object getInstanceFromFactory(String name)
+ public static Object getInstanceFromFactory(String name) {
+ return getInstanceFromFactory(name, null);
+ }
+
+
+ private static synchronized Object getInstanceFromFactory(String name, ScopeType scope)
{
Init init = Init.instance();
if (init==null) //for unit tests, yew!
@@ -2055,6 +2060,14 @@
}
else
{
+ // check whether there has been created an instance by another thread while waiting for this function's lock
+ if (scope != STATELESS) {
+ Object value = (scope == null) ? Contexts.lookupInStatefulContexts(name) : scope.getContext().get(name);
+ if (value != null) {
+ return value;
+ }
+ }
+
Init.FactoryMethod factoryMethod = init.getFactory(name);
Init.FactoryExpression methodBinding = init.getFactoryMethodExpression(name);
Init.FactoryExpression valueBinding = init.getFactoryValueExpression(name);
Added: branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/ConcurrentFactoryTest.java
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/ConcurrentFactoryTest.java (rev 0)
+++ branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/ConcurrentFactoryTest.java 2010-02-01 16:33:40 UTC (rev 12001)
@@ -0,0 +1,78 @@
+package org.jboss.seam.test.integration;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Factory;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.contexts.ServletLifecycle;
+import org.jboss.seam.core.Init;
+import org.jboss.seam.mock.SeamTest;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+import static org.jboss.seam.ScopeType.APPLICATION;
+
+public class ConcurrentFactoryTest
+ extends SeamTest
+{
+ @Override
+ protected void startJbossEmbeddedIfNecessary()
+ throws org.jboss.deployers.spi.DeploymentException,
+ java.io.IOException
+ {
+ // don't deploy
+ }
+
+ @Test(threadPoolSize = 2, invocationCount = 2)
+ public void concurrentFactoryCall()
+ throws Exception
+ {
+ new ComponentTest() {
+ @Override
+ protected void testComponents() throws Exception {
+ assert "slowly created String".equals(getValue("#{concurrentFactoryTest.component.injectedString}"));
+ }
+ }.run();
+ }
+
+ @AfterMethod
+ @Override
+ public void end()
+ {
+ if (session != null) {
+ // Because we run in threads. Only the first thread that finishes ends the session.
+ ServletLifecycle.endSession(session);
+ }
+ session = null;
+ }
+
+ @Name("concurrentFactoryTest.component")
+ static public class Component {
+ @In(value = "concurrentFactoryTest.slowlyCreatedString") String injectedString;
+
+ public String getInjectedString() {
+ return injectedString;
+ }
+ }
+
+ @Name("concurrentFactoryTest.SlowFactory")
+ static public class SlowFactory {
+ @Factory(value = "concurrentFactoryTest.slowlyCreatedString", scope = APPLICATION, autoCreate = true)
+ public String slowlyCreateString() {
+ try
+ {
+ Thread.sleep(1000);
+ return "slowly created String";
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ }
+
+
+
+}
Modified: branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/testng.xml
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/testng.xml 2010-02-01 09:46:43 UTC (rev 12000)
+++ branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/testng.xml 2010-02-01 16:33:40 UTC (rev 12001)
@@ -9,6 +9,7 @@
<class name="org.jboss.seam.test.integration.NamespaceTest" />
<class name="org.jboss.seam.test.integration.JavaBeanEqualsTest" />
<class name="org.jboss.seam.test.integration.NamespaceResolverTest" />
+ <class name="org.jboss.seam.test.integration.ConcurrentFactoryTest" />
</classes>
</test>
<test name="Seam Integration Tests - Persistence">
More information about the seam-commits
mailing list