Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeNewNodePropertyInTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeNewNodePropertyInTransaction()
        {
            long   nodeId;
            string propKey1 = "prop1";
            string propKey2 = "prop2";

            using (Transaction tx = beginTransaction())
            {
                nodeId = tx.DataWrite().nodeCreate();
                int prop1 = tx.Token().propertyKeyGetOrCreateForName(propKey1);
                int prop2 = tx.Token().propertyKeyGetOrCreateForName(propKey2);
                assertEquals(tx.DataWrite().nodeSetProperty(nodeId, prop1, stringValue("hello")), NO_VALUE);
                assertEquals(tx.DataWrite().nodeSetProperty(nodeId, prop2, stringValue("world")), NO_VALUE);

                using (NodeCursor node = tx.Cursors().allocateNodeCursor(), PropertyCursor property = tx.Cursors().allocatePropertyCursor())
                {
                    tx.DataRead().singleNode(nodeId, node);
                    assertTrue("should access node", node.Next());

                    node.Properties(property);
                    assertTrue(property.Next());
                    //First property
                    assertEquals(prop1, property.PropertyKey());
                    assertEquals(property.PropertyValue(), stringValue("hello"));
                    //second property
                    assertTrue(property.Next());
                    assertEquals(prop2, property.PropertyKey());
                    assertEquals(property.PropertyValue(), stringValue("world"));

                    assertFalse("should only find two properties", property.Next());
                    assertFalse("should only find one node", node.Next());
                }
                tx.Success();
            }
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeNewLabeledNodeInTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeNewLabeledNodeInTransaction()
        {
            long         nodeId;
            int          labelId;
            const string labelName = "Town";

            using (Transaction tx = beginTransaction())
            {
                nodeId  = tx.DataWrite().nodeCreate();
                labelId = tx.Token().labelGetOrCreateForName(labelName);
                tx.DataWrite().nodeAddLabel(nodeId, labelId);

                using (NodeCursor node = tx.Cursors().allocateNodeCursor())
                {
                    tx.DataRead().singleNode(nodeId, node);
                    assertTrue("should access node", node.Next());

                    LabelSet labels = node.Labels();
                    assertEquals(1, labels.NumberOfLabels());
                    assertEquals(labelId, labels.Label(0));
                    assertTrue(node.HasLabel(labelId));
                    assertFalse(node.HasLabel(labelId + 1));
                    assertFalse("should only find one node", node.Next());
                }
                tx.Success();
            }

            using (Org.Neo4j.Graphdb.Transaction ignore = graphDb.beginTx())
            {
                assertThat(graphDb.getNodeById(nodeId).Labels, equalTo(Iterables.iterable(label(labelName))));
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFollowSpecificRelationship()
        public virtual void ShouldFollowSpecificRelationship()
        {
            // given
            using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor(), RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor())
            {
                // when - traversing from start to end
                read.singleNode(_start, node);
                assertTrue("access start node", node.Next());
                node.Relationships(group);
                assertTrue("access relationship group", group.next());
                group.Outgoing(relationship);
                assertTrue("access outgoing relationships", relationship.next());

                // then
                assertEquals("source node", _start, relationship.SourceNodeReference());
                assertEquals("target node", _end, relationship.TargetNodeReference());

                assertEquals("node of origin", _start, relationship.OriginNodeReference());
                assertEquals("neighbouring node", _end, relationship.NeighbourNodeReference());

                assertEquals("relationship should have same label as group", group.Type(), relationship.Type());

                assertFalse("only a single relationship", relationship.next());

                group.Incoming(relationship);
                assertFalse("no incoming relationships", relationship.next());
                group.Loops(relationship);
                assertFalse("no loop relationships", relationship.next());

                assertFalse("only a single group", group.next());

                // when - traversing from end to start
                read.singleNode(_end, node);
                assertTrue("access start node", node.Next());
                node.Relationships(group);
                assertTrue("access relationship group", group.next());
                group.Incoming(relationship);
                assertTrue("access incoming relationships", relationship.next());

                // then
                assertEquals("source node", _start, relationship.SourceNodeReference());
                assertEquals("target node", _end, relationship.TargetNodeReference());

                assertEquals("node of origin", _end, relationship.OriginNodeReference());
                assertEquals("neighbouring node", _start, relationship.NeighbourNodeReference());

                assertEquals("relationship should have same label as group", group.Type(), relationship.Type());

                assertFalse("only a single relationship", relationship.next());

                group.Outgoing(relationship);
                assertFalse("no outgoing relationships", relationship.next());
                group.Loops(relationship);
                assertFalse("no loop relationships", relationship.next());

                assertFalse("only a single group", group.next());
            }
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeLabelChangesInTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeLabelChangesInTransaction()
        {
            long         nodeId;
            int          toRetain, toDelete, toAdd, toRegret;
            const string toRetainName = "ToRetain";
            const string toDeleteName = "ToDelete";
            const string toAddName    = "ToAdd";
            const string toRegretName = "ToRegret";

            using (Transaction tx = beginTransaction())
            {
                nodeId   = tx.DataWrite().nodeCreate();
                toRetain = tx.Token().labelGetOrCreateForName(toRetainName);
                toDelete = tx.Token().labelGetOrCreateForName(toDeleteName);
                tx.DataWrite().nodeAddLabel(nodeId, toRetain);
                tx.DataWrite().nodeAddLabel(nodeId, toDelete);
                tx.Success();
            }

            using (Org.Neo4j.Graphdb.Transaction ignore = graphDb.beginTx())
            {
                assertThat(graphDb.getNodeById(nodeId).Labels, containsInAnyOrder(label(toRetainName), label(toDeleteName)));
            }

            using (Transaction tx = beginTransaction())
            {
                toAdd = tx.Token().labelGetOrCreateForName(toAddName);
                tx.DataWrite().nodeAddLabel(nodeId, toAdd);
                tx.DataWrite().nodeRemoveLabel(nodeId, toDelete);

                toRegret = tx.Token().labelGetOrCreateForName(toRegretName);
                tx.DataWrite().nodeAddLabel(nodeId, toRegret);
                tx.DataWrite().nodeRemoveLabel(nodeId, toRegret);

                using (NodeCursor node = tx.Cursors().allocateNodeCursor())
                {
                    tx.DataRead().singleNode(nodeId, node);
                    assertTrue("should access node", node.Next());

                    AssertLabels(node.Labels(), toRetain, toAdd);
                    assertTrue(node.HasLabel(toAdd));
                    assertTrue(node.HasLabel(toRetain));
                    assertFalse(node.HasLabel(toDelete));
                    assertFalse(node.HasLabel(toRegret));
                    assertFalse("should only find one node", node.Next());
                }
                tx.Success();
            }

            using (Org.Neo4j.Graphdb.Transaction ignored = graphDb.beginTx())
            {
                assertThat(graphDb.getNodeById(nodeId).Labels, containsInAnyOrder(label(toRetainName), label(toAddName)));
            }
        }
Пример #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeAddedPropertyFromExistingNodeWithPropertiesInTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeAddedPropertyFromExistingNodeWithPropertiesInTransaction()
        {
            // Given
            long   nodeId;
            string propKey1 = "prop1";
            string propKey2 = "prop2";
            int    propToken1;
            int    propToken2;

            using (Transaction tx = beginTransaction())
            {
                nodeId     = tx.DataWrite().nodeCreate();
                propToken1 = tx.Token().propertyKeyGetOrCreateForName(propKey1);
                assertEquals(tx.DataWrite().nodeSetProperty(nodeId, propToken1, stringValue("hello")), NO_VALUE);
                tx.Success();
            }

            // When/Then
            using (Transaction tx = beginTransaction())
            {
                propToken2 = tx.Token().propertyKeyGetOrCreateForName(propKey2);
                assertEquals(tx.DataWrite().nodeSetProperty(nodeId, propToken2, stringValue("world")), NO_VALUE);

                using (NodeCursor node = tx.Cursors().allocateNodeCursor(), PropertyCursor property = tx.Cursors().allocatePropertyCursor())
                {
                    tx.DataRead().singleNode(nodeId, node);
                    assertTrue("should access node", node.Next());

                    node.Properties(property);

                    //property 2, start with tx state
                    assertTrue(property.Next());
                    assertEquals(propToken2, property.PropertyKey());
                    assertEquals(property.PropertyValue(), stringValue("world"));

                    //property 1, from disk
                    assertTrue(property.Next());
                    assertEquals(propToken1, property.PropertyKey());
                    assertEquals(property.PropertyValue(), stringValue("hello"));

                    assertFalse("should only find two properties", property.Next());
                    assertFalse("should only find one node", node.Next());
                }
                tx.Success();
            }

            using (Org.Neo4j.Graphdb.Transaction ignored = graphDb.beginTx())
            {
                assertThat(graphDb.getNodeById(nodeId).getProperty(propKey1), equalTo("hello"));
                assertThat(graphDb.getNodeById(nodeId).getProperty(propKey2), equalTo("world"));
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHaveBeenAbleToCreateDenseAndSparseNodes()
        public virtual void ShouldHaveBeenAbleToCreateDenseAndSparseNodes()
        {
            // given
            using (NodeCursor node = cursors.allocateNodeCursor())
            {
                read.singleNode(_dense.id, node);
                assertTrue("access dense node", node.Next());
                assertTrue("dense node", node.Dense);

                read.singleNode(_sparse.id, node);
                assertTrue("access sparse node", node.Next());
                assertFalse("sparse node", node.Dense && SupportsSparseNodes());
            }
        }
Пример #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void propertyTypeShouldBeTxStateAware() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void PropertyTypeShouldBeTxStateAware()
        {
            // Given
            long node;

            using (Transaction tx = beginTransaction())
            {
                node = tx.DataWrite().nodeCreate();
                tx.Success();
            }

            // Then
            using (Transaction tx = beginTransaction())
            {
                using (NodeCursor nodes = tx.Cursors().allocateNodeCursor(), PropertyCursor properties = tx.Cursors().allocatePropertyCursor())
                {
                    tx.DataRead().singleNode(node, nodes);
                    assertTrue(nodes.Next());
                    assertFalse(HasProperties(nodes, properties));
                    int prop = tx.TokenWrite().propertyKeyGetOrCreateForName("prop");
                    tx.DataWrite().nodeSetProperty(node, prop, stringValue("foo"));
                    nodes.Properties(properties);

                    assertTrue(properties.Next());
                    assertThat(properties.PropertyType(), equalTo(ValueGroup.TEXT));
                }
            }
        }
Пример #8
0
        private ResourceIterator <Relationship> GetRelationshipSelectionIterator(KernelTransaction transaction, Direction direction, int[] typeIds)
        {
            NodeCursor node = transaction.AmbientNodeCursor();

            transaction.DataRead().singleNode(Id, node);
            if (!node.Next())
            {
                throw new NotFoundException(format("Node %d not found", _nodeId));
            }

            switch (direction.innerEnumValue)
            {
            case Direction.InnerEnum.OUTGOING:
                return(outgoingIterator(transaction.Cursors(), node, typeIds, this));

            case Direction.InnerEnum.INCOMING:
                return(incomingIterator(transaction.Cursors(), node, typeIds, this));

            case Direction.InnerEnum.BOTH:
                return(allIterator(transaction.Cursors(), node, typeIds, this));

            default:
                throw new System.InvalidOperationException("Unknown direction " + direction);
            }
        }
Пример #9
0
        internal virtual IEnumerator <long> NodeGetRelationships(Transaction transaction, long node, Direction direction, int[] types)
        {
            NodeCursor cursor = transaction.Cursors().allocateNodeCursor();

            transaction.DataRead().singleNode(node, cursor);
            if (!cursor.Next())
            {
                return(emptyIterator());
            }

            switch (direction.innerEnumValue)
            {
            case Direction.InnerEnum.OUTGOING:
                return(outgoingIterator(transaction.Cursors(), cursor, types, (id, startNodeId, typeId, endNodeId) => id));

            case Direction.InnerEnum.INCOMING:
                return(incomingIterator(transaction.Cursors(), cursor, types, (id, startNodeId, typeId, endNodeId) => id));

            case Direction.InnerEnum.BOTH:
                return(allIterator(transaction.Cursors(), cursor, types, (id, startNodeId, typeId, endNodeId) => id));

            default:
                throw new System.InvalidOperationException(direction + " is not a valid direction");
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void traverseViaGroups(RelationshipTestSupport.StartNode start, boolean detached) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private void TraverseViaGroups(RelationshipTestSupport.StartNode start, bool detached)
        {
            // given
            IDictionary <string, int> expectedCounts = start.ExpectedCounts();

            using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor(), RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor())
            {
                // when
                read.singleNode(start.Id, node);
                assertTrue("access node", node.Next());
                if (detached)
                {
                    read.relationshipGroups(start.Id, node.RelationshipGroupReference(), group);
                }
                else
                {
                    node.Relationships(group);
                }

                while (group.next())
                {
                    // outgoing
                    if (detached)
                    {
                        read.relationships(start.Id, group.OutgoingReference(), relationship);
                    }
                    else
                    {
                        group.Outgoing(relationship);
                    }
                    // then
                    assertCount(tx, relationship, expectedCounts, group.Type(), OUTGOING);

                    // incoming
                    if (detached)
                    {
                        read.relationships(start.Id, group.IncomingReference(), relationship);
                    }
                    else
                    {
                        group.Incoming(relationship);
                    }
                    // then
                    assertCount(tx, relationship, expectedCounts, group.Type(), INCOMING);

                    // loops
                    if (detached)
                    {
                        read.relationships(start.Id, group.LoopsReference(), relationship);
                    }
                    else
                    {
                        group.Loops(relationship);
                    }
                    // then
                    assertCount(tx, relationship, expectedCounts, group.Type(), BOTH);
                }
            }
        }
Пример #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAccessNodesByReference()
        public virtual void ShouldAccessNodesByReference()
        {
            // given
            using (NodeCursor nodes = cursors.allocateNodeCursor())
            {
                foreach (long id in _nodeIds)
                {
                    // when
                    read.singleNode(id, nodes);

                    // then
                    assertTrue("should access defined node", nodes.Next());
                    assertEquals("should access the correct node", id, nodes.NodeReference());
                    assertFalse("should only access a single node", nodes.Next());
                }
            }
        }
Пример #12
0
 private void SingleNode(KernelTransaction transaction, NodeCursor nodes)
 {
     transaction.DataRead().singleNode(_nodeId, nodes);
     if (!nodes.Next())
     {
         throw new NotFoundException(new EntityNotFoundException(EntityType.NODE, _nodeId));
     }
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldManageRandomTraversals()
        public virtual void ShouldManageRandomTraversals()
        {
            // given
            try
            {
                using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor(), RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor())
                {
                    for (int i = 0; i < N_TRAVERSALS; i++)
                    {
                        // when
                        long nodeId = _nodeIds[_random.Next(_nNodes)];
                        read.singleNode(nodeId, node);
                        assertTrue("access root node", node.Next());
                        node.Relationships(group);
                        assertFalse("single root", node.Next());

                        // then
                        while (group.next())
                        {
                            group.Incoming(relationship);
                            while (relationship.next())
                            {
                                assertEquals("incoming origin", nodeId, relationship.OriginNodeReference());
                                relationship.Neighbour(node);
                            }
                            group.Outgoing(relationship);
                            while (relationship.next())
                            {
                                assertEquals("outgoing origin", nodeId, relationship.OriginNodeReference());
                                relationship.Neighbour(node);
                            }
                            group.Loops(relationship);
                            while (relationship.next())
                            {
                                assertEquals("loop origin", nodeId, relationship.OriginNodeReference());
                                relationship.Neighbour(node);
                            }
                        }
                    }
                }
            }
            catch (Exception t)
            {
                throw new Exception("Failed with random seed " + _seed, t);
            }
        }
Пример #14
0
        private void ScanEverythingBelongingToNodes(NodeMappings nodeMappings)
        {
            using (NodeCursor nodeCursor = _cursors.allocateNodeCursor(), PropertyCursor propertyCursor = _cursors.allocatePropertyCursor())
            {
                _dataRead.allNodesScan(nodeCursor);
                while (nodeCursor.Next())
                {
                    // each node
                    SortedLabels labels = SortedLabels.From(nodeCursor.Labels());
                    nodeCursor.Properties(propertyCursor);
                    MutableIntSet propertyIds = IntSets.mutable.empty();

                    while (propertyCursor.Next())
                    {
                        Value currentValue           = propertyCursor.PropertyValue();
                        int   propertyKeyId          = propertyCursor.PropertyKey();
                        Pair <SortedLabels, int> key = Pair.of(labels, propertyKeyId);
                        UpdateValueTypeInMapping(currentValue, key, nodeMappings.LabelSetANDNodePropertyKeyIdToValueType);

                        propertyIds.add(propertyKeyId);
                    }
                    propertyCursor.Close();

                    MutableIntSet oldPropertyKeySet = nodeMappings.LabelSetToPropertyKeys.getOrDefault(labels, _emptyPropertyIdSet);

                    // find out which old properties we did not visited and mark them as nullable
                    if (oldPropertyKeySet == _emptyPropertyIdSet)
                    {
                        if (propertyIds.size() == 0)
                        {
                            // Even if we find property key on other nodes with those labels, set all of them nullable
                            nodeMappings.NullableLabelSets.Add(labels);
                        }

                        propertyIds.addAll(oldPropertyKeySet);
                    }
                    else
                    {
                        MutableIntSet currentPropertyIdsHelperSet = new IntHashSet(propertyIds.size());
                        currentPropertyIdsHelperSet.addAll(propertyIds);
                        propertyIds.removeAll(oldPropertyKeySet);                                     // only the brand new ones in propIds now
                        oldPropertyKeySet.removeAll(currentPropertyIdsHelperSet);                     // only the old ones that are not on the new node

                        propertyIds.addAll(oldPropertyKeySet);
                        propertyIds.forEach(id =>
                        {
                            Pair <SortedLabels, int> key = Pair.of(labels, id);
                            nodeMappings.LabelSetANDNodePropertyKeyIdToValueType[key].setNullable();
                        });

                        propertyIds.addAll(currentPropertyIdsHelperSet);
                    }

                    nodeMappings.LabelSetToPropertyKeys[labels] = propertyIds;
                }
                nodeCursor.Close();
            }
        }
Пример #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAccessNonExistentProperties()
        public virtual void ShouldNotAccessNonExistentProperties()
        {
            // given
            using (NodeCursor node = cursors.allocateNodeCursor(), PropertyCursor props = cursors.allocatePropertyCursor())
            {
                // when
                read.singleNode(_bare, node);
                assertTrue("node by reference", node.Next());
                assertFalse("no properties", HasProperties(node, props));

                node.Properties(props);
                assertFalse("no properties by direct method", props.Next());

                read.nodeProperties(node.NodeReference(), node.PropertiesReference(), props);
                assertFalse("no properties via property ref", props.Next());

                assertFalse("only one node", node.Next());
            }
        }
Пример #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeRemovedThenAddedPropertyInTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeRemovedThenAddedPropertyInTransaction()
        {
            // Given
            long   nodeId;
            string propKey = "prop1";
            int    propToken;

            using (Transaction tx = beginTransaction())
            {
                nodeId    = tx.DataWrite().nodeCreate();
                propToken = tx.Token().propertyKeyGetOrCreateForName(propKey);
                assertEquals(tx.DataWrite().nodeSetProperty(nodeId, propToken, stringValue("hello")), NO_VALUE);
                tx.Success();
            }

            // When/Then
            using (Transaction tx = beginTransaction())
            {
                assertEquals(tx.DataWrite().nodeRemoveProperty(nodeId, propToken), stringValue("hello"));
                assertEquals(tx.DataWrite().nodeSetProperty(nodeId, propToken, stringValue("world")), NO_VALUE);
                using (NodeCursor node = tx.Cursors().allocateNodeCursor(), PropertyCursor property = tx.Cursors().allocatePropertyCursor())
                {
                    tx.DataRead().singleNode(nodeId, node);
                    assertTrue("should access node", node.Next());

                    node.Properties(property);
                    assertTrue(property.Next());
                    assertEquals(propToken, property.PropertyKey());
                    assertEquals(property.PropertyValue(), stringValue("world"));

                    assertFalse("should not find any properties", property.Next());
                    assertFalse("should only find one node", node.Next());
                }

                tx.Success();
            }

            using (Org.Neo4j.Graphdb.Transaction ignored = graphDb.beginTx())
            {
                assertThat(graphDb.getNodeById(nodeId).getProperty(propKey), equalTo("world"));
            }
        }
Пример #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowManyLabelsAndPropertyCursor()
        public virtual void ShouldAllowManyLabelsAndPropertyCursor()
        {
            int propertyCount = 10;
            int labelCount    = 15;

            GraphDatabaseAPI db = DbRule.GraphDatabaseAPI;
            Node             node;

            using (Transaction tx = Db.beginTx())
            {
                node = Db.createNode();
                for (int i = 0; i < propertyCount; i++)
                {
                    node.SetProperty("foo" + i, "bar");
                }
                for (int i = 0; i < labelCount; i++)
                {
                    node.AddLabel(label("label" + i));
                }
                tx.Success();
            }

            ISet <int> seenProperties = new HashSet <int>();
            ISet <int> seenLabels     = new HashSet <int>();

            using (Transaction tx = Db.beginTx())
            {
                DependencyResolver             resolver = Db.DependencyResolver;
                ThreadToStatementContextBridge bridge   = resolver.ResolveDependency(typeof(ThreadToStatementContextBridge));
                KernelTransaction ktx = bridge.GetKernelTransactionBoundToThisThread(true);
                using (NodeCursor nodes = ktx.Cursors().allocateNodeCursor(), PropertyCursor propertyCursor = ktx.Cursors().allocatePropertyCursor())
                {
                    ktx.DataRead().singleNode(node.Id, nodes);
                    while (nodes.Next())
                    {
                        nodes.Properties(propertyCursor);
                        while (propertyCursor.Next())
                        {
                            seenProperties.Add(propertyCursor.PropertyKey());
                        }

                        LabelSet labels = nodes.Labels();
                        for (int i = 0; i < labels.NumberOfLabels(); i++)
                        {
                            seenLabels.Add(labels.Label(i));
                        }
                    }
                }
                tx.Success();
            }

            assertEquals(propertyCount, seenProperties.Count);
            assertEquals(labelCount, seenLabels.Count);
        }
Пример #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTraverseTreeOfDepthThree()
        public virtual void ShouldTraverseTreeOfDepthThree()
        {
            using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor(), RelationshipTraversalCursor relationship1 = cursors.allocateRelationshipTraversalCursor(), RelationshipTraversalCursor relationship2 = cursors.allocateRelationshipTraversalCursor())
            {
                MutableLongSet leafs = new LongHashSet();
                long           total = 0;

                // when
                read.singleNode(_threeRoot, node);
                assertTrue("access root node", node.Next());
                node.Relationships(group);
                assertFalse("single root", node.Next());

                assertTrue("access group of root", group.next());
                group.Incoming(relationship1);
                assertFalse("single group of root", group.next());

                while (relationship1.next())
                {
                    relationship1.Neighbour(node);

                    assertTrue("child level 1", node.Next());
                    node.Relationships(group);
                    assertFalse("single node", node.Next());

                    assertTrue("group of level 1 child", group.next());
                    group.Incoming(relationship2);
                    assertFalse("single group of level 1 child", group.next());

                    while (relationship2.next())
                    {
                        leafs.add(relationship2.NeighbourNodeReference());
                        total++;
                    }
                }

                // then
                assertEquals("total number of leaf nodes", _expectedTotal, total);
                assertEquals("number of distinct leaf nodes", _expectedUnique, leafs.size());
            }
        }
Пример #19
0
        // This is functionality which is only required for the hacky db.schema not to leak real data
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAccessNegativeReferences()
        public virtual void ShouldNotAccessNegativeReferences()
        {
            // given
            using (NodeCursor node = cursors.allocateNodeCursor())
            {
                // when
                read.singleNode(-2L, node);

                // then
                assertFalse("should not access negative reference node", node.Next());
            }
        }
Пример #20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotFindDeletedNode()
        public virtual void ShouldNotFindDeletedNode()
        {
            // given
            using (NodeCursor nodes = cursors.allocateNodeCursor())
            {
                // when
                read.singleNode(_gone, nodes);

                // then
                assertFalse("should not access deleted node", nodes.Next());
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTraverseRelationshipsOfGivenType()
        public virtual void ShouldTraverseRelationshipsOfGivenType()
        {
            // given
            using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor(), RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor())
            {
                int empty = 0;
                // when
                read.allNodesScan(node);
                while (node.Next())
                {
                    node.Relationships(group);
                    bool none = true;
                    while (group.next())
                    {
                        none = false;
                        Sizes degree = new Sizes();
                        group.Outgoing(relationship);
                        while (relationship.next())
                        {
                            assertEquals("node #" + node.NodeReference() + " relationship should have same label as group", group.Type(), relationship.Type());
                            degree.Outgoing++;
                        }
                        group.Incoming(relationship);
                        while (relationship.next())
                        {
                            assertEquals("node #" + node.NodeReference() + "relationship should have same label as group", group.Type(), relationship.Type());
                            degree.Incoming++;
                        }
                        group.Loops(relationship);
                        while (relationship.next())
                        {
                            assertEquals("node #" + node.NodeReference() + "relationship should have same label as group", group.Type(), relationship.Type());
                            degree.Loop++;
                        }

                        // then
                        assertNotEquals("all", 0, degree.Incoming + degree.Outgoing + degree.Loop);
                        assertEquals("node #" + node.NodeReference() + " outgoing", group.OutgoingCount(), degree.Outgoing);
                        assertEquals("node #" + node.NodeReference() + " incoming", group.IncomingCount(), degree.Incoming);
                        assertEquals("node #" + node.NodeReference() + " loop", group.LoopCount(), degree.Loop);
                        assertEquals("node #" + node.NodeReference() + " all = incoming + outgoing - loop", group.TotalCount(), degree.Incoming + degree.Outgoing + degree.Loop);
                    }
                    if (none)
                    {
                        empty++;
                    }
                }

                // then
                assertEquals("number of empty nodes", 1, empty);
            }
        }
Пример #22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeNodeInTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeNodeInTransaction()
        {
            long nodeId;

            using (Transaction tx = beginTransaction())
            {
                nodeId = tx.DataWrite().nodeCreate();
                using (NodeCursor node = tx.Cursors().allocateNodeCursor())
                {
                    tx.DataRead().singleNode(nodeId, node);
                    assertTrue("should access node", node.Next());
                    assertEquals(nodeId, node.NodeReference());
                    assertFalse("should only find one node", node.Next());
                }
                tx.Success();
            }

            using (Org.Neo4j.Graphdb.Transaction ignore = graphDb.beginTx())
            {
                assertEquals(nodeId, graphDb.getNodeById(nodeId).Id);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAccessGroupsOfBareNode()
        public virtual void ShouldNotAccessGroupsOfBareNode()
        {
            // given
            using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor())
            {
                // when
                read.singleNode(_bare, node);
                assertTrue("access node", node.Next());
                node.Relationships(group);

                // then
                assertFalse("access group", group.next());
            }
        }
Пример #24
0
        protected internal virtual int CountNodes(Transaction transaction)
        {
            int result = 0;

            using (NodeCursor cursor = transaction.Cursors().allocateNodeCursor())
            {
                transaction.DataRead().allNodesScan(cursor);
                while (cursor.Next())
                {
                    result++;
                }
            }
            return(result);
        }
Пример #25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void hasPropertiesShouldSeeNewlyCreatedPropertiesOnNewlyCreatedNode() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void HasPropertiesShouldSeeNewlyCreatedPropertiesOnNewlyCreatedNode()
        {
            using (Transaction tx = beginTransaction())
            {
                long node = tx.DataWrite().nodeCreate();
                using (NodeCursor cursor = tx.Cursors().allocateNodeCursor(), PropertyCursor props = tx.Cursors().allocatePropertyCursor())
                {
                    tx.DataRead().singleNode(node, cursor);
                    assertTrue(cursor.Next());
                    assertFalse(HasProperties(cursor, props));
                    tx.DataWrite().nodeSetProperty(node, tx.TokenWrite().propertyKeyGetOrCreateForName("prop"), stringValue("foo"));
                    assertTrue(HasProperties(cursor, props));
                }
            }
        }
Пример #26
0
        public override bool HasLabel(Label label)
        {
            KernelTransaction transaction = SafeAcquireTransaction();
            NodeCursor        nodes       = transaction.AmbientNodeCursor();

            using (Statement ignore = transaction.AcquireStatement())
            {
                int labelId = transaction.TokenRead().nodeLabel(label.Name());
                if (labelId == NO_SUCH_LABEL)
                {
                    return(false);
                }
                transaction.DataRead().singleNode(_nodeId, nodes);
                return(nodes.Next() && nodes.HasLabel(labelId));
            }
        }
Пример #27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldScanNodes()
        public virtual void ShouldScanNodes()
        {
            // given
            IList <long> ids = new List <long>();

            using (NodeCursor nodes = cursors.allocateNodeCursor())
            {
                // when
                read.allNodesScan(nodes);
                while (nodes.Next())
                {
                    ids.Add(nodes.NodeReference());
                }
            }

            // then
            assertEquals(_nodeIds, ids);
        }
Пример #28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAccessAllNodeProperties()
        public virtual void ShouldAccessAllNodeProperties()
        {
            // given
            using (NodeCursor node = cursors.allocateNodeCursor(), PropertyCursor props = cursors.allocatePropertyCursor())
            {
                // when
                read.singleNode(_allProps, node);
                assertTrue("node by reference", node.Next());
                assertTrue("has properties", HasProperties(node, props));

                node.Properties(props);
                ISet <object> values = new HashSet <object>();
                while (props.Next())
                {
                    values.Add(props.PropertyValue().asObject());
                }

                assertTrue("byteProp", values.Contains(( sbyte )13));
                assertTrue("shortProp", values.Contains(( short )13));
                assertTrue("intProp", values.Contains(13));
                assertTrue("inlineLongProp", values.Contains(13L));
                assertTrue("longProp", values.Contains(long.MaxValue));
                assertTrue("floatProp", values.Contains(13.0f));
                assertTrue("doubleProp", values.Contains(13.0));
                assertTrue("trueProp", values.Contains(true));
                assertTrue("falseProp", values.Contains(false));
                assertTrue("charProp", values.Contains('x'));
                assertTrue("emptyStringProp", values.Contains(""));
                assertTrue("shortStringProp", values.Contains("hello"));
                assertTrue("utf8Prop", values.Contains(_chinese));
                if (SupportsBigProperties())
                {
                    assertTrue("longStringProp", values.Contains(LONG_STRING));
                    assertThat("smallArray", values, hasItem(IntArray(1, 2, 3, 4)));
                    assertThat("bigArray", values, hasItem(arrayContaining(LONG_STRING)));
                }
                assertTrue("pointProp", values.Contains(_pointValue));

                int expected = SupportsBigProperties() ? 18 : 15;
                assertEquals("number of values", expected, values.Count);
            }
        }
Пример #29
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDiscoverDeletedNodeInTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDiscoverDeletedNodeInTransaction()
        {
            long nodeId;

            using (Transaction tx = beginTransaction())
            {
                nodeId = tx.DataWrite().nodeCreate();
                tx.Success();
            }

            using (Transaction tx = beginTransaction())
            {
                assertTrue(tx.DataWrite().nodeDelete(nodeId));
                using (NodeCursor node = tx.Cursors().allocateNodeCursor())
                {
                    tx.DataRead().singleNode(nodeId, node);
                    assertFalse(node.Next());
                }
                tx.Success();
            }
        }
Пример #30
0
        private void AssertAccessSingleProperty(long nodeId, object expectedValue, ValueGroup expectedValueType)
        {
            // given
            using (NodeCursor node = cursors.allocateNodeCursor(), PropertyCursor props = cursors.allocatePropertyCursor())
            {
                // when
                read.singleNode(nodeId, node);
                assertTrue("node by reference", node.Next());
                assertTrue("has properties", HasProperties(node, props));

                node.Properties(props);
                assertTrue("has properties by direct method", props.Next());
                assertEquals("correct value", expectedValue, props.PropertyValue());
                assertEquals("correct value type ", expectedValueType, props.PropertyType());
                assertFalse("single property", props.Next());

                read.nodeProperties(node.NodeReference(), node.PropertiesReference(), props);
                assertTrue("has properties via property ref", props.Next());
                assertEquals("correct value", expectedValue, props.PropertyValue());
                assertFalse("single property", props.Next());
            }
        }