usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject git commit: shell of a WriteOptimisticVerifyTest now in place, but it does not really test anything.
Date Wed, 12 Feb 2014 20:21:06 GMT
Updated Branches:
  refs/heads/optimistic-tx-semantics 7d3a9c789 -> c04f49d9b


shell of a WriteOptimisticVerifyTest now in place, but it does not really test anything.


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

Branch: refs/heads/optimistic-tx-semantics
Commit: c04f49d9b500dfef80b041f817a395073cea2744
Parents: 7d3a9c7
Author: Dave Johnson <dmjohnson@apigee.com>
Authored: Wed Feb 12 14:29:34 2014 -0500
Committer: Dave Johnson <dmjohnson@apigee.com>
Committed: Wed Feb 12 14:29:34 2014 -0500

----------------------------------------------------------------------
 .../astyanax/IdRowCompositeSerializer.java      |  4 +-
 .../mvcc/changelog/ChangeLogGeneratorImpl.java  |  3 ++
 .../mvcc/stage/write/WriteOptimisticVerify.java | 23 ++++-----
 .../collection/guice/TestCollectionModule.java  | 31 +++++++------
 .../stage/write/WriteOptimisticVerifyTest.java  | 49 +++++++++++++-------
 5 files changed, 64 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c04f49d9/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/astyanax/IdRowCompositeSerializer.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/astyanax/IdRowCompositeSerializer.java
