예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void relationshipIdReusableOnlyAfterTransactionFinish()
        public virtual void RelationshipIdReusableOnlyAfterTransactionFinish()
        {
            Label testLabel      = Label.label("testLabel");
            long  relationshipId = CreateRelationship(testLabel);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.IdController idMaintenanceController = getIdMaintenanceController();
            IdController idMaintenanceController = IdMaintenanceController;

            using (Transaction transaction = DbRule.beginTx(), ResourceIterator <Node> nodes = DbRule.findNodes(testLabel))
            {
                IList <Node> nodeList = Iterators.asList(nodes);
                foreach (Node node in nodeList)
                {
                    IEnumerable <Relationship> relationships = node.GetRelationships(TestRelationshipType.Marker);
                    foreach (Relationship relationship in relationships)
                    {
                        relationship.Delete();
                    }
                }

                idMaintenanceController.Maintenance();

                Node node1 = DbRule.createNode(testLabel);
                Node node2 = DbRule.createNode(testLabel);

                Relationship relationshipTo = node1.CreateRelationshipTo(node2, TestRelationshipType.Marker);

                assertNotEquals("Relationships should have different ids.", relationshipId, relationshipTo.Id);
                transaction.Success();
            }
        }
예제 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void writeTransactionsAndRotateTwice() throws java.io.IOException
        private void WriteTransactionsAndRotateTwice()
        {
            LogRotation logRotation = Db.DependencyResolver.resolveDependency(typeof(LogRotation));

            // Apparently we always keep an extra log file what even though the threshold is reached... produce two then
            using (Transaction tx = Db.beginTx())
            {
                Db.createNode();
                tx.Success();
            }
            logRotation.RotateLogFile();
            using (Transaction tx = Db.beginTx())
            {
                Db.createNode();
                tx.Success();
            }
            logRotation.RotateLogFile();
            using (Transaction tx = Db.beginTx())
            {
                Db.createNode();
                tx.Success();
            }
            using (Transaction tx = Db.beginTx())
            {
                Db.createNode();
                tx.Success();
            }
        }
