private LabelTokenRecord createLabelTokenRecord( int id ) { LabelTokenRecord labelTokenRecord = new LabelTokenRecord( id ); labelTokenRecord.setInUse( true ); labelTokenRecord.setNameId( 333 ); labelTokenRecord.addNameRecord( new DynamicRecord( 43 ) ); return labelTokenRecord; }
private LabelTokenRecord readLabelTokenRecord( 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 ); } LabelTokenRecord record = new LabelTokenRecord( 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; }
@Override public LabelTokenRecord clone() { LabelTokenRecord labelTokenRecord = new LabelTokenRecord( getIntId() ); labelTokenRecord.setInUse( inUse() ); if ( isCreated() ) { labelTokenRecord.setCreated(); } labelTokenRecord.setNameId( getNameId() ); labelTokenRecord.addNameRecords( getNameRecords() ); return labelTokenRecord; } }
@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 ); }
private LabelTokenRecord readLabelTokenRecord( 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 ); } LabelTokenRecord record = new LabelTokenRecord( 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 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 ); }
private Command visitLabelTokenCommand( 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 ); } LabelTokenRecord record = new LabelTokenRecord( 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.LabelTokenCommand( null, record ); }
private Command visitLabelTokenCommand( 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 ); } LabelTokenRecord record = new LabelTokenRecord( 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.LabelTokenCommand( null, record ); }
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; }
@Override protected LabelTokenRecord createExistingRecord( boolean light ) { LabelTokenRecord record = new LabelTokenRecord( ID ); record.setNameId( NAME_RECORD_ID ); record.setInUse( true ); if ( !light ) { DynamicRecord nameRecord = new DynamicRecord( NAME_RECORD_ID ); nameRecord.setInUse( true ); nameRecord.setData( NAME_RECORD_DATA ); record.addNameRecord( nameRecord ); } return record; }
@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(); }
@Override public LabelTokenRecord clone() { LabelTokenRecord labelTokenRecord = new LabelTokenRecord( getIntId() ); labelTokenRecord.setInUse( inUse() ); if ( isCreated() ) { labelTokenRecord.setCreated(); } labelTokenRecord.setNameId( getNameId() ); labelTokenRecord.addNameRecords( getNameRecords() ); return labelTokenRecord; } }
private LabelTokenRecord readLabelTokenRecord( 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 ); } LabelTokenRecord record = new LabelTokenRecord( 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 LabelTokenRecord readLabelTokenRecord( 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 ); } LabelTokenRecord record = new LabelTokenRecord( 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 Command visitLabelTokenCommand( 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 ); } LabelTokenRecord record = new LabelTokenRecord( 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.LabelTokenCommand( null, record ); }
private Command visitLabelTokenCommand( 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 ); } LabelTokenRecord record = new LabelTokenRecord( 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.LabelTokenCommand( null, record ); }
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 public void shouldReportLabelInconsistencies() throws Exception { // given StoreAccess access = fixture.directStoreAccess().nativeStores(); LabelTokenRecord record = access.getLabelTokenStore().forceGetRecord( 1 ); record.setNameId( 20 ); record.setInUse( true ); access.getLabelTokenStore().updateRecord( record ); // when ConsistencySummaryStatistics stats = check( fixture.directStoreAccess() ); // then on( stats ).verify( RecordType.LABEL, 1 ) .andThatsAllFolks(); }