@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 ) ); }
@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() ); }