示例#1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void handleFailure(Throwable cause, boolean fatal) throws org.neo4j.bolt.runtime.BoltConnectionFatality
        public override void HandleFailure(Exception cause, bool fatal)
        {
            if (ExceptionUtils.indexOfType(cause, typeof(BoltConnectionFatality)) != -1)
            {
                fatal = true;
            }

            Neo4jError error = fatal ? Neo4jError.fatalFrom(cause) : Neo4jError.from(cause);

            Fail(error);

            if (error.Fatal)
            {
                if (ExceptionUtils.indexOfType(cause, typeof(AuthorizationExpiredException)) != -1)
                {
                    throw new BoltConnectionAuthFatality("Failed to process a bolt message", cause);
                }
                if (cause is AuthenticationException)
                {
                    throw new BoltConnectionAuthFatality(( AuthenticationException )cause);
                }

                throw new BoltConnectionFatality("Failed to process a bolt message", cause);
            }
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailWhenTryingToPackAndUnpackMapContainingNullKeys() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFailWhenTryingToPackAndUnpackMapContainingNullKeys()
        {
            // Given
            PackedOutputArray output = new PackedOutputArray();

            Org.Neo4j.Bolt.messaging.Neo4jPack_Packer packer = _neo4jPack.newPacker(output);

            IDictionary <string, AnyValue> map = new Dictionary <string, AnyValue>();

            map[null]  = longValue(42L);
            map["foo"] = longValue(1337L);
            packer.PackMapHeader(map.Count);
            foreach (KeyValuePair <string, AnyValue> entry in map.SetOfKeyValuePairs())
            {
                packer.pack(entry.Key);
                packer.pack(entry.Value);
            }

            // When
            try
            {
                PackedInputArray input = new PackedInputArray(output.Bytes());
                Org.Neo4j.Bolt.messaging.Neo4jPack_Unpacker unpacker = _neo4jPack.newUnpacker(input);
                unpacker.Unpack();

                fail("exception expected");
            }
            catch (BoltIOException ex)
            {
                assertEquals(Neo4jError.from(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.Invalid, "Value `null` is not supported as key in maps, must be a non-nullable string."), Neo4jError.from(ex));
            }
        }
示例#3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowOnUnpackingMapWithDuplicateKeys() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowOnUnpackingMapWithDuplicateKeys()
        {
            // Given
            PackedOutputArray output = new PackedOutputArray();

            Org.Neo4j.Bolt.messaging.Neo4jPack_Packer packer = _neo4jPack.newPacker(output);
            packer.PackMapHeader(2);
            packer.Pack("key");
            packer.pack(intValue(1));
            packer.Pack("key");
            packer.pack(intValue(2));

            // When
            try
            {
                PackedInputArray input = new PackedInputArray(output.Bytes());
                Org.Neo4j.Bolt.messaging.Neo4jPack_Unpacker unpacker = _neo4jPack.newUnpacker(input);
                unpacker.Unpack();

                fail("exception expected");
            }
            catch (BoltIOException ex)
            {
                assertEquals(Neo4jError.from(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.Invalid, "Duplicate map key `key`."), Neo4jError.from(ex));
            }
        }
示例#4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCallExternalErrorOnInitWithDuplicateKeys() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCallExternalErrorOnInitWithDuplicateKeys()
        {
            BoltStateMachine          stateMachine = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection connection   = new SynchronousBoltConnection(stateMachine);

            _channel = new EmbeddedChannel(NewDecoder(connection));

            // Generate INIT message with duplicate keys
            PackedOutputArray @out = new PackedOutputArray();

            Org.Neo4j.Bolt.messaging.Neo4jPack_Packer packer = PackerUnderTest.newPacker(@out);
            packer.PackStructHeader(2, InitMessage.SIGNATURE);
            packer.Pack("Test/User Agent 1.0");
            packer.PackMapHeader(3);
            packer.Pack("scheme");
            packer.Pack("basic");
            packer.Pack("principal");
            packer.Pack("user");
            packer.Pack("scheme");
            packer.Pack("password");

            _channel.writeInbound(Unpooled.wrappedBuffer(@out.Bytes()));
            _channel.finishAndReleaseAll();

            verify(stateMachine).handleExternalFailure(eq(Neo4jError.from(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.Invalid, "Duplicate map key `scheme`.")), any());
        }
示例#5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProcessAckFailureMessageWithPendingError() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldProcessAckFailureMessageWithPendingError()
        {
            Neo4jError error = Neo4jError.from(new Exception());

            _connectionState.markFailed(error);
            assertEquals(error, _connectionState.PendingError);

            BoltStateMachineState newState = _state.process(AckFailureMessage.INSTANCE, _context);

            assertEquals(_readyState, newState);
            assertNull(_connectionState.PendingError);
        }
示例#6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotBeAbleToUnpackRelationship() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotBeAbleToUnpackRelationship()
        {
            try
            {
                // When
                Unpacked(Packed(ALICE_KNOWS_BOB));
                fail("exception expected.");
            }
            catch (BoltIOException ex)
            {
                assertEquals(Neo4jError.from(Org.Neo4j.Kernel.Api.Exceptions.Status_Statement.TypeError, "Relationship values cannot be unpacked with this version of bolt."), Neo4jError.from(ex));
            }
        }
示例#7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProcessResetMessageWithPerndingError() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldProcessResetMessageWithPerndingError()
        {
            when(_context.resetMachine()).thenReturn(true);                 // reset successful
            Neo4jError error = Neo4jError.from(new Exception());

            _connectionState.markFailed(error);
            assertEquals(error, _connectionState.PendingError);

            BoltStateMachineState newState = _state.process(ResetMessage.INSTANCE, _context);

            assertEquals(_readyState, newState);
            assertNull(_connectionState.PendingError);
        }
示例#8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCallExternalErrorOnInitWithNullKeys() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCallExternalErrorOnInitWithNullKeys()
        {
            BoltStateMachine          stateMachine = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection connection   = new SynchronousBoltConnection(stateMachine);

            _channel = new EmbeddedChannel(NewDecoder(connection));

            string userAgent = "Test/User Agent 1.0";
            IDictionary <string, object> authToken = MapUtil.map("scheme", "basic", null, "user", "credentials", "password");

            _channel.writeInbound(Unpooled.wrappedBuffer(serialize(PackerUnderTest, new InitMessage(userAgent, authToken))));
            _channel.finishAndReleaseAll();

            verify(stateMachine).handleExternalFailure(eq(Neo4jError.from(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.Invalid, "Value `null` is not supported as key in maps, must be a non-nullable string.")), any());
        }
示例#9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void testUnpackableStructParametersWithKnownType(org.neo4j.bolt.messaging.Neo4jPack packerForSerialization, org.neo4j.values.AnyValue parameterValue, String expectedMessage) throws Exception
        private void TestUnpackableStructParametersWithKnownType(Neo4jPack packerForSerialization, AnyValue parameterValue, string expectedMessage)
        {
            string   statement  = "RETURN $x";
            MapValue parameters = VirtualValues.map(new string[] { "x" }, new AnyValue[] { parameterValue });

            BoltStateMachine          stateMachine = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection connection   = new SynchronousBoltConnection(stateMachine);

            _channel = new EmbeddedChannel(NewDecoder(connection));

            _channel.writeInbound(Unpooled.wrappedBuffer(serialize(packerForSerialization, new RunMessage(statement, parameters))));
            _channel.finishAndReleaseAll();

            verify(stateMachine).handleExternalFailure(eq(Neo4jError.from(Org.Neo4j.Kernel.Api.Exceptions.Status_Statement.TypeError, expectedMessage)), any());
        }
示例#10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotBeAbleToUnpackPaths() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotBeAbleToUnpackPaths()
        {
            foreach (PathValue path in ALL_PATHS)
            {
                try
                {
                    // When
                    Unpacked(Packed(path));
                    fail("exception expected.");
                }
                catch (BoltIOException ex)
                {
                    assertEquals(Neo4jError.from(Org.Neo4j.Kernel.Api.Exceptions.Status_Statement.TypeError, "Path values cannot be unpacked with this version of bolt."), Neo4jError.from(ex));
                }
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLogShortWarningOnClientDisconnectMidwayThroughQuery() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLogShortWarningOnClientDisconnectMidwayThroughQuery()
        {
            // Connections dying is not exceptional per-se, so we don't need to fill the log with
            // eye-catching stack traces; but it could be indicative of some issue, so log a brief
            // warning in the debug log at least.

            // Given
            PackOutputClosedException outputClosed = new PackOutputClosedException("Output closed", "<client>");
            Neo4jError txTerminated = Neo4jError.from(new TransactionTerminatedException(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.Terminated));

            // When
            AssertableLogProvider logProvider = EmulateFailureWritingError(txTerminated, outputClosed);

            // Then
            logProvider.AssertExactly(inLog("Test").warn(equalTo("Client %s disconnected while query was running. Session has been cleaned up. " + "This can be caused by temporary network problems, but if you see this often, ensure your " + "applications are properly waiting for operations to complete before exiting."), equalTo("<client>")));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleErrorThatCausesFailureMessage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleErrorThatCausesFailureMessage()
        {
            Neo4jPack_Unpacker unpacker = mock(typeof(Neo4jPack_Unpacker));
            BoltIOException    error    = new BoltIOException(Org.Neo4j.Kernel.Api.Exceptions.Status_General.UnknownError, "Hello");

            when(unpacker.UnpackStructHeader()).thenThrow(error);

            BoltStateMachine stateMachine = mock(typeof(BoltStateMachine));
            BoltConnection   connection   = new SynchronousBoltConnection(stateMachine);

            BoltResponseHandler      externalErrorResponseHandler = ResponseHandlerMock();
            BoltRequestMessageReader reader = new TestBoltRequestMessageReader(connection, externalErrorResponseHandler, emptyList());

            reader.Read(unpacker);

            verify(stateMachine).handleExternalFailure(Neo4jError.from(error), externalErrorResponseHandler);
        }
示例#13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void read(Neo4jPack_Unpacker unpacker) throws java.io.IOException
        public virtual void Read(Neo4jPack_Unpacker unpacker)
        {
            try
            {
                DoRead(unpacker);
            }
            catch (BoltIOException e)
            {
                if (e.CausesFailureMessage())
                {
                    Neo4jError error = Neo4jError.from(e);
                    _connection.enqueue(stateMachine => stateMachine.handleExternalFailure(error, _externalErrorResponseHandler));
                }
                else
                {
                    throw e;
                }
            }
        }
示例#14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void onlyDatabaseErrorsAreLogged()
        public virtual void OnlyDatabaseErrorsAreLogged()
        {
            AssertableLogProvider userLog     = new AssertableLogProvider();
            AssertableLogProvider internalLog = new AssertableLogProvider();
            ErrorReporter         reporter    = NewErrorReporter(userLog, internalLog);

            foreach (Org.Neo4j.Kernel.Api.Exceptions.Status_Classification classification in Enum.GetValues(typeof(Org.Neo4j.Kernel.Api.Exceptions.Status_Classification)))
            {
                if (classification != Org.Neo4j.Kernel.Api.Exceptions.Status_Classification.DatabaseError)
                {
                    Org.Neo4j.Kernel.Api.Exceptions.Status_Code code = NewStatusCode(classification);
                    Neo4jError error = Neo4jError.from(() => code, "Database error");
                    reporter.Report(error);

                    userLog.AssertNoLoggingOccurred();
                    internalLog.AssertNoLoggingOccurred();
                }
            }
        }
示例#15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotBeAbleToUnpackUnboundRelationship() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotBeAbleToUnpackUnboundRelationship()
        {
            // Given
            PackedOutputArray @out = new PackedOutputArray();

            Neo4jPackV1.Packer packer = _neo4jPack.newPacker(@out);

            packer.packStructHeader(3, UNBOUND_RELATIONSHIP);
            packer.pack(ValueUtils.of(1L));
            packer.pack(ValueUtils.of("RELATES_TO"));
            packer.pack(ValueUtils.asMapValue(MapUtil.map("a", 1L, "b", "x")));

            try
            {
                // When
                Unpacked(@out.Bytes());
                fail("exception expected.");
            }
            catch (BoltIOException ex)
            {
                assertEquals(Neo4jError.from(Org.Neo4j.Kernel.Api.Exceptions.Status_Statement.TypeError, "Relationship values cannot be unpacked with this version of bolt."), Neo4jError.from(ex));
            }
        }
示例#16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowOnUnpackingMapWithUnsupportedKeyType() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowOnUnpackingMapWithUnsupportedKeyType()
        {
            // Given
            PackedOutputArray output = new PackedOutputArray();

            Org.Neo4j.Bolt.messaging.Neo4jPack_Packer packer = _neo4jPack.newPacker(output);
            packer.PackMapHeader(2);
            packer.Pack(ValueUtils.of(1L));
            packer.pack(intValue(1));

            // When
            try
            {
                PackedInputArray input = new PackedInputArray(output.Bytes());
                Org.Neo4j.Bolt.messaging.Neo4jPack_Unpacker unpacker = _neo4jPack.newUnpacker(input);
                unpacker.Unpack();

                fail("exception expected");
            }
            catch (BoltIOException ex)
            {
                assertEquals(Neo4jError.from(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.InvalidFormat, "Bad key type: INTEGER"), Neo4jError.from(ex));
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLogWriteErrorAndOriginalErrorWhenUnknownFailure() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLogWriteErrorAndOriginalErrorWhenUnknownFailure()
        {
            TestLoggingOfWriteErrorAndOriginalErrorWhenUnknownFailure(Neo4jError.from(new Exception("Non-fatal error")));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLogOriginalErrorWhenOutputIsClosed() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLogOriginalErrorWhenOutputIsClosed()
        {
            TestLoggingOfOriginalErrorWhenOutputIsClosed(Neo4jError.from(new Exception("Non-fatal error")));
        }