You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:26:49 UTC
[sling-tooling-scm] 01/27: SLING-2311 - adding small performance
test suite. Based heavily on the work of Antonio Sanso and the Jackrabbit
team (Thanks!!!)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.performance.base-0.0.2
in repository https://gitbox.apache.org/repos/asf/sling-tooling-scm.git
commit df6828963622eea9e292083a49ccce003d110ee1
Author: Justin Edelson <ju...@apache.org>
AuthorDate: Mon Aug 27 20:13:21 2012 +0000
SLING-2311 - adding small performance test suite. Based heavily on the work of Antonio Sanso and the Jackrabbit team (Thanks!!!)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/performance/base@1377819 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 110 ++++++++
.../sling/performance/AbstractPerformanceTest.java | 91 +++++++
.../sling/performance/AbstractRepositoryTest.java | 90 +++++++
.../org/apache/sling/performance/AbstractTest.java | 134 ++++++++++
.../performance/ResourceResolverTestRequest.java | 285 +++++++++++++++++++++
.../org/apache/sling/performance/TestHelper.java | 32 +++
.../tests/ResolveWith10000AliasTest.java | 27 ++
.../tests/ResolveWith10000VanityPathTest.java | 27 ++
.../tests/ResolveWith1000AliasTest.java | 27 ++
.../tests/ResolveWith1000VanityPathTest.java | 27 ++
.../tests/ResolveWith30000AliasTest.java | 27 ++
.../tests/ResolveWith30000VanityPathTest.java | 27 ++
.../tests/ResolveWith5000AliasTest.java | 27 ++
.../tests/ResolveWith5000VanityPathTest.java | 27 ++
.../tests/ResolveWithManyAliasTest.java | 127 +++++++++
.../tests/ResolveWithManyVanityPathTest.java | 137 ++++++++++
16 files changed, 1222 insertions(+)
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..c02e8db
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling-performance-tests</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>org.apache.sling.performance.base</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+
+ <name>Apache Sling Performance Test Utilities</name>
+
+ <properties>
+ <junit.version>4.8.2</junit.version>
+ </properties>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/testing/performance/base</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/testing/performance/base</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/trunk/testing/performance/base</url>
+ </scm>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-math</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit-addons</groupId>
+ <artifactId>junit-addons</artifactId>
+ <version>1.4</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ <version>2.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.commons.testing</artifactId>
+ <version>2.0.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.commons.classloader</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>r09</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.8.2</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/src/main/java/org/apache/sling/performance/AbstractPerformanceTest.java b/src/main/java/org/apache/sling/performance/AbstractPerformanceTest.java
new file mode 100644
index 0000000..1540cf7
--- /dev/null
+++ b/src/main/java/org/apache/sling/performance/AbstractPerformanceTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.sling.performance;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
+import junit.framework.TestCase;
+import org.apache.commons.io.output.FileWriterWithEncoding;
+import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
+
+public abstract class AbstractPerformanceTest extends TestCase {
+
+ private final int runtime = 5;
+
+ private final int warmup = 1;
+
+ private void runTest(String name, AbstractTest test) throws Exception {
+ DescriptiveStatistics statistics = new DescriptiveStatistics();
+
+ test.setUp();
+ try {
+ // Run a few iterations to warm up the system
+ long warmupEnd = System.currentTimeMillis() + warmup * 1000;
+ while (System.currentTimeMillis() < warmupEnd) {
+ test.execute();
+ }
+
+ // Run test iterations, and capture the execution times
+ long runtimeEnd = System.currentTimeMillis() + runtime * 1000;
+ while (System.currentTimeMillis() < runtimeEnd) {
+ statistics.addValue(test.execute());
+ }
+ } finally {
+ test.tearDown();
+ }
+
+ if (statistics.getN() > 0) {
+ writeReport(test.toString(), name, statistics);
+ }
+ }
+
+ protected void testPerformance(String name, List <AbstractTest> tests) throws Exception {
+ for (AbstractTest test:tests){
+ runTest(name,test);
+ }
+ }
+
+ private void writeReport(String test, String name, DescriptiveStatistics statistics)
+ throws IOException {
+ File report = new File("target", test + ".txt");
+
+ boolean needsPrefix = !report.exists();
+ PrintWriter writer = new PrintWriter(
+ new FileWriterWithEncoding(report, "UTF-8", true));
+ try {
+ if (needsPrefix) {
+ writer.format(
+ "# %-34.34s min 10%% 50%% 90%% max%n",
+ test);
+ }
+
+ writer.format(
+ "%-36.36s %6.0f %6.0f %6.0f %6.0f %6.0f%n",
+ name,
+ statistics.getMin(),
+ statistics.getPercentile(10.0),
+ statistics.getPercentile(50.0),
+ statistics.getPercentile(90.0),
+ statistics.getMax());
+ } finally {
+ writer.close();
+ }
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/performance/AbstractRepositoryTest.java b/src/main/java/org/apache/sling/performance/AbstractRepositoryTest.java
new file mode 100644
index 0000000..f5f818d
--- /dev/null
+++ b/src/main/java/org/apache/sling/performance/AbstractRepositoryTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.sling.performance;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.naming.NamingException;
+
+import org.apache.sling.commons.testing.jcr.RepositoryUtil;
+import org.apache.sling.jcr.api.SlingRepository;
+
+
+
+public abstract class AbstractRepositoryTest extends AbstractTest {
+
+ private static class ShutdownThread extends Thread {
+ @Override
+ public void run() {
+ try {
+ RepositoryUtil.stopRepository();
+ } catch(Exception e) {
+ System.out.println("Exception in ShutdownThread:" + e);
+ }
+ }
+
+ }
+ private static SlingRepository repository;
+ private int counter;
+ protected Session session;
+
+ protected Node testRoot;;
+
+ /** Return a Repository - first call initializes it, and a JVM
+ * shutdown hook is registered to stop it
+ */
+ protected SlingRepository getRepository() throws RepositoryException, NamingException {
+ if(repository != null) {
+ return repository;
+ }
+
+ synchronized (AbstractRepositoryTest.class) {
+ if(repository == null) {
+ RepositoryUtil.startRepository();
+ repository = RepositoryUtil.getRepository();
+ Runtime.getRuntime().addShutdownHook(new ShutdownThread());
+ }
+ return repository;
+ }
+ }
+
+ /** Return a JCR Session, initialized on demand */
+ protected Session getSession() throws RepositoryException, NamingException {
+ if(session == null) {
+ session = getRepository().loginAdministrative(null);
+ }
+ return session;
+ }
+
+ /** Return a test root node, created on demand, with a unique path */
+ protected Node getTestRootNode() throws RepositoryException, NamingException {
+ if(testRoot==null) {
+ final Node root = getSession().getRootNode();
+ final Node classRoot = root.addNode(getClass().getSimpleName());
+ testRoot = classRoot.addNode(System.currentTimeMillis() + "_" + (++counter));
+ }
+ return testRoot;
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ if(session != null) {
+ session.logout();
+ }
+ }}
diff --git a/src/main/java/org/apache/sling/performance/AbstractTest.java b/src/main/java/org/apache/sling/performance/AbstractTest.java
new file mode 100644
index 0000000..7cdaca2
--- /dev/null
+++ b/src/main/java/org/apache/sling/performance/AbstractTest.java
@@ -0,0 +1,134 @@
+/*
+ * 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.sling.performance;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Abstract base class for individual performance benchmarks.
+ */
+public abstract class AbstractTest {
+
+ protected static int getScale(int def) {
+ int scale = Integer.getInteger("scale", 0);
+ if (scale == 0) {
+ scale = def;
+ }
+ return scale;
+ }
+
+ private volatile boolean running;
+
+ private List<Thread> threads;
+
+ /**
+ * Adds a background thread that repeatedly executes the given job
+ * until all the iterations of this test have been executed.
+ *
+ * @param job background job
+ */
+ protected void addBackgroundJob(final Runnable job) {
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ while (running) {
+ job.run();
+ }
+ }
+ };
+ thread.start();
+ threads.add(thread);
+ }
+
+ /**
+ * Run after all iterations of this test have been executed. Subclasses can
+ * override this method to clean up static test content.
+ *
+ * @throws Exception if an error occurs
+ */
+ protected void afterSuite() throws Exception {
+ }
+
+ protected void afterTest() throws Exception {
+ }
+
+
+ /**
+ * Run before any iterations of this test get executed. Subclasses can
+ * override this method to set up static test content.
+ *
+ * @throws Exception if an error occurs
+ */
+ protected void beforeSuite() throws Exception {
+ }
+
+ protected void beforeTest() throws Exception {
+ }
+
+ /**
+ * Executes a single iteration of this test.
+ *
+ * @return number of milliseconds spent in this iteration
+ * @throws Exception if an error occurs
+ */
+ public long execute() throws Exception {
+ beforeTest();
+ try {
+ long start = System.currentTimeMillis();
+ runTest();
+ return System.currentTimeMillis() - start;
+ } finally {
+ afterTest();
+ }
+ }
+
+ protected abstract void runTest() throws Exception;
+
+ /**
+ * Prepares this performance benchmark.
+ *
+ * @param repository the repository to use
+ * @param credentials credentials of a user with write access
+ * @throws Exception if the benchmark can not be prepared
+ */
+ public void setUp()
+ throws Exception {
+ this.threads = new LinkedList<Thread>();
+ this.running = true;
+ beforeSuite();
+ }
+
+ /**
+ * Cleans up after this performance benchmark.
+ *
+ * @throws Exception if the benchmark can not be cleaned up
+ */
+ public void tearDown() throws Exception {
+ this.running = false;
+ for (Thread thread : threads) {
+ thread.join();
+ }
+ afterSuite();
+ this.threads = null;
+ }
+
+ public String toString() {
+ String name = getClass().getName();
+ return name.substring(name.lastIndexOf('.') + 1);
+ }
+ }
diff --git a/src/main/java/org/apache/sling/performance/ResourceResolverTestRequest.java b/src/main/java/org/apache/sling/performance/ResourceResolverTestRequest.java
new file mode 100644
index 0000000..38f9ceb
--- /dev/null
+++ b/src/main/java/org/apache/sling/performance/ResourceResolverTestRequest.java
@@ -0,0 +1,285 @@
+/*
+ * 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.sling.performance;
+
+import java.io.BufferedReader;
+import java.security.Principal;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+public class ResourceResolverTestRequest implements HttpServletRequest {
+
+ private final Map<String, Object> attrs = new HashMap<String, Object>();
+
+ private String contextPath;
+
+ private final String host;
+
+ private final String method;
+
+ private final String pathInfo;
+
+ private final int port;
+
+ private final String scheme;
+
+ public ResourceResolverTestRequest(String pathInfo) {
+ this(pathInfo, null);
+ }
+
+ public ResourceResolverTestRequest(String pathInfo, String httpMethod) {
+ this(null, null, -1, pathInfo, httpMethod);
+ }
+
+ public ResourceResolverTestRequest(String scheme, String host, int port, String pathInfo) {
+ this(scheme, host, port, pathInfo, null);
+ }
+
+ public ResourceResolverTestRequest(String scheme, String host, int port, String pathInfo, String httpMethod) {
+ this.scheme = (scheme == null) ? "http" : scheme;
+ this.host = (host == null) ? "localhost" : host;
+ this.port = port;
+ this.pathInfo = pathInfo;
+ this.method = httpMethod;
+ }
+
+ public Object getAttribute(String name) {
+ return attrs.get(name);
+ }
+
+ public Enumeration<?> getAttributeNames() {
+ return null;
+ }
+
+ public String getAuthType() {
+ return null;
+ }
+
+ public String getCharacterEncoding() {
+ return null;
+ }
+
+ public int getContentLength() {
+ return 0;
+ }
+
+ public String getContentType() {
+ return null;
+ }
+
+ public String getContextPath() {
+ return contextPath;
+ }
+
+ public Cookie[] getCookies() {
+ return null;
+ }
+
+ public long getDateHeader(String name) {
+ return 0;
+ }
+
+ public String getHeader(String name) {
+ return null;
+ }
+
+ public Enumeration<?> getHeaderNames() {
+ return null;
+ }
+
+ public Enumeration<?> getHeaders(String name) {
+ return null;
+ }
+
+ public ServletInputStream getInputStream() {
+ return null;
+ }
+
+ public int getIntHeader(String name) {
+ return 0;
+ }
+
+ public String getLocalAddr() {
+ return null;
+ }
+
+ public Locale getLocale() {
+ return null;
+ }
+
+ public Enumeration<?> getLocales() {
+ return null;
+ }
+
+ public String getLocalName() {
+ return null;
+ }
+
+ public int getLocalPort() {
+ return 0;
+ }
+
+ public String getMethod() {
+ return method;
+ }
+
+ public String getParameter(String name) {
+ return null;
+ }
+
+ public Map<?, ?> getParameterMap() {
+ return null;
+ }
+
+ public Enumeration<?> getParameterNames() {
+ return null;
+ }
+
+ public String[] getParameterValues(String name) {
+ return null;
+ }
+
+ public String getPathInfo() {
+ return pathInfo;
+ }
+
+ public String getPathTranslated() {
+ return null;
+ }
+
+ public String getProtocol() {
+ return null;
+ }
+
+ public String getQueryString() {
+ return null;
+ }
+
+ public BufferedReader getReader() {
+ return null;
+ }
+
+ public String getRealPath(String path) {
+ return null;
+ }
+
+ public String getRemoteAddr() {
+ return null;
+ }
+
+ public String getRemoteHost() {
+ return null;
+ }
+
+ public int getRemotePort() {
+ return 0;
+ }
+
+ public String getRemoteUser() {
+ return null;
+ }
+
+ public RequestDispatcher getRequestDispatcher(String path) {
+ return null;
+ }
+
+ public String getRequestedSessionId() {
+ return null;
+ }
+
+ public String getRequestURI() {
+ return null;
+ }
+
+ public StringBuffer getRequestURL() {
+ return null;
+ }
+
+ public String getScheme() {
+ return scheme;
+ }
+
+ public String getServerName() {
+ return host;
+ }
+
+ public int getServerPort() {
+ return port;
+ }
+
+ public String getServletPath() {
+ return null;
+ }
+
+ public HttpSession getSession() {
+ return null;
+ }
+
+ public HttpSession getSession(boolean create) {
+ return null;
+ }
+
+ public Principal getUserPrincipal() {
+ return null;
+ }
+
+ public boolean isRequestedSessionIdFromCookie() {
+ return false;
+ }
+
+ public boolean isRequestedSessionIdFromUrl() {
+ return false;
+ }
+
+ public boolean isRequestedSessionIdFromURL() {
+ return false;
+ }
+
+ public boolean isRequestedSessionIdValid() {
+ return false;
+ }
+
+ public boolean isSecure() {
+ return false;
+ }
+
+ public boolean isUserInRole(String role) {
+ return false;
+ }
+
+ public void removeAttribute(String name) {
+ }
+
+ public void setAttribute(String name, Object o) {
+ attrs.put(name, o);
+ }
+
+ public void setCharacterEncoding(String env) {
+ }
+
+ public void setContextPath(String contextPath) {
+ this.contextPath = contextPath;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/performance/TestHelper.java b/src/main/java/org/apache/sling/performance/TestHelper.java
new file mode 100644
index 0000000..6584ca1
--- /dev/null
+++ b/src/main/java/org/apache/sling/performance/TestHelper.java
@@ -0,0 +1,32 @@
+/*
+ * 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.sling.performance;
+
+import javax.jcr.Session;
+
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.jcr.api.SlingRepository;
+
+public interface TestHelper {
+
+ void dispose();
+
+ ResourceResolver getResourceResolver();
+
+ void init(String rootPath, Session session, SlingRepository repository) throws Exception;
+
+}
diff --git a/src/main/java/org/apache/sling/performance/tests/ResolveWith10000AliasTest.java b/src/main/java/org/apache/sling/performance/tests/ResolveWith10000AliasTest.java
new file mode 100644
index 0000000..4f6952a
--- /dev/null
+++ b/src/main/java/org/apache/sling/performance/tests/ResolveWith10000AliasTest.java
@@ -0,0 +1,27 @@
+/*
+ * 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.sling.performance.tests;
+
+import org.apache.sling.performance.TestHelper;
+
+public class ResolveWith10000AliasTest extends ResolveWithManyAliasTest {
+
+ public ResolveWith10000AliasTest(TestHelper helper) {
+ super(helper, 10000);
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/performance/tests/ResolveWith10000VanityPathTest.java b/src/main/java/org/apache/sling/performance/tests/ResolveWith10000VanityPathTest.java
new file mode 100644
index 0000000..88ad4ab
--- /dev/null
+++ b/src/main/java/org/apache/sling/performance/tests/ResolveWith10000VanityPathTest.java
@@ -0,0 +1,27 @@
+/*
+ * 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.sling.performance.tests;
+
+import org.apache.sling.performance.TestHelper;
+
+public class ResolveWith10000VanityPathTest extends ResolveWithManyVanityPathTest {
+
+ public ResolveWith10000VanityPathTest(TestHelper helper) {
+ super(helper, 100, 100);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/performance/tests/ResolveWith1000AliasTest.java b/src/main/java/org/apache/sling/performance/tests/ResolveWith1000AliasTest.java
new file mode 100644
index 0000000..9f93d1d
--- /dev/null
+++ b/src/main/java/org/apache/sling/performance/tests/ResolveWith1000AliasTest.java
@@ -0,0 +1,27 @@
+/*
+ * 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.sling.performance.tests;
+
+import org.apache.sling.performance.TestHelper;
+
+public class ResolveWith1000AliasTest extends ResolveWithManyAliasTest {
+
+ public ResolveWith1000AliasTest(TestHelper helper) {
+ super(helper, 1000);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/performance/tests/ResolveWith1000VanityPathTest.java b/src/main/java/org/apache/sling/performance/tests/ResolveWith1000VanityPathTest.java
new file mode 100644
index 0000000..7c5f167
--- /dev/null
+++ b/src/main/java/org/apache/sling/performance/tests/ResolveWith1000VanityPathTest.java
@@ -0,0 +1,27 @@
+/*
+ * 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.sling.performance.tests;
+
+import org.apache.sling.performance.TestHelper;
+
+public class ResolveWith1000VanityPathTest extends ResolveWithManyVanityPathTest {
+
+ public ResolveWith1000VanityPathTest(TestHelper helper) {
+ super(helper, 100, 10);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/performance/tests/ResolveWith30000AliasTest.java b/src/main/java/org/apache/sling/performance/tests/ResolveWith30000AliasTest.java
new file mode 100644
index 0000000..56e4ab2
--- /dev/null
+++ b/src/main/java/org/apache/sling/performance/tests/ResolveWith30000AliasTest.java
@@ -0,0 +1,27 @@
+/*
+ * 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.sling.performance.tests;
+
+import org.apache.sling.performance.TestHelper;
+
+public class ResolveWith30000AliasTest extends ResolveWithManyAliasTest {
+
+ public ResolveWith30000AliasTest(TestHelper helper) {
+ super(helper, 30000);
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/performance/tests/ResolveWith30000VanityPathTest.java b/src/main/java/org/apache/sling/performance/tests/ResolveWith30000VanityPathTest.java
new file mode 100644
index 0000000..7248a6e
--- /dev/null
+++ b/src/main/java/org/apache/sling/performance/tests/ResolveWith30000VanityPathTest.java
@@ -0,0 +1,27 @@
+/*
+ * 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.sling.performance.tests;
+
+import org.apache.sling.performance.TestHelper;
+
+public class ResolveWith30000VanityPathTest extends ResolveWithManyVanityPathTest {
+
+ public ResolveWith30000VanityPathTest(TestHelper helper) {
+ super(helper, 300, 100);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/performance/tests/ResolveWith5000AliasTest.java b/src/main/java/org/apache/sling/performance/tests/ResolveWith5000AliasTest.java
new file mode 100644
index 0000000..54f9cdb
--- /dev/null
+++ b/src/main/java/org/apache/sling/performance/tests/ResolveWith5000AliasTest.java
@@ -0,0 +1,27 @@
+/*
+ * 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.sling.performance.tests;
+
+import org.apache.sling.performance.TestHelper;
+
+public class ResolveWith5000AliasTest extends ResolveWithManyAliasTest {
+
+ public ResolveWith5000AliasTest(TestHelper helper) {
+ super(helper, 5000);
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/performance/tests/ResolveWith5000VanityPathTest.java b/src/main/java/org/apache/sling/performance/tests/ResolveWith5000VanityPathTest.java
new file mode 100644
index 0000000..b22c6d4
--- /dev/null
+++ b/src/main/java/org/apache/sling/performance/tests/ResolveWith5000VanityPathTest.java
@@ -0,0 +1,27 @@
+/*
+ * 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.sling.performance.tests;
+
+import org.apache.sling.performance.TestHelper;
+
+public class ResolveWith5000VanityPathTest extends ResolveWithManyVanityPathTest {
+
+ public ResolveWith5000VanityPathTest(TestHelper helper) {
+ super(helper, 100, 50);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/performance/tests/ResolveWithManyAliasTest.java b/src/main/java/org/apache/sling/performance/tests/ResolveWithManyAliasTest.java
new file mode 100644
index 0000000..f886957
--- /dev/null
+++ b/src/main/java/org/apache/sling/performance/tests/ResolveWithManyAliasTest.java
@@ -0,0 +1,127 @@
+/*
+ * 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.sling.performance.tests;
+
+import java.math.BigInteger;
+import java.security.SecureRandom;
+
+import javax.jcr.Node;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.commons.testing.jcr.RepositoryUtil;
+import org.apache.sling.performance.AbstractRepositoryTest;
+import org.apache.sling.performance.TestHelper;
+import org.apache.sling.performance.ResourceResolverTestRequest;
+
+import static org.junit.Assert.assertNotNull;
+
+class ResolveWithManyAliasTest extends AbstractRepositoryTest {
+
+ private static final String PN_SLING_ALIAS = "sling:alias";
+
+ private final TestHelper helper;
+
+ private Node mapRoot;
+
+ private ResourceResolver resResolver;
+
+ private Node rootNode;
+
+ private String rootPath;
+
+ private final int nodeCount;
+
+ public ResolveWithManyAliasTest(TestHelper helper, int nodeCount) {
+ this.helper = helper;
+ this.nodeCount = nodeCount;
+ }
+
+ @Override
+ protected void afterSuite() throws Exception {
+ if (helper != null) {
+ helper.dispose();
+ }
+
+ if (rootNode != null) {
+ rootNode.remove();
+ }
+ if (mapRoot != null) {
+ mapRoot.remove();
+ }
+ /*
+ * if ( this.listener != null ) { this.listener.dispose(); }
+ */
+ session.save();
+ }
+
+ @Override
+ protected void beforeSuite() throws Exception {
+ RepositoryUtil.registerNodeType(getSession(),
+ this.getClass().getResourceAsStream("/SLING-INF/nodetypes/folder.cnd"));
+ RepositoryUtil.registerNodeType(getSession(),
+ this.getClass().getResourceAsStream("/SLING-INF/nodetypes/resource.cnd"));
+ RepositoryUtil.registerNodeType(getSession(),
+ this.getClass().getResourceAsStream("/SLING-INF/nodetypes/vanitypath.cnd"));
+ RepositoryUtil.registerNodeType(getSession(),
+ this.getClass().getResourceAsStream("/SLING-INF/nodetypes/mapping.cnd"));
+
+ // test data
+ rootPath = "/test" + System.currentTimeMillis();
+ rootNode = getSession().getRootNode().addNode(rootPath.substring(1), JcrConstants.NT_UNSTRUCTURED);
+
+ // test mappings
+ mapRoot = getSession().getRootNode().addNode("etc", "nt:folder");
+ Node map = mapRoot.addNode("map", "sling:Mapping");
+ Node http = map.addNode("http", "sling:Mapping");
+ http.addNode("localhost.80", "sling:Mapping");
+ Node https = map.addNode("https", "sling:Mapping");
+ https.addNode("localhost.443", "sling:Mapping");
+
+ // define a vanity path for the rootPath
+ SecureRandom random = new SecureRandom();
+ // creating <nodeCount> nodes
+ for (int j = 0; j < nodeCount; j++) {
+ Node content = rootNode.addNode("a" + j, JcrConstants.NT_UNSTRUCTURED);
+ String alias = new BigInteger(130, random).toString(32);
+ content.setProperty(PN_SLING_ALIAS, alias);
+
+ if (j % 10 == 0) {
+ session.save();
+ }
+ }
+
+ session.save();
+
+ helper.init(rootPath, session, getRepository());
+
+ resResolver = helper.getResourceResolver();
+
+ }
+
+ @Override
+ protected void runTest() throws Exception {
+ String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + "testNonExistingAlias"
+ + ".print.html");
+ HttpServletRequest request = new ResourceResolverTestRequest(path);
+ Resource res = resResolver.resolve(request, path);
+ assertNotNull(res);
+ }
+}
diff --git a/src/main/java/org/apache/sling/performance/tests/ResolveWithManyVanityPathTest.java b/src/main/java/org/apache/sling/performance/tests/ResolveWithManyVanityPathTest.java
new file mode 100644
index 0000000..3e51942
--- /dev/null
+++ b/src/main/java/org/apache/sling/performance/tests/ResolveWithManyVanityPathTest.java
@@ -0,0 +1,137 @@
+/*
+ * 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.sling.performance.tests;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.math.BigInteger;
+import java.security.SecureRandom;
+
+import javax.jcr.Node;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.commons.testing.jcr.RepositoryUtil;
+import org.apache.sling.performance.AbstractRepositoryTest;
+import org.apache.sling.performance.TestHelper;
+import org.apache.sling.performance.ResourceResolverTestRequest;
+
+class ResolveWithManyVanityPathTest extends AbstractRepositoryTest {
+
+ private static final String NT_VANITY_PATH = "sling:VanityPath";
+
+ private static final String PN_VANITY_PATH = "sling:vanityPath";
+
+ private final TestHelper helper;
+
+ private Node mapRoot;
+
+ // private JcrResourceListener listener;
+ private ResourceResolver resResolver;
+
+ private Node rootNode;
+
+ private String rootPath;
+
+ private final int nodeCount;
+
+ private final int childNodeCount;
+
+ public ResolveWithManyVanityPathTest(TestHelper helper, int nodeCount, int childNodeCount) {
+ this.helper = helper;
+ this.nodeCount = nodeCount;
+ this.childNodeCount = childNodeCount;
+ }
+
+ @Override
+ protected void afterSuite() throws Exception {
+ if (helper != null) {
+ helper.dispose();
+ }
+
+ if (rootNode != null) {
+ rootNode.remove();
+ }
+ if (mapRoot != null) {
+ mapRoot.remove();
+ }
+ session.save();
+ }
+
+ @Override
+ protected void beforeSuite() throws Exception {
+ RepositoryUtil.registerNodeType(getSession(),
+ this.getClass().getResourceAsStream("/SLING-INF/nodetypes/folder.cnd"));
+ RepositoryUtil.registerNodeType(getSession(),
+ this.getClass().getResourceAsStream("/SLING-INF/nodetypes/resource.cnd"));
+ RepositoryUtil.registerNodeType(getSession(),
+ this.getClass().getResourceAsStream("/SLING-INF/nodetypes/vanitypath.cnd"));
+ RepositoryUtil.registerNodeType(getSession(),
+ this.getClass().getResourceAsStream("/SLING-INF/nodetypes/mapping.cnd"));
+
+ // test data
+ rootPath = "/test" + System.currentTimeMillis();
+ rootNode = getSession().getRootNode().addNode(rootPath.substring(1), "nt:unstructured");
+
+ // test mappings
+ mapRoot = getSession().getRootNode().addNode("etc", JcrConstants.NT_FOLDER);
+ Node map = mapRoot.addNode("map", "sling:Mapping");
+ Node http = map.addNode("http", "sling:Mapping");
+ http.addNode("localhost.80", "sling:Mapping");
+ Node https = map.addNode("https", "sling:Mapping");
+ https.addNode("localhost.443", "sling:Mapping");
+
+ SecureRandom random = new SecureRandom();
+
+ // creating <nodeCount> x <childNodeCount> nodes with vanity
+ for (int j = 0; j < nodeCount; j++) {
+ Node content = rootNode.addNode("a" + j, JcrConstants.NT_UNSTRUCTURED);
+ String s = new BigInteger(130, random).toString(32);
+ content.addMixin(NT_VANITY_PATH);
+ content.setProperty(PN_VANITY_PATH, s);
+ for (int k = 0; k < childNodeCount; k++) {
+ Node content2 = content.addNode("b" + k, JcrConstants.NT_UNSTRUCTURED);
+ String ss = new BigInteger(130, random).toString(32);
+ content2.addMixin(NT_VANITY_PATH);
+ content2.setProperty(PN_VANITY_PATH, ss);
+ }
+ if (j % 10 == 0) {
+ session.save();
+ }
+ }
+
+ session.save();
+
+ helper.init(rootPath, session, getRepository());
+
+ resResolver = helper.getResourceResolver();
+
+ }
+
+ @Override
+ protected void runTest() throws Exception {
+ String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + "testNonExistingVanity"
+ + ".print.html");
+ HttpServletRequest request = new ResourceResolverTestRequest(path);
+ Resource res = resResolver.resolve(request, path);
+ assertNotNull(res);
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.