Exemple #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleGroupCountBeyondSignedShortRange()
        public virtual void ShouldHandleGroupCountBeyondSignedShortRange()
        {
            // GIVEN
            long nodeId = 0;
            int  limit  = short.MaxValue + 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.OwningNode = nodeId;
            for (int type = 0; type < limit; type++)
            {
                group.Id       = type;
                group.FirstOut = type;                         // just some relationship
                group.Type     = 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));
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSortOutOfOrderTypes()
        public virtual void ShouldSortOutOfOrderTypes()
        {
            // GIVEN
            int nodeCount = 100;
            RelationshipGroupCache cache = new RelationshipGroupCache(HEAP, ByteUnit.kibiBytes(40), nodeCount);

            int[] counts     = new int[nodeCount];
            int   groupCount = 0;

            for (int nodeId = 0; nodeId < Counts.Length; nodeId++)
            {
                counts[nodeId] = Random.Next(10);
                SetCount(cache, nodeId, counts[nodeId]);
                groupCount += counts[nodeId];
            }
            assertEquals(nodeCount, cache.Prepare(0));
            bool thereAreMoreGroups = true;
            int  cachedCount        = 0;

            int[] types = ScrambledTypes(10);
            for (int i = 0; thereAreMoreGroups; i++)
            {
                int typeId = types[i];
                thereAreMoreGroups = false;
                for (int nodeId = 0; nodeId < nodeCount; nodeId++)
                {
                    if (counts[nodeId] > 0)
                    {
                        thereAreMoreGroups = true;
                        if (cache.Put((new RelationshipGroupRecord(nodeId)).initialize(true, typeId, -1, -1, -1, nodeId, -1)))
                        {
                            cachedCount++;
                            counts[nodeId]--;
                        }
                    }
                }
            }
            assertEquals(groupCount, cachedCount);

            // WHEN/THEN
            long currentNodeId = -1;
            int  currentTypeId = -1;
            int  readCount     = 0;

            foreach (RelationshipGroupRecord group in cache)
            {
                assertTrue(group.OwningNode >= currentNodeId);
                if (group.OwningNode > currentNodeId)
                {
                    currentNodeId = group.OwningNode;
                    currentTypeId = -1;
                }
                assertTrue(group.Type > currentTypeId);
                readCount++;
            }
            assertEquals(cachedCount, readCount);
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotFindSpaceToPutMoreGroupsThanSpecifiedForANode()
        public virtual 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 (System.InvalidOperationException)
            {               // Good
            }
        }
Exemple #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPutGroupsOnlyWithinPreparedRange()
        public virtual void ShouldPutGroupsOnlyWithinPreparedRange()
        {
            // GIVEN
            int nodeCount = 1000;
            RelationshipGroupCache cache = new RelationshipGroupCache(HEAP, ByteUnit.kibiBytes(4), nodeCount);

            int[] counts = new int[nodeCount];
            for (int nodeId = 0; nodeId < Counts.Length; nodeId++)
            {
                counts[nodeId] = Random.Next(10);
                SetCount(cache, nodeId, counts[nodeId]);
            }

            long toNodeId = cache.Prepare(0);

            assertTrue(toNodeId < nodeCount);

            // WHEN
            bool thereAreMoreGroups = true;
            int  cachedCount        = 0;

            while (thereAreMoreGroups)
            {
                thereAreMoreGroups = false;
                for (int nodeId = 0; nodeId < nodeCount; nodeId++)
                {
                    if (counts[nodeId] > 0)
                    {
                        thereAreMoreGroups = true;
                        int typeId = counts[nodeId]--;
                        if (cache.Put((new RelationshipGroupRecord(nodeId)).initialize(true, typeId, -1, -1, -1, nodeId, -1)))
                        {
                            cachedCount++;
                        }
                    }
                }
            }
            assertTrue(cachedCount >= toNodeId);

            // THEN the relationship groups we get back are only for those we prepared for
            int readCount = 0;

            foreach (RelationshipGroupRecord cachedGroup in cache)
            {
                assertTrue(cachedGroup.OwningNode >= 0 && cachedGroup.OwningNode < toNodeId);
                readCount++;
            }
            assertEquals(cachedCount, readCount);
        }