Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustCombineSamples()
        public virtual void MustCombineSamples()
        {
            // given
            int sumIndexSize    = 0;
            int sumUniqueValues = 0;
            int sumSampleSize   = 0;

            IndexSample[] samples = new IndexSample[_providers.Count];
            for (int i = 0; i < samples.Length; i++)
            {
                int indexSize    = Random.Next(0, 1_000_000);
                int uniqueValues = Random.Next(0, 1_000_000);
                int sampleSize   = Random.Next(0, 1_000_000);
                samples[i]       = new IndexSample(indexSize, uniqueValues, sampleSize);
                sumIndexSize    += indexSize;
                sumUniqueValues += uniqueValues;
                sumSampleSize   += sampleSize;
            }

            // when
            IndexSample fusionSample = FusionIndexSampler.CombineSamples(Arrays.asList(samples));

            // then
            assertEquals(sumIndexSize, fusionSample.IndexSize());
            assertEquals(sumUniqueValues, fusionSample.UniqueValues());
            assertEquals(sumSampleSize, fusionSample.SampleSize());
        }
Example #2
0
        private Node CreateNewNode(Label[] labels)
        {
            Node node = Db.createNode(labels);

            node.SetProperty(PROPERTY_KEY, Random.Next());
            return(node);
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSearchAndFindOnRandomData()
        internal virtual void ShouldSearchAndFindOnRandomData()
        {
            // GIVEN a leaf node with random, although sorted (as of course it must be to binary-search), data
            _node.initializeLeaf(_cursor, STABLE_GENERATION, UNSTABLE_GENERATION);
            IList <MutableLong> keys = new List <MutableLong>();
            int         currentKey   = _random.Next(10_000);
            MutableLong key          = _layout.newKey();

            int keyCount = 0;

            while (true)
            {
                MutableLong expectedKey = _layout.newKey();
                key.Value = currentKey;
                if (_node.leafOverflow(_cursor, keyCount, key, _dummyValue) != NO)
                {
                    break;
                }
                _layout.copyKey(key, expectedKey);
                keys.Insert(keyCount, expectedKey);
                _node.insertKeyValueAt(_cursor, key, _dummyValue, keyCount, keyCount);
                currentKey += _random.Next(100) + 10;
                keyCount++;
            }
            TreeNode.SetKeyCount(_cursor, keyCount);

            // WHEN searching for random keys within that general range
            MutableLong searchKey = _layout.newKey();

            for (int i = 0; i < 1_000; i++)
            {
                searchKey.Value = _random.Next(currentKey + 10);
                int searchResult = search(_cursor, _node, LEAF, searchKey, _readKey, keyCount);

                // THEN position should be as expected
                bool exists   = contains(keys, searchKey, _layout);
                int  position = KeySearch.PositionOf(searchResult);
                assertEquals(exists, KeySearch.IsHit(searchResult));
                if (_layout.Compare(searchKey, keys[0]) <= 0)
                {                         // Our search key was lower than any of our keys, expect 0
                    assertEquals(0, position);
                }
                else
                {                         // step backwards through our expected keys and see where it should fit, assert that fact
                    bool found = false;
                    for (int j = keyCount - 1; j >= 0; j--)
                    {
                        if (_layout.Compare(searchKey, keys[j]) > 0)
                        {
                            assertEquals(j + 1, position);
                            found = true;
                            break;
                        }
                    }

                    assertTrue(found);
                }
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void randomizedTest()
        internal virtual void RandomizedTest()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int count = 10000 + rnd.nextInt(1000);
            int count = 10000 + _rnd.Next(1000);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.map.primitive.MutableLongLongMap m = new org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap();
            MutableLongLongMap m = new LongLongHashMap();

            while (m.size() < count)
            {
                m.put(_rnd.nextLong(), _rnd.nextLong());
            }

            m.forEachKeyValue((k, v) =>
            {
                assertFalse(_map.containsKey(k));
                _map.put(k, v);
                assertTrue(_map.containsKey(k));
                assertEquals(v, _map.get(k));
                assertEquals(v, _map.getOrThrow(k));
                assertEquals(v, _map.getIfAbsent(k, v * 2));
                assertEquals(v, _map.getIfAbsentPut(k, v * 2));
                assertEquals(v, _map.getIfAbsentPut(k, () => v * 2));
            });

            assertEquals(m.size(), _map.size());
            assertTrue(m.Keys.allSatisfy(_map.containsKey));

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<org.eclipse.collections.api.tuple.primitive.LongLongPair> toRemove = m.keyValuesView().select(p -> rnd.nextInt(100) < 75).toList().shuffleThis(rnd.random());
            IList <LongLongPair> toRemove = m.keyValuesView().select(p => _rnd.Next(100) < 75).toList().shuffleThis(_rnd.random());

            toRemove.ForEach(p =>
            {
                long k = p.One;
                long v = p.Two;

                _map.updateValue(k, v + 1, x => - x);
                assertEquals(-v, _map.get(k));

                _map.remove(k);
                assertEquals(v * 2, _map.removeKeyIfAbsent(k, v * 2));
                assertEquals(v * 2, _map.getIfAbsent(k, v * 2));
                assertFalse(_map.containsKey(k));
                assertThrows(typeof(System.InvalidOperationException), () => _map.getOrThrow(k));

                _map.updateValue(k, v + 42, x => - x);
                assertEquals(-v - 42, _map.get(k));
            });

            toRemove.ForEach(p => _map.removeKey(p.One));

            assertEquals(count - toRemove.Count, _map.size());
        }
Example #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldWriteAndReadSmallToSemiLargeEntries() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldWriteAndReadSmallToSemiLargeEntries()
        {
            int keyValueSizeCap = keyValueSizeCapFromPageSize(PAGE_SIZE);
            int minValueSize    = 0;
            int maxValueSize    = Random.Next(200);
            int minKeySize      = 4;
            int maxKeySize      = keyValueSizeCap / 5;

            ShouldWriteAndReadEntriesOfRandomSizes(minKeySize, maxKeySize, minValueSize, maxValueSize);
        }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleRemoveEntireTree() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleRemoveEntireTree()
        {
            // given
            using (GBPTree <KEY, VALUE> index = CreateIndex())
            {
                int numberOfNodes = 200_000;
                using (Writer <KEY, VALUE> writer = CreateWriter(index))
                {
                    for (int i = 0; i < numberOfNodes; i++)
                    {
                        writer.Put(Key(i), Value(i));
                    }
                }

                // when
                BitArray removed = new BitArray();
                using (Writer <KEY, VALUE> writer = CreateWriter(index))
                {
                    for (int i = 0; i < numberOfNodes - numberOfNodes / 10; i++)
                    {
                        int candidate;
                        do
                        {
                            candidate = Random.Next(max(1, Random.Next(numberOfNodes)));
                        } while (removed.Get(candidate));
                        removed.Set(candidate, true);

                        writer.Remove(Key(candidate));
                    }
                }

                int next = 0;
                using (Writer <KEY, VALUE> writer = CreateWriter(index))
                {
                    for (int i = 0; i < numberOfNodes / 10; i++)
                    {
                        next = removed.nextClearBit(next);
                        removed.Set(next, true);
                        writer.Remove(Key(next));
                    }
                }

                // then
                using (RawCursor <Hit <KEY, VALUE>, IOException> seek = index.Seek(Key(0), Key(numberOfNodes)))
                {
                    assertFalse(seek.Next());
                }

                // and finally
                index.ConsistencyCheck();
            }
        }
Example #7
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));
            }
        }
