@Override public RelationshipGroupRecord newRecord() { return new RelationshipGroupRecord( -1 ); }
@Override public RelationshipGroupRecord newUnused( long key, Integer type ) { RelationshipGroupRecord record = new RelationshipGroupRecord( key ); record.setType( type ); return andMarkAsCreated( record ); }
private RelationshipGroupRecord group( long id, int type ) { RelationshipGroupRecord group = new RelationshipGroupRecord( id, type ); group.setInUse( true ); return group; } }
public static RelationshipGroupCommand createRelationshipGroup( long id, int type ) { RelationshipGroupRecord before = new RelationshipGroupRecord( id ); RelationshipGroupRecord after = new RelationshipGroupRecord( id, type ); after.setInUse( true ); after.setCreated(); return new RelationshipGroupCommand( before, after ); }
@Override public RelationshipGroupRecord clone() { RelationshipGroupRecord clone = new RelationshipGroupRecord( getId() ).initialize( inUse(), type, firstOut, firstIn, firstLoop, owningNode, next ); clone.setSecondaryUnitId( getSecondaryUnitId() ); return clone; }
protected static List<RelationshipGroupRecord> groups( Group... groups ) { List<RelationshipGroupRecord> records = new ArrayList<>(); for ( Group group : groups ) { for ( int i = 0; i < group.count; i++ ) { RelationshipGroupRecord record = new RelationshipGroupRecord( NULL_REFERENCE.longValue() ); record.setOwningNode( group.owningNode ); record.setNext( group.count - i - 1 ); // count: how many come after it (importer does this) records.add( record ); } } return records; }
@Test public void shouldApplyRelationshipGroupCommandToTheStore() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); // 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 ); final boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( relationshipGroupStore, times( 1 ) ).updateRecord( after ); }
@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 ); }
private RelationshipGroupRecord createRelationshipGroup( long id, long relationshipId ) { return new RelationshipGroupRecord( id, TYPE, getFirstOut( relationshipId ), getFirstIn( relationshipId ), getFirstLoop( relationshipId ), FIRST_OWNING_NODE, true ); }
public static RelationshipGroupRecord relGroup( long id, Consumer<RelationshipGroupRecord>... modifiers ) { RelationshipGroupRecord record = new RelationshipGroupRecord( id ); record.initialize( true, 0, Record.NO_NEXT_RELATIONSHIP.longValue(), Record.NO_NEXT_RELATIONSHIP.longValue(), Record.NO_NEXT_RELATIONSHIP.longValue(), -1, Record.NO_NEXT_RELATIONSHIP.longValue() ); for ( Consumer<RelationshipGroupRecord> modifier : modifiers ) { modifier.accept( record ); } return record; }
public void create( RelationshipGroupRecord group ) { group.setCreated(); update( new RelationshipGroupRecord( group.getId(), group.getType() ), group ); }
@Override protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next ) { // node -[first]-> group -[owner]-> -1 long group = next.relationshipGroup(); tx.create( withOwner( inUse( new RelationshipGroupRecord( group, C ) ), -1 ) ); } } );
public void delete( RelationshipGroupRecord group ) { group.setInUse( false ); add( group, new RelationshipGroupRecord( group.getId(), group.getType() ) ); }
@Override protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next ) { // group -[owner]-> <not-in-use node> long node = next.node(); long group = next.relationshipGroup(); tx.create( withOwner( inUse( new RelationshipGroupRecord( group, C ) ), node ) ); } } );
@Override protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next ) { long node = next.node(); long firstGroupId = next.relationshipGroup(); long otherGroupId = next.relationshipGroup(); tx.create( inUse( new NodeRecord( node, true, firstGroupId, NO_NEXT_PROPERTY.intValue() ) ) ); tx.create( withOwner( withNext( inUse( new RelationshipGroupRecord( firstGroupId, T ) ), otherGroupId ), node ) ); tx.create( withOwner( inUse( new RelationshipGroupRecord( otherGroupId, C ) ), node ) ); } } );
@Override public Generator<RelationshipGroupRecord> relationshipGroup() { return ( recordSize, format, recordId ) -> new RelationshipGroupRecord( recordId ).initialize( random.nextBoolean(), randomInt( tokenBits ), randomLongOrOccasionallyNull( entityBits ), randomLongOrOccasionallyNull( entityBits ), randomLongOrOccasionallyNull( entityBits ), randomLongOrOccasionallyNull( entityBits ), randomLongOrOccasionallyNull( entityBits ) ); }
@Override protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next ) { long node = next.node(); long group = next.relationshipGroup(); tx.create( inUse( new NodeRecord( node, true, group, NO_NEXT_PROPERTY.intValue() ) ) ); tx.create( withOwner( withNext( inUse( new RelationshipGroupRecord( group, C ) ), group + 1 /*non-existent group id*/ ), node ) ); } } );
@Override protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next ) { long node = next.node(); long group = next.relationshipGroup(); int nonExistentType = next.relationshipType() + 1; tx.create( inUse( new NodeRecord( node, true, group, NO_NEXT_PROPERTY.intValue() ) ) ); tx.create( withOwner( inUse( new RelationshipGroupRecord( group, nonExistentType ) ), node ) ); } } );
@Override protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next ) { long node = next.node(); long groupId = next.relationshipGroup(); long rel = next.relationship(); tx.create( inUse( new NodeRecord( node, true, groupId, NO_NEXT_PROPERTY.intValue() ) ) ); tx.create( withOwner( withRelationships( inUse( new RelationshipGroupRecord( groupId, C ) ), rel, rel, rel ), node ) ); } } );
@Override protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next ) { // node -[first]-> group -[owner]-> otherNode long node = next.node(); long otherNode = next.node(); long group = next.relationshipGroup(); tx.create( inUse( new NodeRecord( node, true, group, NO_NEXT_PROPERTY.intValue() ) ) ); tx.create( inUse( new NodeRecord( otherNode, false, NO_NEXT_RELATIONSHIP.intValue(), NO_NEXT_PROPERTY.intValue() ) ) ); tx.create( withOwner( inUse( new RelationshipGroupRecord( group, C ) ), otherNode ) ); } } );