Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertKeepAuthorizationForLifetimeOfTransaction(String username, System.Action<org.neo4j.driver.v1.Transaction> assertion) throws Throwable
        private void AssertKeepAuthorizationForLifetimeOfTransaction(string username, System.Action <Transaction> assertion)
        {
            DoubleLatch latch = new DoubleLatch(2);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final Throwable[] threadFail = {null};
            Exception[] threadFail = new Exception[] { null };

            Thread readerThread = new Thread(() =>
            {
                try
                {
                    using (Driver driver = ConnectDriver(username, "abc123"), Session session = driver.session(), Transaction tx = session.beginTransaction())
                    {
                        assertion(tx);
                        latch.StartAndWaitForAllToStart();
                        latch.FinishAndWaitForAllToFinish();
                        assertion(tx);
                        tx.success();
                    }
                }
                catch (Exception t)
                {
                    threadFail[0] = t;
                    // Always release the latch so we get the failure in the main thread
                    latch.Start();
                    latch.Finish();
                }
            });

            readerThread.Start();
            latch.StartAndWaitForAllToStart();

            ClearAuthCacheFromDifferentConnection();

            latch.FinishAndWaitForAllToFinish();

            readerThread.Join();
            if (threadFail[0] != null)
            {
                throw threadFail[0];
            }
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTerminateQueriesEvenIfUsingPeriodicCommit() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTerminateQueriesEvenIfUsingPeriodicCommit()
        {
            // Spawns a throttled HTTP server, runs a PERIODIC COMMIT that fetches data from this server,
            // and checks that the query able to be terminated

            // We start with 3, because that is how many actors we have -
            // 1. the http server
            // 2. the running query
            // 3. the one terminating 2
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.DoubleLatch latch = new org.neo4j.test.DoubleLatch(3, true);
            DoubleLatch latch = new DoubleLatch(3, true);

            // This is used to block the http server between the first and second batch
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.Barrier_Control barrier = new org.neo4j.test.Barrier_Control();
            Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control();

            // Serve CSV via local web server, let Jetty find a random port for us
            Server server = CreateHttpServer(latch, barrier, 20, 30);

            server.start();
            int localPort = GetLocalPort(server);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.bolt.runtime.BoltStateMachine[] machine = {null};
            BoltStateMachine[] machine = new BoltStateMachine[] { null };

            Thread thread = new Thread(() =>
            {
                try
                {
                    using (BoltStateMachine stateMachine = Env.newMachine(_boltChannel))
                    {
                        machine[0] = stateMachine;
                        stateMachine.process(new InitMessage(USER_AGENT, emptyMap()), nullResponseHandler());
                        string query = format("USING PERIODIC COMMIT 10 LOAD CSV FROM 'http://localhost:%d' AS line " + "CREATE (n:A {id: line[0], square: line[1]}) " + "WITH count(*) as number " + "CREATE (n:ShouldNotExist)", localPort);
                        try
                        {
                            latch.Start();
                            stateMachine.process(new RunMessage(query, EMPTY_MAP), nullResponseHandler());
                            stateMachine.process(PullAllMessage.INSTANCE, nullResponseHandler());
                        }
                        finally
                        {
                            latch.Finish();
                        }
                    }
                }
                catch (BoltConnectionFatality connectionFatality)
                {
                    throw new Exception(connectionFatality);
                }
            });

            thread.Name = "query runner";
            thread.Start();

            // We block this thread here, waiting for the http server to spin up and the running query to get started
            latch.StartAndWaitForAllToStart();
            Thread.Sleep(1000);

            // This is the call that RESETs the Bolt connection and will terminate the running query
            machine[0].Process(ResetMessage.INSTANCE, nullResponseHandler());

            barrier.Release();

            // We block again here, waiting for the running query to have been terminated, and for the server to have
            // wrapped up and finished streaming http results
            latch.FinishAndWaitForAllToFinish();

            // And now we check that the last node did not get created
            using (Transaction ignored = Env.graph().beginTx())
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse("Query was not terminated in time - nodes were created!", Env.graph().findNodes(Label.label("ShouldNotExist")).hasNext());
            }
        }