//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: private Thread newThreadForNodeAction(final long nodeId, final System.Action<org.neo4j.graphdb.Node> nodeConsumer)
        private Thread NewThreadForNodeAction(long nodeId, System.Action <Node> nodeConsumer)
        {
            return(new Thread(() =>
            {
                try
                {
                    using (Transaction tx = _db.beginTx())
                    {
                        Node node = _db.getNodeById(nodeId);
                        _barrier.await();
                        nodeConsumer(node);
                        tx.success();
                    }
                }
                catch (Exception e)
                {
                    _ex.set(e);
                }
            }));
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void concurrentStartupShouldWork() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ConcurrentStartupShouldWork()
        {
            // Ensures that the instances don't race to create the test's base directory and only care about their own.
            TestDirectory.directory("nothingToSeeHereMoveAlong");
            int[] clusterPorts = new int[] { PortAuthority.allocatePort(), PortAuthority.allocatePort(), PortAuthority.allocatePort() };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String initialHosts = initialHosts(clusterPorts);
            string initialHosts = initialHosts(clusterPorts);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CyclicBarrier barrier = new java.util.concurrent.CyclicBarrier(clusterPorts.length);
            CyclicBarrier barrier = new CyclicBarrier(clusterPorts.Length);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<Thread> daThreads = new java.util.ArrayList<>(clusterPorts.length);
            IList <Thread> daThreads = new List <Thread>(clusterPorts.Length);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final HighlyAvailableGraphDatabase[] dbs = new HighlyAvailableGraphDatabase[clusterPorts.length];
            HighlyAvailableGraphDatabase[] dbs = new HighlyAvailableGraphDatabase[clusterPorts.Length];

            for (int i = 0; i < clusterPorts.Length; i++)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int finalI = i;
                int finalI = i;

                Thread t = new Thread(() =>
                {
                    try
                    {
                        barrier.await();
                        dbs[finalI] = StartDbAtBase(finalI, initialHosts, clusterPorts[finalI]);
                    }
                    catch (Exception e) when(e is InterruptedException || e is BrokenBarrierException)
                    {
                        throw new Exception(e);
                    }
                });
                daThreads.Add(t);
                t.Start();
            }

            foreach (Thread daThread in daThreads)
            {
                daThread.Join();
            }

            bool masterDone = false;

            foreach (HighlyAvailableGraphDatabase db in dbs)
            {
                if (Db.Master)
                {
                    if (masterDone)
                    {
                        throw new Exception("Two masters discovered");
                    }
                    masterDone = true;
                }
                using (Transaction tx = Db.beginTx())
                {
                    Db.createNode();
                    tx.Success();
                }
            }

            assertTrue(masterDone);

            foreach (HighlyAvailableGraphDatabase db in dbs)
            {
                Db.shutdown();
            }
        }