Modified: 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java?rev=1792993&r1=1792992&r2=1792993&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java
 (original)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java
 Fri Apr 28 07:16:13 2017
@@ -18,62 +18,19 @@
  */
 package org.apache.jackrabbit.oak.upgrade;
 
-import static com.google.common.collect.Sets.newHashSet;
-import static java.util.Arrays.asList;
-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 static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_ADD_CHILD_NODES;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_ALL;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_LIFECYCLE_MANAGEMENT;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_LOCK_MANAGEMENT;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_MODIFY_ACCESS_CONTROL;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_MODIFY_PROPERTIES;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_NAMESPACE_MANAGEMENT;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_NODE_TYPE_MANAGEMENT;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_READ;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_READ_ACCESS_CONTROL;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_REMOVE_CHILD_NODES;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_REMOVE_NODE;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_RETENTION_MANAGEMENT;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_VERSION_MANAGEMENT;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_WORKSPACE_MANAGEMENT;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_WRITE;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.REP_ADD_PROPERTIES;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.REP_ALTER_PROPERTIES;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.REP_INDEX_DEFINITION_MANAGEMENT;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.REP_PRIVILEGE_MANAGEMENT;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.REP_READ_NODES;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.REP_READ_PROPERTIES;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.REP_REMOVE_PROPERTIES;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.REP_USER_MANAGEMENT;
-import static 
org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.REP_WRITE;
-
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.math.BigDecimal;
-import java.util.Arrays;
 import java.util.Calendar;
-import java.util.List;
-import java.util.Map;
 import java.util.Random;
 import java.util.Set;
-
 import javax.jcr.Binary;
 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.Value;
@@ -82,19 +39,27 @@ import javax.jcr.nodetype.NodeTypeManage
 import javax.jcr.nodetype.NodeTypeTemplate;
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.nodetype.PropertyDefinitionTemplate;
-import javax.jcr.security.Privilege;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
 import javax.jcr.version.VersionManager;
 
-import com.google.common.collect.Maps;
-import org.apache.jackrabbit.api.JackrabbitSession;
+import com.google.common.collect.Sets;
 import org.apache.jackrabbit.api.JackrabbitWorkspace;
-import org.apache.jackrabbit.api.security.authorization.PrivilegeManager;
 import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 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 {
 
     private static final Calendar DATE = Calendar.getInstance();
@@ -107,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/";);
 
-            PrivilegeManager privilegeManager = 
workspace.getPrivilegeManager();
-            privilegeManager.registerPrivilege("test:privilege", false, null);
-            privilegeManager.registerPrivilege(
-                    "test:aggregate", false, new String[] { "jcr:read", 
"test:privilege" });
-
-            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();
-
-            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();
         }
     }
 
@@ -214,108 +171,6 @@ public class RepositoryUpgradeTest exten
     }
 
     @Test
