Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void createStore(java.io.File super, org.neo4j.io.fs.FileSystemAbstraction fileSystem, String dbName, int nodesToCreate, String recordFormat, boolean recoveryNeeded, String logicalLogsLocation) throws java.io.IOException
            internal static void CreateStore(File @base, FileSystemAbstraction fileSystem, string dbName, int nodesToCreate, string recordFormat, bool recoveryNeeded, string logicalLogsLocation)
            {
                File storeDir           = new File(@base, dbName);
                GraphDatabaseService db = (new TestGraphDatabaseFactory()).setFileSystem(fileSystem).newEmbeddedDatabaseBuilder(storeDir).setConfig(GraphDatabaseSettings.record_format, recordFormat).setConfig(OnlineBackupSettings.online_backup_enabled, false.ToString()).setConfig(GraphDatabaseSettings.logical_logs_location, logicalLogsLocation).newGraphDatabase();

                for (int i = 0; i < (nodesToCreate / 2); i++)
                {
                    using (Transaction tx = Db.beginTx())
                    {
                        Node node1 = Db.createNode(Label.label("Label-" + i));
                        Node node2 = Db.createNode(Label.label("Label-" + i));
                        node1.CreateRelationshipTo(node2, RelationshipType.withName("REL-" + i));
                        tx.Success();
                    }
                }

                if (recoveryNeeded)
                {
                    File tmpLogs = new File(@base, "unrecovered");
                    fileSystem.Mkdir(tmpLogs);
                    File txLogsDir = new File(storeDir, logicalLogsLocation);
                    foreach (File file in fileSystem.ListFiles(txLogsDir, TransactionLogFiles.DEFAULT_FILENAME_FILTER))
                    {
                        fileSystem.CopyFile(file, new File(tmpLogs, file.Name));
                    }

                    Db.shutdown();

                    foreach (File file in fileSystem.ListFiles(txLogsDir, TransactionLogFiles.DEFAULT_FILENAME_FILTER))
                    {
                        fileSystem.DeleteFile(file);
                    }

                    foreach (File file in fileSystem.ListFiles(tmpLogs, TransactionLogFiles.DEFAULT_FILENAME_FILTER))
                    {
                        fileSystem.CopyFile(file, new File(txLogsDir, file.Name));
                    }
                }
                else
                {
                    Db.shutdown();
                }
            }
Пример #2
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();
            }
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateACountsStoreWhenThereAreNodesAndRelationshipsInTheDB()
        public virtual void ShouldCreateACountsStoreWhenThereAreNodesAndRelationshipsInTheDB()
        {
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("deprecation") final org.neo4j.kernel.internal.GraphDatabaseAPI db = (org.neo4j.kernel.internal.GraphDatabaseAPI) dbBuilder.newGraphDatabase();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            GraphDatabaseAPI db = ( GraphDatabaseAPI )_dbBuilder.newGraphDatabase();

            using (Transaction tx = Db.beginTx())
            {
                Node nodeA = Db.createNode(Label.label("A"));
                Node nodeC = Db.createNode(Label.label("C"));
                Node nodeD = Db.createNode(Label.label("D"));
                Node node  = Db.createNode();
                nodeA.CreateRelationshipTo(nodeD, RelationshipType.withName("TYPE"));
                node.CreateRelationshipTo(nodeC, RelationshipType.withName("TYPE2"));
                tx.Success();
            }
            long lastCommittedTransactionId = GetLastTxId(db);

            Db.shutdown();

            RebuildCounts(lastCommittedTransactionId);

            using (Lifespan life = new Lifespan())
            {
                CountsTracker store = life.Add(CreateCountsTracker());
                assertEquals(BASE_TX_ID + 1 + 1 + 1 + 1 + 1 + 1, store.TxId());
                assertEquals(13, store.TotalEntriesStored());
                assertEquals(4, Get(store, nodeKey(-1)));
                assertEquals(1, Get(store, nodeKey(0)));
                assertEquals(1, Get(store, nodeKey(1)));
                assertEquals(1, Get(store, nodeKey(2)));
                assertEquals(0, Get(store, nodeKey(3)));
                assertEquals(2, Get(store, relationshipKey(-1, -1, -1)));
                assertEquals(1, Get(store, relationshipKey(-1, 0, -1)));
                assertEquals(1, Get(store, relationshipKey(-1, 1, -1)));
                assertEquals(0, Get(store, relationshipKey(-1, 2, -1)));
                assertEquals(1, Get(store, relationshipKey(-1, 1, 1)));
                assertEquals(0, Get(store, relationshipKey(-1, 0, 1)));
            }
        }