Example #8
0
        private IList <InputEntity> RandomRelationshipData(IList <InputEntity> nodeData)
        {
            IList <InputEntity> relationships = new List <InputEntity>();

            for (int i = 0; i < 1000; i++)
            {
                InputEntity relationship = new InputEntity();
                relationship.StartId(nodeData[Random.Next(nodeData.Count)].id(), [email protected]_Fields.Global);
                relationship.EndId(nodeData[Random.Next(nodeData.Count)].id(), [email protected]_Fields.Global);
                relationship.Type("TYPE_" + Random.Next(3));
                relationships.Add(relationship);
            }
            return(relationships);
        }
Example #9
0
        /// <summary>
        /// This test verify that the documented formula for calculating size limit for string array
        /// actually calculate correctly.
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testDocumentedStringArrayKeySizeFormulaIsCorrect()
        internal virtual void TestDocumentedStringArrayKeySizeFormulaIsCorrect()
        {
            CompositeGenericKey key = new CompositeGenericKey(1, mock(typeof(IndexSpecificSpaceFillingCurveSettingsCache)));
            int maxArrayLength      = Random.Next(500);
            int maxStringLength     = Random.Next(100);

            for (int i = 0; i < 100; i++)
            {
                string[] strings = Random.randomValues().nextStringArrayRaw(0, maxArrayLength, 0, maxStringLength);
                key.initialize(i);
                key.WriteValue(0, Values.of(strings), NativeIndexKey.Inclusion.Neutral);
                assertThat(IncludingEntityId(CalculateKeySize(strings)), equalTo(key.Size()));
            }
        }
        private void RemoveExistingNode(IList <Pair <long, Label[]> > nodesInStore)
        {
            Node node;

            Label[] labels;
            do
            {
                int targetIndex = Random.Next(nodesInStore.Count);
                Pair <long, Label[]> existingNode = nodesInStore[targetIndex];
                node   = Db.getNodeById(existingNode.First());
                labels = existingNode.Other();
            } while (labels.Length == 0);
            node.Delete();
        }
