Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustSelectSpatialForExactPredicateWithSpatialValue() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MustSelectSpatialForExactPredicateWithSpatialValue()
        {
            // given
            assumeTrue(HasSpatialSupport());
            foreach (object value in FusionIndexTestHelp.ValuesSupportedBySpatial())
            {
                IndexQuery indexQuery = IndexQuery.exact(PROP_KEY, value);

                // then
                VerifyQueryWithCorrectReader(_readers[SPATIAL], indexQuery);
            }
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustSelectTemporalForExactPredicateWithTemporalValue() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MustSelectTemporalForExactPredicateWithTemporalValue()
        {
            // given
            assumeTrue(HasTemporalSupport());
            foreach (object temporalValue in FusionIndexTestHelp.ValuesSupportedByTemporal())
            {
                IndexQuery indexQuery = IndexQuery.exact(PROP_KEY, temporalValue);

                // then
                VerifyQueryWithCorrectReader(_readers[TEMPORAL], indexQuery);
            }
        }
Example #3
0
 private void AssertMatch(BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator, Value value, long id)
 {
     using (NativeIndexReader <GenericKey, NativeIndexValue> reader = populator.newReader())
     {
         SimpleNodeValueClient cursor = new SimpleNodeValueClient();
         reader.Query(cursor, IndexOrder.NONE, true, IndexQuery.exact(_indexDescriptor.properties()[0], value));
         assertTrue(cursor.Next());
         assertEquals(id, cursor.Reference);
         assertEquals(value, cursor.Values[0]);
         assertFalse(cursor.Next());
     }
 }
Example #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void seekOverAllPartitions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SeekOverAllPartitions()
        {
            PartitionedIndexReader indexReader = CreatePartitionedReaderFromReaders();

            IndexQuery.ExactPredicate query = IndexQuery.exact(1, "Test");
            when(_indexReader1.query(query)).thenReturn(PrimitiveLongResourceCollections.iterator(null, 1));
            when(_indexReader2.query(query)).thenReturn(PrimitiveLongResourceCollections.iterator(null, 2));
            when(_indexReader3.query(query)).thenReturn(PrimitiveLongResourceCollections.iterator(null, 3));

            LongSet results = PrimitiveLongCollections.asSet(indexReader.Query(query));

            VerifyResult(results);
        }
Example #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertIndexData(org.neo4j.internal.kernel.api.Transaction transaction, int[] propertyKeyIds, org.neo4j.values.storable.TextValue value, long node, org.neo4j.internal.kernel.api.IndexReference index) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private void AssertIndexData(Transaction transaction, int[] propertyKeyIds, TextValue value, long node, IndexReference index)
        {
            using (NodeValueIndexCursor indexCursor = transaction.Cursors().allocateNodeValueIndexCursor())
            {
                IndexQuery[] query = new IndexQuery[propertyKeyIds.Length];
                for (int i = 0; i < propertyKeyIds.Length; i++)
                {
                    query[i] = IndexQuery.exact(propertyKeyIds[i], value);
                }
                transaction.DataRead().nodeIndexSeek(index, indexCursor, IndexOrder.NONE, false, query);
                assertTrue(indexCursor.Next());
                assertEquals(node, indexCursor.NodeReference());
                assertFalse(indexCursor.Next());
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertHasAllValues(java.util.List<NodeAndValue> values) throws java.io.IOException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException
        private void AssertHasAllValues(IList <NodeAndValue> values)
        {
            using (IndexAccessor accessor = IndexProvider.getOnlineAccessor(Descriptor, IndexSamplingConfig))
            {
                using (IndexReader reader = new QueryResultComparingIndexReader(accessor.NewReader()))
                {
                    int propertyKeyId = Descriptor.schema().PropertyId;
                    foreach (NodeAndValue entry in values)
                    {
                        NodeValueIterator nodes = new NodeValueIterator();
                        reader.Query(nodes, IndexOrder.NONE, false, IndexQuery.exact(propertyKeyId, entry.Value));
                        assertEquals(entry.NodeId, nodes.Next());
                        assertFalse(nodes.HasNext());
                    }
                }
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void exactMatchOnAllValues(java.util.List<org.neo4j.values.storable.Value> values) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException
        private void ExactMatchOnAllValues(IList <Value> values)
        {
            using (IndexReader indexReader = _accessor.newReader())
            {
                SimpleNodeValueClient client = new SimpleNodeValueClient();
                foreach (Value value in values)
                {
                    IndexQuery.ExactPredicate exact = IndexQuery.exact(_descriptor.schema().PropertyId, value);
                    indexReader.Query(client, IndexOrder.NONE, true, exact);

                    // then
                    assertTrue(client.Next());
                    assertEquals(value, client.Values[0]);
                    assertFalse(client.Next());
                }
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyIndex(org.neo4j.kernel.impl.api.TransactionToApply tx) throws Exception
            internal virtual void VerifyIndex(TransactionToApply tx)
            {
                using (IndexReader reader = Index.newReader())
                {
                    NodeVisitor visitor = new NodeVisitor();
                    for (int i = 0; tx != null; i++)
                    {
                        tx.TransactionRepresentation().accept(visitor.Clear());

                        Value propertyValue             = propertyValue(Id, Base + i);
                        IndexQuery.ExactPredicate query = IndexQuery.exact(outerInstance.descriptor.PropertyId, propertyValue);
                        LongIterator hits = reader.Query(query);
                        assertEquals("Index doesn't contain " + visitor.NodeId + " " + propertyValue, visitor.NodeId, hits.next());
                        assertFalse(hits.hasNext());
                        tx = tx.Next();
                    }
                }
            }
Example #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldQueryAboutAddedAndChangedValueTuples() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldQueryAboutAddedAndChangedValueTuples()
        {
            // given
            IndexUpdater actual = mock(typeof(IndexUpdater));
            IndexReader  reader = mock(typeof(IndexReader));

            when(reader.Query(anyVararg())).thenAnswer(invocation => iterator(0));
            long nodeId = 0;
            IList <IndexEntryUpdate <IndexDescriptor> > updates = new List <IndexEntryUpdate <IndexDescriptor> >();

            updates.Add(add(nodeId++, _descriptor, Tuple(10, 11)));
            updates.Add(change(nodeId++, _descriptor, Tuple("abc", "def"), Tuple("ghi", "klm")));
            updates.Add(remove(nodeId++, _descriptor, Tuple(1001L, 1002L)));
            updates.Add(change(nodeId++, _descriptor, Tuple(( sbyte )2, ( sbyte )3), Tuple(( sbyte )4, ( sbyte )5)));
            updates.Add(add(nodeId++, _descriptor, Tuple(5, "5")));
            using (DeferredConflictCheckingIndexUpdater updater = new DeferredConflictCheckingIndexUpdater(actual, () => reader, _descriptor))
            {
                // when
                foreach (IndexEntryUpdate <IndexDescriptor> update in updates)
                {
                    updater.Process(update);
                    verify(actual).process(update);
                }
            }

            // then
            foreach (IndexEntryUpdate <IndexDescriptor> update in updates)
            {
                if (update.UpdateMode() == UpdateMode.ADDED || update.UpdateMode() == UpdateMode.CHANGED)
                {
                    Value[]      tuple = update.Values();
                    IndexQuery[] query = new IndexQuery[tuple.Length];
                    for (int i = 0; i < tuple.Length; i++)
                    {
                        query[i] = IndexQuery.exact(_propertyKeyIds[i], tuple[i]);
                    }
                    verify(reader).query(query);
                }
            }
            verify(reader).close();
            verifyNoMoreInteractions(reader);
        }
        private void ShouldConsultProvidedFilters(System.Func <Value[], Value[]> filterValues, bool filterAcceptsValue)
        {
            // given
            long nodeReference = 123;
            int  labelId       = 10;
            int  slots         = Random.Next(3, 8);

            IndexQuery[]             filters      = new IndexQuery[slots];
            Value[]                  actualValues = new Value[slots];
            Value[]                  values       = new Value[slots];
            IDictionary <int, Value> properties   = new Dictionary <int, Value>();

            int[] propertyKeyIds = new int[slots];
            int   filterCount    = 0;

            for (int i = 0; i < slots; i++)
            {
                actualValues[i] = Random.nextValue();
                int propertyKeyId = i;
                propertyKeyIds[i] = propertyKeyId;
                //    we want at least one filter         ,  randomly add filter or not
                if ((filterCount == 0 && i == slots - 1) || Random.nextBoolean())
                {
                    object filterValue = (filterAcceptsValue ? actualValues[i] : AnyOtherValueThan(actualValues[i])).asObjectCopy();
                    filters[i] = IndexQuery.exact(propertyKeyId, filterValue);
                    filterCount++;
                }
                values[i] = Random.nextBoolean() ? NO_VALUE : actualValues[i];
                properties[propertyKeyId] = actualValues[i];
            }
            _node.withNode(nodeReference, new long[] { labelId }, properties);

            // when
            NodeValueClientFilter filter = new NodeValueClientFilter(this, _node, _property, _read, filters);

            filter.Initialize(TestIndexDescriptorFactory.forLabel(labelId, propertyKeyIds), this, null, IndexOrder.NONE, true);
            bool accepted = filter.AcceptNode(nodeReference, filterValues(values));

            // then
            assertEquals(filterAcceptsValue, accepted);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testExactMatchOnRandomValues() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestExactMatchOnRandomValues()
        {
            // given
            ValueType[]   types  = RandomSetOfSupportedTypes();
            IList <Value> values = GenerateValuesFromType(types, new HashSet <Value>(), 30_000);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.List<IndexEntryUpdate<?>> updates = generateUpdatesFromValues(values, new org.apache.commons.lang3.mutable.MutableLong());
            IList <IndexEntryUpdate <object> > updates = GenerateUpdatesFromValues(values, new MutableLong());

            UpdateAndCommit(updates);

            // when
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (IndexEntryUpdate<?> update : updates)
            foreach (IndexEntryUpdate <object> update in updates)
            {
                // then
                IList <long> hits = Query(IndexQuery.exact(0, update.Values()[0]));
                assertEquals(hits.ToString(), 1, hits.Count);
                assertThat(single(hits), equalTo(update.EntityId));
            }
        }
        /// <summary>
        /// This test target a bug around minimal splitter in gbpTree and unique index populator. It goes like this:
        /// Given a set of updates (value,entityId):
        /// - ("A01",1), ("A90",3), ("A9",2)
        /// If ("A01",1) and ("A90",3) would cause a split to occur they would produce a minimal splitter ("A9",3).
        /// Note that the value in this minimal splitter is equal to our last update ("A9",2).
        /// When making insertions with the unique populator we don't compare entityId which would means ("A9",2)
        /// ends up to the right of ("A9",3), even though it belongs to the left because of entityId being smaller.
        /// At this point the tree is in an inconsistent (key on wrong side of splitter).
        ///
        /// To work around this problem the entityId is only kept in minimal splitter if strictly necessary to divide
        /// left from right. This means the minimal splitter between ("A01",1) and ("A90",3) is ("A9",-1) and ("A9",2)
        /// will correctly be placed on the right side of this splitter.
        ///
        /// To trigger this scenario this test first insert a bunch of values that are all unique and that will cause a
        /// split to happen. This is the firstBatch.
        /// The second batch are constructed so that at least one of them will have a value equal to the splitter key
        /// constructed during the firstBatch.
        /// It's important that the secondBatch has ids that are lower than the first batch to align with example described above.
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPopulateAndRemoveEntriesWithSimilarMinimalSplitter() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPopulateAndRemoveEntriesWithSimilarMinimalSplitter()
        {
            string prefix     = "Work out your own salvation. Do not depend on others. ";
            int    nbrOfNodes = 200;
            long   nodeId     = 0;

            // Second batch has lower ids
            IList <NodeAndValue> secondBatch = new List <NodeAndValue>();

            for (int i = 0; i < nbrOfNodes; i++)
            {
                secondBatch.Add(new NodeAndValue(nodeId++, stringValue(prefix + i)));
            }

            // First batch has higher ids and minimal splitter among values in first batch will be found among second batch
            IList <NodeAndValue> firstBatch = new List <NodeAndValue>();

            for (int i = 0; i < nbrOfNodes; i++)
            {
                firstBatch.Add(new NodeAndValue(nodeId++, stringValue(prefix + i + " " + i)));
            }

            WithPopulator(IndexProvider.getPopulator(Descriptor, IndexSamplingConfig, heapBufferFactory(1024)), p =>
            {
                p.add(Updates(firstBatch));
                p.add(Updates(secondBatch));

                // Index should be consistent
            });

            IList <NodeAndValue> toRemove = new List <NodeAndValue>();

            ((IList <NodeAndValue>)toRemove).AddRange(firstBatch);
            ((IList <NodeAndValue>)toRemove).AddRange(secondBatch);
            Collections.shuffle(toRemove);

            // And we should be able to remove the entries in any order
            using (IndexAccessor accessor = IndexProvider.getOnlineAccessor(Descriptor, IndexSamplingConfig))
            {
                // WHEN
                using (IndexUpdater updater = accessor.NewUpdater(IndexUpdateMode.ONLINE))
                {
                    foreach (NodeAndValue nodeAndValue in toRemove)
                    {
                        updater.Process(IndexEntryUpdate.Remove(nodeAndValue.NodeId, Descriptor, nodeAndValue.Value));
                    }
                }

                // THEN
                using (IndexReader reader = new QueryResultComparingIndexReader(accessor.NewReader()))
                {
                    int propertyKeyId = Descriptor.schema().PropertyId;
                    foreach (NodeAndValue nodeAndValue in toRemove)
                    {
                        NodeValueIterator nodes = new NodeValueIterator();
                        reader.Query(nodes, IndexOrder.NONE, false, IndexQuery.exact(propertyKeyId, nodeAndValue.Value));
                        bool anyHits = false;

                        StringJoiner nodesStillLeft = new StringJoiner(", ", "[", "]");
                        while (nodes.HasNext())
                        {
                            anyHits = true;
                            nodesStillLeft.add(Convert.ToString(nodes.Next()));
                        }
                        assertFalse("Expected this query to have zero hits but found " + nodesStillLeft.ToString(), anyHits);
                    }
                }
            }
        }
Example #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void concurrentIndexPopulationAndInsertsShouldNotProduceDuplicates() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ConcurrentIndexPopulationAndInsertsShouldNotProduceDuplicates()
        {
            // Given
            Config config           = Config.defaults();
            GraphDatabaseService db = NewEmbeddedGraphDatabaseWithSlowJobScheduler(config);

            try
            {
                // When
                using (Transaction tx = Db.beginTx())
                {
                    Db.schema().indexFor(label(LABEL)).on(KEY).create();
                    tx.Success();
                }
                Node node;
                using (Transaction tx = Db.beginTx())
                {
                    node = Db.createNode(label(LABEL));
                    node.SetProperty(KEY, VALUE);
                    tx.Success();
                }

                using (Transaction tx = Db.beginTx())
                {
                    Db.schema().awaitIndexesOnline(1, MINUTES);
                    tx.Success();
                }

                // Then
                using (Transaction tx = Db.beginTx())
                {
                    KernelTransaction    ktx    = (( GraphDatabaseAPI )db).DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);
                    IndexReference       index  = ktx.SchemaRead().index(ktx.TokenRead().nodeLabel(LABEL), ktx.TokenRead().propertyKey(KEY));
                    NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor();
                    ktx.DataRead().nodeIndexSeek(index, cursor, IndexOrder.NONE, false, IndexQuery.exact(1, VALUE));
                    assertTrue(cursor.Next());
                    assertEquals(node.Id, cursor.NodeReference());
                    assertFalse(cursor.Next());
                    tx.Success();
                }
            }
            finally
            {
                Db.shutdown();
            }
        }
Example #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleCompositeSizesCloseToTheLimit() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleCompositeSizesCloseToTheLimit()
        {
            // given
            CreateIndex(KEY, KEY2);

            // when a string longer than native string limit, but within lucene limit
            int    length  = 20_000;
            string string1 = Random.nextAlphaNumericString(length, length);
            string string2 = Random.nextAlphaNumericString(length, length);
            Node   node;

            using (Transaction tx = Db.beginTx())
            {
                node = Db.createNode(LABEL);
                node.SetProperty(KEY, string1);
                node.SetProperty(KEY2, string2);
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                KernelTransaction ktx = Db.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);
                int labelId           = ktx.TokenRead().nodeLabel(LABEL.Name());
                int propertyKeyId1    = ktx.TokenRead().propertyKey(KEY);
                int propertyKeyId2    = ktx.TokenRead().propertyKey(KEY2);
                using (NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor())
                {
                    ktx.DataRead().nodeIndexSeek(TestIndexDescriptorFactory.forLabel(labelId, propertyKeyId1, propertyKeyId2), cursor, IndexOrder.NONE, false, IndexQuery.exact(propertyKeyId1, string1), IndexQuery.exact(propertyKeyId2, string2));
                    assertTrue(cursor.Next());
                    assertEquals(node.Id, cursor.NodeReference());
                    assertFalse(cursor.Next());
                }
                tx.Success();
            }
        }
Example #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertIndexedNodesMatchesStoreNodes() throws Exception
        private void AssertIndexedNodesMatchesStoreNodes()
        {
            int   nodesInStore = 0;
            Label label        = Label.label(PERSON_LABEL);

            using (Transaction tx = _db.beginTx())
            {
                KernelTransaction ktx        = (( GraphDatabaseAPI )_db).DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);
                IList <string>    mismatches = new List <string>();
                int            labelId       = ktx.TokenRead().nodeLabel(PERSON_LABEL);
                int            propertyKeyId = ktx.TokenRead().propertyKey(NAME_PROPERTY);
                IndexReference index         = ktx.SchemaRead().index(labelId, propertyKeyId);
                using (NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor())
                {
                    // Node --> Index
                    foreach (Node node in filter(n => n.hasLabel(label) && n.hasProperty(NAME_PROPERTY), _db.AllNodes))
                    {
                        nodesInStore++;
                        string name = ( string )node.GetProperty(NAME_PROPERTY);
                        ktx.DataRead().nodeIndexSeek(index, cursor, IndexOrder.NONE, false, IndexQuery.exact(propertyKeyId, name));
                        bool found = false;
                        while (cursor.Next())
                        {
                            long indexedNode = cursor.NodeReference();
                            if (indexedNode == node.Id)
                            {
                                if (found)
                                {
                                    mismatches.Add("Index has multiple entries for " + name + " and " + indexedNode);
                                }
                                found = true;
                            }
                        }
                        if (!found)
                        {
                            mismatches.Add("Index is missing entry for " + name + " " + node);
                        }
                    }
                    if (mismatches.Count > 0)
                    {
                        fail(join(mismatches.ToArray(), format("%n")));
                    }
                    // Node count == indexed node count
                    ktx.DataRead().nodeIndexSeek(index, cursor, IndexOrder.NONE, false, IndexQuery.exists(propertyKeyId));
                    int nodesInIndex = 0;
                    while (cursor.Next())
                    {
                        nodesInIndex++;
                    }
                    assertEquals(nodesInStore, nodesInIndex);
                }
            }
        }