You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2013/12/05 01:55:29 UTC
[3/6] Working deletes. Need to add more test cases
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/43aba652/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/CreateTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/CreateTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/CreateTest.java
index 0ce01c3..4547c80 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/CreateTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/CreateTest.java
@@ -7,7 +7,7 @@ import java.util.concurrent.ExecutionException;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
-import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
+import org.apache.usergrid.persistence.collection.mvcc.stage.ExecutionContext;
import org.apache.usergrid.persistence.collection.service.TimeService;
import org.apache.usergrid.persistence.collection.service.UUIDService;
import org.apache.usergrid.persistence.model.entity.Entity;
@@ -28,13 +28,13 @@ public class CreateTest {
@Test
public void testValidInput() throws ConnectionException, ExecutionException, InterruptedException {
- final WriteContext writeContext = mock( WriteContext.class );
+ final ExecutionContext executionContext = mock( ExecutionContext.class );
//set up the mock to return the entity from the start phase
final Entity entity = new Entity();
- when( writeContext.getMessage( Entity.class ) ).thenReturn( entity );
+ when( executionContext.getMessage( Entity.class ) ).thenReturn( entity );
//mock returning the time
@@ -59,14 +59,14 @@ public class CreateTest {
//perform the stage
final Create create = new Create( timeService, uuidService );
- create.performStage( writeContext );
+ create.performStage( executionContext );
//now verify our output was correct
ArgumentCaptor<Entity> mvccEntity = ArgumentCaptor.forClass( Entity.class );
- verify( writeContext ).setMessage( mvccEntity.capture() );
+ verify( executionContext ).setMessage( mvccEntity.capture() );
Entity created = mvccEntity.getValue();
@@ -81,7 +81,7 @@ public class CreateTest {
//now verify the proceed was called
- verify( writeContext ).proceed();
+ verify( executionContext ).proceed();
}
@@ -89,10 +89,10 @@ public class CreateTest {
@Test(expected = NullPointerException.class)
public void testInvalidInput() throws ConnectionException, ExecutionException, InterruptedException {
- final WriteContext writeContext = mock( WriteContext.class );
+ final ExecutionContext executionContext = mock( ExecutionContext.class );
- when( writeContext.getMessage( Entity.class ) ).thenReturn( null );
+ when( executionContext.getMessage( Entity.class ) ).thenReturn( null );
//mock returning the time
@@ -107,7 +107,7 @@ public class CreateTest {
final Create create = new Create( timeService, uuidService );
//should throw an NPE
- create.performStage( writeContext );
+ create.performStage( executionContext );
}
@@ -117,10 +117,10 @@ public class CreateTest {
@Test(expected = NullPointerException.class)
public void testNoTimeService() throws ConnectionException, ExecutionException, InterruptedException {
- final WriteContext writeContext = mock( WriteContext.class );
+ final ExecutionContext executionContext = mock( ExecutionContext.class );
- when( writeContext.getMessage( Entity.class ) ).thenReturn( null );
+ when( executionContext.getMessage( Entity.class ) ).thenReturn( null );
//mock the uuid service
@@ -136,10 +136,10 @@ public class CreateTest {
@Test(expected = NullPointerException.class)
public void testNoUUIDService() throws ConnectionException, ExecutionException, InterruptedException {
- final WriteContext writeContext = mock( WriteContext.class );
+ final ExecutionContext executionContext = mock( ExecutionContext.class );
- when( writeContext.getMessage( Entity.class ) ).thenReturn( null );
+ when( executionContext.getMessage( Entity.class ) ).thenReturn( null );
//mock returning the time
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/43aba652/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/StartTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/StartTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/StartTest.java
deleted file mode 100644
index a6786b1..0000000
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/StartTest.java
+++ /dev/null
@@ -1,187 +0,0 @@
-package org.apache.usergrid.persistence.collection.mvcc.stage.impl;
-
-
-import java.util.UUID;
-
-import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-
-import org.apache.commons.lang3.reflect.FieldUtils;
-
-import org.apache.usergrid.persistence.collection.CollectionContext;
-import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
-import org.apache.usergrid.persistence.collection.mvcc.entity.MvccLogEntry;
-import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
-import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
-import org.apache.usergrid.persistence.collection.serialization.MvccLogEntrySerializationStrategy;
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-
-import com.netflix.astyanax.MutationBatch;
-
-import static junit.framework.TestCase.assertSame;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.same;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-
-/** @author tnine */
-public class StartTest {
-
- /** Standard flow */
- @Test
- public void testStartStage() throws Exception {
-
-
- final WriteContext writeContext = mock( WriteContext.class );
- final CollectionContext context = mock( CollectionContext.class );
-
-
- //mock returning the context
- when( writeContext.getCollectionContext() ).thenReturn( context );
-
-
- //set up the mock to return the entity from the start phase
- final Entity entity = generateEntity();
-
- //mock returning the entity from the write context
- when( writeContext.getMessage( Entity.class ) ).thenReturn( entity );
-
-
- //mock returning a mock mutation when we do a log entry write
- final MvccLogEntrySerializationStrategy logStrategy = mock( MvccLogEntrySerializationStrategy.class );
-
- final ArgumentCaptor<MvccLogEntry> logEntry = ArgumentCaptor.forClass( MvccLogEntry.class );
-
- final MutationBatch mutation = mock( MutationBatch.class );
-
- when( logStrategy.write( same( context ), logEntry.capture() ) ).thenReturn( mutation );
-
-
- //run the stage
- Start newStage = new Start( logStrategy );
-
- newStage.performStage( writeContext );
-
-
- //now verify our output was correct
- ArgumentCaptor<MvccEntity> mvccEntity = ArgumentCaptor.forClass( MvccEntity.class );
-
-
- //verify the log entry is correct
- MvccLogEntry entry = logEntry.getValue();
-
- assertEquals( "entity id did not match ", entity.getUuid(), entry.getEntityId() );
- assertEquals( "version did not not match entityId", entity.getVersion(), entry.getVersion() );
- assertEquals( "Stage is correct", Stage.ACTIVE, entry.getStage() );
-
-
- //now verify we set the message into the write context
- verify( writeContext ).setMessage( mvccEntity.capture() );
-
- MvccEntity created = mvccEntity.getValue();
-
- //verify uuid and version in both the MvccEntity and the entity itself
- assertEquals( "entity id did not match generator", entity.getUuid(), created.getUuid() );
- assertEquals( "version did not not match entityId", entity.getVersion(), created.getVersion() );
- assertSame( "Entity correct", entity, created.getEntity().get() );
-
-
- //now verify the proceed was called
- verify( writeContext ).proceed();
- }
-
-
- /** Test no entity in the pipeline */
- @Test( expected = NullPointerException.class )
- public void testNoEntity() throws Exception {
-
-
- final WriteContext writeContext = mock( WriteContext.class );
-
-
- //mock returning the entity from the write context
- when( writeContext.getMessage( Entity.class ) ).thenReturn( null );
-
-
- //mock returning a mock mutation when we do a log entry write
- final MvccLogEntrySerializationStrategy logStrategy = mock( MvccLogEntrySerializationStrategy.class );
-
- //run the stage
- Start newStage = new Start( logStrategy );
-
- newStage.performStage( writeContext );
- }
-
-
- /** Test no entity id on the entity */
- @Test( expected = NullPointerException.class )
- public void testNoEntityId() throws Exception {
-
-
- final WriteContext writeContext = mock( WriteContext.class );
-
-
- final Entity entity = new Entity();
- final UUID version = UUIDGenerator.newTimeUUID();
-
- entity.setVersion( version );
-
- //mock returning the entity from the write context
- when( writeContext.getMessage( Entity.class ) ).thenReturn( entity );
-
-
- //mock returning a mock mutation when we do a log entry write
- final MvccLogEntrySerializationStrategy logStrategy = mock( MvccLogEntrySerializationStrategy.class );
-
- //run the stage
- Start newStage = new Start( logStrategy );
-
- newStage.performStage( writeContext );
- }
-
-
- /** Test no entity id on the entity */
- @Test( expected = NullPointerException.class )
- public void testNoEntityVersion() throws Exception {
-
-
- final WriteContext writeContext = mock( WriteContext.class );
-
-
- final Entity entity = new Entity();
- final UUID entityId = UUIDGenerator.newTimeUUID();
-
-
- FieldUtils.writeDeclaredField( entity, "uuid", entityId, true );
-
-
- //mock returning the entity from the write context
- when( writeContext.getMessage( Entity.class ) ).thenReturn( entity );
-
-
- //mock returning a mock mutation when we do a log entry write
- final MvccLogEntrySerializationStrategy logStrategy = mock( MvccLogEntrySerializationStrategy.class );
-
- //run the stage
- Start newStage = new Start( logStrategy );
-
- newStage.performStage( writeContext );
- }
-
-
- private Entity generateEntity() throws IllegalAccessException {
- final Entity entity = new Entity();
- final UUID entityId = UUIDGenerator.newTimeUUID();
- final UUID version = UUIDGenerator.newTimeUUID();
-
- FieldUtils.writeDeclaredField( entity, "uuid", entityId, true );
- entity.setVersion( version );
-
- return entity;
- }
-}
-
-
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/43aba652/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/StartWriteTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/StartWriteTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/StartWriteTest.java
new file mode 100644
index 0000000..d7a6b46
--- /dev/null
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/StartWriteTest.java
@@ -0,0 +1,187 @@
+package org.apache.usergrid.persistence.collection.mvcc.stage.impl;
+
+
+import java.util.UUID;
+
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+
+import org.apache.commons.lang3.reflect.FieldUtils;
+
+import org.apache.usergrid.persistence.collection.CollectionContext;
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccLogEntry;
+import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
+import org.apache.usergrid.persistence.collection.mvcc.stage.ExecutionContext;
+import org.apache.usergrid.persistence.collection.serialization.MvccLogEntrySerializationStrategy;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import com.netflix.astyanax.MutationBatch;
+
+import static junit.framework.TestCase.assertSame;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.same;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+
+/** @author tnine */
+public class StartWriteTest {
+
+ /** Standard flow */
+ @Test
+ public void testStartStage() throws Exception {
+
+
+ final ExecutionContext executionContext = mock( ExecutionContext.class );
+ final CollectionContext context = mock( CollectionContext.class );
+
+
+ //mock returning the context
+ when( executionContext.getCollectionContext() ).thenReturn( context );
+
+
+ //set up the mock to return the entity from the start phase
+ final Entity entity = generateEntity();
+
+ //mock returning the entity from the write context
+ when( executionContext.getMessage( Entity.class ) ).thenReturn( entity );
+
+
+ //mock returning a mock mutation when we do a log entry write
+ final MvccLogEntrySerializationStrategy logStrategy = mock( MvccLogEntrySerializationStrategy.class );
+
+ final ArgumentCaptor<MvccLogEntry> logEntry = ArgumentCaptor.forClass( MvccLogEntry.class );
+
+ final MutationBatch mutation = mock( MutationBatch.class );
+
+ when( logStrategy.write( same( context ), logEntry.capture() ) ).thenReturn( mutation );
+
+
+ //run the stage
+ StartWrite newStage = new StartWrite( logStrategy );
+
+ newStage.performStage( executionContext );
+
+
+ //now verify our output was correct
+ ArgumentCaptor<MvccEntity> mvccEntity = ArgumentCaptor.forClass( MvccEntity.class );
+
+
+ //verify the log entry is correct
+ MvccLogEntry entry = logEntry.getValue();
+
+ assertEquals( "entity id did not match ", entity.getUuid(), entry.getEntityId() );
+ assertEquals( "version did not not match entityId", entity.getVersion(), entry.getVersion() );
+ assertEquals( "Stage is correct", Stage.ACTIVE, entry.getStage() );
+
+
+ //now verify we set the message into the write context
+ verify( executionContext ).setMessage( mvccEntity.capture() );
+
+ MvccEntity created = mvccEntity.getValue();
+
+ //verify uuid and version in both the MvccEntity and the entity itself
+ assertEquals( "entity id did not match generator", entity.getUuid(), created.getUuid() );
+ assertEquals( "version did not not match entityId", entity.getVersion(), created.getVersion() );
+ assertSame( "Entity correct", entity, created.getEntity().get() );
+
+
+ //now verify the proceed was called
+ verify( executionContext ).proceed();
+ }
+
+
+ /** Test no entity in the pipeline */
+ @Test( expected = NullPointerException.class )
+ public void testNoEntity() throws Exception {
+
+
+ final ExecutionContext executionContext = mock( ExecutionContext.class );
+
+
+ //mock returning the entity from the write context
+ when( executionContext.getMessage( Entity.class ) ).thenReturn( null );
+
+
+ //mock returning a mock mutation when we do a log entry write
+ final MvccLogEntrySerializationStrategy logStrategy = mock( MvccLogEntrySerializationStrategy.class );
+
+ //run the stage
+ StartWrite newStage = new StartWrite( logStrategy );
+
+ newStage.performStage( executionContext );
+ }
+
+
+ /** Test no entity id on the entity */
+ @Test( expected = NullPointerException.class )
+ public void testNoEntityId() throws Exception {
+
+
+ final ExecutionContext executionContext = mock( ExecutionContext.class );
+
+
+ final Entity entity = new Entity();
+ final UUID version = UUIDGenerator.newTimeUUID();
+
+ entity.setVersion( version );
+
+ //mock returning the entity from the write context
+ when( executionContext.getMessage( Entity.class ) ).thenReturn( entity );
+
+
+ //mock returning a mock mutation when we do a log entry write
+ final MvccLogEntrySerializationStrategy logStrategy = mock( MvccLogEntrySerializationStrategy.class );
+
+ //run the stage
+ StartWrite newStage = new StartWrite( logStrategy );
+
+ newStage.performStage( executionContext );
+ }
+
+
+ /** Test no entity id on the entity */
+ @Test( expected = NullPointerException.class )
+ public void testNoEntityVersion() throws Exception {
+
+
+ final ExecutionContext executionContext = mock( ExecutionContext.class );
+
+
+ final Entity entity = new Entity();
+ final UUID entityId = UUIDGenerator.newTimeUUID();
+
+
+ FieldUtils.writeDeclaredField( entity, "uuid", entityId, true );
+
+
+ //mock returning the entity from the write context
+ when( executionContext.getMessage( Entity.class ) ).thenReturn( entity );
+
+
+ //mock returning a mock mutation when we do a log entry write
+ final MvccLogEntrySerializationStrategy logStrategy = mock( MvccLogEntrySerializationStrategy.class );
+
+ //run the stage
+ StartWrite newStage = new StartWrite( logStrategy );
+
+ newStage.performStage( executionContext );
+ }
+
+
+ private Entity generateEntity() throws IllegalAccessException {
+ final Entity entity = new Entity();
+ final UUID entityId = UUIDGenerator.newTimeUUID();
+ final UUID version = UUIDGenerator.newTimeUUID();
+
+ FieldUtils.writeDeclaredField( entity, "uuid", entityId, true );
+ entity.setVersion( version );
+
+ return entity;
+ }
+}
+
+
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/43aba652/stack/corepersistence/index/src/main/java/org/apache/usergrid/persistence/index/stage/Complete.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/index/src/main/java/org/apache/usergrid/persistence/index/stage/Complete.java b/stack/corepersistence/index/src/main/java/org/apache/usergrid/persistence/index/stage/Complete.java
index dad2b21..2569c3a 100644
--- a/stack/corepersistence/index/src/main/java/org/apache/usergrid/persistence/index/stage/Complete.java
+++ b/stack/corepersistence/index/src/main/java/org/apache/usergrid/persistence/index/stage/Complete.java
@@ -1,8 +1,8 @@
package org.apache.usergrid.persistence.index.stage;
-import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
-import org.apache.usergrid.persistence.collection.mvcc.stage.WriteStage;
+import org.apache.usergrid.persistence.collection.mvcc.stage.ExecutionContext;
+import org.apache.usergrid.persistence.collection.mvcc.stage.Stage;
/**
@@ -10,11 +10,11 @@ import org.apache.usergrid.persistence.collection.mvcc.stage.WriteStage;
* @author: tnine
*
*/
-public class Complete implements WriteStage
+public class Complete implements Stage
{
@Override
- public void performStage( final WriteContext context ) {
+ public void performStage( final ExecutionContext context ) {
//To change body of implemented methods use File | Settings | File Templates.
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/43aba652/stack/corepersistence/index/src/main/java/org/apache/usergrid/persistence/index/stage/Start.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/index/src/main/java/org/apache/usergrid/persistence/index/stage/Start.java b/stack/corepersistence/index/src/main/java/org/apache/usergrid/persistence/index/stage/Start.java
index 05ecb1d..3809880 100644
--- a/stack/corepersistence/index/src/main/java/org/apache/usergrid/persistence/index/stage/Start.java
+++ b/stack/corepersistence/index/src/main/java/org/apache/usergrid/persistence/index/stage/Start.java
@@ -1,16 +1,16 @@
package org.apache.usergrid.persistence.index.stage;
-import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
-import org.apache.usergrid.persistence.collection.mvcc.stage.WriteStage;
+import org.apache.usergrid.persistence.collection.mvcc.stage.ExecutionContext;
+import org.apache.usergrid.persistence.collection.mvcc.stage.Stage;
/** This state should signal an index update has started */
-public class Start implements WriteStage
+public class Start implements Stage
{
@Override
- public void performStage( final WriteContext context ) {
+ public void performStage( final ExecutionContext context ) {
//To change body of implemented methods use File | Settings | File Templates.
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/43aba652/stack/corepersistence/index/src/main/java/org/apache/usergrid/persistence/index/stage/Write.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/index/src/main/java/org/apache/usergrid/persistence/index/stage/Write.java b/stack/corepersistence/index/src/main/java/org/apache/usergrid/persistence/index/stage/Write.java
index cff6d97..b9433a6 100644
--- a/stack/corepersistence/index/src/main/java/org/apache/usergrid/persistence/index/stage/Write.java
+++ b/stack/corepersistence/index/src/main/java/org/apache/usergrid/persistence/index/stage/Write.java
@@ -1,17 +1,17 @@
package org.apache.usergrid.persistence.index.stage;
-import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
-import org.apache.usergrid.persistence.collection.mvcc.stage.WriteStage;
+import org.apache.usergrid.persistence.collection.mvcc.stage.Stage;
+import org.apache.usergrid.persistence.collection.mvcc.stage.ExecutionContext;
/** This state should perform an update of the index. */
-public class Write implements WriteStage
+public class Write implements Stage
{
@Override
- public void performStage( final WriteContext context ) {
+ public void performStage( final ExecutionContext context ) {
//To change body of implemented methods use File | Settings | File Templates.
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/43aba652/stack/corepersistence/perftest/Readme.md
----------------------------------------------------------------------
diff --git a/stack/corepersistence/perftest/Readme.md b/stack/corepersistence/perftest/Readme.md
index 8061dda..d507e98 100644
--- a/stack/corepersistence/perftest/Readme.md
+++ b/stack/corepersistence/perftest/Readme.md
@@ -21,7 +21,7 @@ Perftest instance.
The following endpoints are used to control the framework:
- * /perftest/start
+ * /perftest/startWrite
* /perftest/stop
* /perftest/reset
* /perftest/stats
@@ -29,7 +29,7 @@ The following endpoints are used to control the framework:
The following ascii text shows the states of the framework which one can
go through while issuing POSTs to the end points above:
- start stop
+ startWrite stop
+-----+ +-------+ +-------+
---+ready+-------+running+-----+stopped|
+--+--+ +-------+ +---+---+