Example #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @TestFactory Stream<org.junit.jupiter.api.DynamicTest> shouldGetAndSetRandomItems()
        internal virtual Stream <DynamicTest> ShouldGetAndSetRandomItems()
        {
            ThrowingConsumer <NumberArrayTestData> throwingConsumer = data =>
            {
                using (NumberArray array = data.array)
                {
                    IDictionary <int, object> key = new Dictionary <int, object>();
                    Reader reader       = data.reader;
                    object defaultValue = reader.read(array, 0);

                    // WHEN setting random items
                    for (int i = 0; i < INDEXES * 2; i++)
                    {
                        int    index = _random.Next(INDEXES);
                        object value = data.valueGenerator.apply(_random);
                        data.writer.write(i % 2 == 0 ? array : array.at(index), index, value);
                        key.put(index, value);
                    }

                    // THEN they should be read correctly
                    AssertAllValues(key, defaultValue, reader, array);

                    // AND WHEN swapping some
                    for (int i = 0; i < INDEXES / 2; i++)
                    {
                        int fromIndex = _random.Next(INDEXES);
                        int toIndex;
                        do
                        {
                            toIndex = _random.Next(INDEXES);
                        } while (toIndex == fromIndex);
                        object fromValue = reader.read(array, fromIndex);
                        object toValue   = reader.read(array, toIndex);
                        key.put(fromIndex, toValue);
                        key.put(toIndex, fromValue);
                        array.swap(fromIndex, toIndex);
                    }

                    // THEN they should end up in the correct places
                    AssertAllValues(key, defaultValue, reader, array);
                }
            };

            return(DynamicTest.stream(Arrays().GetEnumerator(), data => data.name, throwingConsumer));
        }
Example #12
0
        private long IncrementRandomCounts(NodeRelationshipCache link, int nodeCount, int i)
        {
            long highestSeenCount = 0;

            while (i-- > 0)
            {
                long node = Random.Next(nodeCount);
                highestSeenCount = max(highestSeenCount, link.IncrementCount(node));
            }
            return(highestSeenCount);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void randomizedTest()
        internal virtual void RandomizedTest()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int count = 10000 + rnd.nextInt(1000);
            int count = 10000 + _rnd.Next(1000);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<org.eclipse.collections.api.tuple.primitive.ObjectLongPair<org.neo4j.values.storable.Value>> valueRefPairs = new java.util.ArrayList<>();
            IList <ObjectLongPair <Value> > valueRefPairs = new List <ObjectLongPair <Value> >();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.list.MutableList<org.eclipse.collections.api.tuple.primitive.ObjectLongPair<org.neo4j.values.storable.Value>> toRemove = new org.eclipse.collections.impl.list.mutable.FastList<>();
            MutableList <ObjectLongPair <Value> > toRemove = new FastList <ObjectLongPair <Value> >();

            for (int i = 0; i < count; i++)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.values.storable.Value value = rnd.randomValues().nextValue();
                Value value = _rnd.randomValues().nextValue();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long ref = container.add(value);
                long @ref = _container.add(value);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.tuple.primitive.ObjectLongPair<org.neo4j.values.storable.Value> pair = pair(value, ref);
                ObjectLongPair <Value> pair = pair(value, @ref);
                if (_rnd.nextBoolean())
                {
                    toRemove.add(pair);
                }
                else
                {
                    valueRefPairs.Add(pair);
                }
            }

            toRemove.shuffleThis(_rnd.random());
            foreach (ObjectLongPair <Value> valueRefPair in toRemove)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.values.storable.Value removed = container.remove(valueRefPair.getTwo());
                Value removed = _container.remove(valueRefPair.Two);
                assertEquals(valueRefPair.One, removed);
                assertThrows(typeof(System.ArgumentException), () => _container.remove(valueRefPair.Two));
                assertThrows(typeof(System.ArgumentException), () => _container.get(valueRefPair.Two));
            }

            foreach (ObjectLongPair <Value> valueRefPair in valueRefPairs)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.values.storable.Value actualValue = container.get(valueRefPair.getTwo());
                Value actualValue = _container.get(valueRefPair.Two);
                assertEquals(valueRefPair.One, actualValue);
            }
        }
