@Test public void testNoConflict() throws Exception { final ApplicationScope collectionScope = mock( ApplicationScope.class ); when( collectionScope.getApplication() ) .thenReturn( new SimpleId( UUIDGenerator.newTimeUUID(), "organization" ) ); final Entity entity = generateEntity(); entity.setField(new StringField("name", "FOO", true)); entity.setField(new StringField("identifier", "BAR", true)); final MvccEntity mvccEntity = fromEntity( entity ); List<MvccLogEntry> logEntries = new ArrayList<MvccLogEntry>(); logEntries.add( new MvccLogEntryImpl( entity.getId(), UUIDGenerator.newTimeUUID(), Stage.ACTIVE, MvccLogEntry.State.COMPLETE )); logEntries.add( new MvccLogEntryImpl( entity.getId(), UUIDGenerator.newTimeUUID(), Stage.COMMITTED, MvccLogEntry.State.COMPLETE )); MvccLogEntrySerializationStrategy noConflictLog = mock( MvccLogEntrySerializationStrategy.class ); when( noConflictLog.load( collectionScope, entity.getId(), entity.getVersion(), 2) ) .thenReturn( logEntries ); UniqueValueSerializationStrategy uvstrat = mock( UniqueValueSerializationStrategy.class); WriteOptimisticVerify newStage = new WriteOptimisticVerify( noConflictLog ); newStage.call( new CollectionIoEvent<>( collectionScope, mvccEntity ) ); }
@Override public void call( final CollectionIoEvent<MvccEntity> ioevent ) { MvccValidationUtils.verifyMvccEntityWithEntity( ioevent.getEvent() ); MvccEntity mvccEntity = ioevent.getEvent(); final Entity entity = mvccEntity.getEntity().get(); ApplicationScope applicationScope = ioevent.getEntityCollection(); if ( entity.getVersion() == null ) { return; } List<MvccLogEntry> versions = logEntryStrat.load( applicationScope, entity.getId(), entity.getVersion(), 2 ); if ( versions.size() > 1 && versions.get( 1 ).getStage().ordinal() < Stage.COMMITTED.ordinal() ) { logger.debug( "Conflict writing entity id {} version {}", entity.getId().toString(), entity.getVersion().toString() ); throw new WriteOptimisticVerifyException( mvccEntity, applicationScope, "Change conflict, not first writer" ); } }
WriteOptimisticVerify implements Action1<CollectionIoEvent<MvccEntity>> { @Override public void call( final CollectionIoEvent<MvccEntity> ioevent ) { MvccValidationUtils.verifyMvccEntityWithEntity( ioevent.getEvent() ); MvccEntity mvccEntity = ioevent.getEvent(); final Entity entity = mvccEntity.getEntity().get(); ApplicationScope applicationScope = ioevent.getEntityCollection(); if ( entity.getVersion() == null ) { return; } List<MvccLogEntry> versions = logEntryStrat.load( applicationScope, entity.getId(), entity.getVersion(), 2 ); if ( versions.size() > 1 && versions.get( 1 ).getStage().ordinal() < Stage.COMMITTED.ordinal() ) { logger.debug( "Conflict writing entity id {} version {}", entity.getId().toString(), entity.getVersion().toString() ); throw new WriteOptimisticVerifyException( mvccEntity, applicationScope, "Change conflict, not first writer" ); } } }
WriteOptimisticVerify implements Action1<CollectionIoEvent<MvccEntity>> { @Override public void call( final CollectionIoEvent<MvccEntity> ioevent ) { MvccValidationUtils.verifyMvccEntityWithEntity( ioevent.getEvent() ); MvccEntity mvccEntity = ioevent.getEvent(); final Entity entity = mvccEntity.getEntity().get(); ApplicationScope applicationScope = ioevent.getEntityCollection(); if ( entity.getVersion() == null ) { return; } List<MvccLogEntry> versions = logEntryStrat.load( applicationScope, entity.getId(), entity.getVersion(), 2 ); if ( versions.size() > 1 && versions.get( 1 ).getStage().ordinal() < Stage.COMMITTED.ordinal() ) { logger.debug( "Conflict writing entity id {} version {}", entity.getId().toString(), entity.getVersion().toString() ); throw new WriteOptimisticVerifyException( mvccEntity, applicationScope, "Change conflict, not first writer" ); } } @Inject  WriteOptimisticVerify( MvccLogEntrySerializationStrategy logEntryStrat ); }
WriteOptimisticVerify implements Action1<CollectionIoEvent<MvccEntity>> { @Override public void call( final CollectionIoEvent<MvccEntity> ioevent ) { MvccValidationUtils.verifyMvccEntityWithEntity( ioevent.getEvent() ); MvccEntity mvccEntity = ioevent.getEvent(); final Entity entity = mvccEntity.getEntity().get(); ApplicationScope applicationScope = ioevent.getEntityCollection(); if ( entity.getVersion() == null ) { return; } List<MvccLogEntry> versions = logEntryStrat.load( applicationScope, entity.getId(), entity.getVersion(), 2 ); if ( versions.size() > 1 && versions.get( 1 ).getStage().ordinal() < Stage.COMMITTED.ordinal() ) { logger.debug( "Conflict writing entity id {} version {}", entity.getId().toString(), entity.getVersion().toString() ); throw new WriteOptimisticVerifyException( mvccEntity, applicationScope, "Change conflict, not first writer" ); } } @Inject  WriteOptimisticVerify( MvccLogEntrySerializationStrategy logEntryStrat ); @Override void call( final CollectionIoEvent<MvccEntity> ioevent ); }
WriteOptimisticVerify implements Action1<CollectionIoEvent<MvccEntity>> { @Override public void call( final CollectionIoEvent<MvccEntity> ioevent ) { MvccValidationUtils.verifyMvccEntityWithEntity( ioevent.getEvent() ); MvccEntity mvccEntity = ioevent.getEvent(); final Entity entity = mvccEntity.getEntity().get(); ApplicationScope applicationScope = ioevent.getEntityCollection(); if ( entity.getVersion() == null ) { return; } List<MvccLogEntry> versions = logEntryStrat.load( applicationScope, entity.getId(), entity.getVersion(), 2 ); if ( versions.size() > 1 && versions.get( 1 ).getStage().ordinal() < Stage.COMMITTED.ordinal() ) { logger.debug( "Conflict writing entity id {} version {}", entity.getId().toString(), entity.getVersion().toString() ); throw new WriteOptimisticVerifyException( mvccEntity, applicationScope, "Change conflict, not first writer" ); } } @Inject  WriteOptimisticVerify( MvccLogEntrySerializationStrategy logEntryStrat ); @Override void call( final CollectionIoEvent<MvccEntity> ioevent );  }