//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(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotCreateIndexesForReadOnlyDb() public virtual void ShouldNotCreateIndexesForReadOnlyDb() { // given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.io.layout.DatabaseLayout databaseLayout = db.databaseLayout(); DatabaseLayout databaseLayout = Db.databaseLayout(); // Make sure we have database to start on Db.shutdown(); GraphDatabaseService db = (new GraphDatabaseFactory()).newEmbeddedDatabaseBuilder(databaseLayout.DatabaseDirectory()).setConfig(GraphDatabaseSettings.read_only, TRUE.ToString()).newGraphDatabase(); try { // when try { using (Transaction tx = Db.beginTx()) { Db.index().forNodes("NODE"); fail("Should've failed"); } } catch (WriteOperationsNotAllowedException) { // then good } try { using (Transaction tx = Db.beginTx()) { Db.index().forRelationships("RELATIONSHIP"); fail("Should've failed"); } } catch (WriteOperationsNotAllowedException) { // then good } } finally { Db.shutdown(); } }