jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r700519 - in /jackrabbit/sandbox/benchmark: ./ src/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/jackrabbit/ src/test/java/org/apache/jackrabbit/harness/
Date Tue, 30 Sep 2008 16:17:53 GMT
Author: jukka
Date: Tue Sep 30 09:17:48 2008
New Revision: 700519

URL: http://svn.apache.org/viewvc?rev=700519&view=rev
Log:
Added an integration test harness project in sandbox.

Added:
    jackrabbit/sandbox/benchmark/
    jackrabbit/sandbox/benchmark/pom.xml   (with props)
    jackrabbit/sandbox/benchmark/src/
    jackrabbit/sandbox/benchmark/src/test/
    jackrabbit/sandbox/benchmark/src/test/java/
    jackrabbit/sandbox/benchmark/src/test/java/org/
    jackrabbit/sandbox/benchmark/src/test/java/org/apache/
    jackrabbit/sandbox/benchmark/src/test/java/org/apache/jackrabbit/
    jackrabbit/sandbox/benchmark/src/test/java/org/apache/jackrabbit/harness/
    jackrabbit/sandbox/benchmark/src/test/java/org/apache/jackrabbit/harness/ImportMemoryTest.java
  (with props)
    jackrabbit/sandbox/benchmark/src/test/java/org/apache/jackrabbit/harness/Repository.java
  (with props)
    jackrabbit/sandbox/benchmark/testng.xml   (with props)

Added: jackrabbit/sandbox/benchmark/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/benchmark/pom.xml?rev=700519&view=auto
==============================================================================
--- jackrabbit/sandbox/benchmark/pom.xml (added)
+++ jackrabbit/sandbox/benchmark/pom.xml Tue Sep 30 09:17:48 2008
@@ -0,0 +1,91 @@
+<?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>
+
+  <!-- =================================================================== -->
+  <!-- P R O J E C T  D E S C R I P T I O N                                -->
+  <!-- =================================================================== -->
+
+  <parent>
+    <groupId>org.apache</groupId>
+    <artifactId>apache</artifactId>
+    <version>4</version>
+  </parent>
+
+  <groupId>org.apache.jackrabbit</groupId>
+  <artifactId>jackrabbit-test-harness</artifactId>
+  <name>Apache Jackrabbit Test Harness</name>
+  <version>SNAPSHOT</version>
+
+  <dependencies>
+    <dependency>
+      <groupId>javax.jcr</groupId>
+      <artifactId>jcr</artifactId>
+      <version>1.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.testng</groupId>
+      <artifactId>testng</artifactId>
+      <classifier>jdk15</classifier>
+      <version>5.8</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>1.5.2</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.jackrabbit</groupId>
+      <artifactId>jackrabbit-core</artifactId>
+      <version>1.5-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>1.4</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <suiteXmlFiles>
+            <suiteXmlFile>testng.xml</suiteXmlFile>
+          </suiteXmlFiles>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
+

