@Override public String toString() { return "RelationshipGroup[" + getId() + ",type=" + type + ",out=" + firstOut + ",in=" + firstIn + ",loop=" + firstLoop + ",prev=" + prev + ",next=" + next + ",used=" + inUse() + ",owner=" + getOwningNode() + ",secondaryUnitId=" + getSecondaryUnitId() + "]"; }
@Override public void serialize( WritableChannel channel ) throws IOException { channel.put( NeoCommandType.REL_GROUP_COMMAND ); channel.putLong( after.getId() ); writeRelationshipGroupRecord( channel, before ); writeRelationshipGroupRecord( channel, after ); }
@Override public RelationshipGroupRecord clone() { RelationshipGroupRecord clone = new RelationshipGroupRecord( getId() ).initialize( inUse(), type, firstOut, firstIn, firstLoop, owningNode, next ); clone.setSecondaryUnitId( getSecondaryUnitId() ); return clone; }
public void create( RelationshipGroupRecord group ) { group.setCreated(); update( new RelationshipGroupRecord( group.getId(), group.getType() ), group ); }
public void delete( RelationshipGroupRecord group ) { group.setInUse( false ); add( group, new RelationshipGroupRecord( group.getId(), group.getType() ) ); }
@Test public void shouldApplyRelationshipGroupCommandToTheStoreInRecovery() throws Exception { // given final BatchTransactionApplier applier = newApplier( true ); // when final RelationshipGroupRecord before = new RelationshipGroupRecord( 42, 1 ); final RelationshipGroupRecord after = new RelationshipGroupRecord( 42, 1, 2, 3, 4, 5, 6, true ); final Command command = new Command.RelationshipGroupCommand( before, after ); boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( relationshipGroupStore, times( 1 ) ).setHighestPossibleIdInUse( after.getId() ); verify( relationshipGroupStore, times( 1 ) ).updateRecord( after ); }
store.updateRecord( group23 ); RelationshipGroupGetter groupGetter = new RelationshipGroupGetter( store ); NodeRecord node = new NodeRecord( 0, true, group2.getId(), -1 ); verification.verify( store ).getRecord( eq( group2.getId() ), any( RelationshipGroupRecord.class ), any( RecordLoad.class ) ); verification.verify( store ).getRecord( eq( group4.getId() ), any( RelationshipGroupRecord.class ), any( RecordLoad.class ) ); verification.verify( store ).getRecord( eq( group10.getId() ), any( RelationshipGroupRecord.class ), any( RecordLoad.class ) ); verification.verify( store, never() ) .getRecord( eq( group23.getId() ), any( RelationshipGroupRecord.class ), any( RecordLoad.class ) );
@Override protected void process( RelationshipGroupRecord[] batch, BatchSender sender ) { for ( RelationshipGroupRecord group : batch ) { if ( !group.inUse() ) { continue; } long nodeId = group.getOwningNode(); if ( cache.getByte( nodeId, 0 ) == 0 ) { cache.setByte( nodeId, 0, (byte) 1 ); NodeRecord nodeRecord = nodeStore.newRecord(); nodeStore.getRecordByCursor( nodeId, nodeRecord, NORMAL, nodeCursor ); nodeRecord.setNextRel( group.getId() ); nodeRecord.setDense( true ); current[cursor++] = nodeRecord; if ( cursor == batchSize ) { sender.send( current ); newBatch(); } } } control.recycle( batch ); }
private String diff( RelationshipGroupRecord expected, RelationshipGroupRecord actual ) { if ( actual.getId() == expected.getId() && actual.getType() == expected.getType() && actual.getNext() == expected.getNext() && actual.getFirstOut() == expected.getFirstOut() && actual.getFirstIn() == expected.getFirstIn() && actual.getFirstLoop() == expected.getFirstLoop() && actual.getOwningNode() == expected.getOwningNode() ) { return null; } return describeDiff( expected.toString(), actual.toString() ); }
nodeRecord.initialize( true, -1, true, groupRecord.getId(), 0 ); nodeRecord.setId( nodeId ); nodeStore.updateRecord( nodeRecord );
private void assertBatch( RelationshipGroupRecord[] batch, long lastOwningNodeLastBatch ) { for ( int i = 0; i < batch.length; i++ ) { RelationshipGroupRecord record = batch[i]; assertTrue( record.getId() > Record.NULL_REFERENCE.longValue() ); assertTrue( record.getOwningNode() > lastOwningNodeLastBatch ); assertEquals( 1, record.getFirstOut() ); // the mark our store mock sets when preparing if ( record.getNext() == Record.NULL_REFERENCE.longValue() ) { // This is the last in the chain, verify that this is either: assertTrue( // - the last one in the batch, or i == batch.length - 1 || // - the last one for this node batch[i + 1].getOwningNode() > record.getOwningNode() ); } } }
@Test public void shouldReadUnsignedRelationshipTypeId() throws Exception { // GIVEN try ( PageCursor cursor = new StubPageCursor( 1, recordSize * 10 ) ) { int offset = 10; cursor.next(); RelationshipGroupRecord group = new RelationshipGroupRecord( 2 ) .initialize( true, Short.MAX_VALUE + offset, 1, 2, 3, 4, 5 ); cursor.setOffset( offset ); format.write( group, cursor, recordSize ); // WHEN RelationshipGroupRecord read = new RelationshipGroupRecord( group.getId() ); cursor.setOffset( offset ); format.read( read, cursor, NORMAL, recordSize ); // THEN assertEquals( group, read ); } } }
private static void assertValidRelGroupCommand( StorageCommand command ) { assertThat( command, instanceOf( RelationshipGroupCommand.class ) ); RelationshipGroupCommand relGroupCommand = (RelationshipGroupCommand) command; RelationshipGroupRecord record = relGroupCommand.getAfter(); assertEquals( ID, record.getId() ); if ( IN_USE_FLAG == Record.IN_USE.byteValue() ) { assertTrue( record.inUse() ); } else if ( IN_USE_FLAG == Record.NOT_IN_USE.byteValue() ) { assertFalse( record.inUse() ); } else { throw new IllegalStateException( "Illegal inUse flag: " + IN_USE_FLAG ); } assertEquals( TYPE_AS_INT, record.getType() ); assertEquals( NEXT, record.getNext() ); assertEquals( FIRST_OUT, record.getFirstOut() ); assertEquals( FIRST_IN, record.getFirstIn() ); assertEquals( FIRST_LOOP, record.getNext() ); assertEquals( OWNING_NODE, record.getOwningNode() ); }
nodeRecord.initialize( true, -1, true, groupRecord.getId(), 0 ); nodeRecord.setId( nodeId ); nodeStore.updateRecord( nodeRecord );
groupRecord.getNext() == groupRecord.getId() + 1 || groupRecord.getNext() == Record.NO_NEXT_RELATIONSHIP.intValue() ); assertTrue( "Expected " + groupRecord + " to have type > " + currentTypeId,
new RelationshipRecord( relationship.getId() ), relationship ) ); tracker.visitRelationshipGroupCommand( new RelationshipGroupCommand( new RelationshipGroupRecord( relationshipGroup.getId() ), relationshipGroup ) ); tracker.close();
@Override public void serialize( WritableChannel channel ) throws IOException { channel.put( NeoCommandType.REL_GROUP_COMMAND ); channel.putLong( after.getId() ); writeRelationshipGroupRecord( channel, before ); writeRelationshipGroupRecord( channel, after ); }
@Override public RelationshipGroupRecord clone() { RelationshipGroupRecord clone = new RelationshipGroupRecord( getId() ).initialize( inUse(), type, firstOut, firstIn, firstLoop, owningNode, next ); clone.setSecondaryUnitId( getSecondaryUnitId() ); return clone; }