usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [11/50] [abbrv] incubator-usergrid git commit: Fixes bugs when migrations are run by rolling back the the migration version -1, creating the application at that system version, then running the migration
Date Wed, 03 Dec 2014 19:59:21 GMT
Fixes bugs when migrations are run by rolling back the the migration version -1, creating the
application at that system version, then running the migration


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/0857947f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/0857947f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/0857947f

Branch: refs/heads/two-dot-o-events
Commit: 0857947f03a1c9646e0163b4a8485124e6ed6a6c
Parents: 3e21011
Author: Todd Nine <tnine@apigee.com>
Authored: Fri Nov 21 17:54:51 2014 -0700
Committer: Todd Nine <tnine@apigee.com>
Committed: Fri Nov 21 17:54:51 2014 -0700

----------------------------------------------------------------------
 .../org/apache/usergrid/CoreApplication.java    |  17 +++-
 .../migration/EntityDataMigrationIT.java        |  16 +--
 .../migration/EntityTypeMappingMigrationIT.java |  17 ++++
 .../migration/GraphShardVersionMigrationIT.java |  20 ++--
 .../migration/MigrationTestRule.java            | 101 +++++++++++++++++++
 5 files changed, 155 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0857947f/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
index edc887d..1970af5 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
@@ -145,9 +145,14 @@ public class CoreApplication implements Application, TestRule {
     }
 
 
