Exemple #1
0
        private void AssertYieldsErrors(string json, params Neo4jError[] expectedErrors)
        {
            StatementDeserializer de = new StatementDeserializer(new ByteArrayInputStreamAnonymousInnerClass(this, UTF8.encode(json)));

            while (de.MoveNext())
            {
                de.Current;
            }

            IEnumerator <Neo4jError> actual   = de.Errors();
            IEnumerator <Neo4jError> expected = asList(expectedErrors).GetEnumerator();

            while (actual.MoveNext())
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(expected.hasNext());
                Neo4jError error = actual.Current;
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                Neo4jError expectedError = expected.next();

                assertThat(error.Message, equalTo(expectedError.Message));
                assertThat(error.Status(), equalTo(expectedError.Status()));
            }

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(expected.hasNext());
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test @SuppressWarnings("unchecked") public void shouldDeserializeMultipleStatements()
        public virtual void ShouldDeserializeMultipleStatements()
        {
            // Given
            string json = createJsonFrom(map("statements", asList(map("statement", "Blah blah", "parameters", map("one", 12)), map("statement", "Blah bluh", "parameters", map("asd", asList("one, two"))))));

            // When
            StatementDeserializer de = new StatementDeserializer(new MemoryStream(UTF8.encode(json)));

            // Then
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertThat(de.HasNext(), equalTo(true));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            Statement stmt = de.Next();

            assertThat(stmt.StatementConflict(), equalTo("Blah blah"));
            assertThat(stmt.Parameters(), equalTo(map("one", 12)));

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertThat(de.HasNext(), equalTo(true));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            Statement stmt2 = de.Next();

            assertThat(stmt2.StatementConflict(), equalTo("Blah bluh"));
            assertThat(stmt2.Parameters(), equalTo(map("asd", asList("one, two"))));

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertThat(de.HasNext(), equalTo(false));
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowSpecificExceptionOnConcurrentTransactionAccess() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowSpecificExceptionOnConcurrentTransactionAccess()
        {
            // given
            TransactionRegistry registry = new TransactionHandleRegistry(mock(typeof(Clock)), 0, NullLogProvider.Instance);
            TransitionalPeriodTransactionMessContainer kernel           = mock(typeof(TransitionalPeriodTransactionMessContainer));
            GraphDatabaseQueryService queryService                      = mock(typeof(GraphDatabaseQueryService));
            TransitionalTxManagementKernelTransaction kernelTransaction = mock(typeof(TransitionalTxManagementKernelTransaction));

            when(kernel.NewTransaction(any(typeof(KernelTransaction.Type)), any(typeof(LoginContext)), anyLong())).thenReturn(kernelTransaction);
            TransactionFacade actions = new TransactionFacade(kernel, null, queryService, registry, NullLogProvider.Instance);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TransactionHandle transactionHandle = actions.newTransactionHandle(new DisgustingUriScheme(), true, org.neo4j.internal.kernel.api.security.LoginContext.AUTH_DISABLED, -1);
            TransactionHandle transactionHandle = actions.NewTransactionHandle(new DisgustingUriScheme(), true, LoginContext.AUTH_DISABLED, -1);

//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();
            DoubleLatch latch = new DoubleLatch();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final StatementDeserializer statements = mock(StatementDeserializer.class);
            StatementDeserializer statements = mock(typeof(StatementDeserializer));

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            when(statements.HasNext()).thenAnswer(invocation =>
            {
                latch.StartAndWaitForAllToStartAndFinish();
                return(false);
            });

            (new Thread(() =>
            {
                // start and block until finish
                transactionHandle.Execute(statements, mock(typeof(ExecutionResultSerializer)), mock(typeof(HttpServletRequest)));
            })).Start();

            latch.WaitForAllToStart();

            try
            {
                // when
                actions.FindTransactionHandle(DisgustingUriScheme.ParseTxId(transactionHandle.Uri()));
                fail("should have thrown exception");
            }
            catch (InvalidConcurrentTransactionAccess)
            {
                // then we get here
            }
            finally
            {
                latch.Finish();
            }
        }
Exemple #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTreatEmptyInputStreamAsEmptyStatementList()
        public virtual void ShouldTreatEmptyInputStreamAsEmptyStatementList()
        {
            // Given
            sbyte[] json = new sbyte[0];

            // When
            StatementDeserializer de = new StatementDeserializer(new MemoryStream(json));

            // Then
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(de.HasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(de.Errors().hasNext());
        }
Exemple #5
0
        private void Execute(StatementDeserializer statements, ExecutionResultSerializer output, IList <Neo4jError> errors, HttpServletRequest request)
        {
            ExecuteStatements(statements, output, errors, request);

            if (Neo4jError.shouldRollBackOn(errors))
            {
                Rollback(errors);
            }
            else
            {
                _context.suspendSinceTransactionsAreStillThreadBound();
                long lastActiveTimestamp = _registry.release(_id, this);
                output.TransactionStatus(lastActiveTimestamp);
            }
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIgnoreUnknownFields()
        public virtual void ShouldIgnoreUnknownFields()
        {
            // Given
            string json = "{ \"statements\" : [ { \"a\" : \"\", \"b\" : { \"k\":1 }, \"statement\" : \"blah\" } ] }";

            // When
            StatementDeserializer de = new StatementDeserializer(new MemoryStream(UTF8.encode(json)));

            // Then
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertThat(de.HasNext(), equalTo(true));

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertThat(de.Next().statement(), equalTo("blah"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertThat(de.HasNext(), equalTo(false));
        }
Exemple #7
0
        public virtual void Execute(StatementDeserializer statements, ExecutionResultSerializer output, HttpServletRequest request)
        {
            IList <Neo4jError> errors = new LinkedList <Neo4jError>();

            try
            {
                output.TransactionCommitUri(_uriScheme.txCommitUri(_id));
                EnsureActiveTransaction();
                Execute(statements, output, errors, request);
            }
            catch (InternalBeginTransactionError e)
            {
                errors.Add(e.ToNeo4jError());
            }
            finally
            {
                output.Errors(errors);
                output.Finish();
            }
        }
Exemple #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTakeParametersBeforeStatement()
        public virtual void ShouldTakeParametersBeforeStatement()
        {
            // Given
            string json = "{ \"statements\" : [ { \"a\" : \"\", \"parameters\" : { \"k\":1 }, \"statement\" : \"blah\"}]}";

            // When
            StatementDeserializer de = new StatementDeserializer(new MemoryStream(UTF8.encode(json)));

            // Then
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertThat(de.HasNext(), equalTo(true));

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            Statement stmt = de.Next();

            assertThat(stmt.StatementConflict(), equalTo("blah"));
            assertThat(stmt.Parameters(), equalTo(map("k", 1)));

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertThat(de.HasNext(), equalTo(false));
        }
Exemple #9
0
        public virtual void Commit(StatementDeserializer statements, ExecutionResultSerializer output, HttpServletRequest request)
        {
            IList <Neo4jError> errors = new LinkedList <Neo4jError>();

            try
            {
                try
                {
                    Statement peek = statements.Peek();
                    if (Implicit && peek == null)                                // JSON parse error
                    {
                        addToCollection(statements.Errors(), errors);
                    }
                    else
                    {
                        EnsureActiveTransaction();
                        ExecuteStatements(statements, output, errors, request);
                        CloseContextAndCollectErrors(errors);
                    }
                }
                finally
                {
                    _registry.forget(_id);
                }
            }
            catch (InternalBeginTransactionError e)
            {
                errors.Add(e.ToNeo4jError());
            }
            catch (CypherException e)
            {
                errors.Add(new Neo4jError(e.status(), e));
                throw e;
            }
            finally
            {
                output.Errors(errors);
                output.Finish();
            }
        }
Exemple #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTotallyIgnoreInvalidJsonAfterStatementArrayHasFinished()
        public virtual void ShouldTotallyIgnoreInvalidJsonAfterStatementArrayHasFinished()
        {
            // NOTE: We don't really want this behaviour, but it's a symptom of keeping
            // streaming behaviour while moving the statement list into a map.

            // Given
            string json = "{ \"statements\" : [ { \"statement\" : \"Blah blah\", \"parameters\" : {\"one\" : 12}} ] " +
                          "totally invalid json is totally ignored";

            // When
            StatementDeserializer de = new StatementDeserializer(new MemoryStream(UTF8.encode(json)));

            // Then
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertThat(de.HasNext(), equalTo(true));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            Statement stmt = de.Next();

            assertThat(stmt.StatementConflict(), equalTo("Blah blah"));

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertThat(de.HasNext(), equalTo(false));
        }
Exemple #11
0
        private void ExecuteStatements(StatementDeserializer statements, ExecutionResultSerializer output, IList <Neo4jError> errors, HttpServletRequest request)
        {
            try
            {
                bool hasPrevious = false;
                while (statements.MoveNext())
                {
                    Statement statement = statements.Current;
                    try
                    {
                        bool hasPeriodicCommit = _engine.isPeriodicCommit(statement.StatementConflict());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                        if ((statements.HasNext() || hasPrevious) && hasPeriodicCommit)
                        {
                            throw new QueryExecutionKernelException(new InvalidSemanticsException("Cannot execute another statement after executing " + "PERIODIC COMMIT statement in the same transaction"));
                        }

                        if (!hasPrevious && hasPeriodicCommit)
                        {
                            _context.closeTransactionForPeriodicCommit();
                        }

                        hasPrevious = true;
                        TransactionalContext tc = _txManagerFacade.create(request, _queryService, _type, _loginContext, statement.StatementConflict(), statement.Parameters());
                        Result result           = SafelyExecute(statement, hasPeriodicCommit, tc);
                        output.StatementResult(result, statement.IncludeStats(), statement.ResultDataContents());
                        output.Notifications(result.Notifications);
                    }
                    catch (Exception e) when(e is KernelException || e is CypherException || e is AuthorizationViolationException || e is WriteOperationsNotAllowedException)
                    {
                        errors.Add(new Neo4jError(e.status(), e));
                        break;
                    }
                    catch (DeadlockDetectedException e)
                    {
                        errors.Add(new Neo4jError(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.DeadlockDetected, e));
                    }
                    catch (IOException e)
                    {
                        errors.Add(new Neo4jError(Org.Neo4j.Kernel.Api.Exceptions.Status_Network.CommunicationError, e));
                        break;
                    }
                    catch (Exception e)
                    {
                        Exception cause = e.InnerException;
                        if (cause is Org.Neo4j.Kernel.Api.Exceptions.Status_HasStatus)
                        {
                            errors.Add(new Neo4jError(((Org.Neo4j.Kernel.Api.Exceptions.Status_HasStatus)cause).Status(), cause));
                        }
                        else
                        {
                            errors.Add(new Neo4jError(Org.Neo4j.Kernel.Api.Exceptions.Status_Statement.ExecutionFailed, e));
                        }

                        break;
                    }
                }

                addToCollection(statements.Errors(), errors);
            }
            catch (Exception e)
            {
                errors.Add(new Neo4jError(Org.Neo4j.Kernel.Api.Exceptions.Status_General.UnknownError, e));
            }
        }