[exo-jcr-commits] exo-jcr SVN: r4474 - in jcr/trunk/exo.jcr.component.core: src/main/java/org/exoplatform/services/jcr/impl/core and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Jun 3 10:24:20 EDT 2011


Author: tolusha
Date: 2011-06-03 10:24:20 -0400 (Fri, 03 Jun 2011)
New Revision: 4474

Modified:
   jcr/trunk/exo.jcr.component.core/pom.xml
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionRegistry.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSessionCleaner.java
Log:
EXOJCR-1364: test cleanup

Modified: jcr/trunk/exo.jcr.component.core/pom.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/pom.xml	2011-06-03 12:44:26 UTC (rev 4473)
+++ jcr/trunk/exo.jcr.component.core/pom.xml	2011-06-03 14:24:20 UTC (rev 4474)
@@ -402,7 +402,6 @@
                   <exclude>org/exoplatform/services/jcr/**/impl/**/TestWorkspaceManagement.java</exclude>
                   <exclude>org/exoplatform/services/jcr/**/impl/**/TestWorkspaceRestore.java</exclude>
                   <exclude>org/exoplatform/services/jcr/**/impl/**/TestRepositoryManagement.java</exclude>
-                  <exclude>org/exoplatform/services/jcr/**/impl/**/TestSessionCleaner.java</exclude>
                   <exclude>org/exoplatform/services/jcr/**/impl/**/Base*.java</exclude>
                   <exclude>org/exoplatform/services/jcr/**/impl/**/TestJCRSerializationStream.java</exclude>
                   <exclude>org/exoplatform/services/jcr/**/impl/**/TestJCRSerializationVersionRestore.java</exclude>
@@ -740,30 +739,20 @@
                         <include>org/apache/jackrabbit/test/api/version/*Test.java</include>
                      </includes>
                      <excludes>
-                        <!-- From default tests -->
                         <exclude>org/exoplatform/services/jcr/**/TestQueryUsecases.java</exclude>
-                        <exclude>org/exoplatform/services/jcr/**/TestRollbackBigFiles.java</exclude>
-                        <exclude>org/exoplatform/services/jcr/**/TestImport.java</exclude>
-                        <exclude>org/exoplatform/services/jcr/**/TestRollbackBigFiles.java</exclude>
-                        <exclude>org/exoplatform/services/jcr/**/TestErrorMultithreading.java</exclude>
                         <exclude>org/exoplatform/services/jcr/**/api/TestAll.java</exclude>
-                        <exclude>org/exoplatform/services/jcr/**/api/**/TestSameNameItems.java</exclude>
-                        <exclude>org/exoplatform/services/jcr/**/api/**/TestSameNameItems.java</exclude>
+                        <exclude>org/exoplatform/services/jcr/**/TestErrorMultithreading.java</exclude>
+                        <exclude>org/exoplatform/services/jcr/**/TestRollbackBigFiles.java</exclude>
                         <exclude>org/exoplatform/services/jcr/**/impl/**/TestWorkspaceManagement.java</exclude>
-                        <exclude>org/exoplatform/services/jcr/**/impl/**/TestWorkspaceRestore.java</exclude>   
+                        <exclude>org/exoplatform/services/jcr/**/impl/**/TestWorkspaceRestore.java</exclude>
                         <exclude>org/exoplatform/services/jcr/**/impl/**/TestRepositoryManagement.java</exclude>
-                        <exclude>org/exoplatform/services/jcr/**/impl/**/ValueStoragePluginTest.java</exclude>
-                        <exclude>org/exoplatform/services/jcr/**/impl/**/TestSessionCleaner.java</exclude>
                         <exclude>org/exoplatform/services/jcr/**/impl/**/Base*.java</exclude>
                         <exclude>org/exoplatform/services/jcr/**/impl/**/TestJCRSerializationStream.java</exclude>
                         <exclude>org/exoplatform/services/jcr/**/impl/**/TestJCRSerializationVersionRestore.java</exclude>
                         <exclude>org/exoplatform/services/jcr/**/usecases/**/RemoveSameNameSiblingTest.java</exclude>
                         <exclude>org/exoplatform/services/jcr/**/usecases/**/TestQueryWithNumberAndSpace.java</exclude>
                         <exclude>org/exoplatform/services/jcr/**/usecases/BaseUsecasesTest.java</exclude>