Пример #4
0
 internal static void CreateTestData(GraphDatabaseService db)
 {
     using (Transaction tx = Db.beginTx())
     {
         Label            label            = Label.label("Label");
         RelationshipType relationshipType = RelationshipType.withName("REL");
         long[]           largeValue       = new long[1024];
         for (int i = 0; i < 1000; i++)
         {
             Node node = Db.createNode(label);
             node.SetProperty("Niels", "Borh");
             node.SetProperty("Albert", largeValue);
             for (int j = 0; j < 30; j++)
             {
                 Relationship rel = node.CreateRelationshipTo(node, relationshipType);
                 rel.SetProperty("Max", "Planck");
             }
         }
         tx.Success();
     }
 }
Пример #5
0
        private void CreateChainOfNodesWithLabelAndProperty(int length, string relationshipName, string labelName, string property, string value)
        {
            RelationshipType relationshipType = RelationshipType.withName(relationshipName);
            Label            label            = Label.label(labelName);
            Node             prev             = null;

            for (int i = 0; i < length; i++)
            {
                Node node = _db.createNode(label);
                node.SetProperty(property, value);
                if (!property.Equals("name"))
                {
                    node.SetProperty("name", labelName + " " + i);
                }
                if (prev != null)
                {
                    prev.CreateRelationshipTo(node, relationshipType);
                }
                prev = node;
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void should_remove_all_data()
        public virtual void ShouldRemoveAllData()
        {
            using (Transaction tx = _db.beginTx())
            {
                RelationshipType relationshipType = RelationshipType.withName("R");

                Node n1 = _db.createNode();
                Node n2 = _db.createNode();
                Node n3 = _db.createNode();

                n1.CreateRelationshipTo(n2, relationshipType);
                n2.CreateRelationshipTo(n1, relationshipType);
                n3.CreateRelationshipTo(n1, relationshipType);

                tx.Success();
            }

            CleanDatabaseContent(_db);

            assertThat(NodeCount(), @is(0L));
        }
Пример #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAcceptValuesWithNullToString() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAcceptValuesWithNullToString()
        {
            using (Transaction tx = Db.beginTx())
            {
                Node              node              = Db.createNode();
                Node              otherNode         = Db.createNode();
                Relationship      rel               = node.CreateRelationshipTo(otherNode, RelationshipType.withName("recovery"));
                Index <Node>      nodeIndex         = Db.index().forNodes("node-index");
                RelationshipIndex relationshipIndex = Db.index().forRelationships("rel-index");

                // Add
                AssertAddFailsWithIllegalArgument(nodeIndex, node, "key1", new ClassWithToStringAlwaysNull());
                AssertAddFailsWithIllegalArgument(relationshipIndex, rel, "key1", new ClassWithToStringAlwaysNull());

                // Remove
                AssertRemoveFailsWithIllegalArgument(nodeIndex, node, "key1", new ClassWithToStringAlwaysNull());
                AssertRemoveFailsWithIllegalArgument(relationshipIndex, rel, "key1", new ClassWithToStringAlwaysNull());
                tx.Success();
            }

            ForceRecover();
        }
Пример #8
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();
        }
Пример #9
0
//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()
        {
            for (int i = 0; i < 100; i++)
            {
                using (Transaction tx = Db.beginTx())
                {
                    Node prev = null;
                    for (int j = 0; j < 100; j++)
                    {
                        Node node = Db.createNode(label("L"));

                        if (prev != null)
                        {
                            Relationship rel = prev.CreateRelationshipTo(node, RelationshipType.withName("T"));
                            rel.SetProperty("prop", i + j);
                        }
                        prev = node;
                    }
                    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 createDropRelationshipLongArrayProperty()
        public virtual void CreateDropRelationshipLongArrayProperty()
        {
            Label  markerLabel     = Label.label("marker");
            string testPropertyKey = "testProperty";

            sbyte[] propertyValue = RandomUtils.NextBytes(1024);

            using (Transaction tx = Db.beginTx())
            {
                Node         start        = Db.createNode(markerLabel);
                Node         end          = Db.createNode(markerLabel);
                Relationship relationship = start.CreateRelationshipTo(end, withName("type"));
                relationship.SetProperty(testPropertyKey, propertyValue);
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                Relationship relationship = Db.getRelationshipById(0);
                assertArrayEquals(propertyValue, ( sbyte[] )relationship.GetProperty(testPropertyKey));
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                Relationship relationship = Db.getRelationshipById(0);
                relationship.RemoveProperty(testPropertyKey);
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                Relationship relationship = Db.getRelationshipById(0);
                assertFalse(relationship.HasProperty(testPropertyKey));
                tx.Success();
            }
        }
Пример #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldListAndReadExplicitIndexesForReadOnlyDb() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldListAndReadExplicitIndexesForReadOnlyDb()
        {
            // given a db with some nodes and populated explicit indexes
            string key = "key";

            using (Transaction tx = Db.beginTx())
            {
                Index <Node>         nodeIndex         = Db.index().forNodes("NODE");
                Index <Relationship> relationshipIndex = Db.index().forRelationships("RELATIONSHIP");

                for (int i = 0; i < 10; i++)
                {
                    Node         node         = Db.createNode();
                    Relationship relationship = node.CreateRelationshipTo(node, MyRelTypes.TEST);
                    nodeIndex.Add(node, key, i.ToString());
                    relationshipIndex.Add(relationship, key, i.ToString());
                }
                tx.Success();
            }

            // when restarted as read-only
            Db.restartDatabase(GraphDatabaseSettings.read_only.name(), TRUE.ToString());
            using (Transaction tx = Db.beginTx())
            {
                Index <Node>         nodeIndex         = Db.index().forNodes(Db.index().nodeIndexNames()[0]);
                Index <Relationship> relationshipIndex = Db.index().forRelationships(Db.index().relationshipIndexNames()[0]);

                // then try and read the indexes
                for (int i = 0; i < 10; i++)
                {
                    assertNotNull(nodeIndex.get(key, i.ToString()).Single);
                    assertNotNull(relationshipIndex.get(key, i.ToString()).Single);
                }
                tx.Success();
            }
        }
Пример #12
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)));
        }
