public override void CreateTestGraph(GraphDatabaseService graphDb) { using (Transaction tx = graphDb.BeginTx()) { for (int i = 0; i < _nNodes; i++) { _nodeIds.Add(graphDb.CreateNode(Label.label("LABEL" + i)).Id); } tx.Success(); } using (Transaction tx = graphDb.BeginTx()) { for (int i = 0; i < _nRelationships; i++) { long?source = _nodeIds[_random.Next(_nNodes)]; long?target = _nodeIds[_random.Next(_nNodes)]; graphDb.GetNodeById(source.Value).createRelationshipTo(graphDb.GetNodeById(target.Value), RelationshipType.withName("REL" + (i % 10))); } tx.Success(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldUseDynamicPropertiesToIndexANodeWhenAddedAlongsideExistingPropertiesInASeparateTransaction() public virtual void ShouldUseDynamicPropertiesToIndexANodeWhenAddedAlongsideExistingPropertiesInASeparateTransaction() { // Given GraphDatabaseService beansAPI = DbRule.GraphDatabaseAPI; // When long id; { using (Transaction tx = beansAPI.BeginTx()) { Node myNode = beansAPI.CreateNode(); id = myNode.Id; myNode.SetProperty("key0", true); myNode.SetProperty("key1", true); tx.Success(); } } Neo4jMatchers.createIndex(beansAPI, _label1, "key2"); Node myNode; { using (Transaction tx = beansAPI.BeginTx()) { myNode = beansAPI.GetNodeById(id); myNode.AddLabel(_label1); myNode.SetProperty("key2", LONG_STRING); myNode.SetProperty("key3", LONG_STRING); tx.Success(); } } // Then assertThat(myNode, inTx(beansAPI, hasProperty("key2").withValue(LONG_STRING))); assertThat(myNode, inTx(beansAPI, hasProperty("key3").withValue(LONG_STRING))); assertThat(findNodesByLabelAndProperty(_label1, "key2", LONG_STRING, beansAPI), containsOnly(myNode)); }
public Node entity(long id, GraphDatabaseService graphDatabaseService) { return(graphDatabaseService.GetNodeById(id)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void oneRound() throws Throwable private void OneRound() { // GIVEN a cluster and a node const string key = "key"; ClusterManager.ManagedCluster cluster = ClusterRule.startCluster(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.GraphDatabaseService master = cluster.getMaster(); GraphDatabaseService master = cluster.Master; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final long nodeId = createNode(master); long nodeId = CreateNode(master); cluster.Sync(); // and a bunch of workers contending on that node, each changing it Workers <ThreadStart> transactors = new Workers <ThreadStart>("Transactors"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger successes = new java.util.concurrent.atomic.AtomicInteger(); AtomicInteger successes = new AtomicInteger(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean(); AtomicBoolean end = new AtomicBoolean(); for (int i = 0; i < 10; i++) { transactors.Start(() => { Random random = ThreadLocalRandom.current(); while (!end.get()) { bool committed = true; try { using (Transaction tx = master.BeginTx()) { Node node = master.GetNodeById(nodeId); // Acquiring lock, read int property value, increment, set incremented int property // should not break under any circumstances. tx.acquireWriteLock(node); node.setProperty(key, ( int? )node.getProperty(key, 0) + 1); // Throw in relationship for good measure node.createRelationshipTo(master.CreateNode(), TEST); Thread.Sleep(random.Next(1_000)); tx.success(); } } catch (Exception) { // It's OK committed = false; } if (committed) { successes.incrementAndGet(); } } }); } // WHEN entering a period of induced cluster instabilities ReelectTheSameMasterMakingItGoToPendingAndBack(cluster); // ... letting transactions run a bit after the role switch as well. long targetSuccesses = successes.get() + 20; while (successes.get() < targetSuccesses) { Thread.Sleep(100); } end.set(true); transactors.AwaitAndThrowOnError(); // THEN verify that the count is equal to the number of successful transactions assertEquals(successes.get(), GetNodePropertyValue(master, nodeId, key)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void makeSureLazyLoadingRelationshipsWorksEvenIfOtherIteratorAlsoLoadsInTheSameIteration() public virtual void MakeSureLazyLoadingRelationshipsWorksEvenIfOtherIteratorAlsoLoadsInTheSameIteration() { int numEdges = 100; /* create 256 nodes */ GraphDatabaseService graphDB = GraphDb; Node[] nodes = new Node[256]; for (int numNodes = 0; numNodes < nodes.Length; numNodes += 1) { nodes[numNodes] = graphDB.CreateNode(); } NewTransaction(); /* create random outgoing relationships from node 5 */ Node hub = nodes[4]; int nextID = 7; RelationshipType outtie = withName("outtie"); RelationshipType innie = withName("innie"); for (int k = 0; k < numEdges; k++) { Node neighbor = nodes[nextID]; nextID += 7; nextID &= 255; if (nextID == 0) { nextID = 1; } hub.CreateRelationshipTo(neighbor, outtie); } NewTransaction(); /* create random incoming relationships to node 5 */ for (int k = 0; k < numEdges; k += 1) { Node neighbor = nodes[nextID]; nextID += 7; nextID &= 255; if (nextID == 0) { nextID = 1; } neighbor.CreateRelationshipTo(hub, innie); } Commit(); NewTransaction(); hub = graphDB.GetNodeById(hub.Id); int count = 0; foreach (Relationship ignore in hub.Relationships) { count += ( int )Iterables.count(hub.Relationships); } assertEquals(40000, count); count = 0; //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: for (@SuppressWarnings("unused") org.neo4j.graphdb.Relationship r1 : hub.getRelationships()) foreach (Relationship r1 in hub.Relationships) { count += ( int )Iterables.count(hub.Relationships); } assertEquals(40000, count); Commit(); }