Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void transactionShouldReleaseLocksWhenGraphDbIsBeingShutdown()
        public virtual void TransactionShouldReleaseLocksWhenGraphDbIsBeingShutdown()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.locking.Locks locks = db.getDependencyResolver().resolveDependency(org.neo4j.kernel.impl.locking.Locks.class);
            Locks locks = _db.DependencyResolver.resolveDependency(typeof(Locks));

            assertEquals(0, LockCount(locks));
            Exception exceptionThrownByTxClose = null;

            // WHEN
            try
            {
                using (Transaction tx = _db.beginTx())
                {
                    Node node = _db.createNode();
                    tx.AcquireWriteLock(node);
                    assertThat(LockCount(locks), greaterThanOrEqualTo(1));

                    _db.shutdown();

                    _db.createNode();
                    tx.Success();
                }
            }
            catch (Exception e)
            {
                exceptionThrownByTxClose = e;
            }

            // THEN
            assertThat(exceptionThrownByTxClose, instanceOf(typeof(DatabaseShutdownException)));
            assertFalse(_db.isAvailable(1));
            assertEquals(0, LockCount(locks));
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void startDb()
        public virtual void StartDb()
        {
            _graphDb = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).newImpermanentDatabaseBuilder().setConfig(new Dictionary <string, string>()).newGraphDatabase();

            using (Transaction tx = _graphDb.beginTx())
            {
                // Create the node and relationship auto-indexes
                _graphDb.index().NodeAutoIndexer.Enabled = true;
                _graphDb.index().NodeAutoIndexer.startAutoIndexingProperty("nodeProp");
                _graphDb.index().RelationshipAutoIndexer.Enabled = true;
                _graphDb.index().RelationshipAutoIndexer.startAutoIndexingProperty("type");

                tx.Success();
            }

            using (Transaction tx = _graphDb.beginTx())
            {
                Node node1 = _graphDb.createNode();
                Node node2 = _graphDb.createNode();
                Node node3 = _graphDb.createNode();
                _id1 = node1.Id;
                _id2 = node2.Id;
                _id3 = node3.Id;
                Relationship rel = node1.CreateRelationshipTo(node2, RelationshipType.withName("FOO"));
                rel.SetProperty("type", "FOO");

                tx.Success();
            }
        }
Example #3
0
 private void CreatePropertyIndex()
 {
     using (Transaction tx = _graphDb.beginTx())
     {
         _graphDb.schema().indexFor(Label).on(PROP_NAME).create();
         tx.Success();
     }
 }
Example #4
0
 private void NewTransaction()
 {
     if (_tx != null)
     {
         _tx.success();
         _tx.close();
     }
     _tx = _graphDb.beginTx();
 }
Example #5
0
        /// <summary>
        /// Set all properties on an entity, deleting any properties that existed on the entity but not in the
        /// provided map.
        /// </summary>
        /// <param name="entity"> </param>
        /// <param name="properties"> </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void setAllProperties(org.neo4j.graphdb.PropertyContainer entity, java.util.Map<String, Object> properties) throws org.neo4j.server.rest.web.PropertyValueException
        public virtual void SetAllProperties(PropertyContainer entity, IDictionary <string, object> properties)
        {
            IDictionary <string, object> propsToSet = properties == null ? new Dictionary <string, object>() : properties;

            using (Transaction tx = _db.beginTx())
            {
                SetProperties(entity, properties);
                EnsureHasOnlyTheseProperties(entity, propsToSet.Keys);

                tx.Success();
            }
        }
Example #6
0
 protected internal static Node CreateLabeledNode(GraphDatabaseService db, IDictionary <string, object> properties, params Label[] labels)
 {
     using (Transaction tx = Db.beginTx())
     {
         Node node = Db.createNode(labels);
         foreach (KeyValuePair <string, object> property in properties.SetOfKeyValuePairs())
         {
             node.SetProperty(property.Key, property.Value);
         }
         tx.Success();
         return(node);
     }
 }