-                        <exclude>org/exoplatform/services/jcr/**/usecases/**/ExportWorkspaceSystemViewTest.java</exclude>
-                        <exclude>org/exoplatform/services/jcr/**/impl/**/TestLinkedWorkspaceStorageCacheMetrics.java</exclude>
                         <exclude>org/exoplatform/services/jcr/**/impl/**/SQLBenchmarkTest.java</exclude>
-                        <exclude>org/exoplatform/services/jcr/**/impl/**/TestCleanableFileStreamValueData.java</exclude>
                         <!-- From TCK -->
                         <exclude>org/apache/jackrabbit/test/api/TestAll.java</exclude>
                         <exclude>org/apache/jackrabbit/test/api/**/Abstract*.java</exclude>

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionRegistry.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionRegistry.java	2011-06-03 12:44:26 UTC (rev 4473)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionRegistry.java	2011-06-03 14:24:20 UTC (rev 4474)
@@ -74,12 +74,19 @@
    @ManagedDescription("Set the session time out in seconds")
    public void setTimeOut(long timeout)
    {
+      if (this.timeOut == timeout)
+      {
+         return;
+      }
+
+      // disable the cleaner
+      this.sessionCleaner.halt();
+      this.sessionCleaner = null;
+
       this.timeOut = timeout <= 0 ? 0 : timeout * 1000;
       if (timeOut == 0 && sessionCleaner != null)
       {
-         // We set a time out to 0 so we disable the cleaner
-         this.sessionCleaner.halt();
-         this.sessionCleaner = null;
+         // We set a time out to 0, no need to create new cleaner
          if (log.isDebugEnabled())
          {
             log.debug("Stop the previous session cleaner");
@@ -87,7 +94,7 @@
       }
       else if (timeOut > 0 && sessionCleaner == null)
       {
-         // We set a time out greater than 0, so we enable the cleaner
+         // We set a time out greater than 0, so we create new cleaner
          this.sessionCleaner = new SessionCleaner(repositoryId, DEFAULT_CLEANER_TIMEOUT, timeOut);      
          if (log.isDebugEnabled())
          {

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSessionCleaner.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSessionCleaner.java	2011-06-03 12:44:26 UTC (rev 4473)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSessionCleaner.java	2011-06-03 14:24:20 UTC (rev 4474)
@@ -21,17 +21,10 @@
 import org.exoplatform.services.jcr.JcrImplBaseTest;
 
 import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Random;
-import java.util.WeakHashMap;
 
 import javax.jcr.LoginException;
 import javax.jcr.NoSuchWorkspaceException;
-import javax.jcr.Node;
 import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 
 /**
  * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
@@ -41,48 +34,42 @@
 {
    private final static int AGENT_COUNT = 10;
 
+   private final static int TEST_SESSION_TIMEOUT = 1; // seconds
+
    private SessionRegistry sessionRegistry;
 
    private long oldTimeOut;
 
-   private final static long TEST_SESSION_TIMEOUT = 20000;
-
    @Override
    public void setUp() throws Exception
    {
       super.setUp();
       sessionRegistry = (SessionRegistry)session.getContainer().getComponentInstanceOfType(SessionRegistry.class);
-      oldTimeOut = sessionRegistry.timeOut;
-      sessionRegistry.timeOut = TEST_SESSION_TIMEOUT;
-      sessionRegistry.stop();
-      Thread.yield();
-      sessionRegistry.start();
+      oldTimeOut = sessionRegistry.getTimeOut();
+      sessionRegistry.setTimeOut(TEST_SESSION_TIMEOUT);
    }
 
    @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
-      sessionRegistry.stop();
-      sessionRegistry.timeOut = oldTimeOut;
-      Thread.yield();
-      sessionRegistry.start();
+      sessionRegistry.setTimeOut(oldTimeOut);
    }
 
    public void testSessionRemove() throws LoginException, NoSuchWorkspaceException, RepositoryException,
       InterruptedException
    {
       SessionImpl session2 = (SessionImpl)repository.login(credentials, "ws");
+      assertTrue(session2.isLive());
 
       // Create a weak reference to the session
       WeakReference<SessionImpl> ref = new WeakReference<SessionImpl>(session2);
 
-      assertTrue(session2.isLive());
+      Thread.sleep(5000);
 
-      assertNotNull(sessionRegistry);
+      System.out.println(session2.getLastAccessTime());
+      sessionRegistry.runCleanup();
 
-      Thread.sleep(SessionRegistry.DEFAULT_CLEANER_TIMEOUT + 1000);
-
       assertFalse(session2.isLive());
 
       // Dereference the session explicitely
@@ -95,353 +82,4 @@
       assertNull(ref.get());
 
    }
-
-   public void testSessionLoginLogoutSimultaneouslyMultiThread() throws Exception
-   {
-      assertNotNull(sessionRegistry);
-
-      class AgentLogin extends Thread
-      {
-
-         Random random = new Random();
-
-         SessionImpl workSession;
-
-         boolean sessionStarted = false;
-
-         public AgentLogin()
-         {
-         }
-
-         @Override
-         public void run()
-         {
-            try
-            {
-               Thread.sleep(SessionRegistry.DEFAULT_CLEANER_TIMEOUT - random.nextInt(200) + 200);
-
-               workSession = (SessionImpl)repository.login(credentials, "ws");
-               sessionStarted = true;
-
-            }
-            catch (Exception e)
-            {
-               e.printStackTrace();
-               fail("Exception should not be thrown");
-            }
-         }
-      }
-
-      class AgentLogout extends Thread
-      {
-         AgentLogin agentLogin;
-
-         public AgentLogout(AgentLogin agentLogin)
-         {
-            this.agentLogin = agentLogin;
-         }
-
-         @Override
-         public void run()
-         {
-            try
-            {
-               while (!agentLogin.sessionStarted)
-               {
-                  Thread.sleep(50);
-               }
-
-               if (agentLogin.workSession.isLive())
-               {
-                  agentLogin.workSession.logout();
-               }
-
-            }
-            catch (Exception e)
-            {
-               e.printStackTrace();
-               fail("Exception should not be thrown");
-            }
-         }
-      }
-
-      Session workSession = (SessionImpl)repository.login(credentials, "ws");
-      while (workSession.isLive())
-      {
-         Thread.sleep(100);
-      }
-
-      // start
-      List<Object> agents = new ArrayList<Object>();
-
-      for (int i = 0; i < AGENT_COUNT; i++)
-      {
-         AgentLogin agentLogin = new AgentLogin();
-         agents.add(agentLogin);
-         agentLogin.start();
-
-         AgentLogout agentLogout = new AgentLogout(agentLogin);
-         agents.add(agentLogout);
-         agentLogout.start();
-      }
-
-      // wait to stop all threads
-      boolean isNeedWait = true;
-      while (isNeedWait)
-      {
-         isNeedWait = false;
-         for (int i = 0; i < AGENT_COUNT * 2; i++)
-         {
-            Thread agent = (Thread)agents.get(i);
-            if (agent.isAlive())
-            {
-               isNeedWait = true;
-               break;
-            }
-         }
-         Thread.sleep(1000);
-      }
-
-      assertFalse(sessionRegistry.isInUse("ws"));
-   }
-
-   public void testSessionLoginLogoutMultiThread() throws InterruptedException
-   {
-      assertNotNull(sessionRegistry);
-
-      class AgentLogin extends Thread
-      {
-
-         SessionImpl workSession;
-
-         int sleepTime;
-
-         boolean sessionStarted = false;
-
-         public AgentLogin(int sleepTime)
-         {
-            this.sleepTime = sleepTime;
-         }
-
-         @Override
-         public void run()
-         {
-            try
-            {
-               Thread.sleep(sleepTime);
-               workSession = (SessionImpl)repository.login(credentials, "ws");
-               sessionStarted = true;
-
-            }
-            catch (Exception e)
-            {
-               e.printStackTrace();
-               fail("Exception should not be thrown");
-            }
-         }
-      }
-
-      class AgentLogout extends Thread
-      {
-         AgentLogin agentLogin;
-
-         public AgentLogout(AgentLogin agentLogin)
-         {
-            this.agentLogin = agentLogin;
-         }
-
-         @Override
-         public void run()
-         {
-            try
-            {
-               while (!agentLogin.sessionStarted)
-               {
-                  Thread.sleep(1000);
-               }
-
-               Thread.sleep(SessionRegistry.DEFAULT_CLEANER_TIMEOUT / 2);
-
-               if (agentLogin.workSession.isLive())
-               {
-                  agentLogin.workSession.logout();
-               }
-
-            }
-            catch (Exception e)
-            {
-               e.printStackTrace();
-               fail("Exception should not be thrown");
-            }
-         }
-      }
-
-      // start
-      List<Object> agents = new ArrayList<Object>();
-
-      int sleepTime = 0;
-      for (int i = 0; i < AGENT_COUNT; i++)
-      {
-         AgentLogin agentLogin = new AgentLogin(sleepTime);
-         agents.add(agentLogin);
-         agentLogin.start();
-
-         AgentLogout agentLogout = new AgentLogout(agentLogin);
-         agents.add(agentLogout);
-         agentLogout.start();
-
-         sleepTime =
-            SessionRegistry.DEFAULT_CLEANER_TIMEOUT / 10
-               + (sleepTime >= 2 * SessionRegistry.DEFAULT_CLEANER_TIMEOUT ? 0 : sleepTime);
-      }
-
-      // wait to stop all threads
-      boolean isNeedWait = true;
-      while (isNeedWait)
-      {
-         isNeedWait = false;
-         for (int i = 0; i < AGENT_COUNT * 2; i++)
-         {
-            Thread agent = (Thread)agents.get(i);
-            if (agent.isAlive())
-            {
-               isNeedWait = true;
-               break;
-            }
-         }
-         Thread.sleep(100);
-      }
-
-      assertFalse(sessionRegistry.isInUse("ws"));
-   }
-
-   public void testSessionRemoveMultiThread() throws InterruptedException
-   {
-      assertNotNull(sessionRegistry);
-      final Random random = new Random();
-      class Agent extends Thread
-      {
-         boolean result = false;
-
-         boolean active = false;
-
-         public Agent()
-         {
-            active = random.nextBoolean();
-         }
-
-         @Override
-         public void run()
-         {
-            try
-            {
-               SessionImpl session2 = (SessionImpl)repository.login(credentials, "ws");
-               Node rootNode = session2.getRootNode();
-               rootNode.addNode("test");
-               assertTrue(session2.isLive());
-
-               if (active)
-               {
-                  log.info("start active session");
-                  long startTime = System.currentTimeMillis();
-                  while (startTime + sessionRegistry.timeOut * 2 < System.currentTimeMillis())
-                  {
-                     Node root2 = session2.getRootNode();
-                     Node testNode = root2.getNode("test");
-                     testNode.setProperty("prop1", "value");
-                     Thread.sleep(sessionRegistry.timeOut / 2);
-                  }
-                  result = session2.isLive();
-               }
-               else
-               {
-                  log.info("start pasive session");
-                  Thread.sleep(SessionRegistry.DEFAULT_CLEANER_TIMEOUT + 1000);
-                  result = !session2.isLive();
-               }
-
-            }
-            catch (InterruptedException e)
-            {
-            }
-            catch (LoginException e)
-            {
-            }
-            catch (NoSuchWorkspaceException e)
-            {
-            }
-            catch (RepositoryException e)
-            {
-            }
-         }
-
-      }
-      List<Agent> agents = new ArrayList<Agent>();
-      for (int i = 0; i < AGENT_COUNT; i++)
-      {
-         agents.add(new Agent());
-      }
-      for (Agent agent : agents)
-      {
-         agent.start();
-      }
-      boolean isNeedWait = true;
-      while (isNeedWait)
-      {
-         isNeedWait = false;
-         for (int i = 0; i < AGENT_COUNT; i++)
-         {
-            Agent curClient = agents.get(i);
-            if (curClient.isAlive())
-            {
-               isNeedWait = true;
-               break;
-            }
-         }
-         Thread.sleep(100);
-      }
-      for (Agent agent2 : agents)
-      {
-         assertTrue(agent2.result);
-      }
-   }
-
-   public void testManySessionRemove() throws LoginException, NoSuchWorkspaceException, RepositoryException,
-      InterruptedException
-   {
-      int sessionCount = 100000;
-      WeakReference<SessionImpl> refSessions[] = new WeakReference[100000];
-      SessionImpl sessions[] = new SessionImpl[100000];
-
-      for (int i = 0; i < sessionCount; i++)
-      {
-         sessions[i] = (SessionImpl)repository.login(credentials, "ws");
-         refSessions[i] = new WeakReference<SessionImpl>(sessions[i]);
-      }
-
-      assertNotNull(sessionRegistry);
-
-      Thread.sleep(SessionRegistry.DEFAULT_CLEANER_TIMEOUT + 120000);
-
-      for (SessionImpl session : sessions)
-      {
-         assertFalse(session.isLive());
-      }
-
-      // Dereference the session explicitely
-      for (int i = 0; i < sessionCount; i++)
-      {
-         sessions[i] = null;
-      }
-
-      // Make a GC
-      forceGC();
-
-      // The weak reference must now be null
-      for (WeakReference ref : refSessions)
-      {
-         assertNull(ref.get());
-      }
-
-   }
 }



More information about the exo-jcr-commits mailing list