@Test public void testWrite() { final ApplicationScope context = mock( ApplicationScope.class ); 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 ); final UUIDService uuidService = mock( UUIDService.class ); final UUID version = UUIDGenerator.newTimeUUID(); when( uuidService.newTimeUUID() ).thenReturn( version ); MarkStart newStage = new MarkStart( logStrategy, uuidService ); final Id id = TestEntityGenerator.generateId(); CollectionIoEvent<MvccEntity> result = newStage.call( new CollectionIoEvent<Id>( context, id ) ); MvccLogEntry entry = logEntry.getValue(); assertEquals( "id correct", id, entry.getEntityId() ); assertEquals( "version correct", version, entry.getVersion() ); assertEquals( "EventStage is correct", Stage.ACTIVE, entry.getStage() ); MvccEntity created = result.getEvent(); assertSame( "id correct", id, created.getId() ); assertSame( "version did not not match entityId", version, created.getVersion() ); assertFalse( "Entity correct", created.getEntity().isPresent() ); }
@Override public CollectionIoEvent<MvccEntity> call( final CollectionIoEvent<Id> entityIoEvent ) { final Id entityId = entityIoEvent.getEvent(); ValidationUtils.verifyIdentity( entityId ); final UUID version = uuidService.newTimeUUID(); final ApplicationScope applicationScope = entityIoEvent.getEntityCollection(); final MvccLogEntry startEntry = new MvccLogEntryImpl( entityId, version, Stage.ACTIVE, MvccLogEntry.State.DELETED ); MutationBatch write = logStrategy.write( applicationScope, startEntry ); try { write.execute(); } catch ( ConnectionException e ) { logger.error( "Failed to execute write asynchronously ", e ); throw new CollectionRuntimeException( null, applicationScope, "Failed to execute write asynchronously ", e ); } final MvccEntityImpl nextStage = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE, Optional.<Entity>absent(), 0 ); return new CollectionIoEvent<MvccEntity>( applicationScope, nextStage ); }
MarkStart implements Func1<CollectionIoEvent<Id>, CollectionIoEvent<MvccEntity>> { @Override public CollectionIoEvent<MvccEntity> call( final CollectionIoEvent<Id> entityIoEvent ) { final Id entityId = entityIoEvent.getEvent(); ValidationUtils.verifyIdentity( entityId ); final UUID version = uuidService.newTimeUUID(); final ApplicationScope applicationScope = entityIoEvent.getEntityCollection(); final MvccLogEntry startEntry = new MvccLogEntryImpl( entityId, version, Stage.ACTIVE, MvccLogEntry.State.DELETED ); MutationBatch write = logStrategy.write( applicationScope, startEntry ); try { write.execute(); } catch ( ConnectionException e ) { logger.error( "Failed to execute write asynchronously ", e ); throw new CollectionRuntimeException( null, applicationScope, "Failed to execute write asynchronously ", e ); } final MvccEntityImpl nextStage = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE, Optional.<Entity>absent(), 0 ); return new CollectionIoEvent<MvccEntity>( applicationScope, nextStage ); } }
MarkStart implements Func1<CollectionIoEvent<Id>, CollectionIoEvent<MvccEntity>> { @Override public CollectionIoEvent<MvccEntity> call( final CollectionIoEvent<Id> entityIoEvent ) { final Id entityId = entityIoEvent.getEvent(); ValidationUtils.verifyIdentity( entityId ); final UUID version = uuidService.newTimeUUID(); final ApplicationScope applicationScope = entityIoEvent.getEntityCollection(); final MvccLogEntry startEntry = new MvccLogEntryImpl( entityId, version, Stage.ACTIVE, MvccLogEntry.State.DELETED ); MutationBatch write = logStrategy.write( applicationScope, startEntry ); try { write.execute(); } catch ( ConnectionException e ) { logger.error( "Failed to execute write asynchronously ", e ); throw new CollectionRuntimeException( null, applicationScope, "Failed to execute write asynchronously ", e ); } final MvccEntityImpl nextStage = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE, Optional.<Entity>absent(), 0 ); return new CollectionIoEvent<MvccEntity>( applicationScope, nextStage ); } @Inject  MarkStart(final MvccLogEntrySerializationStrategy logStrategy, final UUIDService uuidService ); }
MarkStart implements Func1<CollectionIoEvent<Id>, CollectionIoEvent<MvccEntity>> { @Override public CollectionIoEvent<MvccEntity> call( final CollectionIoEvent<Id> entityIoEvent ) { final Id entityId = entityIoEvent.getEvent(); ValidationUtils.verifyIdentity( entityId ); final UUID version = uuidService.newTimeUUID(); final ApplicationScope applicationScope = entityIoEvent.getEntityCollection(); final MvccLogEntry startEntry = new MvccLogEntryImpl( entityId, version, Stage.ACTIVE, MvccLogEntry.State.DELETED ); MutationBatch write = logStrategy.write( applicationScope, startEntry ); try { write.execute(); } catch ( ConnectionException e ) { logger.error( "Failed to execute write asynchronously ", e ); throw new CollectionRuntimeException( null, applicationScope, "Failed to execute write asynchronously ", e ); } final MvccEntityImpl nextStage = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE, Optional.<Entity>absent(), 0 ); return new CollectionIoEvent<MvccEntity>( applicationScope, nextStage ); } @Inject  MarkStart(final MvccLogEntrySerializationStrategy logStrategy, final UUIDService uuidService ); @Override CollectionIoEvent<MvccEntity> call( final CollectionIoEvent<Id> entityIoEvent ); }
MarkStart implements Func1<CollectionIoEvent<Id>, CollectionIoEvent<MvccEntity>> { @Override public CollectionIoEvent<MvccEntity> call( final CollectionIoEvent<Id> entityIoEvent ) { final Id entityId = entityIoEvent.getEvent(); ValidationUtils.verifyIdentity( entityId ); final UUID version = uuidService.newTimeUUID(); final ApplicationScope applicationScope = entityIoEvent.getEntityCollection(); final MvccLogEntry startEntry = new MvccLogEntryImpl( entityId, version, Stage.ACTIVE, MvccLogEntry.State.DELETED ); MutationBatch write = logStrategy.write( applicationScope, startEntry ); try { write.execute(); } catch ( ConnectionException e ) { logger.error( "Failed to execute write asynchronously ", e ); throw new CollectionRuntimeException( null, applicationScope, "Failed to execute write asynchronously ", e ); } final MvccEntityImpl nextStage = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE, Optional.<Entity>absent(), 0 ); return new CollectionIoEvent<MvccEntity>( applicationScope, nextStage ); } @Inject  MarkStart(final MvccLogEntrySerializationStrategy logStrategy, final UUIDService uuidService ); @Override CollectionIoEvent<MvccEntity> call( final CollectionIoEvent<Id> entityIoEvent );  }