Example #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReportCorrectValidationErrorsOnRandomlyGeneratedValues()
		 public virtual void ShouldReportCorrectValidationErrorsOnRandomlyGeneratedValues()
		 {
			  // given
			  int slots = Random.Next( 1, 6 );
			  int maxLength = Random.Next( 15, 30 ) * slots;
			  GenericLayout layout = new GenericLayout( slots, SpatialSettings() );
			  GenericIndexKeyValidator validator = new GenericIndexKeyValidator( maxLength, layout );
			  GenericKey key = layout.NewKey();

			  int countOk = 0;
			  int countNotOk = 0;
			  for ( int i = 0; i < 100; i++ )
			  {
					// when
					Value[] tuple = GenerateValueTuple( slots );
					bool isOk;
					try
					{
						 validator.Validate( tuple );
						 isOk = true;
						 countOk++;
					}
					catch ( System.ArgumentException )
					{
						 isOk = false;
						 countNotOk++;
					}
					int actualSize = actualSize( tuple, key );
					bool manualIsOk = actualSize <= maxLength;

					// then
					if ( manualIsOk != isOk )
					{
						 fail( format( "Validator not validating %s correctly. Manual validation on actual key resulted in %b whereas validator said %b", Arrays.ToString( tuple ), manualIsOk, isOk ) );
					}
			  }
		 }
Example #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void shouldStartFromGivenId(int sparsity) throws java.io.IOException
        private void ShouldStartFromGivenId(int sparsity)
        {
            // given
            NativeLabelScanStore store = Life.add(new NativeLabelScanStore(Storage.pageCache(), DatabaseLayout.of(Storage.directory().directory()), Storage.fileSystem(), EMPTY, false, new Monitors(), immediate()));
            int      labelId           = 1;
            int      highNodeId        = 100_000;
            BitArray expected          = new BitArray(highNodeId);

            using (LabelScanWriter writer = store.NewWriter())
            {
                int updates = highNodeId / sparsity;
                for (int i = 0; i < updates; i++)
                {
                    int nodeId = Random.Next(highNodeId);
                    writer.Write(labelChanges(nodeId, EMPTY_LONG_ARRAY, new long[] { labelId }));
                    expected.Set(nodeId, true);
                }
            }

            // when
            long fromId         = Random.Next(highNodeId);
            int  nextExpectedId = expected.nextSetBit(toIntExact(fromId + 1));

            using (LabelScanReader reader = store.NewReader(), PrimitiveLongResourceIterator ids = reader.NodesWithAnyOfLabels(fromId, new int[] { labelId }))
            {
                // then
                while (nextExpectedId != -1)
                {
                    assertTrue(ids.hasNext());
                    long nextId = ids.next();
                    assertEquals(nextExpectedId, toIntExact(nextId));
                    nextExpectedId = expected.nextSetBit(nextExpectedId + 1);
                }
                assertFalse(ids.hasNext());
            }
        }
Example #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void randomizedWithSharedValuesContainer()
        internal virtual void RandomizedWithSharedValuesContainer()
        {
            const int maps = 13;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int COUNT = 10000 + rnd.nextInt(1000);
            int count = 10000 + _rnd.Next(1000);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final AppendOnlyValuesContainer valuesContainer = new AppendOnlyValuesContainer(new TestMemoryAllocator());
            AppendOnlyValuesContainer valuesContainer = new AppendOnlyValuesContainer(new TestMemoryAllocator());

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<ValuesMap> actualMaps = new java.util.ArrayList<>();
            IList <ValuesMap> actualMaps = new List <ValuesMap>();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<org.eclipse.collections.api.map.primitive.MutableLongObjectMap<org.neo4j.values.storable.Value>> expectedMaps = new java.util.ArrayList<>();
            IList <MutableLongObjectMap <Value> > expectedMaps = new List <MutableLongObjectMap <Value> >();

            for (int i = 0; i < maps; i++)
            {
                actualMaps.Add(NewMap(valuesContainer));
                expectedMaps.Add(new LongObjectHashMap <>());
            }

            for (int i = 0; i < maps; i++)
            {
                Put(count, actualMaps[i], expectedMaps[i]);
            }

            for (int i = 0; i < maps; i++)
            {
                Remove(count, actualMaps[i], expectedMaps[i]);
            }

            for (int i = 0; i < maps; i++)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.map.primitive.MutableLongObjectMap<org.neo4j.values.storable.Value> expected = expectedMaps.get(i);
                MutableLongObjectMap <Value> expected = expectedMaps[i];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ValuesMap actual = actualMaps.get(i);
                ValuesMap actual = actualMaps[i];
                expected.forEachKeyValue((k, v) => assertEquals(v, actual.Get(k)));
            }
        }