-    protected void before( Description description ) throws Exception {
-        orgName = description.getClassName()+ UUIDGenerator.newTimeUUID();
-        appName = description.getMethodName();
+    /**
+     * Create an application with the given app name and org name
+     * @param orgName
+     * @param appName
+     */
+    public void createApplication(final String orgName, final String appName) throws Exception
{
+        this.orgName = orgName;
+        this.appName = appName;
         id = setup.createApplication( orgName, appName );
         assertNotNull( id );
 
@@ -156,7 +161,13 @@ public class CoreApplication implements Application, TestRule {
 
         LOG.info( "Created new application {} in organization {}", appName, orgName );
 
+    }
+
+    protected void before( Description description ) throws Exception {
+        final String orgName = description.getClassName()+ UUIDGenerator.newTimeUUID();
+        final String appName = description.getMethodName();
 
+        createApplication( orgName, appName  );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0857947f/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/EntityDataMigrationIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/EntityDataMigrationIT.java
b/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/EntityDataMigrationIT.java
index b8c0093..d5f2fe1 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/EntityDataMigrationIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/EntityDataMigrationIT.java
@@ -25,6 +25,7 @@ import java.util.Iterator;
 import java.util.Set;
 
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
 import org.apache.usergrid.AbstractCoreIT;
@@ -73,6 +74,13 @@ public class EntityDataMigrationIT extends AbstractCoreIT {
     private EntityManagerFactory emf;
 
 
+
+    /**
+     * Rule to do the resets we need
+     */
+    @Rule
+    public MigrationTestRule migrationTestRule = new MigrationTestRule( app, CpSetup.getInjector()
,EntityDataMigration.class  );
+
     @Before
     public void setup() {
         emf = setup.getEmf();
@@ -90,13 +98,7 @@ public class EntityDataMigrationIT extends AbstractCoreIT {
     public void testDataMigration() throws Throwable {
 
         assertEquals( "version 3 expected", 3, entityDataMigration.getVersion() );
-
-
-        /**
-         * Reset to our version -1 and start the migration
-         */
-        dataMigrationManager.resetToVersion( entityDataMigration.getVersion() - 1 );
-        dataMigrationManager.invalidate();
+        assertEquals( "Previous version expected", 2, dataMigrationManager.getCurrentVersion());
 
 
         final EntityManager newAppEm = app.getEntityManager();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0857947f/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/EntityTypeMappingMigrationIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/EntityTypeMappingMigrationIT.java
b/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/EntityTypeMappingMigrationIT.java
index 1f0665a..3a52b96 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/EntityTypeMappingMigrationIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/EntityTypeMappingMigrationIT.java
@@ -24,6 +24,7 @@ import java.util.HashSet;
 import java.util.Set;
 
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
 import org.apache.usergrid.AbstractCoreIT;
@@ -35,8 +36,10 @@ import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.EntityManager;
 import org.apache.usergrid.persistence.EntityManagerFactory;
+import org.apache.usergrid.persistence.core.migration.data.DataMigrationManager;
 import org.apache.usergrid.persistence.map.impl.MapSerializationImpl;
 import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 
 import com.google.inject.Injector;
 import com.netflix.astyanax.Keyspace;
@@ -58,6 +61,15 @@ public class EntityTypeMappingMigrationIT extends AbstractCoreIT {
     private Keyspace keyspace;
     private EntityManagerFactory emf;
     private ManagerCache managerCache;
+    private DataMigrationManager dataMigrationManager;
+
+
+    /**
+     * Rule to do the resets we need
+     */
+    @Rule
+    public MigrationTestRule migrationTestRule = new MigrationTestRule( app, CpSetup.getInjector()
,EntityTypeMappingMigration.class  );
+
 
 
     @Before
@@ -67,6 +79,7 @@ public class EntityTypeMappingMigrationIT extends AbstractCoreIT {
         entityTypeMappingMigration = injector.getInstance( EntityTypeMappingMigration.class
);
         keyspace = injector.getInstance( Keyspace.class );
         managerCache = injector.getInstance( ManagerCache.class );
+        dataMigrationManager = injector.getInstance( DataMigrationManager.class );
     }
 
 
@@ -74,6 +87,7 @@ public class EntityTypeMappingMigrationIT extends AbstractCoreIT {
     public void testIdMapping() throws Throwable {
 
         assertEquals( "version 1 expected", 1, entityTypeMappingMigration.getVersion() );
+        assertEquals( "Previous version expected", 0, dataMigrationManager.getCurrentVersion());
 
         final EntityManager newAppEm = app.getEntityManager();
 
@@ -97,6 +111,9 @@ public class EntityTypeMappingMigrationIT extends AbstractCoreIT {
         keyspace.truncateColumnFamily( MapSerializationImpl.MAP_ENTRIES );
         keyspace.truncateColumnFamily( MapSerializationImpl.MAP_KEYS );
 
+        app.createApplication( GraphShardVersionMigrationIT.class.getSimpleName()+ UUIDGenerator.newTimeUUID(),
"migrationTest" );
+
+
 
         final TestProgressObserver progressObserver = new TestProgressObserver();
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0857947f/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/GraphShardVersionMigrationIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/GraphShardVersionMigrationIT.java
b/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/GraphShardVersionMigrationIT.java
index e119788..3ab9f63 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/GraphShardVersionMigrationIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/GraphShardVersionMigrationIT.java
@@ -24,9 +24,11 @@ import java.util.HashSet;
 import java.util.Set;
 
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
 import org.apache.usergrid.AbstractCoreIT;
+import org.apache.usergrid.CoreApplication;
 import org.apache.usergrid.corepersistence.CpSetup;
 import org.apache.usergrid.corepersistence.EntityWriteHelper;
 import org.apache.usergrid.corepersistence.ManagerCache;
@@ -35,9 +37,11 @@ import org.apache.usergrid.persistence.EntityManager;
 import org.apache.usergrid.persistence.core.migration.data.DataMigrationManager;
 import org.apache.usergrid.persistence.core.migration.data.DataMigrationManagerImpl;
 import org.apache.usergrid.persistence.core.migration.data.MigrationInfoSerialization;
+import org.apache.usergrid.persistence.core.migration.schema.MigrationException;
 import org.apache.usergrid.persistence.graph.GraphManager;
 import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
 import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.Multimap;
@@ -59,6 +63,14 @@ public class GraphShardVersionMigrationIT extends AbstractCoreIT {
     private MigrationInfoSerialization migrationInfoSerialization;
 
 
+    /**
+     * Rule to do the resets we need
+     */
+    @Rule
+    public MigrationTestRule migrationTestRule = new MigrationTestRule( app, CpSetup.getInjector()
,GraphShardVersionMigration.class  );
+
+
+
     @Before
     public void setup() {
         injector = CpSetup.getInjector();
@@ -66,6 +78,7 @@ public class GraphShardVersionMigrationIT extends AbstractCoreIT {
         managerCache = injector.getInstance( ManagerCache.class );
         dataMigrationManager = injector.getInstance( DataMigrationManager.class );
         migrationInfoSerialization = injector.getInstance( MigrationInfoSerialization.class
);
+
     }
 
 
@@ -73,12 +86,7 @@ public class GraphShardVersionMigrationIT extends AbstractCoreIT {
     public void testIdMapping() throws Throwable {
 
         assertEquals( "version 2 expected", 2, graphShardVersionMigration.getVersion() );
-
-        /**
-         * Reset to our version -1 and start the migration
-         */
-        dataMigrationManager.resetToVersion( graphShardVersionMigration.getVersion() - 1
);
-        dataMigrationManager.invalidate();
+        assertEquals( "Previous version expected", 1, dataMigrationManager.getCurrentVersion());
 
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0857947f/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/MigrationTestRule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/MigrationTestRule.java
b/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/MigrationTestRule.java
new file mode 100644
index 0000000..13d06ee
--- /dev/null
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/migration/MigrationTestRule.java
@@ -0,0 +1,101 @@
+/*
+ * 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.usergrid.corepersistence.migration;
+
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import org.apache.usergrid.CoreApplication;
+import org.apache.usergrid.persistence.core.migration.data.DataMigration;
+import org.apache.usergrid.persistence.core.migration.data.DataMigrationManager;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import com.google.inject.Injector;
+
+
+/**
+ * This class is required because we cannot create the system's framework on a higher version
(the default behavior is
+ * the latest) then roll back to a previous version
+ *
+ * This rule performs the following operations.
+ *
+ * <ol> <li>Sets up the system's version to be the DataMigration impl's version
-1</li> <li>Creates an application using
+ * that version of the schema.</li> <li>Sets the new org and app in the CoreApplication
to the app created</li> </ol>
+ */
+public class MigrationTestRule implements TestRule {
+
+    protected final CoreApplication core;
+    protected final DataMigrationManager dataMigrationManager;
+    protected final DataMigration dataMigration;
+
+    protected int currentVersion;
+
+
+    /**
+     * Create a new migration test rule.
+     *
+     * @param core the CoreApplication rule used in this test
+     * @param injector The injector used in this test
+     * @param dataMigrationClass The data migration class that is under test
+     */
+    public MigrationTestRule( final CoreApplication core, final Injector injector,
+                              final Class<? extends DataMigration> dataMigrationClass
) {
+        this.core = core;
+        this.dataMigrationManager = injector.getInstance( DataMigrationManager.class );
+        this.dataMigration = injector.getInstance( dataMigrationClass );
+    }
+
+
+    public void resetAndCreateApp( final String className, final String methodName ) throws
Exception {
+        dataMigrationManager.invalidate();
+        currentVersion = dataMigrationManager.getCurrentVersion();
+
+        dataMigrationManager.resetToVersion( dataMigration.getVersion() - 1 );
+        dataMigrationManager.invalidate();
+
+        core.createApplication( className + UUIDGenerator.newTimeUUID(), methodName );
+    }
+
+
+    public void resetVersion(){
+        dataMigrationManager.resetToVersion( currentVersion );
+        dataMigrationManager.invalidate();
+    }
+
+    @Override
+    public Statement apply( final Statement base, final Description description ) {
+
+        return new Statement() {
+            @Override
+            public void evaluate() throws Throwable {
+                try {
+                    resetAndCreateApp( description.getClassName(), description.getMethodName()
);
+
+
+                    base.evaluate();
+                }finally {
+                    resetVersion();
+                }
+            }
+        };
+    }
+}


Mime
View raw message