[exo-jcr-commits] exo-jcr SVN: r1530 - in jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster: test and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jan 21 09:39:49 EST 2010


Author: nfilotto
Date: 2010-01-21 09:39:48 -0500 (Thu, 21 Jan 2010)
New Revision: 1530

Modified:
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestLoadIndexerWriter.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestLoadIndexerWriterWithModes.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestLoadIndexerQuery.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestLoadIndexerQueryWithModes.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestReadNWrite.java
Log:
EXOJCR-402: The memory leak of the test classes have been removed

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestLoadIndexerWriter.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestLoadIndexerWriter.java	2010-01-21 14:39:42 UTC (rev 1529)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestLoadIndexerWriter.java	2010-01-21 14:39:48 UTC (rev 1530)
@@ -26,6 +26,7 @@
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 
 /**
  * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
@@ -77,12 +78,6 @@
 
       private int id;
 
-      private SessionImpl sessionLocal;
-
-      private Node statisticNode;
-
-      private Node contentNode;
-
       private Random random;
 
       public WriterTask(int id) throws RepositoryException
@@ -90,14 +85,16 @@
          this.id = id;
          // login
          CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
-         sessionLocal = (SessionImpl)repository.login(credentials, "ws");
+         Session sessionLocal = (SessionImpl)repository.login(credentials, "ws");
          // prepare nodes
          Node root = sessionLocal.getRootNode();
          Node threadNode = root.addNode("Thread" + id);
-         statisticNode = threadNode.addNode(STATISTIC);
-         contentNode = threadNode.addNode(CONTENT);
+         threadNode.addNode(STATISTIC);
+         threadNode.addNode(CONTENT);
          random = new Random();
          sessionLocal.save();
+         sessionLocal.logout();
+         sessionLocal = null;
       }
 
       /**
@@ -105,33 +102,45 @@
        */
       public void run()
       {
-         try
+         while (!stop)
          {
-            while (!stop)
+            // get any word
+            int i = random.nextInt(WORDS.length);
+            String word = WORDS[i] + id; // "hello12" if thread#12 is creating it
+            Session sessionLocal = null;
+            try
             {
-               // get any word
-               int i = random.nextInt(WORDS.length);
-               String word = WORDS[i] + id; // "hello12" if thread#12 is creating it
+               CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
+               sessionLocal = (SessionImpl)repository.login(credentials, "ws");  
+               long time = System.currentTimeMillis();
                // update statistic
-               updateStatistic(word);
+               updateStatistic((Node)sessionLocal.getItem("/Thread" + id + "/" + STATISTIC),word);
                // add actual node
-               createTree().addNode(word);
+               createTree((Node)sessionLocal.getItem("/Thread" + id + "/" + CONTENT)).addNode(word);
                sessionLocal.save();
-               System.out.print("#");
-               
-               try
+               log.info("Time : " + (System.currentTimeMillis() - time));
+            }
+            catch (RepositoryException e)
+            {
+               log.error(e);
+            }
+            finally
+            {
+               if (sessionLocal != null)
                {
-                  Thread.sleep(300);
+                  sessionLocal.logout();
+                  sessionLocal = null;                  
                }
-               catch (InterruptedException e)
-               {
-               }
             }
+            
+            try
+            {
+               Thread.sleep(300);
+            }
+            catch (InterruptedException e)
+            {
+            }
          }
-         catch (RepositoryException e)
-         {
-            log.error(e);
-         }
       }
 
       /**
@@ -140,7 +149,7 @@
        * @param word
        * @throws RepositoryException
        */
