You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ju...@apache.org on 2012/09/17 14:54:06 UTC
svn commit: r1386591 [3/7] - in /jackrabbit/oak/trunk: ./ oak-mongomk-api/
oak-mongomk-api/src/ oak-mongomk-api/src/main/
oak-mongomk-api/src/main/java/ oak-mongomk-api/src/main/java/org/
oak-mongomk-api/src/main/java/org/apache/ oak-mongomk-api/src/ma...
Added: jackrabbit/oak/trunk/oak-mongomk-perf/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-perf/pom.xml?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-perf/pom.xml (added)
+++ jackrabbit/oak/trunk/oak-mongomk-perf/pom.xml Mon Sep 17 12:54:01 2012
@@ -0,0 +1,98 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-parent</artifactId>
+ <version>0.5-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>oak-mongomk-perf</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-mongomk-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-mongomk-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-mongomk</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.16</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>com.jamonapi</groupId>
+ <artifactId>jamon</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ <archive>
+ <manifest>
+ <mainClass>org.apache.jackrabbit.mongomk.perf.MicroKernelPerf</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ <executions>
+ <execution>
+ <id>make-assembly</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Propchange: jackrabbit/oak/trunk/oak-mongomk-perf/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/BlobStoreFS.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/BlobStoreFS.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/BlobStoreFS.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/BlobStoreFS.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,55 @@
+/*
+ * 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.mongomk.perf;
+
+import java.io.File;
+import java.io.InputStream;
+
+import org.apache.jackrabbit.mongomk.api.BlobStore;
+
+
+/**
+ * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ */
+public class BlobStoreFS implements BlobStore {
+
+ private final File rootDir;
+
+ public BlobStoreFS(String rootPath) {
+ File rootDir = new File(rootPath);
+ if (!rootDir.isDirectory()) {
+ rootDir.mkdirs();
+ }
+
+ this.rootDir = rootDir;
+ }
+
+ @Override
+ public long getBlobLength(String blobId) throws Exception {
+ return 0;
+ }
+
+ @Override
+ public int readBlob(String blobId, long blobOffset, byte[] buffer, int bufferOffset, int length) throws Exception {
+ return 0;
+ }
+
+ @Override
+ public String writeBlob(InputStream is) throws Exception {
+ return null;
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/BlobStoreFS.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/Config.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/Config.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/Config.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/Config.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,56 @@
+/*
+ * 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.mongomk.perf;
+
+import java.util.Properties;
+
+/**
+ * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ */
+public class Config {
+
+ private static final String MASTER_HOST = "master.host";
+ private static final String MASTER_PORT = "master.port";
+ private static final String MONGO_DATABASE = "mongo.db";
+ private static final String MONGO_HOST = "mongo.host";
+ private static final String MONGO_PORT = "mongo.port";
+ private final Properties properties;
+
+ public Config(Properties properties) {
+ this.properties = properties;
+ }
+
+ public String getMasterHost() {
+ return properties.getProperty(MASTER_HOST);
+ }
+
+ public int getMasterPort() {
+ return Integer.parseInt(properties.getProperty(MASTER_PORT));
+ }
+
+ public String getMongoDatabase() {
+ return properties.getProperty(MONGO_DATABASE);
+ }
+
+ public String getMongoHost() {
+ return properties.getProperty(MONGO_HOST);
+ }
+
+ public int getMongoPort() {
+ return Integer.parseInt(properties.getProperty(MONGO_PORT));
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/Config.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/MicroKernelPerf.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/MicroKernelPerf.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/MicroKernelPerf.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/MicroKernelPerf.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,113 @@
+/*
+ * 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.mongomk.perf;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.log4j.PropertyConfigurator;
+
+/**
+ * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ */
+public class MicroKernelPerf {
+ private static Config config;
+ private static boolean masterMode;
+ private static boolean prepareEnvironment;
+
+ public static void main(String[] args) throws Exception {
+ configLog4J(null);
+ readConfig();
+
+ evalCommandLineOptions(args);
+
+ if (prepareEnvironment) {
+ PrepareEnvironment prepare = new PrepareEnvironment(config);
+ prepare.start();
+ }
+
+ if (masterMode) {
+ MicroKernelPerfMaster master = new MicroKernelPerfMaster(config);
+ master.start();
+ } else {
+ MicroKernelPerfClient client = new MicroKernelPerfClient(config);
+ client.start();
+ }
+ }
+
+ private static void configLog4J(String path) throws Exception {
+ InputStream is = null;
+
+ if (path == null) {
+ is = MicroKernelPerfClient.class.getResourceAsStream("/log4j.cfg");
+ } else {
+ is = new FileInputStream(path);
+ }
+
+ Properties properties = new Properties();
+ properties.load(is);
+ is.close();
+
+ PropertyConfigurator.configure(properties);
+ }
+
+ @SuppressWarnings("static-access")
+ private static void evalCommandLineOptions(String[] args) throws Exception {
+ Option log4jOption = OptionBuilder.withLongOpt("log4j-path").hasArg().withArgName("path")
+ .withDescription("path to a log4j config file").create("log4j");
+ Option masterOption = OptionBuilder.withLongOpt("master-mode").withDescription("starts this in master mode")
+ .create("master");
+ Option prepareOption = OptionBuilder.withLongOpt("prepare-environment")
+ .withDescription("resets the environment before executing").create("prep");
+
+ Options options = new Options();
+ options.addOption(log4jOption);
+ options.addOption(masterOption);
+ options.addOption(prepareOption);
+
+ CommandLineParser parser = new GnuParser();
+ CommandLine line = parser.parse(options, args);
+
+ if (line.hasOption(log4jOption.getOpt())) {
+ configLog4J(line.getOptionValue(log4jOption.getOpt()));
+ }
+ if (line.hasOption(masterOption.getOpt())) {
+ masterMode = true;
+ }
+ if (line.hasOption(prepareOption.getOpt())) {
+ prepareEnvironment = true;
+ }
+ }
+
+ private static void readConfig() throws Exception {
+ InputStream is = MicroKernelPerfClient.class.getResourceAsStream("/config.cfg");
+
+ Properties properties = new Properties();
+ properties.load(is);
+
+ is.close();
+
+ config = new Config(properties);
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/MicroKernelPerf.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/MicroKernelPerfClient.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/MicroKernelPerfClient.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/MicroKernelPerfClient.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/MicroKernelPerfClient.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,220 @@
+/*
+ * 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.mongomk.perf;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.jackrabbit.mongomk.MongoConnection;
+import org.apache.jackrabbit.mongomk.NodeStoreMongo;
+import org.apache.jackrabbit.mongomk.api.BlobStore;
+import org.apache.jackrabbit.mongomk.api.NodeStore;
+import org.apache.jackrabbit.mongomk.impl.MongoMicroKernel;
+import org.apache.jackrabbit.mongomk.impl.json.DefaultJsopHandler;
+import org.apache.jackrabbit.mongomk.impl.json.JsopParser;
+import org.apache.jackrabbit.mongomk.perf.RandomJsopGenerator.RandomJsop;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.log4j.Logger;
+import org.json.JSONObject;
+
+import com.jamonapi.Monitor;
+import com.jamonapi.MonitorFactory;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBCollection;
+import com.mongodb.WriteConcern;
+
+/**
+ * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ */
+public class MicroKernelPerfClient {
+
+ private static class Stats extends BasicDBObject {
+ private static final long serialVersionUID = -8819985408570757782L;
+
+ private Stats(String id, double duration, long numOfCommits, long numOfNodes, long numOfObjects) {
+ put("id", id);
+ put("duration", duration);
+ put("numOfCommits", numOfCommits);
+ put("numOfNodes", numOfNodes);
+ put("numOfObjects", numOfObjects);
+ }
+ }
+
+ private static class VerificationHandler extends DefaultJsopHandler {
+
+ private final List<String> addedNodes = new LinkedList<String>();
+ private final Map<String, List<String>> addedProperties = new HashMap<String, List<String>>();
+
+ @Override
+ public void nodeAdded(String parentPath, String name) {
+ addedNodes.add(PathUtils.concat(parentPath, name));
+ }
+
+ @Override
+ public void propertyAdded(String path, String key, Object value) {
+ List<String> properties = addedProperties.get(path);
+ if (properties == null) {
+ properties = new LinkedList<String>();
+ addedProperties.put(path, properties);
+ }
+ properties.add(key);
+ }
+ }
+
+ private static final Logger LOG = Logger.getLogger(MicroKernelPerfClient.class);
+
+ private static final Logger PERF = Logger.getLogger("PERFORMANCE");
+
+ private static void assertNodeExists(String path, String node, JSONObject result) throws Exception {
+ if (!path.equals(node)) {
+ JSONObject temp = result;
+ for (String segment : PathUtils.elements(node)) {
+ temp = temp.getJSONObject(segment);
+
+ if (temp == null) {
+ throw new Exception(String.format("The node %s could not be found!", node));
+ }
+ }
+ }
+ }
+
+ private static void assertPropertyExists(String path, String property, JSONObject result) throws Exception {
+ JSONObject temp = result;
+ for (String segment : PathUtils.elements(path)) {
+ temp = temp.optJSONObject(segment);
+
+ if (temp == null) {
+ throw new Exception(String.format("The node %s could not be found!", path));
+ }
+ }
+
+ Object value = temp.opt(property);
+ if (value == null) {
+ throw new Exception(String.format("The node %s did not containt the property %s!", path, property));
+ }
+ }
+
+ private Monitor commitMonitor;
+ private final Config config;
+ private Monitor getNodesMonitor;
+
+ private MongoMicroKernel microKernel;
+
+ private MongoConnection mongoConnection;
+
+ private RandomJsopGenerator randomJsopGenerator;
+
+ public MicroKernelPerfClient(Config config) throws Exception {
+ this.config = config;
+
+ initMongo();
+ initMicroKernel();
+ initRandomJsopGenerator();
+ initMonitoring();
+ }
+
+ public void start() throws Exception {
+ LOG.info("Starting client...");
+
+ startCommitting();
+ }
+
+ private void createStats(VerificationHandler handler, JSONObject result) {
+ long numOfNodes = mongoConnection.getNodeCollection().count();
+ long numOfCommits = mongoConnection.getCommitCollection().count();
+
+ Stats commitStats = new Stats("commit", commitMonitor.getLastValue(), numOfCommits, numOfNodes,
+ handler.addedNodes.size() + handler.addedProperties.size());
+
+ Stats getNodesStats = new Stats("getNodes", getNodesMonitor.getLastValue(), numOfCommits, numOfNodes,
+ numOfNodes - handler.addedNodes.size());
+
+ DBCollection statsCollection = mongoConnection.getDB().getCollection("statistics");
+ statsCollection.insert(new Stats[] { commitStats, getNodesStats }, WriteConcern.NONE);
+ }
+
+ private void initMicroKernel() throws Exception {
+ NodeStore nodeStore = new NodeStoreMongo(mongoConnection);
+ BlobStore blobStore = new BlobStoreFS(System.getProperty("java.io.tmpdir"));
+
+ microKernel = new MongoMicroKernel(nodeStore, blobStore);
+ }
+
+ private void initMongo() throws Exception {
+ mongoConnection = new MongoConnection(config.getMongoHost(), config.getMongoPort(), config.getMongoDatabase());
+ }
+
+ private void initMonitoring() {
+ commitMonitor = MonitorFactory.getTimeMonitor("commit");
+ getNodesMonitor = MonitorFactory.getTimeMonitor("getNodes");
+ }
+
+ private void initRandomJsopGenerator() throws Exception {
+ randomJsopGenerator = new RandomJsopGenerator();
+ }
+
+ private void startCommitting() throws Exception {
+ while (true) {
+ RandomJsop randomJsop = randomJsopGenerator.nextRandom();
+
+ String commitPath = randomJsop.getPath();
+ String jsonDiff = randomJsop.getJsop();
+ String revisionId = null;
+ String message = randomJsop.getMessage();
+
+ commitMonitor.start();
+ String newRevisionId = microKernel.commit(commitPath, jsonDiff, revisionId, message);
+ commitMonitor.stop();
+ PERF.info(commitMonitor);
+ LOG.debug(String.format("Committed (%s): %s, %s\n%s", newRevisionId, commitPath, message, jsonDiff));
+
+ getNodesMonitor.start();
+ String getPath = "".equals(commitPath) ? "/" : commitPath;
+ String json = microKernel.getNodes(getPath, newRevisionId, -1, 0, -1, null);
+ getNodesMonitor.stop();
+ PERF.info(getNodesMonitor);
+ LOG.debug(String.format("GetNodes (%s: %s", newRevisionId, json));
+
+ VerificationHandler handler = new VerificationHandler();
+ JsopParser jsopParser = new JsopParser(commitPath, jsonDiff, handler);
+ jsopParser.parse();
+
+ JSONObject result = new JSONObject(json);
+
+ verify(handler, result, getPath);
+ createStats(handler, result);
+
+ randomJsopGenerator.setSeed(getPath, json);
+ }
+ }
+
+ private void verify(VerificationHandler handler, JSONObject result, String getPath) throws Exception {
+ for (String node : handler.addedNodes) {
+ assertNodeExists(getPath, node, result);
+ }
+
+ for (Map.Entry<String, List<String>> entry : handler.addedProperties.entrySet()) {
+ String path = entry.getKey();
+ List<String> properties = entry.getValue();
+ for (String property : properties) {
+ assertPropertyExists(path, property, result);
+ }
+ }
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/MicroKernelPerfClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/MicroKernelPerfMaster.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/MicroKernelPerfMaster.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/MicroKernelPerfMaster.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/MicroKernelPerfMaster.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,257 @@
+/*
+ * 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.mongomk.perf;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.jackrabbit.mongomk.MongoConnection;
+import org.apache.jackrabbit.mongomk.NodeStoreMongo;
+import org.apache.jackrabbit.mongomk.api.BlobStore;
+import org.apache.jackrabbit.mongomk.api.NodeStore;
+import org.apache.jackrabbit.mongomk.impl.MongoMicroKernel;
+import org.apache.jackrabbit.mongomk.impl.json.DefaultJsopHandler;
+import org.apache.jackrabbit.mongomk.impl.json.JsopParser;
+import org.apache.jackrabbit.mongomk.model.CommitMongo;
+import org.apache.jackrabbit.mongomk.model.HeadMongo;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.log4j.Logger;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+import com.mongodb.DBCollection;
+import com.mongodb.DBCursor;
+import com.mongodb.DBObject;
+import com.mongodb.QueryBuilder;
+
+/**
+ * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ */
+public class MicroKernelPerfMaster {
+
+ private class ContinousHandler extends DefaultJsopHandler {
+ private final JSONObject jsonObject;
+
+ private ContinousHandler() {
+ this.jsonObject = new JSONObject();
+ }
+
+ @Override
+ public void nodeAdded(String parentPath, String name) {
+ try {
+ if (!PathUtils.denotesRoot(name)) {
+ JSONObject parent = this.getObjectByPath(parentPath);
+ if (!parent.has(name)) {
+ parent.put(name, new JSONObject());
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void propertyAdded(String path, String key, Object value) {
+ try {
+ if (!PathUtils.denotesRoot(key)) {
+ JSONObject element = this.getObjectByPath(path);
+ element.put(key, value);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private JSONObject getObjectByPath(String path) throws Exception {
+ JSONObject jsonObject = this.jsonObject;
+
+ if (!"".equals(path)) {
+ for (String segment : PathUtils.elements(path)) {
+ LOG.debug(String.format("Checking segment %s of path %s in object %s", segment, path, jsonObject));
+ jsonObject = jsonObject.optJSONObject(segment);
+ if (jsonObject == null) {
+ throw new Exception(String.format("The path %s was not found in the current state", path));
+ }
+ }
+ }
+
+ return jsonObject;
+ }
+ }
+
+ private static final Logger LOG = Logger.getLogger(MicroKernelPerfMaster.class);
+ private final Config config;
+ private ContinousHandler handler;
+ private long lastCommitRevId;
+ private long lastHeadRevId;
+ private long lastRevId;
+ private MongoMicroKernel microKernel;
+ private MongoConnection mongoConnection;
+
+ public MicroKernelPerfMaster(Config config) throws Exception {
+ this.config = config;
+
+ this.initMongo();
+ this.initMicroKernel();
+ this.initHandler();
+ }
+
+ public void start() throws Exception {
+ LOG.info("Starting server...");
+
+ this.startVerifying();
+ }
+
+ private void initHandler() {
+ this.handler = new ContinousHandler();
+ }
+
+ private void initMicroKernel() throws Exception {
+ NodeStore nodeStore = new NodeStoreMongo(this.mongoConnection);
+ BlobStore blobStore = new BlobStoreFS(System.getProperty("java.io.tmpdir"));
+
+ this.microKernel = new MongoMicroKernel(nodeStore, blobStore);
+ }
+
+ private void initMongo() throws Exception {
+ this.mongoConnection = new MongoConnection(this.config.getMongoHost(), this.config.getMongoPort(),
+ this.config.getMongoDatabase());
+ }
+
+ private void startVerifying() throws Exception {
+ while (true) {
+ List<CommitMongo> commitMongos = this.waitForCommit();
+ for (CommitMongo commitMongo : commitMongos) {
+ if (commitMongo.hasFailed()) {
+ LOG.info(String.format("Skipping commit %d because it failed", commitMongo.getRevisionId()));
+ this.lastRevId = commitMongo.getRevisionId();
+ } else {
+ LOG.info(String.format("Verifying commit %d", commitMongo.getRevisionId()));
+ this.verifyCommit(commitMongo);
+ this.verifyCommitOrder(commitMongo);
+ this.lastRevId = commitMongo.getRevisionId();
+ this.lastCommitRevId = commitMongo.getRevisionId();
+ }
+ }
+ }
+ }
+
+ private void verifyCommit(CommitMongo commitMongo) throws Exception {
+ String path = commitMongo.getPath();
+ String jsop = commitMongo.getDiff();
+
+ JsopParser jsopParser = new JsopParser(path, jsop, this.handler);
+ jsopParser.parse();
+
+ String json = this.microKernel.getNodes("/", String.valueOf(commitMongo.getRevisionId()), -1, 0, -1, null);
+ JSONObject resultJson = new JSONObject(json);
+
+ this.verifyEquality(this.handler.jsonObject, resultJson);
+
+ LOG.info(String.format("Successfully verified commit %d", commitMongo.getRevisionId()));
+ }
+
+ private void verifyCommitOrder(CommitMongo commitMongo) throws Exception {
+ long baseRevId = commitMongo.getBaseRevisionId();
+ long revId = commitMongo.getRevisionId();
+ if (baseRevId != this.lastCommitRevId) {
+ throw new Exception(String.format(
+ "Revision %d has a base revision of %d but last successful commit was %d", revId, baseRevId,
+ this.lastCommitRevId));
+ }
+ }
+
+ private void verifyEquality(JSONObject expected, JSONObject actual) throws Exception {
+ LOG.debug(String.format("Verifying for equality %s (expected) vs %s (actual)", expected, actual));
+
+ try {
+ if (expected.length() != (actual.length() - 1)) { // substract 1 b/c of :childCount
+ throw new Exception(String.format(
+ "Unequal number of children/properties: %d (expected) vs %d (actual)", expected.length(),
+ actual.length() - 1));
+ }
+
+ JSONArray expectedNames = expected.names();
+ if (expectedNames != null) {
+ for (int i = 0; i < expectedNames.length(); ++i) {
+ String name = expectedNames.getString(i);
+
+ Object expectedValue = expected.get(name);
+ Object actualValue = actual.get(name);
+
+ if ((expectedValue instanceof JSONObject) && (actualValue instanceof JSONObject)) {
+ this.verifyEquality((JSONObject) expectedValue, (JSONObject) actualValue);
+ } else if ((expectedValue != null) && (actualValue != null)) {
+ if (!expectedValue.equals(actualValue)) {
+ throw new Exception(String.format(
+ "Key %s: Expected value '%s' does not macht actual value '%s'", name,
+ expectedValue, actualValue));
+ }
+ } else if (expectedValue != null) {
+ throw new Exception(String.format(
+ "Key %s: Did not find an actual value for expected value '%s'", name, expectedValue));
+ } else if (actualValue != null) {
+ throw new Exception(String.format(
+ "Key %s: Did not find an expected value for actual value '%s'", name, actualValue));
+ }
+ }
+ }
+ } catch (Exception e) {
+ LOG.error(
+ String.format("Verificytion for equality failed: %s (expected) vs %s (actual)", expected, actual),
+ e);
+ throw e;
+ }
+ }
+
+ private List<CommitMongo> waitForCommit() {
+ // TODO Change this to MicroKernel#waitForCommit
+ List<CommitMongo> commitMongos = new LinkedList<CommitMongo>();
+ this.lastHeadRevId = 0L;
+
+ while (true) {
+ LOG.debug("Waiting for commit...");
+
+ DBCollection headCollection = this.mongoConnection.getHeadCollection();
+ HeadMongo headMongo = (HeadMongo) headCollection.findOne();
+ if (this.lastHeadRevId < headMongo.getHeadRevisionId()) {
+ DBCollection commitCollection = this.mongoConnection.getCommitCollection();
+ DBObject query = QueryBuilder.start(CommitMongo.KEY_REVISION_ID).greaterThan(this.lastRevId)
+ .and(CommitMongo.KEY_REVISION_ID).lessThanEquals(headMongo.getHeadRevisionId()).get();
+ DBObject sort = QueryBuilder.start(CommitMongo.KEY_REVISION_ID).is(1).get();
+ DBCursor dbCursor = commitCollection.find(query).sort(sort);
+ while (dbCursor.hasNext()) {
+ commitMongos.add((CommitMongo) dbCursor.next());
+ }
+
+ if (commitMongos.size() > 0) {
+ LOG.debug(String.format("Found %d new commits", commitMongos.size()));
+
+ break;
+ }
+ this.lastHeadRevId = headMongo.getHeadRevisionId();
+ }
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ // noop
+ }
+ }
+
+ return commitMongos;
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/MicroKernelPerfMaster.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/PrepareEnvironment.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/PrepareEnvironment.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/PrepareEnvironment.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/PrepareEnvironment.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,50 @@
+/*
+ * 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.mongomk.perf;
+
+import org.apache.jackrabbit.mongomk.MongoConnection;
+import org.apache.jackrabbit.mongomk.util.MongoUtil;
+import org.apache.log4j.Logger;
+
+
+/**
+ * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ */
+public class PrepareEnvironment {
+
+ private static final Logger LOG = Logger.getLogger(PrepareEnvironment.class);
+
+ private final Config config;
+ private MongoConnection mongoConnection;
+
+ public PrepareEnvironment(Config config) throws Exception {
+ this.config = config;
+
+ this.initMongo();
+ }
+
+ public void start() {
+ LOG.info("Preparing environment");
+
+ MongoUtil.initDatabase(this.mongoConnection);
+ }
+
+ private void initMongo() throws Exception {
+ this.mongoConnection = new MongoConnection(this.config.getMongoHost(), this.config.getMongoPort(),
+ this.config.getMongoDatabase());
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/PrepareEnvironment.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/RandomJsopGenerator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/RandomJsopGenerator.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/RandomJsopGenerator.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/RandomJsopGenerator.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,190 @@
+/*
+ * 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.mongomk.perf;
+
+import java.util.Random;
+import java.util.UUID;
+
+import org.apache.jackrabbit.mk.json.JsopBuilder;
+import org.apache.jackrabbit.mongomk.api.model.Node;
+import org.apache.jackrabbit.mongomk.impl.builder.NodeBuilder;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+
+
+/**
+ * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ */
+public class RandomJsopGenerator {
+
+ public static class RandomJsop {
+ private final String jsop;
+ private final String message;
+ private final String path;
+
+ public RandomJsop(String path, String jsop, String message) {
+ this.path = path;
+ this.jsop = jsop;
+ this.message = message;
+ }
+
+ public String getJsop() {
+ return this.jsop;
+ }
+
+ public String getMessage() {
+ return this.message;
+ }
+
+ public String getPath() {
+ return this.path;
+ }
+ }
+
+ private static final int OP_ADD_NODE = 0;
+
+ private static final int OP_ADD_PROP = 1;
+
+ public static void main(String[] args) throws Exception {
+ RandomJsopGenerator gen = new RandomJsopGenerator();
+ for (int i = 0; i < 10; ++i) {
+ RandomJsop rand = gen.nextRandom();
+ System.out.println(rand.path);
+ System.out.println(rand.jsop);
+ System.out.println();
+ }
+ }
+
+ private Node[] descendants;
+
+ private String path;
+
+ private Random random;
+
+ public RandomJsopGenerator() throws Exception {
+ this.setSeed("", "{ \"/\" : {} }");
+ }
+
+ public RandomJsop nextRandom() {
+ JsopBuilder jsopBuilder = new JsopBuilder();
+
+ int numOps = this.random.nextInt(10) + 1;
+ for (int i = 0; i < numOps; ++i) {
+ if (this.createRandomOp(jsopBuilder)) {
+ jsopBuilder.newline();
+ } else {
+ --i;
+ }
+ }
+
+ return new RandomJsop(this.path, jsopBuilder.toString(), UUID.randomUUID().toString());
+ }
+
+ public void setSeed(String path, String json) throws Exception {
+ this.path = path;
+ String all = String.format("{ \"%s\" : %s }", PathUtils.getName(path), json);
+ Node node = NodeBuilder.build(all, path);
+ this.descendants = node.getDescendants(false).toArray(new Node[0]);
+ this.random = new Random();
+ }
+
+ private boolean createRandomAddNodeOp(JsopBuilder jsopBuilder) {
+ Node random = this.selectRandom();
+
+ String childName = this.createRandomString();
+ String newPath = PathUtils.concat(random.getPath(), childName);
+ String addPath = newPath;
+ if (!"".equals(this.path)) {
+ addPath = PathUtils.relativize(this.path, newPath);
+ }
+
+ jsopBuilder.tag('+');
+ jsopBuilder.key(addPath);
+ jsopBuilder.object();
+ jsopBuilder.endObject();
+
+ return true;
+ }
+
+ private boolean createRandomAddPropOp(JsopBuilder jsopBuilder) {
+ int next = this.random.nextInt(this.descendants.length);
+ Node random = this.descendants[next];
+ String addPath = PathUtils.relativize(this.path, random.getPath());
+ if ("".equals(addPath)) {
+ addPath = "/";
+ }
+
+ jsopBuilder.tag('+');
+ jsopBuilder.key(addPath);
+ jsopBuilder.object();
+
+ int numProps = this.random.nextInt(10) + 1;
+ for (int i = 0; i < numProps; ++i) {
+ String propName = this.createRandomString();
+ String propValue = this.createRandomString();
+
+ jsopBuilder.key(propName);
+ jsopBuilder.value(propValue);
+ }
+
+ jsopBuilder.endObject();
+
+ return true;
+ }
+
+ private boolean createRandomOp(JsopBuilder jsopBuilder) {
+ boolean performed = false;
+
+ int op = this.random.nextInt(2);
+
+ switch (op) {
+ case OP_ADD_NODE: {
+ performed = this.createRandomAddNodeOp(jsopBuilder);
+ break;
+ }
+ case OP_ADD_PROP: {
+ performed = this.createRandomAddPropOp(jsopBuilder);
+ break;
+ }
+ }
+
+ return performed;
+ }
+
+ private String createRandomString() {
+ int length = this.random.nextInt(6) + 5;
+ char[] chars = new char[length];
+ for (int i = 0; i < length; ++i) {
+ char rand = (char) (this.random.nextInt(65) + 59);
+ if (Character.isLetterOrDigit(rand)) {
+ chars[i] = rand;
+ } else {
+ --i;
+ }
+ }
+
+ return new String(chars);
+ }
+
+ private Node selectRandom() {
+ Node randomNode = null;
+
+ int next = this.random.nextInt(this.descendants.length);
+ randomNode = this.descendants[next];
+
+ return randomNode;
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/perf/RandomJsopGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/MultipleMksWriteNodesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/MultipleMksWriteNodesTest.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/MultipleMksWriteNodesTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/MultipleMksWriteNodesTest.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,126 @@
+/*
+ * 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.mongomk.performance.write;
+
+import org.apache.jackrabbit.mongomk.impl.MongoMicroKernel;
+import org.apache.jackrabbit.mongomk.util.MongoUtil;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+/**
+ * Writing tests with multiple Mks.
+ * @author rogoz
+ *
+ */
+public class MultipleMksWriteNodesTest extends MultipleNodesTestBase {
+
+ static int mkNumber = 5;
+ static long nodesNumber=2000;
+ static SimpleWriter[] sWorker = new SimpleWriter[mkNumber];
+ static AdvanceWriter[] aWorker = new AdvanceWriter[mkNumber];
+
+ @BeforeClass
+ public static void init() throws Exception {
+ readConfig();
+ initMongo();
+ for (int i = 0; i < mkNumber; i++) {
+ MongoMicroKernel mk = initMicroKernel();
+ sWorker[i] = new SimpleWriter("Thread " + i, mk,nodesNumber);
+ aWorker[i] = new AdvanceWriter("Thread " + i, mk,nodesNumber);
+ }
+ }
+
+ @Before
+ public void cleanDatabase() {
+ MongoUtil.initDatabase(mongoConnection);
+ }
+
+ /**
+ * Each worker creates 2000 nodes on the same level.
+ * 5 workers x 2000 nodes=10000 nodes
+ * @throws InterruptedException
+ */
+ @Test
+ public void testWriteSameLine() throws InterruptedException {
+
+ for (int i = 0; i < mkNumber; i++) {
+ sWorker[i].start();
+
+ }
+ for (int i = 0; i < mkNumber; i++) {
+ sWorker[i].join();
+ }
+ }
+
+ /**
+ * Each worker is creating a pyramid containing 2000 nodes.
+ * 5 workers x 2000 nodes=10000 nodes
+ *
+ * @throws InterruptedException
+ */
+ @Test
+ public void testWritePyramid() throws InterruptedException {
+
+ for (int i = 0; i < mkNumber; i++) {
+ aWorker[i].start();
+
+ }
+ for (int i = 0; i < mkNumber; i++) {
+ aWorker[i].join();
+ }
+ }
+
+}
+
+class SimpleWriter extends Thread {
+
+ MongoMicroKernel mk;
+
+ long nodesNumber;
+
+ public SimpleWriter(String str, MongoMicroKernel mk, long nodesNumber) {
+ super(str);
+ this.mk = mk;
+ this.nodesNumber = nodesNumber;
+ }
+
+ public void run() {
+ for (int i = 0; i < nodesNumber; i++) {
+ TestUtil.createNode(mk, "/", getId() + "No" + i);
+ }
+ }
+}
+
+class AdvanceWriter extends Thread {
+
+ MongoMicroKernel mk;
+ long nodesNumber;
+
+ public AdvanceWriter(String str, MongoMicroKernel mk, long nodesNumber) {
+ super(str);
+ this.mk = mk;
+ this.nodesNumber = nodesNumber;
+ }
+
+ public void run() {
+
+ TestUtil.insertNode(mk, "/", 0, 50, nodesNumber, "T" + getId());
+
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/MultipleMksWriteNodesTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/MultipleNodesTestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/MultipleNodesTestBase.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/MultipleNodesTestBase.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/MultipleNodesTestBase.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,59 @@
+/*
+ * 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.mongomk.performance.write;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.jackrabbit.mongomk.MongoConnection;
+import org.apache.jackrabbit.mongomk.NodeStoreMongo;
+import org.apache.jackrabbit.mongomk.api.BlobStore;
+import org.apache.jackrabbit.mongomk.api.NodeStore;
+import org.apache.jackrabbit.mongomk.impl.MongoMicroKernel;
+import org.apache.jackrabbit.mongomk.perf.BlobStoreFS;
+import org.apache.jackrabbit.mongomk.perf.Config;
+
+
+
+
+public class MultipleNodesTestBase {
+
+
+ protected static MongoConnection mongoConnection;
+ private static Config config;
+
+ static void initMongo() throws Exception {
+ mongoConnection = new MongoConnection(config.getMongoHost(),
+ config.getMongoPort(), config.getMongoDatabase());
+ }
+
+ static MongoMicroKernel initMicroKernel() throws Exception {
+ NodeStore nodeStore = new NodeStoreMongo(mongoConnection);
+ BlobStore blobStore = new BlobStoreFS(
+ System.getProperty("java.io.tmpdir"));
+ return new MongoMicroKernel(nodeStore, blobStore);
+ }
+
+ static void readConfig() throws Exception {
+ InputStream is = MultipleNodesTestBase.class
+ .getResourceAsStream("/config.cfg");
+ Properties properties = new Properties();
+ properties.load(is);
+ is.close();
+ config = new Config(properties);
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/MultipleNodesTestBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/TestUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/TestUtil.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/TestUtil.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/TestUtil.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,71 @@
+/*
+ * 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.mongomk.performance.write;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+
+public class TestUtil {
+
+ /**
+ * Recursively builds a pyramid tree structure.
+ *
+ * @param mk
+ * @param parentFolderName
+ * The path where the node will be added.
+ * @param index
+ * @param numberOfChildren
+ * Number of children.
+ * @param nodesNumber
+ * Number of nodes.
+ */
+ static void insertNode(MicroKernel mk, String parentFolderName, int index,
+ int numberOfChildren, long nodesNumber, String nodePrefixName) {
+ // if all the nodes are on the same level
+ if (numberOfChildren == 0) {
+ for (long i = 0; i < nodesNumber; i++) {
+ createNode(mk, parentFolderName, nodePrefixName + i);
+ System.out.println("Created node " + i);
+ }
+ return;
+ }
+
+ if (index >= nodesNumber)
+ return;
+ createNode(mk, parentFolderName, nodePrefixName + index);
+ for (int i = 1; i <= numberOfChildren; i++) {
+ if (!parentFolderName.endsWith("/"))
+ parentFolderName = parentFolderName + "/";
+ insertNode(mk, parentFolderName + nodePrefixName + index, index
+ * numberOfChildren + i, numberOfChildren, nodesNumber, nodePrefixName);
+ }
+
+ }
+
+ /**
+ * Creates a new node.
+ *
+ * @param mk
+ * @param parentNode
+ * @param name
+ * @return
+ */
+ public static String createNode(MicroKernel mk, String parentNode, String name) {
+
+ return mk.commit(parentNode, "+\"" + name + "\" : {} \n", null, "");
+
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/TestUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/WriteNodesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/WriteNodesTest.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/WriteNodesTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/WriteNodesTest.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,85 @@
+/*
+ * 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.mongomk.performance.write;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mongomk.util.MongoUtil;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Measures the time needed for creating different tree node structures.Only one
+ * mongoMk is used for writing operation.
+ *
+ * @author rogoz
+ *
+ */
+public class WriteNodesTest extends MultipleNodesTestBase {
+ static MicroKernel mk;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ readConfig();
+ initMongo();
+ mk=initMicroKernel();
+ }
+
+ @Before
+ public void cleanDatabase() {
+ MongoUtil.initDatabase(mongoConnection);
+ }
+
+ /**
+ * Creates 10000 nodes, all with on the same level with the same parent
+ * node.
+ */
+ @Test
+ public void addNodesInLine() {
+ int nodesNumber = 10000;
+ TestUtil.insertNode(mk, "/", 0, 0, nodesNumber, "N");
+ }
+
+ /**
+ * Creates 10000 nodes, all of them having 10 children nodes.
+ */
+ @Test
+ public void addNodes10Children() {
+ int nodesNumber = 10000;
+ TestUtil.insertNode(mk, "/", 0, 10, nodesNumber, "N");
+ }
+
+ /**
+ * Creates 10000 nodes, all of them having 100 children nodes.
+ */
+ @Test
+ public void addNodes100Children() {
+ int nodesNumber = 10000;
+ TestUtil.insertNode(mk, "/", 0, 100, nodesNumber, "N");
+ }
+
+ /**
+ * Creates 10000 nodes, all of them on different levels.Each node has one
+ * child only.
+ */
+ @Test
+ public void addNodes1Child() {
+ int nodesNumber = 2000;
+ TestUtil.insertNode(mk, "/", 0, 1, nodesNumber,"N");
+ }
+
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/java/org/apache/jackrabbit/mongomk/performance/write/WriteNodesTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/resources/config.cfg
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-perf/src/main/resources/config.cfg?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-perf/src/main/resources/config.cfg (added)
+++ jackrabbit/oak/trunk/oak-mongomk-perf/src/main/resources/config.cfg Mon Sep 17 12:54:01 2012
@@ -0,0 +1,21 @@
+# 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.
+
+master.host = localhost
+master.port = 12345
+
+mongo.host = localhost
+mongo.port = 27017
+mongo.db = mk-tf
\ No newline at end of file
Added: jackrabbit/oak/trunk/oak-mongomk-perf/src/main/resources/log4j.cfg
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-perf/src/main/resources/log4j.cfg?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-perf/src/main/resources/log4j.cfg (added)
+++ jackrabbit/oak/trunk/oak-mongomk-perf/src/main/resources/log4j.cfg Mon Sep 17 12:54:01 2012
@@ -0,0 +1,22 @@
+# 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.
+
+log4j.rootLogger=INFO, console
+
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=[%t] %-5p %c: %m%n
+
+log4j.logger.PERFORMANCE=INFO
\ No newline at end of file
Added: jackrabbit/oak/trunk/oak-mongomk-test/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-test/pom.xml?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-test/pom.xml (added)
+++ jackrabbit/oak/trunk/oak-mongomk-test/pom.xml Mon Sep 17 12:54:01 2012
@@ -0,0 +1,69 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-parent</artifactId>
+ <version>0.5-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>oak-mongomk-test</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-mongomk-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-mongomk-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-mongomk</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ <version>20090211</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-it-mk</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Propchange: jackrabbit/oak/trunk/oak-mongomk-test/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoDataStoreIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoDataStoreIT.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoDataStoreIT.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoDataStoreIT.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,28 @@
+/*
+ * 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.mongomk.test.it;
+
+import org.apache.jackrabbit.mk.test.DataStoreIT;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ DataStoreIT.class,
+})
+public class MongoDataStoreIT {
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoDataStoreIT.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoEverythingIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoEverythingIT.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoEverythingIT.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoEverythingIT.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,28 @@
+/*
+ * 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.mongomk.test.it;
+
+import org.apache.jackrabbit.mk.test.MicroKernelTestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ MicroKernelTestSuite.class
+})
+public class MongoEverythingIT {
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoEverythingIT.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoMicroKernelFixture.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoMicroKernelFixture.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoMicroKernelFixture.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoMicroKernelFixture.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,85 @@
+/*
+ * 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.mongomk.test.it;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.test.MicroKernelFixture;
+import org.apache.jackrabbit.mongomk.BlobStoreMongo;
+import org.apache.jackrabbit.mongomk.MongoConnection;
+import org.apache.jackrabbit.mongomk.NodeStoreMongo;
+import org.apache.jackrabbit.mongomk.api.BlobStore;
+import org.apache.jackrabbit.mongomk.api.NodeStore;
+import org.apache.jackrabbit.mongomk.impl.MongoMicroKernel;
+import org.apache.jackrabbit.mongomk.util.MongoUtil;
+import org.junit.Assert;
+
+
+/**
+ * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ */
+public class MongoMicroKernelFixture implements MicroKernelFixture {
+
+ private static MongoConnection mongoConnection = createMongoConnection();
+
+ private static MongoConnection createMongoConnection() {
+ try {
+ InputStream is = MongoMicroKernelFixture.class.getResourceAsStream("/config.cfg");
+ Properties properties = new Properties();
+ properties.load(is);
+
+ String host = properties.getProperty("mongo.host");
+ int port = Integer.parseInt(properties.getProperty("mongo.port"));
+ String database = properties.getProperty("mongo.db");
+
+ return new MongoConnection(host, port, database);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void setUpCluster(MicroKernel[] cluster) {
+ try {
+ MongoUtil.initDatabase(mongoConnection);
+ NodeStore nodeStore = new NodeStoreMongo(mongoConnection);
+ BlobStore blobStore = new BlobStoreMongo(mongoConnection);
+
+ MicroKernel mk = new MongoMicroKernel(nodeStore, blobStore);
+ for (int i = 0; i < cluster.length; i++) {
+ cluster[i] = mk;
+ }
+ } catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ @Override
+ public void syncMicroKernelCluster(MicroKernel... nodes) {
+ }
+
+ @Override
+ public void tearDownCluster(MicroKernel[] cluster) {
+ try {
+ MongoUtil.clearDatabase(mongoConnection);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoMicroKernelFixture.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoMicroKernelIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoMicroKernelIT.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoMicroKernelIT.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoMicroKernelIT.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,28 @@
+/*
+ * 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.mongomk.test.it;
+
+import org.apache.jackrabbit.mk.test.MicroKernelIT;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ MicroKernelIT.class,
+})
+public class MongoMicroKernelIT {
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/MongoMicroKernelIT.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk-test/src/test/resources/META-INF/services/org.apache.jackrabbit.mk.test.MicroKernelFixture
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-test/src/test/resources/META-INF/services/org.apache.jackrabbit.mk.test.MicroKernelFixture?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-test/src/test/resources/META-INF/services/org.apache.jackrabbit.mk.test.MicroKernelFixture (added)
+++ jackrabbit/oak/trunk/oak-mongomk-test/src/test/resources/META-INF/services/org.apache.jackrabbit.mk.test.MicroKernelFixture Mon Sep 17 12:54:01 2012
@@ -0,0 +1,16 @@
+# 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.
+
+org.apache.jackrabbit.mongomk.test.it.MongoMicroKernelFixture
Added: jackrabbit/oak/trunk/oak-mongomk-test/src/test/resources/config.cfg
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-test/src/test/resources/config.cfg?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-test/src/test/resources/config.cfg (added)
+++ jackrabbit/oak/trunk/oak-mongomk-test/src/test/resources/config.cfg Mon Sep 17 12:54:01 2012
@@ -0,0 +1,18 @@
+# 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.
+
+mongo.host = 127.0.0.1
+mongo.port = 27017
+mongo.db = mk-tf
\ No newline at end of file
Added: jackrabbit/oak/trunk/oak-mongomk/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/pom.xml?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/pom.xml (added)
+++ jackrabbit/oak/trunk/oak-mongomk/pom.xml Mon Sep 17 12:54:01 2012
@@ -0,0 +1,90 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-parent</artifactId>
+ <version>0.5-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>oak-mongomk</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.3</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.6</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>3.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.16</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-mongomk-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-mongomk-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mongodb</groupId>
+ <artifactId>mongo-java-driver</artifactId>
+ <version>2.7.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-commons</artifactId>
+ <version>0.5-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-mongomk-impl</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Propchange: jackrabbit/oak/trunk/oak-mongomk/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/BlobStoreMongo.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/BlobStoreMongo.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/BlobStoreMongo.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/BlobStoreMongo.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,56 @@
+/*
+ * 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.mongomk;
+
+import java.io.InputStream;
+
+import org.apache.jackrabbit.mongomk.api.BlobStore;
+import org.apache.jackrabbit.mongomk.api.command.Command;
+import org.apache.jackrabbit.mongomk.api.command.CommandExecutor;
+import org.apache.jackrabbit.mongomk.command.GetBlobLengthCommandMongo;
+import org.apache.jackrabbit.mongomk.command.ReadBlobCommandMongo;
+import org.apache.jackrabbit.mongomk.command.WriteBlobCommandMongo;
+import org.apache.jackrabbit.mongomk.impl.command.CommandExecutorImpl;
+
+public class BlobStoreMongo implements BlobStore {
+
+ private final MongoConnection mongoConnection;
+ private final CommandExecutor commandExecutor;
+
+ public BlobStoreMongo(MongoConnection mongoConnection) {
+ this.mongoConnection = mongoConnection;
+ this.commandExecutor = new CommandExecutorImpl();
+ }
+
+ @Override
+ public long getBlobLength(String blobId) throws Exception {
+ Command<Long> command = new GetBlobLengthCommandMongo(mongoConnection, blobId);
+ return commandExecutor.execute(command);
+ }
+
+ @Override
+ public int readBlob(String blobId, long blobOffset, byte[] buffer, int bufferOffset, int length) throws Exception {
+ Command<Integer> command = new ReadBlobCommandMongo(mongoConnection, blobId, blobOffset, buffer, bufferOffset, length);
+ return commandExecutor.execute(command);
+ }
+
+ @Override
+ public String writeBlob(InputStream is) throws Exception {
+ Command<String> command = new WriteBlobCommandMongo(mongoConnection, is);
+ return commandExecutor.execute(command);
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/BlobStoreMongo.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MongoConnection.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MongoConnection.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MongoConnection.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MongoConnection.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,107 @@
+/*
+ * 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.mongomk;
+
+import org.apache.jackrabbit.mongomk.model.CommitMongo;
+import org.apache.jackrabbit.mongomk.model.HeadMongo;
+import org.apache.jackrabbit.mongomk.model.NodeMongo;
+
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.Mongo;
+import com.mongodb.gridfs.GridFS;
+
+/**
+ * The {@code MongoConnection} contains connection properties for the {@code MongoDB}.
+ *
+ * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ */
+public class MongoConnection {
+
+ private static final String COLLECTION_COMMIT = "commit";
+ private static final String COLLECTION_HEAD = "head";
+ private static final String COLLECTION_NODES = "nodes";
+ private final DB db;
+ private final GridFS gridFS;
+
+ /**
+ * Constructs a new {@code MongoConnection}.
+ *
+ * @param host The host address.
+ * @param port The port.
+ * @param database The database name.
+ * @throws Exception If an error occurred while trying to connect.
+ */
+ public MongoConnection(String host, int port, String database) throws Exception {
+ db = new Mongo(host, port).getDB(database);
+ gridFS = new GridFS(db);
+ }
+
+ /**
+ * Returns the commit {@link DBCollection}.
+ *
+ * @return The commit {@link DBCollection}.
+ */
+ public DBCollection getCommitCollection() {
+ DBCollection commitCollection = db.getCollection(COLLECTION_COMMIT);
+ commitCollection.setObjectClass(CommitMongo.class);
+
+ return commitCollection;
+ }
+
+ /**
+ * Returns the {@link DB}.
+ *
+ * @return The {@link DB}.
+ */
+ public DB getDB() {
+ return db;
+ }
+
+ /**
+ * Returns the {@link GridFS}.
+ *
+ * @return The {@link GridFS}.
+ */
+ public GridFS getGridFS() {
+ return gridFS;
+ }
+
+ /**
+ * Returns the head {@link DBCollection}.
+ *
+ * @return The head {@link DBCollection}.
+ */
+ public DBCollection getHeadCollection() {
+ DBCollection headCollection = db.getCollection(COLLECTION_HEAD);
+ headCollection.setObjectClass(HeadMongo.class);
+
+ return headCollection;
+ }
+
+ /**
+ * Returns the node {@link DBCollection}.
+ *
+ * @return The node {@link DBCollection}.
+ */
+ public DBCollection getNodeCollection() {
+ DBCollection nodeCollection = db.getCollection(COLLECTION_NODES);
+ nodeCollection.setObjectClass(NodeMongo.class);
+
+ return nodeCollection;
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MongoConnection.java
------------------------------------------------------------------------------
svn:eol-style = native