@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 } }
toNodeId = groupCache.prepare( fromNodeId ); monitor.defragmentingNodeRange( fromNodeId, toNodeId );
@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 ) ); }
long toNodeId = cache.prepare( 0 ); assertTrue( toNodeId < nodeCount );
groupCount += counts[nodeId]; assertEquals( nodeCount, cache.prepare( 0 ) ); boolean thereAreMoreGroups = true; int cachedCount = 0;
toNodeId = groupCache.prepare( fromNodeId ); monitor.defragmentingNodeRange( fromNodeId, toNodeId );