Example #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldFillRandomGaps()
        internal virtual void ShouldFillRandomGaps()
        {
            // given
            int numberOfRanges = _random.intBetween(50, 100);

            int[] ranges = new int[numberOfRanges];
            for (int rangeId = 0; rangeId < numberOfRanges; rangeId++)
            {
                ranges[rangeId] = _random.Next(1 << RANGE_SIZE);
            }
            GapFreeAllEntriesLabelScanReader reader = NewGapFreeAllEntriesLabelScanReader(ranges);

            // when
            IEnumerator <NodeLabelRange> iterator = reader.GetEnumerator();

            // then
            AssertRanges(iterator, ranges);
        }
        /// <summary>
        /// This test verify that we correctly handle unique point arrays where every point in every array belong to the same tile on the space filling curve.
        /// We verify this by asserting that we always get exactly one hit on an exact match and that the value is what we expect.
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustHandlePointArraysWithinSameTile() throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MustHandlePointArraysWithinSameTile()
        {
            // given
            // Many random points that all are close enough to each other to belong to the same tile on the space filling curve.
            int        nbrOfValues = 10000;
            PointValue origin      = Values.pointValue(WGS84, 0.0, 0.0);
            long?      derivedValueForCenterPoint = _curve.derivedValueFor(origin.Coordinate());

            double[] centerPoint      = _curve.centerPointFor(derivedValueForCenterPoint.Value);
            double   xWidthMultiplier = _curve.getTileWidth(0, _curve.MaxLevel) / 2;
            double   yWidthMultiplier = _curve.getTileWidth(1, _curve.MaxLevel) / 2;

            IList <Value> pointArrays = new List <Value>();
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.List<org.neo4j.kernel.api.index.IndexEntryUpdate<?>> updates = new java.util.ArrayList<>();
            IList <IndexEntryUpdate <object> > updates = new List <IndexEntryUpdate <object> >();

            for (int i = 0; i < nbrOfValues; i++)
            {
                int          arrayLength = _random.Next(5) + 1;
                PointValue[] pointValues = new PointValue[arrayLength];
                for (int j = 0; j < arrayLength; j++)
                {
                    double     x     = (_random.NextDouble() * 2 - 1) * xWidthMultiplier;
                    double     y     = (_random.NextDouble() * 2 - 1) * yWidthMultiplier;
                    PointValue value = Values.pointValue(WGS84, centerPoint[0] + x, centerPoint[1] + y);

                    AssertDerivedValue(derivedValueForCenterPoint, value);
                    pointValues[j] = value;
                }
                PointArray array = Values.pointArray(pointValues);
                pointArrays.Add(array);
                updates.Add(IndexEntryUpdate.add(i, _descriptor, array));
            }

            ProcessAll(updates);

            // then
            ExactMatchOnAllValues(pointArrays);
        }
