private LabelTokenRecord createLabelTokenRecord( int id ) { LabelTokenRecord labelTokenRecord = new LabelTokenRecord( id ); labelTokenRecord.setInUse( true ); labelTokenRecord.setNameId( 333 ); labelTokenRecord.addNameRecord( new DynamicRecord( 43 ) ); return labelTokenRecord; }
@Override public LabelTokenRecord clone() { LabelTokenRecord labelTokenRecord = new LabelTokenRecord( getIntId() ); labelTokenRecord.setInUse( inUse() ); if ( isCreated() ) { labelTokenRecord.setCreated(); } labelTokenRecord.setNameId( getNameId() ); labelTokenRecord.addNameRecords( getNameRecords() ); return labelTokenRecord; } }
@Override protected LabelTokenRecord createNullRecord( long id ) { return new LabelTokenRecord( (int) id ).initialize( false, 0 ); }
@Override public LabelTokenRecord newRecord() { return new LabelTokenRecord( -1 ); } }
private int createNewLabelId( String stringKey ) { int keyId = (int) labelTokenStore.nextId(); LabelTokenRecord record = new LabelTokenRecord( keyId ); record.setInUse( true ); record.setCreated(); Collection<DynamicRecord> keyRecords = labelTokenStore.allocateNameRecords( encodeString( stringKey ) ); record.setNameId( (int) Iterables.first( keyRecords ).getId() ); record.addNameRecords( keyRecords ); labelTokenStore.updateRecord( record ); tokenHolders.labelTokens().addToken( new NamedToken( stringKey, keyId ) ); return keyId; }
@Test void shouldReportDynamicBlockNotInUse() { // given LabelTokenRecord key = inUse( new LabelTokenRecord( 42 ) ); DynamicRecord name = addLabelName( notInUse( new DynamicRecord( 6 ) ) ); key.setNameId( (int) name.getId() ); // when LabelTokenConsistencyReport report = check( key ); // then verify( report ).nameBlockNotInUse( name ); verifyNoMoreInteractions( report ); }
@Test public void shouldApplyLabelTokenCommandToTheStoreInRecovery() throws Exception { // given final BatchTransactionApplier applier = newApplier( true ); final LabelTokenRecord before = new LabelTokenRecord( 42 ); final LabelTokenRecord after = new LabelTokenRecord( 42 ); after.setInUse( true ); after.setNameId( 323 ); final Command.LabelTokenCommand command = new Command.LabelTokenCommand( before, after ); final NamedToken token = new NamedToken( "token", 21 ); when( labelTokenStore.getToken( (int) command.getKey() ) ).thenReturn( token ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( labelTokenStore, times( 1 ) ).setHighestPossibleIdInUse( after.getId() ); verify( labelTokenStore, times( 1 ) ).updateRecord( after ); verify( cacheAccess, times( 1 ) ).addLabelToken( token ); }
@Test public void shouldApplyLabelTokenCommandToTheStore() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); final LabelTokenRecord before = new LabelTokenRecord( 42 ); final LabelTokenRecord after = new LabelTokenRecord( 42 ); after.setInUse( true ); after.setNameId( 323 ); final Command command = new LabelTokenCommand( before, after ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( labelTokenStore, times( 1 ) ).updateRecord( after ); }
public void create( LabelTokenRecord labelToken ) { labelToken.setCreated(); update( new LabelTokenRecord( labelToken.getIntId() ), labelToken ); }
@Test public void shouldReportLabelInconsistencies() throws Exception { // given StoreAccess access = fixture.directStoreAccess().nativeStores(); LabelTokenRecord record = access.getLabelTokenStore().getRecord( 1, access.getLabelTokenStore().newRecord(), FORCE ); record.setNameId( 20 ); record.setInUse( true ); access.getLabelTokenStore().updateRecord( record ); // when ConsistencySummaryStatistics stats = check(); // then on( stats ).verify( RecordType.LABEL, 1 ) .andThatsAllFolks(); }
private void writeLabelTokenRecord( WritableChannel channel, LabelTokenRecord record ) throws IOException { // id+in_use(byte)+type_blockId(int)+nr_type_records(int) byte inUse = record.inUse() ? Record.IN_USE.byteValue() : Record.NOT_IN_USE.byteValue(); channel.put( inUse ).putInt( record.getNameId() ); writeDynamicRecords( channel, record.getNameRecords() ); } }
assertThat( "getNameId", actualRecord.getNameId(), is( expectedRecord.getNameId() ) ); assertThat( "getId", actualRecord.getId(), is( expectedRecord.getId() ) ); assertThat( "getLongId", actualRecord.getId(), is( expectedRecord.getId() ) ); assertThat( "isLight", actualRecord.isLight(), is( expectedRecord.isLight() ) ); Collection<DynamicRecord> actualNameRecords = actualRecord.getNameRecords(); Collection<DynamicRecord> expectedNameRecords = expectedRecord.getNameRecords(); assertThat( "getNameRecords.size", actualNameRecords.size(), is( expectedNameRecords.size() ) ); Iterator<DynamicRecord> actualNRs = actualNameRecords.iterator();
LabelToken( LabelTokenRecord record ) { this.id = record.getIntId(); }
@Override protected LabelTokenStore initialiseStore( NeoStores neoStores ) { LabelTokenStore store = getStore( neoStores ); LabelTokenRecord record = createExistingRecord( false ); DynamicRecord nameRecord = new DynamicRecord( NAME_RECORD_ID ); record.getNameRecords().clear(); nameRecord.setData( NAME_RECORD_DATA ); nameRecord.setInUse( true ); record.addNameRecord( nameRecord ); store.updateRecord( record ); return store; }
@Override public void checkReference( NodeRecord node, LabelTokenRecord labelTokenRecord, CheckerEngine<NodeRecord, ConsistencyReport.NodeConsistencyReport> engine, RecordAccess records ) { if ( !labelTokenRecord.inUse() ) { engine.report().labelNotInUse( labelTokenRecord ); } }
public void create( LabelTokenRecord labelToken ) { labelToken.setCreated(); update( labelToken ); }
@Override public LabelTokenRecord newUnused( long key, Void additionalData ) { return andMarkAsCreated( new LabelTokenRecord( toIntExact( key ) ) ); }
private int createNewLabelId( String stringKey ) { int keyId = (int) labelTokenStore.nextId(); LabelTokenRecord record = new LabelTokenRecord( keyId ); record.setInUse( true ); record.setCreated(); Collection<DynamicRecord> keyRecords = labelTokenStore.allocateNameRecords( encodeString( stringKey ) ); record.setNameId( (int) Iterables.first( keyRecords ).getId() ); record.addNameRecords( keyRecords ); labelTokenStore.updateRecord( record ); tokenHolders.labelTokens().addToken( new NamedToken( stringKey, keyId ) ); return keyId; }
@Test void shouldReportEmptyName() { // given LabelTokenRecord key = inUse( new LabelTokenRecord( 42 ) ); DynamicRecord name = addLabelName( inUse( new DynamicRecord( 6 ) ) ); key.setNameId( (int) name.getId() ); // when LabelTokenConsistencyReport report = check( key ); // then verify( report ).emptyName( name ); verifyNoMoreInteractions( report ); } }