-    public void verifyPrivileges() throws RepositoryException {
-        Set<String> nonAggregatePrivileges = newHashSet(
-            REP_READ_NODES, REP_READ_PROPERTIES, REP_ADD_PROPERTIES, 
REP_ALTER_PROPERTIES,
-            REP_REMOVE_PROPERTIES, JCR_ADD_CHILD_NODES, 
JCR_REMOVE_CHILD_NODES, JCR_REMOVE_NODE,
-            JCR_READ_ACCESS_CONTROL, JCR_MODIFY_ACCESS_CONTROL, 
JCR_NODE_TYPE_MANAGEMENT,
-            JCR_VERSION_MANAGEMENT, JCR_LOCK_MANAGEMENT, 
JCR_LIFECYCLE_MANAGEMENT,
-            JCR_RETENTION_MANAGEMENT, JCR_WORKSPACE_MANAGEMENT, 
JCR_NODE_TYPE_DEFINITION_MANAGEMENT,
-            JCR_NAMESPACE_MANAGEMENT, REP_PRIVILEGE_MANAGEMENT, 
REP_USER_MANAGEMENT,
-            REP_INDEX_DEFINITION_MANAGEMENT);
-
-        Map<String, String[]> aggregatePrivileges = Maps.newHashMap();
-        aggregatePrivileges.put(JCR_READ,
-                new String[] {REP_READ_NODES, REP_READ_PROPERTIES});
-        aggregatePrivileges.put(JCR_MODIFY_PROPERTIES,
-                new String[] {REP_ADD_PROPERTIES, REP_ALTER_PROPERTIES, 
REP_REMOVE_PROPERTIES});
-        aggregatePrivileges.put(JCR_WRITE,
-                new String[] {JCR_MODIFY_PROPERTIES, REP_ADD_PROPERTIES, 
REP_ALTER_PROPERTIES,
-                        REP_REMOVE_PROPERTIES, JCR_ADD_CHILD_NODES, 
JCR_REMOVE_CHILD_NODES,
-                        JCR_REMOVE_NODE});
-        aggregatePrivileges.put(REP_WRITE,
-                new String[] {JCR_WRITE, JCR_MODIFY_PROPERTIES, 
REP_ADD_PROPERTIES,
-                        REP_ALTER_PROPERTIES, REP_REMOVE_PROPERTIES, 
JCR_ADD_CHILD_NODES,
-                        JCR_REMOVE_CHILD_NODES, JCR_REMOVE_NODE, 
JCR_NODE_TYPE_MANAGEMENT});
-        aggregatePrivileges.put(JCR_ALL,
-                new String[] {REP_READ_NODES, REP_READ_PROPERTIES, 
REP_ADD_PROPERTIES, REP_ALTER_PROPERTIES,
-                        REP_REMOVE_PROPERTIES, JCR_ADD_CHILD_NODES, 
JCR_REMOVE_CHILD_NODES, JCR_REMOVE_NODE,
-                        JCR_READ_ACCESS_CONTROL, JCR_MODIFY_ACCESS_CONTROL, 
JCR_NODE_TYPE_MANAGEMENT,
-                        JCR_VERSION_MANAGEMENT, JCR_LOCK_MANAGEMENT, 
JCR_LIFECYCLE_MANAGEMENT,
-                        JCR_RETENTION_MANAGEMENT, JCR_WORKSPACE_MANAGEMENT, 
JCR_NODE_TYPE_DEFINITION_MANAGEMENT,
-                        JCR_NAMESPACE_MANAGEMENT, REP_PRIVILEGE_MANAGEMENT, 
REP_USER_MANAGEMENT,
-                        REP_INDEX_DEFINITION_MANAGEMENT, JCR_READ, 
JCR_MODIFY_PROPERTIES, JCR_WRITE, REP_WRITE,
-                        "test:privilege", "test:aggregate"});
-
-        JackrabbitSession session = createAdminSession();
-        try {
-            JackrabbitWorkspace workspace = (JackrabbitWorkspace) 
session.getWorkspace();
-            PrivilegeManager manager = workspace.getPrivilegeManager();
-            Privilege[] privileges = manager.getRegisteredPrivileges();
-
-            for (Privilege privilege : privileges) {
-                if (privilege.isAggregate()) {
-                    String[] expected = 
aggregatePrivileges.remove(privilege.getName());
-                    if (expected != null) {
-                        String[] actual = 
getNames(privilege.getAggregatePrivileges());
-                        assertTrue("Miss match in aggregate privilege " + 
privilege.getName() +
-                                " expected " + Arrays.toString(expected) +
-                                " actual " + Arrays.toString(actual),
-                            newHashSet(expected).equals(newHashSet(actual)));
-                    }
-                } else {
-                    nonAggregatePrivileges.remove(privilege.getName());
-                }
-            }
-
-            assertTrue("Missing non aggregate privileges: " + 
nonAggregatePrivileges,
-                    nonAggregatePrivileges.isEmpty());
-            assertTrue("Missing aggregate privileges: " + 
aggregatePrivileges.keySet(),
-                aggregatePrivileges.isEmpty());
-        }
-        finally {
-            session.logout();
-        }
-    }
-
-    private static String[] getNames(Privilege[] privileges) {
-        String[] names = new String[privileges.length];
-        for (int i = 0; i < privileges.length; i++) {
-            names[i] = privileges[i].getName();
-        }
-        return names;
-    }
-
-    @Test
-    public void verifyCustomPrivileges() throws Exception {
-        JackrabbitSession session = createAdminSession();
-        try {
-            JackrabbitWorkspace workspace =
-                    (JackrabbitWorkspace) session.getWorkspace();
-            PrivilegeManager manager = workspace.getPrivilegeManager();
-
-            Privilege privilege = manager.getPrivilege("test:privilege");
-            assertNotNull(privilege);
-            assertFalse(privilege.isAbstract());
-            assertFalse(privilege.isAggregate());
-            assertEquals(0, privilege.getDeclaredAggregatePrivileges().length);
-
-            Privilege aggregate = manager.getPrivilege("test:aggregate");
-            assertNotNull(aggregate);
-            assertFalse(aggregate.isAbstract());
-            assertTrue(aggregate.isAggregate());
-            assertEquals(2, aggregate.getDeclaredAggregatePrivileges().length);
-
-            Privilege jcrAll = manager.getPrivilege("jcr:all");
-            List<Privilege> privileges = 
asList(jcrAll.getAggregatePrivileges());
-            assertTrue(privileges.contains(privilege));
-            assertTrue(privileges.contains(aggregate));
-        } finally {
-            session.logout();
-        }
-    }
-
-    @Test
     public void verifyCustomNodeTypes() throws Exception {
         Session session = createAdminSession();
         try {
@@ -546,11 +401,31 @@ public class RepositoryUpgradeTest exten
                     frozenChild2.getProperty(JCR_FROZENUUID).getString());
 
             VersionHistory history = manager.getVersionHistory("/versionable");
+            assertTrue(history.isNodeType("rep:VersionablePaths"));
             Property versionablePath = history.getProperty("default");
             assertEquals("/versionable", versionablePath.getString());
         } 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();
