//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldObserveFirstRelationshipAsEmptyInEachDirection() public virtual void ShouldObserveFirstRelationshipAsEmptyInEachDirection() { // GIVEN _cache = new NodeRelationshipCache(NumberArrayFactory_Fields.AutoWithoutPagecache, 1, 100, Base); int nodes = 100; int typeId = 5; Direction[] directions = Direction.values(); GroupVisitor groupVisitor = mock(typeof(GroupVisitor)); _cache.setForwardScan(true, true); _cache.NodeCount = nodes + 1; for (int i = 0; i < nodes; i++) { assertEquals(-1L, _cache.getFirstRel(nodes, groupVisitor)); _cache.incrementCount(i); long previous = _cache.getAndPutRelationship(i, typeId, directions[i % directions.Length], Random.Next(1_000_000), true); assertEquals(-1L, previous); } // WHEN _cache.setForwardScan(false, true); for (int i = 0; i < nodes; i++) { long previous = _cache.getAndPutRelationship(i, typeId, directions[i % directions.Length], Random.Next(1_000_000), false); assertEquals(-1L, previous); } // THEN _cache.setForwardScan(true, true); for (int i = 0; i < nodes; i++) { assertEquals(-1L, _cache.getFirstRel(nodes, groupVisitor)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHaveDenseNodesWithBigCounts() public virtual void ShouldHaveDenseNodesWithBigCounts() { // A count of a dense node follow a different path during import, first there's counting per node // then import goes into actual import of relationships where individual chain degrees are // kept. So this test will first set a total count, then set count for a specific chain // GIVEN _cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 1, 100, Base); long nodeId = 1; int typeId = 10; _cache.NodeCount = nodeId + 1; _cache.setCount(nodeId, 2, typeId, OUTGOING); // surely dense now _cache.getAndPutRelationship(nodeId, typeId, OUTGOING, 1, true); _cache.getAndPutRelationship(nodeId, typeId, INCOMING, 2, true); // WHEN long highCountOut = NodeRelationshipCache.MaxCount - 100; long highCountIn = NodeRelationshipCache.MaxCount - 50; _cache.setCount(nodeId, highCountOut, typeId, OUTGOING); _cache.setCount(nodeId, highCountIn, typeId, INCOMING); _cache.getAndPutRelationship(nodeId, typeId, OUTGOING, 1, true); _cache.getAndPutRelationship(nodeId, typeId, INCOMING, 2, true); // THEN assertEquals(highCountOut + 1, _cache.getCount(nodeId, typeId, OUTGOING)); assertEquals(highCountIn + 1, _cache.getCount(nodeId, typeId, INCOMING)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldKeepNextGroupIdForNextRound() public virtual void ShouldKeepNextGroupIdForNextRound() { // GIVEN _cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 1, 100, Base); long nodeId = 0; int typeId = 10; _cache.NodeCount = nodeId + 1; _cache.incrementCount(nodeId); GroupVisitor groupVisitor = mock(typeof(GroupVisitor)); when(groupVisitor.Visit(anyLong(), anyInt(), anyLong(), anyLong(), anyLong())).thenReturn(1L, 2L, 3L); long firstRelationshipGroupId; { // WHEN importing the first type long relationshipId = 10; _cache.getAndPutRelationship(nodeId, typeId, OUTGOING, relationshipId, true); firstRelationshipGroupId = _cache.getFirstRel(nodeId, groupVisitor); // THEN assertEquals(1L, firstRelationshipGroupId); verify(groupVisitor).visit(nodeId, typeId, relationshipId, -1L, -1L); // Also simulate going back again ("clearing" of the cache requires this) _cache.setForwardScan(false, true); _cache.getAndPutRelationship(nodeId, typeId, OUTGOING, relationshipId, false); _cache.setForwardScan(true, true); } long secondRelationshipGroupId; { // WHEN importing the second type long relationshipId = 11; _cache.getAndPutRelationship(nodeId, typeId, INCOMING, relationshipId, true); secondRelationshipGroupId = _cache.getFirstRel(nodeId, groupVisitor); // THEN assertEquals(2L, secondRelationshipGroupId); verify(groupVisitor).visit(nodeId, typeId, -1, relationshipId, -1L); // Also simulate going back again ("clearing" of the cache requires this) _cache.setForwardScan(false, true); _cache.getAndPutRelationship(nodeId, typeId, OUTGOING, relationshipId, false); _cache.setForwardScan(true, true); } { // WHEN importing the third type long relationshipId = 10; _cache.getAndPutRelationship(nodeId, typeId, BOTH, relationshipId, true); long thirdRelationshipGroupId = _cache.getFirstRel(nodeId, groupVisitor); assertEquals(3L, thirdRelationshipGroupId); verify(groupVisitor).visit(nodeId, typeId, -1L, -1L, relationshipId); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPut6ByteRelationshipIds() public virtual void ShouldPut6ByteRelationshipIds() { // GIVEN _cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 1, 100, Base); long sparseNode = 0; long denseNode = 1; long relationshipId = (1L << 48) - 2; int typeId = 10; _cache.NodeCount = 2; _cache.incrementCount(denseNode); // WHEN assertEquals(-1L, _cache.getAndPutRelationship(sparseNode, typeId, OUTGOING, relationshipId, false)); assertEquals(-1L, _cache.getAndPutRelationship(denseNode, typeId, OUTGOING, relationshipId, false)); // THEN assertEquals(relationshipId, _cache.getAndPutRelationship(sparseNode, typeId, OUTGOING, 1, false)); assertEquals(relationshipId, _cache.getAndPutRelationship(denseNode, typeId, OUTGOING, 1, false)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFailFastIfTooBigRelationshipId() public virtual void ShouldFailFastIfTooBigRelationshipId() { // GIVEN int typeId = 10; _cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 1, 100, Base); _cache.NodeCount = 1; // WHEN _cache.getAndPutRelationship(0, typeId, OUTGOING, (1L << 48) - 2, false); try { _cache.getAndPutRelationship(0, typeId, OUTGOING, (1L << 48) - 1, false); fail("Should fail"); } catch (System.ArgumentException e) { // THEN Good assertTrue(e.Message.contains("max")); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldResetCountAfterGetOnDenseNodes() public virtual void ShouldResetCountAfterGetOnDenseNodes() { // GIVEN _cache = new NodeRelationshipCache(NumberArrayFactory_Fields.AutoWithoutPagecache, 1, 100, Base); long nodeId = 0; int typeId = 3; _cache.NodeCount = 1; _cache.incrementCount(nodeId); _cache.incrementCount(nodeId); _cache.getAndPutRelationship(nodeId, typeId, OUTGOING, 10, true); _cache.getAndPutRelationship(nodeId, typeId, OUTGOING, 12, true); assertTrue(_cache.isDense(nodeId)); // WHEN long count = _cache.getCount(nodeId, typeId, OUTGOING); assertEquals(2, count); // THEN assertEquals(0, _cache.getCount(nodeId, typeId, OUTGOING)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldVisitChangedNodes() public virtual void ShouldVisitChangedNodes() { // GIVEN int nodes = 10; int typeId = 10; _cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 2, 100, Base); _cache.NodeCount = nodes; for (long nodeId = 0; nodeId < nodes; nodeId++) { _cache.incrementCount(nodeId); if (Random.nextBoolean()) { _cache.incrementCount(nodeId); } } MutableLongSet keySparseChanged = new LongHashSet(); MutableLongSet keyDenseChanged = new LongHashSet(); for (int i = 0; i < nodes / 2; i++) { long nodeId = Random.nextLong(nodes); _cache.getAndPutRelationship(nodeId, typeId, Direction.OUTGOING, Random.nextLong(1_000_000), false); bool dense = _cache.isDense(nodeId); (dense ? keyDenseChanged : keySparseChanged).add(nodeId); } { // WHEN (sparse) NodeChangeVisitor visitor = (nodeId, array) => { // THEN (sparse) assertTrue("Unexpected sparse change reported for " + nodeId, keySparseChanged.remove(nodeId)); }; _cache.visitChangedNodes(visitor, NodeType.NODE_TYPE_SPARSE); assertTrue("There was " + keySparseChanged.size() + " expected sparse changes that weren't reported", keySparseChanged.Empty); } { // WHEN (dense) NodeChangeVisitor visitor = (nodeId, array) => { // THEN (dense) assertTrue("Unexpected dense change reported for " + nodeId, keyDenseChanged.remove(nodeId)); }; _cache.visitChangedNodes(visitor, NodeType.NODE_TYPE_DENSE); assertTrue("There was " + keyDenseChanged.size() + " expected dense changes that weren reported", keyDenseChanged.Empty); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldGetAndPutRelationshipAroundChunkEdge() public virtual void ShouldGetAndPutRelationshipAroundChunkEdge() { // GIVEN _cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 10); // WHEN long nodeId = 1_000_000 - 1; int typeId = 10; _cache.NodeCount = nodeId + 1; Direction direction = Direction.OUTGOING; long relId = 10; _cache.getAndPutRelationship(nodeId, typeId, direction, relId, false); // THEN assertEquals(relId, _cache.getFirstRel(nodeId, mock(typeof(GroupVisitor)))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCacheMultipleDenseNodeRelationshipHeads() public virtual void ShouldCacheMultipleDenseNodeRelationshipHeads() { // GIVEN _cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 1); _cache.NodeCount = 10; long nodeId = 3; _cache.setCount(nodeId, 10, 0, OUTGOING); // WHEN IDictionary <Pair <int, Direction>, long> firstRelationshipIds = new Dictionary <Pair <int, Direction>, long>(); int typeCount = 3; for (int typeId = 0, relationshipId = 0; typeId < typeCount; typeId++) { foreach (Direction direction in Direction.values()) { long firstRelationshipId = relationshipId++; _cache.getAndPutRelationship(nodeId, typeId, direction, firstRelationshipId, true); firstRelationshipIds[Pair.of(typeId, direction)] = firstRelationshipId; } } AtomicInteger visitCount = new AtomicInteger(); GroupVisitor visitor = (nodeId1, typeId, @out, @in, loop) => { visitCount.incrementAndGet(); assertEquals(firstRelationshipIds[Pair.of(typeId, OUTGOING)], @out); assertEquals(firstRelationshipIds[Pair.of(typeId, INCOMING)], @in); assertEquals(firstRelationshipIds[Pair.of(typeId, BOTH)], loop); return(0); }; _cache.getFirstRel(nodeId, visitor); // THEN assertEquals(typeCount, visitCount.get()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPutRandomStuff() public virtual void ShouldPutRandomStuff() { // GIVEN int typeId = 10; int nodes = 10_000; MutableLongObjectMap <long[]> key = new LongObjectHashMap <long[]>(nodes); _cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 1, 1000, Base); // mark random nodes as dense (dense node threshold is 1 so enough with one increment _cache.NodeCount = nodes; for (long nodeId = 0; nodeId < nodes; nodeId++) { if (Random.nextBoolean()) { _cache.incrementCount(nodeId); } } // WHEN for (int i = 0; i < 100_000; i++) { long nodeId = Random.nextLong(nodes); bool dense = _cache.isDense(nodeId); Direction direction = Random.among(Direction.values()); long relationshipId = Random.nextLong(1_000_000); long previousHead = _cache.getAndPutRelationship(nodeId, typeId, direction, relationshipId, false); long[] keyIds = key.get(nodeId); int keyIndex = dense ? direction.ordinal() : 0; if (keyIds == null) { key.put(nodeId, keyIds = MinusOneLongs(Direction.values().length)); } assertEquals(keyIds[keyIndex], previousHead); keyIds[keyIndex] = relationshipId; } }