Пример #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testNotInTransactionException()
        public virtual void TestNotInTransactionException()
        {
            Node node1 = _graph.createNode();

            node1.SetProperty("test", 1);
            Node         node2 = _graph.createNode();
            Node         node3 = _graph.createNode();
            Relationship rel   = node1.CreateRelationshipTo(node2, MyRelTypes.TEST);

            rel.SetProperty("test", 11);
            Commit();
            try
            {
                _graph.createNode();
                fail("Create node with no transaction should throw exception");
            }
            catch (NotInTransactionException)
            {               // good
            }
            try
            {
                node1.CreateRelationshipTo(node2, MyRelTypes.TEST);
                fail("Create relationship with no transaction should " + "throw exception");
            }
            catch (NotInTransactionException)
            {               // good
            }
            try
            {
                node1.SetProperty("test", 2);
                fail("Set property with no transaction should throw exception");
            }
            catch (NotInTransactionException)
            {               // good
            }
            try
            {
                rel.SetProperty("test", 22);
                fail("Set property with no transaction should throw exception");
            }
            catch (NotInTransactionException)
            {               // good
            }
            try
            {
                node3.Delete();
                fail("Delete node with no transaction should " + "throw exception");
            }
            catch (NotInTransactionException)
            {               // good
            }
            try
            {
                rel.Delete();
                fail("Delete relationship with no transaction should " + "throw exception");
            }
            catch (NotInTransactionException)
            {               // good
            }
            NewTransaction();
            assertEquals(node1.GetProperty("test"), 1);
            assertEquals(rel.GetProperty("test"), 11);
            assertEquals(rel, node1.GetSingleRelationship(MyRelTypes.TEST, Direction.OUTGOING));
            node1.Delete();
            node2.Delete();
            rel.Delete();
            node3.Delete();

            // Finally
            Rollback();
        }