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 RelationshipTypeTokenRecord readRelationshipTypeTokenRecord( int id, ReadableChannel channel ) throws IOException { // in_use(byte)+type_blockId(int)+nr_type_records(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 ); } RelationshipTypeTokenRecord record = new RelationshipTypeTokenRecord( id ); record.setInUse( inUse ); record.setNameId( channel.getInt() ); int nrTypeRecords = channel.getInt(); for ( int i = 0; i < nrTypeRecords; i++ ) { DynamicRecord dr = readDynamicRecord( channel ); if ( dr == null ) { return null; } record.addNameRecord( dr ); } return record; }
private RelationshipTypeTokenRecord readRelationshipTypeTokenRecord( int id, ReadableChannel channel ) throws IOException { // in_use(byte)+type_blockId(int)+nr_type_records(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 ); } RelationshipTypeTokenRecord record = new RelationshipTypeTokenRecord( id ); record.setInUse( inUse ); record.setNameId( channel.getInt() ); int nrTypeRecords = channel.getInt(); for ( int i = 0; i < nrTypeRecords; i++ ) { DynamicRecord dr = readDynamicRecord( channel ); if ( dr == null ) { return null; } record.addNameRecord( dr ); } return record; }
@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 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 ); } }
@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 ); }
private Command visitRelationshipTypeTokenCommand( ReadableChannel channel ) throws IOException { // id+in_use(byte)+type_blockId(int)+nr_type_records(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 ); } RelationshipTypeTokenRecord record = new RelationshipTypeTokenRecord( id ); record.setInUse( inUse ); record.setNameId( channel.getInt() ); int nrTypeRecords = channel.getInt(); for ( int i = 0; i < nrTypeRecords; i++ ) { DynamicRecord dr = readDynamicRecord( channel ); if ( dr == null ) { return null; } record.addNameRecord( dr ); } return new Command.RelationshipTypeTokenCommand( null, record ); }
private Command visitRelationshipTypeTokenCommand( ReadableChannel channel ) throws IOException { // id+in_use(byte)+type_blockId(int)+nr_type_records(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 ); } RelationshipTypeTokenRecord record = new RelationshipTypeTokenRecord( id ); record.setInUse( inUse ); record.setNameId( channel.getInt() ); int nrTypeRecords = channel.getInt(); for ( int i = 0; i < nrTypeRecords; i++ ) { DynamicRecord dr = readDynamicRecord( channel ); if ( dr == null ) { return null; } record.addNameRecord( dr ); } return new Command.RelationshipTypeTokenCommand( null, record ); }
@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 ); }
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 void shouldReportDynamicRecordOwnedByTwoRelationshipLabels() { // given RecordAccessStub records = new RecordAccessStub(); OwnerCheck decorator = new OwnerCheck( true, DynamicStore.RELATIONSHIP_TYPE ); RecordCheck<RelationshipTypeTokenRecord, ConsistencyReport.RelationshipTypeConsistencyReport> checker = decorator.decorateRelationshipTypeTokenChecker( dummyRelationshipLabelCheck() ); DynamicRecord dynamic = records.addRelationshipTypeName( inUse( string( new DynamicRecord( 42 ) ) ) ); RelationshipTypeTokenRecord record1 = records.add( inUse( new RelationshipTypeTokenRecord( 1 ) ) ); RelationshipTypeTokenRecord record2 = records.add( inUse( new RelationshipTypeTokenRecord( 2 ) ) ); record1.setNameId( (int) dynamic.getId() ); record2.setNameId( (int) dynamic.getId() ); // when ConsistencyReport.RelationshipTypeConsistencyReport report1 = check( ConsistencyReport.RelationshipTypeConsistencyReport.class, checker,record1, records ); ConsistencyReport.RelationshipTypeConsistencyReport report2 = check( ConsistencyReport.RelationshipTypeConsistencyReport.class, checker,record2, records ); // then verifyNoMoreInteractions( report1 ); verify( report2 ).nameMultipleOwners( record1 ); verifyNoMoreInteractions( report2 ); }
@Test void shouldReportDynamicRecordOwnedByRelationshipLabelAndOtherDynamicRecord() { // given RecordAccessStub records = new RecordAccessStub(); OwnerCheck decorator = new OwnerCheck( true, DynamicStore.RELATIONSHIP_TYPE ); RecordCheck<DynamicRecord, ConsistencyReport.DynamicConsistencyReport> dynChecker = decorator.decorateDynamicChecker( RecordType.RELATIONSHIP_TYPE_NAME, dummyDynamicCheck( configureDynamicStore( 50 ), DynamicStore.RELATIONSHIP_TYPE ) ); RecordCheck<RelationshipTypeTokenRecord, ConsistencyReport.RelationshipTypeConsistencyReport> labelCheck = decorator.decorateRelationshipTypeTokenChecker( dummyRelationshipLabelCheck() ); DynamicRecord owned = records.addRelationshipTypeName( inUse( string( new DynamicRecord( 42 ) ) ) ); DynamicRecord dynamic = records.addRelationshipTypeName( inUse( string( new DynamicRecord( 1 ) ) ) ); RelationshipTypeTokenRecord label = records.add( inUse( new RelationshipTypeTokenRecord( 1 ) ) ); dynamic.setNextBlock( owned.getId() ); label.setNameId( (int) owned.getId() ); // when ConsistencyReport.RelationshipTypeConsistencyReport labelReport = check( ConsistencyReport.RelationshipTypeConsistencyReport.class, labelCheck, label, records ); ConsistencyReport.DynamicConsistencyReport dynReport = check( ConsistencyReport.DynamicConsistencyReport.class, dynChecker, dynamic, records ); // then verifyNoMoreInteractions( labelReport ); verify( dynReport ).nextMultipleOwners( label ); verifyNoMoreInteractions( dynReport ); }
@Test void shouldReportDynamicRecordOwnedByOtherDynamicRecordAndRelationshipLabel() { // given RecordAccessStub records = new RecordAccessStub(); OwnerCheck decorator = new OwnerCheck( true, DynamicStore.RELATIONSHIP_TYPE ); RecordCheck<DynamicRecord, ConsistencyReport.DynamicConsistencyReport> dynChecker = decorator.decorateDynamicChecker( RecordType.RELATIONSHIP_TYPE_NAME, dummyDynamicCheck( configureDynamicStore( 50 ), DynamicStore.RELATIONSHIP_TYPE ) ); RecordCheck<RelationshipTypeTokenRecord, ConsistencyReport.RelationshipTypeConsistencyReport> labelCheck = decorator.decorateRelationshipTypeTokenChecker( dummyRelationshipLabelCheck() ); DynamicRecord owned = records.addRelationshipTypeName( inUse( string( new DynamicRecord( 42 ) ) ) ); DynamicRecord dynamic = records.addRelationshipTypeName( inUse( string( new DynamicRecord( 1 ) ) ) ); RelationshipTypeTokenRecord label = records.add( inUse( new RelationshipTypeTokenRecord( 1 ) ) ); dynamic.setNextBlock( owned.getId() ); label.setNameId( (int) owned.getId() ); // when ConsistencyReport.DynamicConsistencyReport dynReport = check( ConsistencyReport.DynamicConsistencyReport.class, dynChecker, dynamic, records ); ConsistencyReport.RelationshipTypeConsistencyReport labelReport = check( ConsistencyReport.RelationshipTypeConsistencyReport.class, labelCheck, label, records ); // then verifyNoMoreInteractions( dynReport ); verify( labelReport ).nameMultipleOwners( dynamic ); verifyNoMoreInteractions( labelReport ); }
@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(); }
@Override public RelationshipTypeTokenRecord clone() { RelationshipTypeTokenRecord relationshipTypeTokenRecord = new RelationshipTypeTokenRecord( getIntId() ); relationshipTypeTokenRecord.setInUse( inUse() ); if ( isCreated() ) { relationshipTypeTokenRecord.setCreated(); } relationshipTypeTokenRecord.setNameId( getNameId() ); relationshipTypeTokenRecord.addNameRecords( getNameRecords() ); return relationshipTypeTokenRecord; } }
@Test public void shouldReportDynamicBlockNotInUse() throws Exception { // given RelationshipTypeTokenRecord label = inUse( new RelationshipTypeTokenRecord( 42 ) ); DynamicRecord name = addRelationshipTypeName( notInUse( new DynamicRecord( 6 ) ) ); label.setNameId( (int) name.getId() ); // when ConsistencyReport.RelationshipTypeConsistencyReport report = check( label ); // then verify( report ).nameBlockNotInUse( name ); verifyNoMoreInteractions( report ); }
@Test public void shouldReportEmptyName() throws Exception { // given RelationshipTypeTokenRecord label = inUse( new RelationshipTypeTokenRecord( 42 ) ); DynamicRecord name = addRelationshipTypeName( inUse( new DynamicRecord( 6 ) ) ); label.setNameId( (int) name.getId() ); // when ConsistencyReport.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 shouldNotReportAnythingForConsistentlyChangedRecord() throws Exception { // given RelationshipTypeTokenRecord oldRecord = notInUse( new RelationshipTypeTokenRecord( 42 ) ); RelationshipTypeTokenRecord newRecord = inUse( new RelationshipTypeTokenRecord( 42 ) ); DynamicRecord name = addRelationshipTypeName( inUse( new DynamicRecord( 6 ) ) ); name.setData( new byte[1] ); newRecord.setNameId( (int) name.getId() ); // when ConsistencyReport.RelationshipTypeConsistencyReport report = checkChange( oldRecord, newRecord ); // then verifyNoMoreInteractions( report ); }