Index: pom.xml
===================================================================
--- pom.xml (revision 948421)
+++ pom.xml (working copy)
@@ -61,12 +61,12 @@
org.apache.jackrabbit
jackrabbit-jcr-tests
- 2.1-SNAPSHOT
+ 2.2-SNAPSHOT
org.apache.jackrabbit
jackrabbit-core
- 2.1-SNAPSHOT
+ 2.2-SNAPSHOT
org.slf4j
Index: src/main/java/org/apache/jackrabbit/benchmark/LogoutAfterReadTest.java
===================================================================
--- src/main/java/org/apache/jackrabbit/benchmark/LogoutAfterReadTest.java (revision 0)
+++ src/main/java/org/apache/jackrabbit/benchmark/LogoutAfterReadTest.java (revision 0)
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.benchmark;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+/**
+ * LogoutAfterReadTest implements a performance test that logs out
+ * sessions using multiple threads after some reading was done. See JCR-2643.
+ */
+public class LogoutAfterReadTest extends PerformanceTest {
+
+ private static final String TEST_CONTENT = "test-content";
+
+ private static final int NUM_SESSIONS = 1000;
+
+ private static final int NUM_THREADS = 8;
+
+ private List identifiers = new ArrayList();
+
+ private Session[] sessions = new Session[NUM_SESSIONS];
+
+ private ExecutorService executor;
+
+ @Override
+ public String toString() {
+ return NUM_SESSIONS + " x logout() after reads";
+ }
+
+ @Override
+ public void beforeSuite() throws Exception {
+ super.beforeSuite();
+ identifiers.clear();
+ Session session = createSession();
+ Node test;
+ if (!session.getRootNode().hasNode(TEST_CONTENT)) {
+ test = session.getRootNode().addNode(TEST_CONTENT);
+ } else {
+ test = session.getRootNode().getNode(TEST_CONTENT);
+ }
+ createNodes(identifiers, test, 10, 3, 0, 1000);
+ }
+
+ @Override
+ public void beforeTest() throws Exception {
+ super.beforeTest();
+ Random rand = new Random();
+ for (int i = 0; i < sessions.length; i++) {
+ Session s = createSession();
+ sessions[i] = s;
+ for (int j = 0; j < 100; j++) {
+ s.getNodeByIdentifier(identifiers.get(rand.nextInt(identifiers.size())));
+ }
+ }
+ executor = Executors.newFixedThreadPool(NUM_THREADS);
+ }
+
+ @Override
+ public void runTest() throws Exception {
+ for (Session session : sessions) {
+ final Session s = session;
+ executor.execute(new Runnable() {
+ public void run() {
+ s.logout();
+ }
+ });
+ }
+ executor.shutdown();
+ executor.awaitTermination(1, TimeUnit.HOURS);
+ }
+
+ @Override
+ public void afterSuite() throws Exception {
+ Session session = createSession();
+ try {
+ if (session.getRootNode().hasNode(TEST_CONTENT)) {
+ session.getRootNode().getNode(TEST_CONTENT).remove();
+ session.save();
+ }
+ } finally {
+ session.logout();
+ }
+ super.afterSuite();
+ }
+
+ private Session createSession() throws Exception {
+ return getRepository().login(getCredentials());
+ }
+
+ private int createNodes(List identifiers,
+ Node n,
+ int nodesPerLevel,
+ int levels,
+ int count,
+ int saveInterval)
+ throws RepositoryException {
+ levels--;
+ for (int i = 0; i < nodesPerLevel; i++) {
+ Node child = n.addNode("node" + i);
+ identifiers.add(child.getIdentifier());
+ count++;
+ if (count % saveInterval == 0) {
+ n.getSession().save();
+ }
+ if (levels > 0) {
+ count = createNodes(identifiers, child, nodesPerLevel,
+ levels, count, saveInterval);
+ }
+ }
+ if (levels == 0) {
+ // final save
+ n.getSession().save();
+ }
+ return count;
+ }
+}
Property changes on: src\main\java\org\apache\jackrabbit\benchmark\LogoutAfterReadTest.java
___________________________________________________________________
Added: svn:eol-style
+ native
Index: src/main/java/org/apache/jackrabbit/benchmark/PerformanceTestSuite.java
===================================================================
--- src/main/java/org/apache/jackrabbit/benchmark/PerformanceTestSuite.java (revision 948421)
+++ src/main/java/org/apache/jackrabbit/benchmark/PerformanceTestSuite.java (working copy)
@@ -107,6 +107,7 @@
new PerformanceTestSuite(repository, credentials);
suite.runTest(new LoginTest());
suite.runTest(new LoginLogoutTest());
+ suite.runTest(new LogoutAfterReadTest());
// suite.runTest(new RefreshTest());
// suite.runTest(new SmallFileReadTest());
// suite.runTest(new SmallFileWriteTest());