[weld-commits] Weld SVN: r6082 - in core/trunk: impl/src/main/java/org/jboss/weld/servlet and 1 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Thu Apr 8 07:55:47 EDT 2010


Author: nickarls
Date: 2010-04-08 07:55:46 -0400 (Thu, 08 Apr 2010)
New Revision: 6082

Modified:
   core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java
   core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java
   core/trunk/tests/src/main/java/org/jboss/weld/mock/cluster/AbstractClusterTest.java
Log:
Fix clustering test (don't serialize beanstore)

Modified: core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java	2010-04-08 09:46:20 UTC (rev 6081)
+++ core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java	2010-04-08 11:55:46 UTC (rev 6082)
@@ -37,6 +37,7 @@
 import org.jboss.weld.context.api.BeanStore;
 import org.jboss.weld.context.api.helpers.ConcurrentHashMapBeanStore;
 import org.jboss.weld.context.beanstore.HashMapBeanStore;
+import org.jboss.weld.servlet.HttpPassThruSessionBeanStore;
 import org.slf4j.cal10n.LocLogger;
 
 /**
@@ -201,8 +202,7 @@
 
    private void activateSessionContext()
    {
-//      activateContext(sessionContext, new HttpPassThruSessionBeanStore());
-      sessionContext.setActive(true);
+      activateContext(sessionContext, new HttpPassThruSessionBeanStore());
    }
 
    public void endApplication()

Modified: core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java	2010-04-08 09:46:20 UTC (rev 6081)
+++ core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java	2010-04-08 11:55:46 UTC (rev 6082)
@@ -91,14 +91,15 @@
     */
    public void beginRequest(HttpServletRequest request)
    {
-      if (!RequestBeanStoreCache.isSet(request))
+      if (RequestBeanStoreCache.isSet(request))
       {
-         BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
-         RequestBeanStoreCache.set(request, requestBeanStore);
-         lifecycle.beginRequest(request.getRequestURI(), requestBeanStore);
-         restoreSessionContext(request);
-         restoreConversationContext(request);
+         return;
       }
+      BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
+      RequestBeanStoreCache.set(request, requestBeanStore);
+      lifecycle.beginRequest(request.getRequestURI(), requestBeanStore);
+      restoreSessionContext(request);
+      restoreConversationContext(request);
    }
 
    /**
@@ -111,7 +112,7 @@
    protected BeanStore restoreSessionContext(HttpServletRequest request)
    {
       HttpPassThruSessionBeanStore sessionBeanStore = HttpPassThruOnDemandSessionBeanStore.of(request);
-      HttpSession session = request.getSession(true);
+      HttpSession session = request.getSession();
       String sessionId = session == null ? "Inactive session" : session.getId();
       lifecycle.restoreSession(sessionId, sessionBeanStore);
       if (session != null)

Modified: core/trunk/tests/src/main/java/org/jboss/weld/mock/cluster/AbstractClusterTest.java
===================================================================
--- core/trunk/tests/src/main/java/org/jboss/weld/mock/cluster/AbstractClusterTest.java	2010-04-08 09:46:20 UTC (rev 6081)
+++ core/trunk/tests/src/main/java/org/jboss/weld/mock/cluster/AbstractClusterTest.java	2010-04-08 11:55:46 UTC (rev 6082)
@@ -23,14 +23,22 @@
 import java.io.ObjectOutputStream;
 import java.lang.reflect.Field;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
+import javax.enterprise.inject.spi.PassivationCapable;
+
 import org.jboss.weld.Container;
 import org.jboss.weld.bootstrap.api.Singleton;
 import org.jboss.weld.context.ContextLifecycle;
 import org.jboss.weld.context.api.BeanStore;
+import org.jboss.weld.context.api.ContextualInstance;
+import org.jboss.weld.context.beanstore.HashMapBeanStore;
 import org.jboss.weld.manager.BeanManagerImpl;
 import org.jboss.weld.mock.MockEELifecycle;
 import org.jboss.weld.mock.TestContainer;
+import org.jboss.weld.serialization.spi.helpers.SerializableContextual;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 
@@ -38,21 +46,21 @@
 {
 
    private Singleton<Container> singleton;
-   
+
    @BeforeClass
    public void beforeClass() throws Exception
    {
       singleton = (Singleton) getInstanceField().get(null);
       getInstanceField().set(null, new SwitchableSingletonProvider().create(Container.class));
    }
-   
+
    private static Field getInstanceField() throws Exception
    {
       Field field = Container.class.getDeclaredField("instance");
       field.setAccessible(true);
       return field;
    }
-   
+
    @AfterClass
    public void afterClass() throws Exception
    {
@@ -63,26 +71,48 @@
    {
       // Bootstrap container
       SwitchableSingletonProvider.use(id);
-      
+
       TestContainer container = new TestContainer(new MockEELifecycle(), classes, null);
       container.startContainer();
       container.ensureRequestActive();
-      
+
       return container;
    }
-   
+
    protected void use(int id)
    {
       SwitchableSingletonProvider.use(id);
    }
 
+   private Map<String, ContextualInstance<?>> getContextualInstances(BeanStore beanStore)
+   {
+      Map<String, ContextualInstance<?>> instances = new HashMap<String, ContextualInstance<?>>();
+      for (String id : beanStore.getContextualIds())
+      {
+         instances.put(id, beanStore.get(id));
+      }
+      return instances;
+   }
+
+   private BeanStore setContextualInstances(Map<String, ContextualInstance<?>> instances)
+   {
+      BeanStore beanStore = new HashMapBeanStore();
+      for (Map.Entry<String, ContextualInstance<?>> i : instances.entrySet())
+      {
+         beanStore.put(i.getKey(), i.getValue());
+      }
+      return beanStore;
+   }
+
+   @SuppressWarnings("unchecked")
    protected void replicateSession(int fromId, BeanManagerImpl fromBeanManager, int toId, BeanManagerImpl toBeanManager) throws Exception
    {
       // Mimic replicating the session
       BeanStore sessionBeanStore = fromBeanManager.getServices().get(ContextLifecycle.class).getSessionContext().getBeanStore();
-      byte[] bytes = serialize(sessionBeanStore);
+      Map<String, ContextualInstance<?>> contextuals = getContextualInstances(sessionBeanStore);
+      byte[] bytes = serialize(contextuals);
       use(toId);
-      BeanStore replicatedSessionBeanStore = (BeanStore) deserialize(bytes);
+      BeanStore replicatedSessionBeanStore = setContextualInstances((Map<String, ContextualInstance<?>>) deserialize(bytes));
       toBeanManager.getServices().get(ContextLifecycle.class).getSessionContext().setBeanStore(replicatedSessionBeanStore);
       use(fromId);
    }



More information about the weld-commits mailing list