[exo-jcr-commits] exo-jcr SVN: r1898 - in jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load: query and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Feb 18 08:25:20 EST 2010
Author: skabashnyuk
Date: 2010-02-18 08:25:20 -0500 (Thu, 18 Feb 2010)
New Revision: 1898
Added:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractAvgResponseTimeTest.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/JcrQueryAvgResponseTimeTest.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavAvgResponseTimeTest.java
Removed:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractAvgResponceTimeTest.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/JcrQueryAvgResponceTimeTest.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavAvgResponceTimeTest.java
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractTestAgent.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavTestAgent.java
Log:
EXOJCR-510 : Added more statistical information to the result: now it shows, ammount of work minimum, maximum, average, stddev of response time. E
Deleted: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractAvgResponceTimeTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractAvgResponceTimeTest.java 2010-02-18 13:23:36 UTC (rev 1897)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractAvgResponceTimeTest.java 2010-02-18 13:25:20 UTC (rev 1898)
@@ -1,140 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.cluster.load;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Random;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author <a href="mailto:Sergey.Kabashnyuk at exoplatform.org">Sergey Kabashnyuk</a>
- * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
- *
- */
-public abstract class AbstractAvgResponceTimeTest
-{
-
- private final int iterationGrowingPoll;
-
- private final int iterationTime;
-
- private final int initialSize;
-
- private final int readValue;
-
- /**
- * @param iterationGrowingPoll
- * @param iterationTime
- * @param initialSize
- */
- public AbstractAvgResponceTimeTest(int iterationGrowingPoll, int iterationTime, int initialSize, int readValue)
- {
- super();
- this.iterationGrowingPoll = iterationGrowingPoll;
- this.iterationTime = iterationTime;
- this.initialSize = initialSize;
- this.readValue = readValue;
- }
-
- public void testResponce() throws Exception
- {
- final List<NodeInfo> nodesPath = new ArrayList<NodeInfo>();
- //start from 1 thread
- int threadCount = initialSize;
-
- Random random = new Random();
-
- while (true)
- {
-
- final List<WorkerResult> responceResults = Collections.synchronizedList(new ArrayList<WorkerResult>());
-
- ExecutorService threadPool = Executors.newFixedThreadPool(threadCount);
- CountDownLatch startSignal = new CountDownLatch(1);
- AbstractTestAgent[] testAgents = new AbstractTestAgent[threadCount];
- //pool initialization
- for (int i = 0; i < threadCount; i++)
- {
- testAgents[i] = getAgent(nodesPath, responceResults, startSignal, readValue, random);
- threadPool.execute(testAgents[i]);
-
- }
- responceResults.clear();
- startSignal.countDown();//let all threads proceed
-
- Thread.sleep(iterationTime);
-
- threadPool.shutdown();
- for (int i = 0; i < testAgents.length; i++)
- {
- testAgents[i].setShouldStop(true);
- }
- //wait 10 minutes
- threadPool.awaitTermination(60 * 10, TimeUnit.SECONDS);
- dumpResults(responceResults, threadCount);
- threadCount += iterationGrowingPoll;
- }
- }
-
- /**
- * Create new agent
- * @param nodesPath
- * @param responceResults
- * @param startSignal
- * @param READ_VALUE
- * @param random
- * @return
- */
- protected abstract AbstractTestAgent getAgent(List<NodeInfo> nodesPath, List<WorkerResult> responceResults,
- CountDownLatch startSignal, int readValue, Random random);
-
- private void dumpResults(List<WorkerResult> responceResults, int threadCount)
- {
- long sum_read = 0;
- long sum_write = 0;
- long read = 0;
- long write = 0;
- for (WorkerResult workerResult : responceResults)
- {
-
- if (workerResult.isRead())
- {
- read++;
- sum_read += workerResult.getResponceTime();
- }
- else
- {
- write++;
- sum_write += workerResult.getResponceTime();
- }
- }
- if ((read + write) > 0)
- {
- System.out.println(" ThreadCount= " + threadCount + " Read=" + read + " Write=" + write + " value "
- + (read * 100 / (read + write)) + " Avg read resp=" + (read > 0 ? (sum_read / read) : 0)
- + " Avg write resp=" + (write > 0 ? (sum_write / write) : 0));
- }
- responceResults.clear();
- }
-}
Copied: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractAvgResponseTimeTest.java (from rev 1827, jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractAvgResponceTimeTest.java)
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractAvgResponseTimeTest.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractAvgResponseTimeTest.java 2010-02-18 13:25:20 UTC (rev 1898)
@@ -0,0 +1,331 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.cluster.load;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk at exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public abstract class AbstractAvgResponseTimeTest
+{
+
+ private final int iterationGrowingPoll;
+
+ private final int iterationTime;
+
+ private final int initialSize;
+
+ private final int readValue;
+
+ private final DecimalFormat df = new DecimalFormat("#####.##");
+
+ /**
+ * @param iterationGrowingPoll
+ * @param iterationTime
+ * @param initialSize
+ */
+ public AbstractAvgResponseTimeTest(int iterationGrowingPoll, int iterationTime, int initialSize, int readValue)
+ {
+ super();
+ this.iterationGrowingPoll = iterationGrowingPoll;
+ this.iterationTime = iterationTime;
+ this.initialSize = initialSize;
+ this.readValue = readValue;
+ }
+
+ public void testResponce() throws Exception
+ {
+ final List<NodeInfo> nodesPath = new LinkedList<NodeInfo>();
+ //start from 1 thread
+ int threadCount = initialSize;
+
+ Random random = new Random();
+
+ while (true)
+ {
+ //test init
+ setUp();
+
+ final List<WorkerResult> responceResults = new LinkedList<WorkerResult>();
+
+ ExecutorService threadPool = Executors.newFixedThreadPool(threadCount);
+ CountDownLatch startSignal = new CountDownLatch(1);
+ AbstractTestAgent[] testAgents = new AbstractTestAgent[threadCount];
+
+ //pool initialization
+ for (int i = 0; i < threadCount; i++)
+ {
+ testAgents[i] = getAgent(nodesPath, responceResults, startSignal, readValue, random);
+ //init agent
+ testAgents[i].prepare();
+ threadPool.execute(testAgents[i]);
+
+ }
+ responceResults.clear();
+ startSignal.countDown();//let all threads proceed
+
+ Thread.sleep(iterationTime);
+
+ threadPool.shutdown();
+ for (int i = 0; i < testAgents.length; i++)
+ {
+ testAgents[i].setShouldStop(true);
+ }
+ //wait 10 minutes
+ threadPool.awaitTermination(60 * 10, TimeUnit.SECONDS);
+ dumpResults(responceResults, threadCount, iterationTime);
+ threadCount += iterationGrowingPoll;
+ tearDown();
+ }
+ }
+
+ /**
+ * Made some actions before iteration run
+ * @throws Exception
+ */
+ protected void setUp() throws Exception
+ {
+
+ }
+
+ /**
+ * Made some actions after iteration finished
+ * @throws Exception
+ */
+ protected void tearDown() throws Exception
+ {
+
+ }
+
+ /**
+ * Create new agent
+ * @param nodesPath
+ * @param responceResults
+ * @param startSignal
+ * @param READ_VALUE
+ * @param random
+ * @return
+ */
+ protected abstract AbstractTestAgent getAgent(List<NodeInfo> nodesPath, List<WorkerResult> responceResults,
+ CountDownLatch startSignal, int readValue, Random random);
+
+ private void dumpResults(List<WorkerResult> responceResults, int threadCount, int iterationTime)
+ {
+
+ List<Double> readResult = new ArrayList<Double>();
+ List<Double> writeResult = new ArrayList<Double>();
+
+ for (WorkerResult workerResult : responceResults)
+ {
+ if (workerResult == null)
+ {
+ continue;
+ }
+ if (workerResult.isRead())
+ {
+ // read++;
+ // sum_read += workerResult.getResponceTime();
+ readResult.add(new Double(workerResult.getResponceTime()));
+ }
+ else
+ {
+ writeResult.add(new Double(workerResult.getResponceTime()));
+ }
+ }
+ ResultInfo readResultInfo = new ResultInfo(readResult);
+ readResultInfo.calculate();
+
+ ResultInfo writeResultInfo = new ResultInfo(writeResult);
+ writeResultInfo.calculate();
+
+ StringBuffer result = new StringBuffer();
+ result.append("ThreadCount= ").append(threadCount);
+ result.append(" TPS = ").append(
+ Math.round(((readResultInfo.getResultCount() + writeResultInfo.getResultCount()) * 1000) / iterationTime));
+ result.append(" Total read= ").append(df.format(readResultInfo.getResultCount()));
+ result.append(" Max= ").append(df.format(readResultInfo.getMaxValue()));
+ result.append(" Min= ").append(df.format(readResultInfo.getMinValue()));
+ result.append(" Avg= ").append(df.format(readResultInfo.getAvgValue()));
+ result.append(" StdDev= ").append(df.format(readResultInfo.getStdDevValue()));
+ result.append(" Total write= ").append(writeResultInfo.getResultCount());
+ result.append(" Max= ").append(df.format(writeResultInfo.getMaxValue()));
+ result.append(" Min= ").append(df.format(writeResultInfo.getMinValue()));
+ result.append(" Avg= ").append(df.format(writeResultInfo.getAvgValue()));
+ result.append(" StdDev= ").append(df.format(writeResultInfo.getStdDevValue()));
+
+ System.out.println(result.toString());
+ // long sum_read = 0;
+ // long sum_write = 0;
+ // long read = 0;
+ // long write = 0;
+ // for (WorkerResult workerResult : responceResults)
+ // {
+ // if (workerResult == null)
+ // {
+ // continue;
+ // }
+ // if (workerResult.isRead())
+ // {
+ // read++;
+ // sum_read += workerResult.getResponceTime();
+ // }
+ // else
+ // {
+ // write++;
+ // sum_write += workerResult.getResponceTime();
+ // }
+ // }
+ // if ((read + write) > 0)
+ // {
+ // StringBuffer result = new StringBuffer();
+ // result.append("ThreadCount= ").append(threadCount);
+ // result.append(" TPS = ").append(Math.round(((read + write) * 1000) / iterationTime));
+ // if (read > 0)
+ // {
+ // result.append(" Total read = ").append(read);
+ //
+ // result.append(" Avg read response = ").append((sum_read / read));
+ // }
+ // if (write > 0)
+ // {
+ // result.append(" Total write = ").append(write);
+ //
+ // result.append(" Avg write response = ").append((sum_write / write));
+ // }
+ //
+ // System.out.println(result.toString());
+ // }
+ responceResults.clear();
+ }
+
+ public class ResultInfo
+ {
+ private double maxValue;
+
+ private double minValue;
+
+ private double avgValue;
+
+ private double stdDevValue;
+
+ private List<Double> data;
+
+ /**
+ * @param data
+ */
+ public ResultInfo(List<Double> data)
+ {
+ super();
+ this.data = data;
+ }
+
+ private void calculate()
+ {
+ final int n = data.size();
+ if (n < 2)
+ {
+ this.stdDevValue = Double.NaN;
+ this.avgValue = data.get(0);
+ this.maxValue = data.get(0);
+ this.minValue = data.get(0);
+ }
+ else
+ {
+ this.avgValue = data.get(0);
+ this.maxValue = data.get(0);
+ this.minValue = data.get(0);
+ double sum = 0;
+ for (int i = 1; i < data.size(); i++)
+ {
+ Double currValue = data.get(i);
+ if (currValue > maxValue)
+ {
+ maxValue = currValue;
+ }
+ if (currValue < minValue)
+ {
+ minValue = currValue;
+ }
+ double newavg = avgValue + (currValue - avgValue) / (i + 1);
+ sum += (currValue - avgValue) * (currValue - newavg);
+ this.avgValue = newavg;
+ }
+ // Change to ( n - 1 ) to n if you have complete data instead of a sample.
+ this.stdDevValue = Math.sqrt(sum / (n - 1));
+ }
+ }
+
+ /**
+ * @return the stdDevValue
+ */
+ public double getStdDevValue()
+ {
+ return stdDevValue;
+ }
+
+ /**
+ * @return the maxValue
+ */
+ public double getMaxValue()
+ {
+ return maxValue;
+ }
+
+ /**
+ * @return the minValue
+ */
+ public double getMinValue()
+ {
+ return minValue;
+ }
+
+ /**
+ * @return the avgValue
+ */
+ public double getAvgValue()
+ {
+ return avgValue;
+ }
+
+ /**
+ * @return the data
+ */
+ public List<Double> getData()
+ {
+ return data;
+ }
+
+ public long getResultCount()
+ {
+ return data.size();
+ }
+
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractAvgResponseTimeTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractTestAgent.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractTestAgent.java 2010-02-18 13:23:36 UTC (rev 1897)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractTestAgent.java 2010-02-18 13:25:20 UTC (rev 1898)
@@ -59,15 +59,23 @@
* Do read
* @return
*/
- public abstract List<WorkerResult> doRead(List<NodeInfo> nodesPath);
+ public abstract void doRead(List<NodeInfo> nodesPath, List<WorkerResult> responseResults);
/**
* Do write
* @return
*/
- public abstract List<WorkerResult> doWrite(List<NodeInfo> nodesPath);
+ public abstract void doWrite(List<NodeInfo> nodesPath, List<WorkerResult> responseResults);
/**
+ * Prepare agent
+ */
+ protected void prepare()
+ {
+
+ }
+
+ /**
* @see java.lang.Runnable#run()
*/
public void run()
@@ -75,16 +83,17 @@
try
{
startSignal.await();
+
while (!shouldStop)
{
- if (random.nextInt(100) > readValue)
+ if (nodesPath.size() < 10 || random.nextInt(100) > readValue)
{
- responceResults.addAll(doWrite(nodesPath));
+ doWrite(nodesPath, responceResults);
}
else
{
- responceResults.addAll(doRead(nodesPath));
+ doRead(nodesPath, responceResults);
}
}
}
Deleted: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/JcrQueryAvgResponceTimeTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/JcrQueryAvgResponceTimeTest.java 2010-02-18 13:23:36 UTC (rev 1897)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/JcrQueryAvgResponceTimeTest.java 2010-02-18 13:25:20 UTC (rev 1898)
@@ -1,344 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.cluster.load.query;
-
-import org.exoplatform.services.jcr.JcrImplBaseTest;
-import org.exoplatform.services.jcr.cluster.load.AbstractAvgResponceTimeTest;
-import org.exoplatform.services.jcr.cluster.load.AbstractTestAgent;
-import org.exoplatform.services.jcr.cluster.load.NodeInfo;
-import org.exoplatform.services.jcr.cluster.load.WorkerResult;
-import org.exoplatform.services.jcr.core.CredentialsImpl;
-import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
-import org.jboss.cache.CacheException;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
-import java.util.UUID;
-import java.util.concurrent.CountDownLatch;
-
-import javax.jcr.AccessDeniedException;
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.ItemExistsException;
-import javax.jcr.LoginException;
-import javax.jcr.NoSuchWorkspaceException;
-import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.nodetype.NoSuchNodeTypeException;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryResult;
-import javax.jcr.version.VersionException;
-
-/**
- * @author <a href="mailto:Sergey.Kabashnyuk at exoplatform.org">Sergey Kabashnyuk</a>
- * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
- *
- */
-public class JcrQueryAvgResponceTimeTest extends JcrImplBaseTest
-{
-
- /**
- * 2min default time of work of one iteration.
- */
- private static final int ITERATION_TIME = 60 * 1000;
-
- /**
- * How much thread will be added on the next iteration.
- */
- private static final int ITERATION_GROWING_POLL = 15;
-
- /**
- * Number between 0 and 100 show % how many read operations.
- */
- private static final int READ_VALUE = 90;
-
- 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",
- "basetest", "writer"};
-
- public static final String FIELDNAME_COUNT = "count";
-
- public static final String FIELDNAME_CONTENT = "Content";
-
- public static final String FIELDNAME_STATISTIC = "Statistic";
-
- private static final String TEST_ROOT = "JcrQueryAvgResponceTimeTest";
-
- public void testname() throws Exception
- {
- QueryAvgResponceTimeTest test =
- new QueryAvgResponceTimeTest(repository, ITERATION_GROWING_POLL, ITERATION_TIME, 5, READ_VALUE);
- test.testResponce();
-
- }
-
- private class QueryAvgResponceTimeTest extends AbstractAvgResponceTimeTest
- {
-
- private final RepositoryImpl repository;
-
- /**
- * @param iterationGrowingPoll
- * @param iterationTime
- * @param initialSize
- * @param readValue
- */
- public QueryAvgResponceTimeTest(RepositoryImpl repository, int iterationGrowingPoll, int iterationTime,
- int initialSize, int readValue)
- {
- super(iterationGrowingPoll, iterationTime, initialSize, readValue);
- this.repository = repository;
- }
-
- /**
- * @see org.exoplatform.services.jcr.cluster.load.AbstractAvgResponceTimeTest#getAgent(java.util.List, java.util.List, java.util.concurrent.CountDownLatch, int, java.util.Random)
- */
- @Override
- protected AbstractTestAgent getAgent(List<NodeInfo> nodesPath, List<WorkerResult> responceResults,
- CountDownLatch startSignal, int readValue, Random random)
- {
- return new QueryTestAgent(repository, nodesPath, responceResults, startSignal, readValue, random);
- }
-
- }
-
- private class QueryTestAgent extends AbstractTestAgent
- {
- private final RepositoryImpl repository;
-
- private UUID threadUUID;
-
- /**
- * @param repository
- * @param nodesPath
- * @param responceResults
- * @param startSignal
- * @param READ_VALUE
- * @param random
- */
- public QueryTestAgent(RepositoryImpl repository, List<NodeInfo> nodesPath, List<WorkerResult> responceResults,
- CountDownLatch startSignal, int readValue, Random random)
- {
- super(nodesPath, responceResults, startSignal, readValue, random);
- this.threadUUID = UUID.randomUUID();
- this.repository = repository;
- initRoot();
- }
-
- /**
- * @param repository
- * @throws LoginException
- * @throws NoSuchWorkspaceException
- * @throws RepositoryException
- * @throws ItemExistsException
- * @throws PathNotFoundException
- * @throws VersionException
- * @throws ConstraintViolationException
- * @throws LockException
- * @throws AccessDeniedException
- * @throws InvalidItemStateException
- * @throws NoSuchNodeTypeException
- */
- private void initRoot()
- {
- int maxAttempts = 10;
- CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
- for (int i = 0; i < maxAttempts; i++)
- {
- boolean isSuccessful = false;
- Session sessionLocal = null;
- try
- {
-
- sessionLocal = repository.login(credentials, "ws");
- // prepare nodes
- Node wsRoot = sessionLocal.getRootNode();
- Node threadNode = getOrCreateNode(getOrCreateNode(TEST_ROOT, wsRoot), threadUUID);
- sessionLocal.save();
- sessionLocal.logout();
- sessionLocal = null;
- isSuccessful = true;
- }
- catch (CacheException e)
- {
- log.error("error on creating root attempt " + i + " from " + maxAttempts);
- //ignore
- }
- catch (RepositoryException e)
- {
- log.error("error on creating root attempt " + i + " from " + maxAttempts);
- }
- finally
- {
- if (sessionLocal != null)
- {
- try
- {
- sessionLocal.refresh(false);
- sessionLocal.logout();
- }
- catch (RepositoryException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- if (isSuccessful)
- {
- break;
- }
- }
-
- }
-
- /**
- * @see org.exoplatform.services.jcr.cluster.load.AbstractTestAgent#doRead(java.util.List)
- */
- @Override
- public List<WorkerResult> doRead(List<NodeInfo> nodesPath)
- {
- List<WorkerResult> result = new ArrayList<WorkerResult>();
- Session sessionLocal = null;
- try
- {
- // login
- CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
-
- sessionLocal = repository.login(credentials, "ws");
- Node testRoot = sessionLocal.getRootNode().getNode(TEST_ROOT);
- // prepare nodes
- int i = random.nextInt(words.length);
- String word = words[i];
- Query q =
- sessionLocal.getWorkspace().getQueryManager().createQuery(
- "SELECT * FROM nt:base WHERE " + FIELDNAME_CONTENT + "='" + word + "' AND jcr:path LIKE '"
- + testRoot.getPath() + "/%'", Query.SQL);
- long start = System.currentTimeMillis();
- QueryResult res = q.execute();
- long sqlsize = res.getNodes().getSize();
- result.add(new WorkerResult(true, System.currentTimeMillis() - start));
- //log.info(word + " found:" + sqlsize + " time=" + (System.currentTimeMillis() - start));
-
- }
- catch (Exception e)
- {
- log.error(e);
- }
- finally
- {
- if (sessionLocal != null)
- {
- sessionLocal.logout();
- sessionLocal = null;
- }
- }
- return result;
- }
-
- /**
- * @see org.exoplatform.services.jcr.cluster.load.AbstractTestAgent#doWrite(java.util.List)
- */
- @Override
- public List<WorkerResult> doWrite(List<NodeInfo> nodesPath)
- {
- List<WorkerResult> result = new ArrayList<WorkerResult>();
- // get any word
- int i = random.nextInt(words.length);
- String word = words[i];
-
- Session sessionLocal = null;
- try
- {
- CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
- sessionLocal = repository.login(credentials, "ws");
- long start = System.currentTimeMillis();
- Node threadNode = getOrCreateNode(getOrCreateNode(TEST_ROOT, sessionLocal.getRootNode()), threadUUID);
- addCountent(threadNode, UUID.randomUUID(), word);
- sessionLocal.save();
- result.add(new WorkerResult(false, System.currentTimeMillis() - start));
- //log.info(word + " time : " + (System.currentTimeMillis() - start));
- }
- catch (Exception e1)
- {
- if (sessionLocal != null)
- {
- // discard session changes
- try
- {
- sessionLocal.refresh(false);
- }
- catch (RepositoryException e)
- {
- log.error("An error occurs", e);
- }
- }
- log.error("An error occurs", e1);
- }
- finally
- {
- if (sessionLocal != null)
- {
- sessionLocal.logout();
- sessionLocal = null;
- }
- }
- return result;
- }
-
- private void addCountent(Node testRoot, UUID nodePath, String content) throws RepositoryException
- {
- Node l5 = getOrCreateNode(testRoot, nodePath);
- l5.setProperty(FIELDNAME_CONTENT, content);
- }
-
- private Node getOrCreateNode(Node testRoot, UUID nodePath) throws RepositoryException
- {
- String uuidPath = nodePath.toString();
- Node l1 = getOrCreateNode(uuidPath.substring(0, 8), testRoot);
- Node l2 = getOrCreateNode(uuidPath.substring(9, 13), l1);
- Node l3 = getOrCreateNode(uuidPath.substring(14, 18), l2);
- Node l4 = getOrCreateNode(uuidPath.substring(19, 23), l3);
- return getOrCreateNode(uuidPath.substring(24), l4);
-
- }
-
- /**
- * Gets or creates node
- *
- * @param name
- * @param parent
- * @return
- * @throws RepositoryException
- */
- private Node getOrCreateNode(String name, Node parent) throws RepositoryException
- {
- if (parent.hasNode(name))
- {
- return parent.getNode(name);
- }
- return parent.addNode(name);
- }
- }
-}
Copied: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/JcrQueryAvgResponseTimeTest.java (from rev 1827, jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/JcrQueryAvgResponceTimeTest.java)
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/JcrQueryAvgResponseTimeTest.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/JcrQueryAvgResponseTimeTest.java 2010-02-18 13:25:20 UTC (rev 1898)
@@ -0,0 +1,339 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.cluster.load.query;
+
+import org.exoplatform.services.jcr.JcrImplBaseTest;
+import org.exoplatform.services.jcr.cluster.load.AbstractAvgResponseTimeTest;
+import org.exoplatform.services.jcr.cluster.load.AbstractTestAgent;
+import org.exoplatform.services.jcr.cluster.load.NodeInfo;
+import org.exoplatform.services.jcr.cluster.load.WorkerResult;
+import org.exoplatform.services.jcr.core.CredentialsImpl;
+import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
+import org.jboss.cache.CacheException;
+
+import java.util.List;
+import java.util.Random;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.ItemExistsException;
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
+import javax.jcr.version.VersionException;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk at exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class JcrQueryAvgResponseTimeTest extends JcrImplBaseTest
+{
+
+ /**
+ * 2min default time of work of one iteration.
+ */
+ private static final int ITERATION_TIME = 60 * 1000;
+
+ /**
+ * How much thread will be added on the next iteration.
+ */
+ private static final int ITERATION_GROWING_POLL = 15;
+
+ /**
+ * Number between 0 and 100 show % how many read operations.
+ */
+ private static final int READ_VALUE = 90;
+
+ 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",
+ "basetest", "writer"};
+
+ public static final String FIELDNAME_COUNT = "count";
+
+ public static final String FIELDNAME_CONTENT = "Content";
+
+ public static final String FIELDNAME_STATISTIC = "Statistic";
+
+ private static final String TEST_ROOT = "JcrQueryAvgResponceTimeTest";
+
+ public void testname() throws Exception
+ {
+ QueryAvgResponceTimeTest test =
+ new QueryAvgResponceTimeTest(repository, ITERATION_GROWING_POLL, ITERATION_TIME, 5, READ_VALUE);
+ test.testResponce();
+
+ }
+
+ private class QueryAvgResponceTimeTest extends AbstractAvgResponseTimeTest
+ {
+
+ private final RepositoryImpl repository;
+
+ /**
+ * @param iterationGrowingPoll
+ * @param iterationTime
+ * @param initialSize
+ * @param readValue
+ */
+ public QueryAvgResponceTimeTest(RepositoryImpl repository, int iterationGrowingPoll, int iterationTime,
+ int initialSize, int readValue)
+ {
+ super(iterationGrowingPoll, iterationTime, initialSize, readValue);
+ this.repository = repository;
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.cluster.load.AbstractAvgResponseTimeTest#getAgent(java.util.List, java.util.List, java.util.concurrent.CountDownLatch, int, java.util.Random)
+ */
+ @Override
+ protected AbstractTestAgent getAgent(List<NodeInfo> nodesPath, List<WorkerResult> responceResults,
+ CountDownLatch startSignal, int readValue, Random random)
+ {
+ return new QueryTestAgent(repository, nodesPath, responceResults, startSignal, readValue, random);
+ }
+
+ }
+
+ private class QueryTestAgent extends AbstractTestAgent
+ {
+ private final RepositoryImpl repository;
+
+ private UUID threadUUID;
+
+ /**
+ * @param repository
+ * @param nodesPath
+ * @param responceResults
+ * @param startSignal
+ * @param READ_VALUE
+ * @param random
+ */
+ public QueryTestAgent(RepositoryImpl repository, List<NodeInfo> nodesPath, List<WorkerResult> responceResults,
+ CountDownLatch startSignal, int readValue, Random random)
+ {
+ super(nodesPath, responceResults, startSignal, readValue, random);
+ this.threadUUID = UUID.randomUUID();
+ this.repository = repository;
+ initRoot();
+ }
+
+ /**
+ * @param repository
+ * @throws LoginException
+ * @throws NoSuchWorkspaceException
+ * @throws RepositoryException
+ * @throws ItemExistsException
+ * @throws PathNotFoundException
+ * @throws VersionException
+ * @throws ConstraintViolationException
+ * @throws LockException
+ * @throws AccessDeniedException
+ * @throws InvalidItemStateException
+ * @throws NoSuchNodeTypeException
+ */
+ private void initRoot()
+ {
+ int maxAttempts = 10;
+ CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
+ for (int i = 0; i < maxAttempts; i++)
+ {
+ boolean isSuccessful = false;
+ Session sessionLocal = null;
+ try
+ {
+
+ sessionLocal = repository.login(credentials, "ws");
+ // prepare nodes
+ Node wsRoot = sessionLocal.getRootNode();
+ Node threadNode = getOrCreateNode(getOrCreateNode(TEST_ROOT, wsRoot), threadUUID);
+ sessionLocal.save();
+ sessionLocal.logout();
+ sessionLocal = null;
+ isSuccessful = true;
+ }
+ catch (CacheException e)
+ {
+ log.error("error on creating root attempt " + i + " from " + maxAttempts);
+ //ignore
+ }
+ catch (RepositoryException e)
+ {
+ log.error("error on creating root attempt " + i + " from " + maxAttempts);
+ }
+ finally
+ {
+ if (sessionLocal != null)
+ {
+ try
+ {
+ sessionLocal.refresh(false);
+ sessionLocal.logout();
+ }
+ catch (RepositoryException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ if (isSuccessful)
+ {
+ break;
+ }
+ }
+
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.cluster.load.AbstractTestAgent#doRead(java.util.List)
+ */
+ @Override
+ public void doRead(List<NodeInfo> nodesPath, List<WorkerResult> responseResults)
+ {
+ Session sessionLocal = null;
+ try
+ {
+ // login
+ CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
+
+ sessionLocal = repository.login(credentials, "ws");
+ Node testRoot = sessionLocal.getRootNode().getNode(TEST_ROOT);
+ // prepare nodes
+ int i = random.nextInt(words.length);
+ String word = words[i];
+ Query q =
+ sessionLocal.getWorkspace().getQueryManager().createQuery(
+ "SELECT * FROM nt:base WHERE " + FIELDNAME_CONTENT + "='" + word + "' AND jcr:path LIKE '"
+ + testRoot.getPath() + "/%'", Query.SQL);
+ long start = System.currentTimeMillis();
+ QueryResult res = q.execute();
+ long sqlsize = res.getNodes().getSize();
+ responseResults.add(new WorkerResult(true, System.currentTimeMillis() - start));
+ //log.info(word + " found:" + sqlsize + " time=" + (System.currentTimeMillis() - start));
+
+ }
+ catch (Exception e)
+ {
+ log.error(e);
+ }
+ finally
+ {
+ if (sessionLocal != null)
+ {
+ sessionLocal.logout();
+ sessionLocal = null;
+ }
+ }
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.cluster.load.AbstractTestAgent#doWrite(java.util.List)
+ */
+ @Override
+ public void doWrite(List<NodeInfo> nodesPath, List<WorkerResult> responseResults)
+ {
+ // get any word
+ int i = random.nextInt(words.length);
+ String word = words[i];
+
+ Session sessionLocal = null;
+ try
+ {
+ CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
+ sessionLocal = repository.login(credentials, "ws");
+ long start = System.currentTimeMillis();
+ Node threadNode = getOrCreateNode(getOrCreateNode(TEST_ROOT, sessionLocal.getRootNode()), threadUUID);
+ addCountent(threadNode, UUID.randomUUID(), word);
+ sessionLocal.save();
+ responseResults.add(new WorkerResult(false, System.currentTimeMillis() - start));
+ //log.info(word + " time : " + (System.currentTimeMillis() - start));
+ }
+ catch (Exception e1)
+ {
+ if (sessionLocal != null)
+ {
+ // discard session changes
+ try
+ {
+ sessionLocal.refresh(false);
+ }
+ catch (RepositoryException e)
+ {
+ log.error("An error occurs", e);
+ }
+ }
+ log.error("An error occurs", e1);
+ }
+ finally
+ {
+ if (sessionLocal != null)
+ {
+ sessionLocal.logout();
+ sessionLocal = null;
+ }
+ }
+ }
+
+ private void addCountent(Node testRoot, UUID nodePath, String content) throws RepositoryException
+ {
+ Node l5 = getOrCreateNode(testRoot, nodePath);
+ l5.setProperty(FIELDNAME_CONTENT, content);
+ }
+
+ private Node getOrCreateNode(Node testRoot, UUID nodePath) throws RepositoryException
+ {
+ String uuidPath = nodePath.toString();
+ Node l1 = getOrCreateNode(uuidPath.substring(0, 8), testRoot);
+ Node l2 = getOrCreateNode(uuidPath.substring(9, 13), l1);
+ Node l3 = getOrCreateNode(uuidPath.substring(14, 18), l2);
+ Node l4 = getOrCreateNode(uuidPath.substring(19, 23), l3);
+ return getOrCreateNode(uuidPath.substring(24), l4);
+
+ }
+
+ /**
+ * Gets or creates node
+ *
+ * @param name
+ * @param parent
+ * @return
+ * @throws RepositoryException
+ */
+ private Node getOrCreateNode(String name, Node parent) throws RepositoryException
+ {
+ if (parent.hasNode(name))
+ {
+ return parent.getNode(name);
+ }
+ return parent.addNode(name);
+ }
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/JcrQueryAvgResponseTimeTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavAvgResponceTimeTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavAvgResponceTimeTest.java 2010-02-18 13:23:36 UTC (rev 1897)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavAvgResponceTimeTest.java 2010-02-18 13:25:20 UTC (rev 1898)
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.cluster.load.webdav;
-
-import junit.framework.TestCase;
-
-import org.exoplatform.services.jcr.cluster.load.AbstractAvgResponceTimeTest;
-import org.exoplatform.services.jcr.cluster.load.AbstractTestAgent;
-import org.exoplatform.services.jcr.cluster.load.NodeInfo;
-import org.exoplatform.services.jcr.cluster.load.WorkerResult;
-
-import java.util.List;
-import java.util.Random;
-import java.util.concurrent.CountDownLatch;
-
-/**
- * @author <a href="mailto:Sergey.Kabashnyuk at exoplatform.org">Sergey Kabashnyuk</a>
- * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
- *
- */
-public class WebDavAvgResponceTimeTest extends TestCase
-{
-
- /**
- * 2min default time of work of one iteration.
- */
- private static final int ITERATION_TIME = 60 * 1000;
-
- /**
- * How much thread will be added on the next iteration.
- */
- private static final int ITERATION_GROWING_POLL = 5;
-
- /**
- * Number between 0 and 100 show % how many read operations.
- */
- private static final int READ_VALUE = 90;
-
- public void testWebDav() throws Exception
- {
- WebDavTest test = new WebDavTest(ITERATION_GROWING_POLL, ITERATION_TIME, 1, READ_VALUE);
- test.testResponce();
- }
-
- private class WebDavTest extends AbstractAvgResponceTimeTest
- {
- /**
- * @param iterationGrowingPoll
- * @param iterationTime
- * @param initialSize
- * @param readValue
- */
- public WebDavTest(int iterationGrowingPoll, int iterationTime, int initialSize, int readValue)
- {
- super(iterationGrowingPoll, iterationTime, initialSize, readValue);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @see org.exoplatform.services.jcr.cluster.load.AbstractAvgResponceTimeTest#getAgent(java.util.List, java.util.List, java.util.concurrent.CountDownLatch, int, java.util.Random)
- */
- @Override
- protected AbstractTestAgent getAgent(List<NodeInfo> nodesPath, List<WorkerResult> responceResults,
- CountDownLatch startSignal, int readValue, Random random)
- {
- return new WebDavTestAgent(nodesPath, responceResults, startSignal, readValue, random);
- }
-
- }
-}
Copied: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavAvgResponseTimeTest.java (from rev 1827, jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavAvgResponceTimeTest.java)
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavAvgResponseTimeTest.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavAvgResponseTimeTest.java 2010-02-18 13:25:20 UTC (rev 1898)
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.cluster.load.webdav;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.services.jcr.cluster.load.AbstractAvgResponseTimeTest;
+import org.exoplatform.services.jcr.cluster.load.AbstractTestAgent;
+import org.exoplatform.services.jcr.cluster.load.NodeInfo;
+import org.exoplatform.services.jcr.cluster.load.WorkerResult;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk at exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class WebDavAvgResponseTimeTest extends TestCase
+{
+
+ /**
+ * 2min default time of work of one iteration.
+ */
+ private static final int ITERATION_TIME = 60 * 1000;
+
+ /**
+ * How much thread will be added on the next iteration.
+ */
+ private static final int ITERATION_GROWING_POLL = 10;
+
+ /**
+ * Number between 0 and 100 show % how many read operations.
+ */
+ private static final int READ_VALUE = 90;
+
+ private static final String TEST_ROOT = "WebDavAvgResponseTimeTestRoot";
+
+ public void testWebDav() throws Exception
+ {
+ WebDavTest test = new WebDavTest(ITERATION_GROWING_POLL, ITERATION_TIME, 10, READ_VALUE);
+ test.testResponce();
+ }
+
+ private class WebDavTest extends AbstractAvgResponseTimeTest
+ {
+ private String iterationRoot;
+
+ private int counter;
+
+ /**
+ * @param iterationGrowingPoll
+ * @param iterationTime
+ * @param initialSize
+ * @param readValue
+ */
+ public WebDavTest(int iterationGrowingPoll, int iterationTime, int initialSize, int readValue)
+ {
+ super(iterationGrowingPoll, iterationTime, initialSize, readValue);
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.cluster.load.AbstractAvgResponseTimeTest#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception
+ {
+ // TODO Auto-generated method stub
+ super.setUp();
+ WebDavTestAgent setUpAgent = new WebDavTestAgent(null, null, null, null, 0, null);
+
+ String testRoot = setUpAgent.createDirIfAbsent("", TEST_ROOT, new ArrayList<WorkerResult>());
+ iterationRoot =
+ setUpAgent.createDirIfAbsent(testRoot, UUID.randomUUID().toString(), new ArrayList<WorkerResult>());
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.cluster.load.AbstractAvgResponseTimeTest#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.cluster.load.AbstractAvgResponseTimeTest#getAgent(java.util.List, java.util.List, java.util.concurrent.CountDownLatch, int, java.util.Random)
+ */
+ @Override
+ protected AbstractTestAgent getAgent(List<NodeInfo> nodesPath, List<WorkerResult> responceResults,
+ CountDownLatch startSignal, int readValue, Random random)
+ {
+ return new WebDavTestAgent(iterationRoot, nodesPath, responceResults, startSignal, readValue, random);
+ }
+
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavAvgResponseTimeTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavTestAgent.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavTestAgent.java 2010-02-18 13:23:36 UTC (rev 1897)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavTestAgent.java 2010-02-18 13:25:20 UTC (rev 1898)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.jcr.cluster.load.webdav;
+import org.exoplatform.common.http.HTTPStatus;
import org.exoplatform.common.http.client.HTTPResponse;
import org.exoplatform.services.jcr.cluster.JCRWebdavConnection;
import org.exoplatform.services.jcr.cluster.load.NodeInfo;
@@ -26,6 +27,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
+import java.util.UUID;
import java.util.concurrent.CountDownLatch;
/**
@@ -36,12 +38,8 @@
public class WebDavTestAgent extends AbstractWebDavTestAgent
{
- private volatile static long l1FolderCount = 0;
+ private String testRoot;
- private String l1FolderName;
-
- private long l2FolderCount;
-
/**
* @param nodesPath
* @param responceResults
@@ -49,19 +47,20 @@
* @param READ_VALUE
* @param random
*/
- public WebDavTestAgent(List<NodeInfo> nodesPath, List<WorkerResult> responceResults, CountDownLatch startSignal,
- int READ_VALUE, Random random)
+ public WebDavTestAgent(String testRoot, List<NodeInfo> nodesPath, List<WorkerResult> responceResults,
+ CountDownLatch startSignal, int READ_VALUE, Random random)
{
super(nodesPath, responceResults, startSignal, READ_VALUE, random);
+ this.testRoot = testRoot;
}
/**
* @see org.exoplatform.services.jcr.cluster.load.AbstractTestAgent#doRead(java.util.List)
*/
@Override
- public List<WorkerResult> doRead(List<NodeInfo> nodesPath)
+ public void doRead(List<NodeInfo> nodesPath, List<WorkerResult> responseResults)
{
- List<WorkerResult> result = new ArrayList<WorkerResult>();
+ //List<WorkerResult> result = new ArrayList<WorkerResult>();
if (nodesPath.size() > 0)
{
@@ -76,14 +75,20 @@
}
long start = System.currentTimeMillis();
- JCRWebdavConnection conn = getNewConnection();
+ JCRWebdavConnection conn = null;
try
{
+ conn = getNewConnection();
HTTPResponse response = conn.getNode(readNodePath);
- if (response.getStatusCode() != 200)
+ if (response.getStatusCode() == HTTPStatus.OK)
{
+ responseResults.add(new WorkerResult(true, System.currentTimeMillis() - start));
+ }
+ else
+ {
System.out.println("Can not get (response code " + response.getStatusCode()
+ new String(response.getData()) + " ) node with path : " + readNodePath);
+
}
}
@@ -93,47 +98,52 @@
}
finally
{
- conn.stop();
+ if (conn != null)
+ {
+ conn.stop();
+ }
}
- result.add(new WorkerResult(true, System.currentTimeMillis() - start));
-
}
- return result;
}
/**
+ * @see org.exoplatform.services.jcr.cluster.load.AbstractTestAgent#prepare()
+ */
+ @Override
+ protected void prepare()
+ {
+ testRoot = createDirIfAbsent(testRoot, UUID.randomUUID().toString(), new ArrayList<WorkerResult>());
+ }
+
+ /**
* @see org.exoplatform.services.jcr.cluster.load.AbstractTestAgent#doWrite(java.util.List)
*/
@Override
- public List<WorkerResult> doWrite(List<NodeInfo> nodesPath)
+ public void doWrite(List<NodeInfo> nodesPath, List<WorkerResult> responseResults)
{
- List<WorkerResult> result = new ArrayList<WorkerResult>();
- long start = 0;
+
JCRWebdavConnection connection = null;
try
{
connection = getNewConnection();
+ String putFile =
+ createDirIfAbsent(testRoot, UUID.randomUUID().toString(), new ArrayList<WorkerResult>()) + "/file";
+ long start = System.currentTimeMillis();
+ HTTPResponse response = connection.addNode(putFile, ("__the_data_in_nt+file__").getBytes());
- if (l1FolderName == null || l2FolderCount == 100)
+ if (response.getStatusCode() == HTTPStatus.CREATED)
{
- l1FolderName = "folder" + (l1FolderCount++);
- start = System.currentTimeMillis();
- connection.addDir(l1FolderName);
- l2FolderCount = 0;
- result.add(new WorkerResult(false, System.currentTimeMillis() - start));
+ responseResults.add(new WorkerResult(false, System.currentTimeMillis() - start));
+ nodesPath.add(new NodeInfo(putFile, System.currentTimeMillis()));
}
- String path = l1FolderName + "/" + "node" + l2FolderCount++;
- start = System.currentTimeMillis();
- HTTPResponse response = connection.addNode(path, ("__the_data_in_nt+file__" + l2FolderCount).getBytes());
-
- if (response.getStatusCode() != 201)
+ else
{
System.out.println(Thread.currentThread().getName() + " : Can not add (response code "
- + response.getStatusCode() + new String(response.getData()) + " ) node with path : " + path);
+ + response.getStatusCode() + new String(response.getData()) + " ) file with path : " + putFile);
+
}
- result.add(new WorkerResult(false, System.currentTimeMillis() - start));
- nodesPath.add(new NodeInfo(path, System.currentTimeMillis()));
+
}
catch (Exception e)
{
@@ -146,6 +156,74 @@
connection.stop();
}
}
- return result;
}
+
+ /**
+ * Create WebDav node if not exist
+ * @param root
+ * @param name
+ * @param data
+ * @return
+ */
+ public String createDirIfAbsent(String root, String name, List<WorkerResult> result)
+ {
+ String path = root.length() == 0 ? name : root + "/" + name;
+ JCRWebdavConnection connection = null;
+ try
+ {
+ connection = getNewConnection();
+
+ long start = System.currentTimeMillis();
+ HTTPResponse nodeResponce = connection.getNode(path);
+ //add information about read
+ result.add(new WorkerResult(true, System.currentTimeMillis() - start));
+ if (nodeResponce.getStatusCode() != HTTPStatus.OK)
+ {
+ start = System.currentTimeMillis();
+ HTTPResponse addResponce = connection.addDir(path);
+ //add information about write
+
+ if (addResponce.getStatusCode() == HTTPStatus.CREATED)
+ {
+ result.add(new WorkerResult(false, System.currentTimeMillis() - start));
+ }
+ else
+ {
+ System.out.println(Thread.currentThread().getName() + " : Can not add (response code "
+ + addResponce.getStatusCode() + new String(addResponce.getData()) + " ) node with path : " + path);
+
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ System.out.println(e.getLocalizedMessage());
+ }
+ finally
+ {
+ if (connection != null)
+ {
+ connection.stop();
+ }
+ }
+ return path;
+ }
+
+ /**
+ * Create WebDav node if not exist
+ * @param root
+ * @param uuid
+ * @param data
+ * @return
+ */
+ public String createDirIfAbsent(String root, UUID uuid, List<WorkerResult> result)
+ {
+ String uuidPath = uuid.toString();
+ String l1 = createDirIfAbsent(root, uuidPath.substring(0, 8), result);
+ // String l2 = createDirIfAbsent(l1, uuidPath.substring(9, 13), result);
+ // String l3 = createDirIfAbsent(l2, uuidPath.substring(14, 18), result);
+ // String l4 = createDirIfAbsent(l3, uuidPath.substring(19, 23), result);
+ return createDirIfAbsent(l1, uuidPath.substring(9), result);
+
+ }
}
More information about the exo-jcr-commits
mailing list