b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/astyanax/IdRowCompositeSerializer.java
index 5961196..d47579f 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/astyanax/IdRowCompositeSerializer.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/astyanax/IdRowCompositeSerializer.java
@@ -44,8 +44,8 @@ public class IdRowCompositeSerializer implements CompositeFieldSerializer<Id>
{
 
     @Override
     public void toComposite( final CompositeBuilder builder, final Id id ) {
-        //note that this order is important.  Our default behavior is it order by time uuid,
NOT by type, so we want our
-        //uuid written BEFORE the string type
+        // NOTE that this order is important.  Our default behavior is to order by 
+        // Time UUID and NOT by type, so we want our UUID written BEFORE the string type
         builder.addUUID( id.getUuid() );
         builder.addString( id.getType() );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c04f49d9/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImpl.java
b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImpl.java
index 6d43918..b727ba0 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImpl.java
@@ -60,6 +60,9 @@ public class ChangeLogGeneratorImpl implements ChangeLogGenerator {
             }
         }
 
+        // TODO: what about cleared entities, all fields deleted but entity still there.
+        // i.e. the optional entity will be delete
+
         for ( MvccEntity mvccEntity : mvccEntities ) {
 
             Entity entity = mvccEntity.getEntity().get();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c04f49d9/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerify.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerify.java
b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerify.java
index 0f9fd92..be37d72 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerify.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerify.java
@@ -40,7 +40,8 @@ import rx.util.functions.Func1;
  * This phase should execute any optimistic verification on the MvccEntity
  */
 @Singleton
-public class WriteOptimisticVerify implements Func1<CollectionIoEvent<MvccEntity>,
CollectionIoEvent<MvccEntity>> {
+public class WriteOptimisticVerify 
+    implements Func1<CollectionIoEvent<MvccEntity>, CollectionIoEvent<MvccEntity>>
{
 
     private static final Logger LOG = LoggerFactory.getLogger( WriteOptimisticVerify.class
);
 
@@ -53,8 +54,8 @@ public class WriteOptimisticVerify implements Func1<CollectionIoEvent<MvccEntity
 
 
     @Override
-    public CollectionIoEvent<MvccEntity> call( final CollectionIoEvent<MvccEntity>
mvccEntityIoEvent ) {
-        ValidationUtils.verifyMvccEntityWithEntity( mvccEntityIoEvent.getEvent() );
+    public CollectionIoEvent<MvccEntity> call( final CollectionIoEvent<MvccEntity>
ioevent ) {
+        ValidationUtils.verifyMvccEntityWithEntity( ioevent.getEvent() );
 
         // If the version was included on the entity write operation (delete or write) we
need
         // to read back the entity log, and ensure that our "new" version is the only version
@@ -62,18 +63,18 @@ public class WriteOptimisticVerify implements Func1<CollectionIoEvent<MvccEntity
         //
         // If not, fail fast, signal to the user their entity is "stale".
 
-        MvccEntity entity = mvccEntityIoEvent.getEvent();
-        CollectionScope collectionScope = mvccEntityIoEvent.getEntityCollection();
+        MvccEntity entity = ioevent.getEvent();
+        CollectionScope collectionScope = ioevent.getEntityCollection();
 
         try {
-            List<MvccLogEntry> versions = logEntryStrat.load( collectionScope, 
-                    entity.getId(), entity.getVersion(), 2 );
+            List<MvccLogEntry> versions = logEntryStrat.load( 
+                collectionScope, entity.getId(), entity.getVersion(), 2 );
 
-            // previous log entry must be committed, otherwise somebody is already writing
+            // Previous log entry must be committed, otherwise somebody is already writing
             if ( versions.size() > 1 
                     && versions.get(1).getStage().ordinal() < Stage.COMMITTED.ordinal()
) {
             
-                // we're not the first writer, rollback and throw-up
+                // We're not the first writer, rollback and throw-up
                 final MvccLogEntry rollbackEntry = 
                         new MvccLogEntryImpl( entity.getId(), entity.getVersion(), Stage.ROLLBACK);
                 logEntryStrat.write( collectionScope, rollbackEntry );
@@ -86,7 +87,7 @@ public class WriteOptimisticVerify implements Func1<CollectionIoEvent<MvccEntity
             throw new CollectionRuntimeException( "Error reading entity log", e );
         }
 
-        //no op, just emit the value
-        return mvccEntityIoEvent;
+        // No op, just emit the value
+        return ioevent;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c04f49d9/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/guice/TestCollectionModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/guice/TestCollectionModule.java
b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/guice/TestCollectionModule.java
index 1736113..7d15db7 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/guice/TestCollectionModule.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/guice/TestCollectionModule.java
@@ -1,22 +1,23 @@
-package org.apache.usergrid.persistence.collection.guice;
-
-
-import java.io.IOException;
-
-import org.safehaus.guicyfig.Env;
-
-import com.google.inject.AbstractModule;
-import com.netflix.config.ConfigurationManager;
-import com.netflix.config.SimpleDeploymentContext;
-
-
-/**
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
+ *     http://www.apache.org/licenses/LICENSE-2.0
  *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
  */
-public class TestCollectionModule extends TestModule {
-
+package org.apache.usergrid.persistence.collection.guice;
 
+public class TestCollectionModule extends TestModule {
 
     @Override
     protected void configure() {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c04f49d9/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerifyTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerifyTest.java
b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerifyTest.java
index 5157b3a..942abbf 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerifyTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerifyTest.java
@@ -18,64 +18,77 @@
 package org.apache.usergrid.persistence.collection.mvcc.stage.write;
 
 import com.google.inject.Inject;
-import org.junit.Test;
-
 import org.apache.usergrid.persistence.collection.CollectionScope;
 import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
-import org.apache.usergrid.persistence.collection.guice.CollectionModule;
+import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
+import org.apache.usergrid.persistence.collection.guice.TestCollectionModule;
 import org.apache.usergrid.persistence.collection.mvcc.MvccLogEntrySerializationStrategy;
 import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
 import org.apache.usergrid.persistence.collection.mvcc.stage.AbstractMvccEntityStageTest;
 import org.apache.usergrid.persistence.collection.mvcc.stage.CollectionIoEvent;
-import org.apache.usergrid.persistence.model.entity.Entity;
-
 import static org.apache.usergrid.persistence.collection.mvcc.stage.TestEntityGenerator.fromEntity;
 import static org.apache.usergrid.persistence.collection.mvcc.stage.TestEntityGenerator.generateEntity;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+import org.jukito.JukitoRunner;
 import org.jukito.UseModules;
 import org.junit.Assert;
 import static org.junit.Assert.assertSame;
 import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 
-@UseModules( CollectionModule.class )
+@RunWith( JukitoRunner.class )
+@UseModules( TestCollectionModule.class )
 public class WriteOptimisticVerifyTest extends AbstractMvccEntityStageTest {
 
     @ClassRule
-    public static CassandraRule rule = new CassandraRule();
+    public static CassandraRule cassandraRule = new CassandraRule();
+
+    @Inject
+    @Rule
+    public MigrationManagerRule migrationManagerRule = new MigrationManagerRule();
 
     @Inject
     private MvccLogEntrySerializationStrategy logEntryStrat;
 
-    /** Standard flow */
     @Test
     public void testStartStage() throws Exception {
 
         Assert.assertNotNull( logEntryStrat );
 
         final CollectionScope collectionScope = mock( CollectionScope.class );
+        when( collectionScope.getOrganization() )
+                .thenReturn( new SimpleId( UUIDGenerator.newTimeUUID(), "organization" )
);
+        when( collectionScope.getOwner() )
+                .thenReturn( new SimpleId( UUIDGenerator.newTimeUUID(), "owner" ) );
 
-        // set up the mock to return the entity from the start phase
+        // Set up the mock to return the entity from the start phase
         final Entity entity = generateEntity();
 
         final MvccEntity mvccEntity = fromEntity( entity );
 
-        // run the stage
+        // Run the stage
         WriteOptimisticVerify newStage = new WriteOptimisticVerify( logEntryStrat );
 
-        CollectionIoEvent<MvccEntity>
-            result = newStage.call( new CollectionIoEvent<MvccEntity>( collectionScope,
mvccEntity ) );
+        CollectionIoEvent<MvccEntity> result;
+        result = newStage.call( new CollectionIoEvent<MvccEntity>( collectionScope,
mvccEntity ) );
 
         assertSame("Context was correct", collectionScope, result.getEntityCollection())
;
 
-        // verify the entity is correct
+        // Verify the entity is correct
         MvccEntity entry = result.getEvent();
 
-        // verify uuid and version in both the MvccEntity and the entity itself
-        // assertSame is used on purpose.  We want to make sure the same instance is used,
not a copy.
-        // this way the caller's runtime type is retained.
-        assertSame( "id correct", entity.getId(), entry.getId() );
-        assertSame( "version did not not match entityId", entity.getVersion(), entry.getVersion()
);
+        // Verify UUID and version in both the MvccEntity and the entity itself. Here assertSame

+        // is used on purpose as we want to make sure the same instance is used, not a copy.
+        // This way the caller's runtime type is retained.
+        assertSame( "Id correct", entity.getId(), entry.getId() );
+        assertSame( "Version did not not match entityId", entity.getVersion(), entry.getVersion()
);
         assertSame( "Entity correct", entity, entry.getEntity().get() );
     }
 


Mime
View raw message