Propchange: jackrabbit/sandbox/benchmark/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/sandbox/benchmark/src/test/java/org/apache/jackrabbit/harness/ImportMemoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/benchmark/src/test/java/org/apache/jackrabbit/harness/ImportMemoryTest.java?rev=700519&view=auto
==============================================================================
--- jackrabbit/sandbox/benchmark/src/test/java/org/apache/jackrabbit/harness/ImportMemoryTest.java
(added)
+++ jackrabbit/sandbox/benchmark/src/test/java/org/apache/jackrabbit/harness/ImportMemoryTest.java
Tue Sep 30 09:17:48 2008
@@ -0,0 +1,242 @@
+/*
+ * 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.harness;
+
+import java.io.ByteArrayInputStream;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Calendar;
+import java.util.Random;
+import java.util.UUID;
+
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.PropertyType;
+import javax.jcr.Session;
+import javax.jcr.ValueFactory;
+
+import org.apache.jackrabbit.util.Base64;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * Test case that attempts to validate the following requirements:
+ * <ul>
+ *   <li>import file details:
+ *     <ul>
+ *       <li>size - 100MB,</li>
+ *       <li>number of nodes - 100 000 (40% are versionable nodes),</li>
+ *     </ul>
+ *   </li>
+ *   <li>binary properties:
+ *     <ul>
+ *       <li>number - 2000,</li>
+ *       <li>size - up to 100kB,</li> 
+ *     </ul>
+ *   </li>
+ *   <li>heap size : 1024 MB.</li>
+ * </ul>
+ * <p>
+ * To validate the above, this test case generates a virtual XML system
+ * view import file with the following characteristics:
+ * <ol>
+ *   <li>one nt:folder node</li>
+ *   <li>ten nt:folder nodes under the top level node</li>
+ *   <li>100 nt:folder nodes under each second level node</li>
+ *   <li>100 versionable nt:file nodes under each third level node</li>
+ *   <li>
+ *     one nt:resource node under each fourth level node,
+ *     each with 10k bytes of random binary content
+ *   </li>
+ * </ol>
+ * <p>
+ * This is a total of 100k files or 200+k nodes, which should well cover the
+ * above requirements.
+ */
+public class ImportMemoryTest {
+
+    private static final String JCR = "http://www.jcp.org/jcr/1.0";
+
+    private static final String NT = "http://www.jcp.org/jcr/nt/1.0";
+
+    private static final String SV = "http://www.jcp.org/jcr/sv/1.0";
+
+    private Session session;
+
+    private ContentHandler handler;
+
+    private String date;
+
+    private long nodes;
+
+    private long maxUsedMemory;
+
+    private volatile boolean running;
+
+    private Thread thread;
+
+    @BeforeMethod
+    public void login() throws Exception {
+        session = Repository.login();
+        handler = session.getImportContentHandler(
+                "/", ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+        ValueFactory factory = session.getValueFactory();
+        date = factory.createValue(Calendar.getInstance()).getString();
+        nodes = 0;
+        maxUsedMemory = 0;
+        running = true;
+        thread = new Thread() {
+            public void run() {
+                Runtime runtime = Runtime.getRuntime();
+                long start = runtime.totalMemory() - runtime.freeMemory();
+                while (running) {
+                    try {
+                        long currentUsedMemory =
+                            runtime.totalMemory() - runtime.freeMemory() - start;
+                        System.out.println("Current: " + currentUsedMemory);
+                        if (maxUsedMemory < currentUsedMemory) {
+                            maxUsedMemory = currentUsedMemory;
+                        }
+                        Thread.sleep(1000);
+                    } catch (InterruptedException e) {
+                    }
+                }
+            }
+        };
+        thread.start();
+    }
+
+    @AfterMethod
+    public void logout() throws Exception {
+        session.logout();
+        running = false;
+        thread.join();
+    }
+
+    @Test
+    public void testMemoryUse() throws Exception {
+        handler.startDocument();
+        handler.startPrefixMapping("jcr", JCR);
+        handler.startPrefixMapping("nt", NT);
+        handler.startPrefixMapping("sv", SV);
+        handler.startPrefixMapping("", "");
+        exportTopLevelNode();
+        handler.endPrefixMapping("");
+        handler.endPrefixMapping("sv");
+        handler.endPrefixMapping("nt");
+        handler.endPrefixMapping("jcr");
+        handler.endDocument();
+
+        System.out.println("Saving...");
+        session.save();
+    }
+
+    private void exportTopLevelNode() throws Exception {
+        startNode("top", "nt:folder");
+        for (int i = 0; i < 10; i++) {
+            System.out.println("Exporting " + (i + 1) + "/10...");
+            exportSecondLevelNode(i);
+        }
+        endNode();
+    }
+
+    private void exportSecondLevelNode(int index) throws Exception {
+        startNode("folder" + index, "nt:folder");
+        for (int i = 0; i < 100; i++) {
+            exportThirdLevelNode(i);
+        }
+        endNode();
+    }
+
+    private void exportThirdLevelNode(int index) throws Exception {
+        startNode("folder" + index, "nt:folder");
+        for (int i = 0; i < 100; i++) {
+            exportFourthLevelNode(i);
+        }
+        endNode();
+    }
+
+    private void exportFourthLevelNode(int index) throws Exception {
+        startNode("file" + index, "nt:file");
+        property("jcr:mixinTypes", PropertyType.NAME, "mix:versionable");
+        property("jcr:uuid", PropertyType.STRING, UUID.randomUUID().toString());
+        exportFifthLevelNode();
+        endNode();
+    }
+
+    private void exportFifthLevelNode() throws Exception {
+        startNode("jcr:content", "nt:resource");
+
+        property("jcr:uuid", PropertyType.STRING, UUID.randomUUID().toString());
+        property("jcr:mimeType", PropertyType.STRING, "application/octet-stream");
+        property("jcr:lastModified", PropertyType.DATE, date);
+
+        Writer buffer = new StringWriter();
+        byte[] random = new byte[10 * 1024];
+        new Random().nextBytes(random);
+        Base64.encode(new ByteArrayInputStream(random), buffer);
+        property("jcr:data", PropertyType.BINARY, buffer.toString());
+
+        endNode();
+    }
+
+    private void startNode(String name, String type) throws SAXException {
+        AttributesImpl attributes = new AttributesImpl();
+        attributes.addAttribute(SV, "name", "sv:name", "CDATA", name);
+        handler.startElement(SV, "node", "sv:node", attributes);
+        property("jcr:primaryType", PropertyType.NAME, type);
+    }
+
+    private void endNode() throws SAXException {
+        handler.endElement(SV, "node", "sv:node");
+        nodes++;
+    }
+
+    private void property(String name, int type, String value)
+            throws SAXException {
+        startProperty(name, type);
+        startValue();
+        handler.characters(value.toCharArray(), 0, value.length());
+        endValue();
+        endProperty();
+    }
+
+    private void startProperty(String name, int type) throws SAXException {
+        String tname = PropertyType.nameFromValue(type);
+        AttributesImpl attributes = new AttributesImpl();
+        attributes.addAttribute(SV, "name", "sv:name", "CDATA", name);
+        attributes.addAttribute(SV, "type", "sv:type", "CDATA", tname);
+        handler.startElement(SV, "property", "sv:property", attributes);
+    }
+
+    private void endProperty() throws SAXException {
+        handler.endElement(SV, "property", "sv:property");
+    }
+
+    private void startValue() throws SAXException {
+        AttributesImpl attributes = new AttributesImpl();
+        handler.startElement(SV, "value", "sv:value", attributes);
+    }
+
+    private void endValue() throws SAXException {
+        handler.endElement(SV, "value", "sv:value");
+    }
+
+}

Propchange: jackrabbit/sandbox/benchmark/src/test/java/org/apache/jackrabbit/harness/ImportMemoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/sandbox/benchmark/src/test/java/org/apache/jackrabbit/harness/Repository.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/benchmark/src/test/java/org/apache/jackrabbit/harness/Repository.java?rev=700519&view=auto
==============================================================================
--- jackrabbit/sandbox/benchmark/src/test/java/org/apache/jackrabbit/harness/Repository.java
(added)
+++ jackrabbit/sandbox/benchmark/src/test/java/org/apache/jackrabbit/harness/Repository.java
Tue Sep 30 09:17:48 2008
@@ -0,0 +1,58 @@
+/*
+ * 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.harness;
+
+import java.io.File;
+
+import javax.jcr.Credentials;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.testng.annotations.AfterSuite;
+import org.testng.annotations.BeforeSuite;
+
+public class Repository {
+
+    private static final Credentials CREDENTIALS =
+        new SimpleCredentials("admin", "admin".toCharArray());
+
+    private static RepositoryImpl repository;
+
+    @BeforeSuite
+    public void startRepository() throws Exception {
+        FileUtils.deleteDirectory(new File("target/repository"));
+
+        RepositoryConfig config = RepositoryConfig.create(
+                RepositoryImpl.class.getResourceAsStream("repository.xml"),
+                "target/repository");
+        repository = RepositoryImpl.create(config);
+    }
+
+    @AfterSuite
+    public void closeRepository() throws Exception {
+        repository.shutdown();
+    }
+
+    public static Session login() throws RepositoryException {
+        return repository.login(CREDENTIALS);
+    }
+
+}

Propchange: jackrabbit/sandbox/benchmark/src/test/java/org/apache/jackrabbit/harness/Repository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/sandbox/benchmark/testng.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/benchmark/testng.xml?rev=700519&view=auto
==============================================================================
--- jackrabbit/sandbox/benchmark/testng.xml (added)
+++ jackrabbit/sandbox/benchmark/testng.xml Tue Sep 30 09:17:48 2008
@@ -0,0 +1,8 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
+<suite name="jackrabbit-test-harness">
+  <test name="JackrabbitTestHarness">
+    <packages>
+      <package name="org.apache.jackrabbit.harness"/>
+    </packages>
+  </test>
+</suite>

Propchange: jackrabbit/sandbox/benchmark/testng.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message