You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2007/02/28 16:16:40 UTC
svn commit: r512797 - in /jackrabbit/trunk/contrib/spi/client: ./
src/test/config/ src/test/java/org/apache/jackrabbit/jcr2spi/
Author: mreutegg
Date: Wed Feb 28 07:16:39 2007
New Revision: 512797
URL: http://svn.apache.org/viewvc?view=rev&rev=512797
Log:
- Simple SPI server main class for testing purpose
- Additional repository stub implementations
Added:
jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/JCR2SPI2JCROverRMIRepositoryStub.java (with props)
jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/JCR2SPIOverRMIRepositoryStub.java (with props)
jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/SPIServer.java (with props)
Modified:
jackrabbit/trunk/contrib/spi/client/project.xml
jackrabbit/trunk/contrib/spi/client/src/test/config/repositoryStubImpl.properties
Modified: jackrabbit/trunk/contrib/spi/client/project.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/project.xml?view=diff&rev=512797&r1=512796&r2=512797
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/project.xml (original)
+++ jackrabbit/trunk/contrib/spi/client/project.xml Wed Feb 28 07:16:39 2007
@@ -53,6 +53,11 @@
<artifactId>jackrabbit-spi-spi2jcr</artifactId>
<version>${jackrabbit.build.version.spi}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-spi-rmi</artifactId>
+ <version>${jackrabbit.build.version.spi}</version>
+ </dependency>
<!-- jackrabbit dependencies -->
<dependency>
<groupId>org.apache.jackrabbit</groupId>
Modified: jackrabbit/trunk/contrib/spi/client/src/test/config/repositoryStubImpl.properties
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/config/repositoryStubImpl.properties?view=diff&rev=512797&r1=512796&r2=512797
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/src/test/config/repositoryStubImpl.properties (original)
+++ jackrabbit/trunk/contrib/spi/client/src/test/config/repositoryStubImpl.properties Wed Feb 28 07:16:39 2007
@@ -8,6 +8,12 @@
# Use this stub implementation instead for testing SPI2JCR on Jackrabbit
#javax.jcr.tck.repository_stub_impl=org.apache.jackrabbit.jcr2spi.JCR2SPI2JCRRepositoryStub
+# Use this stub implementation instead for testing SPI-RMI on Jackrabbit with SPI2JCR
+#javax.jcr.tck.repository_stub_impl=org.apache.jackrabbit.jcr2spi.JCR2SPI2JCROverRMIRepositoryStub
+
+# Use this stub implementation instead for testing SPI-RMI using a stand-alone server
+#javax.jcr.tck.repository_stub_impl=org.apache.jackrabbit.jcr2spi.JCR2SPIOverRMIRepositoryStub
+
# repository specific configuration
org.apache.jackrabbit.jcr2spi.repository.url=http://localhost:5502/jackrabbit/server/
org.apache.jackrabbit.jcr2spi.workspace.name=default
@@ -17,6 +23,9 @@
org.apache.jackrabbit.repository.name=repo
org.apache.jackrabbit.repository.home=../../../jackrabbit-core/applications/test
org.apache.jackrabbit.repository.jaas.config=../../../jackrabbit-core/applications/test/jaas.config
+
+# config for SPI-RMI repository stub
+org.apache.jackrabbit.spi.rmi.repository.name=spi-server
# credential configuration
javax.jcr.tck.superuser.name=admin
Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/JCR2SPI2JCROverRMIRepositoryStub.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/JCR2SPI2JCROverRMIRepositoryStub.java?view=auto&rev=512797
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/JCR2SPI2JCROverRMIRepositoryStub.java (added)
+++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/JCR2SPI2JCROverRMIRepositoryStub.java Wed Feb 28 07:16:39 2007
@@ -0,0 +1,96 @@
+/*
+ * 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.jcr2spi;
+
+import org.apache.jackrabbit.test.RepositoryStubException;
+import org.apache.jackrabbit.core.JackrabbitRepositoryStub;
+import org.apache.jackrabbit.spi2jcr.RepositoryServiceImpl;
+import org.apache.jackrabbit.spi.RepositoryService;
+import org.apache.jackrabbit.spi.rmi.server.ServerRepositoryService;
+import org.apache.jackrabbit.spi.rmi.remote.RemoteRepositoryService;
+import org.apache.jackrabbit.spi.rmi.client.ClientRepositoryService;
+import org.apache.jackrabbit.jcr2spi.config.RepositoryConfig;
+import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
+import org.apache.jackrabbit.value.ValueFactoryImpl;
+import org.apache.log4j.PropertyConfigurator;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFactory;
+import java.util.Properties;
+
+/**
+ * <code>JCR2SPI2JCROverRMIRepositoryStub</code> implements a repository stub that
+ * initializes a Jackrabbit repository and wraps it with a SPI2JCR layer,
+ * a SPI-RMI layer and a JCR2SPI layer.
+ */
+public class JCR2SPI2JCROverRMIRepositoryStub extends JackrabbitRepositoryStub {
+
+ /**
+ * The Jackrabbit repository.
+ */
+ private Repository repo;
+
+ /**
+ * Constructor required by TCK.
+ *
+ * @param env the environment.
+ */
+ public JCR2SPI2JCROverRMIRepositoryStub(Properties env) {
+ super(env);
+ }
+
+ /**
+ * @return the repository instance to test.
+ * @throws RepositoryStubException if an error occurs while starting up the
+ * repository.
+ */
+ public Repository getRepository() throws RepositoryStubException {
+ if (repo == null) {
+ Repository jackrabbitRepo = super.getRepository();
+ RepositoryService spi2jcrRepoService = new RepositoryServiceImpl(jackrabbitRepo);
+ RemoteRepositoryService remoteRepoService = new ServerRepositoryService(spi2jcrRepoService);
+ final RepositoryService localRepoService = new ClientRepositoryService(remoteRepoService);
+
+ try {
+ repo = RepositoryImpl.create(new RepositoryConfig() {
+ public RepositoryService getRepositoryService() {
+ return localRepoService;
+ }
+
+ public ValueFactory getValueFactory() {
+ return ValueFactoryImpl.getInstance();
+ }
+
+ public String getDefaultWorkspaceName() {
+ // not needed for SPI2JCR
+ return null;
+ }
+
+ public CacheBehaviour getCacheBehaviour() {
+ return CacheBehaviour.INVALIDATE;
+ }
+ });
+ } catch (RepositoryException e) {
+ RepositoryStubException ex = new RepositoryStubException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
+ }
+ return repo;
+ }
+}
Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/JCR2SPI2JCROverRMIRepositoryStub.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/JCR2SPIOverRMIRepositoryStub.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/JCR2SPIOverRMIRepositoryStub.java?view=auto&rev=512797
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/JCR2SPIOverRMIRepositoryStub.java (added)
+++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/JCR2SPIOverRMIRepositoryStub.java Wed Feb 28 07:16:39 2007
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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.jcr2spi;
+
+import org.apache.jackrabbit.test.RepositoryStub;
+import org.apache.jackrabbit.test.RepositoryStubException;
+import org.apache.jackrabbit.jcr2spi.config.RepositoryConfig;
+import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
+import org.apache.jackrabbit.spi.RepositoryService;
+import org.apache.jackrabbit.spi.rmi.client.ClientRepositoryService;
+import org.apache.jackrabbit.spi.rmi.remote.RemoteRepositoryService;
+import org.apache.jackrabbit.spi.rmi.common.ValueFactoryImpl;
+import org.apache.log4j.PropertyConfigurator;
+
+import javax.jcr.Repository;
+import javax.jcr.ValueFactory;
+import java.util.Properties;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+
+/**
+ * <code>JCR2SPIRepositoryStub</code> implements a repository stub that returns
+ * a JCR2SPI Client that works on a SPI-RMI transport.
+ */
+public class JCR2SPIOverRMIRepositoryStub extends RepositoryStub {
+
+ /**
+ * Property for the repository url
+ */
+ public static final String PROP_REPOSITORY_NAME = "org.apache.jackrabbit.spi.rmi.repository.name";
+
+ static {
+ PropertyConfigurator.configure(JCR2SPIOverRMIRepositoryStub.class.getClassLoader().getResource("log4j.properties"));
+ }
+
+ /**
+ * The repository instance
+ */
+ private Repository repository;
+
+ /**
+ * Overwritten constructor from base class.
+ */
+ public JCR2SPIOverRMIRepositoryStub(Properties env) {
+ super(env);
+ }
+
+ public synchronized Repository getRepository() throws RepositoryStubException {
+ if (repository == null) {
+ try {
+ String repName = environment.getProperty(PROP_REPOSITORY_NAME);
+
+ Registry reg = LocateRegistry.getRegistry(Registry.REGISTRY_PORT);
+ RemoteRepositoryService remoteService = (RemoteRepositoryService) reg.lookup(repName);
+ final RepositoryService rmiService = new ClientRepositoryService(remoteService);
+
+ RepositoryConfig config = new RepositoryConfig() {
+ public RepositoryService getRepositoryService() {
+ return rmiService;
+ }
+
+ public ValueFactory getValueFactory() {
+ return ValueFactoryImpl.getInstance();
+ }
+
+ public String getDefaultWorkspaceName() {
+ return null;
+ }
+
+ public CacheBehaviour getCacheBehaviour() {
+ return CacheBehaviour.INVALIDATE;
+ }
+ };
+
+ repository = RepositoryImpl.create(config);
+ } catch (Exception e) {
+ throw new RepositoryStubException(e.toString());
+ }
+ }
+ return repository;
+ }
+}
Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/JCR2SPIOverRMIRepositoryStub.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/SPIServer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/SPIServer.java?view=auto&rev=512797
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/SPIServer.java (added)
+++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/SPIServer.java Wed Feb 28 07:16:39 2007
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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.jcr2spi;
+
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.jackrabbit.spi.RepositoryService;
+import org.apache.jackrabbit.spi.rmi.remote.RemoteRepositoryService;
+import org.apache.jackrabbit.spi.rmi.server.ServerRepositoryService;
+import org.apache.jackrabbit.spi2jcr.RepositoryServiceImpl;
+import org.apache.log4j.PropertyConfigurator;
+
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.rmi.RemoteException;
+import java.rmi.NotBoundException;
+import java.rmi.server.UnicastRemoteObject;
+
+/**
+ * <code>SPIServer</code> starts a jackrabbit repository and wraps it with
+ * a SPI2JCR layer and finally makes it available over RMI.
+ */
+public class SPIServer {
+
+ private static final String REPO_CONFIG = "../../../jackrabbit-core/applications/test/repository.xml";
+
+ private static final String REPO_HOME = "../../../jackrabbit-core/applications/test";
+
+ private final org.apache.jackrabbit.core.RepositoryImpl repo;
+
+ private final RemoteRepositoryService remoteService;
+
+ private final Registry reg;
+
+ static {
+ PropertyConfigurator.configure(SPIServer.class.getClassLoader().getResource("log4j.properties"));
+ }
+
+ private SPIServer() throws Exception {
+ // start a jackrabbit repository
+ System.out.println("Starting Jackrabbit...");
+ RepositoryConfig config = RepositoryConfig.create(REPO_CONFIG, REPO_HOME);
+ repo = org.apache.jackrabbit.core.RepositoryImpl.create(config);
+ System.out.println("Jackrabbit started");
+ // wrap with spi2jcr
+ RepositoryService repoService = new RepositoryServiceImpl(repo);
+ System.out.println("Wrapped with SPI2JCR");
+ // create spi server
+ remoteService = new ServerRepositoryService(repoService);
+ System.out.println("Wrapped with SPI-RMI");
+ // register server
+ reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
+ reg.bind("spi-server", remoteService);
+ System.out.println("Bound to RMI Registry");
+ }
+
+ private void shutdown() {
+ System.out.println("Shutting down...");
+ try {
+ reg.unbind("spi-server");
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ } catch (NotBoundException e) {
+ e.printStackTrace();
+ }
+ repo.shutdown();
+ System.out.println("Jackrabbit stopped");
+ }
+
+ public static void main(String[] args) {
+ try {
+ SPIServer server = new SPIServer();
+ // wait for console input, then terminate
+ while (System.in.read() != 'q') {
+ // read again
+ }
+ server.shutdown();
+ System.exit(0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/SPIServer.java
------------------------------------------------------------------------------
svn:eol-style = native