RegularDegreeEdgePool extends AbstractRegularDegreeEdgePool { @Override public void addEdge(int nodeA, int nodeB) { long nodeAInfo; if (readerAccessibleInfo.getNodeInfo().getBothValues(nodeA) == -1L) { nodeAInfo = addNewNode(nodeA); } else { nodeAInfo = readerAccessibleInfo.getNodeInfo().getBothValues(nodeA); } int nodeADegree = getNodeDegreeFromNodeInfo(nodeAInfo); Preconditions.checkArgument(nodeADegree < maxDegree, "Exceeded the maximum degree (" + maxDegree + ") for node " + nodeA); int nodeAPosition = getNodePositionFromNodeInfo(nodeAInfo); int position = nodeAPosition + nodeADegree; readerAccessibleInfo.getEdges().addEntry(nodeB, position); currentNumEdgesStored++; readerAccessibleInfo.getNodeInfo().incrementSecondValue(nodeA, 1); numEdgesCounter.incr(); } RegularDegreeEdgePool(int expectedNumNodes, int maxDegree, StatsReceiver statsReceiver); @Override void addEdge(int nodeA, int nodeB); @Override void addEdge(int nodeA, int nodeB, long metadata); @Override long[] getMetadataShard(int node);  }
@Test public void testGetNodeEdgeMetadataReturningNegative() { NullStatsReceiver nullStatsReceiver = new NullStatsReceiver(); RegularDegreeEdgePool regularDegreeEdgePool = new RegularDegreeEdgePool(4, 4, nullStatsReceiver); regularDegreeEdgePool.addEdge(2048, 587); assertEquals((-1L), regularDegreeEdgePool.getNodeEdgeMetadata(2048, 426)); }
@Test public void testAddEdgeTakingThreeArgumentsThrowsIllegalArgumentException() { NullStatsReceiver nullStatsReceiver = new NullStatsReceiver(); RegularDegreeEdgePool regularDegreeEdgePool = new RegularDegreeEdgePool(508, 2, nullStatsReceiver); ShardedBigIntArray shardedBigIntArray = new ShardedBigIntArray(3157, 2, (-1035), nullStatsReceiver); IntToIntPairArrayIndexBasedMap intToIntPairArrayIndexBasedMap = new IntToIntPairArrayIndexBasedMap(3157, 16, nullStatsReceiver); RegularDegreeEdgePool.ReaderAccessibleInfo regularDegreeEdgePool_ReaderAccessibleInfo = new RegularDegreeEdgePool.ReaderAccessibleInfo(shardedBigIntArray, intToIntPairArrayIndexBasedMap); regularDegreeEdgePool.readerAccessibleInfo = regularDegreeEdgePool_ReaderAccessibleInfo; try { regularDegreeEdgePool.addEdge(0, 0); fail("Expecting exception: IllegalArgumentException"); } catch (IllegalArgumentException e) { assertEquals(Preconditions.class.getName(), e.getStackTrace()[0].getClassName()); } }
@Test public void testAddEdgeTakingTwoArgumentsReturningMinsOne() { RegularDegreeEdgePool regularDegreeEdgePool = new RegularDegreeEdgePool(4355, 4355, new NullStatsReceiver()); regularDegreeEdgePool.addEdge(4355, 4355); assertEquals((-1), regularDegreeEdgePool.getNodeEdge(4355, 4355)); }