Property( RecordType type, PropertyRecord record ) { this.type = type; this.id = record.getId(); }
@Override public PropertyRecord getPropertyFromCache( long id ) { Collection<PropertyRecord> properties = cachedProperties( false ); if ( properties != null ) { for ( PropertyRecord property : properties ) { if ( property.getId() == id ) { return property; } } } return null; }
buf.append( "Property[" ).append( getId() ).append( ",used=" ).append( inUse() ).append( ",prev=" ).append( prevProp ).append( ",next=" ).append( nextProp );
@Override public Iterator<PropertyRecord> rawPropertyChain( long firstId ) { return new FilteringIterator<>( super.rawPropertyChain( firstId ), item -> shouldCheck( item.getId() /*for some reason we don't care about the id*/, MultiPassStore.PROPERTIES ) ); }
@Override public void checkReference( PropertyRecord record, PropertyRecord property, CheckerEngine<PropertyRecord, ConsistencyReport.PropertyConsistencyReport> engine, RecordAccess records ) { if ( record.getId() != property.getId() ) { if ( !property.inUse() || Record.NO_NEXT_PROPERTY.is( property.getNextProp() ) ) { wrongOwner( engine.report() ); } else if ( property.getNextProp() != record.getId() ) { engine.comparativeCheck( property( records, property.getNextProp() ), this ); } } }
@Override public void serialize( WritableChannel channel ) throws IOException { channel.put( NeoCommandType.PROP_COMMAND ); channel.putLong( after.getId() ); writePropertyRecord( channel, before ); writePropertyRecord( channel, after ); }
private <RECEIVER extends PropertyReceiver> void receivePropertyChain( RECEIVER receiver, Collection<PropertyRecord> chain ) { if ( chain != null ) { for ( PropertyRecord propRecord : chain ) { for ( PropertyBlock propBlock : propRecord ) { receiver.receive( propBlock.newPropertyKeyValue( pStore ), propRecord.getId() ); } } } }
@Override public PropertyRecord clone() { PropertyRecord result = (PropertyRecord) new PropertyRecord( getId() ).initialize( inUse() ); result.nextProp = nextProp; result.prevProp = prevProp; result.entityId = entityId; result.entityType = entityType; System.arraycopy( blocks, 0, result.blocks, 0, blocks.length ); result.blocksCursor = blocksCursor; for ( int i = 0; i < blockRecordsCursor; i++ ) { result.blockRecords[i] = blockRecords[i].clone(); } result.blockRecordsCursor = blockRecordsCursor; result.blocksLoaded = blocksLoaded; if ( deletedRecords != null ) { for ( DynamicRecord deletedRecord : deletedRecords ) { result.addDeletedRecord( deletedRecord.clone() ); } } return result; }
@Override public void checkReference( PropertyRecord record, PropertyRecord referred, CheckerEngine<PropertyRecord, ConsistencyReport.PropertyConsistencyReport> engine, RecordAccess records ) { if ( !referred.inUse() ) { notInUse( engine.report(), referred ); } else { if ( otherReference( referred ) != record.getId() ) { noBackReference( engine.report(), referred ); } } }
private void existingChain( ExpectedRecord... initialRecords ) { PropertyRecord prev = null; for ( ExpectedRecord initialRecord : initialRecords ) { PropertyRecord record = this.records.create( propertyStore.nextId(), primitive.record ).forChangingData(); record.setInUse( true ); existingRecord( record, initialRecord ); if ( prev == null ) { // This is the first one, update primitive to point to this primitive.record.setNextProp( record.getId() ); } else { // link property records together record.setPrevProp( prev.getId() ); prev.setNextProp( record.getId() ); } prev = record; } }
@Override protected void assertRecordsEqual( PropertyRecord actualRecord, PropertyRecord expectedRecord ) { assertNotNull( "actualRecord", actualRecord ); assertNotNull( "expectedRecord", expectedRecord ); assertThat( "getDeletedRecords", actualRecord.getDeletedRecords(), is( expectedRecord.getDeletedRecords() ) ); assertThat( "getNextProp", actualRecord.getNextProp(), is( expectedRecord.getNextProp() ) ); assertThat( "getEntityId", actualRecord.getNodeId(), is( expectedRecord.getNodeId() ) ); assertThat( "getPrevProp", actualRecord.getPrevProp(), is( expectedRecord.getPrevProp() ) ); assertThat( "getRelId", actualRecord.getRelId(), is( expectedRecord.getRelId() ) ); assertThat( "getId", actualRecord.getId(), is( expectedRecord.getId() ) ); assertThat( "getLongId", actualRecord.getId(), is( expectedRecord.getId() ) ); List<PropertyBlock> actualBlocks = Iterables.asList( actualRecord ); List<PropertyBlock> expectedBlocks = Iterables.asList( expectedRecord ); assertThat( "getPropertyBlocks().size", actualBlocks.size(), is( expectedBlocks.size() ) ); for ( int i = 0; i < actualBlocks.size(); i++ ) { PropertyBlock actualBlock = actualBlocks.get( i ); PropertyBlock expectedBlock = expectedBlocks.get( i ); assertPropertyBlocksEqual( i, actualBlock, expectedBlock ); } }
@Test public void shouldApplyNodePropertyCommandToTheStoreInRecovery() throws Exception { // given final BatchTransactionApplier applier = newApplier( true ); final PropertyRecord before = new PropertyRecord( 11 ); final PropertyRecord after = new PropertyRecord( 12 ); after.setNodeId( 42 ); final Command command = new Command.PropertyCommand( before, after ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( lockService, times( 1 ) ).acquireNodeLock( 42, LockService.LockType.WRITE_LOCK ); verify( propertyStore, times( 1 ) ).setHighestPossibleIdInUse( after.getId() ); verify( propertyStore, times( 1 ) ).updateRecord( after ); }
@Test void shouldReportPropertyNotInUse() { // given NeoStoreRecord record = new NeoStoreRecord(); PropertyRecord property = add( notInUse( new PropertyRecord( 7 ) ) ); record.setNextProp( property.getId() ); // when ConsistencyReport.NeoStoreConsistencyReport report = check( record ); // then verify( report ).propertyNotInUse( property ); verifyNoMoreInteractions( report ); }
@Test void shouldReportPreviousPropertyNotInUse() { // given PropertyRecord property = inUse( new PropertyRecord( 42 ) ); PropertyRecord prev = add( notInUse( new PropertyRecord( 51 ) ) ); property.setPrevProp( prev.getId() ); // when ConsistencyReport.PropertyConsistencyReport report = check( property ); // then verify( report ).prevNotInUse( prev ); verifyNoMoreInteractions( report ); }
@Test void shouldNotReportAnythingForRecordWithConsistentReferenceToProperty() { // given NeoStoreRecord record = new NeoStoreRecord(); record.setNextProp( add( inUse( new PropertyRecord( 7 ) ) ).getId() ); // when ConsistencyReport.NeoStoreConsistencyReport report = check( record ); // then verifyNoMoreInteractions( report ); }
@Test void shouldReportNextPropertyNotInUse() { // given PropertyRecord property = inUse( new PropertyRecord( 42 ) ); PropertyRecord next = add( notInUse( new PropertyRecord( 51 ) ) ); property.setNextProp( next.getId() ); // when ConsistencyReport.PropertyConsistencyReport report = check( property ); // then verify( report ).nextNotInUse( next ); verifyNoMoreInteractions( report ); }
@Test void shouldReportNextPropertyNotReferringBack() { // given PropertyRecord property = inUse( new PropertyRecord( 42 ) ); PropertyRecord next = add( inUse( new PropertyRecord( 51 ) ) ); property.setNextProp( next.getId() ); // when ConsistencyReport.PropertyConsistencyReport report = check( property ); // then verify( report ).nextDoesNotReferenceBack( next ); verifyNoMoreInteractions( report ); }
@Test void shouldReportPreviousPropertyNotReferringBack() { // given PropertyRecord property = inUse( new PropertyRecord( 42 ) ); PropertyRecord prev = add( inUse( new PropertyRecord( 51 ) ) ); property.setPrevProp( prev.getId() ); // when ConsistencyReport.PropertyConsistencyReport report = check( property ); // then verify( report ).previousDoesNotReferenceBack( prev ); verifyNoMoreInteractions( report ); }
@Test void shouldReportPropertyNotFirstInChain() { // given NeoStoreRecord record = new NeoStoreRecord(); PropertyRecord property = add( inUse( new PropertyRecord( 7 ) ) ); property.setPrevProp( 6 ); record.setNextProp( property.getId() ); // when ConsistencyReport.NeoStoreConsistencyReport report = check( record ); // then verify( report ).propertyNotFirstInChain( property ); verifyNoMoreInteractions( report ); } }
public void create( PropertyRecord property ) { property.setCreated(); PropertyRecord before = new PropertyRecord( property.getId() ); if ( property.isNodeSet() ) { before.setNodeId( property.getNodeId() ); } if ( property.isRelSet() ) { before.setRelId( property.getRelId() ); } update( before, property ); }