+        }
     }
 
 }

Added: 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/SameNodeSiblingsTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/SameNodeSiblingsTest.java?rev=1792993&view=auto
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/SameNodeSiblingsTest.java
 (added)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/SameNodeSiblingsTest.java
 Fri Apr 28 07:16:13 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.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeFromTwoSourcesTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeFromTwoSourcesTest.java?rev=1792993&view=auto
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeFromTwoSourcesTest.java
 (added)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeFromTwoSourcesTest.java
 Fri Apr 28 07:16:13 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.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeOldSegmentTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeOldSegmentTest.java?rev=1792993&view=auto
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeOldSegmentTest.java
 (added)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/UpgradeOldSegmentTest.java
 Fri Apr 28 07:16:13 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.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/blob/LengthCachingDataStoreTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/blob/LengthCachingDataStoreTest.java?rev=1792993&r1=1792992&r2=1792993&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/blob/LengthCachingDataStoreTest.java
 (original)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/blob/LengthCachingDataStoreTest.java
 Fri Apr 28 07:16:13 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.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/AbstractOak2OakTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/AbstractOak2OakTest.java?rev=1792993&view=auto
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/AbstractOak2OakTest.java
 (added)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/AbstractOak2OakTest.java
 Fri Apr 28 07:16:13 2017
