//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            _db = DbRule.GraphDatabaseAPI;
            if (WithIndex)
            {
                using (Org.Neo4j.Graphdb.Transaction tx = _db.beginTx())
                {
                    _db.schema().indexFor(_label).on(Keys[0]).create();

                    IndexCreator indexCreator = _db.schema().indexFor(_label);
                    foreach (string key in Keys)
                    {
                        indexCreator = indexCreator.On(key);
                    }
                    indexCreator.Create();
                    tx.Success();
                }

                using (Org.Neo4j.Graphdb.Transaction tx = _db.beginTx())
                {
                    _db.schema().awaitIndexesOnline(5, TimeUnit.MINUTES);
                    tx.Success();
                }
            }
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void createIndexWithProviderThatUsesNeoAsDataSource()
        internal virtual void CreateIndexWithProviderThatUsesNeoAsDataSource()
        {
            string indexName = "inneo";

            assertFalse(IndexExists(indexName));
            IDictionary <string, string> config = stringMap(PROVIDER, "test-dummy-neo-index", "config1", "A value", "another config", "Another value");

            Index <Node> index;

            using (Transaction transaction = _db.beginTx())
            {
                index = _db.index().forNodes(indexName, config);
                transaction.Success();
            }

            using (Transaction tx = _db.beginTx())
            {
                assertTrue(IndexExists(indexName));
                assertEquals(config, _db.index().getConfiguration(index));
                using (IndexHits <Node> indexHits = index.get("key", "something else"))
                {
                    assertEquals(0, Iterables.count(indexHits));
                }
                tx.Success();
            }

            RestartDb();

            using (Transaction tx = _db.beginTx())
            {
                assertTrue(IndexExists(indexName));
                assertEquals(config, _db.index().getConfiguration(index));
                tx.Success();
            }
        }
Ejemplo n.º 3
0
        private DbRepresentation CreateTransactionWithWeirdRelationshipGroupRecord(File path)
        {
            _db = StartGraphDatabase(path);
            int              i = 0;
            Node             node;
            RelationshipType typeToDelete = RelationshipType.withName("A");
            RelationshipType theOtherType = RelationshipType.withName("B");
            int              defaultDenseNodeThreshold = int.Parse(GraphDatabaseSettings.dense_node_threshold.DefaultValue);

            using (Transaction tx = _db.beginTx())
            {
                node = _db.createNode();
                for ( ; i < defaultDenseNodeThreshold - 1; i++)
                {
                    node.CreateRelationshipTo(_db.createNode(), theOtherType);
                }
                node.CreateRelationshipTo(_db.createNode(), typeToDelete);
                tx.Success();
            }
            using (Transaction tx = _db.beginTx())
            {
                node.CreateRelationshipTo(_db.createNode(), theOtherType);
                foreach (Relationship relationship in node.GetRelationships(Direction.BOTH, typeToDelete))
                {
                    relationship.Delete();
                }
                tx.Success();
            }
            DbRepresentation result = DbRepresentation.of(_db);

            _db.shutdown();
            return(result);
        }
Ejemplo n.º 4
0
 public virtual void BeginTx()
 {
     if (_tx == null)
     {
         _tx = _graphDb.beginTx();
     }
 }
Ejemplo n.º 5
0
        public virtual Node NewState(ClusterState state)
        {
            using (Transaction tx = _gds.beginTx())
            {
                Node node = _gds.createNode(label("State"));
                node.SetProperty("description", state.ToString());
                tx.Success();

                _stateNodes[state] = node;
                return(node);
            }
        }
Ejemplo n.º 6
0
 private TimelineIndex <PropertyContainer> NodeTimeline()
 {
     using (Transaction tx = _db.beginTx())
     {
         Index <Node> nodeIndex = _db.index().forNodes("timeline");
         tx.Success();
         return(new LuceneTimeline(_db, nodeIndex));
     }
 }
Ejemplo n.º 7
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()
        {
            if (Tx == null)
            {
                Tx = GraphDb.beginTx();
            }
        }
Ejemplo n.º 8
0
 public override void Run()
 {
     try
     {
         while (!outerInstance.stop)
         {
             try
             {
                 using (Transaction transaction = Database.beginTx())
                 {
                     Label[]             createdLabels = outerInstance.Labels;
                     Node                node          = Database.createNode(createdLabels);
                     IEnumerable <Label> nodeLabels    = node.Labels;
                     assertEquals(asSet(asList(createdLabels)), asSet(nodeLabels));
                     transaction.Success();
                 }
             }
             catch (Exception e)
             {
                 outerInstance.stop = true;
                 throw e;
             }
         }
     }
     finally
     {
         CreateLatch.Signal();
     }
 }
