### Question:
NodeRelationshipCache implements MemoryStatsVisitor.Visitable, AutoCloseable { public void setNodeCount( long nodeCount ) { if ( nodeCount - 1 > BigIdTracker.MAX_ID ) { throw new IllegalArgumentException( format( "Invalid number of nodes %d. Max is %d", nodeCount, BigIdTracker.MAX_ID ) ); } this.highNodeId = nodeCount; this.array = arrayFactory.newByteArray( highNodeId, minusOneBytes( ID_AND_COUNT_SIZE ) ); this.chunkChangedArray = new byte[chunkOf( nodeCount ) + 1]; } NodeRelationshipCache( NumberArrayFactory arrayFactory, int denseNodeThreshold );   NodeRelationshipCache( NumberArrayFactory arrayFactory, int denseNodeThreshold, int chunkSize, long base ); long incrementCount( long nodeId ); void setCount( long nodeId, long count, int typeId, Direction direction ); void setNodeCount( long nodeCount ); boolean isDense( long nodeId ); long getAndPutRelationship( long nodeId, int typeId, Direction direction, long firstRelId,
            boolean incrementCount ); long getFirstRel( long nodeId, GroupVisitor visitor ); void setForwardScan( boolean forward, boolean denseNodes ); long getCount( long nodeId, int typeId, Direction direction ); @Override String toString(); @Override void close(); @Override void acceptMemoryStatsVisitor( MemoryStatsVisitor visitor ); void visitChangedNodes( NodeChangeVisitor visitor, int nodeTypes ); long calculateMaxMemoryUsage( long numberOfRelationships ); static long calculateMaxMemoryUsage( long numberOfDenseNodes, long numberOfRelationships ); void countingCompleted(); long getNumberOfDenseNodes(); MemoryStatsVisitor.Visitable memoryEstimation( long numberOfNodes ); static final int GROUP_ENTRY_SIZE; static final GroupVisitor NO_GROUP_VISITOR; }### Answer:
@Test public void shouldGoThroughThePhases() { int nodeCount = 10; cache = new NodeRelationshipCache( NumberArrayFactory.OFF_HEAP, 20, 100, base ); cache.setNodeCount( nodeCount ); incrementRandomCounts( cache, nodeCount, nodeCount * 20 ); { long node = findNode( cache, nodeCount, false ); testNode( cache, node, null ); } { long node = findNode( cache, nodeCount, true ); testNode( cache, node, Direction.OUTGOING ); testNode( cache, node, Direction.INCOMING ); } }
@Test public void shouldFailFastOnTooHighNodeCount() { cache = new NodeRelationshipCache( NumberArrayFactory.HEAP, 1 ); try { cache.setNodeCount( 2L << (5 * Byte.SIZE) ); fail( "Should have failed" ); } catch ( IllegalArgumentException e ) { } }