@@ -0,0 +1,262 @@
+/*
+ * 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 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.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);
+
+        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)) {
+            checkpointReference = c.getName();
+        }
+
+        assertNotNull(checkpointReference);
+
+        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.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/Jcr2ToSegmentTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/Jcr2ToSegmentTest.java?rev=1792993&view=auto
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/Jcr2ToSegmentTest.java
 (added)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/Jcr2ToSegmentTest.java
 Fri Apr 28 07:16:13 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.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/JdbcToSegmentTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/JdbcToSegmentTest.java?rev=1792993&view=auto
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/JdbcToSegmentTest.java
 (added)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/JdbcToSegmentTest.java
 Fri Apr 28 07:16:13 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;
+    }
+}

Added: 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/MongoToMongoFbsTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/MongoToMongoFbsTest.java?rev=1792993&view=auto
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/MongoToMongoFbsTest.java
 (added)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/MongoToMongoFbsTest.java
 Fri Apr 28 07:16:13 2017
@@ -0,0 +1,67 @@
+/*
+ * 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 static 
org.apache.jackrabbit.oak.upgrade.cli.container.MongoNodeStoreContainer.isMongoAvailable;
+import static org.junit.Assume.assumeTrue;
+
+import org.apache.jackrabbit.oak.upgrade.cli.container.BlobStoreContainer;
+import org.apache.jackrabbit.oak.upgrade.cli.container.FileBlobStoreContainer;
+import org.apache.jackrabbit.oak.upgrade.cli.container.MongoNodeStoreContainer;
+import org.apache.jackrabbit.oak.upgrade.cli.container.NodeStoreContainer;
+
+/**
+ * This covers the bug GRANITE-8719.
+ */
+public class MongoToMongoFbsTest extends AbstractOak2OakTest {
+
+    private final BlobStoreContainer destinationBlob;
+
+    private final NodeStoreContainer source;
+
+    private final NodeStoreContainer destination;
+
+    public MongoToMongoFbsTest() throws IOException {
+        assumeTrue(isMongoAvailable());
+        destinationBlob = new FileBlobStoreContainer();
+        source = new MongoNodeStoreContainer();
+        destination = new MongoNodeStoreContainer(destinationBlob);
+    }
+
+    @Override
+    protected NodeStoreContainer getSourceContainer() {
+        return source;
+    }
+
+    @Override
+    protected NodeStoreContainer getDestinationContainer() {
+        return destination;
+    }
+
+    @Override
+    protected String[] getArgs() {
+        return new String[] { "--copy-binaries", "--fileblobstore", 
destinationBlob.getDescription(),
+                source.getDescription(), destination.getDescription() };
+    }
+
+    @Override
+    protected boolean supportsCheckpointMigration() {
+        return true;
+    }
+}

Added: 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/MongoToMongoFdsTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/MongoToMongoFdsTest.java?rev=1792993&view=auto
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/MongoToMongoFdsTest.java
 (added)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/MongoToMongoFdsTest.java
 Fri Apr 28 07:16:13 2017
