예제 #1
0
        private IList <IndexEntryUpdate <SchemaDescriptorSupplier> > GenerateSomeUpdates(int count)
        {
            IList <IndexEntryUpdate <SchemaDescriptorSupplier> > updates = new List <IndexEntryUpdate <SchemaDescriptorSupplier> >();

            for (int i = 0; i < count; i++)
            {
                long entityId = Random.nextLong(10_000_000);
                switch (Random.among(UpdateMode.MODES))
                {
                case ADDED:
                    updates.Add(IndexEntryUpdate.add(entityId, _descriptor, Random.nextValue()));
                    break;

                case REMOVED:
                    updates.Add(IndexEntryUpdate.remove(entityId, _descriptor, Random.nextValue()));
                    break;

                case CHANGED:
                    updates.Add(IndexEntryUpdate.change(entityId, _descriptor, Random.nextValue(), Random.nextValue()));
                    break;

                default:
                    throw new System.ArgumentException();
                }
            }
            return(updates);
        }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSplitUpRelationshipTypesInBatches()
        public virtual void ShouldSplitUpRelationshipTypesInBatches()
        {
            // GIVEN
            int denseNodeThreshold      = 5;
            int numberOfNodes           = 100;
            int numberOfTypes           = 10;
            NodeRelationshipCache cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, denseNodeThreshold);

            cache.NodeCount = numberOfNodes + 1;
            Direction[] directions = Direction.values();
            for (int i = 0; i < numberOfNodes; i++)
            {
                int count = Random.Next(1, denseNodeThreshold * 2);
                cache.setCount(i, count, Random.Next(numberOfTypes), Random.among(directions));
            }
            cache.CountingCompleted();
            IList <RelationshipTypeCount> types = new List <RelationshipTypeCount>();
            int numberOfRelationships           = 0;

            for (int i = 0; i < numberOfTypes; i++)
            {
                int count = Random.Next(1, 100);
                types.Add(new RelationshipTypeCount(i, count));
                numberOfRelationships += count;
            }
            types.sort((t1, t2) => Long.compare(t2.Count, t1.Count));
            DataStatistics typeDistribution = new DataStatistics(0, 0, types.ToArray());

            {
                // WHEN enough memory for all types
                long memory   = cache.CalculateMaxMemoryUsage(numberOfRelationships) * numberOfTypes;
                int  upToType = ImportLogic.NextSetOfTypesThatFitInMemory(typeDistribution, 0, memory, cache.NumberOfDenseNodes);

                // THEN
                assertEquals(types.Count, upToType);
            }

            {
                // and WHEN less than enough memory for all types
                long memory           = cache.CalculateMaxMemoryUsage(numberOfRelationships) * numberOfTypes / 3;
                int  startingFromType = 0;
                int  rounds           = 0;
                while (startingFromType < types.Count)
                {
                    rounds++;
                    startingFromType = ImportLogic.NextSetOfTypesThatFitInMemory(typeDistribution, startingFromType, memory, cache.NumberOfDenseNodes);
                }
                assertEquals(types.Count, startingFromType);
                assertThat(rounds, greaterThan(1));
            }
        }
예제 #3
0
        private long[] RandomNodes(Ids[] ids)
        {
            long[] nodeIds = new long[ids.Length];
            int    cursor  = 0;

            foreach (Ids id in ids)
            {
                if (random.nextBoolean())
                {
                    nodeIds[cursor++] = id.Node.Id;
                }
            }

            // If none was selected, then pick just one
            if (cursor == 0)
            {
                nodeIds[cursor++] = random.among(ids).node.Id;
            }
            return(Arrays.copyOf(nodeIds, cursor));
        }
예제 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void allEntriesReaderMustCombineResultFromAllAccessors()
        public virtual void AllEntriesReaderMustCombineResultFromAllAccessors()
        {
            // given
            IList <long>[] parts = new System.Collections.IList[_aliveAccessors.Length];
            for (int i = 0; i < parts.Length; i++)
            {
                parts[i] = new List <long>();
            }
            for (long i = 0; i < 10; i++)
            {
                Random.among(parts).Add(i);
            }
            MockAllEntriesReaders(parts);

            // when
            ISet <long> result = Iterables.asSet(_fusionIndexAccessor.newAllEntriesReader());

            // then
            foreach (IList <long> part in parts)
            {
                AssertResultContainsAll(result, part);
            }
        }
예제 #5
0
//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;
            }
        }
예제 #6
0
 internal virtual string RandomToken()
 {
     return(RandomConflict.among(Tokens));
 }