private StoreAccess CreateStoreWithOneHighDegreeNodeAndSeveralDegreeTwoNodes(int nDegreeTwoNodes)
        {
            File storeDirectory           = _testDirectory.databaseDir();
            GraphDatabaseService database = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(storeDirectory).setConfig(GraphDatabaseSettings.record_format, RecordFormatName).setConfig("dbms.backup.enabled", "false").newGraphDatabase();

            using (Transaction transaction = database.BeginTx())
            {
                Node denseNode = database.CreateNode();
                for (int i = 0; i < nDegreeTwoNodes; i++)
                {
                    Node degreeTwoNode = database.CreateNode();
                    Node leafNode      = database.CreateNode();
                    if (i % 2 == 0)
                    {
                        denseNode.CreateRelationshipTo(degreeTwoNode, TestRelationshipType.Connected);
                    }
                    else
                    {
                        degreeTwoNode.CreateRelationshipTo(denseNode, TestRelationshipType.Connected);
                    }
                    degreeTwoNode.CreateRelationshipTo(leafNode, TestRelationshipType.Connected);
                }
                transaction.Success();
            }
            database.Shutdown();
            PageCache   pageCache   = PageCacheRule.getPageCache(_fileSystemRule.get());
            StoreAccess storeAccess = new StoreAccess(_fileSystemRule.get(), pageCache, _testDirectory.databaseLayout(), Config.defaults());

            return(storeAccess.Initialize());
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAccountForRemovedLabels()
        public virtual void ShouldAccountForRemovedLabels()
        {
            // given
            GraphDatabaseService graphDb = Db.GraphDatabaseAPI;
            Node n1;
            Node n2;
            Node n3;

            using (Transaction tx = graphDb.BeginTx())
            {
                n1 = graphDb.CreateNode(label("Foo"), label("Bar"));
                n2 = graphDb.CreateNode(label("Bar"));
                n3 = graphDb.CreateNode(label("Foo"));

                tx.Success();
            }
            using (Transaction tx = graphDb.BeginTx())
            {
                n1.RemoveLabel(label("Bar"));
                n2.RemoveLabel(label("Bar"));
                n3.RemoveLabel(label("Foo"));

                tx.Success();
            }

            // when
            long fooCount = NumberOfNodesWith(label("Foo"));
            long barCount = NumberOfNodesWith(label("Bar"));

            // then
            assertEquals(1, fooCount);
            assertEquals(0, barCount);
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGiveNiceErrorWhenShutdownLegacy()
        public virtual void ShouldGiveNiceErrorWhenShutdownLegacy()
        {
            GraphDatabaseService graphDb = _graph;
            Node node = graphDb.CreateNode();

            Commit();
            graphDb.Shutdown();

            try
            {
                node.Relationships;
                fail("Did not get a nice exception");
            }
            catch (DatabaseShutdownException)
            {               // good
            }
            try
            {
                graphDb.CreateNode();
                fail("Create node did not produce expected error");
            }
            catch (DatabaseShutdownException)
            {               // good
            }
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAccountForDeletedNodes()
        public virtual void ShouldAccountForDeletedNodes()
        {
            // given
            GraphDatabaseService graphDb = Db.GraphDatabaseAPI;
            Node node;

            using (Transaction tx = graphDb.BeginTx())
            {
                node = graphDb.CreateNode(label("Foo"));
                graphDb.CreateNode(label("Foo"));

                tx.Success();
            }
            using (Transaction tx = graphDb.BeginTx())
            {
                node.Delete();

                tx.Success();
            }

            // when
            long fooCount = NumberOfNodesWith(label("Foo"));

            // then
            assertEquals(1, fooCount);
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIncludeNumberOfNodesDeletedInTransaction()
        public virtual void ShouldIncludeNumberOfNodesDeletedInTransaction()
        {
            // given
            GraphDatabaseService graphDb = Db.GraphDatabaseAPI;
            Node one;

            using (Transaction tx = graphDb.BeginTx())
            {
                one = graphDb.CreateNode();
                graphDb.CreateNode();
                tx.Success();
            }
            long before = NumberOfNodes();

            using (Transaction tx = graphDb.BeginTx())
            {
                // when
                one.Delete();
                long nodeCount = CountsForNode();

                // then
                assertEquals(before - 1, nodeCount);
                tx.Success();
            }
        }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void compositeNodeKeyConstraintUpdate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CompositeNodeKeyConstraintUpdate()
        {
            GraphDatabaseService database = (new EnterpriseGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(TestDirectory.storeDir()).setConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).newGraphDatabase();

            Label label = Label.label("label");

            using (Transaction transaction = database.BeginTx())
            {
                Node node = database.CreateNode(label);
                node.SetProperty("b", ( short )3);
                node.SetProperty("a", new double[] { 0.6, 0.4, 0.2 });
                transaction.Success();
            }

            using (Transaction transaction = database.BeginTx())
            {
                string query = format("CREATE CONSTRAINT ON (n:%s) ASSERT (n.%s,n.%s) IS NODE KEY", label.Name(), "a", "b");
                database.Execute(query);
                transaction.Success();
            }

            AwaitIndex(database);

            using (Transaction transaction = database.BeginTx())
            {
                Node node = database.CreateNode(label);
                node.SetProperty("a", ( short )7);
                node.SetProperty("b", new double[] { 0.7, 0.5, 0.3 });
                transaction.Success();
            }
            database.Shutdown();

            ConsistencyCheckService.Result consistencyCheckResult = CheckDbConsistency(TestDirectory.storeDir());
            assertTrue("Database is consistent", consistencyCheckResult.Successful);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReportTotalNumberOfRelationships()
        public virtual void ShouldReportTotalNumberOfRelationships()
        {
            // given
            GraphDatabaseService graphDb = Db.GraphDatabaseAPI;
            long before = NumberOfRelationships();
            long during;

            using (Transaction tx = graphDb.BeginTx())
            {
                Node node = graphDb.CreateNode();
                node.CreateRelationshipTo(graphDb.CreateNode(), withName("KNOWS"));
                node.CreateRelationshipTo(graphDb.CreateNode(), withName("KNOWS"));
                node.CreateRelationshipTo(graphDb.CreateNode(), withName("KNOWS"));
                during = CountsForRelationship(null, null, null);
                tx.Success();
            }

            // when
            long after = NumberOfRelationships();

            // then
            assertEquals(0, before);
            assertEquals(3, during);
            assertEquals(3, after);
        }
        public override void CreateTestGraph(GraphDatabaseService graphDb)
        {
            using (Transaction tx = graphDb.BeginTx())
            {
                graphDb.Index().forNodes("foo").add(graphDb.CreateNode(), "bar", "this is it");
                Relationship edge = graphDb.CreateNode().createRelationshipTo(graphDb.CreateNode(), withName("LALA"));
                graphDb.Index().forRelationships("rels").add(edge, "alpha", "betting on the wrong string");

                tx.Success();
            }
        }
Beispiel #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void extractTransactionalInformationFromLogs(String path, java.io.File customLogLocation, org.neo4j.io.layout.DatabaseLayout databaseLayout, java.io.File storeDir) throws java.io.IOException
        private void ExtractTransactionalInformationFromLogs(string path, File customLogLocation, DatabaseLayout databaseLayout, File storeDir)
        {
            LogService logService = new SimpleLogService(NullLogProvider.Instance, NullLogProvider.Instance);
            File       neoStore   = databaseLayout.MetadataStore();

            GraphDatabaseService database = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(storeDir).setConfig(logical_logs_location, path).newGraphDatabase();

            for (int i = 0; i < 10; i++)
            {
                using (Transaction transaction = database.BeginTx())
                {
                    Node node = database.CreateNode();
                    transaction.Success();
                }
            }
            database.Shutdown();

            MetaDataStore.setRecord(_pageCache, neoStore, MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_VERSION, MetaDataRecordFormat.FIELD_NOT_PRESENT);
            Config        config      = Config.defaults(logical_logs_location, path);
            StoreMigrator migrator    = new StoreMigrator(_fileSystemRule.get(), _pageCache, config, logService, _jobScheduler);
            LogPosition   logPosition = migrator.ExtractTransactionLogPosition(neoStore, databaseLayout, 100);

            File[] logFiles = customLogLocation.listFiles();
            assertNotNull(logFiles);
            assertEquals(0, logPosition.LogVersion);
            assertEquals(logFiles[0].length(), logPosition.ByteOffset);
        }
Beispiel #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReportNumberOfNodes()
        public virtual void ShouldReportNumberOfNodes()
        {
            // given
            GraphDatabaseService graphDb = Db.GraphDatabaseAPI;

            using (Transaction tx = graphDb.BeginTx())
            {
                graphDb.CreateNode();
                graphDb.CreateNode();
                tx.Success();
            }

            // when
            long nodeCount = NumberOfNodes();

            // then
            assertEquals(2, nodeCount);
        }
Beispiel #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGetNumberOfNodesWithLabel()
        public virtual void ShouldGetNumberOfNodesWithLabel()
        {
            // given
            GraphDatabaseService graphDb = Db.GraphDatabaseAPI;

            using (Transaction tx = graphDb.BeginTx())
            {
                graphDb.CreateNode(label("Foo"));
                graphDb.CreateNode(label("Bar"));
                graphDb.CreateNode(label("Bar"));

                tx.Success();
            }

            // when
            long fooCount = NumberOfNodesWith(label("Foo"));
            long barCount = NumberOfNodesWith(label("Bar"));

            // then
            assertEquals(1, fooCount);
            assertEquals(2, barCount);
        }
Beispiel #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void question5346011()
        public virtual void Question5346011()
        {
            GraphDatabaseService service = (new TestGraphDatabaseFactory()).newImpermanentDatabase();

            using (Transaction tx = service.BeginTx())
            {
                RelationshipIndex index = service.Index().forRelationships("exact");
                // ...creation of the nodes and relationship
                Node         node1        = service.CreateNode();
                Node         node2        = service.CreateNode();
                string       uuid         = "xyz";
                Relationship relationship = node1.CreateRelationshipTo(node2, RelationshipType.withName("related"));
                index.add(relationship, "uuid", uuid);
                // query
                using (IndexHits <Relationship> hits = index.Get("uuid", uuid, node1, node2))
                {
                    assertEquals(1, hits.Size());
                }
                tx.Success();
            }
            service.Shutdown();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotCountRelationshipsDeletedInOtherTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotCountRelationshipsDeletedInOtherTransaction()
        {
            // given
            GraphDatabaseService graphDb = Db.GraphDatabaseAPI;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Relationship rel;
            Relationship rel;

            using (Transaction tx = graphDb.BeginTx())
            {
                Node node = graphDb.CreateNode();
                node.CreateRelationshipTo(graphDb.CreateNode(), withName("KNOWS"));
                rel = node.CreateRelationshipTo(graphDb.CreateNode(), withName("KNOWS"));
                node.CreateRelationshipTo(graphDb.CreateNode(), withName("KNOWS"));
                tx.Success();
            }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.Barrier_Control barrier = new org.neo4j.test.Barrier_Control();
            Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control();
            long          before = NumberOfRelationships();
            Future <long> tx     = Threading.execute(new NamedFunctionAnonymousInnerClass2(this, graphDb, rel, tx, barrier)
                                                     , graphDb);

            barrier.Await();

            // when
            long during = NumberOfRelationships();

            barrier.Release();
            long whatOtherThreadSees = tx.get();
            long after = NumberOfRelationships();

            // then
            assertEquals(3, before);
            assertEquals(3, during);
            assertEquals(2, after);
            assertEquals(after, whatOtherThreadSees);
        }
Beispiel #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void tracePageCacheFlushProgress()
        public virtual void TracePageCacheFlushProgress()
        {
            AssertableLogProvider logProvider = new AssertableLogProvider(true);
            GraphDatabaseService  database    = (new TestGraphDatabaseFactory()).setInternalLogProvider(logProvider).newEmbeddedDatabaseBuilder(TestDirectory.directory()).setConfig(GraphDatabaseSettings.tracer, "verbose").newGraphDatabase();

            using (Transaction transaction = database.BeginTx())
            {
                database.CreateNode();
                transaction.Success();
            }
            database.Shutdown();
            logProvider.FormattedMessageMatcher().assertContains("Flushing file");
            logProvider.FormattedMessageMatcher().assertContains("Page cache flush completed. Flushed ");
        }
Beispiel #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReportAccurateNumberOfNodesAfterDeletion()
        public virtual void ShouldReportAccurateNumberOfNodesAfterDeletion()
        {
            // given
            GraphDatabaseService graphDb = Db.GraphDatabaseAPI;
            Node one;

            using (Transaction tx = graphDb.BeginTx())
            {
                one = graphDb.CreateNode();
                graphDb.CreateNode();
                tx.Success();
            }
            using (Transaction tx = graphDb.BeginTx())
            {
                one.Delete();
                tx.Success();
            }

            // when
            long nodeCount = NumberOfNodes();

            // then
            assertEquals(1, nodeCount);
        }
Beispiel #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void canAvoidDeadlockThatWouldHappenIfTheRelationshipTypeCreationTransactionModifiedData()
        public virtual void CanAvoidDeadlockThatWouldHappenIfTheRelationshipTypeCreationTransactionModifiedData()
        {
            GraphDatabaseService graphdb = Database.GraphDatabaseAPI;
            Node node = null;

            using (Transaction tx = graphdb.BeginTx())
            {
                node = graphdb.CreateNode();
                node.SetProperty("counter", 0L);
                tx.Success();
            }

            graphdb.RegisterTransactionEventHandler(new RelationshipCounterTransactionEventHandler(node));

            using (Transaction tx = graphdb.BeginTx())
            {
                node.SetProperty("state", "not broken yet");
                node.CreateRelationshipTo(graphdb.CreateNode(), RelationshipType.withName("TEST"));
                node.RemoveProperty("state");
                tx.Success();
            }

            assertThat(node, inTx(graphdb, hasProperty("counter").withValue(1L)));
        }
Beispiel #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGiveNiceErrorWhenShutdownKernelApi()
        public virtual void ShouldGiveNiceErrorWhenShutdownKernelApi()
        {
            GraphDatabaseService graphDb = _graph;
            Node node = graphDb.CreateNode();

            Commit();
            graphDb.Shutdown();

            try
            {
                count(node.Labels.GetEnumerator());
                fail("Did not get a nice exception");
            }
            catch (DatabaseShutdownException)
            {               // good
            }
        }
Beispiel #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void storeMigrationToolShouldBeAbleToMigrateOldStore() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void StoreMigrationToolShouldBeAbleToMigrateOldStore()
        {
            StoreMigration.Main(new string[] { TestDir.databaseDir().AbsolutePath });

            // after migration we can open store and do something
            GraphDatabaseService database = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(TestDir.databaseDir()).setConfig(GraphDatabaseSettings.logs_directory, TestDir.directory("logs").AbsolutePath).newGraphDatabase();

            try
            {
                using (Transaction transaction = database.BeginTx())
                {
                    Node node = database.CreateNode();
                    node.SetProperty("key", "value");
                    transaction.Success();
                }
            }
            finally
            {
                database.Shutdown();
            }
        }
Beispiel #19
0
        private void Prepare34DatabaseWithNodes()
        {
            GraphDatabaseService embeddedDatabase = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(_storeDir);

            try
            {
                using (Transaction transaction = embeddedDatabase.BeginTx())
                {
                    for (int i = 0; i < 10; i++)
                    {
                        embeddedDatabase.CreateNode(Label.label("label" + i));
                    }
                    transaction.Success();
                }
            }
            finally
            {
                embeddedDatabase.Shutdown();
            }
            _fileSystem.deleteFile(_nativeLabelIndex);
        }
Beispiel #20
0
        private void SetAndRemoveSomeProperties(GraphDatabaseService graphDatabaseService, object value)
        {
            Node commonNode;

            using (Transaction transaction = graphDatabaseService.BeginTx())
            {
                commonNode = graphDatabaseService.CreateNode();
                for (int i = 0; i < 10; i++)
                {
                    commonNode.SetProperty("key" + i, value);
                }
                transaction.Success();
            }

            using (Transaction transaction = graphDatabaseService.BeginTx())
            {
                for (int i = 0; i < 10; i++)
                {
                    commonNode.RemoveProperty("key" + i);
                }
                transaction.Success();
            }
        }
Beispiel #21
0
        public override void CreateTestGraph(GraphDatabaseService graphDb)
        {
            using (Transaction tx = graphDb.BeginTx())
            {
                Node root = graphDb.CreateNode();
                _threeRoot = root.Id;

                Node[] leafs = new Node[32];
                for (int i = 0; i < leafs.Length; i++)
                {
                    leafs[i] = graphDb.CreateNode();
                }
                int offset = 0, duplicate = 12;

                Node interdup = graphDb.CreateNode();
                interdup.CreateRelationshipTo(root, _parent);
                offset = Relate(duplicate, leafs, offset, interdup);
                for (int i = 0; i < 5; i++)
                {
                    Node inter = graphDb.CreateNode();
                    inter.CreateRelationshipTo(root, _parent);
                    offset = Relate(3 + i, leafs, offset, inter);
                }
                interdup.CreateRelationshipTo(root, _parent);
                for (int i = 0; i < 4; i++)
                {
                    Node inter = graphDb.CreateNode();
                    inter.CreateRelationshipTo(root, _parent);
                    offset = Relate(2 + i, leafs, offset, inter);
                }

                Node inter = graphDb.CreateNode();
                inter.CreateRelationshipTo(root, _parent);
                offset = Relate(1, leafs, offset, inter);

                _expectedTotal  = offset + duplicate;
                _expectedUnique = leafs.Length;

                tx.Success();
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCountRelationshipsByType()
        public virtual void ShouldCountRelationshipsByType()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.GraphDatabaseService graphDb = db.getGraphDatabaseAPI();
            GraphDatabaseService graphDb = Db.GraphDatabaseAPI;

            using (Transaction tx = graphDb.BeginTx())
            {
                graphDb.CreateNode().createRelationshipTo(graphDb.CreateNode(), withName("FOO"));
                graphDb.CreateNode().createRelationshipTo(graphDb.CreateNode(), withName("FOO"));
                graphDb.CreateNode().createRelationshipTo(graphDb.CreateNode(), withName("BAR"));
                graphDb.CreateNode().createRelationshipTo(graphDb.CreateNode(), withName("BAR"));
                graphDb.CreateNode().createRelationshipTo(graphDb.CreateNode(), withName("BAR"));
                graphDb.CreateNode().createRelationshipTo(graphDb.CreateNode(), withName("BAZ"));
                tx.Success();
            }

            // when
            long total = NumberOfRelationships();
            long foo   = NumberOfRelationships(withName("FOO"));
            long bar   = NumberOfRelationships(withName("BAR"));
            long baz   = NumberOfRelationships(withName("BAZ"));
            long qux   = NumberOfRelationships(withName("QUX"));

            // then
            assertEquals(2, foo);
            assertEquals(3, bar);
            assertEquals(1, baz);
            assertEquals(0, qux);
            assertEquals(6, total);
        }