private RelationshipTypeTokenRecord createRelationshipTypeTokenRecord( int id ) { RelationshipTypeTokenRecord relationshipTypeTokenRecord = new RelationshipTypeTokenRecord( id ); relationshipTypeTokenRecord.setInUse( true ); relationshipTypeTokenRecord.setNameId( 333 ); relationshipTypeTokenRecord.addNameRecord( new DynamicRecord( 43 ) ); return relationshipTypeTokenRecord; }
@Override public RelationshipTypeTokenRecord clone() { RelationshipTypeTokenRecord relationshipTypeTokenRecord = new RelationshipTypeTokenRecord( getIntId() ); relationshipTypeTokenRecord.setInUse( inUse() ); if ( isCreated() ) { relationshipTypeTokenRecord.setCreated(); } relationshipTypeTokenRecord.setNameId( getNameId() ); relationshipTypeTokenRecord.addNameRecords( getNameRecords() ); return relationshipTypeTokenRecord; } }
private int createNewRelationshipType( String name ) { int id = (int) relationshipTypeTokenStore.nextId(); RelationshipTypeTokenRecord record = new RelationshipTypeTokenRecord( id ); record.setInUse( true ); record.setCreated(); Collection<DynamicRecord> nameRecords = relationshipTypeTokenStore.allocateNameRecords( encodeString( name ) ); record.setNameId( (int) Iterables.first( nameRecords ).getId() ); record.addNameRecords( nameRecords ); relationshipTypeTokenStore.updateRecord( record ); tokenHolders.relationshipTypeTokens().addToken( new NamedToken( name, id ) ); return id; }
@Override public RelationshipTypeTokenRecord newRecord() { return new RelationshipTypeTokenRecord( -1 ); } }
@Test void shouldReportDynamicBlockNotInUse() { // given RelationshipTypeTokenRecord label = inUse( new RelationshipTypeTokenRecord( 42 ) ); DynamicRecord name = addRelationshipTypeName( notInUse( new DynamicRecord( 6 ) ) ); label.setNameId( (int) name.getId() ); // when RelationshipTypeConsistencyReport report = check( label ); // then verify( report ).nameBlockNotInUse( name ); verifyNoMoreInteractions( report ); }
@Test public void shouldApplyRelationshipTypeTokenCommandToTheStoreInRecovery() throws Exception { // given final BatchTransactionApplier applier = newApplier( true ); final RelationshipTypeTokenRecord before = new RelationshipTypeTokenRecord( 42 ); final RelationshipTypeTokenRecord after = new RelationshipTypeTokenRecord( 42 ); after.setInUse( true ); after.setNameId( 323 ); final Command.RelationshipTypeTokenCommand command = new Command.RelationshipTypeTokenCommand( before, after ); final NamedToken token = new NamedToken( "token", 21 ); when( relationshipTypeTokenStore.getToken( (int) command.getKey() ) ).thenReturn( token ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( relationshipTypeTokenStore, times( 1 ) ).setHighestPossibleIdInUse( after.getId() ); verify( relationshipTypeTokenStore, times( 1 ) ).updateRecord( after ); verify( cacheAccess, times( 1 ) ).addRelationshipTypeToken( token ); }
@Test public void shouldApplyRelationshipTypeTokenCommandToTheStore() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); final RelationshipTypeTokenRecord before = new RelationshipTypeTokenRecord( 42 ); final RelationshipTypeTokenRecord after = new RelationshipTypeTokenRecord( 42 ); after.setInUse( true ); after.setNameId( 323 ); final Command command = new RelationshipTypeTokenCommand( before, after ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( relationshipTypeTokenStore, times( 1 ) ).updateRecord( after ); }
@Test public void shouldReportRelationshipTypeInconsistencies() throws Exception { // given StoreAccess access = fixture.directStoreAccess().nativeStores(); RecordStore<RelationshipTypeTokenRecord> relTypeStore = access.getRelationshipTypeTokenStore(); RelationshipTypeTokenRecord record = relTypeStore.getRecord( (int) relTypeStore.nextId(), relTypeStore.newRecord(), FORCE ); record.setNameId( 20 ); record.setInUse( true ); relTypeStore.updateRecord( record ); // when ConsistencySummaryStatistics stats = check(); // then access.close(); on( stats ).verify( RecordType.RELATIONSHIP_TYPE, 1 ) .andThatsAllFolks(); }
private void writeRelationshipTypeTokenRecord( WritableChannel channel, RelationshipTypeTokenRecord record ) throws IOException { // id+in_use(byte)+count(int)+key_blockId(int)+nr_key_records(int) byte inUse = record.inUse() ? Record.IN_USE.byteValue() : Record.NOT_IN_USE.byteValue(); channel.put( inUse ); channel.putInt( record.getNameId() ); if ( record.isLight() ) { channel.putInt( 0 ); } else { writeDynamicRecords( channel, record.getNameRecords() ); } } }
@Override public Generator<RelationshipTypeTokenRecord> relationshipTypeToken() { return ( recordSize, format, recordId ) -> new RelationshipTypeTokenRecord( toIntExact( recordId ) ).initialize( random.nextBoolean(), randomInt( tokenBits ) ); }
RelationshipTypeToken( RelationshipTypeTokenRecord record ) { this.id = record.getIntId(); }
@Override public void checkReference( RelationshipGroupRecord record, RelationshipTypeTokenRecord referred, CheckerEngine<RelationshipGroupRecord, RelationshipGroupConsistencyReport> engine, RecordAccess records ) { if ( !referred.inUse() ) { engine.report().relationshipTypeNotInUse( referred ); } } }
@Override public RelationshipTypeTokenRecord newUnused( long key, Void additionalData ) { return andMarkAsCreated( new RelationshipTypeTokenRecord( toIntExact( key ) ) ); }
@Test void shouldReportEmptyName() { // given RelationshipTypeTokenRecord label = inUse( new RelationshipTypeTokenRecord( 42 ) ); DynamicRecord name = addRelationshipTypeName( inUse( new DynamicRecord( 6 ) ) ); label.setNameId( (int) name.getId() ); // when RelationshipTypeConsistencyReport report = check( label ); // then verify( report ).emptyName( name ); verifyNoMoreInteractions( report ); } }
private int createNewRelationshipType( String name ) { int id = (int) relationshipTypeTokenStore.nextId(); RelationshipTypeTokenRecord record = new RelationshipTypeTokenRecord( id ); record.setInUse( true ); record.setCreated(); Collection<DynamicRecord> nameRecords = relationshipTypeTokenStore.allocateNameRecords( encodeString( name ) ); record.setNameId( (int) Iterables.first( nameRecords ).getId() ); record.addNameRecords( nameRecords ); relationshipTypeTokenStore.updateRecord( record ); tokenHolders.relationshipTypeTokens().addToken( new NamedToken( name, id ) ); return id; }
@Test public void shouldReportRelationshipTypeInconsistencies() throws Exception { // given StoreAccess access = fixture.directStoreAccess().nativeStores(); RecordStore<RelationshipTypeTokenRecord> relTypeStore = access.getRelationshipTypeTokenStore(); RelationshipTypeTokenRecord record = relTypeStore.forceGetRecord( (int) relTypeStore.nextId() ); record.setNameId( 20 ); record.setInUse( true ); relTypeStore.updateRecord( record ); // when ConsistencySummaryStatistics stats = check( fixture.directStoreAccess() ); // then access.close(); on( stats ).verify( RecordType.RELATIONSHIP_TYPE, 1 ) .andThatsAllFolks(); }
private void writeRelationshipTypeTokenRecord( WritableChannel channel, RelationshipTypeTokenRecord record ) throws IOException { // id+in_use(byte)+count(int)+key_blockId(int)+nr_key_records(int) byte inUse = record.inUse() ? Record.IN_USE.byteValue() : Record.NOT_IN_USE.byteValue(); channel.put( inUse ); channel.putInt( record.getNameId() ); if ( record.isLight() ) { channel.putInt( 0 ); } else { writeDynamicRecords( channel, record.getNameRecords() ); } } }
@Override public void serialize( WritableChannel channel ) throws IOException { channel.put( NeoCommandType.REL_TYPE_COMMAND ); channel.putInt( after.getIntId() ); writeRelationshipTypeTokenRecord( channel, before ); writeRelationshipTypeTokenRecord( channel, after ); }
@Override public void checkReference( RelationshipRecord record, RelationshipTypeTokenRecord referred, CheckerEngine<RelationshipRecord,ConsistencyReport.RelationshipConsistencyReport> engine, RecordAccess records ) { if ( !referred.inUse() ) { engine.report().relationshipTypeNotInUse( referred ); } } }