//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void createTestingGraph() public virtual void CreateTestingGraph() { Node node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); Relationship rel = node1.CreateRelationshipTo(node2, MyRelTypes.TEST); _node1Id = node1.Id; _node2Id = node2.Id; node1.SetProperty(_key1, _int1); node1.SetProperty(_key2, _string1); node2.SetProperty(_key1, _int2); node2.SetProperty(_key2, _string2); rel.SetProperty(_key1, _int1); rel.SetProperty(_key2, _string1); node1.SetProperty(_arrayKey, _array); node2.SetProperty(_arrayKey, _array); rel.SetProperty(_arrayKey, _array); Transaction tx = Transaction; tx.Success(); tx.Close(); tx = GraphDb.beginTx(); assertEquals(1, node1.GetProperty(_key1)); Transaction = tx; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testNodeChangePropertyArray() public virtual void TestNodeChangePropertyArray() { Transaction.close(); Node node; using (Transaction tx = GraphDb.beginTx()) { node = GraphDb.createNode(); tx.Success(); } using (Transaction tx = GraphDb.beginTx()) { node.SetProperty("test", new string[] { "value1" }); tx.Success(); } using (Transaction ignored = GraphDb.beginTx()) { node.SetProperty("test", new string[] { "value1", "value2" }); // no success, we wanna test rollback on this operation } using (Transaction tx = GraphDb.beginTx()) { string[] value = ( string[] )node.GetProperty("test"); assertEquals(1, value.Length); assertEquals("value1", value[0]); tx.Success(); } Transaction = GraphDb.beginTx(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testDeleteReferenceNodeOrLastNodeIsOk() public virtual void TestDeleteReferenceNodeOrLastNodeIsOk() { Transaction tx = Transaction; for (int i = 0; i < 10; i++) { GraphDb.createNode(); } // long numNodesPre = getNodeManager().getNumberOfIdsInUse( Node.class // ); // empty the DB instance foreach (Node node in GraphDb.AllNodes) { foreach (Relationship rel in node.Relationships) { rel.Delete(); } node.Delete(); } tx.Success(); tx.Close(); tx = GraphDb.beginTx(); assertFalse(GraphDb.AllNodes.GetEnumerator().hasNext()); // TODO: this should be valid, fails right now! // assertEquals( 0, numNodesPost ); tx.Success(); tx.Close(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testCreateRelOnDeletedNode() public virtual void TestCreateRelOnDeletedNode() { Node node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); Transaction tx = Transaction; tx.Success(); tx.Close(); tx = GraphDb.beginTx(); node1.Delete(); try { node1.CreateRelationshipTo(node2, MyRelTypes.TEST); fail("Create of rel on deleted node should fail fast"); } catch (Exception) { // ok } try { tx.Failure(); tx.Close(); // fail( "Transaction should be marked rollback" ); } catch (Exception) { // good } Transaction = GraphDb.beginTx(); node2.Delete(); node1.Delete(); }
private void AssertPropertyEqual(PropertyContainer primitive, string key, string value) { using (Transaction tx = GraphDb.beginTx()) { assertEquals(value, primitive.GetProperty(key)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void newTransaction() public virtual void NewTransaction() { if (_tx != null) { CloseTransaction(); } _tx = GraphDb.beginTx(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeout = 5000) public void testForLoops() public virtual void TestForLoops() { /* * * (b) * / \ 0 * 0 0 / \ - 0 - (c1) - 0 - * \ / \/ / \ * (s) - 1 - (a1) - 1 - (a2) - 1 - (a3) (a4) - 1 - (t) * \ / * - 0 - (c2) - 0 - * */ using (Transaction tx = GraphDb.beginTx()) { Node s = Graph.makeNode("s"); Node t = Graph.makeNode("t"); // Blob loop Graph.makeEdge("s", "a1", "length", 1); Graph.makeEdge("a1", "b", "length", 0); Graph.makeEdge("b", "a1", "length", 0); // Self loop Graph.makeEdge("a1", "a2", "length", 1); Graph.makeEdge("a2", "a2", "length", 0); // Diamond loop Graph.makeEdge("a2", "a3", "length", 1); Graph.makeEdge("a3", "c1", "length", 0); Graph.makeEdge("a3", "c2", "length", 0); Graph.makeEdge("c1", "a4", "length", 0); Graph.makeEdge("c1", "a4", "length", 0); Graph.makeEdge("a4", "t", "length", 1); PathExpander expander = PathExpanders.allTypesAndDirections(); Dijkstra algo = new Dijkstra(expander, CommonEvaluators.doubleCostEvaluator("length"), PathInterestFactory.all(NoneStrictMath.EPSILON)); IEnumerator <WeightedPath> paths = algo.FindAllPaths(s, t).GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue("Expected at least one path", paths.hasNext()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertEquals("Expected first path of length 6", 6, paths.next().length()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue("Expected at least two paths", paths.hasNext()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertEquals("Expected second path of length 6", 6, paths.next().length()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse("Expected exactly two paths", paths.hasNext()); tx.Success(); } }
private void AssertRelationshipCount(Node node, int count) { using (Transaction tx = GraphDb.beginTx()) { int actualCount = 0; foreach (Relationship rel in node.Relationships) { actualCount++; } assertEquals(count, actualCount); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void name() public virtual void Name() { Node node = GraphDb.createNode(); node.SetProperty("name", "yo"); node.GetProperty("name"); Commit(); using (Transaction tx = GraphDb.beginTx()) { node.GetProperty("name"); tx.Success(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testRollbackDeleteRelationship() public virtual void TestRollbackDeleteRelationship() { Node node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); Relationship rel1 = node1.CreateRelationshipTo(node2, TEST); NewTransaction(); node1.Delete(); rel1.Delete(); Transaction.failure(); Transaction.close(); Transaction = GraphDb.beginTx(); node1.Delete(); node2.Delete(); rel1.Delete(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testDeleteNodeWithRel1() public virtual void TestDeleteNodeWithRel1() { Node node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); node1.CreateRelationshipTo(node2, MyRelTypes.TEST); node1.Delete(); try { Transaction tx = Transaction; tx.Success(); tx.Close(); fail("Should not validate"); } catch (Exception) { // good } Transaction = GraphDb.beginTx(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testDeleteNodeWithRel3() public virtual void TestDeleteNodeWithRel3() { // make sure we can delete in wrong order Node node0 = GraphDb.createNode(); Node node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); Relationship rel0 = node0.CreateRelationshipTo(node1, MyRelTypes.TEST); Relationship rel1 = node0.CreateRelationshipTo(node2, MyRelTypes.TEST); node1.Delete(); rel0.Delete(); Transaction tx = Transaction; tx.Success(); tx.Close(); Transaction = GraphDb.beginTx(); node2.Delete(); rel1.Delete(); node0.Delete(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testDeleteWithRelationship() public virtual void TestDeleteWithRelationship() { // do some evil stuff Node node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); node1.CreateRelationshipTo(node2, TEST); node1.Delete(); node2.Delete(); try { Transaction.success(); Transaction.close(); fail("deleting node with relationship should not commit."); } catch (Exception) { // good } Transaction = GraphDb.beginTx(); }
protected internal virtual Transaction BeginTx() { return(GraphDb.beginTx()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testIllegalPropertyType() public virtual void TestIllegalPropertyType() { Node node1 = GraphDb.createNode(); try { node1.SetProperty(_key, new object()); fail("Shouldn't validate"); } catch (Exception) { // good } { Transaction tx = Transaction; tx.Failure(); tx.Close(); } Transaction = GraphDb.beginTx(); try { GraphDb.getNodeById(node1.Id); fail("Node should not exist, previous tx didn't rollback"); } catch (NotFoundException) { // good } node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); Relationship rel = node1.CreateRelationshipTo(node2, MyRelTypes.TEST); try { rel.SetProperty(_key, new object()); fail("Shouldn't validate"); } catch (Exception) { // good } try { Transaction tx = Transaction; tx.Success(); tx.Close(); fail("Shouldn't validate"); } catch (Exception) { // good } Transaction = GraphDb.beginTx(); try { GraphDb.getNodeById(node1.Id); fail("Node should not exist, previous tx didn't rollback"); } catch (NotFoundException) { // good } try { GraphDb.getNodeById(node2.Id); fail("Node should not exist, previous tx didn't rollback"); } catch (NotFoundException) { // good } }
/* * Tests that changes performed in a transaction before commit are not apparent in another. */ //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testSimpleTransactionIsolation() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void TestSimpleTransactionIsolation() { // Start setup - create base data Commit(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch latch1 = new java.util.concurrent.CountDownLatch(1); System.Threading.CountdownEvent latch1 = new System.Threading.CountdownEvent(1); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch latch2 = new java.util.concurrent.CountDownLatch(1); System.Threading.CountdownEvent latch2 = new System.Threading.CountdownEvent(1); Node n1; Node n2; Relationship r1; using (Transaction tx = GraphDb.beginTx()) { n1 = GraphDb.createNode(); n2 = GraphDb.createNode(); r1 = n1.CreateRelationshipTo(n2, RelationshipType.withName("TEST")); tx.Success(); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Node node1 = n1; Node node1 = n1; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Node node2 = n2; Node node2 = n2; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Relationship rel1 = r1; Relationship rel1 = r1; using (Transaction tx = GraphDb.beginTx()) { node1.SetProperty("key", "old"); rel1.SetProperty("key", "old"); tx.Success(); } AssertPropertyEqual(node1, "key", "old"); AssertPropertyEqual(rel1, "key", "old"); AssertRelationshipCount(node1, 1); AssertRelationshipCount(node2, 1); // This is the mutating transaction - it will change stuff which will be read in between //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicReference<Exception> t1Exception = new java.util.concurrent.atomic.AtomicReference<>(); AtomicReference <Exception> t1Exception = new AtomicReference <Exception>(); Thread t1 = new Thread(() => { try { using (Transaction tx = GraphDb.beginTx()) { node1.SetProperty("key", "new"); rel1.SetProperty("key", "new"); node1.CreateRelationshipTo(node2, RelationshipType.withName("TEST")); AssertPropertyEqual(node1, "key", "new"); AssertPropertyEqual(rel1, "key", "new"); AssertRelationshipCount(node1, 2); AssertRelationshipCount(node2, 2); latch1.Signal(); latch2.await(); AssertPropertyEqual(node1, "key", "new"); AssertPropertyEqual(rel1, "key", "new"); AssertRelationshipCount(node1, 2); AssertRelationshipCount(node2, 2); // no tx.success(); } } catch (Exception e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); Thread.interrupted(); t1Exception.set(e); } finally { try { AssertPropertyEqual(node1, "key", "old"); AssertPropertyEqual(rel1, "key", "old"); AssertRelationshipCount(node1, 1); AssertRelationshipCount(node2, 1); } catch (Exception e) { t1Exception.compareAndSet(null, e); } } }); t1.Start(); latch1.await(); // The transaction started above that runs in t1 has not finished. The old values should still be visible. AssertPropertyEqual(node1, "key", "old"); AssertPropertyEqual(rel1, "key", "old"); AssertRelationshipCount(node1, 1); AssertRelationshipCount(node2, 1); latch2.Signal(); t1.Join(); // The transaction in t1 has finished but not committed. Its changes should still not be visible. AssertPropertyEqual(node1, "key", "old"); AssertPropertyEqual(rel1, "key", "old"); AssertRelationshipCount(node1, 1); AssertRelationshipCount(node2, 1); if (t1Exception.get() != null) { throw t1Exception.get(); } using (Transaction tx = GraphDb.beginTx()) { foreach (Relationship rel in node1.Relationships) { rel.Delete(); } node1.Delete(); node2.Delete(); tx.Success(); } }