@Override protected void process( RelationshipGroupRecord[] batch, BatchSender sender ) { // These records are read page-wise forwards, but should be cached in reverse // since the records exists in the store in reverse order. for ( int i = batch.length - 1; i >= 0; i-- ) { RelationshipGroupRecord record = batch[i]; if ( record.inUse() ) { cache.put( record ); } } } }
@Test public void shouldNotFindSpaceToPutMoreGroupsThanSpecifiedForANode() { // GIVEN int nodeCount = 10; RelationshipGroupCache cache = new RelationshipGroupCache( HEAP, ByteUnit.kibiBytes( 4 ), nodeCount ); setCount( cache, 1, 7 ); assertEquals( nodeCount, cache.prepare( 0 ) ); // WHEN for ( int i = 0; i < 7; i++ ) { cache.put( new RelationshipGroupRecord( i + 1 ).initialize( true, i, -1, -1, -1, 1, -1 ) ); } try { cache.put( new RelationshipGroupRecord( 8 ).initialize( true, 8, -1, -1, -1, 1, -1 ) ); fail( "Should have failed" ); } catch ( IllegalStateException e ) { // Good } }
@Test public void shouldHandleGroupCountBeyondSignedShortRange() { // GIVEN long nodeId = 0; int limit = Short.MAX_VALUE + 10; RelationshipGroupCache cache = new RelationshipGroupCache( HEAP, ByteUnit.kibiBytes( 100 ), nodeId + 1 ); // WHEN first counting all groups per node for ( int type = 0; type < limit; type++ ) { cache.incrementGroupCount( nodeId ); } // and WHEN later putting group records into the cache RelationshipGroupRecord group = new RelationshipGroupRecord( -1 ); group.setOwningNode( nodeId ); for ( int type = 0; type < limit; type++ ) { group.setId( type ); group.setFirstOut( type ); // just some relationship group.setType( type ); cache.put( group ); } long prepared = cache.prepare( nodeId ); // THEN that should work, because it used to fail inside prepare, but we can also ask // the groupCount method to be sure assertEquals( nodeId, prepared ); assertEquals( limit, cache.groupCount( nodeId ) ); }
if ( cache.put( new RelationshipGroupRecord( nodeId ) .initialize( true, typeId, -1, -1, -1, nodeId, -1 ) ) )
if ( cache.put( new RelationshipGroupRecord( nodeId ) .initialize( true, typeId, -1, -1, -1, nodeId, -1 ) ) )
@Override protected void process( RelationshipGroupRecord[] batch, BatchSender sender ) { // These records are read page-wise forwards, but should be cached in reverse // since the records exists in the store in reverse order. for ( int i = batch.length - 1; i >= 0; i-- ) { RelationshipGroupRecord record = batch[i]; if ( record.inUse() ) { cache.put( record ); } } } }