Beispiel #1
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);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testMultipleCreate() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestMultipleCreate()
        {
            const int numThreads = 25;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String uuid = java.util.UUID.randomUUID().toString();
            string uuid = System.Guid.randomUUID().ToString();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Node commonNode;
            Node commonNode;

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

            ExecutorCompletionService <Node> ecs = new ExecutorCompletionService <Node>(Executors.newFixedThreadPool(numThreads));

            for (int i = 0; i < numThreads; i++)
            {
                ecs.submit(() =>
                {
                    using (Transaction tx = _graphDb.beginTx())
                    {
                        Node node = _graphDb.createNode();
                        // Acquire lock
                        tx.AcquireWriteLock(commonNode);
                        Index <Node> index = _graphDb.index().forNodes("uuids");
                        Node existing      = index.get("uuid", uuid).Single;
                        if (existing != null)
                        {
                            throw new Exception("Node already exists");
                        }
                        node.setProperty("uuid", uuid);
                        index.add(node, "uuid", uuid);
                        tx.Success();
                        return(node);
                    }
                });
            }
            int numSucceeded = 0;

            for (int i = 0; i < numThreads; i++)
            {
                try
                {
                    ecs.take().get();
                    ++numSucceeded;
                }
                catch (ExecutionException)
                {
                }
            }
            assertEquals(1, numSucceeded);
        }
Beispiel #3
0
        private Node CreateNode(Label label, params object[] properties)
        {
            Node node = _db.createNode(label);

            foreach (KeyValuePair <string, object> property in map(properties).entrySet())
            {
                node.SetProperty(property.Key, property.Value);
            }
            return(node);
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void createInitialData()
        public virtual void CreateInitialData()
        {
            BeginTx();
            _index = _graphDb.index().forNodes(INDEX_NAME);
            _index.delete();
            RestartTx();

            _index = _graphDb.index().forNodes(INDEX_NAME);
            _key   = "key";

            _value = "my own value";
            _node  = _graphDb.createNode();
            _index.add(_node, _key, _value);
            _workers = new List <WorkThread>();
        }
Beispiel #5
0
            internal virtual Node CreateNode()
            {
                Node node = Db.createNode();

                Nodes.Add(node);
                return(node);
            }
Beispiel #6
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();
     }
 }
Beispiel #7
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);
        }
 private void CreateNode()
 {
     using (Transaction transaction = _db.beginTx())
     {
         _db.createNode();
         transaction.Success();
     }
 }
Beispiel #9
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();
     }
 }
Beispiel #10
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);
        }
Beispiel #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = TEST_TIMEOUT) public void indexCreationDoNotBlockQueryExecutions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void IndexCreationDoNotBlockQueryExecutions()
        {
            Label nodeLabel = Label.label("nodeLabel");

            using (Transaction transaction = _database.beginTx())
            {
                _database.createNode(nodeLabel);
                transaction.Success();
            }

            using (Transaction transaction = _database.beginTx())
            {
                _database.schema().indexFor(Label.label("testLabel")).on("testProperty").create();

                Future <Number> countFuture = _executorService.submit(CountNodes());
                assertEquals(1, countFuture.get().intValue());

                transaction.Success();
            }
        }
Beispiel #12
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);
            }
        }
Beispiel #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void addingUniquenessConstraintWhenDuplicateDataExistsGivesNiceError()
        public virtual void AddingUniquenessConstraintWhenDuplicateDataExistsGivesNiceError()
        {
            // GIVEN
            using (Transaction transaction = _db.beginTx())
            {
                _db.createNode(_label).setProperty(_propertyKey, "value1");
                _db.createNode(_label).setProperty(_propertyKey, "value1");
                transaction.Success();
            }

            // WHEN
            try
            {
                CreateUniquenessConstraint(_label, _propertyKey);
                fail("Expected exception to be thrown");
            }
            catch (ConstraintViolationException e)
            {
                assertThat(e.Message, containsString("Unable to create CONSTRAINT ON ( my_label:MY_LABEL ) ASSERT my_label.my_property_key IS UNIQUE"));
            }
        }
Beispiel #14
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();
     }
 }
Beispiel #15
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();
     }
 }
Beispiel #17
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);
            }
        }
Beispiel #18
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();
                        }
                    }
                }
            }
Beispiel #19
0
        public virtual Node MakeNode(string id, IDictionary <string, object> properties)
        {
            Node node = GraphDb.createNode();

            Nodes[id]       = node;
            NodeNames[node] = id;
            node.SetProperty(KEY_ID, id);
            foreach (KeyValuePair <string, object> property in properties.SetOfKeyValuePairs())
            {
                if (property.Key.Equals(KEY_ID))
                {
                    throw new Exception("Can't use '" + property.Key + "'");
                }
                node.SetProperty(property.Key, property.Value);
            }
            return(node);
        }
Beispiel #20
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);
        }
Beispiel #21
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);
                    }
                }
            }
Beispiel #22
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);
            }
Beispiel #23
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);
                    }
                }
            }
Beispiel #24
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void createAndVerifyGraphStartingWithId(long startId, int requiredHeapMb) throws Exception
        private void CreateAndVerifyGraphStartingWithId(long startId, int requiredHeapMb)
        {
            assumeTrue(MachineIsOkToRunThisTest(requiredHeapMb));

            /*
             * Will create a layout like this:
             *
             * (refNode) --> (node) --> (highNode)
             *           ...
             *           ...
             *
             * Each node/relationship will have a bunch of different properties on them.
             */
            Node refNode = CreateReferenceNode(_db);

            HighIds = startId - 1000;

            sbyte[] bytes = new sbyte[45];
            bytes[2]  = 5;
            bytes[10] = 42;
            IDictionary <string, object> properties = map("number", 11, "short string", "test", "long string", "This is a long value, long enough", "array", bytes);
            Transaction tx    = _db.beginTx();
            int         count = 10000;

            for (int i = 0; i < count; i++)
            {
                Node node = _db.createNode();
                SetProperties(node, properties);
                Relationship rel1 = refNode.CreateRelationshipTo(node, this);
                SetProperties(rel1, properties);
                Node         highNode = _db.createNode();
                Relationship rel2     = node.CreateRelationshipTo(highNode, _otherType);
                SetProperties(rel2, properties);
                SetProperties(highNode, properties);
                if (i % 100 == 0 && i > 0)
                {
                    tx.Success();
                    tx.Close();
                    tx = _db.beginTx();
                }
            }
            tx.Success();
            tx.Close();

            _db = DbRule.restartDatabase();

            // Verify the data
            int verified = 0;

            using (Transaction transaction = _db.beginTx())
            {
                refNode = _db.getNodeById(refNode.Id);
                foreach (Relationship rel in refNode.GetRelationships(Direction.OUTGOING))
                {
                    Node node = rel.EndNode;
                    AssertProperties(properties, node);
                    AssertProperties(properties, rel);
                    Node highNode = node.GetSingleRelationship(_otherType, Direction.OUTGOING).EndNode;
                    AssertProperties(properties, highNode);
                    verified++;
                }
                transaction.Success();
            }
            assertEquals(count, verified);
        }
Beispiel #25
0
 public virtual void CreateNode()
 {
     Db.createNode();
 }
Beispiel #26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testNodeWithProperties()
        public virtual void TestNodeWithProperties()
        {
            _gdb.createNode().setProperty("name", "Andres");
            assertEquals("create (_0 {`name`:\"Andres\"})" + lineSeparator() + ";" + lineSeparator(), DoExportGraph(_gdb));
        }