[gatein-commits] gatein SVN: r5344 - in portal/branches/branch-GTNPORTAL-1700/component/portal/src: test/java/org/exoplatform/portal/config and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Nov 29 05:05:55 EST 2010


Author: hoang_to
Date: 2010-11-29 05:05:54 -0500 (Mon, 29 Nov 2010)
New Revision: 5344

Modified:
   portal/branches/branch-GTNPORTAL-1700/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java
   portal/branches/branch-GTNPORTAL-1700/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java
Log:
Add missing Java code in TestDataStorage and POMSessionManager

Modified: portal/branches/branch-GTNPORTAL-1700/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1700/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java	2010-11-29 10:03:03 UTC (rev 5343)
+++ portal/branches/branch-GTNPORTAL-1700/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java	2010-11-29 10:05:54 UTC (rev 5344)
@@ -23,6 +23,7 @@
 import org.exoplatform.commons.chromattic.ChromatticManager;
 import org.exoplatform.commons.chromattic.SessionContext;
 import org.exoplatform.portal.pom.config.cache.DataCache;
+import org.exoplatform.portal.pom.config.cache.PortalNamesCache;
 import org.exoplatform.portal.pom.data.OwnerKey;
 import org.exoplatform.portal.pom.data.PortalKey;
 import org.exoplatform.services.cache.CacheService;
@@ -73,7 +74,7 @@
       this.manager = manager;
       this.cache = cacheService.getCacheInstance("MOPSessionManager");
       this.pomService = null;
-      this.executor = new DataCache(new ExecutorDispatcher());
+      this.executor = new PortalNamesCache(new DataCache(new ExecutorDispatcher()));
    }
 
    public void cachePut(Serializable key, Object value)

Modified: portal/branches/branch-GTNPORTAL-1700/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1700/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java	2010-11-29 10:03:03 UTC (rev 5343)
+++ portal/branches/branch-GTNPORTAL-1700/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java	2010-11-29 10:05:54 UTC (rev 5344)
@@ -37,7 +37,11 @@
 import org.exoplatform.services.listener.ListenerService;
 
 import java.util.*;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicReference;
 
+import junit.framework.AssertionFailedError;
+
 /**
  * Created by The eXo Platform SARL Author : Tung Pham thanhtungty at gmail.com Nov
  * 13, 2007
@@ -888,6 +892,121 @@
       assertNull(storage_.getPage(CLASSIC_HOME));
    }
 
+   public void testGetAllPortalNames() throws Exception
+   {
+      final List<String> names = storage_.getAllPortalNames();
+
+      // Create new portal
+      storage_.create(new PortalConfig("portal", "testGetAllPortalNames"));
+
+      // Test during tx we see the good names
+      List<String> transientNames = storage_.getAllPortalNames();
+      assertTrue(transientNames.containsAll(names));
+      transientNames.removeAll(names);
+      assertEquals(Collections.singletonList("testGetAllPortalNames"), transientNames);
+
+      // Test we have not seen anything yet outside of tx
+      final CountDownLatch addSync = new CountDownLatch(1);
+      final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
+      new Thread()
+      {
+         @Override
+         public void run()
+         {
+            begin();
+            try
+            {
+               List<String> isolatedNames = storage_.getAllPortalNames();
+               assertEquals(new HashSet<String>(names), new HashSet<String>(isolatedNames));
+            }
+            catch (Throwable t)
+            {
+               error.set(t);
+            }
+            finally
+            {
+               addSync.countDown();
+               end();
+            }
+         }
+      }.start();
+
+      //
+      addSync.await();
+      if (error.get() != null)
+      {
+         AssertionFailedError afe = new AssertionFailedError();
+         afe.initCause(error.get());
+         throw afe;
+      }
+
+      // Now commit tx
+      session.close(true);
+      end(true);
+
+      // We test we observe the change
+      begin();
+      session = mgr.openSession();
+      List<String> afterNames = storage_.getAllPortalNames();
+      assertTrue(afterNames.containsAll(names));
+      afterNames.removeAll(names);
+      assertEquals(Collections.singletonList("testGetAllPortalNames"), afterNames);
+
+      // Then we remove the newly created portal
+      storage_.remove(new PortalConfig("portal", "testGetAllPortalNames"));
+
+      // Test we are syeing the transient change
+      transientNames.clear();
+      transientNames = storage_.getAllPortalNames();
+      assertEquals(names, transientNames);
+
+      // Test we have not seen anything yet outside of tx
+      error.set(null);
+      final CountDownLatch removeSync = new CountDownLatch(1);
+      new Thread()
+      {
+         public void run()
+         {
+            begin();
+            try
+            {
+               List<String> isolatedNames = storage_.getAllPortalNames();
+               assertTrue(isolatedNames.containsAll(names));
+               isolatedNames.removeAll(names);
+               assertEquals(Collections.singletonList("testGetAllPortalNames"), isolatedNames);
+            }
+            catch (Throwable t)
+            {
+               error.set(t);
+            }
+            finally
+            {
+               removeSync.countDown();
+               end();
+            }
+         }
+      }.start();
+
+      //
+      removeSync.await();
+      if (error.get() != null)
+      {
+         AssertionFailedError afe = new AssertionFailedError();
+         afe.initCause(error.get());
+         throw afe;
+      }
+
+      //
+      session.close(true);
+      end(true);
+
+      // Now test it is still removed
+      begin();
+      session = mgr.openSession();
+      afterNames = storage_.getAllPortalNames();
+      assertEquals(new HashSet<String>(names), new HashSet<String>(afterNames));
+   }
+
    private Application<Portlet> create(String instanceId)
    {
       int i0 = instanceId.indexOf("#");



More information about the gatein-commits mailing list