Esempio n. 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected <T> org.neo4j.graphdb.Result executeWithRetries(String query, T parameters, org.neo4j.kernel.impl.query.TransactionalContext context, ParametrizedQueryExecutor<T> executor) throws org.neo4j.kernel.impl.query.QueryExecutionKernelException
        protected internal virtual Result ExecuteWithRetries <T>(string query, T parameters, TransactionalContext context, ParametrizedQueryExecutor <T> executor)
        {
            VersionContext versionContext = GetCursorContext(context);
            EagerResult    eagerResult;
            int            attempt = 0;
            bool           dirtySnapshot;

            do
            {
                if (attempt == _maxQueryExecutionAttempts)
                {
                    return(ThrowQueryExecutionException("Unable to get clean data snapshot for query '%s' after %d attempts.", query, attempt));
                }
                attempt++;
                versionContext.InitRead();
                Result result = executor(query, parameters, context);
                eagerResult = new EagerResult(result, versionContext);
                eagerResult.Consume();
                dirtySnapshot = versionContext.Dirty;
                if (dirtySnapshot && result.QueryStatistics.containsUpdates())
                {
                    return(ThrowQueryExecutionException("Unable to get clean data snapshot for query '%s' that perform updates.", query, attempt));
                }
            } while (dirtySnapshot);
            return(eagerResult);
        }
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 shouldNotGetEagerPlanForANonEagerProcedure()
        public virtual void ShouldNotGetEagerPlanForANonEagerProcedure()
        {
            // When explaining a call to an non-eagerized procedure
            Result res = _db.execute("EXPLAIN MATCH (n) WHERE n.key = 'value' " + "WITH n CALL org.neo4j.procedure.deleteNeighboursNotEagerized(n, 'FOLLOWS') " + "YIELD value RETURN value");

            assertThat("The plan description shouldn't contain the 'Eager' operation", res.ExecutionPlanDescription.ToString(), Matchers.not(containsString("+Eager")));
        }
Esempio n. 3
0
        private void VerifyResult(Result result)
        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            System.Collections.IDictionary firstRowValue = (System.Collections.IDictionary)result.Next().Values.GetEnumerator().next();
            assertThat(firstRowValue["key"], @is("Value"));
            System.Collections.IList theList = (System.Collections.IList)firstRowValue["collectionKey"];
            assertThat(((System.Collections.IDictionary)theList[0])["inner"], @is("Map1"));
            assertThat(((System.Collections.IDictionary)theList[1])["inner"], @is("Map2"));
        }
Esempio n. 4
0
        private long NodesInDatabase()
        {
            Result r = Graphdb().execute("MATCH (n) RETURN count(n) AS c");
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            long?nodes = ( long? )r.ColumnAs("c").next();

            r.Close();
            return(nodes.Value);
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotGetPropertyAccessFailureWhenStreamingToAnEagerDestructiveProcedure()
        public virtual void ShouldNotGetPropertyAccessFailureWhenStreamingToAnEagerDestructiveProcedure()
        {
            // When we have a simple graph (a)
            SetUpTestData();

            // Then we can run an eagerized destructive procedure
            Result res = _db.execute("MATCH (n) WHERE n.key = 'value' " + "WITH n CALL org.neo4j.procedure.deleteNeighboursEagerized(n, 'FOLLOWS') " + "YIELD value RETURN value");

            assertThat("Should get as many rows as original nodes", res.ResultAsString(), containsString("2 rows"));
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void executeLabelScanQueryWithSingleRetry()
        public virtual void ExecuteLabelScanQueryWithSingleRetry()
        {
            Result result = _database.execute("MATCH (n:toRetry) RETURN n.c");

            assertEquals(1, _testCursorContext.AdditionalAttempts);
            while (result.MoveNext())
            {
                assertEquals("d", result.Current.get("n.c"));
            }
        }
Esempio n. 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void executeCountStoreQueryWithSingleRetry()
        public virtual void ExecuteCountStoreQueryWithSingleRetry()
        {
            Result result = _database.execute("MATCH (n:toRetry) RETURN count(n)");

            assertEquals(1, _testCursorContext.AdditionalAttempts);
            while (result.MoveNext())
            {
                assertEquals(1L, result.Current.get("count(n)"));
            }
        }
Esempio n. 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void executeQueryWithoutRestarts()
        public virtual void ExecuteQueryWithoutRestarts()
        {
            _testCursorContext.WrongLastClosedTxId = false;

            Result result = _database.execute("MATCH (n:label) RETURN n.c");

            while (result.MoveNext())
            {
                assertEquals("d", result.Current.get("n.c"));
            }
            assertEquals(0, _testCursorContext.AdditionalAttempts);
        }
Esempio n. 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotGetErrorBecauseOfNormalEagerizationWhenStreamingFromANormalReadProcedureToDestructiveCypher()
        public virtual void ShouldNotGetErrorBecauseOfNormalEagerizationWhenStreamingFromANormalReadProcedureToDestructiveCypher()
        {
            // When we have a simple graph (a)
            int count = 10;

            UpTestData = count;

            // Then we can run an normal read procedure and it will be eagerized by normal Cypher eagerization
            Result res = _db.execute("MATCH (n) WHERE n.key = 'value' " + "CALL org.neo4j.procedure.findNeighboursNotEagerized(n) " + "YIELD relationship AS r, node as m " + "DELETE r, m RETURN true");

            assertThat("Should get one fewer rows than original nodes", res.ResultAsString(), containsString((count - 1) + " rows"));
            assertThat("The plan description should contain the 'Eager' operation", res.ExecutionPlanDescription.ToString(), containsString("+Eager"));
        }
Esempio n. 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGetPropertyAccessFailureWhenStreamingToANonEagerDestructiveProcedure()
        public virtual void ShouldGetPropertyAccessFailureWhenStreamingToANonEagerDestructiveProcedure()
        {
            // When we have a simple graph (a)
            SetUpTestData();

            // Expect a specific error
            Exception.expect(typeof(QueryExecutionException));
            Exception.expectMessage("Node with id 1 has been deleted in this transaction");

            // When we try to run an eagerized destructive procedure
            Result res = _db.execute("MATCH (n) WHERE n.key = 'value' " + "WITH n CALL org.neo4j.procedure.deleteNeighboursNotEagerized(n, 'FOLLOWS') " + "YIELD value RETURN value");

            res.ResultAsString();               // pull all results. The second row will cause the exception
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SetUp()
        {
            GraphDatabaseQueryService cypherService = new GraphDatabaseCypherService(this.Database.GraphDatabaseAPI);

            _compilerFactory      = mock(typeof(CompilerFactory));
            _transactionalContext = mock(typeof(TransactionalContext));
            KernelStatement kernelStatement = mock(typeof(KernelStatement));

            _executor       = mock(typeof(SnapshotExecutionEngine.ParametrizedQueryExecutor));
            _versionContext = mock(typeof(VersionContext));

            _executionEngine = CreateExecutionEngine(cypherService);
            when(kernelStatement.VersionContext).thenReturn(_versionContext);
            when(_transactionalContext.statement()).thenReturn(kernelStatement);
            Result          result     = mock(typeof(Result));
            QueryStatistics statistics = mock(typeof(QueryStatistics));

            when(result.QueryStatistics).thenReturn(statistics);
            when(_executor.execute(any(), anyMap(), any())).thenReturn(result);
        }