cmd.serialize( channel ); Command.NodeCommand result = (Command.NodeCommand) commandReader.read( channel );
@Test public void shouldSerializeDynamicRecordsRemoved() throws Exception { channel.reset(); // Given NodeRecord before = new NodeRecord( 12, false, 1, 2 ); before.setInUse( true ); List<DynamicRecord> beforeDyn = singletonList( dynamicRecord( 0, true, true, -1L, LONG.intValue(), new byte[]{1, 2, 3, 4, 5, 6, 7, 8} ) ); before.setLabelField( dynamicPointer( beforeDyn ), beforeDyn ); NodeRecord after = new NodeRecord( 12, false, 2, 1 ); after.setInUse( true ); List<DynamicRecord> dynamicRecords = singletonList( dynamicRecord( 0, false, true, -1L, LONG.intValue(), new byte[]{ 1, 2, 3, 4, 5, 6, 7, 8} ) ); after.setLabelField( dynamicPointer( dynamicRecords ), dynamicRecords ); // When Command.NodeCommand cmd = new Command.NodeCommand( before, after ); cmd.serialize( channel ); Command.NodeCommand result = (Command.NodeCommand) commandReader.read( channel ); // Then assertThat( result, equalTo( cmd ) ); assertThat( result.getMode(), equalTo( cmd.getMode() ) ); assertThat( result.getBefore(), equalTo( cmd.getBefore() ) ); assertThat( result.getAfter(), equalTo( cmd.getAfter() ) ); // And dynamic records should be the same assertThat( result.getBefore().getDynamicLabelRecords(), equalTo( cmd.getBefore().getDynamicLabelRecords() ) ); assertThat( result.getAfter().getDynamicLabelRecords(), equalTo( cmd.getAfter().getDynamicLabelRecords() ) ); }
@Test public void nodeCommandWithFixedReferenceFormat302() throws Exception { // Given InMemoryClosableChannel channel = new InMemoryClosableChannel(); NodeRecord before = new NodeRecord( 42, true, false, 33, 99, 66 ); NodeRecord after = new NodeRecord( 42, true, false, 33, 99, 66 ); before.setUseFixedReferences( true ); after.setUseFixedReferences( true ); new Command.NodeCommand( before, after ).serialize( channel ); // When PhysicalLogCommandReaderV3_0_2 reader = new PhysicalLogCommandReaderV3_0_2(); Command command = reader.read( channel ); assertTrue( command instanceof Command.NodeCommand); Command.NodeCommand nodeCommand = (Command.NodeCommand) command; // Then assertEquals( before, nodeCommand.getBefore() ); assertEquals( after, nodeCommand.getAfter() ); assertTrue( nodeCommand.getBefore().isUseFixedReferences() ); assertTrue( nodeCommand.getAfter().isUseFixedReferences() ); }
@Test public void nodeCommandWithFixedReferenceFormat300() throws Exception { // Given InMemoryClosableChannel channel = new InMemoryClosableChannel(); NodeRecord before = new NodeRecord( 42, true, false, 33, 99, 66 ); NodeRecord after = new NodeRecord( 42, true, false, 33, 99, 66 ); before.setUseFixedReferences( true ); after.setUseFixedReferences( true ); new Command.NodeCommand( before, after ).serialize( channel ); // When PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0(); Command command = reader.read( channel ); assertTrue( command instanceof Command.NodeCommand); Command.NodeCommand nodeCommand = (Command.NodeCommand) command; // Then assertEquals( before, nodeCommand.getBefore() ); assertEquals( after, nodeCommand.getAfter() ); assertTrue( nodeCommand.getBefore().isUseFixedReferences() ); assertTrue( nodeCommand.getAfter().isUseFixedReferences() ); }
@Test public void shouldReadSomeCommands() throws Exception { // GIVEN InMemoryClosableChannel channel = new InMemoryClosableChannel(); Commands.createNode( 0 ).serialize( channel ); Commands.createNode( 1 ).serialize( channel ); Commands.createRelationshipTypeToken( 0, 0 ).serialize( channel ); Commands.createRelationship( 0, 0, 1, 0 ).serialize( channel ); Commands.createPropertyKeyToken( 0, 0 ).serialize( channel ); Commands.createProperty( 0, PropertyType.SHORT_STRING, 0 ).serialize( channel ); CommandReader reader = new PhysicalLogCommandReaderV3_0(); // THEN assertTrue( reader.read( channel ) instanceof Command.NodeCommand ); assertTrue( reader.read( channel ) instanceof Command.NodeCommand ); assertTrue( reader.read( channel ) instanceof Command.RelationshipTypeTokenCommand ); assertTrue( reader.read( channel ) instanceof Command.RelationshipCommand ); assertTrue( reader.read( channel ) instanceof Command.PropertyKeyTokenCommand ); assertTrue( reader.read( channel ) instanceof Command.PropertyCommand ); }
@Test public void shouldReadACommandLogEntry() throws IOException { // given LogEntryVersion version = LogEntryVersion.CURRENT; Command.NodeCommand nodeCommand = new Command.NodeCommand( new NodeRecord( 11 ), new NodeRecord( 11 ) ); final LogEntryCommand command = new LogEntryCommand( version, nodeCommand ); final InMemoryClosableChannel channel = new InMemoryClosableChannel(); channel.put( version.byteCode() ); channel.put( LogEntryByteCodes.COMMAND ); nodeCommand.serialize( channel ); // when final LogEntry logEntry = logEntryReader.readLogEntry( channel ); // then assertEquals( command, logEntry ); }