Ejemplo n.º 9
0
        public override void Run()
        {
            do
            {
                try
                {
                    using (Transaction tx = _db.beginTx())
                    {
                        for (int i = 0; i < _numOpsPerTx; i++)
                        {
                            _randomMutation.perform();
                        }
                        tx.Success();
                    }
                }
                catch (DeadlockDetectedException)
                {
                    // simply give up
                }
                catch (Exception e)
                {
                    // ignore and go on
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                }

                _monitor.transactionCompleted();
            } while (!_monitor.stop());

            _monitor.done();
        }
Ejemplo n.º 10
0
            public override void Run()
            {
                for (int i = 0; i < OPERATIONS_COUNT; i++)
                {
                    long highestId = HighestNodeId(Db);
                    if (highestId > 0)
                    {
                        long id = ThreadLocalRandom.current().nextLong(highestId);

                        try
                        {
                            using (Transaction tx = Db.beginTx())
                            {
                                Db.getNodeById(id).delete();
                                tx.Success();
                            }
                        }
                        catch (NotFoundException)
                        {
                            // same node was removed concurrently
                        }
                    }

                    MaybeRunIdMaintenance(Db, i);
                }
            }
Ejemplo n.º 11
0
 public override void Accept(DbStructureVisitor visitor)
 {
     using (Transaction tx = _db.beginTx())
     {
         ShowStructure(_bridge.getKernelTransactionBoundToThisThread(true), visitor);
         tx.Success();
     }
 }
