[webbeans-commits] Webbeans SVN: r226 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/contexts and 2 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Mon Nov 3 14:18:33 EST 2008
Author: nickarls
Date: 2008-11-03 14:18:33 -0500 (Mon, 03 Nov 2008)
New Revision: 226
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NormalContextTest.java
Removed:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ProxyMethodHandler.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
Log:
BeanMap backing Map -> ConcurrentHashMap
CopyOnWriteArrayList setter for beans in Manager
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-03 16:30:43 UTC (rev 225)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-03 19:18:33 UTC (rev 226)
@@ -3,6 +3,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -195,6 +196,18 @@
return resolutionManager;
}
+ /**
+ * Wraps a collection of beans into a thread safe list.
+ * Since this overwrites any existing list of beans in the manager,
+ * this should only be done on startup and other controlled situations.
+ *
+ * @param beans The collection of beans to wrap.
+ */
+ public Manager setBeans(Collection<Bean<?>> beans) {
+ this.beans = new CopyOnWriteArrayList<Bean<?>>(beans);
+ return this;
+ }
+
public List<Bean<?>> getBeans()
{
return beans;
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java 2008-11-03 16:30:43 UTC (rev 225)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java 2008-11-03 19:18:33 UTC (rev 226)
@@ -1,7 +1,7 @@
package org.jboss.webbeans.contexts;
import java.lang.annotation.Annotation;
-import java.util.HashMap;
+import java.util.concurrent.ConcurrentHashMap;
import javax.webbeans.manager.Bean;
import javax.webbeans.manager.Context;
@@ -22,10 +22,10 @@
protected class BeanMap extends MapWrapper<Bean<? extends Object>, Object>
{
-
+
public BeanMap()
{
- super(new HashMap<Bean<? extends Object>, Object>());
+ super(new ConcurrentHashMap<Bean<? extends Object>, Object>());
}
@SuppressWarnings("unchecked")
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ProxyMethodHandler.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ProxyMethodHandler.java 2008-11-03 16:30:43 UTC (rev 225)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ProxyMethodHandler.java 2008-11-03 19:18:33 UTC (rev 226)
@@ -2,7 +2,6 @@
import java.io.Serializable;
import java.lang.reflect.Method;
-import java.util.List;
import javassist.util.proxy.MethodHandler;
@@ -26,7 +25,6 @@
ProxyMethodHandler.manager = manager;
}
- //@Override Let's stay compatible with JDK5 :-)
public Object invoke(Object self, Method method, Method proceed, Object[] args) throws Throwable
{
if (bean == null)
Deleted: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java 2008-11-03 16:30:43 UTC (rev 225)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java 2008-11-03 19:18:33 UTC (rev 226)
@@ -1,86 +0,0 @@
-package org.jboss.webbeans.test;
-
-import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;
-
-import java.lang.reflect.Method;
-
-import javax.webbeans.ContextNotActiveException;
-import javax.webbeans.manager.Bean;
-import javax.webbeans.manager.Context;
-
-import org.jboss.webbeans.contexts.AbstractContext;
-import org.jboss.webbeans.contexts.RequestContext;
-import org.jboss.webbeans.introspector.SimpleAnnotatedMethod;
-import org.jboss.webbeans.introspector.SimpleAnnotatedType;
-import org.jboss.webbeans.model.bean.ProducerMethodBeanModel;
-import org.jboss.webbeans.model.bean.SimpleBeanModel;
-import org.jboss.webbeans.test.beans.SpiderProducer;
-import org.jboss.webbeans.test.beans.Tarantula;
-import org.jboss.webbeans.test.beans.Tuna;
-import org.jboss.webbeans.test.util.Util;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- *
- * @author Nicklas Karlsson (nickarls at gmail.com)
- * @author Pete Muir
- *
- * This class tests a basic context against section 8 of the specification
- *
- */
- at SpecVersion("PDR")
-public class CommonContextTest extends AbstractTest
-{
- Context context;
-
- @BeforeMethod
- public void initContext() {
- context = new RequestContext();
- }
-
- @Test(groups="contexts") @SpecAssertion(section="8.1")
- public void testGetWithCreateFalseReturnsNull() {
- Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
- assert context.get(tunaBean, false) == null;
- }
-
- @Test(groups="contexts") @SpecAssertion(section="8.1")
- public void testGetWithCreateTrueReturnsBean() {
- Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
- assert context.get(tunaBean, true) != null;
- }
-
- @Test(groups="contexts", expectedExceptions=ContextNotActiveException.class) @SpecAssertion(section="8.1")
- public void testInactiveContextThrowsContextNotActiveException() {
- ((AbstractContext)context).setActive(false);
- context.get(null, false);
- assert true;
- }
-
- @Test(groups="contexts") @SpecAssertion(section="8.1")
- public void testReturnsCorrectExistingBean() {
- Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
- Tuna firstTuna = context.get(tunaBean, true);
- Tuna secondTuna = context.get(tunaBean, false);
- assert firstTuna == secondTuna;
- }
-
- @Test(groups={"contexts", "producerMethod"}) @SpecAssertion(section="8.1")
- public void testProducerMethodReturningNullOK() throws SecurityException, NoSuchMethodException {
- SimpleBeanModel<SpiderProducer> producer = new SimpleBeanModel<SpiderProducer>(new SimpleAnnotatedType<SpiderProducer>(SpiderProducer.class), getEmptyAnnotatedType(SpiderProducer.class), manager);
- manager.getModelManager().addBeanModel(producer);
- Method nullProducer = SpiderProducer.class.getMethod("produceShelob");
- ProducerMethodBeanModel<Tarantula> producerModel = new ProducerMethodBeanModel<Tarantula>(new SimpleAnnotatedMethod<Tarantula>(nullProducer), manager);
- //Bean<Tarantula> shelobBean = new ProducerBeanImpl<Tarantula>(producerModel, manager);
- //assert context.get(shelobBean, true) == null;
- }
-
- @Test(groups="contexts")
- public void testDestroy() {
- Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
- assert context.get(tunaBean, true) instanceof Tuna;
- ((AbstractContext)context).destroy(manager);
- assert context.get(tunaBean, false) == null;
- }
-}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java 2008-11-03 16:30:43 UTC (rev 225)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java 2008-11-03 19:18:33 UTC (rev 226)
@@ -60,7 +60,14 @@
{
assert false;
}
-
+
+ @Test(groups="manager")
+ public void testWrappingOfBeanCollection()
+ {
+ // TODO stub
+ assert false;
+ }
+
/*
@Test(groups="manager") @SpecAssertion(section="4.8")
Copied: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NormalContextTest.java (from rev 214, ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java)
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NormalContextTest.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NormalContextTest.java 2008-11-03 19:18:33 UTC (rev 226)
@@ -0,0 +1,93 @@
+package org.jboss.webbeans.test;
+
+import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;
+
+import java.lang.reflect.Method;
+
+import javax.webbeans.ContextNotActiveException;
+import javax.webbeans.manager.Bean;
+import javax.webbeans.manager.Context;
+
+import org.jboss.webbeans.contexts.AbstractContext;
+import org.jboss.webbeans.contexts.RequestContext;
+import org.jboss.webbeans.introspector.SimpleAnnotatedMethod;
+import org.jboss.webbeans.introspector.SimpleAnnotatedType;
+import org.jboss.webbeans.model.bean.ProducerMethodBeanModel;
+import org.jboss.webbeans.model.bean.SimpleBeanModel;
+import org.jboss.webbeans.test.beans.SpiderProducer;
+import org.jboss.webbeans.test.beans.Tarantula;
+import org.jboss.webbeans.test.beans.Tuna;
+import org.jboss.webbeans.test.util.Util;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ *
+ * @author Nicklas Karlsson (nickarls at gmail.com)
+ * @author Pete Muir
+ *
+ * This class tests a basic context against section 8 of the specification
+ *
+ */
+ at SpecVersion("PDR")
+public class NormalContextTest extends AbstractTest
+{
+ Context context;
+
+ @BeforeMethod
+ public void initContext() {
+ context = new RequestContext();
+ }
+
+ @Test(groups="contexts") @SpecAssertion(section="8.1")
+ public void testGetWithCreateFalseReturnsNull() {
+ Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
+ assert context.get(tunaBean, false) == null;
+ }
+
+ @Test(groups="contexts") @SpecAssertion(section="8.1")
+ public void testGetWithCreateTrueReturnsBean() {
+ Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
+ assert context.get(tunaBean, true) != null;
+ }
+
+ @Test(groups="contexts", expectedExceptions=ContextNotActiveException.class) @SpecAssertion(section="8.1")
+ public void testInactiveContextThrowsContextNotActiveException() {
+ ((AbstractContext)context).setActive(false);
+ context.get(null, false);
+ assert true;
+ }
+
+ @Test(groups="contexts") @SpecAssertion(section="8.1")
+ public void testReturnsCorrectExistingBean() {
+ Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
+ Tuna firstTuna = context.get(tunaBean, true);
+ Tuna secondTuna = context.get(tunaBean, false);
+ assert firstTuna == secondTuna;
+ }
+
+ @Test(groups={"contexts", "producerMethod"}) @SpecAssertion(section="8.1")
+ public void testProducerMethodReturningNullOK() throws SecurityException, NoSuchMethodException {
+ SimpleBeanModel<SpiderProducer> producer = new SimpleBeanModel<SpiderProducer>(new SimpleAnnotatedType<SpiderProducer>(SpiderProducer.class), getEmptyAnnotatedType(SpiderProducer.class), manager);
+ manager.getModelManager().addBeanModel(producer);
+ Method nullProducer = SpiderProducer.class.getMethod("produceShelob");
+ ProducerMethodBeanModel<Tarantula> producerModel = new ProducerMethodBeanModel<Tarantula>(new SimpleAnnotatedMethod<Tarantula>(nullProducer), manager);
+ //Bean<Tarantula> shelobBean = new ProducerBeanImpl<Tarantula>(producerModel, manager);
+ //assert context.get(shelobBean, true) == null;
+ }
+
+ @Test(groups="contexts")
+ public void testDestroy() {
+ Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
+ assert context.get(tunaBean, true) instanceof Tuna;
+ ((AbstractContext)context).destroy(manager);
+ assert context.get(tunaBean, false) == null;
+ }
+
+ @Test(groups="contexts")
+ public void testThreadSafety() {
+ //TODO stub
+ assert false;
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NormalContextTest.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java 2008-11-03 16:30:43 UTC (rev 225)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java 2008-11-03 19:18:33 UTC (rev 226)
@@ -3,7 +3,6 @@
import static org.jboss.webbeans.test.util.Util.createSimpleWebBean;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
import java.util.Set;
More information about the weld-commits
mailing list