-      private void updateStatistic(String word) throws RepositoryException
+      private void updateStatistic(Node statisticNode, String word) throws RepositoryException
       {
          Node wordNode;
          long count = 0;
@@ -163,7 +172,7 @@
        * @return
        * @throws RepositoryException
        */
-      private Node createTree() throws RepositoryException
+      private Node createTree(Node contentNode) throws RepositoryException
       {
          // created node tree like: "./content/n123456/n1234567/n12345678"
          Node end;

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestLoadIndexerWriterWithModes.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestLoadIndexerWriterWithModes.java	2010-01-21 14:39:42 UTC (rev 1529)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestLoadIndexerWriterWithModes.java	2010-01-21 14:39:48 UTC (rev 1530)
@@ -20,6 +20,8 @@
 
 import org.exoplatform.services.jcr.JcrAPIBaseTest;
 import org.exoplatform.services.jcr.core.CredentialsImpl;
+import org.exoplatform.services.jcr.core.WorkspaceContainerFacade;
+import org.exoplatform.services.jcr.dataflow.persistent.WorkspaceStorageCache;
 import org.exoplatform.services.jcr.impl.core.SessionImpl;
 
 import java.io.BufferedReader;
@@ -31,6 +33,7 @@
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 
 /**
  * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
@@ -64,8 +67,12 @@
          "exception", "cycle", "value", "index", "meaning", "strange", "words", "hello", "outline", "finest",
          "basetest", "writer"};
 
+   private WorkspaceStorageCache cache;
+   
    public void testWrite() throws Exception
    {
+      WorkspaceContainerFacade wsc = repository.getWorkspaceContainer("ws");
+      this.cache = (WorkspaceStorageCache)wsc.getComponent(WorkspaceStorageCache.class);
       log.info("Skip (y/n) :");
       BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
       String line = reader.readLine();
@@ -115,12 +122,6 @@
 
       private int id;
 
-      private SessionImpl sessionLocal;
-
-      private Node statisticNode;
-
-      private Node contentNode;
-
       private Random random;
 
       public WriterTask(int id) throws RepositoryException
@@ -128,14 +129,16 @@
          this.id = id;
          // login
          CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
-         sessionLocal = (SessionImpl)repository.login(credentials, "ws");
+         Session sessionLocal = (SessionImpl)repository.login(credentials, "ws");
          // prepare nodes
          Node root = sessionLocal.getRootNode();
          Node threadNode = root.addNode("Thread" + id);
-         statisticNode = threadNode.addNode(STATISTIC);
-         contentNode = threadNode.addNode(CONTENT);
+         threadNode.addNode(STATISTIC);
+         threadNode.addNode(CONTENT);
          random = new Random();
          sessionLocal.save();
+         sessionLocal.logout();
+         sessionLocal = null;
       }
 
       /**
@@ -148,32 +151,45 @@
             startSignal.await();
             while (!stop)
             {
-               long time = System.currentTimeMillis();
                // get any word
                int i = random.nextInt(words.length);
                String word = words[i] + id; // "hello12" if thread#12 is creating it
+               Session sessionLocal = null;
                try
                {
+                  CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
+                  sessionLocal = (SessionImpl)repository.login(credentials, "ws");                  
+                  long time = System.currentTimeMillis();
                   // update statistic
-                  updateStatistic(word);
+                  updateStatistic((Node)sessionLocal.getItem("/Thread" + id + "/" + STATISTIC),word);
                   // add actual node
-                  createTree().addNode(word);
+                  createTree((Node)sessionLocal.getItem("/Thread" + id + "/" + CONTENT)).addNode(word);
                   sessionLocal.save();
-                  System.out.println(Thread.currentThread() + " time : " + (System.currentTimeMillis() - time));
+                  log.info("Time : " + (System.currentTimeMillis() - time));
                }
                catch (Exception e1)
                {
-                  // discard session changes 
-                  sessionLocal.refresh(false);
+                  if (sessionLocal != null)
+                  {
+                     // discard session changes 
+                     sessionLocal.refresh(false);                     
+                  }
                   log.error("An error occurs", e1);
                }
-
+               finally
+               {
+                  if (sessionLocal != null)
+                  {
+                     sessionLocal.logout();
+                     sessionLocal = null;                  
+                  }
+               }
                try
                {
                   if (makeThemWait.get())
                   {
                      barrier.await();
-                     log.info("The threads are waiting for the go signal");
+                     log.info("The threads are waiting for the go signal, the current size of the cache is " + cache.getSize());
                      goSignal.await();
                   }
                   else
@@ -202,7 +218,7 @@
        * @param word
        * @throws RepositoryException
        */
-      private void updateStatistic(String word) throws RepositoryException
+      private void updateStatistic(Node statisticNode, String word) throws RepositoryException
       {
          Node wordNode;
          long count = 0;
@@ -225,7 +241,7 @@
        * @return
        * @throws RepositoryException
        */
-      private Node createTree() throws RepositoryException
+      private Node createTree(Node contentNode) throws RepositoryException
       {
          // created node tree like: "./content/n123456/n1234567/n12345678"
          Node end;

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestLoadIndexerQuery.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestLoadIndexerQuery.java	2010-01-21 14:39:42 UTC (rev 1529)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestLoadIndexerQuery.java	2010-01-21 14:39:48 UTC (rev 1530)
@@ -30,6 +30,7 @@
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
@@ -73,19 +74,10 @@
 
    private class QueryTask implements Runnable
    {
-      private SessionImpl sessionLocal;
-
-      private Node rootLocal;
-
       private Random random;
 
       public QueryTask() throws RepositoryException
       {
-         // login
-         CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
-         sessionLocal = (SessionImpl)repository.login(credentials, "ws");
-         // prepare nodes
-         rootLocal = sessionLocal.getRootNode();
          random = new Random();
       }
 
@@ -94,10 +86,16 @@
        */
       public void run()
       {
-         try
+         while (!stop)
          {
-            while (!stop)
+            Session sessionLocal = null;            
+            try
             {
+               // login
+               CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
+               sessionLocal = (SessionImpl)repository.login(credentials, "ws");
+               // prepare nodes
+               Node rootLocal = sessionLocal.getRootNode();
                Node threadNode = getRandomChild(rootLocal, "Thread*");
                if (threadNode != null)
                {
@@ -116,7 +114,7 @@
                      catch (InterruptedException e1)
                      {
                      }
-
+                     long time = System.currentTimeMillis();
                      QueryManager qman = sessionLocal.getWorkspace().getQueryManager();
 
                      Query q =
@@ -124,21 +122,23 @@
                            + "/%' and fn:name() = '" + word + "'", Query.SQL);
                      QueryResult res = q.execute();
                      long sqlsize = res.getNodes().getSize();
-                     log.info("Exp: " + count + "\t found:" + sqlsize);
+                     log.info("Exp: " + count + "\t found:" + sqlsize + " time: " + (System.currentTimeMillis() - time));
                   }
                }
             }
-
+            catch (Exception e)
+            {
+               log.error("An error occurs", e);
+            }
+            finally
+            {
+               if (sessionLocal != null)
+               {
+                  sessionLocal.logout();
+                  sessionLocal = null;                  
+               }
+            }            
          }
-         catch (RepositoryException e)
-         {
-            log.error(e);
-         }
-         catch (Exception e)
-         {
-            log.error(e);
-         }
-
       }
 
       private Node getRandomChild(Node parent, String pattern) throws RepositoryException

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestLoadIndexerQueryWithModes.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestLoadIndexerQueryWithModes.java	2010-01-21 14:39:42 UTC (rev 1529)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestLoadIndexerQueryWithModes.java	2010-01-21 14:39:48 UTC (rev 1530)
@@ -32,6 +32,7 @@
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
@@ -86,19 +87,11 @@
 
    private class QueryTask implements Runnable
    {
-      private SessionImpl sessionLocal;
 
-      private Node rootLocal;
-
       private Random random;
 
       public QueryTask() throws RepositoryException
       {
-         // login
-         CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
-         sessionLocal = (SessionImpl)repository.login(credentials, "ws");
-         // prepare nodes
-         rootLocal = sessionLocal.getRootNode();
          random = new Random();
       }
 
@@ -110,8 +103,14 @@
 
          while (!stop)
          {
+            Session sessionLocal = null;            
             try
             {
+               // login
+               CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
+               sessionLocal = (SessionImpl)repository.login(credentials, "ws");
+               // prepare nodes
+               Node rootLocal = sessionLocal.getRootNode();
                Node threadNode = getRandomChild(rootLocal, "Thread*");
                if (threadNode != null)
                {
@@ -143,16 +142,19 @@
                   }
                }
             }
-            catch (RepositoryException e)
+            catch (Exception e)
             {
                log.error(e);
             }
-            catch (Exception e)
+            finally
             {
-               log.error(e);
-            }
+               if (sessionLocal != null)
+               {
+                  sessionLocal.logout();
+                  sessionLocal = null;                  
+               }
+            }            
          }
-
       }
 
       private Node getRandomChild(Node parent, String pattern) throws RepositoryException

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestReadNWrite.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestReadNWrite.java	2010-01-21 14:39:42 UTC (rev 1529)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestReadNWrite.java	2010-01-21 14:39:48 UTC (rev 1530)
@@ -30,6 +30,7 @@
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
@@ -54,7 +55,7 @@
    private int threadReaderCount = 20;
 
    private final CountDownLatch doneSignal = new CountDownLatch(threadReaderCount + threadWriterCount);
-   
+
    private static final String[] words =
       new String[]{"private", "branch", "final", "string", "logging", "bottle", "property", "node", "repository",
          "exception", "cycle", "value", "index", "meaning", "strange", "words", "hello", "outline", "finest",
@@ -79,11 +80,13 @@
       // wait 4 minutes
       try
       {
-         //Thread.sleep(60000 * 4);
+         Thread.sleep(60000 * 4);
+         /*
          synchronized (this)
          {
             wait();
          }
+         */
       }
       catch (InterruptedException e)
       {
@@ -92,7 +95,7 @@
 
       stop = true;
       doneSignal.await();
-      System.exit(0);      
+      System.exit(0);
    }
 
    private class WriterTask implements Runnable
@@ -100,12 +103,6 @@
 
       private int id;
 
-      private SessionImpl sessionLocal;
-
-      private Node statisticNode;
-
-      private Node contentNode;
-
       private Random random;
 
       public WriterTask(int id) throws RepositoryException
@@ -113,14 +110,16 @@
          this.id = id;
          // login
          CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
-         sessionLocal = (SessionImpl)repository.login(credentials, "ws");
+         Session sessionLocal = (SessionImpl)repository.login(credentials, "ws");
          // prepare nodes
          Node root = sessionLocal.getRootNode();
          Node threadNode = root.addNode("Thread" + id);
-         statisticNode = threadNode.addNode(STATISTIC);
-         contentNode = threadNode.addNode(CONTENT);
+         threadNode.addNode(STATISTIC);
+         threadNode.addNode(CONTENT);
          random = new Random();
          sessionLocal.save();
+         sessionLocal.logout();
+         sessionLocal = null;
       }
 
       /**
@@ -132,23 +131,34 @@
          {
             while (!stop)
             {
-               long time = System.currentTimeMillis();
                // get any word
                int i = random.nextInt(words.length);
                String word = words[i] + id; // "hello12" if thread#12 is creating it
+               Session sessionLocal = null;
                try
                {
+                  CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
+                  sessionLocal = (SessionImpl)repository.login(credentials, "ws");
+                  long time = System.currentTimeMillis();
                   // update statistic
-                  updateStatistic(word);
+                  updateStatistic((Node)sessionLocal.getItem("/Thread" + id + "/" + STATISTIC), word);
                   // add actual node
-                  createTree().addNode(word);
+                  createTree((Node)sessionLocal.getItem("/Thread" + id + "/" + CONTENT)).addNode(word);
                   sessionLocal.save();
-                  System.out.println(Thread.currentThread() + " time : " + (System.currentTimeMillis() - time));
+                  log.info("Time : " + (System.currentTimeMillis() - time));
                }
-               catch (Exception e1)
+               catch (RepositoryException e)
                {
-                  log.error("An error occurs", e1);
+                  log.error(e);
                }
+               finally
+               {
+                  if (sessionLocal != null)
+                  {
+                     sessionLocal.logout();
+                     sessionLocal = null;
+                  }
+               }
 
                try
                {
@@ -175,7 +185,7 @@
        * @param word
        * @throws RepositoryException
        */
-      private void updateStatistic(String word) throws RepositoryException
+      private void updateStatistic(Node statisticNode, String word) throws RepositoryException
       {
          Node wordNode;
          long count = 0;
@@ -198,7 +208,7 @@
        * @return
        * @throws RepositoryException
        */
-      private Node createTree() throws RepositoryException
+      private Node createTree(Node contentNode) throws RepositoryException
       {
          // created node tree like: "./content/n123456/n1234567/n12345678"
          Node end;
@@ -233,19 +243,11 @@
 
    private class QueryTask implements Runnable
    {
-      private SessionImpl sessionLocal;
 
-      private Node rootLocal;
-
       private Random random;
 
       public QueryTask() throws RepositoryException
       {
-         // login
-         CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
-         sessionLocal = (SessionImpl)repository.login(credentials, "ws");
-         // prepare nodes
-         rootLocal = sessionLocal.getRootNode();
          random = new Random();
       }
 
@@ -256,8 +258,14 @@
       {
          while (!stop)
          {
+            Session sessionLocal = null;
             try
             {
+               // login
+               CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
+               sessionLocal = (SessionImpl)repository.login(credentials, "ws");
+               // prepare nodes
+               Node rootLocal = sessionLocal.getRootNode();
                Node threadNode = getRandomChild(rootLocal, "Thread*");
                if (threadNode != null)
                {
@@ -284,14 +292,11 @@
                      try
                      {
                         assertTrue("Exp: " + count + "\t found:" + sqlsize, sqlsize >= count);
-                        System.out.println(Thread.currentThread() + " size : " + sqlsize + " time : "
-                           + (System.currentTimeMillis() - time));
+                        log.info("Size : " + sqlsize + " time : " + (System.currentTimeMillis() - time));
                      }
                      catch (AssertionFailedError e)
                      {
-                        System.out
-                           .println((Thread.currentThread() + " error : " + e.getMessage() + " time : " + (System
-                              .currentTimeMillis() - time)));
+                        log.info("Error : " + e.getMessage() + " time : " + (System.currentTimeMillis() - time));
                      }
                   }
                }
@@ -300,6 +305,14 @@
             {
                log.error("An error occurs", e);
             }
+            finally
+            {
+               if (sessionLocal != null)
+               {
+                  sessionLocal.logout();
+                  sessionLocal = null;
+               }
+            }
          }
          doneSignal.countDown();
       }



More information about the exo-jcr-commits mailing list