Example #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void fulltextIndexesMustBeUpdatedByIncrementalBackup()
        public virtual void FulltextIndexesMustBeUpdatedByIncrementalBackup()
        {
            InitializeTestData();
            File backup = _dir.databaseDir("backup");

            OnlineBackup.from("127.0.0.1", _backupPort).backup(backup);

            long nodeId3;
            long nodeId4;
            long relId2;

            using (Transaction tx = _db.beginTx())
            {
                Node node3 = _db.createNode(_label);
                node3.SetProperty(PROP, "Additional data.");
                Node node4 = _db.createNode(_label);
                node4.SetProperty(PROP, "Even more additional data.");
                Relationship rel = node3.CreateRelationshipTo(node4, _rel);
                rel.SetProperty(PROP, "Knows of");
                nodeId3 = node3.Id;
                nodeId4 = node4.Id;
                relId2  = rel.Id;
                tx.Success();
            }
            VerifyData(_db);

            OnlineBackup.from("127.0.0.1", _backupPort).backup(backup);
            _db.shutdown();

            GraphDatabaseAPI backupDb = StartBackupDatabase(backup);

            VerifyData(backupDb);

            using (Transaction tx = backupDb.BeginTx())
            {
                using (Result nodes = backupDb.Execute(format(QUERY_NODES, NODE_INDEX, "additional")))
                {
                    IList <long> nodeIds = nodes.Select(m => (( Node )m.get(NODE)).Id).ToList();
                    assertThat(nodeIds, containsInAnyOrder(nodeId3, nodeId4));
                }
                using (Result relationships = backupDb.Execute(format(QUERY_RELS, REL_INDEX, "knows")))
                {
                    IList <long> relIds = relationships.Select(m => (( Relationship )m.get(RELATIONSHIP)).Id).ToList();
                    assertThat(relIds, containsInAnyOrder(relId2));
                }
                tx.Success();
            }
        }
Example #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void modifiedNodeImpliesLock()
        public virtual void ModifiedNodeImpliesLock()
        {
            Node node = CreateNode();

            using (Transaction ignore = _graphDb.beginTx())
            {
                node.SetProperty("key", "value");

                IList <LockInfo> locks = _lockManager.Locks;
                assertEquals("unexpected lock count", 1, locks.Count);
                LockInfo @lock = locks[0];
                assertNotNull("null lock", @lock);
            }
            IList <LockInfo> locks = _lockManager.Locks;

            assertEquals("unexpected lock count", 0, locks.Count);
        }
Example #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.graphdb.Node node(long id) throws NodeNotFoundException
        private Node Node(long id)
        {
            try
            {
                using (Transaction tx = _graphDb.beginTx())
                {
                    Node node = _graphDb.getNodeById(id);

                    tx.Success();
                    return(node);
                }
            }
            catch (NotFoundException e)
            {
                throw new NodeNotFoundException(e);
            }
        }
