Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 49165 invoked from network); 4 Nov 2008 12:31:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Nov 2008 12:31:35 -0000 Received: (qmail 35065 invoked by uid 500); 4 Nov 2008 12:31:41 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 35035 invoked by uid 500); 4 Nov 2008 12:31:41 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 35026 invoked by uid 99); 4 Nov 2008 12:31:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Nov 2008 04:31:41 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Nov 2008 12:30:23 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7BA7D23888EB; Tue, 4 Nov 2008 04:30:34 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r711242 - in /jackrabbit/sandbox/jackrabbit-test-harness/cluster: ./ 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/ src/test/java/... Date: Tue, 04 Nov 2008 12:30:34 -0000 To: commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081104123034.7BA7D23888EB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jukka Date: Tue Nov 4 04:30:32 2008 New Revision: 711242 URL: http://svn.apache.org/viewvc?rev=711242&view=rev Log: JCR-1677: Allow workspace creation over cluster Test case for cluster behaviour Added: jackrabbit/sandbox/jackrabbit-test-harness/cluster/ (with props) jackrabbit/sandbox/jackrabbit-test-harness/cluster/pom.xml jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/ jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/ jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/ jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/org/ jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/org/apache/ jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/org/apache/jackrabbit/ jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/org/apache/jackrabbit/harness/ jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/org/apache/jackrabbit/harness/cluster/ jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/org/apache/jackrabbit/harness/cluster/Cluster.java jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/org/apache/jackrabbit/harness/cluster/CreateWorkspaceTest.java jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/resources/ jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/resources/log4j.properties jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/resources/repository.xml jackrabbit/sandbox/jackrabbit-test-harness/cluster/testng.xml Propchange: jackrabbit/sandbox/jackrabbit-test-harness/cluster/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Tue Nov 4 04:30:32 2008 @@ -0,0 +1,5 @@ +target +.* +*.iws +*.iml +*.ipr Added: jackrabbit/sandbox/jackrabbit-test-harness/cluster/pom.xml URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-test-harness/cluster/pom.xml?rev=711242&view=auto ============================================================================== --- jackrabbit/sandbox/jackrabbit-test-harness/cluster/pom.xml (added) +++ jackrabbit/sandbox/jackrabbit-test-harness/cluster/pom.xml Tue Nov 4 04:30:32 2008 @@ -0,0 +1,104 @@ + + + + + + 4.0.0 + + + org.apache + apache + 4 + + + org.apache.jackrabbit.harness + cluster + SNAPSHOT + Jackrabbit Cluster Tests + + + + javax.jcr + jcr + 1.0 + test + + + org.apache.jackrabbit + jackrabbit-core + 1.6-SNAPSHOT + test + + + org.slf4j + slf4j-log4j12 + 1.5.2 + test + + + org.apache.derby + derbynet + 10.2.1.6 + test + + + org.apache.derby + derbyclient + 10.2.1.6 + test + + + org.testng + testng + jdk15 + 5.8 + test + + + + + + + maven-compiler-plugin + + 1.5 + 1.5 + + + + maven-surefire-plugin + + + + derby.stream.error.file + target/derby.log + + + + testng.xml + + + + + + + + Added: jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/org/apache/jackrabbit/harness/cluster/Cluster.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/org/apache/jackrabbit/harness/cluster/Cluster.java?rev=711242&view=auto ============================================================================== --- jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/org/apache/jackrabbit/harness/cluster/Cluster.java (added) +++ jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/org/apache/jackrabbit/harness/cluster/Cluster.java Tue Nov 4 04:30:32 2008 @@ -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.harness.cluster; + +import java.io.File; +import java.net.InetAddress; +import java.sql.DriverManager; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + +import javax.jcr.Repository; +import javax.jcr.Session; + +import org.apache.commons.io.FileUtils; +import org.apache.derby.drda.NetworkServerControl; +import org.apache.jackrabbit.api.JackrabbitWorkspace; +import org.apache.jackrabbit.core.RepositoryImpl; +import org.apache.jackrabbit.core.config.RepositoryConfig; +import org.apache.jackrabbit.core.config.RepositoryConfigurationParser; +import org.testng.annotations.AfterSuite; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; +import org.xml.sax.InputSource; + +public class Cluster { + + /** + * Number of nodes in the test cluster. + */ + private static final int CLUSTER_SIZE = 10; + + private static NetworkServerControl control; + + private static RepositoryImpl[] nodes = new RepositoryImpl[CLUSTER_SIZE]; + + @BeforeSuite + public void startClusterNodes() throws Exception { + control = new NetworkServerControl( + InetAddress.getByName("localhost"), 32649); + control.start(null); + + File cluster = new File("target", "cluster"); + FileUtils.deleteQuietly(cluster); + + File database = new File(cluster, "database"); + Class.forName("org.apache.derby.jdbc.ClientDriver"); + String url = "jdbc:derby://localhost:32649/" + database.getPath(); + DriverManager.getConnection(url + ";create=true").close(); + + for (int i = 0; i < nodes.length; i++) { + File node = new File(cluster, "node" + i); + node.mkdirs(); + + Properties properties = new Properties(); + properties.setProperty( + RepositoryConfigurationParser.REPOSITORY_HOME_VARIABLE, + node.getPath()); + properties.setProperty("node", node.getName()); + properties.setProperty("database", url); + + RepositoryConfigurationParser parser = + new RepositoryConfigurationParser(properties); + InputSource xml = new InputSource( + Cluster.class.getResourceAsStream("/repository.xml")); + RepositoryConfig config = parser.parseRepositoryConfig(xml); + config.init(); + nodes[i] = RepositoryImpl.create(config); + } + } + + public static Collection getNodes() { + return new ArrayList(Arrays.asList(nodes)); + } + + @Test + public void testCreateWorkspace() throws Exception { + Session session = nodes[0].login(); + try { + JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace(); + workspace.createWorkspace("test"); + } finally { + session.logout(); + } + + for (int i = 0; i < nodes.length; i++) { + nodes[i].getClusterNode().sync(); + session = nodes[i].login(); + try { + Set names = new HashSet(Arrays.asList( + session.getWorkspace().getAccessibleWorkspaceNames())); + System.out.println(i + ": " + names); + assert names.contains("test"); + } finally { + session.logout(); + } + } + } + + @AfterSuite + public void stopClusterNodes() throws Exception { + for (int i = 0; i < nodes.length; i++) { + nodes[i].shutdown(); + } + + control.shutdown(); + } + +} Added: jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/org/apache/jackrabbit/harness/cluster/CreateWorkspaceTest.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/org/apache/jackrabbit/harness/cluster/CreateWorkspaceTest.java?rev=711242&view=auto ============================================================================== --- jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/org/apache/jackrabbit/harness/cluster/CreateWorkspaceTest.java (added) +++ jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/java/org/apache/jackrabbit/harness/cluster/CreateWorkspaceTest.java Tue Nov 4 04:30:32 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.cluster; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import javax.jcr.Repository; +import javax.jcr.Session; + +import org.apache.jackrabbit.api.JackrabbitWorkspace; +import org.apache.jackrabbit.core.RepositoryImpl; +import org.testng.annotations.Test; + +public class CreateWorkspaceTest { + + @Test + public void createWorkspace() throws Exception { + // Create a new workspace + Session session = Cluster.getNodes().iterator().next().login(); + try { + JackrabbitWorkspace workspace = + (JackrabbitWorkspace) session.getWorkspace(); + workspace.createWorkspace("test"); + } finally { + session.logout(); + } + + // Check that the workspace is now available in all cluster nodes + for (Repository node : Cluster.getNodes()) { + ((RepositoryImpl) node).getClusterNode().sync(); + session = node.login(); + try { + Set names = new HashSet(Arrays.asList( + session.getWorkspace().getAccessibleWorkspaceNames())); + assert names.contains("test"); + } finally { + session.logout(); + } + } + } + +} Added: jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/resources/log4j.properties URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/resources/log4j.properties?rev=711242&view=auto ============================================================================== --- jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/resources/log4j.properties (added) +++ jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/resources/log4j.properties Tue Nov 4 04:30:32 2008 @@ -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. + +log4j.rootLogger=DEBUG, file +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.File=target/jcr.log +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}: %m (%F, line %L)\n + Added: jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/resources/repository.xml URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/resources/repository.xml?rev=711242&view=auto ============================================================================== --- jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/resources/repository.xml (added) +++ jackrabbit/sandbox/jackrabbit-test-harness/cluster/src/test/resources/repository.xml Tue Nov 4 04:30:32 2008 @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: jackrabbit/sandbox/jackrabbit-test-harness/cluster/testng.xml URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-test-harness/cluster/testng.xml?rev=711242&view=auto ============================================================================== --- jackrabbit/sandbox/jackrabbit-test-harness/cluster/testng.xml (added) +++ jackrabbit/sandbox/jackrabbit-test-harness/cluster/testng.xml Tue Nov 4 04:30:32 2008 @@ -0,0 +1,8 @@ + + + + + + + +