private PropertyKeyTokenRecord createPropertyKeyTokenRecord( int id ) { PropertyKeyTokenRecord propertyKeyTokenRecord = new PropertyKeyTokenRecord( id ); propertyKeyTokenRecord.setInUse( true ); propertyKeyTokenRecord.setNameId( 333 ); propertyKeyTokenRecord.addNameRecord( new DynamicRecord( 43 ) ); return propertyKeyTokenRecord; } }
private PropertyKeyTokenRecord readPropertyKeyTokenRecord( int id, ReadableChannel channel ) throws IOException { // in_use(byte)+count(int)+key_blockId(int) byte inUseFlag = channel.get(); boolean inUse = false; if ( (inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue() ) { inUse = true; } else if ( inUseFlag != Record.NOT_IN_USE.byteValue() ) { throw new IOException( "Illegal in use flag: " + inUseFlag ); } PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( id ); record.setInUse( inUse ); record.setPropertyCount( channel.getInt() ); record.setNameId( channel.getInt() ); if ( readDynamicRecords( channel, record, PROPERTY_INDEX_DYNAMIC_RECORD_ADDER ) == -1 ) { return null; } return record; }
private PropertyKeyTokenRecord readPropertyKeyTokenRecord( int id, ReadableChannel channel ) throws IOException { // in_use(byte)+count(int)+key_blockId(int) byte inUseFlag = channel.get(); boolean inUse = false; if ( (inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue() ) { inUse = true; } else if ( inUseFlag != Record.NOT_IN_USE.byteValue() ) { throw new IOException( "Illegal in use flag: " + inUseFlag ); } PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( id ); record.setInUse( inUse ); record.setPropertyCount( channel.getInt() ); record.setNameId( channel.getInt() ); if ( readDynamicRecords( channel, record, PROPERTY_INDEX_DYNAMIC_RECORD_ADDER ) == -1 ) { return null; } return record; }
@Test public void shouldApplyPropertyKeyTokenCommandToTheStoreInRecovery() throws Exception { // given final BatchTransactionApplier applier = newApplier( true ); final PropertyKeyTokenRecord before = new PropertyKeyTokenRecord( 42 ); final PropertyKeyTokenRecord after = new PropertyKeyTokenRecord( 42 ); after.setInUse( true ); after.setNameId( 323 ); final Command.PropertyKeyTokenCommand command = new Command.PropertyKeyTokenCommand( before, after ); final NamedToken token = new NamedToken( "token", 21 ); when( propertyKeyTokenStore.getToken( (int) command.getKey() ) ).thenReturn( token ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( propertyKeyTokenStore, times( 1 ) ).setHighestPossibleIdInUse( after.getId() ); verify( propertyKeyTokenStore, times( 1 ) ).updateRecord( after ); verify( cacheAccess, times( 1 ) ).addPropertyKeyToken( token ); }
@Test void shouldReportEmptyName() { // given PropertyKeyTokenRecord key = inUse( new PropertyKeyTokenRecord( 42 ) ); DynamicRecord name = addKeyName( inUse( new DynamicRecord( 6 ) ) ); key.setNameId( (int) name.getId() ); // when PropertyKeyTokenConsistencyReport report = check( key ); // then verify( report ).emptyName( name ); verifyNoMoreInteractions( report ); } }
@Test public void shouldApplyPropertyKeyTokenCommandToTheStore() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); final PropertyKeyTokenRecord before = new PropertyKeyTokenRecord( 42 ); final PropertyKeyTokenRecord after = new PropertyKeyTokenRecord( 42 ); after.setInUse( true ); after.setNameId( 323 ); final Command command = new PropertyKeyTokenCommand( before, after ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( propertyKeyTokenStore, times( 1 ) ).updateRecord( after ); }
@Test void shouldReportDynamicBlockNotInUse() { // given PropertyKeyTokenRecord key = inUse( new PropertyKeyTokenRecord( 42 ) ); DynamicRecord name = addKeyName( notInUse( new DynamicRecord( 6 ) ) ); key.setNameId( (int) name.getId() ); // when PropertyKeyTokenConsistencyReport report = check( key ); // then verify( report ).nameBlockNotInUse( name ); verifyNoMoreInteractions( report ); }
private Command visitPropertyKeyTokenCommand( ReadableChannel channel ) throws IOException { // id+in_use(byte)+count(int)+key_blockId(int) int id = channel.getInt(); byte inUseFlag = channel.get(); boolean inUse = false; if ( (inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue() ) { inUse = true; } else if ( inUseFlag != Record.NOT_IN_USE.byteValue() ) { throw new IOException( "Illegal in use flag: " + inUseFlag ); } PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( id ); record.setInUse( inUse ); record.setPropertyCount( channel.getInt() ); record.setNameId( channel.getInt() ); if ( readDynamicRecords( channel, record, PROPERTY_INDEX_DYNAMIC_RECORD_ADDER ) == -1 ) { return null; } return new Command.PropertyKeyTokenCommand( null, record ); }
private Command visitPropertyKeyTokenCommand( ReadableChannel channel ) throws IOException { // id+in_use(byte)+count(int)+key_blockId(int) int id = channel.getInt(); byte inUseFlag = channel.get(); boolean inUse = false; if ( (inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue() ) { inUse = true; } else if ( inUseFlag != Record.NOT_IN_USE.byteValue() ) { throw new IOException( "Illegal in use flag: " + inUseFlag ); } PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( id ); record.setInUse( inUse ); record.setPropertyCount( channel.getInt() ); record.setNameId( channel.getInt() ); if ( readDynamicRecords( channel, record, PROPERTY_INDEX_DYNAMIC_RECORD_ADDER ) == -1 ) { return null; } return new Command.PropertyKeyTokenCommand( null, record ); }
@Override public PropertyKeyTokenRecord clone() { PropertyKeyTokenRecord propertyKeyTokenRecord = new PropertyKeyTokenRecord( getIntId() ); propertyKeyTokenRecord.setInUse( inUse() ); if ( isCreated() ) { propertyKeyTokenRecord.setCreated(); } propertyKeyTokenRecord.setNameId( getNameId() ); propertyKeyTokenRecord.addNameRecords( getNameRecords() ); propertyKeyTokenRecord.setPropertyCount( getPropertyCount() ); return propertyKeyTokenRecord; } }
private int createNewPropertyKeyId( String stringKey ) { int keyId = (int) propertyKeyTokenStore.nextId(); PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( keyId ); record.setInUse( true ); record.setCreated(); Collection<DynamicRecord> keyRecords = propertyKeyTokenStore.allocateNameRecords( encodeString( stringKey ) ); record.setNameId( (int) Iterables.first( keyRecords ).getId() ); record.addNameRecords( keyRecords ); propertyKeyTokenStore.updateRecord( record ); tokenHolders.propertyKeyTokens().addToken( new NamedToken( stringKey, keyId ) ); return keyId; }
@Test void shouldReportDynamicRecordOwnedByTwoPropertyKeys() { // given RecordAccessStub records = new RecordAccessStub(); OwnerCheck decorator = new OwnerCheck( true, DynamicStore.PROPERTY_KEY ); RecordCheck<PropertyKeyTokenRecord, ConsistencyReport.PropertyKeyTokenConsistencyReport> checker = decorator.decoratePropertyKeyTokenChecker( dummyPropertyKeyCheck() ); DynamicRecord dynamic = records.addPropertyKeyName( inUse( string( new DynamicRecord( 42 ) ) ) ); PropertyKeyTokenRecord record1 = records.add( inUse( new PropertyKeyTokenRecord( 1 ) ) ); PropertyKeyTokenRecord record2 = records.add( inUse( new PropertyKeyTokenRecord( 2 ) ) ); record1.setNameId( (int) dynamic.getId() ); record2.setNameId( (int) dynamic.getId() ); // when ConsistencyReport.PropertyKeyTokenConsistencyReport report1 = check( ConsistencyReport.PropertyKeyTokenConsistencyReport.class, checker,record1, records ); ConsistencyReport.PropertyKeyTokenConsistencyReport report2 = check( ConsistencyReport.PropertyKeyTokenConsistencyReport.class, checker,record2, records ); // then verifyNoMoreInteractions( report1 ); verify( report2 ).nameMultipleOwners( record1 ); verifyNoMoreInteractions( report2 ); }
@Test void shouldReportDynamicRecordOwnedByPropertyKeyAndOtherDynamicRecord() { // given RecordAccessStub records = new RecordAccessStub(); OwnerCheck decorator = new OwnerCheck( true, DynamicStore.PROPERTY_KEY ); RecordCheck<DynamicRecord, ConsistencyReport.DynamicConsistencyReport> dynChecker = decorator.decorateDynamicChecker( RecordType.PROPERTY_KEY_NAME, dummyDynamicCheck( configureDynamicStore( 50 ), DynamicStore.PROPERTY_KEY ) ); RecordCheck<PropertyKeyTokenRecord, ConsistencyReport.PropertyKeyTokenConsistencyReport> keyCheck = decorator.decoratePropertyKeyTokenChecker( dummyPropertyKeyCheck() ); DynamicRecord owned = records.addPropertyKeyName( inUse( string( new DynamicRecord( 42 ) ) ) ); DynamicRecord dynamic = records.addPropertyKeyName( inUse( string( new DynamicRecord( 1 ) ) ) ); PropertyKeyTokenRecord key = records.add( inUse( new PropertyKeyTokenRecord( 1 ) ) ); dynamic.setNextBlock( owned.getId() ); key.setNameId( (int) owned.getId() ); // when ConsistencyReport.PropertyKeyTokenConsistencyReport keyReport = check( ConsistencyReport.PropertyKeyTokenConsistencyReport.class, keyCheck, key, records ); ConsistencyReport.DynamicConsistencyReport dynReport = check( ConsistencyReport.DynamicConsistencyReport.class, dynChecker, dynamic, records ); // then verifyNoMoreInteractions( keyReport ); verify( dynReport ).nextMultipleOwners( key ); verifyNoMoreInteractions( dynReport ); }
@Test void shouldReportDynamicRecordOwnedByOtherDynamicRecordAndPropertyKey() { // given RecordAccessStub records = new RecordAccessStub(); OwnerCheck decorator = new OwnerCheck( true, DynamicStore.PROPERTY_KEY ); RecordCheck<DynamicRecord, ConsistencyReport.DynamicConsistencyReport> dynChecker = decorator.decorateDynamicChecker( RecordType.PROPERTY_KEY_NAME, dummyDynamicCheck( configureDynamicStore( 50 ), DynamicStore.PROPERTY_KEY ) ); RecordCheck<PropertyKeyTokenRecord, ConsistencyReport.PropertyKeyTokenConsistencyReport> keyCheck = decorator.decoratePropertyKeyTokenChecker( dummyPropertyKeyCheck() ); DynamicRecord owned = records.addPropertyKeyName( inUse( string( new DynamicRecord( 42 ) ) ) ); DynamicRecord dynamic = records.addPropertyKeyName( inUse( string( new DynamicRecord( 1 ) ) ) ); PropertyKeyTokenRecord key = records.add( inUse( new PropertyKeyTokenRecord( 1 ) ) ); dynamic.setNextBlock( owned.getId() ); key.setNameId( (int) owned.getId() ); // when ConsistencyReport.DynamicConsistencyReport dynReport = check( ConsistencyReport.DynamicConsistencyReport.class,dynChecker, dynamic, records ); ConsistencyReport.PropertyKeyTokenConsistencyReport keyReport = check( ConsistencyReport.PropertyKeyTokenConsistencyReport.class, keyCheck, key, records ); // then verifyNoMoreInteractions( dynReport ); verify( keyReport ).nameMultipleOwners( dynamic ); verifyNoMoreInteractions( keyReport ); }
private GraphDatabaseAPI databaseWithManyPropertyKeys( int propertyKeyCount ) { PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() ); StoreFactory storeFactory = new StoreFactory( testDirectory.databaseLayout(), Config.defaults(), new DefaultIdGeneratorFactory( fileSystemRule.get() ), pageCache, fileSystemRule.get(), NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY ); NeoStores neoStores = storeFactory.openAllNeoStores( true ); PropertyKeyTokenStore store = neoStores.getPropertyKeyTokenStore(); for ( int i = 0; i < propertyKeyCount; i++ ) { PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( (int) store.nextId() ); record.setInUse( true ); Collection<DynamicRecord> nameRecords = store.allocateNameRecords( PropertyStore.encodeString( key( i ) ) ); record.addNameRecords( nameRecords ); record.setNameId( (int) Iterables.first( nameRecords ).getId() ); store.updateRecord( record ); } neoStores.close(); return database(); }
@Test public void shouldReportDynamicBlockNotInUse() throws Exception { // given PropertyKeyTokenRecord key = inUse( new PropertyKeyTokenRecord( 42 ) ); DynamicRecord name = addKeyName( notInUse( new DynamicRecord( 6 ) ) ); key.setNameId( (int) name.getId() ); // when ConsistencyReport.PropertyKeyTokenConsistencyReport report = check( key ); // then verify( report ).nameBlockNotInUse( name ); verifyNoMoreInteractions( report ); }
@Test public void shouldReportEmptyName() throws Exception { // given PropertyKeyTokenRecord key = inUse( new PropertyKeyTokenRecord( 42 ) ); DynamicRecord name = addKeyName( inUse( new DynamicRecord( 6 ) ) ); key.setNameId( (int) name.getId() ); // when ConsistencyReport.PropertyKeyTokenConsistencyReport report = check( key ); // then verify( report ).emptyName( name ); verifyNoMoreInteractions( report ); }
@Override public PropertyKeyTokenRecord clone() { PropertyKeyTokenRecord propertyKeyTokenRecord = new PropertyKeyTokenRecord( getIntId() ); propertyKeyTokenRecord.setInUse( inUse() ); if ( isCreated() ) { propertyKeyTokenRecord.setCreated(); } propertyKeyTokenRecord.setNameId( getNameId() ); propertyKeyTokenRecord.addNameRecords( getNameRecords() ); propertyKeyTokenRecord.setPropertyCount( getPropertyCount() ); return propertyKeyTokenRecord; } }
private int createNewPropertyKeyId( String stringKey ) { int keyId = (int) propertyKeyTokenStore.nextId(); PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( keyId ); record.setInUse( true ); record.setCreated(); Collection<DynamicRecord> keyRecords = propertyKeyTokenStore.allocateNameRecords( encodeString( stringKey ) ); record.setNameId( (int) Iterables.first( keyRecords ).getId() ); record.addNameRecords( keyRecords ); propertyKeyTokenStore.updateRecord( record ); tokenHolders.propertyKeyTokens().addToken( new NamedToken( stringKey, keyId ) ); return keyId; }
@Test public void shouldNotReportAnythingForConsistentlyChangedRecord() throws Exception { // given PropertyKeyTokenRecord oldRecord = notInUse( new PropertyKeyTokenRecord( 42 ) ); PropertyKeyTokenRecord newRecord = inUse( new PropertyKeyTokenRecord( 42 ) ); DynamicRecord name = addKeyName( inUse( new DynamicRecord( 6 ) ) ); name.setData( new byte[1] ); newRecord.setNameId( (int) name.getId() ); // when ConsistencyReport.PropertyKeyTokenConsistencyReport report = checkChange( oldRecord, newRecord ); // then verifyNoMoreInteractions( report ); }