Author: mreutegg Date: Tue Aug 25 11:54:11 2015 New Revision: 1697656 URL: http://svn.apache.org/r1697656 Log: OAK-3239: Port RepositoryUpgrade features to the RepositorySidegrade
Apply patch provided by Tomek Rękawek Added: jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/CopyVersionHistorySidegradeTest.java (with props) jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/IncludeExcludeSidegradeTest.java (with props) jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepeatedRepositorySidegradeTest.java (with props) Added: jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/CopyVersionHistorySidegradeTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/CopyVersionHistorySidegradeTest.java?rev=1697656&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/CopyVersionHistorySidegradeTest.java (added) +++ jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/CopyVersionHistorySidegradeTest.java Tue Aug 25 11:54:11 2015 @@ -0,0 +1,61 @@ +/* + * 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.oak.upgrade; + +import org.apache.jackrabbit.oak.Oak; +import org.apache.jackrabbit.oak.jcr.Jcr; +import org.apache.jackrabbit.oak.jcr.repository.RepositoryImpl; +import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore; +import org.apache.jackrabbit.oak.spi.state.NodeStore; +import org.apache.jackrabbit.oak.upgrade.util.VersionCopyTestUtils.VersionCopySetup; +import org.junit.Before; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import java.io.IOException; + +public class CopyVersionHistorySidegradeTest extends CopyVersionHistoryTest { + + private static NodeStore sourceNodeStore; + + @Before + @Override + public void upgradeRepository() throws Exception { + if (sourceNodeStore == null) { + sourceNodeStore = new MemoryNodeStore(); + RepositoryImpl repository = (RepositoryImpl) new Jcr(new Oak(sourceNodeStore)).createRepository(); + Session session = repository.login(CREDENTIALS); + try { + createSourceContent(session); + } finally { + repository.shutdown(); + } + } + } + + @Override + protected Session performCopy(VersionCopySetup setup) throws RepositoryException, IOException { + final NodeStore targetNodeStore = new MemoryNodeStore(); + final RepositorySidegrade sidegrade = new RepositorySidegrade(sourceNodeStore, targetNodeStore); + setup.setup(sidegrade.versionCopyConfiguration); + sidegrade.copy(null); + + repository = (RepositoryImpl) new Jcr(new Oak(targetNodeStore)).createRepository(); + return repository.login(AbstractRepositoryUpgradeTest.CREDENTIALS); + } +} Propchange: jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/CopyVersionHistorySidegradeTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/IncludeExcludeSidegradeTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/IncludeExcludeSidegradeTest.java?rev=1697656&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/IncludeExcludeSidegradeTest.java (added) +++ jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/IncludeExcludeSidegradeTest.java Tue Aug 25 11:54:11 2015 @@ -0,0 +1,64 @@ +package org.apache.jackrabbit.oak.upgrade; + +import org.apache.jackrabbit.oak.Oak; +import org.apache.jackrabbit.oak.jcr.Jcr; +import org.apache.jackrabbit.oak.jcr.repository.RepositoryImpl; +import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore; +import org.apache.jackrabbit.oak.plugins.segment.file.FileStore; +import org.apache.jackrabbit.oak.spi.state.NodeStore; +import org.junit.Before; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import java.io.File; +import java.io.IOException; + +public class IncludeExcludeSidegradeTest extends IncludeExcludeUpgradeTest { + + @Before + public synchronized void upgradeRepository() throws Exception { + if (targetNodeStore == null) { + File directory = getTestDirectory(); + File source = new File(directory, "source"); + source.mkdirs(); + FileStore fileStore = FileStore.newFileStore(source).create(); + SegmentNodeStore segmentNodeStore = SegmentNodeStore.newSegmentNodeStore(fileStore).create(); + RepositoryImpl repository = (RepositoryImpl) new Jcr(new Oak(segmentNodeStore)).createRepository(); + Session session = repository.login(CREDENTIALS); + try { + createSourceContent(session); + } finally { + session.save(); + session.logout(); + repository.shutdown(); + fileStore.close(); + } + final NodeStore target = getTargetNodeStore(); + doUpgradeRepository(source, target); + targetNodeStore = target; + } + } + + @Override + protected void doUpgradeRepository(File source, NodeStore target) throws RepositoryException, IOException { + FileStore fileStore = FileStore.newFileStore(source).create(); + SegmentNodeStore segmentNodeStore = SegmentNodeStore.newSegmentNodeStore(fileStore).create(); + try { + final RepositorySidegrade sidegrade = new RepositorySidegrade(segmentNodeStore, target); + sidegrade.setIncludes( + "/content/foo/en", + "/content/assets/foo" + ); + sidegrade.setExcludes( + "/content/assets/foo/2013", + "/content/assets/foo/2012", + "/content/assets/foo/2011", + "/content/assets/foo/2010" + ); + sidegrade.copy(); + } finally { + fileStore.close(); + } + } +} Propchange: jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/IncludeExcludeSidegradeTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepeatedRepositorySidegradeTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepeatedRepositorySidegradeTest.java?rev=1697656&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepeatedRepositorySidegradeTest.java (added) +++ jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepeatedRepositorySidegradeTest.java Tue Aug 25 11:54:11 2015 @@ -0,0 +1,99 @@ +/* + * 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.oak.upgrade; + +import org.apache.jackrabbit.oak.Oak; +import org.apache.jackrabbit.oak.jcr.Jcr; +import org.apache.jackrabbit.oak.jcr.repository.RepositoryImpl; +import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore; +import org.apache.jackrabbit.oak.plugins.segment.file.FileStore; +import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer; +import org.apache.jackrabbit.oak.spi.state.NodeBuilder; +import org.apache.jackrabbit.oak.spi.state.NodeStore; +import org.junit.Before; + +import javax.annotation.Nonnull; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import java.io.File; +import java.io.IOException; + +public class RepeatedRepositorySidegradeTest extends RepeatedRepositoryUpgradeTest { + + @Before + public synchronized void upgradeRepository() throws Exception { + if (!upgradeComplete) { + final File sourceDir = new File(getTestDirectory(), "jackrabbit2"); + + sourceDir.mkdirs(); + + FileStore fileStore = FileStore.newFileStore(sourceDir).create(); + SegmentNodeStore segmentNodeStore = SegmentNodeStore.newSegmentNodeStore(fileStore).create(); + RepositoryImpl repository = (RepositoryImpl) new Jcr(new Oak(segmentNodeStore)).createRepository(); + Session session = repository.login(CREDENTIALS); + try { + createSourceContent(session); + } finally { + session.save(); + session.logout(); + repository.shutdown(); + fileStore.close(); + } + + final NodeStore target = getTargetNodeStore(); + doUpgradeRepository(sourceDir, target); + fileStore.flush(); + + fileStore = FileStore.newFileStore(sourceDir).create(); + segmentNodeStore = SegmentNodeStore.newSegmentNodeStore(fileStore).create(); + repository = (RepositoryImpl) new Jcr(new Oak(segmentNodeStore)).createRepository(); + session = repository.login(CREDENTIALS); + try { + modifySourceContent(session); + } finally { + session.save(); + session.logout(); + repository.shutdown(); + fileStore.close(); + } + + doUpgradeRepository(sourceDir, target); + fileStore.flush(); + + upgradeComplete = true; + } + } + + @Override + protected void doUpgradeRepository(File source, NodeStore target) throws RepositoryException, IOException { + FileStore fileStore = FileStore.newFileStore(source).create(); + SegmentNodeStore segmentNodeStore = SegmentNodeStore.newSegmentNodeStore(fileStore).create(); + try { + final RepositorySidegrade repositoryUpgrade = new RepositorySidegrade(segmentNodeStore, target); + repositoryUpgrade.copy(new RepositoryInitializer() { + @Override + public void initialize(@Nonnull NodeBuilder builder) { + builder.child("foo").child("bar"); + } + }); + } finally { + fileStore.close(); + } + } +} \ No newline at end of file Propchange: jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepeatedRepositorySidegradeTest.java ------------------------------------------------------------------------------ svn:eol-style = native