Ejemplo n.º 12
0
 private void CreateNode()
 {
     using (Transaction transaction = _db.beginTx())
     {
         _db.createNode();
         transaction.Success();
     }
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSupportIndexSeek()
        public virtual void ShouldSupportIndexSeek()
        {
            // GIVEN
            CreateNodes(_db, _label, _nonMatching);
            LongSet expected = CreateNodes(_db, _label, _matching);

            // WHEN
            MutableLongSet found = new LongHashSet();

            using (Transaction tx = _db.beginTx())
            {
                CollectNodes(found, _db.findNodes(_label, _key, _template, _searchMode));
            }

            // THEN
            assertThat(found, equalTo(expected));
        }
Ejemplo n.º 14
0
 public override void Run()
 {
     using (Transaction tx = Db.beginTx())
     {
         Index <Node> index = Db.index().forNodes("myIndex");
         index.Add(Db.createNode(), "one", "two");
         tx.Success();
     }
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            _label = Label.label("LABEL1-" + TestName.MethodName);
            _db    = DbRule.GraphDatabaseAPI;
            if (_withIndex)
            {
                using (Org.Neo4j.Graphdb.Transaction tx = _db.beginTx())
                {
                    _db.schema().indexFor(_label).on(_key).create();
                    tx.Success();
                }

                using (Org.Neo4j.Graphdb.Transaction tx = _db.beginTx())
                {
                    _db.schema().awaitIndexesOnline(5, TimeUnit.MINUTES);
                    tx.Success();
                }
            }
        }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: private Thread newThreadForNodeAction(final long nodeId, final System.Action<org.neo4j.graphdb.Node> nodeConsumer)
        private Thread NewThreadForNodeAction(long nodeId, System.Action <Node> nodeConsumer)
        {
            return(new Thread(() =>
            {
                try
                {
                    using (Transaction tx = _db.beginTx())
                    {
                        Node node = _db.getNodeById(nodeId);
                        _barrier.await();
                        nodeConsumer(node);
                        tx.success();
                    }
                }
                catch (Exception e)
                {
                    _ex.set(e);
                }
            }));
        }
Ejemplo n.º 17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotMakeIndexWritesVisibleUntilCommit() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotMakeIndexWritesVisibleUntilCommit()
        {
            Node commonNode;

            using (Transaction tx = _graphDatabaseService.beginTx())
            {
                commonNode = _graphDatabaseService.createNode();
                tx.Success();
            }

            using (Transaction transaction = _graphDatabaseService.beginTx())
            {
                // index write first so that that datastore is added first
                _graphDatabaseService.index().forNodes(INDEX_NAME).add(commonNode, INDEX_KEY, INDEX_VALUE);
                commonNode.SetProperty(PROPERTY_NAME, PROPERTY_VALUE);

                AssertNodeIsNotIndexedOutsideThisTransaction();
                AssertNodeIsUnchangedOutsideThisTransaction(commonNode);

                transaction.Success();

                AssertNodeIsNotIndexedOutsideThisTransaction();
                AssertNodeIsUnchangedOutsideThisTransaction(commonNode);
            }

            AssertNodeIsIndexed(commonNode);
            AssertNodeHasBeenUpdated(commonNode);
        }
Ejemplo n.º 18
0
            public override void Run()
            {
                for (int i = 0; i < OPERATIONS_COUNT; i++)
                {
                    using (Transaction tx = Db.beginTx())
                    {
                        Db.createNode();
                        tx.Success();
                    }

                    MaybeRunIdMaintenance(Db, i);
                }
            }
 public override void Run()
 {
     while (!Start.get())
     {
         // spin
     }
     using (Transaction tx = Db.beginTx())
     {
         Node node = Db.createNode();
         node.SetProperty(PropertyKey, PropertyValue);
         Db.index().forNodes(INDEX_NAME).add(node, PropertyKey, PropertyValue);
         tx.Success();
     }
 }
Ejemplo n.º 20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testGetIndexPopulationProgress() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void TestGetIndexPopulationProgress()
        {
            assertFalse(IndexExists(_userLabel));

            // Create some nodes
            using (Transaction tx = _db.beginTx())
            {
                Label label = Label.label("User");

                // Create a huge bunch of users so the index takes a while to build
                for (int id = 0; id < 100000; id++)
                {
                    Node userNode = _db.createNode(label);
                    userNode.SetProperty("username", "user" + id + "@neo4j.org");
                }
                tx.Success();
            }

            // Create an index
            IndexDefinition indexDefinition;

            using (Transaction tx = _db.beginTx())
            {
                Schema schema = _db.schema();
                indexDefinition = Schema.indexFor(_userLabel).on("username").create();
                tx.Success();
            }

            // Get state and progress
            using (Transaction ignore = _db.beginTx())
            {
                Schema schema = _db.schema();
                Org.Neo4j.Graphdb.schema.Schema_IndexState state;

                IndexPopulationProgress progress;
                do
                {
                    state    = Schema.getIndexState(indexDefinition);
                    progress = Schema.getIndexPopulationProgress(indexDefinition);

                    assertTrue(progress.CompletedPercentage >= 0);
                    assertTrue(progress.CompletedPercentage <= 100);
                    Thread.Sleep(10);
                } while (state == Org.Neo4j.Graphdb.schema.Schema_IndexState.Populating);

                assertSame(state, Org.Neo4j.Graphdb.schema.Schema_IndexState.Online);
                assertEquals(100.0, progress.CompletedPercentage, 0.0001);
            }
        }
Ejemplo n.º 21
0
            public override void Run()
            {
                RandomValues randomValues = RandomValues.create();

                awaitLatch(StartSignal);
                while (!EndSignal.get())
                {
                    using (Transaction transaction = DatabaseService.beginTx())
                    {
                        try
                        {
                            int operationType = randomValues.NextIntValue(3).value();
                            switch (operationType)
                            {
                            case 0:
                                long targetNodeId = randomValues.NextLongValue(TotalNodes).value();
                                DatabaseService.getNodeById(targetNodeId).delete();
                                break;

                            case 1:
                                long nodeId = randomValues.NextLongValue(TotalNodes).value();
                                Node node   = DatabaseService.getNodeById(nodeId);
                                IDictionary <string, object> allProperties = node.AllProperties;
                                foreach (string key in allProperties.Keys)
                                {
                                    node.SetProperty(key, randomValues.NextValue().asObject());
                                }
                                break;

                            case 2:
                                Node nodeToUpdate = DatabaseService.createNode(Label.label("label10"));
                                nodeToUpdate.SetProperty("property", randomValues.NextValue().asObject());
                                break;

                            default:
                                throw new System.NotSupportedException("Unknown type of index operation");
                            }
                            transaction.Success();
                        }
                        catch (Exception)
                        {
                            transaction.Failure();
                        }
                    }
                }
            }
Ejemplo n.º 22
0
        private DbRepresentation AddMoreData2(File path)
        {
            _db = StartGraphDatabase(path);
            using (Transaction tx = _db.beginTx())
            {
                Node donald    = _db.getNodeById(2);
                Node gladstone = _db.createNode();
                gladstone.SetProperty("name", "Gladstone");
                Relationship hates = donald.CreateRelationshipTo(gladstone, RelationshipType.withName("HATES"));
                hates.SetProperty("since", 1948);
                tx.Success();
            }
            DbRepresentation result = DbRepresentation.of(_db);

            _db.shutdown();
            return(result);
        }
 public override void Run()
 {
     while (!Start.get())
     {
         // spin
     }
     Sleep();
     using (Transaction tx = Db.beginTx())
     {
         // it is acceptable to either see a node with correct property or not see it at all
         Node node = Db.index().forNodes(INDEX_NAME).get(PropertyKey, PropertyValue).Single;
         if (node != null)
         {
             assertEquals(PropertyValue, node.GetProperty(PropertyKey));
         }
         tx.Success();
     }
 }
Ejemplo n.º 24
0
            public override void Run()
            {
                ThreadLocalRandom localRandom = ThreadLocalRandom.current();

                while (!Canceled)
                {
                    PageCursorCounters pageCursorCounters;
                    using (Transaction transaction = Db.beginTx(), KernelStatement kernelStatement = GetKernelStatement((GraphDatabaseAPI)Db))
                    {
                        pageCursorCounters = kernelStatement.PageCursorTracer;
                        Node node = Db.createNode();
                        node.SetProperty("name", RandomStringUtils.random(localRandom.Next(100)));
                        node.SetProperty("surname", RandomStringUtils.random(localRandom.Next(100)));
                        node.SetProperty("age", localRandom.Next(100));
                        transaction.Success();
                        StoreCounters(pageCursorCounters);
                    }
                }
            }
Ejemplo n.º 25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @GET @Path("createConstraint") public javax.ws.rs.core.Response createProperty()
        public virtual Response CreateProperty()
        {
            try
            {
                using (Transaction tx = _db.beginTx())
                {
                    using (Result result = _db.execute("CREATE CONSTRAINT ON (user:User) ASSERT exists(user.name)"))
                    {
                        // nothing to-do
                    }
                    tx.Success();
                    return(Response.status(HttpStatus.CREATED_201).build());
                }
            }
            catch (Exception)
            {
                return(Response.status(HttpStatus.NOT_IMPLEMENTED_501).build());
            }
        }
Ejemplo n.º 26
0
        private DbRepresentation CreateInitialDataSet(File path)
        {
            _db = StartGraphDatabase(path);
            using (Transaction tx = _db.beginTx())
            {
                _db.createNode().setProperty("name", "Goofy");
                Node donald = _db.createNode();
                donald.SetProperty("name", "Donald");
                Node daisy = _db.createNode();
                daisy.SetProperty("name", "Daisy");
                Relationship knows = donald.CreateRelationshipTo(daisy, RelationshipType.withName("LOVES"));
                knows.SetProperty("since", 1940);
                tx.Success();
            }
            DbRepresentation result = DbRepresentation.of(_db);

            _db.shutdown();
            return(result);
        }
Ejemplo n.º 27
0
            internal virtual int InsertBatchNodes(GraphDatabaseService db, System.Func <string> stringValueSupplier, System.Func <long> longSupplier)
            {
                using (Transaction transaction = Db.beginTx())
                {
                    for (int i = 0; i < _batchSize; i++)
                    {
                        Node node = Db.createNode(Label.label(LABEL));

                        string stringValue = stringValueSupplier();
                        long   longValue   = longSupplier();

                        node.SetProperty(StringProperty, stringValue);
                        node.SetProperty(LongProperty, longValue);

                        node.SetProperty(UniqueStringProperty, stringValue);
                        node.SetProperty(UniqueLongProperty, longValue);
                    }
                    transaction.Success();
                }
                return(_batchSize);
            }
Ejemplo n.º 28
0
 public virtual void Execute()
 {
     for (int attemptsLeft = _attempts - 1; attemptsLeft >= 0; attemptsLeft--)
     {
         try
         {
             using (Transaction tx = _graphDb.beginTx())
             {
                 _unitOfWork.doWork();
                 tx.Success();
             }
         }
         catch (Exception e)
         {
             if (attemptsLeft == 0)
             {
                 throw e;
             }
         }
     }
 }
Ejemplo n.º 29
0
 private void InitDatabase()
 {
     using (Transaction transaction = _db.beginTx())
     {
         Node fry = _db.createNode();
         fry.SetProperty("name", "Fry");
         fry.SetProperty("profession", "Delivery Boy");
         fry.SetProperty("planet", "Earth");
         fry.SetProperty("city", "New York");
         Node lila = _db.createNode();
         lila.SetProperty("name", "Lila");
         lila.SetProperty("profession", "Pilot");
         lila.SetProperty("planet", "Earth");
         lila.SetProperty("city", "New York");
         Node amy = _db.createNode();
         amy.SetProperty("name", "Amy");
         amy.SetProperty("profession", "Student");
         amy.SetProperty("planet", "Mars");
         transaction.Success();
     }
 }
Ejemplo n.º 30
0
            public override void Run()
            {
                AwaitStartSignal();
                while (Failure.get() == null && !StopSignal.get())
                {
                    try
                    {
                        using (Transaction tx = Db.beginTx())
                        {
                            // ArrayIndexOutOfBoundsException happens here
                            Iterables.count(ParentNode.getRelationships(RELTYPE, OUTGOING));

                            ParentNode.createRelationshipTo(Db.createNode(), RELTYPE);
                            tx.Success();
                        }
                    }
                    catch (Exception e)
                    {
                        Failure.compareAndSet(null, e);
                    }
                }
            }