public void setPropertyBlock( PropertyBlock block ) { removePropertyBlock( block.getKeyIndexId() ); addPropertyBlock( block ); }
private void expectInvalidPropertyValue( PropertyRecord property, long[] longs ) { PropertyBlock block = new PropertyBlock(); block.setValueBlocks( longs ); property.addPropertyBlock( block ); // when ConsistencyReport.PropertyConsistencyReport report = check( property ); // then verify( report ).invalidPropertyValue( block ); verifyNoMoreInteractions( report ); }
private static PropertyRecord propertyRecord( PropertyBlock... propertyBlocks ) { PropertyRecord record = new PropertyRecord( 0 ); if ( propertyBlocks != null ) { record.setInUse( true ); for ( PropertyBlock propertyBlock : propertyBlocks ) { record.addPropertyBlock( propertyBlock ); } } record.setNodeId( 0 ); return record; }
@Test public void shouldIterateOverBlocks() { // GIVEN PropertyRecord record = new PropertyRecord( 0 ); PropertyBlock[] blocks = new PropertyBlock[3]; for ( int i = 0; i < blocks.length; i++ ) { blocks[i] = new PropertyBlock(); record.addPropertyBlock( blocks[i] ); } // WHEN Iterator<PropertyBlock> iterator = record.iterator(); // THEN for ( PropertyBlock block : blocks ) { assertTrue( iterator.hasNext() ); assertEquals( block, iterator.next() ); } assertFalse( iterator.hasNext() ); }
private void existingRecord( PropertyRecord record, ExpectedRecord initialRecord ) { for ( ExpectedProperty initialProperty : initialRecord.properties ) { PropertyBlock block = new PropertyBlock(); propertyStore.encodeValue( block, initialProperty.key, initialProperty.value ); record.addPropertyBlock( block ); } assertTrue( record.size() <= PropertyType.getPayloadSize() ); }
private PropertyRecord propertyRecordWithSingleIntProperty( long id, int propertyKeyId, long prev, long next ) { PropertyRecord record = new PropertyRecord( id ).initialize( true, prev, next ); PropertyBlock block = new PropertyBlock(); PropertyStore.encodeValue( block, propertyKeyId, Values.intValue( 10 ), null, null, false ); record.addPropertyBlock( block ); return record; } } );
@Override public boolean id( Object id, Group group ) { long nodeId = nodeIds.next(); nodeRecord.setId( nodeId ); idMapper.put( id, nodeId, group ); // also store this id as property in temp property store if ( id != null ) { idPropertyStore.encodeValue( idPropertyBlock, 0, Values.of( id ) ); idPropertyRecord.addPropertyBlock( idPropertyBlock ); idPropertyRecord.setId( nodeId ); // yes nodeId idPropertyRecord.setInUse( true ); idPropertyStore.updateRecord( idPropertyRecord ); idPropertyRecord.clear(); } return true; }
@Test void shouldReportPropertyKeyNotInUse() { // given PropertyRecord property = inUse( new PropertyRecord( 42 ) ); PropertyKeyTokenRecord key = add( notInUse( new PropertyKeyTokenRecord( 0 ) ) ); PropertyBlock block = propertyBlock( key, PropertyType.INT, 0 ); property.addPropertyBlock( block ); // when ConsistencyReport.PropertyConsistencyReport report = check( property ); // then verify( report ).keyNotInUse( block, key ); verifyNoMoreInteractions( report ); }
@Test void shouldReportEmptyStringRecord() { // given PropertyRecord property = inUse( new PropertyRecord( 42 ) ); PropertyKeyTokenRecord key = add( inUse( new PropertyKeyTokenRecord( 6 ) ) ); DynamicRecord value = add( inUse( string( new DynamicRecord( 1001 ) ) ) ); PropertyBlock block = propertyBlock( key, value ); property.addPropertyBlock( block ); // when ConsistencyReport.PropertyConsistencyReport report = check( property ); // then verify( report ).stringEmpty( block, value ); verifyNoMoreInteractions( report ); }
@Test void shouldReportStringRecordNotInUse() { // given PropertyRecord property = inUse( new PropertyRecord( 42 ) ); PropertyKeyTokenRecord key = add( inUse( new PropertyKeyTokenRecord( 6 ) ) ); DynamicRecord value = add( notInUse( string( new DynamicRecord( 1001 ) ) ) ); PropertyBlock block = propertyBlock( key, value ); property.addPropertyBlock( block ); // when ConsistencyReport.PropertyConsistencyReport report = check( property ); // then verify( report ).stringNotInUse( block, value ); verifyNoMoreInteractions( report ); }
@Test void shouldReportArrayRecordNotInUse() { // given PropertyRecord property = inUse( new PropertyRecord( 42 ) ); PropertyKeyTokenRecord key = add( inUse( new PropertyKeyTokenRecord( 6 ) ) ); DynamicRecord value = add( notInUse( array( new DynamicRecord( 1001 ) ) ) ); PropertyBlock block = propertyBlock( key, value ); property.addPropertyBlock( block ); // when ConsistencyReport.PropertyConsistencyReport report = check( property ); // then verify( report ).arrayNotInUse( block, value ); verifyNoMoreInteractions( report ); }
@Test void shouldReportEmptyArrayRecord() { // given PropertyRecord property = inUse( new PropertyRecord( 42 ) ); PropertyKeyTokenRecord key = add( inUse( new PropertyKeyTokenRecord( 6 ) ) ); DynamicRecord value = add( inUse( array( new DynamicRecord( 1001 ) ) ) ); PropertyBlock block = propertyBlock( key, value ); property.addPropertyBlock( block ); // when ConsistencyReport.PropertyConsistencyReport report = check( property ); // then verify( report ).arrayEmpty( block, value ); verifyNoMoreInteractions( report ); } }
private <RECORD extends AbstractBaseRecord> void createRecordIn( RecordStore<RECORD> store ) { RECORD record = store.newRecord(); record.setId( store.nextId() ); record.setInUse( true ); if ( record instanceof PropertyRecord ) { // Special hack for property store, since it's not enough to simply set a record as in use there PropertyBlock block = new PropertyBlock(); ((PropertyStore)store).encodeValue( block, 0, Values.of( 10 ) ); ((PropertyRecord) record).addPropertyBlock( block ); } store.updateRecord( record ); }
@Test void shouldReportDynamicStringRecordOwnedByTwoPropertyRecords() { // given RecordAccessStub records = new RecordAccessStub(); OwnerCheck decorator = new OwnerCheck( true, DynamicStore.STRING ); RecordCheck<PropertyRecord, ConsistencyReport.PropertyConsistencyReport> propChecker = decorator .decoratePropertyChecker( dummyPropertyChecker() ); DynamicRecord dynamic = records.add( inUse( string( new DynamicRecord( 42 ) ) ) ); PropertyRecord property1 = records.add( inUse( new PropertyRecord( 1 ) ) ); PropertyRecord property2 = records.add( inUse( new PropertyRecord( 2 ) ) ); PropertyKeyTokenRecord key = records.add( inUse( new PropertyKeyTokenRecord( 10 ) ) ); property1.addPropertyBlock( propertyBlock( key, PropertyType.STRING, dynamic.getId() ) ); property2.addPropertyBlock( propertyBlock( key, PropertyType.STRING, dynamic.getId() ) ); // when ConsistencyReport.PropertyConsistencyReport report1 = check( ConsistencyReport.PropertyConsistencyReport.class, propChecker, property1, records ); ConsistencyReport.PropertyConsistencyReport report2 = check( ConsistencyReport.PropertyConsistencyReport.class, propChecker, property2, records ); // then verifyNoMoreInteractions( report1 ); verify( report2 ).stringMultipleOwners( property1 ); verifyNoMoreInteractions( report2 ); }
@Override protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next ) { // structurally correct, but does not have the 'mandatory' property with the 'draconian' label NodeRecord node = new NodeRecord( next.node(), false, -1, next.property() ); node.setInUse( true ); node.setLabelField( inlinedLabelsLongRepresentation( draconian ), Collections.emptySet() ); PropertyRecord property = new PropertyRecord( node.getNextProp(), node ); property.setInUse( true ); PropertyBlock block = new PropertyBlock(); block.setSingleBlock( key1 | (((long) PropertyType.INT.intValue()) << 24) | (1337L << 28) ); property.addPropertyBlock( block ); tx.create( node ); tx.create( property ); } } );
@Test void shouldReportDynamicArrayRecordOwnedByTwoPropertyRecords() { // given RecordAccessStub records = new RecordAccessStub(); OwnerCheck decorator = new OwnerCheck( true, DynamicStore.ARRAY ); RecordCheck<PropertyRecord, ConsistencyReport.PropertyConsistencyReport> propChecker = decorator .decoratePropertyChecker( dummyPropertyChecker() ); DynamicRecord dynamic = records.add( inUse( array( new DynamicRecord( 42 ) ) ) ); PropertyRecord property1 = records.add( inUse( new PropertyRecord( 1 ) ) ); PropertyRecord property2 = records.add( inUse( new PropertyRecord( 2 ) ) ); PropertyKeyTokenRecord key = records.add( inUse( new PropertyKeyTokenRecord( 10 ) ) ); property1.addPropertyBlock( propertyBlock( key, PropertyType.ARRAY, dynamic.getId() ) ); property2.addPropertyBlock( propertyBlock( key, PropertyType.ARRAY, dynamic.getId() ) ); // when ConsistencyReport.PropertyConsistencyReport report1 = check( ConsistencyReport.PropertyConsistencyReport.class, propChecker, property1, records ); ConsistencyReport.PropertyConsistencyReport report2 = check( ConsistencyReport.PropertyConsistencyReport.class, propChecker, property2, records ); // then verifyNoMoreInteractions( report1 ); verify( report2 ).arrayMultipleOwners( property1 ); verifyNoMoreInteractions( report2 ); }
public static PropertyCommand createProperty( long id, PropertyType type, int key, long... valueRecordIds ) { PropertyRecord record = new PropertyRecord( id ); record.setInUse( true ); record.setCreated(); PropertyBlock block = new PropertyBlock(); if ( valueRecordIds.length == 0 ) { PropertyStore.encodeValue( block, key, Values.of( 123 ), null, null, true ); } else { PropertyStore.setSingleBlockValue( block, key, type, valueRecordIds[0] ); block.setValueRecords( dynamicRecords( valueRecordIds ) ); } record.addPropertyBlock( block ); return new PropertyCommand( new PropertyRecord( id ), record ); }
@Override public Generator<PropertyRecord> property() { return ( recordSize, format, recordId ) -> { PropertyRecord record = new PropertyRecord( recordId ); int maxProperties = random.intBetween( 1, 4 ); StandaloneDynamicRecordAllocator stringAllocator = new StandaloneDynamicRecordAllocator(); StandaloneDynamicRecordAllocator arrayAllocator = new StandaloneDynamicRecordAllocator(); record.setInUse( true ); int blocksOccupied = 0; for ( int i = 0; i < maxProperties && blocksOccupied < 4; ) { PropertyBlock block = new PropertyBlock(); // Dynamic records will not be written and read by the property record format, // that happens in the store where it delegates to a "sub" store. PropertyStore.encodeValue( block, random.nextInt( tokenBits ), random.nextValue(), stringAllocator, arrayAllocator, true ); int tentativeBlocksWithThisOne = blocksOccupied + block.getValueBlocks().length; if ( tentativeBlocksWithThisOne <= 4 ) { record.addPropertyBlock( block ); blocksOccupied = tentativeBlocksWithThisOne; } } record.setPrevProp( randomLongOrOccasionallyNull( propertyBits ) ); record.setNextProp( randomLongOrOccasionallyNull( propertyBits ) ); return record; }; }
@Override protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next ) { DynamicRecord array = new DynamicRecord( next.arrayProperty() ); array.setInUse( true ); array.setCreated(); array.setType( ARRAY.intValue() ); array.setNextBlock( next.arrayProperty() ); array.setData( UTF8.encode( "hello world" ) ); PropertyBlock block = new PropertyBlock(); block.setSingleBlock( (((long) ARRAY.intValue()) << 24) | (array.getId() << 28) ); block.addValueRecord( array ); PropertyRecord property = new PropertyRecord( next.property() ); property.addPropertyBlock( block ); tx.create( property ); } } );
@Override protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next ) { DynamicRecord string = new DynamicRecord( next.stringProperty() ); string.setInUse( true ); string.setCreated(); string.setType( PropertyType.STRING.intValue() ); string.setNextBlock( next.stringProperty() ); string.setData( UTF8.encode( "hello world" ) ); PropertyBlock block = new PropertyBlock(); block.setSingleBlock( (((long) PropertyType.STRING.intValue()) << 24) | (string.getId() << 28) ); block.addValueRecord( string ); PropertyRecord property = new PropertyRecord( next.property() ); property.addPropertyBlock( block ); tx.create( property ); } } );