@Test public void shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty() throws Exception { // GIVEN NeoStores neoStores = neoStoresRule.builder().build(); TransactionRecordState recordState = newTransactionRecordState( neoStores ); int nodeId = 1; recordState.nodeCreate( nodeId ); // WHEN recordState.nodeAddProperty( nodeId, propertyId1, value1 ); Collection<StorageCommand> commands = new ArrayList<>(); recordState.extractCommands( commands ); PropertyCommand propertyCommand = singlePropertyCommand( commands ); // THEN PropertyRecord before = propertyCommand.getBefore(); assertFalse( before.inUse() ); assertFalse( before.iterator().hasNext() ); PropertyRecord after = propertyCommand.getAfter(); assertTrue( after.inUse() ); assertEquals( 1, count( after ) ); }
@Override public boolean visitPropertyCommand( PropertyCommand command ) { PropertyStore propertyStore = neoStores.getPropertyStore(); track( propertyStore, command ); for ( PropertyBlock block : command.getAfter() ) { switch ( block.getType() ) { case STRING: track( propertyStore.getStringStore(), block.getValueRecords() ); break; case ARRAY: track( propertyStore.getArrayStore(), block.getValueRecords() ); break; default: // Not needed, no dynamic records then break; } } return false; }
@Override public boolean visitPropertyCommand( PropertyCommand command ) { if ( command.getAfter().isNodeSet() ) { createOrAddToGroup( command, command.getAfter().getNodeId(), propertyCommandsByNodeIds ); } else if ( command.getAfter().isRelSet() ) { createOrAddToGroup( command, command.getAfter().getRelId(), propertyCommandsByRelationshipIds ); } return false; }
@Override public boolean visitPropertyCommand( PropertyCommand command ) { PropertyStore propertyStore = neoStores.getPropertyStore(); track( propertyStore, command ); for ( PropertyBlock block : command.getAfter() ) { switch ( block.getType() ) { case STRING: track( propertyStore.getStringStore(), block.getValueRecords() ); break; case ARRAY: track( propertyStore.getArrayStore(), block.getValueRecords() ); break; default: // Not needed, no dynamic records then break; } } return false; }
@Test public void readPropertyCommandWithFixedReferenceFormat302() throws IOException { InMemoryClosableChannel channel = new InMemoryClosableChannel(); PropertyRecord before = new PropertyRecord( 1 ); PropertyRecord after = new PropertyRecord( 2 ); before.setUseFixedReferences( true ); after.setUseFixedReferences( true ); new Command.PropertyCommand( before, after ).serialize( channel ); PhysicalLogCommandReaderV3_0_2 reader = new PhysicalLogCommandReaderV3_0_2(); Command command = reader.read( channel ); assertTrue( command instanceof Command.PropertyCommand); Command.PropertyCommand neoStoreCommand = (Command.PropertyCommand) command; // Then assertEquals( before.getNextProp(), neoStoreCommand.getBefore().getNextProp() ); assertEquals( after.getNextProp(), neoStoreCommand.getAfter().getNextProp() ); assertTrue( neoStoreCommand.getBefore().isUseFixedReferences() ); assertTrue( neoStoreCommand.getAfter().isUseFixedReferences() ); }
@Test public void readPropertyCommandWithFixedReferenceFormat300() throws IOException { InMemoryClosableChannel channel = new InMemoryClosableChannel(); PropertyRecord before = new PropertyRecord( 1 ); PropertyRecord after = new PropertyRecord( 2 ); before.setUseFixedReferences( true ); after.setUseFixedReferences( true ); new Command.PropertyCommand( before, after ).serialize( channel ); PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0(); Command command = reader.read( channel ); assertTrue( command instanceof Command.PropertyCommand); Command.PropertyCommand neoStoreCommand = (Command.PropertyCommand) command; // Then assertEquals( before.getNextProp(), neoStoreCommand.getBefore().getNextProp() ); assertEquals( after.getNextProp(), neoStoreCommand.getAfter().getNextProp() ); assertTrue( neoStoreCommand.getBefore().isUseFixedReferences() ); assertTrue( neoStoreCommand.getAfter().isUseFixedReferences() ); }
@Test public void readPropertyCommandWithNonRequiredSecondaryUnit() throws IOException { InMemoryClosableChannel channel = new InMemoryClosableChannel(); PropertyRecord before = new PropertyRecord( 1 ); PropertyRecord after = new PropertyRecord( 2 ); after.setRequiresSecondaryUnit( false ); after.setSecondaryUnitId( 78 ); new Command.PropertyCommand( before, after ).serialize( channel ); PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0(); Command command = reader.read( channel ); assertTrue( command instanceof Command.PropertyCommand); Command.PropertyCommand neoStoreCommand = (Command.PropertyCommand) command; // Then assertEquals( before.getNextProp(), neoStoreCommand.getBefore().getNextProp() ); assertEquals( after.getNextProp(), neoStoreCommand.getAfter().getNextProp() ); verifySecondaryUnit( after, neoStoreCommand.getAfter() ); }
@Test public void readPropertyCommandWithSecondaryUnit() throws IOException { InMemoryClosableChannel channel = new InMemoryClosableChannel(); PropertyRecord before = new PropertyRecord( 1 ); PropertyRecord after = new PropertyRecord( 2 ); after.setRequiresSecondaryUnit( true ); after.setSecondaryUnitId( 78 ); new Command.PropertyCommand( before, after ).serialize( channel ); PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0(); Command command = reader.read( channel ); assertTrue( command instanceof Command.PropertyCommand); Command.PropertyCommand neoStoreCommand = (Command.PropertyCommand) command; // Then assertEquals( before.getNextProp(), neoStoreCommand.getBefore().getNextProp() ); assertEquals( after.getNextProp(), neoStoreCommand.getAfter().getNextProp() ); verifySecondaryUnit( after, neoStoreCommand.getAfter() ); }
@Override public boolean visitPropertyCommand( PropertyCommand command ) { if ( command.getAfter().isNodeSet() ) { createOrAddToGroup( command, command.getAfter().getNodeId(), propertyCommandsByNodeIds ); } else if ( command.getAfter().isRelSet() ) { createOrAddToGroup( command, command.getAfter().getRelId(), propertyCommandsByRelationshipIds ); } return false; }