예제 #3
0
        /*
         * Tests for a particular bug with dense nodes. It used to be that if a dense node had relationships
         * for only one direction, if a request for relationships of the other direction was made, no relationships
         * would be returned, ever.
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void givenDenseNodeWhenAskForWrongDirectionThenIncorrectNrOfRelsReturned()
        public virtual void GivenDenseNodeWhenAskForWrongDirectionThenIncorrectNrOfRelsReturned()
        {
            // Given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int denseNodeThreshold = int.Parse(org.neo4j.graphdb.factory.GraphDatabaseSettings.dense_node_threshold.getDefaultValue()) + 1;
            int denseNodeThreshold = int.Parse(GraphDatabaseSettings.dense_node_threshold.DefaultValue) + 1;

            Node node1;

            using (Transaction tx = Db.beginTx())
            {
                node1 = Db.createNode();
                Node node2 = Db.createNode();

                for (int i = 0; i < denseNodeThreshold; i++)
                {
                    node1.CreateRelationshipTo(node2, RelationshipType.withName("FOO"));
                }
                tx.Success();
            }

            // When/Then
            using (Transaction ignored = Db.beginTx())
            {
                Node node1b = Db.getNodeById(node1.Id);

                IEnumerable <Relationship> rels = node1b.GetRelationships(Direction.INCOMING);
                assertEquals(0, Iterables.count(rels));

                IEnumerable <Relationship> rels2 = node1b.GetRelationships(Direction.OUTGOING);
                assertEquals(denseNodeThreshold, Iterables.count(rels2));
            }
        }
예제 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldArchiveFailedIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldArchiveFailedIndex()
        {
            // given
            Db.withSetting(GraphDatabaseSettings.archive_failed_index, "true");
            using (Transaction tx = Db.beginTx())
            {
                Node node = Db.createNode(_person);
                node.SetProperty("name", "Fry");
                tx.Success();
            }
            using (Transaction tx = Db.beginTx())
            {
                Node node = Db.createNode(_person);
                node.SetProperty("name", Values.pointValue(CoordinateReferenceSystem.WGS84, 1, 2));
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                Db.schema().constraintFor(_person).assertPropertyIsUnique("name").create();
                tx.Success();
            }
            assertThat(ArchiveFile(), nullValue());

            // when
            Db.restartDatabase(new SabotageNativeIndex(Random.random()));

            // then
            IndexStateShouldBe(equalTo(ONLINE));
            assertThat(ArchiveFile(), notNullValue());
        }
예제 #5
0
 private Node CreateSomeData()
 {
     using (Transaction tx = Db.beginTx())
     {
         Node node = Db.createNode();
         node.CreateRelationshipTo(Db.createNode(), MyRelTypes.TEST);
         node.CreateRelationshipTo(Db.createNode(), MyRelTypes.TEST2);
         tx.Success();
         return(node);
     }
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void createTokens()
        public virtual void CreateTokens()
        {
            using (Transaction tx = Db.beginTx())
            {
                for (int i = 0; i < _threads; i++)
                {
                    Db.createNode(Label(i)).setProperty(KEY, i);
                }
                tx.Success();
            }
        }
예제 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void lookupWithinTransaction()
        public virtual void LookupWithinTransaction()
        {
            using (Transaction tx = Db.beginTx())
            {
                // when
                Db.createNode(label("Node")).setProperty("prop", _store);

                // then
                assertEquals(1, count(Db.findNodes(label("Node"), "prop", _lookup)));

                // no need to actually commit this node
            }
        }
예제 #8
0
        internal virtual long CreateNodeWithProperty(Label label, string propertyKey, object propertyValue)
        {
            Node node = Db.createNode(label);

            node.SetProperty(propertyKey, propertyValue);
            return(node.Id);
        }
예제 #9
0
        private void InitialData()
        {
            Label            unusedLabel   = Label.label("unusedLabel");
            RelationshipType unusedRelType = RelationshipType.withName("unusedRelType");
            string           unusedPropKey = "unusedPropKey";

            using (Transaction tx = Db.beginTx())
            {
                Node node1 = Db.createNode(unusedLabel);
                node1.SetProperty(unusedPropKey, "value");
                Node node2 = Db.createNode(unusedLabel);
                node2.SetProperty(unusedPropKey, 1);
                node1.CreateRelationshipTo(node2, unusedRelType);
                tx.Success();
            }
        }
예제 #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldApplyChangesWithIntermediateConstraintViolations() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldApplyChangesWithIntermediateConstraintViolations()
        {
            // given
            using (Transaction tx = Db.beginTx())
            {
                Db.schema().constraintFor(_foo).assertPropertyIsUnique(BAR).create();
                tx.Success();
            }
            Node fourtyTwo;
            Node fourtyOne;

            using (Transaction tx = Db.beginTx())
            {
                fourtyTwo = Db.createNode(_foo);
                fourtyTwo.SetProperty(BAR, Value1);
                fourtyOne = Db.createNode(_foo);
                fourtyOne.SetProperty(BAR, Value2);
                tx.Success();
            }

            // when
            using (Transaction tx = Db.beginTx())
            {
                fourtyOne.Delete();
                fourtyTwo.SetProperty(BAR, Value2);
                tx.Success();
            }

            // then
            using (Transaction tx = Db.beginTx())
            {
                assertEquals(Value2, fourtyTwo.GetProperty(BAR));
                try
                {
                    fourtyOne.GetProperty(BAR);
                    fail("Should be deleted");
                }
                catch (NotFoundException)
                {
                    // good
                }
                tx.Success();

                assertEquals(fourtyTwo, Db.findNode(_foo, BAR, Value2));
                assertNull(Db.findNode(_foo, BAR, Value1));
            }
        }
예제 #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldListActiveLocks() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldListActiveLocks()
        {
            // given
            string      query  = "MATCH (x:X) SET x.v = 5 WITH count(x) AS num MATCH (y:Y) SET y.c = num";
            ISet <long> locked = new HashSet <long>();

            try (Resource <Node> test = test(() =>
                {
                    for (int i = 0; i < 5; i++)
                    {
                        locked.Add(_db.createNode(label("X")).Id);
                    }
                    return(_db.createNode(label("Y")));
                }
                                             , query))
                {
                    // when
                    using (Result rows = _db.execute("CALL dbms.listQueries() " + "YIELD query AS queryText, queryId, activeLockCount " + "WHERE queryText = $queryText " + "CALL dbms.listActiveLocks(queryId) YIELD mode, resourceType, resourceId " + "RETURN *", singletonMap("queryText", query)))
                    {
                        // then
                        ISet <long> ids       = new HashSet <long>();
                        long?       lockCount = null;
                        long        rowCount  = 0;
                        while (rows.MoveNext())
                        {
                            IDictionary <string, object> row = rows.Current;
                            object resourceType    = row["resourceType"];
                            object activeLockCount = row["activeLockCount"];
                            if (lockCount == null)
                            {
                                assertThat("activeLockCount", activeLockCount, instanceOf(typeof(Long)));
                                lockCount = ( long? )activeLockCount;
                            }
                            else
                            {
                                assertEquals("activeLockCount", lockCount, activeLockCount);
                            }
                            if (ResourceTypes.LABEL.name().Equals(resourceType))
                            {
                                assertEquals("SHARED", row["mode"]);
                                assertEquals(0L, row["resourceId"]);
                            }
                            else
                            {
                                assertEquals("NODE", resourceType);
                                assertEquals("EXCLUSIVE", row["mode"]);
                                ids.Add(( long? )row["resourceId"]);
                            }
                            rowCount++;
                        }
                        assertEquals(locked, ids);
                        assertNotNull("activeLockCount", lockCount);
                        assertEquals(lockCount.Value, rowCount);                            // note: only true because query is blocked
                    }
                }
        }
예제 #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 30_000) public void terminateExpiredTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TerminateExpiredTransaction()
        {
            using (Transaction transaction = Database.beginTx())
            {
                Database.createNode();
                transaction.Success();
            }

            ExpectedException.expectMessage("The transaction has been terminated.");

            using (Transaction transaction = Database.beginTx())
            {
                Node nodeById = Database.getNodeById(NODE_ID);
                nodeById.SetProperty("a", "b");
                _executor.submit(StartAnotherTransaction()).get();
            }
        }
 private Node CreateLabeledNode(params Label[] labels)
 {
     using (Transaction tx = DbRule.beginTx())
     {
         Node node = DbRule.createNode(labels);
         tx.Success();
         return(node);
     }
 }
예제 #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGiveHelpfulExceptionWhenDeletingNodeWithRels()
        public virtual void ShouldGiveHelpfulExceptionWhenDeletingNodeWithRels()
        {
            // Given
            Node node;

            node = Db.createNode();
            Node node2 = Db.createNode();

            node.CreateRelationshipTo(node2, RelationshipType.withName("MAYOR_OF"));
            Tx.success();

            // And given a transaction deleting just the node
            Tx.begin();
            node.Delete();

            // Expect
            Exception.expect(typeof(ConstraintViolationException));
            Exception.expectMessage("Cannot delete node<" + node.Id + ">, because it still has relationships. " + "To delete this node, you must first delete its relationships.");

            // When I commit
            Tx.success();
        }
        private Node CreateTestNode()
        {
            Node node;

            using (Transaction transaction = DbRule.beginTx())
            {
                node = DbRule.createNode(_label);
                KernelTransaction ktx = DbRule.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);
                _labelId = ktx.TokenRead().nodeLabel(_label.name());
                transaction.Success();
            }
            return(node);
        }
예제 #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleSizesCloseToTheLimit()
        public virtual void ShouldHandleSizesCloseToTheLimit()
        {
            // given
            CreateIndex(KEY);

            // when
            IDictionary <string, long> strings = new Dictionary <string, long>();

            using (Transaction tx = Db.beginTx())
            {
                for (int i = 0; i < 1_000; i++)
                {
                    string @string;
                    do
                    {
                        @string = Random.nextAlphaNumericString(3_000, 4_000);
                    } while (strings.ContainsKey(@string));

                    Node node = Db.createNode(LABEL);
                    node.SetProperty(KEY, @string);
                    strings[@string] = node.Id;
                }
                tx.Success();
            }

            // then
            using (Transaction tx = Db.beginTx())
            {
                foreach (string @string in strings.Keys)
                {
                    Node node = Db.findNode(LABEL, KEY, @string);
                    assertEquals(strings[@string], node.Id);
                }
                tx.Success();
            }
        }
예제 #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldChaseTheLivingRelationships() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldChaseTheLivingRelationships()
        {
            // GIVEN a sound relationship chain
            int  numberOfRelationships = THRESHOLD / 2;
            Node node;

            using (Transaction tx = Db.beginTx())
            {
                node = Db.createNode();
                for (int i = 0; i < numberOfRelationships; i++)
                {
                    node.CreateRelationshipTo(Db.createNode(), TEST);
                }
                tx.Success();
            }
            Relationship[] relationships;
            using (Transaction tx = Db.beginTx())
            {
                relationships = asArray(typeof(Relationship), node.Relationships);
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                // WHEN getting the relationship iterator, i.e. starting to traverse this relationship chain,
                // the cursor eagerly goes to the first relationship before we call #hasNexxt/#next.
                IEnumerator <Relationship> iterator = node.Relationships.GetEnumerator();

                // Therefore we delete relationships [1] and [2] (the second and third), since currently
                // the relationship iterator has read [0] and have already decided to go to [1] after our next
                // call to #next
                DeleteRelationshipsInSeparateThread(relationships[1], relationships[2]);

                // THEN the relationship iterator should recognize the unused relationship, but still try to find
                // the next used relationship in this chain by following the pointers in the unused records.
                AssertNext(relationships[0], iterator);
                AssertNext(relationships[3], iterator);
                AssertNext(relationships[4], iterator);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(iterator.hasNext());
                tx.Success();
            }
        }
예제 #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void prepDB()
        public virtual void PrepDB()
        {
            using (Transaction transaction = Db.beginTx())
            {
                _node1 = Db.createNode(label("hej"), label("ha"), label("he"));
                _node1.setProperty("hej", "value");
                _node1.setProperty("ha", "value1");
                _node1.setProperty("he", "value2");
                _node1.setProperty("ho", "value3");
                _node1.setProperty("hi", "value4");
                _node2 = Db.createNode();
                Relationship rel = _node1.createRelationshipTo(_node2, RelationshipType.withName("hej"));
                rel.SetProperty("hej", "valuuu");
                rel.SetProperty("ha", "value1");
                rel.SetProperty("he", "value2");
                rel.SetProperty("ho", "value3");
                rel.SetProperty("hi", "value4");

                transaction.Success();
            }
        }