private void setCount( RelationshipGroupCache cache, int nodeId, int count ) { for ( int i = 0; i < count; i++ ) { cache.incrementGroupCount( nodeId ); } } }
@Override protected void process( RelationshipGroupRecord[] batch, BatchSender sender ) { for ( RelationshipGroupRecord record : batch ) { if ( record.inUse() ) { cache.incrementGroupCount( record.getOwningNode() ); } } } }
@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 ) ); }
@Override protected void process( RelationshipGroupRecord[] batch, BatchSender sender ) { for ( RelationshipGroupRecord record : batch ) { if ( record.inUse() ) { cache.incrementGroupCount( record.getOwningNode() ); } } } }