Added: jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/IncludeExcludeUpgradeTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/IncludeExcludeUpgradeTest.java?rev=1792995&view=auto ============================================================================== --- jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/IncludeExcludeUpgradeTest.java (added) +++ jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/IncludeExcludeUpgradeTest.java Fri Apr 28 07:18:26 2017 @@ -0,0 +1,111 @@ +/* + * 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.commons.JcrUtils; +import org.apache.jackrabbit.core.RepositoryContext; +import org.apache.jackrabbit.core.config.RepositoryConfig; +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.spi.state.NodeStore; +import org.junit.Test; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import java.io.File; +import java.io.IOException; + +public class IncludeExcludeUpgradeTest extends AbstractRepositoryUpgradeTest { + + protected NodeStore createTargetNodeStore() { + NodeStore ns = new SegmentNodeStore(); + ((RepositoryImpl) new Jcr(ns).createRepository()).shutdown(); + return ns; + } + + @Override + protected void createSourceContent(Session session) throws Exception { + JcrUtils.getOrCreateByPath("/content/foo/de", "nt:folder", session); + JcrUtils.getOrCreateByPath("/content/foo/en", "nt:folder", session); + JcrUtils.getOrCreateByPath("/content/foo/fr", "nt:folder", session); + JcrUtils.getOrCreateByPath("/content/foo/it", "nt:folder", session); + JcrUtils.getOrCreateByPath("/content/assets/foo", "nt:folder", session); + JcrUtils.getOrCreateByPath("/content/assets/foo/2015", "nt:folder", session); + JcrUtils.getOrCreateByPath("/content/assets/foo/2015/02", "nt:folder", session); + JcrUtils.getOrCreateByPath("/content/assets/foo/2015/01", "nt:folder", session); + JcrUtils.getOrCreateByPath("/content/assets/foo/2014", "nt:folder", session); + JcrUtils.getOrCreateByPath("/content/assets/foo/2013", "nt:folder", session); + JcrUtils.getOrCreateByPath("/content/assets/foo/2012", "nt:folder", session); + JcrUtils.getOrCreateByPath("/content/assets/foo/2011", "nt:folder", session); + JcrUtils.getOrCreateByPath("/content/assets/foo/2010", "nt:folder", session); + JcrUtils.getOrCreateByPath("/content/assets/foo/2010/12", "nt:folder", session); + JcrUtils.getOrCreateByPath("/content/assets/foo/2010/11", "nt:folder", session); + session.save(); + } + + @Override + protected void doUpgradeRepository(File source, NodeStore target) throws RepositoryException, IOException { + final RepositoryConfig config = RepositoryConfig.create(source); + final RepositoryContext context = RepositoryContext.create(config); + try { + final RepositoryUpgrade upgrade = new RepositoryUpgrade(context, target); + upgrade.setIncludes( + "/content/foo/en", + "/content/assets/foo" + ); + upgrade.setExcludes( + "/content/assets/foo/2013", + "/content/assets/foo/2012", + "/content/assets/foo/2011", + "/content/assets/foo/2010" + ); + upgrade.copy(null); + } finally { + context.getRepository().shutdown(); + } + } + + @Test + public void shouldHaveIncludedPaths() throws RepositoryException { + assertExisting( + "/content/foo/en", + "/content/assets/foo/2015/02", + "/content/assets/foo/2015/01", + "/content/assets/foo/2014" + ); + } + + @Test + public void shouldLackPathsThatWereNotIncluded() throws RepositoryException { + assertMissing( + "/content/foo/de", + "/content/foo/fr", + "/content/foo/it" + ); + } + + @Test + public void shouldLackExcludedPaths() throws RepositoryException { + assertMissing( + "/content/assets/foo/2013", + "/content/assets/foo/2012", + "/content/assets/foo/2011", + "/content/assets/foo/2010" + ); + } +}
Added: jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/LongNameTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/LongNameTest.java?rev=1792995&view=auto ============================================================================== --- jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/LongNameTest.java (added) +++ jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/LongNameTest.java Fri Apr 28 07:18:26 2017 @@ -0,0 +1,185 @@ +/* + * 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 static com.google.common.collect.Iterables.cycle; +import static com.google.common.collect.Iterables.limit; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.IOException; + +import javax.jcr.Credentials; +import javax.jcr.Node; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.SimpleCredentials; + +import org.apache.commons.io.FileUtils; +import org.apache.jackrabbit.core.RepositoryContext; +import org.apache.jackrabbit.core.RepositoryImpl; +import org.apache.jackrabbit.core.config.RepositoryConfig; +import org.apache.jackrabbit.oak.plugins.document.DocumentMK; +import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; +import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore; +import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore; +import org.apache.jackrabbit.oak.plugins.segment.memory.MemoryStore; +import org.apache.jackrabbit.oak.spi.state.NodeState; +import org.apache.jackrabbit.oak.spi.state.NodeStore; +import org.apache.jackrabbit.oak.stats.Clock; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class LongNameTest { + + public static final Credentials CREDENTIALS = new SimpleCredentials("admin", "admin".toCharArray()); + + private static final String TOO_LONG_NAME = "this string is an example of a very long node name which is approximately one hundred fifty eight bytes long so too long for the document node store to handle"; + + private static final String NOT_TOO_LONG_NAME = "this string despite it is very long as well is not too long for the document node store to handle so it may be migrated succesfully without troubles"; + + private static RepositoryConfig sourceRepositoryConfig; + + private static File crx2RepoDir; + + @BeforeClass + public static void prepareSourceRepository() throws RepositoryException, IOException, InterruptedException { + crx2RepoDir = new File("target", "upgrade-" + Clock.SIMPLE.getTimeIncreasing()); + FileUtils.deleteQuietly(crx2RepoDir); + + sourceRepositoryConfig = createCrx2Config(crx2RepoDir); + RepositoryContext ctx = RepositoryContext.create(sourceRepositoryConfig); + RepositoryImpl sourceRepository = ctx.getRepository(); + Session session = sourceRepository.login(CREDENTIALS); + try { + Assert.assertTrue(TOO_LONG_NAME.getBytes().length > 150); + Assert.assertTrue(NOT_TOO_LONG_NAME.getBytes().length < 150); + + Node longNameParent = createParent(session.getRootNode()); + Assert.assertTrue(longNameParent.getPath().length() >= 350); + + longNameParent.addNode(TOO_LONG_NAME); + longNameParent.addNode(NOT_TOO_LONG_NAME); + session.save(); + + Assert.assertTrue(longNameParent.hasNode(TOO_LONG_NAME)); + Assert.assertTrue(longNameParent.hasNode(NOT_TOO_LONG_NAME)); + + } finally { + session.logout(); + } + sourceRepository.shutdown(); + } + + private static RepositoryConfig createCrx2Config(File crx2RepoDir) throws RepositoryException, IOException { + File source = new File(crx2RepoDir, "source"); + source.mkdirs(); + return RepositoryConfig.install(source); + } + + @Test + public void longNameShouldBeSkipped() throws RepositoryException, IOException { + DocumentNodeStore nodeStore = new DocumentMK.Builder().getNodeStore(); + try { + upgrade(nodeStore, false, true); + + NodeState parent = getParent(nodeStore.getRoot()); + Assert.assertTrue(parent.hasChildNode(NOT_TOO_LONG_NAME)); + Assert.assertEquals(1, parent.getChildNodeCount(10)); + + // The following throws an DocumentStoreException: + // Assert.assertFalse(parent.hasChildNode(TOO_LONG_NAME)); + } finally { + nodeStore.dispose(); + } + } + + @Test + public void assertNoLongNamesTest() throws IOException, RepositoryException { + RepositoryConfig config = createCrx2Config(crx2RepoDir); + RepositoryContext context = RepositoryContext.create(config); + try { + RepositoryUpgrade upgrade = new RepositoryUpgrade(context, new MemoryNodeStore()); + try { + upgrade.assertNoLongNames(); + fail("Exception should be thrown"); + } catch (RepositoryException e) { + // that's fine + } + } finally { + context.getRepository().shutdown(); + } + } + + @Test(expected = RepositoryException.class) + public void longNameOnDocumentStoreThrowsAnException() throws RepositoryException, IOException { + DocumentNodeStore nodeStore = new DocumentMK.Builder().getNodeStore(); + try { + upgrade(nodeStore, false, false); + } finally { + nodeStore.dispose(); + } + } + + @Test + public void longNameOnSegmentStoreWorksFine() throws RepositoryException, IOException { + NodeStore nodeStore = new SegmentNodeStore(new MemoryStore()); + upgrade(nodeStore, false, false); + + NodeState parent = getParent(nodeStore.getRoot()); + Assert.assertTrue(parent.hasChildNode(NOT_TOO_LONG_NAME)); + Assert.assertTrue(parent.hasChildNode(TOO_LONG_NAME)); + } + + private static void upgrade(NodeStore target, boolean skipNameCheck, boolean filterLongNames) throws RepositoryException, IOException { + RepositoryConfig config = createCrx2Config(crx2RepoDir); + RepositoryContext context = RepositoryContext.create(config); + try { + RepositoryUpgrade upgrade = new RepositoryUpgrade(context, target); + upgrade.setCheckLongNames(skipNameCheck); + upgrade.setFilterLongNames(filterLongNames); + upgrade.copy(null); + } finally { + context.getRepository().shutdown(); + } + } + + private static Node createParent(Node root) throws RepositoryException { + Node current = root; + for (String segment : getParentSegments()) { + current = current.addNode(segment); + } + return current; + } + + private static NodeState getParent(NodeState root) throws RepositoryException { + NodeState current = root; + for (String segment : getParentSegments()) { + current = current.getChildNode(segment); + } + return current; + } + + private static Iterable<String> getParentSegments() { + return limit(cycle("this", "is", "a", "path"), 100); // total path + // length + // = 350 + } +} Modified: jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/PrivilegeUpgradeTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/PrivilegeUpgradeTest.java?rev=1792995&r1=1792994&r2=1792995&view=diff ============================================================================== --- jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/PrivilegeUpgradeTest.java (original) +++ jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/PrivilegeUpgradeTest.java Fri Apr 28 07:18:26 2017 @@ -24,7 +24,6 @@ import java.util.Map; import java.util.Set; import javax.jcr.NamespaceRegistry; import javax.jcr.Node; -import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.security.Privilege; @@ -76,26 +75,18 @@ import static org.apache.jackrabbit.oak. public class PrivilegeUpgradeTest extends AbstractRepositoryUpgradeTest { @Override - @SuppressWarnings("unchecked") - protected void createSourceContent(Repository repository) throws Exception { - Session session = repository.login(CREDENTIALS); - try { - JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace(); - - NamespaceRegistry registry = workspace.getNamespaceRegistry(); - registry.registerNamespace("test", "http://www.example.org/"); - - PrivilegeManager privilegeManager = workspace.getPrivilegeManager(); - privilegeManager.registerPrivilege("test:privilege", false, null); - privilegeManager.registerPrivilege( - "test:aggregate", false, new String[] { "jcr:read", "test:privilege" }); - privilegeManager.registerPrivilege("test:privilege2", true, null); - privilegeManager.registerPrivilege( - "test:aggregate2", true, new String[] { "test:aggregate", "test:privilege2" }); - - } finally { - session.logout(); - } + protected void createSourceContent(Session session) throws Exception { + JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace(); + + NamespaceRegistry registry = workspace.getNamespaceRegistry(); + registry.registerNamespace("test", "http://www.example.org/"); + + PrivilegeManager privilegeManager = workspace.getPrivilegeManager(); + privilegeManager.registerPrivilege("test:privilege", false, null); + privilegeManager.registerPrivilege("test:aggregate", false, new String[] { "jcr:read", "test:privilege" }); + privilegeManager.registerPrivilege("test:privilege2", true, null); + privilegeManager.registerPrivilege("test:aggregate2", true, + new String[] { "test:aggregate", "test:privilege2" }); } @Test Added: jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepeatedRepositorySidegradeTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepeatedRepositorySidegradeTest.java?rev=1792995&view=auto ============================================================================== --- jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepeatedRepositorySidegradeTest.java (added) +++ jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepeatedRepositorySidegradeTest.java Fri Apr 28 07:18:26 2017 @@ -0,0 +1,102 @@ +/* + * 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.api.CommitFailedException; +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.commit.CommitInfo; +import org.apache.jackrabbit.oak.spi.commit.EmptyHook; +import org.apache.jackrabbit.oak.spi.state.NodeBuilder; +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 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 = new SegmentNodeStore(fileStore); + 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, false); + fileStore.flush(); + + fileStore = FileStore.newFileStore(sourceDir).create(); + segmentNodeStore = new SegmentNodeStore(fileStore); + 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, true); + fileStore.flush(); + + upgradeComplete = true; + } + } + + @Override + protected void doUpgradeRepository(File source, NodeStore target, boolean skipInit) throws RepositoryException, IOException { + FileStore fileStore = FileStore.newFileStore(source).create(); + SegmentNodeStore segmentNodeStore = new SegmentNodeStore(fileStore); + try { + final RepositorySidegrade repositoryUpgrade = new RepositorySidegrade(segmentNodeStore, target); + + NodeBuilder builder = target.getRoot().builder(); + builder.child("foo").child("bar"); + target.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); + + repositoryUpgrade.copy(); + } catch (CommitFailedException e) { + throw new RepositoryException(e); + } finally { + fileStore.close(); + } + } +} Modified: jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepeatedRepositoryUpgradeTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepeatedRepositoryUpgradeTest.java?rev=1792995&r1=1792994&r2=1792995&view=diff ============================================================================== --- jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepeatedRepositoryUpgradeTest.java (original) +++ jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepeatedRepositoryUpgradeTest.java Fri Apr 28 07:18:26 2017 @@ -54,7 +54,7 @@ import java.io.IOException; */ public class RepeatedRepositoryUpgradeTest extends AbstractRepositoryUpgradeTest { - private static boolean upgradeComplete; + protected static boolean upgradeComplete; private static FileStore fileStore; @Override @@ -88,38 +88,43 @@ public class RepeatedRepositoryUpgradeTe sourceDir.mkdirs(); RepositoryImpl source = createSourceRepository(sourceDir); - + Session session = source.login(CREDENTIALS); try { - createSourceContent(source); + createSourceContent(session); } finally { + session.save(); + session.logout(); source.shutdown(); } final NodeStore target = getTargetNodeStore(); - doUpgradeRepository(sourceDir, target); + doUpgradeRepository(sourceDir, target, false); fileStore.flush(); // re-create source repo source = createSourceRepository(sourceDir); + session = source.login(CREDENTIALS); try { - modifySourceContent(source); + modifySourceContent(session); } finally { + session.save(); + session.logout(); source.shutdown(); } - doUpgradeRepository(sourceDir, target); + doUpgradeRepository(sourceDir, target, true); fileStore.flush(); upgradeComplete = true; } } - @Override - protected void doUpgradeRepository(File source, NodeStore target) throws RepositoryException { + protected void doUpgradeRepository(File source, NodeStore target, boolean skipInit) throws RepositoryException, IOException { final RepositoryConfig config = RepositoryConfig.create(source); final RepositoryContext context = RepositoryContext.create(config); try { final RepositoryUpgrade repositoryUpgrade = new RepositoryUpgrade(context, target); + repositoryUpgrade.setSkipInitialization(skipInit); repositoryUpgrade.copy(new RepositoryInitializer() { @Override public void initialize(@Nonnull NodeBuilder builder) { @@ -132,44 +137,26 @@ public class RepeatedRepositoryUpgradeTe } @Override - protected void createSourceContent(Repository repository) throws RepositoryException { - Session session = null; - try { - session = repository.login(CREDENTIALS); - - registerCustomPrivileges(session); + protected void createSourceContent(Session session) throws RepositoryException { + registerCustomPrivileges(session); - JcrUtils.getOrCreateByPath("/content/child1/grandchild1", "nt:unstructured", session); - JcrUtils.getOrCreateByPath("/content/child1/grandchild2", "nt:unstructured", session); - JcrUtils.getOrCreateByPath("/content/child1/grandchild3", "nt:unstructured", session); - JcrUtils.getOrCreateByPath("/content/child2/grandchild1", "nt:unstructured", session); - JcrUtils.getOrCreateByPath("/content/child2/grandchild2", "nt:unstructured", session); + JcrUtils.getOrCreateByPath("/content/child1/grandchild1", "nt:unstructured", session); + JcrUtils.getOrCreateByPath("/content/child1/grandchild2", "nt:unstructured", session); + JcrUtils.getOrCreateByPath("/content/child1/grandchild3", "nt:unstructured", session); + JcrUtils.getOrCreateByPath("/content/child2/grandchild1", "nt:unstructured", session); + JcrUtils.getOrCreateByPath("/content/child2/grandchild2", "nt:unstructured", session); - session.save(); - } finally { - if (session != null && session.isLive()) { - session.logout(); - } - } + session.save(); } - private void modifySourceContent(Repository repository) throws RepositoryException { - Session session = null; - try { - session = repository.login(CREDENTIALS); - - JcrUtils.getOrCreateByPath("/content/child2/grandchild3", "nt:unstructured", session); - JcrUtils.getOrCreateByPath("/content/child3", "nt:unstructured", session); + protected void modifySourceContent(Session session) throws RepositoryException { + JcrUtils.getOrCreateByPath("/content/child2/grandchild3", "nt:unstructured", session); + JcrUtils.getOrCreateByPath("/content/child3", "nt:unstructured", session); - final Node child1 = JcrUtils.getOrCreateByPath("/content/child1", "nt:unstructured", session); - child1.remove(); + final Node child1 = JcrUtils.getOrCreateByPath("/content/child1", "nt:unstructured", session); + child1.remove(); - session.save(); - } finally { - if (session != null && session.isLive()) { - session.logout(); - } - } + session.save(); } private void registerCustomPrivileges(Session session) throws RepositoryException { Modified: jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryGroupMemberUpgradeTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryGroupMemberUpgradeTest.java?rev=1792995&r1=1792994&r2=1792995&view=diff ============================================================================== --- jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryGroupMemberUpgradeTest.java (original) +++ jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryGroupMemberUpgradeTest.java Fri Apr 28 07:18:26 2017 @@ -24,7 +24,7 @@ import java.util.Iterator; import java.util.Set; import javax.jcr.Node; -import javax.jcr.Repository; +import javax.jcr.Session; import javax.jcr.nodetype.NodeType; import org.apache.jackrabbit.api.JackrabbitSession; @@ -59,27 +59,23 @@ public class RepositoryGroupMemberUpgrad return 2; } - protected void createSourceContent(Repository repository) throws Exception { - JackrabbitSession session = (JackrabbitSession) repository.login(CREDENTIALS); - try { - UserManager userMgr = session.getUserManager(); - userMgr.autoSave(false); - User users[] = new User[getNumUsers()]; - for (int i = 0; i < users.length; i++) { - String userId = TEST_USER_PREFIX + i; - users[i] = userMgr.createUser(userId, userId); - } + @Override + protected void createSourceContent(Session session) throws Exception { + UserManager userMgr = ((JackrabbitSession) session).getUserManager(); + userMgr.autoSave(false); + User users[] = new User[getNumUsers()]; + for (int i = 0; i < users.length; i++) { + String userId = TEST_USER_PREFIX + i; + users[i] = userMgr.createUser(userId, userId); + } - for (int i = 0; i < getNumGroups(); i++) { - Group g = userMgr.createGroup(TEST_GROUP_PREFIX + i); - for (User user : users) { - g.addMember(user); - } + for (int i = 0; i < getNumGroups(); i++) { + Group g = userMgr.createGroup(TEST_GROUP_PREFIX + i); + for (User user : users) { + g.addMember(user); } - session.save(); - } finally { - session.logout(); } + session.save(); } @Test Copied: jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegradeTest.java (from r1792994, jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java) URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegradeTest.java?p2=jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegradeTest.java&p1=jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java&r1=1792994&r2=1792995&rev=1792995&view=diff ============================================================================== --- jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java (original) +++ jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegradeTest.java Fri Apr 28 07:18:26 2017 @@ -18,22 +18,34 @@ */ package org.apache.jackrabbit.oak.upgrade; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertTrue; +import static org.apache.jackrabbit.JcrConstants.JCR_FROZENMIXINTYPES; +import static org.apache.jackrabbit.JcrConstants.JCR_FROZENPRIMARYTYPE; +import static org.apache.jackrabbit.JcrConstants.JCR_FROZENUUID; +import static org.apache.jackrabbit.JcrConstants.JCR_UUID; +import static org.apache.jackrabbit.JcrConstants.MIX_VERSIONABLE; +import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED; + import java.io.ByteArrayInputStream; import java.io.InputStream; import java.math.BigDecimal; import java.util.Calendar; import java.util.Random; -import java.util.Set; + import javax.jcr.Binary; +import javax.jcr.Credentials; import javax.jcr.NamespaceRegistry; import javax.jcr.Node; -import javax.jcr.NodeIterator; import javax.jcr.Property; import javax.jcr.PropertyIterator; import javax.jcr.PropertyType; import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; +import javax.jcr.SimpleCredentials; import javax.jcr.Value; import javax.jcr.nodetype.NodeType; import javax.jcr.nodetype.NodeTypeManager; @@ -44,24 +56,22 @@ import javax.jcr.version.Version; import javax.jcr.version.VersionHistory; import javax.jcr.version.VersionManager; -import com.google.common.collect.Sets; +import org.apache.jackrabbit.api.JackrabbitSession; import org.apache.jackrabbit.api.JackrabbitWorkspace; +import org.apache.jackrabbit.oak.Oak; +import org.apache.jackrabbit.oak.jcr.Jcr; import org.apache.jackrabbit.oak.plugins.index.IndexConstants; +import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore; +import org.apache.jackrabbit.oak.spi.commit.CommitInfo; +import org.apache.jackrabbit.oak.spi.commit.EmptyHook; import org.apache.jackrabbit.oak.spi.security.user.UserConstants; +import org.apache.jackrabbit.oak.spi.state.NodeBuilder; +import org.apache.jackrabbit.oak.spi.state.NodeState; +import org.apache.jackrabbit.oak.spi.state.NodeStore; +import org.junit.Before; import org.junit.Test; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; -import static org.apache.jackrabbit.JcrConstants.JCR_FROZENMIXINTYPES; -import static org.apache.jackrabbit.JcrConstants.JCR_FROZENPRIMARYTYPE; -import static org.apache.jackrabbit.JcrConstants.JCR_FROZENUUID; -import static org.apache.jackrabbit.JcrConstants.JCR_UUID; -import static org.apache.jackrabbit.JcrConstants.MIX_VERSIONABLE; -import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED; - -public class RepositoryUpgradeTest extends AbstractRepositoryUpgradeTest { +public class RepositorySidegradeTest { private static final Calendar DATE = Calendar.getInstance(); @@ -70,10 +80,30 @@ public class RepositoryUpgradeTest exten static { new Random().nextBytes(BINARY); } + + private static final Credentials CREDENTIALS = new SimpleCredentials("admin", "admin".toCharArray()); + + private NodeStore targetNodeStore; + private Repository targetRepository; + + @Before + public synchronized void upgradeRepository() throws Exception { + targetNodeStore = new SegmentNodeStore(); + targetRepository = new Jcr(new Oak(targetNodeStore)).createRepository(); + NodeStore source = createSourceContent(); + RepositorySidegrade sidegrade = new RepositorySidegrade(source, targetNodeStore); + sidegrade.copy(); + } + + public JackrabbitSession createAdminSession() throws RepositoryException { + return (JackrabbitSession) targetRepository.login(CREDENTIALS); + } - @Override @SuppressWarnings("unchecked") - protected void createSourceContent(Repository repository) throws Exception { + protected NodeStore createSourceContent() throws Exception { + NodeStore source = new SegmentNodeStore(); + Repository repository = new Jcr(new Oak(source)).createRepository(); + Session session = repository.login(CREDENTIALS); try { JackrabbitWorkspace workspace = @@ -120,11 +150,6 @@ public class RepositoryUpgradeTest exten child.addNode("child2", NT_UNSTRUCTURED); session.save(); - Node sns = root.addNode("sns"); - sns.addNode("sibling"); - sns.addNode("sibling"); - sns.addNode("sibling"); - session.getWorkspace().getVersionManager().checkin("/versionable"); Node properties = root.addNode("properties", "test:unstructured"); @@ -162,6 +187,7 @@ public class RepositoryUpgradeTest exten } finally { binary.dispose(); } + return source; } finally { session.logout(); } @@ -416,25 +442,6 @@ public class RepositoryUpgradeTest exten } finally { session.logout(); } - } - - @Test - public void verifySNS() throws RepositoryException { - Set<String> nodeNames = Sets.newHashSet("sibling", "sibling[2]", "sibling[3]"); - Session session = createAdminSession(); - try { - Node sns = session.getNode("/sns"); - NodeIterator ns = sns.getNodes(); - int c = 0; - while (ns.hasNext()) { - Node node = ns.nextNode(); - String name = node.getName(); - assertTrue("Unexpected node: " + name, nodeNames.remove(name)); - } - assertTrue("Missing nodes: " + nodeNames, nodeNames.isEmpty()); - } finally { - session.logout(); - } } } Modified: jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java?rev=1792995&r1=1792994&r2=1792995&view=diff ============================================================================== --- jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java (original) +++ jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java Fri Apr 28 07:18:26 2017 @@ -31,7 +31,6 @@ import javax.jcr.NodeIterator; import javax.jcr.Property; import javax.jcr.PropertyIterator; import javax.jcr.PropertyType; -import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.Value; @@ -73,97 +72,89 @@ public class RepositoryUpgradeTest exten @Override @SuppressWarnings("unchecked") - protected void createSourceContent(Repository repository) throws Exception { - Session session = repository.login(CREDENTIALS); - try { - JackrabbitWorkspace workspace = - (JackrabbitWorkspace) session.getWorkspace(); + protected void createSourceContent(Session session) throws Exception { + JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace(); - NamespaceRegistry registry = workspace.getNamespaceRegistry(); - registry.registerNamespace("test", "http://www.example.org/"); + NamespaceRegistry registry = workspace.getNamespaceRegistry(); + registry.registerNamespace("test", "http://www.example.org/"); - NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager(); - NodeTypeTemplate template = nodeTypeManager.createNodeTypeTemplate(); - template.setName("test:unstructured"); - template.setDeclaredSuperTypeNames( - new String[] {"nt:unstructured"}); - PropertyDefinitionTemplate pDef1 = nodeTypeManager.createPropertyDefinitionTemplate(); - pDef1.setName("defaultString"); - pDef1.setRequiredType(PropertyType.STRING); - Value stringValue = session.getValueFactory().createValue("stringValue"); - pDef1.setDefaultValues(new Value[] {stringValue}); - template.getPropertyDefinitionTemplates().add(pDef1); - - PropertyDefinitionTemplate pDef2 = nodeTypeManager.createPropertyDefinitionTemplate(); - pDef2.setName("defaultPath"); - pDef2.setRequiredType(PropertyType.PATH); - Value pathValue = session.getValueFactory().createValue("/jcr:path/nt:value", PropertyType.PATH); - pDef2.setDefaultValues(new Value[] {pathValue}); - template.getPropertyDefinitionTemplates().add(pDef2); - - nodeTypeManager.registerNodeType(template, false); - - template = nodeTypeManager.createNodeTypeTemplate(); - template.setName("test:referenceable"); - template.setDeclaredSuperTypeNames( - new String[] {"nt:unstructured", "mix:referenceable"}); - nodeTypeManager.registerNodeType(template, false); - - Node root = session.getRootNode(); - - Node referenceable = - root.addNode("referenceable", "test:unstructured"); - referenceable.addMixin(NodeType.MIX_REFERENCEABLE); - Node versionable = root.addNode("versionable", NT_UNSTRUCTURED); - versionable.addMixin(MIX_VERSIONABLE); - Node child = versionable.addNode("child", "test:referenceable"); - child.addNode("child2", NT_UNSTRUCTURED); - session.save(); - - Node sns = root.addNode("sns"); - sns.addNode("sibling"); - sns.addNode("sibling"); - sns.addNode("sibling"); - - session.getWorkspace().getVersionManager().checkin("/versionable"); - - Node properties = root.addNode("properties", "test:unstructured"); - properties.setProperty("boolean", true); - Binary binary = session.getValueFactory().createBinary( - new ByteArrayInputStream(BINARY)); - try { - properties.setProperty("binary", binary); - } finally { - binary.dispose(); - } - properties.setProperty("date", DATE); - properties.setProperty("decimal", new BigDecimal(123)); - properties.setProperty("double", Math.PI); - properties.setProperty("long", 9876543210L); - properties.setProperty("reference", referenceable); - properties.setProperty("weak_reference", session.getValueFactory().createValue(referenceable, true)); - properties.setProperty("mv_reference", new Value[]{session.getValueFactory().createValue(versionable, false)}); - properties.setProperty("mv_weak_reference", new Value[]{session.getValueFactory().createValue(versionable, true)}); - properties.setProperty("string", "test"); - properties.setProperty("multiple", "a,b,c".split(",")); - session.save(); + NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager(); + NodeTypeTemplate template = nodeTypeManager.createNodeTypeTemplate(); + template.setName("test:unstructured"); + template.setDeclaredSuperTypeNames(new String[] { "nt:unstructured" }); + PropertyDefinitionTemplate pDef1 = nodeTypeManager.createPropertyDefinitionTemplate(); + pDef1.setName("defaultString"); + pDef1.setRequiredType(PropertyType.STRING); + Value stringValue = session.getValueFactory().createValue("stringValue"); + pDef1.setDefaultValues(new Value[] { stringValue }); + template.getPropertyDefinitionTemplates().add(pDef1); + + PropertyDefinitionTemplate pDef2 = nodeTypeManager.createPropertyDefinitionTemplate(); + pDef2.setName("defaultPath"); + pDef2.setRequiredType(PropertyType.PATH); + Value pathValue = session.getValueFactory().createValue("/jcr:path/nt:value", PropertyType.PATH); + pDef2.setDefaultValues(new Value[] { pathValue }); + template.getPropertyDefinitionTemplates().add(pDef2); + + nodeTypeManager.registerNodeType(template, false); + + template = nodeTypeManager.createNodeTypeTemplate(); + template.setName("test:referenceable"); + template.setDeclaredSuperTypeNames(new String[] { "nt:unstructured", "mix:referenceable" }); + nodeTypeManager.registerNodeType(template, false); + + Node root = session.getRootNode(); + + Node referenceable = root.addNode("referenceable", "test:unstructured"); + referenceable.addMixin(NodeType.MIX_REFERENCEABLE); + Node versionable = root.addNode("versionable", NT_UNSTRUCTURED); + versionable.addMixin(MIX_VERSIONABLE); + Node child = versionable.addNode("child", "test:referenceable"); + child.addNode("child2", NT_UNSTRUCTURED); + session.save(); + + Node sns = root.addNode("sns"); + sns.addNode("sibling"); + sns.addNode("sibling"); + sns.addNode("sibling"); + + session.getWorkspace().getVersionManager().checkin("/versionable"); + + Node properties = root.addNode("properties", "test:unstructured"); + properties.setProperty("boolean", true); + Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream(BINARY)); + try { + properties.setProperty("binary", binary); + } finally { + binary.dispose(); + } + properties.setProperty("date", DATE); + properties.setProperty("decimal", new BigDecimal(123)); + properties.setProperty("double", Math.PI); + properties.setProperty("long", 9876543210L); + properties.setProperty("reference", referenceable); + properties.setProperty("weak_reference", session.getValueFactory().createValue(referenceable, true)); + properties.setProperty("mv_reference", + new Value[] { session.getValueFactory().createValue(versionable, false) }); + properties.setProperty("mv_weak_reference", + new Value[] { session.getValueFactory().createValue(versionable, true) }); + properties.setProperty("string", "test"); + properties.setProperty("multiple", "a,b,c".split(",")); + session.save(); - binary = properties.getProperty("binary").getBinary(); + binary = properties.getProperty("binary").getBinary(); + try { + InputStream stream = binary.getStream(); try { - InputStream stream = binary.getStream(); - try { - for (byte aBINARY : BINARY) { - assertEquals(aBINARY, (byte) stream.read()); - } - assertEquals(-1, stream.read()); - } finally { - stream.close(); + for (byte aBINARY : BINARY) { + assertEquals(aBINARY, (byte) stream.read()); } + assertEquals(-1, stream.read()); } finally { - binary.dispose(); + stream.close(); } } finally { - session.logout(); + binary.dispose(); } } Added: jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/SameNodeSiblingsTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/SameNodeSiblingsTest.java?rev=1792995&view=auto ============================================================================== --- jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/SameNodeSiblingsTest.java (added) +++ jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/SameNodeSiblingsTest.java Fri Apr 28 07:18:26 2017 @@ -0,0 +1,167 @@ +/* + * 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 static com.google.common.collect.ImmutableSet.of; +import static com.google.common.collect.Sets.newHashSet; +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Set; + +import javax.jcr.Credentials; +import javax.jcr.Node; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.SimpleCredentials; + +import org.apache.commons.io.FileUtils; +import org.apache.jackrabbit.core.RepositoryContext; +import org.apache.jackrabbit.core.RepositoryImpl; +import org.apache.jackrabbit.core.config.RepositoryConfig; +import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; +import org.apache.jackrabbit.oak.plugins.document.DocumentMK; +import org.apache.jackrabbit.oak.spi.state.NodeState; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class SameNodeSiblingsTest { + + public static final Credentials CREDENTIALS = new SimpleCredentials("admin", "admin".toCharArray()); + + private File crx2RepoDir; + + @Before + public void createCrx2RepoDir() throws IOException { + crx2RepoDir = Files.createTempDirectory(Paths.get("target"), "repo-crx2").toFile(); + } + + @After + public void deleteCrx2RepoDir() { + FileUtils.deleteQuietly(crx2RepoDir); + } + + @Test + public void snsShouldBeRenamed() throws RepositoryException, IOException { + DocumentNodeStore nodeStore = migrate(new SourceDataCreator() { + @Override + public void create(Session session) throws RepositoryException { + Node parent = session.getRootNode().addNode("parent"); + parent.addNode("child", "nt:folder"); + parent.addNode("child", "nt:folder"); + parent.addNode("child", "nt:folder"); + parent.addNode("something_else", "nt:folder"); + session.save(); + + parent.setPrimaryType("nt:folder"); // change parent type to + // something that doesn't + // allow SNS + session.save(); + } + }); + try { + NodeState parent = nodeStore.getRoot().getChildNode("parent"); + Set<String> children = newHashSet(parent.getChildNodeNames()); + assertEquals(of("child", "child_2_", "child_3_", "something_else"), children); + } finally { + nodeStore.dispose(); + } + } + + @Test + public void snsShouldntBeRenamed() throws RepositoryException, IOException { + DocumentNodeStore nodeStore = migrate(new SourceDataCreator() { + @Override + public void create(Session session) throws RepositoryException { + Node parent = session.getRootNode().addNode("parent"); + parent.addNode("child", "nt:folder"); + parent.addNode("child", "nt:folder"); + parent.addNode("child", "nt:folder"); + parent.addNode("something_else", "nt:folder"); + session.save(); + } + }); + try { + NodeState parent = nodeStore.getRoot().getChildNode("parent"); + Set<String> children = newHashSet(parent.getChildNodeNames()); + assertEquals(of("child", "child[2]", "child[3]", "something_else"), children); + } finally { + nodeStore.dispose(); + } + } + + @Test + public void snsNewNameAlreadyExists() throws RepositoryException, IOException { + DocumentNodeStore nodeStore = migrate(new SourceDataCreator() { + @Override + public void create(Session session) throws RepositoryException { + Node parent = session.getRootNode().addNode("parent"); + parent.addNode("child", "nt:folder"); + parent.addNode("child", "nt:folder"); + parent.addNode("child", "nt:folder"); + parent.addNode("child_2_", "nt:folder"); + parent.addNode("child_3_", "nt:folder"); + parent.addNode("child_3_2", "nt:folder"); + session.save(); + + parent.setPrimaryType("nt:folder"); + session.save(); + } + }); + try { + NodeState parent = nodeStore.getRoot().getChildNode("parent"); + Set<String> children = newHashSet(parent.getChildNodeNames()); + assertEquals(of("child", "child_2_", "child_3_", "child_2_2", "child_3_2", "child_3_3"), children); + } finally { + nodeStore.dispose(); + } + } + + private DocumentNodeStore migrate(SourceDataCreator sourceDataCreator) throws RepositoryException, IOException { + RepositoryConfig config = RepositoryConfig.install(crx2RepoDir); + RepositoryImpl repository = RepositoryImpl.create(config); + + try { + Session session = repository.login(CREDENTIALS); + sourceDataCreator.create(session); + session.logout(); + } finally { + repository.shutdown(); + } + + config = RepositoryConfig.install(crx2RepoDir); // re-create the config + RepositoryContext context = RepositoryContext.create(config); + DocumentNodeStore target = new DocumentMK.Builder().getNodeStore(); + try { + RepositoryUpgrade upgrade = new RepositoryUpgrade(context, target); + upgrade.copy(null); + } finally { + context.getRepository().shutdown(); + } + return target; + } + + private static interface SourceDataCreator { + void create(Session session) throws RepositoryException; + } +} Added: jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeFromTwoSourcesTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeFromTwoSourcesTest.java?rev=1792995&view=auto ============================================================================== --- jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeFromTwoSourcesTest.java (added) +++ jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeFromTwoSourcesTest.java Fri Apr 28 07:18:26 2017 @@ -0,0 +1,157 @@ +/* + * 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.commons.JcrUtils; +import org.apache.jackrabbit.core.RepositoryContext; +import org.apache.jackrabbit.core.RepositoryImpl; +import org.apache.jackrabbit.core.config.RepositoryConfig; +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.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import java.io.File; +import java.io.IOException; + +/** + * Test case that simulates copying different paths from two source repositories + * into a single target repository. + */ +public class UpgradeFromTwoSourcesTest extends AbstractRepositoryUpgradeTest { + + private static boolean upgradeComplete; + private static FileStore fileStore; + + @Override + protected NodeStore createTargetNodeStore() { + return new SegmentNodeStore(fileStore); + } + + @BeforeClass + public static void initialize() { + final File dir = new File(getTestDirectory(), "segments"); + dir.mkdirs(); + try { + fileStore = FileStore.newFileStore(dir).withMaxFileSize(128).create(); + upgradeComplete = false; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @AfterClass + public static void cleanup() { + fileStore.close(); + fileStore = null; + } + + @Before + public synchronized void upgradeRepository() throws Exception { + if (!upgradeComplete) { + final File sourceDir1 = new File(getTestDirectory(), "source1"); + final File sourceDir2 = new File(getTestDirectory(), "source2"); + + sourceDir1.mkdirs(); + sourceDir2.mkdirs(); + + final RepositoryImpl source1 = createSourceRepository(sourceDir1); + final RepositoryImpl source2 = createSourceRepository(sourceDir2); + final Session session1 = source1.login(CREDENTIALS); + final Session session2 = source2.login(CREDENTIALS); + try { + createSourceContent(session1); + createSourceContent2(session2); + } finally { + session1.save(); + session2.save(); + session1.logout(); + session2.logout(); + source1.shutdown(); + source2.shutdown(); + } + + final NodeStore target = getTargetNodeStore(); + doUpgradeRepository(sourceDir1, target, "/left"); + doUpgradeRepository(sourceDir2, target, "/right", "/left/child2", "/left/child3"); + fileStore.flush(); + upgradeComplete = true; + } + } + + private void doUpgradeRepository(File source, NodeStore target, String... includes) throws RepositoryException { + final RepositoryConfig config = RepositoryConfig.create(source); + final RepositoryContext context = RepositoryContext.create(config); + try { + final RepositoryUpgrade upgrade = new RepositoryUpgrade(context, target); + upgrade.setIncludes(includes); + upgrade.copy(null); + } finally { + context.getRepository().shutdown(); + } + } + + @Override + protected void createSourceContent(Session session) throws RepositoryException { + JcrUtils.getOrCreateByPath("/left/child1/grandchild1", "nt:unstructured", session); + JcrUtils.getOrCreateByPath("/left/child1/grandchild2", "nt:unstructured", session); + JcrUtils.getOrCreateByPath("/left/child1/grandchild3", "nt:unstructured", session); + JcrUtils.getOrCreateByPath("/left/child2/grandchild1", "nt:unstructured", session); + JcrUtils.getOrCreateByPath("/left/child2/grandchild2", "nt:unstructured", session); + + session.save(); + } + + protected void createSourceContent2(Session session) throws RepositoryException { + JcrUtils.getOrCreateByPath("/left/child2/grandchild3", "nt:unstructured", session); + JcrUtils.getOrCreateByPath("/left/child2/grandchild2", "nt:unstructured", session); + JcrUtils.getOrCreateByPath("/left/child3", "nt:unstructured", session); + JcrUtils.getOrCreateByPath("/right/child1/grandchild1", "nt:unstructured", session); + JcrUtils.getOrCreateByPath("/right/child1/grandchild2", "nt:unstructured", session); + + session.save(); + } + + @Test + public void shouldContainNodesFromBothSources() throws Exception { + assertExisting( + "/", + "/left", + "/left/child1", + "/left/child2", + "/left/child3", + "/left/child1/grandchild1", + "/left/child1/grandchild2", + "/left/child1/grandchild3", + "/left/child2/grandchild2", + "/left/child2/grandchild3", + "/right", + "/right/child1", + "/right/child1/grandchild1", + "/right/child1/grandchild2" + ); + + assertMissing( + "/left/child2/grandchild1" + ); + } +} \ No newline at end of file Added: jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeOldSegmentTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeOldSegmentTest.java?rev=1792995&view=auto ============================================================================== --- jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeOldSegmentTest.java (added) +++ jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeOldSegmentTest.java Fri Apr 28 07:18:26 2017 @@ -0,0 +1,121 @@ +/* + * 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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.InputStream; +import java.io.StringReader; + +import javax.jcr.Node; +import javax.jcr.Repository; +import javax.jcr.Session; +import javax.jcr.SimpleCredentials; +import javax.jcr.nodetype.NodeType; +import javax.jcr.nodetype.NodeTypeManager; +import javax.jcr.nodetype.PropertyDefinition; + +import com.google.common.collect.Iterators; +import org.apache.commons.io.FileUtils; +import org.apache.jackrabbit.api.JackrabbitRepository; +import org.apache.jackrabbit.commons.cnd.CndImporter; +import org.apache.jackrabbit.oak.jcr.Jcr; +import org.apache.jackrabbit.oak.upgrade.cli.OakUpgrade; +import org.apache.jackrabbit.oak.upgrade.cli.Util; +import org.apache.jackrabbit.oak.upgrade.cli.container.SegmentNodeStoreContainer; +import org.junit.Test; + +public class UpgradeOldSegmentTest { + + @Test + public void upgradeFrom10() throws Exception { + File testFolder = new File(new File("target"), UpgradeOldSegmentTest.class.getSimpleName()); + FileUtils.deleteDirectory(testFolder); + File oldRepo = new File(testFolder, "test-repo-1.0"); + oldRepo.mkdirs(); + InputStream in = UpgradeOldSegmentTest.class.getResourceAsStream("/test-repo-1.0.zip"); + try { + Util.unzip(in, oldRepo); + } finally { + in.close(); + } + + SegmentNodeStoreContainer newRepoContainer = new SegmentNodeStoreContainer(); + OakUpgrade.main(oldRepo.getPath(), newRepoContainer.getDescription()); + + Repository repo = new Jcr(newRepoContainer.open()).createRepository(); + Session s = repo.login(new SimpleCredentials("admin", "admin".toCharArray())); + + Node myType = s.getNode("/jcr:system/jcr:nodeTypes/test:MyType"); + assertEquals(2, Iterators.size(myType.getNodes("jcr:propertyDefinition"))); + + NodeTypeManager ntMgr = s.getWorkspace().getNodeTypeManager(); + assertTrue(ntMgr.hasNodeType("test:MyType")); + NodeType nt = ntMgr.getNodeType("test:MyType"); + PropertyDefinition[] pDefs = nt.getDeclaredPropertyDefinitions(); + assertEquals(2, pDefs.length); + for (PropertyDefinition pd : pDefs) { + String name = pd.getName(); + if (name.equals("test:mandatory")) { + assertTrue(pd.isMandatory()); + } else if (name.equals("test:optional")) { + assertFalse(pd.isMandatory()); + } else { + fail("Unexpected property definition: " + name); + } + } + + // flip mandatory flag for test:mandatory + String cnd = "<'test'='http://www.apache.org/jackrabbit/test'>\n" + + "[test:MyType] > nt:unstructured\n" + + " - test:mandatory (string)\n" + + " - test:optional (string)"; + + CndImporter.registerNodeTypes(new StringReader(cnd), s, true); + + myType = s.getNode("/jcr:system/jcr:nodeTypes/test:MyType"); + assertEquals(2, Iterators.size(myType.getNodes("jcr:propertyDefinition"))); + + nt = ntMgr.getNodeType("test:MyType"); + pDefs = nt.getDeclaredPropertyDefinitions(); + assertEquals(2, pDefs.length); + for (PropertyDefinition pd : pDefs) { + String name = pd.getName(); + if (name.equals("test:mandatory")) { + assertFalse(pd.isMandatory()); + } else if (name.equals("test:optional")) { + assertFalse(pd.isMandatory()); + } else { + fail("Unexpected property definition: " + name); + } + } + + s.logout(); + if (repo instanceof JackrabbitRepository) { + ((JackrabbitRepository) repo).shutdown(); + } + newRepoContainer.close(); + newRepoContainer.clean(); + FileUtils.deleteQuietly(testFolder); + } +} \ No newline at end of file Modified: jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/blob/LengthCachingDataStoreTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/blob/LengthCachingDataStoreTest.java?rev=1792995&r1=1792994&r2=1792995&view=diff ============================================================================== --- jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/blob/LengthCachingDataStoreTest.java (original) +++ jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/blob/LengthCachingDataStoreTest.java Fri Apr 28 07:18:26 2017 @@ -19,6 +19,10 @@ package org.apache.jackrabbit.oak.upgrade.blob; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; @@ -28,7 +32,7 @@ import java.nio.charset.Charset; import java.util.Properties; import java.util.Random; -import com.google.common.io.ByteStreams; +import com.google.common.io.ByteSource; import com.google.common.io.Files; import com.google.common.io.InputSupplier; import org.apache.jackrabbit.core.data.DataIdentifier; @@ -39,14 +43,10 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - public class LengthCachingDataStoreTest { @Rule - public final TemporaryFolder tempFolder = new TemporaryFolder(); + public final TemporaryFolder tempFolder = new TemporaryFolder(new File("target")); @Test public void mappingFileData() throws Exception { @@ -106,7 +106,7 @@ public class LengthCachingDataStoreTest assertEquals(dr, dr2); assertEquals(dr.getLength(), dr2.getLength()); - assertTrue(ByteStreams.equal(supplier(dr), supplier(dr2))); + assertTrue(supplier(dr).contentEquals(supplier(dr2))); } @Test @@ -181,10 +181,10 @@ public class LengthCachingDataStoreTest return data; } - private static InputSupplier<InputStream> supplier(final DataRecord dr) { - return new InputSupplier<InputStream>() { + private static ByteSource supplier(final DataRecord dr) { + return new ByteSource() { @Override - public InputStream getInput() throws IOException { + public InputStream openStream() throws IOException { try { return dr.getStream(); } catch (DataStoreException e) { Added: jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/AbstractOak2OakTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/AbstractOak2OakTest.java?rev=1792995&view=auto ============================================================================== --- jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/AbstractOak2OakTest.java (added) +++ jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/AbstractOak2OakTest.java Fri Apr 28 07:18:26 2017 @@ -0,0 +1,271 @@ +/* + * 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.cli; + +import static java.util.Collections.singletonMap; +import static junit.framework.Assert.assertFalse; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import javax.annotation.Nullable; +import javax.jcr.Node; +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.SimpleCredentials; +import javax.jcr.Value; + +import com.google.common.base.Function; +import com.google.common.collect.Lists; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.jackrabbit.oak.Oak; +import org.apache.jackrabbit.oak.api.Blob; +import org.apache.jackrabbit.oak.api.CommitFailedException; +import org.apache.jackrabbit.oak.commons.IOUtils; +import org.apache.jackrabbit.oak.jcr.Jcr; +import org.apache.jackrabbit.oak.jcr.repository.RepositoryImpl; +import org.apache.jackrabbit.oak.plugins.document.DocumentNodeState; +import org.apache.jackrabbit.oak.plugins.index.reference.ReferenceIndexProvider; +import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeState; +import org.apache.jackrabbit.oak.spi.commit.CommitInfo; +import org.apache.jackrabbit.oak.spi.commit.EmptyHook; +import org.apache.jackrabbit.oak.spi.state.NodeBuilder; +import org.apache.jackrabbit.oak.spi.state.NodeState; +import org.apache.jackrabbit.oak.spi.state.NodeStore; +import org.apache.jackrabbit.oak.upgrade.RepositorySidegrade; +import org.apache.jackrabbit.oak.upgrade.checkpoint.CheckpointRetriever; +import org.apache.jackrabbit.oak.upgrade.cli.container.NodeStoreContainer; +import org.apache.jackrabbit.oak.upgrade.cli.container.SegmentNodeStoreContainer; +import org.apache.jackrabbit.oak.upgrade.cli.parser.CliArgumentException; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Joiner; + +public abstract class AbstractOak2OakTest { + + private static final Logger log = LoggerFactory.getLogger(AbstractOak2OakTest.class); + + protected static SegmentNodeStoreContainer testContent; + + private NodeStore destination; + + protected Session session; + + private RepositoryImpl repository; + + protected abstract NodeStoreContainer getSourceContainer(); + + protected abstract NodeStoreContainer getDestinationContainer(); + + protected abstract String[] getArgs(); + + @BeforeClass + public static void unpackSegmentRepo() throws IOException { + File tempDir = new File("target", "test-segment-store"); + if (!tempDir.isDirectory()) { + Util.unzip(AbstractOak2OakTest.class.getResourceAsStream("/segmentstore.zip"), tempDir); + } + testContent = new SegmentNodeStoreContainer(tempDir); + } + + @Before + public void prepare() throws Exception { + NodeStore source = getSourceContainer().open(); + try { + initContent(source); + } finally { + getSourceContainer().close(); + } + + String[] args = getArgs(); + log.info("oak2oak {}", Joiner.on(' ').join(args)); + OakUpgrade.main(args); + createSession(); + } + + protected void createSession() throws RepositoryException, IOException { + destination = getDestinationContainer().open(); + repository = (RepositoryImpl) new Jcr(new Oak(destination).with("oak.sling")).with(new ReferenceIndexProvider()).createRepository(); + session = repository.login(new SimpleCredentials("admin", "admin".toCharArray())); + } + + @After + public void clean() throws IOException { + try { + if (session != null) { + session.logout(); + } + if (repository != null) { + repository.shutdown(); + } + } finally { + IOUtils.closeQuietly(getDestinationContainer()); + getDestinationContainer().clean(); + getSourceContainer().clean(); + } + } + + protected void initContent(NodeStore target) throws IOException, RepositoryException, CommitFailedException { + NodeStore initialContent = testContent.open(); + try { + RepositorySidegrade sidegrade = new RepositorySidegrade(initialContent, target); + sidegrade.copy(); + } finally { + testContent.close(); + } + + NodeBuilder builder = target.getRoot().builder(); + builder.setProperty("binary-prop", getRandomBlob(target)); + builder.setProperty("checkpoint-state", "before"); + target.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); + target.checkpoint(60000, singletonMap("key", "123")); + + builder.setProperty("checkpoint-state", "after"); + builder.setProperty("binary-prop", getRandomBlob(target)); + builder.child(":async").setProperty("test", "123"); + target.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); + } + + private Blob getRandomBlob(NodeStore target) throws IOException { + Random r = new Random(); + byte[] buff = new byte[512 * 1024]; + r.nextBytes(buff); + return target.createBlob(new ByteArrayInputStream(buff)); + } + + @Test + public void validateMigration() throws RepositoryException, IOException, CliArgumentException { + verifyContent(session); + verifyBlob(session); + if (supportsCheckpointMigration()) { + verifyCheckpoint(); + } else { + verifyEmptyAsync(); + } + } + + public static void verifyContent(Session session) throws RepositoryException { + Node root = session.getRootNode(); + assertEquals("rep:root", root.getPrimaryNodeType().getName()); + assertEquals(1, root.getMixinNodeTypes().length); + assertEquals("rep:AccessControllable", root.getMixinNodeTypes()[0].getName()); + assertEquals("sling:redirect", root.getProperty("sling:resourceType").getString()); + + Node allow = session.getNode("/apps"); + assertEquals("sling:Folder", allow.getProperty("jcr:primaryType").getString()); + assertEquals("admin", allow.getProperty("jcr:createdBy").getString()); + + Node nodeType = session.getNode("/jcr:system/jcr:nodeTypes/sling:OrderedFolder"); + assertEquals("rep:NodeType", nodeType.getProperty("jcr:primaryType").getString()); + + List<String> values = Lists.transform(Arrays.asList(nodeType.getProperty("rep:protectedProperties").getValues()), new Function<Value, String>() { + @Nullable + @Override + public String apply(@Nullable Value input) { + try { + return input.getString(); + } catch (RepositoryException e) { + return null; + } + } + }); + assertTrue(values.contains("jcr:mixinTypes")); + assertTrue(values.contains("jcr:primaryType")); + assertEquals("false", nodeType.getProperty("jcr:isAbstract").getString()); + } + + public static void verifyBlob(Session session) throws IOException, RepositoryException { + Property p = session.getProperty("/sling-logo.png/jcr:content/jcr:data"); + InputStream is = p.getValue().getBinary().getStream(); + String expectedMD5 = "35504d8c59455ab12a31f3d06f139a05"; + try { + assertEquals(expectedMD5, DigestUtils.md5Hex(is)); + } finally { + is.close(); + } + } + + protected void verifyCheckpoint() { + assertEquals("after", destination.getRoot().getString("checkpoint-state")); + + String checkpointReference = null; + + for (CheckpointRetriever.Checkpoint c : CheckpointRetriever.getCheckpoints(destination)) { + String name = c.getName(); + if (destination.checkpointInfo(name).containsKey("key")) { + checkpointReference = name; + break; + } + } + + assertNotNull(checkpointReference); + + Map<String, String> info = destination.checkpointInfo(checkpointReference); + assertEquals("123", info.get("key")); + + NodeState checkpoint = destination.retrieve(checkpointReference); + assertEquals("before", checkpoint.getString("checkpoint-state")); + + assertEquals("123", destination.getRoot().getChildNode(":async").getString("test")); + + for (String name : new String[] {"var", "etc", "sling.css", "apps", "libs", "sightly"}) { + assertSameRecord(destination.getRoot().getChildNode(name), checkpoint.getChildNode(name)); + } + } + + private static void assertSameRecord(NodeState ns1, NodeState ns2) { + String recordId1 = getRecordId(ns1); + String recordId2 = getRecordId(ns2); + assertNotNull(recordId1); + assertEquals(recordId1, recordId2); + } + + private static String getRecordId(NodeState node) { + if (node instanceof SegmentNodeState) { + return ((SegmentNodeState) node).getRecordId().toString(); + } else if (node instanceof DocumentNodeState) { + return ((DocumentNodeState) node).getLastRevision().toString(); + } else { + return null; + } + } + + // OAK-2869 + protected void verifyEmptyAsync() { + NodeState state = destination.getRoot().getChildNode(":async"); + assertFalse(state.hasProperty("test")); + } + + protected boolean supportsCheckpointMigration() { + return false; + } +} Added: jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/Jcr2ToSegmentTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/Jcr2ToSegmentTest.java?rev=1792995&view=auto ============================================================================== --- jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/Jcr2ToSegmentTest.java (added) +++ jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/Jcr2ToSegmentTest.java Fri Apr 28 07:18:26 2017 @@ -0,0 +1,78 @@ +/* + * 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.cli; + +import java.io.File; +import java.io.IOException; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.SimpleCredentials; + +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.index.reference.ReferenceIndexProvider; +import org.apache.jackrabbit.oak.spi.state.NodeStore; +import org.apache.jackrabbit.oak.upgrade.cli.container.NodeStoreContainer; +import org.apache.jackrabbit.oak.upgrade.cli.container.SegmentNodeStoreContainer; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class Jcr2ToSegmentTest { + + private final NodeStoreContainer destinationContainer = new SegmentNodeStoreContainer(); + + private NodeStore destination; + + private RepositoryImpl repository; + + private Session session; + + public Jcr2ToSegmentTest() throws IOException { + } + + @Before + public void prepare() throws Exception { + File tempDir = new File("target", "test-jcr2"); + if (!tempDir.isDirectory()) { + Util.unzip(AbstractOak2OakTest.class.getResourceAsStream("/jcr2.zip"), tempDir); + } + + OakUpgrade.main("--copy-binaries", tempDir.getPath(), destinationContainer.getDescription()); + + destination = destinationContainer.open(); + repository = (RepositoryImpl) new Jcr(new Oak(destination).with("oak.sling")).with(new ReferenceIndexProvider()).createRepository(); + session = repository.login(new SimpleCredentials("admin", "admin".toCharArray())); + } + + @After + public void clean() throws IOException { + session.logout(); + repository.shutdown(); + destinationContainer.close(); + destinationContainer.clean(); + } + + @Test + public void validateMigration() throws RepositoryException, IOException { + AbstractOak2OakTest.verifyContent(session); + AbstractOak2OakTest.verifyBlob(session); + } + +} Added: jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/JdbcToSegmentTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/JdbcToSegmentTest.java?rev=1792995&view=auto ============================================================================== --- jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/JdbcToSegmentTest.java (added) +++ jackrabbit/oak/branches/1.2/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/JdbcToSegmentTest.java Fri Apr 28 07:18:26 2017 @@ -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.oak.upgrade.cli; + +import java.io.IOException; + +import org.apache.jackrabbit.oak.upgrade.cli.container.JdbcNodeStoreContainer; +import org.apache.jackrabbit.oak.upgrade.cli.container.NodeStoreContainer; +import org.apache.jackrabbit.oak.upgrade.cli.container.SegmentNodeStoreContainer; + +public class JdbcToSegmentTest extends AbstractOak2OakTest { + + private final NodeStoreContainer source; + + private final NodeStoreContainer destination; + + public JdbcToSegmentTest() throws IOException { + source = new JdbcNodeStoreContainer(); + destination = new SegmentNodeStoreContainer(); + } + + @Override + protected NodeStoreContainer getSourceContainer() { + return source; + } + + @Override + protected NodeStoreContainer getDestinationContainer() { + return destination; + } + + @Override + protected String[] getArgs() { + return new String[] { "--src-user", "sa", "--src-password", "sa", source.getDescription(), + destination.getDescription() }; + } + + @Override + protected boolean supportsCheckpointMigration() { + return true; + } +}
