//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void deleteNodeWithNewPropertyRecordShouldFreeTheNewRecord() public virtual void DeleteNodeWithNewPropertyRecordShouldFreeTheNewRecord() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final long propcount = getIdGenerator(org.neo4j.kernel.impl.store.id.IdType.PROPERTY).getNumberOfIdsInUse(); long propcount = GetIdGenerator(IdType.PROPERTY).NumberOfIdsInUse; Node node = GraphDb.createNode(); node.SetProperty("one", 1); node.SetProperty("two", 2); node.SetProperty("three", 3); node.SetProperty("four", 4); NewTransaction(); assertEquals("Invalid assumption: property record count", propcount + 1, PropertyRecordsInUse()); node.SetProperty("final", 666); NewTransaction(); assertEquals("Invalid assumption: property record count", propcount + 2, PropertyRecordsInUse()); node.Delete(); Commit(); assertEquals("All property records should be freed", propcount, PropertyRecordsInUse()); }
//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(); }
private void TestAddAndRemoveLoopRelationshipAndOtherRelationships(int size) { foreach (bool[] delete in Permutations(size)) { for (int i = 0; i < size; i++) { Node root = GraphDb.createNode(); Relationship[] relationships = CreateRelationships(size, i, root); for (int j = 0; j < size; j++) { if (delete[j]) { relationships[j].Delete(); relationships[j] = null; } NewTransaction(); } verifyRelationships(string.Format("loop on {0} of {1}, delete {2}", i, size, Arrays.ToString(delete)), root, i, relationships); } } }
private void TestAddManyLoopRelationships(int count) { foreach (bool[] loop in Permutations(count)) { Node root = GraphDb.createNode(); Relationship[] relationships = new Relationship[count]; for (int i = 0; i < count; i++) { if (loop[i]) { relationships[i] = root.CreateRelationshipTo(root, TEST); } else { relationships[i] = root.CreateRelationshipTo(GraphDb.createNode(), TEST); } } NewTransaction(); verifyRelationships(Arrays.ToString(loop), root, loop, relationships); } }
//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(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testNodeMultiRemoveProperty() public virtual void TestNodeMultiRemoveProperty() { Node node = GraphDb.createNode(); node.SetProperty("key0", "0"); node.SetProperty("key1", "1"); node.SetProperty("key2", "2"); node.SetProperty("key3", "3"); node.SetProperty("key4", "4"); NewTransaction(); node.RemoveProperty("key3"); node.RemoveProperty("key2"); node.RemoveProperty("key3"); NewTransaction(); assertEquals("0", node.GetProperty("key0")); assertEquals("1", node.GetProperty("key1")); assertEquals("4", node.GetProperty("key4")); assertTrue(!node.HasProperty("key2")); assertTrue(!node.HasProperty("key3")); node.Delete(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void canAddLoopRelationship() public virtual void CanAddLoopRelationship() { Node node = GraphDb.createNode(); node.CreateRelationshipTo(node, TEST); NewTransaction(); foreach (Direction dir in Direction.values()) { int count = 0; foreach (Relationship rel in node.GetRelationships(dir)) { count++; assertEquals("start node", node, rel.StartNode); assertEquals("end node", node, rel.EndNode); assertEquals("other node", node, rel.GetOtherNode(node)); } assertEquals(dir.name() + " relationship count", 1, count); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testDeleteNodeWithRel2() public virtual void TestDeleteNodeWithRel2() { Node node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); node1.CreateRelationshipTo(node2, MyRelTypes.TEST); node2.Delete(); 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 testAddPropertyDeletedRelationship() public virtual void TestAddPropertyDeletedRelationship() { Node node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); Relationship rel = node1.CreateRelationshipTo(node2, MyRelTypes.TEST); rel.Delete(); try { rel.SetProperty(_key, 1); Transaction tx = Transaction; tx.Success(); tx.Close(); fail("Add property on deleted rel should not validate"); } catch (Exception) { // good } node1.Delete(); node2.Delete(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void bitPackingOfLengthyArrays() public virtual void BitPackingOfLengthyArrays() { long arrayRecordsBefore = DynamicArrayRecordsInUse(); // Store an int array which would w/o packing require two dynamic records // 4*40 = 160B (assuming data size of 120B) int[] arrayWhichUnpackedWouldFillTwoDynamicRecords = new int[40]; for (int i = 0; i < arrayWhichUnpackedWouldFillTwoDynamicRecords.Length; i++) { arrayWhichUnpackedWouldFillTwoDynamicRecords[i] = i * i; } Node node = GraphDb.createNode(); string key = "the array"; node.SetProperty(key, arrayWhichUnpackedWouldFillTwoDynamicRecords); NewTransaction(); // Make sure it only requires one dynamic record assertEquals(arrayRecordsBefore + 1, DynamicArrayRecordsInUse()); assertTrue(Arrays.Equals(arrayWhichUnpackedWouldFillTwoDynamicRecords, ( int[] )node.GetProperty(key))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void deleteEverythingInMiddleRecord() public virtual void DeleteEverythingInMiddleRecord() { long inUseBefore = PropertyRecordsInUse(); Node node = GraphDb.createNode(); for (int i = 0; i < 3 * PropertyType.PayloadSizeLongs; i++) { node.SetProperty("shortString" + i, i.ToString()); } NewTransaction(); assertEquals(inUseBefore + 3, PropertyRecordsInUse()); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<org.eclipse.collections.api.tuple.Pair<String, Object>> middleRecordProps = getPropertiesFromRecord(1); IList <Pair <string, object> > middleRecordProps = GetPropertiesFromRecord(1); middleRecordProps.ForEach(nameAndValue => { string name = nameAndValue.One; object value = nameAndValue.Two; assertEquals(value, node.RemoveProperty(name)); }); NewTransaction(); assertEquals(inUseBefore + 2, PropertyRecordsInUse()); middleRecordProps.ForEach(nameAndValue => assertFalse(node.HasProperty(nameAndValue.One))); GetPropertiesFromRecord(0).ForEach(nameAndValue => { string name = nameAndValue.One; object value = nameAndValue.Two; assertEquals(value, node.RemoveProperty(name)); }); GetPropertiesFromRecord(2).ForEach(nameAndValue => { string name = nameAndValue.One; object value = nameAndValue.Two; assertEquals(value, node.RemoveProperty(name)); }); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testAddCacheCleared() public virtual void TestAddCacheCleared() { Node nodeA = GraphDb.createNode(); nodeA.SetProperty("1", 1); Node nodeB = GraphDb.createNode(); Relationship rel = nodeA.CreateRelationshipTo(nodeB, MyRelTypes.TEST); rel.SetProperty("1", 1); Commit(); NewTransaction(); nodeA.CreateRelationshipTo(nodeB, MyRelTypes.TEST); int count = 0; foreach (Relationship relToB in nodeA.GetRelationships(MyRelTypes.TEST)) { count++; } assertEquals(2, count); nodeA.SetProperty("2", 2); assertEquals(1, nodeA.GetProperty("1")); rel.SetProperty("2", 2); assertEquals(1, rel.GetProperty("1")); // trigger empty load GraphDb.getNodeById(nodeA.Id); GraphDb.getRelationshipById(rel.Id); // apply COW maps Commit(); NewTransaction(); count = 0; foreach (Relationship relToB in nodeA.GetRelationships(MyRelTypes.TEST)) { count++; } assertEquals(2, count); assertEquals(1, nodeA.GetProperty("1")); assertEquals(1, rel.GetProperty("1")); assertEquals(2, nodeA.GetProperty("2")); assertEquals(2, rel.GetProperty("2")); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void createRelationshipAfterClearedCache() public virtual void CreateRelationshipAfterClearedCache() { // Assumes relationship grab size 100 Node node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); int expectedCount = 0; for (int i = 0; i < 150; i++) { node1.CreateRelationshipTo(node2, TEST); expectedCount++; } NewTransaction(); for (int i = 0; i < 50; i++) { node1.CreateRelationshipTo(node2, TEST); expectedCount++; } assertEquals(expectedCount, Iterables.count(node1.Relationships)); NewTransaction(); assertEquals(expectedCount, Iterables.count(node1.Relationships)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void getOtherNodeFunctionsCorrectly() public virtual void getOtherNodeFunctionsCorrectly() { Node node = GraphDb.createNode(); Relationship relationship = node.CreateRelationshipTo(node, TEST); // This loop messes up the readability of the test case, but avoids duplicated // assertion code. Same assertions withing the transaction as after it has committed. for (int i = 0; i < 2; i++) { assertEquals(node, relationship.GetOtherNode(node)); assertEquals(asList(node, node), asList(relationship.Nodes)); try { relationship.GetOtherNode(GraphDb.createNode()); fail("Should throw exception if another node is passed into loop.getOtherNode"); } catch (NotFoundException) { // Good } NewTransaction(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testAdditionsHappenAtTheFirstRecordIfFits1() public virtual void TestAdditionsHappenAtTheFirstRecordIfFits1() { Node node = GraphDb.createNode(); long recordsInUseAtStart = PropertyRecordsInUse(); node.SetProperty("int1", 1); node.SetProperty("double1", 1.0); node.SetProperty("int2", 2); NewTransaction(); assertEquals(recordsInUseAtStart + 1, PropertyRecordsInUse()); node.RemoveProperty("double1"); NewTransaction(); node.SetProperty("double2", 1.0); NewTransaction(); assertEquals(recordsInUseAtStart + 1, PropertyRecordsInUse()); node.SetProperty("paddingBoolean", false); NewTransaction(); assertEquals(recordsInUseAtStart + 2, PropertyRecordsInUse()); }
/* * Adds at least 3 1-block properties and removes the first and third. * Adds a 2-block property and checks if it is added in the same record. */ //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testBlockDefragmentationWithTwoSpaces() public virtual void TestBlockDefragmentationWithTwoSpaces() { Assume.assumeTrue(PropertyType.PayloadSizeLongs > 2); Node node = GraphDb.createNode(); long inUseBefore = PropertyRecordsInUse(); int stuffedIntegers = 0; for ( ; stuffedIntegers < PropertyType.PayloadSizeLongs; stuffedIntegers++) { node.SetProperty("int" + stuffedIntegers, stuffedIntegers); } // Basic check that integers take up one (8 byte) block. assertEquals(stuffedIntegers, PropertyType.PayloadSizeLongs); NewTransaction(); assertEquals(inUseBefore + 1, PropertyRecordsInUse()); // Remove first and third node.RemoveProperty("int0"); node.RemoveProperty("int2"); NewTransaction(); // Add the two block thing. node.SetProperty("theDouble", 1.0); NewTransaction(); // Let's make sure everything is in one record and with proper values. assertEquals(inUseBefore + 1, PropertyRecordsInUse()); assertNull(node.GetProperty("int0", null)); assertEquals(1, node.GetProperty("int1")); assertNull(node.GetProperty("int2", null)); for (int i = 3; i < stuffedIntegers; i++) { assertEquals(i, node.GetProperty("int" + i)); } assertEquals(1.0, node.GetProperty("theDouble")); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testRelationshipChangeProperty() public virtual void TestRelationshipChangeProperty() { int? int1 = 1; int? int2 = 2; string string1 = "1"; string string2 = "2"; Node node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); Relationship rel1 = node1.CreateRelationshipTo(node2, TEST); Relationship rel2 = node2.CreateRelationshipTo(node1, TEST); rel1.SetProperty(_key1, int1); rel2.SetProperty(_key1, string1); rel1.SetProperty(_key2, string2); rel2.SetProperty(_key2, int2); try { rel1.SetProperty(null, null); fail("Null argument should result in exception."); } catch (System.ArgumentException) { // OK } catch (NotFoundException) { fail("wrong exception"); } // test type change of existing property // cannot test this for now because of exceptions in PL rel2.SetProperty(_key1, int1); rel1.Delete(); rel2.Delete(); node2.Delete(); node1.Delete(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void addAndRemovePropertiesWithinOneTransaction2() public virtual void AddAndRemovePropertiesWithinOneTransaction2() { Node node = GraphDb.createNode(); node.SetProperty("foo", "bar"); NewTransaction(); node.SetProperty("foo2", "bar"); node.RemoveProperty("foo"); NewTransaction(); try { node.GetProperty("foo"); fail("property should not exist"); } catch (NotFoundException) { // good } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testMultipleDeleteRelationship() public virtual void TestMultipleDeleteRelationship() { Node node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); Relationship rel = node1.CreateRelationshipTo(node2, MyRelTypes.TEST); rel.Delete(); node1.Delete(); node2.Delete(); try { rel.Delete(); Transaction tx = Transaction; tx.Success(); tx.Close(); fail("Should not validate"); } catch (Exception) { // ok } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void mixAndPackDifferentTypes() public virtual void MixAndPackDifferentTypes() { Node node = GraphDb.createNode(); long recordsInUseAtStart = PropertyRecordsInUse(); int stuffedShortStrings = 0; for ( ; stuffedShortStrings < PropertyType.PayloadSizeLongs; stuffedShortStrings++) { node.SetProperty("shortString" + stuffedShortStrings, stuffedShortStrings.ToString()); } NewTransaction(); assertEquals(recordsInUseAtStart + 1, PropertyRecordsInUse()); node.RemoveProperty("shortString0"); node.RemoveProperty("shortString2"); node.SetProperty("theDoubleOne", -1.0); NewTransaction(); assertEquals(recordsInUseAtStart + 1, PropertyRecordsInUse()); for (int i = 0; i < stuffedShortStrings; i++) { if (i == 0) { assertFalse(node.HasProperty("shortString" + i)); } else if (i == 2) { assertFalse(node.HasProperty("shortString" + i)); } else { assertEquals(i.ToString(), node.GetProperty("shortString" + i)); } } assertEquals(-1.0, node.GetProperty("theDoubleOne")); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testDirectedRelationship() public virtual void TestDirectedRelationship() { Node node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); Relationship rel2 = node1.CreateRelationshipTo(node2, TEST); Relationship rel3 = node2.CreateRelationshipTo(node1, TEST); Node[] nodes = rel2.Nodes; assertEquals(2, nodes.Length); assertTrue(nodes[0].Equals(node1) && nodes[1].Equals(node2)); nodes = rel3.Nodes; assertEquals(2, nodes.Length); assertTrue(nodes[0].Equals(node2) && nodes[1].Equals(node1)); assertEquals(node1, rel2.StartNode); assertEquals(node2, rel2.EndNode); assertEquals(node2, rel3.StartNode); assertEquals(node1, rel3.EndNode); Relationship[] relArray = GetRelationshipArray(node1.GetRelationships(TEST, Direction.OUTGOING)); assertEquals(1, relArray.Length); assertEquals(rel2, relArray[0]); relArray = GetRelationshipArray(node1.GetRelationships(TEST, Direction.INCOMING)); assertEquals(1, relArray.Length); assertEquals(rel3, relArray[0]); relArray = GetRelationshipArray(node2.GetRelationships(TEST, Direction.OUTGOING)); assertEquals(1, relArray.Length); assertEquals(rel3, relArray[0]); relArray = GetRelationshipArray(node2.GetRelationships(TEST, Direction.INCOMING)); assertEquals(1, relArray.Length); assertEquals(rel2, relArray[0]); rel2.Delete(); rel3.Delete(); node1.Delete(); node2.Delete(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void withoutLoops() public virtual void WithoutLoops() { Node node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); assertEquals(0, node1.Degree); assertEquals(0, node2.Degree); node1.CreateRelationshipTo(node2, MyRelTypes.TEST); assertEquals(1, node1.Degree); assertEquals(1, node2.Degree); node1.CreateRelationshipTo(GraphDb.createNode(), MyRelTypes.TEST2); assertEquals(2, node1.Degree); assertEquals(1, node2.Degree); NewTransaction(); assertEquals(2, node1.Degree); assertEquals(1, node2.Degree); for (int i = 0; i < 1000; i++) { if (i % 2 == 0) { node1.CreateRelationshipTo(node2, MyRelTypes.TEST); } else { node2.CreateRelationshipTo(node1, MyRelTypes.TEST); } assertEquals(i + 2 + 1, node1.Degree); assertEquals(i + 1 + 1, node2.Degree); if (i % 10 == 0) { NewTransaction(); } } for (int i = 0; i < 2; i++) { assertEquals(1002, node1.Degree); assertEquals(1002, node1.GetDegree(Direction.BOTH)); assertEquals(502, node1.GetDegree(Direction.OUTGOING)); assertEquals(500, node1.GetDegree(Direction.INCOMING)); assertEquals(1, node1.GetDegree(MyRelTypes.TEST2)); assertEquals(1001, node1.GetDegree(MyRelTypes.TEST)); assertEquals(1001, node1.GetDegree(MyRelTypes.TEST, Direction.BOTH)); assertEquals(501, node1.GetDegree(MyRelTypes.TEST, Direction.OUTGOING)); assertEquals(500, node1.GetDegree(MyRelTypes.TEST, Direction.INCOMING)); assertEquals(1, node1.GetDegree(MyRelTypes.TEST2, Direction.OUTGOING)); assertEquals(0, node1.GetDegree(MyRelTypes.TEST2, Direction.INCOMING)); NewTransaction(); } foreach (Relationship rel in node1.Relationships) { rel.Delete(); } node1.Delete(); foreach (Relationship rel in node2.Relationships) { rel.Delete(); } node2.Delete(); NewTransaction(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void createInitialNode() public virtual void CreateInitialNode() { _node1 = GraphDb.createNode(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testNodeRelDeleteSemantics() public virtual void TestNodeRelDeleteSemantics() { Node node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); Relationship rel1 = node1.CreateRelationshipTo(node2, MyRelTypes.TEST); Relationship rel2 = node1.CreateRelationshipTo(node2, MyRelTypes.TEST); node1.SetProperty("key1", "value1"); rel1.SetProperty("key1", "value1"); NewTransaction(); node1.Delete(); try { node1.GetProperty("key1"); fail("Should throw exception"); } catch (NotFoundException) { // good } try { node1.SetProperty("key1", "value2"); fail("Should throw exception"); } catch (NotFoundException) { // good } try { node1.RemoveProperty("key1"); fail("Should throw exception"); } catch (NotFoundException) { // good } node2.Delete(); try { node2.Delete(); fail("Should throw exception"); } catch (NotFoundException) { // good } try { node1.GetProperty("key1"); fail("Should throw exception"); } catch (NotFoundException) { // good } try { node1.SetProperty("key1", "value2"); fail("Should throw exception"); } catch (NotFoundException) { // good } try { node1.RemoveProperty("key1"); fail("Should throw exception"); } catch (NotFoundException) { // good } assertEquals("value1", rel1.GetProperty("key1")); rel1.Delete(); try { rel1.Delete(); fail("Should throw exception"); } catch (NotFoundException) { // good } try { rel1.GetProperty("key1"); fail("Should throw exception"); } catch (NotFoundException) { // good } try { rel1.SetProperty("key1", "value2"); fail("Should throw exception"); } catch (NotFoundException) { // good } try { rel1.RemoveProperty("key1"); fail("Should throw exception"); } catch (NotFoundException) { // good } try { rel1.GetProperty("key1"); fail("Should throw exception"); } catch (NotFoundException) { // good } try { rel1.SetProperty("key1", "value2"); fail("Should throw exception"); } catch (NotFoundException) { // good } try { rel1.RemoveProperty("key1"); fail("Should throw exception"); } catch (NotFoundException) { // good } try { node2.CreateRelationshipTo(node1, MyRelTypes.TEST); fail("Should throw exception"); } catch (NotFoundException) { // good } try { node2.CreateRelationshipTo(node1, MyRelTypes.TEST); fail("Should throw exception"); } catch (NotFoundException) { // good } assertEquals(node1, rel1.StartNode); assertEquals(node2, rel2.EndNode); Node[] nodes = rel1.Nodes; assertEquals(node1, nodes[0]); assertEquals(node2, nodes[1]); assertEquals(node2, rel1.GetOtherNode(node1)); rel2.Delete(); // will be marked for rollback so commit will throw exception Rollback(); }
//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 } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testGetRelationshipTypesOnDiscreteNode() public virtual void TestGetRelationshipTypesOnDiscreteNode() { TestGetRelationshipTypes(GraphDb.createNode(), new HashSet <string>()); }
private void EnsureRightDegree(int initialSize, ICollection <RelationshipCreationSpec> cspecs, ICollection <RelationshipDeletionSpec> dspecs) { IDictionary <RelType, int[]> expectedCounts = new Dictionary <RelType, int[]>(typeof(RelType)); foreach (RelType type in RelType.values()) { expectedCounts[type] = new int[3]; } Node me = GraphDb.createNode(); for (int i = 0; i < initialSize; i++) { me.CreateRelationshipTo(GraphDb.createNode(), RelType.Initial); } NewTransaction(); expectedCounts[RelType.Initial][0] = initialSize; AssertCounts(me, expectedCounts); int counter = 0; foreach (RelationshipCreationSpec spec in cspecs) { for (int i = 0; i < spec.Count; i++) { Node otherNode = null; if (spec.Dir == Direction.OUTGOING) { otherNode = GraphDb.createNode(); me.CreateRelationshipTo(otherNode, spec.Type); } else if (spec.Dir == Direction.INCOMING) { otherNode = GraphDb.createNode(); otherNode.CreateRelationshipTo(me, spec.Type); } else { me.CreateRelationshipTo(me, spec.Type); } expectedCounts[spec.Type][spec.Dir.ordinal()]++; if (otherNode != null) { assertEquals(1, otherNode.Degree); } AssertCounts(me, expectedCounts); if (counter % 3 == 0 && counter > 0) { NewTransaction(); AssertCounts(me, expectedCounts); } } } AssertCounts(me, expectedCounts); NewTransaction(); AssertCounts(me, expectedCounts); // Delete one of each type/direction combination counter = 0; if (dspecs == null) { foreach (RelType type in RelType.values()) { if (!type.measure) { continue; } foreach (Direction direction in Direction.values()) { int[] counts = expectedCounts[type]; if (counts[direction.ordinal()] > 0) { DeleteOneRelationship(me, type, direction, 0); counts[direction.ordinal()]--; AssertCounts(me, expectedCounts); if (counter % 3 == 0 && counter > 0) { NewTransaction(); AssertCounts(me, expectedCounts); } } } } } else { foreach (RelationshipDeletionSpec spec in dspecs) { DeleteOneRelationship(me, spec.Type, spec.Dir, spec.Which); expectedCounts[spec.Type][spec.Dir.ordinal()]--; AssertCounts(me, expectedCounts); if (counter % 3 == 0 && counter > 0) { NewTransaction(); AssertCounts(me, expectedCounts); } } } AssertCounts(me, expectedCounts); NewTransaction(); AssertCounts(me, expectedCounts); // Clean up foreach (Relationship rel in me.Relationships) { Node otherNode = rel.GetOtherNode(me); if (!otherNode.Equals(me)) { otherNode.Delete(); } rel.Delete(); } me.Delete(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testNodeGetProperties() public virtual void TestNodeGetProperties() { string key1 = "key1"; string key2 = "key2"; string key3 = "key3"; int? int1 = 1; int? int2 = 2; string @string = "3"; Node node1 = GraphDb.createNode(); try { node1.GetProperty(key1); fail("get non existing property didn't throw exception"); } catch (NotFoundException) { } try { node1.GetProperty(null); fail("get of null key didn't throw exception"); } catch (System.ArgumentException) { } assertTrue(!node1.HasProperty(key1)); assertTrue(!node1.HasProperty(null)); node1.SetProperty(key1, int1); node1.SetProperty(key2, int2); node1.SetProperty(key3, @string); IEnumerator <string> keys = node1.PropertyKeys.GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: keys.next(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: keys.next(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: keys.next(); IDictionary <string, object> properties = node1.AllProperties; assertEquals(properties[key1], int1); assertEquals(properties[key2], int2); assertEquals(properties[key3], @string); properties = node1.GetProperties(key1, key2); assertEquals(properties[key1], int1); assertEquals(properties[key2], int2); assertFalse(properties.ContainsKey(key3)); properties = node1.Properties; assertTrue(properties.Count == 0); try { string[] names = null; node1.GetProperties(names); fail(); } catch (System.NullReferenceException) { // Ok } try { string[] names = new string[] { null }; node1.GetProperties(names); fail(); } catch (System.NullReferenceException) { // Ok } try { node1.RemoveProperty(key3); } catch (NotFoundException) { fail("Remove of property failed."); } assertTrue(!node1.HasProperty(key3)); assertTrue(!node1.HasProperty(null)); node1.Delete(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testNodeRemoveProperty() public virtual void TestNodeRemoveProperty() { string key1 = "key1"; string key2 = "key2"; int? int1 = 1; int? int2 = 2; string string1 = "1"; string string2 = "2"; Node node1 = GraphDb.createNode(); Node node2 = GraphDb.createNode(); try { if (node1.RemoveProperty(key1) != null) { fail("Remove of non existing property should return null"); } } catch (NotFoundException) { } try { node1.RemoveProperty(null); fail("Remove null property should throw exception."); } catch (System.ArgumentException) { } node1.SetProperty(key1, int1); node2.SetProperty(key1, string1); node1.SetProperty(key2, string2); node2.SetProperty(key2, int2); try { node1.RemoveProperty(null); fail("Null argument should result in exception."); } catch (System.ArgumentException) { } // test remove property assertEquals(int1, node1.RemoveProperty(key1)); assertEquals(string1, node2.RemoveProperty(key1)); // test remove of non existing property try { if (node2.RemoveProperty(key1) != null) { fail("Remove of non existing property return null."); } } catch (NotFoundException) { // must mark as rollback only } // getTransaction().failure(); }
/* * 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(); } }