Example #19
0
        /*
         * There was this issue that DynamicNodeLabels#add would consider even unused dynamic records when
         * reading existing label ids before making the change. Previously this would create a duplicate
         * last label id (the one formerly being in the second record).
         *
         * This randomized test found this issue every time when it existed and it will potentially find other
         * unforeseen issues as well.
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleRandomAddsAndRemoves()
        public virtual void ShouldHandleRandomAddsAndRemoves()
        {
            // GIVEN
            ISet <int> key  = new HashSet <int>();
            NodeRecord node = new NodeRecord(0);

            node.InUse = true;

            // WHEN
            for (int i = 0; i < 100_000; i++)
            {
                NodeLabels labels  = NodeLabelsField.parseLabelsField(node);
                int        labelId = Random.Next(200);
                if (Random.nextBoolean())
                {
                    if (!key.Contains(labelId))
                    {
                        labels.Add(labelId, _nodeStore, _nodeStore.DynamicLabelStore);
                        key.Add(labelId);
                    }
                }
                else
                {
                    if (key.remove(labelId))
                    {
                        labels.Remove(labelId, _nodeStore);
                    }
                }
            }

            // THEN
            NodeLabels labels = NodeLabelsField.parseLabelsField(node);

            long[] readLabelIds = labels.Get(_nodeStore);
            foreach (long labelId in readLabelIds)
            {
                assertTrue("Found an unexpected label " + labelId, key.remove(( int )labelId));
            }
            assertTrue(key.Count == 0);
        }
Example #20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void backupMultipleSchemaIndexes() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void BackupMultipleSchemaIndexes()
        {
            // given
            ExecutorService      executorService = Executors.newSingleThreadExecutor();
            AtomicBoolean        end             = new AtomicBoolean();
            int                  backupPort      = PortAuthority.allocatePort();
            GraphDatabaseService db = GetEmbeddedTestDataBaseService(backupPort);

            try
            {
                int           numberOfIndexedLabels = 10;
                IList <Label> indexedLabels         = CreateIndexes(db, numberOfIndexedLabels);

                // start thread that continuously writes to indexes
                executorService.submit(() =>
                {
                    while (!end.get())
                    {
                        using (Transaction tx = Db.beginTx())
                        {
                            Db.createNode(indexedLabels[_random.Next(numberOfIndexedLabels)]).setProperty("prop", _random.nextValue());
                            tx.success();
                        }
                    }
                });
                executorService.shutdown();

                // create backup
                OnlineBackup backup = OnlineBackup.From("127.0.0.1", backupPort).full(_backupDatabasePath.Path);
                assertTrue("Should be consistent", backup.Consistent);
                end.set(true);
                executorService.awaitTermination(1, TimeUnit.MINUTES);
            }
            finally
            {
                Db.shutdown();
            }
        }
Example #21
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.io.File nodeCsvFileWithBrokenEntries() throws java.io.IOException
        private File NodeCsvFileWithBrokenEntries()
        {
            File file = _directory.file("broken-node-data.csv");

            using (PrintWriter writer = new PrintWriter(_fs.openAsWriter(file, StandardCharsets.UTF_8, false)))
            {
                writer.println(":ID,name");
                int numberOfLines = BUFFER_SIZE * 10;
                int brokenLine    = _random.Next(numberOfLines);
                for (int i = 0; i < numberOfLines; i++)
                {
                    if (i == brokenLine)
                    {
                        writer.println(i + ",\"broken\"line");
                    }
                    else
                    {
                        writer.println(i + ",name" + i);
                    }
                }
            }
            return(file);
        }
Example #22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldScanAllInUseRelationshipsOfCertainType()
        public virtual void ShouldScanAllInUseRelationshipsOfCertainType()
        {
            // given
            RelationshipStore relationshipStore = _neoStores.RelationshipStore;
            int count = 100;

            relationshipStore.HighId = count;
            ISet <long> expected = new HashSet <long>();
            int         theType  = 1;

            for (long id = 0; id < count; id++)
            {
                bool inUse = Random.nextBoolean();
                int  type  = Random.Next(3);
                CreateRelationshipRecord(id, type, relationshipStore, inUse);
                if (inUse && type == theType)
                {
                    expected.Add(id);
                }
            }

            // when
            AssertSeesRelationships(expected, theType);
        }
Example #23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @BeforeEach void createLayout()
        internal virtual void CreateLayout()
        {
            this._numberOfSlots = Random.Next(1, 3);
            this._layout        = new GenericLayout(_numberOfSlots, _spatialSettings);
        }
Example #24
0
 internal virtual E Random <E>(IList <E> entities) where E : Org.Neo4j.Graphdb.PropertyContainer
 {
     return(entities.Count == 0 ? default(E) : entities[RandomConflict.Next(entities.Count)]);
 }
Example #25
0
 private int RandomRelCount()
 {
     return(RELATIONSHIPS_COUNT + Random.Next(20));
 }
Example #26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @BeforeEach void setup()
        internal virtual void Setup()
        {
            _layout = SimpleLongLayout.longLayout().withFixedSize(Rnd.nextBoolean()).withKeyPadding(Rnd.Next(10)).build();
        }
Example #27
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void verifyContent(java.io.File storeFile) throws java.io.IOException
		 public override void VerifyContent( File storeFile )
		 {
			  PageCache pageCache = _pageCacheRule.getPageCache( GlobalFs.get() );
			  using ( GBPTree<MutableLong, MutableLong> tree = ( new GBPTreeBuilder<MutableLong, MutableLong>( pageCache, storeFile, Layout ) ).build() )
			  {
					{
						 // WHEN reading from the tree
						 // THEN initial keys should be there
						 tree.ConsistencyCheck();
						 using ( RawCursor<Hit<MutableLong, MutableLong>, IOException> cursor = tree.Seek( Layout.key( 0 ), Layout.key( long.MaxValue ) ) )
						 {
							  foreach ( long? expectedKey in _initialKeys )
							  {
									AssertHit( cursor, expectedKey );
							  }
							  assertFalse( cursor.Next() );
						 }
					}

					{
						 // WHEN writing more to the tree
						 // THEN we should not see any format conflicts
						 using ( Writer<MutableLong, MutableLong> writer = tree.Writer() )
						 {
							  while ( _keysToAdd.Count > 0 )
							  {
									int next = _random.Next( _keysToAdd.Count );
									Put( writer, _keysToAdd[next] );
									_keysToAdd.RemoveAt( next );
							  }
						 }
					}

					{
						 // WHEN reading from the tree again
						 // THEN all keys including newly added should be there
						 tree.ConsistencyCheck();
						 using ( RawCursor<Hit<MutableLong, MutableLong>, IOException> cursor = tree.Seek( Layout.key( 0 ), Layout.key( 2 * INITIAL_KEY_COUNT ) ) )
						 {
							  foreach ( long? expectedKey in _allKeys )
							  {
									AssertHit( cursor, expectedKey );
							  }
							  assertFalse( cursor.Next() );
						 }
					}

					{
						 // WHEN randomly removing half of tree content
						 // THEN we should not see any format conflicts
						 using ( Writer<MutableLong, MutableLong> writer = tree.Writer() )
						 {
							  int size = _allKeys.Count;
							  while ( _allKeys.Count > size / 2 )
							  {
									int next = _random.Next( _allKeys.Count );
									MutableLong key = Layout.key( _allKeys[next] );
									writer.Remove( key );
									_allKeys.RemoveAt( next );
							  }
						 }
					}

					{
						 // WHEN reading from the tree after remove
						 // THEN we should see everything that is left in the tree
						 tree.ConsistencyCheck();
						 using ( RawCursor<Hit<MutableLong, MutableLong>, IOException> cursor = tree.Seek( Layout.key( 0 ), Layout.key( 2 * INITIAL_KEY_COUNT ) ) )
						 {
							  foreach ( long? expectedKey in _allKeys )
							  {
									AssertHit( cursor, expectedKey );
							  }
							  assertFalse( cursor.Next() );
						 }
					}
			  }
		 }
Example #28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldInsertAndRemoveRandomKeysAndValues()
        internal virtual void ShouldInsertAndRemoveRandomKeysAndValues()
        {
            // This test doesn't care about sorting, that's an aspect that lies outside of TreeNode, really

            // GIVEN
            _node.initializeLeaf(Cursor, STABLE_GENERATION, UNSTABLE_GENERATION);
            // add +1 to these to simplify some array logic in the test itself
            IList <KEY>   expectedKeys     = new List <KEY>();
            IList <VALUE> expectedValues   = new List <VALUE>();
            int           expectedKeyCount = 0;
            KEY           readKey          = _layout.newKey();
            VALUE         readValue        = _layout.newValue();

            // WHEN/THEN
            for (int i = 0; i < 1000; i++)
            {
                if (_random.nextFloat() < 0.7)
                {                         // 70% insert
                    KEY newKey;
                    do
                    {
                        newKey = Key(_random.nextLong());
                    } while (contains(expectedKeys, newKey, _layout));
                    VALUE newValue = Value(_random.nextLong());

                    Overflow overflow = _node.leafOverflow(Cursor, expectedKeyCount, newKey, newValue);
                    if (overflow == NO_NEED_DEFRAG)
                    {
                        _node.defragmentLeaf(Cursor);
                    }
                    if (overflow != YES)
                    {                              // there's room
                        int position = expectedKeyCount == 0 ? 0 : _random.Next(expectedKeyCount);
                        // ensure unique
                        _node.insertKeyValueAt(Cursor, newKey, newValue, position, expectedKeyCount);
                        expectedKeys.Insert(position, newKey);
                        expectedValues.Insert(position, newValue);

                        TreeNode.SetKeyCount(Cursor, ++expectedKeyCount);
                    }
                }
                else
                {                         // 30% remove
                    if (expectedKeyCount > 0)
                    {                     // there are things to remove
                        int position = _random.Next(expectedKeyCount);
                        _node.keyAt(Cursor, readKey, position, LEAF);
                        _node.valueAt(Cursor, readValue, position);
                        _node.removeKeyValueAt(Cursor, position, expectedKeyCount);
                        KEY   expectedKey   = expectedKeys.RemoveAt(position);
                        VALUE expectedValue = expectedValues.RemoveAt(position);
//JAVA TO C# CONVERTER TODO TASK: The following line has a Java format specifier which cannot be directly translated to .NET:
//ORIGINAL LINE: assertEquals(0, layout.compare(expectedKey, readKey), String.format("Key differ with expected%n    readKey=%s %nexpectedKey=%s%n", readKey, expectedKey));
                        assertEquals(0, _layout.Compare(expectedKey, readKey), string.Format("Key differ with expected%n    readKey=%s %nexpectedKey=%s%n", readKey, expectedKey));
                        assertEquals(0, _layout.compareValue(expectedValue, readValue), "Value differ with expected, value=" + readValue + ", expectedValue=" + expectedValue);

                        TreeNode.SetKeyCount(Cursor, --expectedKeyCount);
                    }
                }
            }

            // THEN
            AssertContent(expectedKeys, expectedValues, expectedKeyCount);
        }
Example #29
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void before()
        public virtual void Before()
        {
            PageCache pageCache = _pageCacheRule.getPageCache(_fileSystem);

            _store = _life.add(new NativeLabelScanStore(pageCache, _directory.databaseLayout(), _fileSystem, Org.Neo4j.Kernel.Impl.Api.scan.FullStoreChangeStream_Fields.Empty, false, new Monitors(), RecoveryCleanupWorkCollector.immediate(), Math.Min(pageCache.PageSize(), 256 << _random.Next(5))));
        }
Example #30
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void doShouldRecoverFromAnything(boolean replayRecoveryExactlyFromCheckpoint) throws Exception
        private void DoShouldRecoverFromAnything(bool replayRecoveryExactlyFromCheckpoint)
        {
            AssertInitialized();
            // GIVEN
            // a tree which has had random updates and checkpoints in it, load generated with specific seed
            File           file                = _directory.file("index");
            IList <Action> load                = GenerateLoad();
            IList <Action> shuffledLoad        = RandomCausalAwareShuffle(load);
            int            lastCheckPointIndex = IndexOfLastCheckpoint(load);

            {
                // _,_,_,_,_,_,_,c,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,c,_,_,_,_,_,_,_,_,_,_,_
                //                                                 ^             ^
                //                                                 |             |------------ crash flush index
                //                                                 |-------------------------- last checkpoint index
                //

                PageCache            pageCache = CreatePageCache();
                GBPTree <KEY, VALUE> index     = CreateIndex(pageCache, file);
                // Execute all actions up to and including last checkpoint ...
                Execute(shuffledLoad.subList(0, lastCheckPointIndex + 1), index);
                // ... a random amount of the remaining "unsafe" actions ...
                int numberOfRemainingActions = shuffledLoad.Count - lastCheckPointIndex - 1;
                int crashFlushIndex          = lastCheckPointIndex + _random.Next(numberOfRemainingActions) + 1;
                Execute(shuffledLoad.subList(lastCheckPointIndex + 1, crashFlushIndex), index);
                // ... flush ...
                pageCache.FlushAndForce();
                // ... execute the remaining actions
                Execute(shuffledLoad.subList(crashFlushIndex, shuffledLoad.Count), index);
                // ... and finally crash
                _fs.snapshot(throwing(() =>
                {
                    index.Dispose();
                    pageCache.Close();
                }));
            }

            // WHEN doing recovery
            IList <Action> recoveryActions;

            if (replayRecoveryExactlyFromCheckpoint)
            {
                recoveryActions = recoveryActions(load, lastCheckPointIndex + 1);
            }
            else
            {
                recoveryActions = recoveryActions(load, _random.Next(lastCheckPointIndex + 1));
            }

            // first crashing during recovery
            int numberOfCrashesDuringRecovery = _random.intBetween(0, 3);

            for (int i = 0; i < numberOfCrashesDuringRecovery; i++)
            {
                using (PageCache pageCache = CreatePageCache(), GBPTree <KEY, VALUE> index = CreateIndex(pageCache, file))
                {
                    int numberOfActionsToRecoverBeforeCrashing = _random.intBetween(1, recoveryActions.Count);
                    Recover(recoveryActions.subList(0, numberOfActionsToRecoverBeforeCrashing), index);
                    // ... crash
                }
            }

            // to finally apply all actions after last checkpoint and verify tree
            using (PageCache pageCache = CreatePageCache(), GBPTree <KEY, VALUE> index = CreateIndex(pageCache, file))
            {
                Recover(recoveryActions, index);

                // THEN
                // we should end up with a consistent index containing all the stuff load says
                index.ConsistencyCheck();
                long[] aggregate = ExpectedSortedAggregatedDataFromGeneratedLoad(load);
                using (RawCursor <Hit <KEY, VALUE>, IOException> cursor = index.Seek(Key(long.MinValue), Key(long.MaxValue)))
                {
                    for (int i = 0; i < aggregate.Length;)
                    {
                        assertTrue(cursor.Next());
                        Hit <KEY, VALUE> hit = cursor.get();
                        AssertEqualsKey(Key(aggregate[i++]), hit.Key());
                        AssertEqualsValue(Value(aggregate[i++]), hit.Value());
                    }
                    assertFalse(cursor.Next());
                }
            }
        }