[portal-commits] JBoss Portal SVN: r8853 - in modules/portlet/trunk/portlet/src/main/org/jboss/portal: test/portlet/state and 1 other directory.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Thu Nov 8 20:21:49 EST 2007


Author: julien at jboss.com
Date: 2007-11-08 20:21:49 -0500 (Thu, 08 Nov 2007)
New Revision: 8853

Modified:
   modules/portlet/trunk/portlet/src/main/org/jboss/portal/portlet/state/producer/ProducerPortletInvoker.java
   modules/portlet/trunk/portlet/src/main/org/jboss/portal/test/portlet/state/AbstractStatefulPortletInvokerTestCase.java
   modules/portlet/trunk/portlet/src/main/org/jboss/portal/test/portlet/state/ConsumerStatefulPortletInvokerTestCase.java
   modules/portlet/trunk/portlet/src/main/org/jboss/portal/test/portlet/state/ProducerStatefulPortletInvokerTestCase.java
Log:
JBPORTAL-1787: Runtime clone before write of a Producer Offered Portlet using the remote storage state management strategy produces a local storage instead of a remote storage

Modified: modules/portlet/trunk/portlet/src/main/org/jboss/portal/portlet/state/producer/ProducerPortletInvoker.java
===================================================================
--- modules/portlet/trunk/portlet/src/main/org/jboss/portal/portlet/state/producer/ProducerPortletInvoker.java	2007-11-08 22:16:22 UTC (rev 8852)
+++ modules/portlet/trunk/portlet/src/main/org/jboss/portal/portlet/state/producer/ProducerPortletInvoker.java	2007-11-09 01:21:49 UTC (rev 8853)
@@ -250,11 +250,12 @@
          //
          if (access == AccessMode.CLONE_BEFORE_WRITE)
          {
+            boolean persist = stateManagementPolicy.persistLocally();
+
             // Create the state
             if (context.isStateful())
             {
                StatefulContext statefulContext = (StatefulContext)context;
-               boolean persist = stateManagementPolicy.persistLocally();
                if (persist)
                {
                   try
@@ -291,14 +292,24 @@
                // Add the missing mutable portlet state
                getPropertiesFromMetaData(portlet.getContext(), newPrefs);
 
-               // Create the new state
-               String cloneStateId = persistenceManager.createState(context.getPortletId(), newPrefs);
+               //
+               if (persist)
+               {
+                  // Create the new state
+                  String cloneStateId = persistenceManager.createState(context.getPortletId(), newPrefs);
 
-               // Return the clone context
-               String cloneId = PRODUCER_CLONE_ID_PREFIX + cloneStateId;
-               PortletContext clonedCtx = PortletContext.createPortletContext(cloneId);
-               StateEvent event = new StateEvent(clonedCtx, StateEvent.PORTLET_CLONED_EVENT);
-               instanceCtx.onStateEvent(event);
+                  // Return the clone context
+                  String cloneId = PRODUCER_CLONE_ID_PREFIX + cloneStateId;
+                  PortletContext clonedCtx = PortletContext.createPortletContext(cloneId);
+                  StateEvent event = new StateEvent(clonedCtx, StateEvent.PORTLET_CLONED_EVENT);
+                  instanceCtx.onStateEvent(event);
+               }
+               else
+               {
+                  PortletContext clonedCtx = marshall(context.getPortletId(), newPrefs);
+                  StateEvent event = new StateEvent(clonedCtx, StateEvent.PORTLET_CLONED_EVENT);
+                  instanceCtx.onStateEvent(event);
+               }
             }
          }
          else if (access == AccessMode.READ_WRITE)

Modified: modules/portlet/trunk/portlet/src/main/org/jboss/portal/test/portlet/state/AbstractStatefulPortletInvokerTestCase.java
===================================================================
--- modules/portlet/trunk/portlet/src/main/org/jboss/portal/test/portlet/state/AbstractStatefulPortletInvokerTestCase.java	2007-11-08 22:16:22 UTC (rev 8852)
+++ modules/portlet/trunk/portlet/src/main/org/jboss/portal/test/portlet/state/AbstractStatefulPortletInvokerTestCase.java	2007-11-09 01:21:49 UTC (rev 8853)
@@ -61,6 +61,14 @@
 public abstract class AbstractStatefulPortletInvokerTestCase
 {
 
+   /** . */
+   protected final boolean persistLocally;
+
+   protected AbstractStatefulPortletInvokerTestCase(boolean persistLocally)
+   {
+      this.persistLocally = persistLocally;
+   }
+
    /**
     *
     */
@@ -159,6 +167,41 @@
    /**
     *
     */
+   protected final void assertCloneDoesNotExist(PortletContext ref)
+   {
+      if (persistLocally)
+      {
+         try
+         {
+            getProperties(ref);
+            fail("Was expecting a NoSuchPortletException to be thrown");
+         }
+         catch (NoSuchPortletException expected)
+         {
+         }
+         catch (PortletInvokerException e)
+         {
+            fail(e);
+         }
+      }
+      else
+      {
+         // We cannot assert it because we really store the state on the consumer and keep no reference
+         // on the producer, so the best we can do is to call it and assert that nothing wrong happens.
+         try
+         {
+            getProperties(ref);
+         }
+         catch (PortletInvokerException e)
+         {
+            fail(e);
+         }
+      }
+   }
+
+   /**
+    *
+    */
    protected final PortletContext createPOPRef(PortletInfoSupport portletInfo) throws PortletInvokerException
    {
       PortletSupport portletSupport = new PortletSupport(portletInfo);
@@ -715,15 +758,15 @@
 
       //
       PropertyChange[] changes = new PropertyChange[]
-         {
-            PropertyChange.newUpdate("override_update", new StringValue("override_update_clone_value_2")),
-            PropertyChange.newReset("override_reset"),
-            PropertyChange.newUpdate("override_create", new StringValue("override_create_clone_value_2")),
-            PropertyChange.newUpdate("dynamic_update", new StringValue("dynamic_update_clone_value_2")),
-            PropertyChange.newReset("dynamic_reset"),
-            PropertyChange.newUpdate("dynamic_create", new StringValue("dynamic_create_clone_value_2")),
-            PropertyChange.newUpdate("readonly_create", new StringValue("readonly_create_clone_value_2")),
-         };
+      {
+         PropertyChange.newUpdate("override_update", new StringValue("override_update_clone_value_2")),
+         PropertyChange.newReset("override_reset"),
+         PropertyChange.newUpdate("override_create", new StringValue("override_create_clone_value_2")),
+         PropertyChange.newUpdate("dynamic_update", new StringValue("dynamic_update_clone_value_2")),
+         PropertyChange.newReset("dynamic_reset"),
+         PropertyChange.newUpdate("dynamic_create", new StringValue("dynamic_create_clone_value_2")),
+         PropertyChange.newUpdate("readonly_create", new StringValue("readonly_create_clone_value_2")),
+      };
       ccpCtx = setProperties(ccpCtx, changes);
 
       //
@@ -739,8 +782,19 @@
    }
 
    @Test
-   public void testInvokeCloneBeforeWriteWithUpdate() throws Exception
+   public void testInvokeCloneBeforeWritePOPWithUpdate() throws Exception
    {
+      invokeCloneBeforeWriteWithUpdate(true);
+   }
+
+   @Test
+   public void testInvokeCloneBeforeWriteCCPWithUpdate() throws Exception
+   {
+      invokeCloneBeforeWriteWithUpdate(false);
+   }
+
+   public void invokeCloneBeforeWriteWithUpdate(boolean pop) throws Exception
+   {
       PortletInfoSupport info = new PortletInfoSupport();
       PortletSupport portletSupport = new PortletSupport(info)
       {
@@ -751,11 +805,24 @@
             return null;
          }
       };
-      PortletContext popCtx = createPOPRef(portletSupport);
-      addPreference(popCtx, "abc", new StringValue("def"));
 
+      PortletContext ctx;
+      if (pop)
+      {
+         PortletContext popCtx = createPOPRef(portletSupport);
+         addPreference(popCtx, "abc", new StringValue("def"));
+         ctx = popCtx;
+      }
+      else
+      {
+         PortletContext popCtx = createPOPRef(portletSupport);
+         addPreference(popCtx, "abc", new StringValue("def"));
+         PortletContext ccpCtx = createClone(popCtx);
+         ctx = ccpCtx;
+      }
+
       //
-      ActionInvocation invocation = createAction(popCtx, AccessMode.CLONE_BEFORE_WRITE);
+      ActionInvocation invocation = createAction(ctx, AccessMode.CLONE_BEFORE_WRITE);
       invoke(invocation);
 
       //
@@ -767,6 +834,12 @@
       PropertyMap expectedProps = new SimplePropertyMap();
       expectedProps.setProperty("abc", new StringValue("_def"));
       ValueMapAssert.assertEquals(expectedProps, blah);
+
+      // Now we test the clone destruction
+      destroyClone(cloneRef);
+
+      // Assert clone ref does not exist anymore
+      assertCloneDoesNotExist(cloneRef);
    }
 
    @Test

Modified: modules/portlet/trunk/portlet/src/main/org/jboss/portal/test/portlet/state/ConsumerStatefulPortletInvokerTestCase.java
===================================================================
--- modules/portlet/trunk/portlet/src/main/org/jboss/portal/test/portlet/state/ConsumerStatefulPortletInvokerTestCase.java	2007-11-08 22:16:22 UTC (rev 8852)
+++ modules/portlet/trunk/portlet/src/main/org/jboss/portal/test/portlet/state/ConsumerStatefulPortletInvokerTestCase.java	2007-11-09 01:21:49 UTC (rev 8853)
@@ -25,6 +25,7 @@
 import org.jboss.portal.portlet.Portlet;
 import org.jboss.portal.portlet.PortletContext;
 import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.NoSuchPortletException;
 import org.jboss.portal.portlet.support.info.PortletInfoSupport;
 import org.jboss.portal.portlet.impl.state.StateManagementPolicyService;
 import org.jboss.portal.portlet.impl.state.StateConverterV0;
@@ -57,13 +58,10 @@
 
    public ConsumerStatefulPortletInvokerTestCase(boolean persistLocally)
    {
-      this.persistLocally = persistLocally;
+      super(persistLocally);
    }
 
    /** . */
-   protected final boolean persistLocally;
-
-   /** . */
    protected ConsumerPortletInvoker consumer;
 
    /** . */

Modified: modules/portlet/trunk/portlet/src/main/org/jboss/portal/test/portlet/state/ProducerStatefulPortletInvokerTestCase.java
===================================================================
--- modules/portlet/trunk/portlet/src/main/org/jboss/portal/test/portlet/state/ProducerStatefulPortletInvokerTestCase.java	2007-11-08 22:16:22 UTC (rev 8852)
+++ modules/portlet/trunk/portlet/src/main/org/jboss/portal/test/portlet/state/ProducerStatefulPortletInvokerTestCase.java	2007-11-09 01:21:49 UTC (rev 8853)
@@ -25,6 +25,7 @@
 import org.jboss.portal.portlet.Portlet;
 import org.jboss.portal.portlet.PortletContext;
 import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.NoSuchPortletException;
 import org.jboss.portal.portlet.impl.state.StateManagementPolicyService;
 import org.jboss.portal.portlet.impl.state.StateConverterV0;
 import org.jboss.portal.portlet.impl.state.producer.PortletStatePersistenceManagerService;
@@ -55,13 +56,10 @@
 
    protected ProducerStatefulPortletInvokerTestCase(boolean persistLocally)
    {
-      this.persistLocally = persistLocally;
+      super(persistLocally);
    }
 
    /** . */
-   protected final boolean persistLocally;
-
-   /** . */
    protected ProducerPortletInvoker producer;
 
    /** . */




More information about the portal-commits mailing list