public void add( NodeRecord before, NodeRecord after ) { nodeCommands.add( new Command.NodeCommand( before, after ) ); }
private Collection<StorageCommand> singleCreateNodeCommand() { Collection<StorageCommand> commands = new ArrayList<>(); long id = 0; NodeRecord before = new NodeRecord( id ); NodeRecord after = new NodeRecord( id ); after.setInUse( true ); commands.add( new Command.NodeCommand( before, after ) ); return commands; }
private Collection<StorageCommand> singleCreateNodeCommand( long id ) { Collection<StorageCommand> commands = new ArrayList<>(); NodeRecord before = new NodeRecord( id ); NodeRecord after = new NodeRecord( id ); after.setInUse( true ); commands.add( new NodeCommand( before, after ) ); return commands; }
private void addCorruptedCommandsToLastLogFile() throws IOException { PositiveLogFilesBasedLogVersionRepository versionRepository = new PositiveLogFilesBasedLogVersionRepository( logFiles ); LogFiles internalLogFiles = LogFilesBuilder.builder( directory.databaseLayout(), fileSystemRule ) .withLogVersionRepository( versionRepository ) .withTransactionIdStore( new SimpleTransactionIdStore() ).build(); try ( Lifespan lifespan = new Lifespan( internalLogFiles ) ) { LogFile transactionLogFile = internalLogFiles.getLogFile(); FlushablePositionAwareChannel channel = transactionLogFile.getWriter(); TransactionLogWriter writer = new TransactionLogWriter( new CorruptedLogEntryWriter( channel ) ); Collection<StorageCommand> commands = new ArrayList<>(); commands.add( new Command.PropertyCommand( new PropertyRecord( 1 ), new PropertyRecord( 2 ) ) ); commands.add( new Command.NodeCommand( new NodeRecord( 2 ), new NodeRecord( 3 ) ) ); PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation( commands ); writer.append( transaction, 1000 ); } }
@Test public void shouldApplyNodeCommandToTheStoreAndInvalidateTheCache() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); final NodeRecord before = new NodeRecord( 11 ); before.setLabelField( 42, asList( one, two ) ); final NodeRecord after = new NodeRecord( 12 ); after.setInUse( false ); after.setLabelField( 42, asList( one, two, three ) ); final Command.NodeCommand command = new Command.NodeCommand( before, after ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( lockService, times( 1 ) ).acquireNodeLock( command.getKey(), LockService.LockType.WRITE_LOCK ); verify( nodeStore, times( 1 ) ).updateRecord( after ); }
@Test public void shouldSerializeSecondaryUnitUsage() throws Exception { // Given // a record that is changed to include a secondary unit NodeRecord before = new NodeRecord( 13, false, 1, 2 ); before.setInUse( true ); before.setRequiresSecondaryUnit( false ); before.setSecondaryUnitId( NO_ID ); // this and the previous line set the defaults, they are here for clarity NodeRecord after = new NodeRecord( 13, false, 1, 2 ); after.setInUse( true ); after.setRequiresSecondaryUnit( true ); after.setSecondaryUnitId( 14L ); Command.NodeCommand command = new Command.NodeCommand( before, after ); // Then assertSerializationWorksFor( command ); }
private Command visitNodeCommand( ReadableChannel channel ) throws IOException { long id = channel.getLong(); NodeRecord before = readNodeRecord( id, channel ); if ( before == null ) { return null; } NodeRecord after = readNodeRecord( id, channel ); if ( after == null ) { return null; } if ( !before.inUse() && after.inUse() ) { after.setCreated(); } return new Command.NodeCommand( before, after ); }
@Test public void shouldSerializeDynamicRecordLabels() throws Exception { // Given NodeRecord before = new NodeRecord( 12, false, 1, 2 ); before.setInUse( true ); NodeRecord after = new NodeRecord( 12, false, 2, 1 ); after.setInUse( true ); NodeLabels nodeLabels = parseLabelsField( after ); for ( int i = 10; i < 100; i++ ) { nodeLabels.add( i, nodeStore, nodeStore.getDynamicLabelStore() ); } // When assertSerializationWorksFor( new Command.NodeCommand( before, after ) ); }
@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 ); }
private TransactionRepresentation tx( int size ) { Collection<StorageCommand> commands = new ArrayList<>(); for ( int i = 0; i < size; i++ ) { // The type of command doesn't matter here commands.add( new Command.NodeCommand( new NodeRecord( i ), new NodeRecord( i ).initialize( true, i, false, i, NO_LABELS_FIELD.longValue() ) ) ); } PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation( commands ); tx.setHeader( new byte[0], 0, 0, 0, 0, 0, 0 ); return tx; }
private static List<StorageCommand> createCommands() { return singletonList( new Command.NodeCommand( new NodeRecord( 1L ), new NodeRecord( 2L ) ) ); }
public static NodeCommand createNode( long id, long... dynamicLabelRecordIds ) { NodeRecord record = new NodeRecord( id ); record.setInUse( true ); record.setCreated(); if ( dynamicLabelRecordIds.length > 0 ) { Collection<DynamicRecord> dynamicRecords = dynamicRecords( dynamicLabelRecordIds ); record.setLabelField( DynamicNodeLabels.dynamicPointer( dynamicRecords ), dynamicRecords ); } return new NodeCommand( new NodeRecord( id ), record ); }
@Test public void shouldSerializeDenseRecord() throws Exception { // Given NodeRecord before = new NodeRecord( 12, false, 1, 2 ); before.setInUse( true ); NodeRecord after = new NodeRecord( 12, true, 2, 1 ); after.setInUse( true ); // When assertSerializationWorksFor( new Command.NodeCommand( before, after ) ); }
@Test public void shouldSerializeAndDeserializeUnusedRecords() throws Exception { // Given NodeRecord before = new NodeRecord( 12, false, 1, 2 ); NodeRecord after = new NodeRecord( 12, false, 2, 1 ); // When assertSerializationWorksFor( new Command.NodeCommand( before, after ) ); }
Command nextCommand() { return new Command.NodeCommand( nodeRecordGenerator.nextRecord(), nodeRecordGenerator.nextRecord() ); } }
private NodeCommand node( long nodeId ) { NodeRecord after = new NodeRecord( nodeId, true, false, NO_NEXT_RELATIONSHIP.intValue(),NO_NEXT_PROPERTY.intValue(), 0 ); NodeLabelsField.parseLabelsField( after ).add( 1, null, null ); return new NodeCommand( new NodeRecord( nodeId ), after ); }
@Test public void shouldSerializeUpdatedRecord() throws Exception { // Given NodeRecord before = new NodeRecord( 12, false, 1, 2 ); before.setInUse( true ); NodeRecord after = new NodeRecord( 12, false, 2, 1 ); after.setInUse( true ); // When assertSerializationWorksFor( new Command.NodeCommand( before, after ) ); }
@Test public void shouldSerializeCreatedRecord() throws Exception { // Given NodeRecord before = new NodeRecord( 12, false, 1, 2 ); NodeRecord after = new NodeRecord( 12, false, 2, 1 ); after.setCreated(); after.setInUse( true ); // When assertSerializationWorksFor( new Command.NodeCommand( before, after ) ); }
protected TransactionToApply tx() { NodeRecord before = new NodeRecord( 0 ); NodeRecord after = new NodeRecord( 0 ); after.setInUse( true ); Command.NodeCommand nodeCommand = new Command.NodeCommand( before, after ); PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation( singletonList( nodeCommand ) ); tx.setHeader( new byte[0], 0, 0, 0, 0, 0, 0 ); return new TransactionToApply( tx ); }
@Test public void shouldSerializeInlineLabels() throws Exception { // Given NodeRecord before = new NodeRecord( 12, false, 1, 2 ); before.setInUse( true ); NodeRecord after = new NodeRecord( 12, false, 2, 1 ); after.setInUse( true ); NodeLabels nodeLabels = parseLabelsField( after ); nodeLabels.add( 1337, nodeStore, nodeStore.getDynamicLabelStore() ); // When assertSerializationWorksFor( new Command.NodeCommand( before, after ) ); }