Refine search
@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 ) ); }
@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 ) ); }
@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 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 recordWithReservedIdIsSkipped() { RecordStore<NodeRecord> store = mock( NodeStore.class ); StageControl stageControl = mock( StageControl.class ); UpdateRecordsStep<NodeRecord> step = new UpdateRecordsStep<>( stageControl, Configuration.DEFAULT, store, new StorePrepareIdSequence() ); NodeRecord node1 = new NodeRecord( 1 ); node1.setInUse( true ); NodeRecord node2 = new NodeRecord( 2 ); node2.setInUse( true ); NodeRecord nodeWithReservedId = new NodeRecord( IdGeneratorImpl.INTEGER_MINUS_ONE ); NodeRecord[] batch = {node1, node2, nodeWithReservedId}; step.process( batch, mock( BatchSender.class ) ); verify( store ).prepareForCommit( eq( node1 ), any( IdSequence.class ) ); verify( store ).updateRecord( node1 ); verify( store ).prepareForCommit( eq( node2 ), any( IdSequence.class ) ); verify( store ).updateRecord( node2 ); verify( store, never() ).prepareForCommit( eq( nodeWithReservedId ), any( IdSequence.class ) ); verify( store, never() ).updateRecord( nodeWithReservedId ); } }
@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 ); }
@Test public void shouldKeepRecordLightWhenSettingLabelFieldWithoutDynamicRecords() { // GIVEN NodeRecord record = new NodeRecord( 0, false, NO_NEXT_RELATIONSHIP.intValue(), NO_NEXT_PROPERTY.intValue() ); // WHEN record.setLabelField( 0, Collections.emptyList() ); // THEN assertTrue( record.isLight() ); }
@Test public void shouldUpdateLabelStoreScanOnNodeCommands() throws Exception { // given final IndexBatchTransactionApplier applier = newIndexTransactionApplier(); final NodeRecord before = new NodeRecord( 11 ); before.setLabelField( 17, emptyDynamicRecords ); final NodeRecord after = new NodeRecord( 12 ); after.setLabelField( 18, emptyDynamicRecords ); final Command.NodeCommand command = new Command.NodeCommand( before, after ); LabelScanWriter labelScanWriter = mock( LabelScanWriter.class ); when( labelScanStore.get() ).thenReturn( labelScanWriter ); // when boolean result; try ( TransactionApplier txApplier = applier.startTx( transactionToApply ) ) { result = txApplier.visitNodeCommand( command ); } // then assertFalse( result ); }
@Test public void deletingNodeWithRelationshipsIsNotAllowed() { // Given NeoStores store = mock( NeoStores.class ); IndexingService indexes = mock(IndexingService.class); IntegrityValidator validator = new IntegrityValidator( store, indexes ); NodeRecord record = new NodeRecord( 1L, false, 1L, -1L ); record.setInUse( false ); // When try { validator.validateNodeRecord( record ); fail( "Should have thrown integrity error." ); } catch ( Exception e ) { // good } }
@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 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 ) ); }
@Test public void ioThroughputStatDoesNotOverflow() { // store with huge record size to force overflow and not create huge batch of records RecordStore<NodeRecord> store = mock( RecordStore.class ); when( store.getRecordSize() ).thenReturn( Integer.MAX_VALUE / 2 ); Configuration configuration = mock( Configuration.class ); StageControl stageControl = mock( StageControl.class ); UpdateRecordsStep<NodeRecord> step = new UpdateRecordsStep<>( stageControl, configuration, store, new StorePrepareIdSequence() ); NodeRecord record = new NodeRecord( 1 ); record.setInUse( true ); NodeRecord[] batch = new NodeRecord[11]; Arrays.fill( batch, record ); step.process( batch, mock( BatchSender.class ) ); Stat stat = step.stat( Keys.io_throughput ); assertThat( stat.asLong(), greaterThan( 0L ) ); }
@Test public void shouldApplyNodeCommandToTheStore() 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( true ); 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 shouldMarkRecordHeavyWhenSettingLabelFieldWithDynamicRecords() { // GIVEN NodeRecord record = new NodeRecord( 0, false, NO_NEXT_RELATIONSHIP.intValue(), NO_NEXT_PROPERTY.intValue() ); // WHEN DynamicRecord dynamicRecord = new DynamicRecord( 1 ); record.setLabelField( 0x8000000001L, asList( dynamicRecord ) ); // THEN assertFalse( record.isLight() ); }
@Test public void shouldCloseLockGroupAfterAppliers() throws Exception NodeRecord after = new NodeRecord( nodeId ); after.setInUse( true ); visitor.visit( new Command.NodeCommand( new NodeRecord( nodeId ), after ) ); return null; } );
@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 shouldReportCircularNodePropertyRecordChain() throws Exception { shouldReportCircularPropertyRecordChain( RecordType.NODE, ( tx, next, propertyRecordId ) -> tx.create( new NodeRecord( next.node() ).initialize( true, propertyRecordId, false, -1, Record.NO_LABELS_FIELD.longValue() ) ) ); }
@Test public void shouldApplyNodeCommandToTheStoreInRecoveryMode() throws Exception { // given final BatchTransactionApplier applier = newApplier( true ); final NodeRecord before = new NodeRecord( 11 ); before.setLabelField( 42, asList( one, two ) ); final NodeRecord after = new NodeRecord( 12 ); after.setInUse( true ); 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 ) ).setHighestPossibleIdInUse( after.getId() ); verify( nodeStore, times( 1 ) ).updateRecord( after ); verify( dynamicLabelStore, times( 1 ) ).setHighestPossibleIdInUse( three.getId() ); }
@Test public void shouldListLabelRecordsInUse() { // Given NodeRecord node = new NodeRecord( 1, false, -1, -1 ); long inlinedLabels = 12L; DynamicRecord dynamic1 = dynamicRecord( 1L, true ); DynamicRecord dynamic2 = dynamicRecord( 2L, true ); DynamicRecord dynamic3 = dynamicRecord( 3L, true ); node.setLabelField( inlinedLabels, asList( dynamic1, dynamic2, dynamic3 ) ); dynamic3.setInUse( false ); // When Iterable<DynamicRecord> usedRecords = node.getUsedDynamicLabelRecords(); // Then assertThat( asList( usedRecords ), equalTo( asList( dynamic1, dynamic2 ) ) ); }
@Test public void shouldInvalidateTheCacheWhenTheNodeBecomesDense() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); final NodeRecord before = new NodeRecord( 11 ); before.setLabelField( 42, singletonList( one ) ); before.setInUse( true ); before.setDense( false ); final NodeRecord after = new NodeRecord( 12 ); after.setInUse( true ); after.setDense( true ); 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 ); }