You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/10/30 14:50:12 UTC
[07/12] git commit: This contains the extra test.
This contains the extra test.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/f5df7b7b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f5df7b7b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f5df7b7b
Branch: refs/heads/two-dot-o-events
Commit: f5df7b7b0eb9741abfe204c61136d12e7f7ae77c
Parents: 839fc2b
Author: grey <gr...@apigee.com>
Authored: Wed Oct 29 16:32:11 2014 -0700
Committer: grey <gr...@apigee.com>
Committed: Wed Oct 29 16:32:11 2014 -0700
----------------------------------------------------------------------
.../impl/EntityVersionCreatedTaskTest.java | 135 +++++++++++++++++++
1 file changed, 135 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f5df7b7b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java
index 4f1abca..9f8d77f 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java
@@ -3,11 +3,13 @@ package org.apache.usergrid.persistence.collection.impl;
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Semaphore;
import org.junit.AfterClass;
import org.junit.Test;
@@ -132,4 +134,137 @@ public class EntityVersionCreatedTaskTest {
}
+ @Test//(timeout=10000)
+ public void oneListener()//why does it matter if it has a version or not without a listener
+ throws ExecutionException, InterruptedException, ConnectionException {
+
+
+ final SerializationFig serializationFig = mock( SerializationFig.class );
+
+ when( serializationFig.getBufferSize() ).thenReturn( 10 );
+
+ final MvccEntitySerializationStrategy ess =
+ mock( MvccEntitySerializationStrategy.class );
+
+ final MvccLogEntrySerializationStrategy less =
+ mock( MvccLogEntrySerializationStrategy.class );
+
+ final Keyspace keyspace = mock( Keyspace.class );
+
+ final MutationBatch entityBatch = mock( MutationBatch.class );
+
+ final MutationBatch logBatch = mock( MutationBatch.class );
+
+ final EntityVersionCreatedFactory entityVersionCreatedFactory = mock(EntityVersionCreatedFactory.class);
+
+ when( keyspace.prepareMutationBatch() )
+ .thenReturn( mock( MutationBatch.class ) ) // don't care what happens to this one
+ .thenReturn( entityBatch )
+ .thenReturn( logBatch );
+
+ // intentionally no events
+
+ //create a latch for the event listener, and add it to the list of events
+ final int sizeToReturn = 1;
+
+ final CountDownLatch latch = new CountDownLatch( sizeToReturn );
+
+ final EntityVersionCreatedTest eventListener = new EntityVersionCreatedTest(latch);
+
+ final Set<EntityVersionCreated> listeners = mock( Set.class );//new HashSet<EntityVersionCreated>();
+
+ final Iterator<EntityVersionCreated> helper = mock(Iterator.class);
+
+
+ when ( listeners.size()).thenReturn( 1 );
+ when ( listeners.iterator()).thenReturn( helper );
+ when ( helper.next() ).thenReturn( eventListener );
+
+ final Id applicationId = new SimpleId( "application" );
+
+ final CollectionScope appScope = new CollectionScopeImpl(
+ applicationId, applicationId, "users" );
+
+ final Id entityId = new SimpleId( "user" );
+
+ final Entity entity = new Entity( entityId );
+
+ final MvccEntity mvccEntity = new MvccEntityImpl( entityId, UUIDGenerator.newTimeUUID(),
+ MvccEntity.Status.COMPLETE,entity );
+
+
+ // mock up a single log entry for our first test
+ final LogEntryMock logEntryMock =
+ LogEntryMock.createLogEntryMock(less, appScope, entityId, 2 );
+
+ final UUID version = logEntryMock.getEntries().iterator().next().getVersion();
+
+ final UniqueValueSerializationStrategy uvss =
+ mock( UniqueValueSerializationStrategy.class );
+
+ //when ( listeners.iterator().next().versionCreated(appScope,entity));
+
+
+ EntityVersionCreatedTask entityVersionCreatedTask =
+ new EntityVersionCreatedTask(entityVersionCreatedFactory,
+ serializationFig,
+ less,
+ ess,
+ uvss,
+ keyspace,
+ appScope,
+ listeners,
+ entity);
+
+ // start the task
+ ListenableFuture<Void> future = taskExecutor.submit( entityVersionCreatedTask );
+
+ // wait for the task
+ future.get();
+
+ //mocked listener makes sure that the task is called
+ verify( listeners ).size();
+ verify( listeners ).iterator();
+ verify( helper ).next();
+
+ }
+
+ private static class EntityVersionCreatedTest implements EntityVersionCreated {
+ final CountDownLatch invocationLatch;
+
+ private EntityVersionCreatedTest( final CountDownLatch invocationLatch) {
+ this.invocationLatch = invocationLatch;
+ }
+
+ @Override
+ public void versionCreated( final CollectionScope scope, final Entity entity ) {
+ invocationLatch.countDown();
+ }
+ }
+
+
+// private static class SlowListener extends EntityVersionCreatedTest {
+// final Semaphore blockLatch;
+//
+// private SlowListener( final CountDownLatch invocationLatch, final Semaphore blockLatch ) {
+// super( invocationLatch );
+// this.blockLatch = blockLatch;
+// }
+//
+//
+// @Override
+// public void versionDeleted( final CollectionScope scope, final Id entityId,
+// final List<MvccEntity> entityVersion ) {
+//
+// //wait for unblock to happen before counting down invocation latches
+// try {
+// blockLatch.acquire();
+// }
+// catch ( InterruptedException e ) {
+// throw new RuntimeException( e );
+// }
+// super.versionDeleted( scope, entityId, entityVersion );
+// }
+// }
+
}