commands.add( new Command.LabelTokenCommand( record.getBefore(), record.forReadingLinkage() ) );
@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 testVisitLabelTokenCommand() throws Exception { Command.LabelTokenCommand cmd = mock( Command.LabelTokenCommand.class ); when( cmd.handle( any( CommandVisitor.class ) ) ).thenCallRealMethod(); // WHEN boolean result = facade.visitLabelTokenCommand( cmd ); // THEN InOrder inOrder = inOrder( txApplier1, txApplier2, txApplier3 ); inOrder.verify( txApplier1 ).visitLabelTokenCommand( cmd ); inOrder.verify( txApplier2 ).visitLabelTokenCommand( cmd ); inOrder.verify( txApplier3 ).visitLabelTokenCommand( cmd ); inOrder.verifyNoMoreInteractions(); assertFalse( result ); }
commands.add( new Command.LabelTokenCommand( record.getBefore(), record.forReadingLinkage() ) );
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 Command visitLabelTokenCommand( ReadableChannel channel ) throws IOException { int id = channel.getInt(); LabelTokenRecord before = readLabelTokenRecord( id, channel ); if ( before == null ) { return null; } LabelTokenRecord after = readLabelTokenRecord( id, channel ); if ( after == null ) { return null; } return new Command.LabelTokenCommand( before, after ); }
private Command visitLabelTokenCommand( ReadableChannel channel ) throws IOException { int id = channel.getInt(); LabelTokenRecord before = readLabelTokenRecord( id, channel ); if ( before == null ) { return null; } LabelTokenRecord after = readLabelTokenRecord( id, channel ); if ( after == null ) { return null; } return new Command.LabelTokenCommand( before, after ); }
public void label( int id, String name, int... dynamicIds ) { Command.LabelTokenCommand command = new Command.LabelTokenCommand(); command.init( withName( new LabelTokenRecord( id ), dynamicIds, name ) ); addCommand( command ); }
@Override public void serialize( WritableChannel channel ) throws IOException { channel.put( NeoCommandType.LABEL_KEY_COMMAND ); channel.putInt( after.getIntId() ); writeLabelTokenRecord( channel, before ); writeLabelTokenRecord( channel, after ); }
@Override public boolean visitLabelTokenCommand( LabelTokenCommand command ) { NamedToken labelId = labelTokenStore.getToken( (int) command.getKey() ); cacheAccess.addLabelToken( labelId ); return false; }
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() ); } }
public void update( LabelTokenRecord labelToken ) { Command.LabelTokenCommand command = new Command.LabelTokenCommand(); command.init( labelToken ); addCommand( command ); }
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 Command visitLabelTokenCommand( ReadableChannel channel ) throws IOException { int id = channel.getInt(); LabelTokenRecord before = readLabelTokenRecord( id, channel ); if ( before == null ) { return null; } LabelTokenRecord after = readLabelTokenRecord( id, channel ); if ( after == null ) { return null; } return new Command.LabelTokenCommand( before, after ); }
@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 update( LabelTokenRecord before, LabelTokenRecord after ) { otherCommands.add( new Command.LabelTokenCommand( before, after ) ); }
private Command visitLabelTokenCommand( ReadableChannel channel ) throws IOException { int id = channel.getInt(); LabelTokenRecord before = readLabelTokenRecord( id, channel ); if ( before == null ) { return null; } LabelTokenRecord after = readLabelTokenRecord( id, channel ); if ( after == null ) { return null; } return new Command.LabelTokenCommand( before, after ); }
public static LabelTokenCommand createLabelToken( int id, int nameId ) { LabelTokenRecord before = new LabelTokenRecord( id ); LabelTokenRecord after = new LabelTokenRecord( id ); populateTokenRecord( after, nameId ); return new LabelTokenCommand( before, after ); }