@@ -0,0 +1,64 @@
+/*
+ * 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 
org.apache.jackrabbit.oak.upgrade.cli.container.MongoNodeStoreContainer.isMongoAvailable;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.IOException;
+
+import org.apache.jackrabbit.oak.upgrade.cli.container.BlobStoreContainer;
+import org.apache.jackrabbit.oak.upgrade.cli.container.FileDataStoreContainer;
+import org.apache.jackrabbit.oak.upgrade.cli.container.MongoNodeStoreContainer;
+import org.apache.jackrabbit.oak.upgrade.cli.container.NodeStoreContainer;
+
+public class MongoToMongoFdsTest extends AbstractOak2OakTest {
+
+    private final BlobStoreContainer destinationBlob;
+
+    private final NodeStoreContainer source;
+
+    private final NodeStoreContainer destination;
+
+    public MongoToMongoFdsTest() throws IOException {
+        assumeTrue(isMongoAvailable());
+        destinationBlob = new FileDataStoreContainer();
+        source = new MongoNodeStoreContainer();
+        destination = new MongoNodeStoreContainer(destinationBlob);
+    }
+
+    @Override
+    protected NodeStoreContainer getSourceContainer() {
+        return source;
+    }
+
+    @Override
+    protected NodeStoreContainer getDestinationContainer() {
+        return destination;
+    }
+
+    @Override
+    protected String[] getArgs() {
+        return new String[] { "--copy-binaries", "--datastore", 
destinationBlob.getDescription(),
+                source.getDescription(), destination.getDescription() };
+    }
+
+    @Override
+    protected boolean supportsCheckpointMigration() {
+        return true;
+    }
+}

Added: 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/MongoToSegmentTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/MongoToSegmentTest.java?rev=1792993&view=auto
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/MongoToSegmentTest.java
 (added)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/MongoToSegmentTest.java
 Fri Apr 28 07:16:13 2017
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.upgrade.cli;
+
+import static 
org.apache.jackrabbit.oak.upgrade.cli.container.MongoNodeStoreContainer.isMongoAvailable;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.IOException;
+
+import org.apache.jackrabbit.oak.upgrade.cli.container.MongoNodeStoreContainer;
+import org.apache.jackrabbit.oak.upgrade.cli.container.NodeStoreContainer;
+import 
org.apache.jackrabbit.oak.upgrade.cli.container.SegmentNodeStoreContainer;
+
+public class MongoToSegmentTest extends AbstractOak2OakTest {
+
+    private final MongoNodeStoreContainer source;
+
+    private final SegmentNodeStoreContainer destination;
+
+    public MongoToSegmentTest() throws IOException {
+        assumeTrue(isMongoAvailable());
+        source = new MongoNodeStoreContainer();
+        destination = new SegmentNodeStoreContainer();
+    }
+
+    @Override
+    protected NodeStoreContainer getSourceContainer() {
+        return source;
+    }
+
+    @Override
+    protected NodeStoreContainer getDestinationContainer() {
+        return destination;
+    }
+
+    @Override
+    protected String[] getArgs() {
+        return new String[] { source.getDescription(), 
destination.getDescription() };
+    }
+
+    @Override
+    protected boolean supportsCheckpointMigration() {
+        return true;
+    }
+}

Added: 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToJdbcTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToJdbcTest.java?rev=1792993&view=auto
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToJdbcTest.java
 (added)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToJdbcTest.java
 Fri Apr 28 07:16:13 2017
@@ -0,0 +1,57 @@
+/*
+ * 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;
+import org.junit.Ignore;
+
+public class SegmentToJdbcTest extends AbstractOak2OakTest {
+
+    private final NodeStoreContainer source;
+
+    private final NodeStoreContainer destination;
+
+    public SegmentToJdbcTest() throws IOException {
+        source = new SegmentNodeStoreContainer();
+        destination = new JdbcNodeStoreContainer();
+    }
+
+    @Override
+    protected NodeStoreContainer getSourceContainer() {
+        return source;
+    }
+
+    @Override
+    protected NodeStoreContainer getDestinationContainer() {
+        return destination;
+    }
+
+    @Override
+    protected String[] getArgs() {
+        return new String[] { "--disable-mmap", "--user", "sa", "--password", 
"sa", source.getDescription(),
+                destination.getDescription() };
+    }
+
+    @Override
+    protected boolean supportsCheckpointMigration() {
+        return true;
+    }
+}

Added: 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToMongoTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToMongoTest.java?rev=1792993&view=auto
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToMongoTest.java
 (added)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToMongoTest.java
 Fri Apr 28 07:16:13 2017
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.upgrade.cli;
+
+import static 
org.apache.jackrabbit.oak.upgrade.cli.container.MongoNodeStoreContainer.isMongoAvailable;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.IOException;
+
+import org.apache.jackrabbit.oak.upgrade.cli.container.MongoNodeStoreContainer;
+import org.apache.jackrabbit.oak.upgrade.cli.container.NodeStoreContainer;
+import 
org.apache.jackrabbit.oak.upgrade.cli.container.SegmentNodeStoreContainer;
+
+public class SegmentToMongoTest extends AbstractOak2OakTest {
+
+    private final NodeStoreContainer source;
+
+    private final NodeStoreContainer destination;
+
+    public SegmentToMongoTest() throws IOException {
+        assumeTrue(isMongoAvailable());
+        source = new SegmentNodeStoreContainer();
+        destination = new MongoNodeStoreContainer();
+    }
+
+    @Override
+    protected NodeStoreContainer getSourceContainer() {
+        return source;
+    }
+
+    @Override
+    protected NodeStoreContainer getDestinationContainer() {
+        return destination;
+    }
+
+    @Override
+    protected String[] getArgs() {
+        return new String[] { source.getDescription(), 
destination.getDescription() };
+    }
+
+    @Override
+    protected boolean supportsCheckpointMigration() {
+        return true;
+    }
+}

Added: 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToSegmentTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToSegmentTest.java?rev=1792993&view=auto
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToSegmentTest.java
 (added)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToSegmentTest.java
 Fri Apr 28 07:16:13 2017
@@ -0,0 +1,54 @@
+/*
+ * 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 org.apache.jackrabbit.oak.upgrade.cli.container.NodeStoreContainer;
+import 
org.apache.jackrabbit.oak.upgrade.cli.container.SegmentNodeStoreContainer;
+
+import java.io.IOException;
+
+public class SegmentToSegmentTest extends AbstractOak2OakTest {
+
+    private final NodeStoreContainer source;
+
+    private final NodeStoreContainer destination;
+
+    public SegmentToSegmentTest() throws IOException {
+        source = new SegmentNodeStoreContainer();
+        destination = new SegmentNodeStoreContainer();
+    }
+
+    @Override
+    protected NodeStoreContainer getSourceContainer() {
+        return source;
+    }
+
+    @Override
+    protected NodeStoreContainer getDestinationContainer() {
+        return destination;
+    }
+
+    @Override
+    protected String[] getArgs() {
+        return new String[] { source.getDescription(), 
destination.getDescription() };
+    }
+
+    @Override
+    protected boolean supportsCheckpointMigration() {
+        return true;
+    }
+}

Added: 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToSegmentWithMissingDestinationDirectoryTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToSegmentWithMissingDestinationDirectoryTest.java?rev=1792993&view=auto
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToSegmentWithMissingDestinationDirectoryTest.java
 (added)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/SegmentToSegmentWithMissingDestinationDirectoryTest.java
 Fri Apr 28 07:16:13 2017
@@ -0,0 +1,60 @@
+/*
+ * 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 org.apache.jackrabbit.oak.upgrade.cli.container.NodeStoreContainer;
+import 
org.apache.jackrabbit.oak.upgrade.cli.container.SegmentNodeStoreContainer;
+
+import java.io.IOException;
+
+public class SegmentToSegmentWithMissingDestinationDirectoryTest extends 
AbstractOak2OakTest {
+    private final NodeStoreContainer source;
+
+    private final NodeStoreContainer destination;
+
+    public SegmentToSegmentWithMissingDestinationDirectoryTest() throws 
IOException {
+        source = new SegmentNodeStoreContainer();
+        destination = getSegmentNodeStoreContainerWithMissingDirectory();
+    }
+
+    private SegmentNodeStoreContainer 
getSegmentNodeStoreContainerWithMissingDirectory() throws IOException {
+        SegmentNodeStoreContainer segmentNodeStoreContainer = new 
SegmentNodeStoreContainer();
+        segmentNodeStoreContainer.getDirectory().delete();
+        return segmentNodeStoreContainer;
+    }
+
+    @Override
+    protected NodeStoreContainer getSourceContainer() {
+        return source;
+    }
+
+    @Override
+    protected NodeStoreContainer getDestinationContainer() {
+        return destination;
+    }
+
+    @Override
+    protected String[] getArgs() {
+        return new String[] { source.getDescription(), 
destination.getDescription() };
+    }
+
+    @Override
+    protected boolean supportsCheckpointMigration() {
+        return true;
+    }
+
+}

Added: 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/Util.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/Util.java?rev=1792993&view=auto
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/Util.java
 (added)
+++ 
jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/Util.java
 Fri Apr 28 07:16:13 2017
@@ -0,0 +1,66 @@
+/*
+ * 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.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class Util {
+
+    private static final Logger log = LoggerFactory.getLogger(Util.class);
+
+    private Util() {
+    }
+
+    public static void unzip(InputStream is, File targetDir) throws 
IOException {
+        long start = System.currentTimeMillis();
+        log.info("Unzipping to {}", targetDir.getAbsolutePath());
+        final ZipInputStream zis = new ZipInputStream(is);
+        try {
+            ZipEntry entry = null;
+            while((entry = zis.getNextEntry()) != null) {
+                if (entry.isDirectory()) {
+                    new File(targetDir, entry.getName()).mkdirs();
+                } else {
+                    File target = new File(targetDir, entry.getName());
+                    target.getParentFile().mkdirs();
+                    OutputStream output = new FileOutputStream(target);
+                    try {
+                        IOUtils.copy(zis, output);
+                    } finally {
+                        output.close();
+                    }
+                }
+            }
+        } finally {
+            zis.close();
+        }
+        final long delta = System.currentTimeMillis() - start;
+        if(delta > 1000L) {
+            log.info("Unzip took {} msec", delta);
+        }
+    }
+}


Reply via email to