Example #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void getAllNodesIteratorShouldPickUpHigherIdsThanHighIdWhenStarted() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void getAllNodesIteratorShouldPickUpHigherIdsThanHighIdWhenStarted()
        {
            {
                // GIVEN
                Transaction tx = _db.beginTx();
                _db.createNode();
                _db.createNode();
                tx.Success();
                tx.Close();
            }

            // WHEN iterator is started
            Transaction        transaction = _db.beginTx();
            IEnumerator <Node> allNodes    = _db.AllNodes.GetEnumerator();

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            allNodes.next();

            // and WHEN another node is then added
            Thread thread = new Thread(() =>
            {
                Transaction newTx = _db.beginTx();
                assertThat(newTx, not(instanceOf(typeof(PlaceboTransaction))));
                _db.createNode();
                newTx.success();
                newTx.close();
            });

            thread.Start();
            thread.Join();

            // THEN the new node is picked up by the iterator
            assertThat(addToCollection(allNodes, new List <>()).size(), @is(2));
            transaction.Close();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverCreationOfUniquenessConstraintFollowedByDeletionOfThatSameConstraint() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecoverCreationOfUniquenessConstraintFollowedByDeletionOfThatSameConstraint()
        {
            // given
            CreateUniqueConstraint();
            DropConstraints();

            // when - perform recovery
            Restart(Snapshot(StoreDir.absolutePath()));

            // then - just make sure the constraint is gone
            using (Transaction tx = _db.beginTx())
            {
                assertFalse(_db.schema().getConstraints(_label).GetEnumerator().hasNext());
                tx.Success();
            }
        }
Example #12
0
            public override string ListTransactions()
            {
                string res;

                try
                {
                    using (Transaction tx = GraphDatabaseAPI.beginTx())
                    {
                        res = GraphDatabaseAPI.execute("CALL dbms.listTransactions()").resultAsString();

                        tx.Success();
                    }
                }
                catch (QueryExecutionException)
                {
                    res = "dbms.listTransactions() is not available";
                }
                return(res);
            }
Example #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testForceOpenIfChanged()
        public virtual void TestForceOpenIfChanged()
        {
            // do some actions to force the indexreader to be reopened
            using (Transaction tx = _graphDb.beginTx())
            {
                Node node1 = _graphDb.getNodeById(_id1);
                Node node2 = _graphDb.getNodeById(_id2);
                Node node3 = _graphDb.getNodeById(_id3);

                node1.SetProperty("np2", "test property");

                node1.GetRelationships(RelationshipType.withName("FOO")).forEach(Relationship.delete);

                // check first node
                Relationship rel;
                using (IndexHits <Relationship> hits = RelationShipAutoIndex().get("type", "FOO", node1, node3))
                {
                    assertEquals(0, hits.Size());
                }
                // create second relation ship
                rel = node1.CreateRelationshipTo(node3, RelationshipType.withName("FOO"));
                rel.SetProperty("type", "FOO");

                // check second node -> crashs with old FullTxData
                using (IndexHits <Relationship> indexHits = RelationShipAutoIndex().get("type", "FOO", node1, node2))
                {
                    assertEquals(0, indexHits.Size());
                }
                // create second relation ship
                rel = node1.CreateRelationshipTo(node2, RelationshipType.withName("FOO"));
                rel.SetProperty("type", "FOO");
                using (IndexHits <Relationship> relationships = RelationShipAutoIndex().get("type", "FOO", node1, node2))
                {
                    assertEquals(1, relationships.Size());
                }

                tx.Success();
            }
        }
Example #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.server.rest.repr.NodeRepresentation createNode(java.util.Map<String, Object> properties, org.neo4j.graphdb.Label... labels) throws PropertyValueException
        public override NodeRepresentation CreateNode(IDictionary <string, object> properties, params Label[] labels)
        {
            using (Transaction transaction = _graph.beginTx())
            {
                NodeRepresentation nodeRepresentation = base.CreateNode(properties, labels);
                transaction.Success();
                return(nodeRepresentation);
            }
        }
Example #15
0
 public override Transaction BeginTx(long timeout, TimeUnit timeUnit)
 {
     return(GraphDatabaseAPI.beginTx(timeout, timeUnit));
 }
Example #16
0
 public override Transaction BeginTx()
 {
     return(GraphDatabaseAPI.beginTx());
 }
Example #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverTransactionWhereNodeIsDeletedInTheFuture() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecoverTransactionWhereNodeIsDeletedInTheFuture()
        {
            // GIVEN
            Node node = CreateNodeWithProperty("key", "value", _label);

            CheckPoint();
            SetProperty(node, "other-key", 1);
            DeleteNode(node);
            _flush.flush(_db);

            // WHEN
            CrashAndRestart();

            // THEN
            // -- really the problem was that recovery threw exception, so mostly assert that.
            try
            {
                using (Transaction tx = _db.beginTx())
                {
                    node = _db.getNodeById(node.Id);
                    tx.Success();
                    fail("Should not exist");
                }
            }
            catch (NotFoundException e)
            {
                assertEquals("Node " + node.Id + " not found", e.Message);
            }
        }
Example #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void beginTx()
        public virtual void BeginTx()
        {
            _tx = _db.beginTx();
        }