Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void testPermutation(byte[] unfragmented, io.netty.buffer.ByteBuf[] fragments) throws Exception
        private void TestPermutation(sbyte[] unfragmented, ByteBuf[] fragments)
        {
            // Given
            _channel = new EmbeddedChannel();
            BoltChannel boltChannel = NewBoltChannel(_channel);

            BoltStateMachine          machine        = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection boltConnection = new SynchronousBoltConnection(machine);
            NullLogService            logging        = NullLogService.Instance;
            BoltProtocol boltProtocol = new BoltProtocolV1(boltChannel, (ch, s) => boltConnection, (v, ch) => machine, logging);

            boltProtocol.Install();

            // When data arrives split up according to the current permutation
            foreach (ByteBuf fragment in fragments)
            {
                _channel.writeInbound(fragment.readerIndex(0).retain());
            }

            // Then the session should've received the specified messages, and the protocol should be in a nice clean state
            try
            {
                RequestMessage run = new RunMessage("Mjölnir", EMPTY_MAP);
                verify(machine).process(eq(run), any(typeof(BoltResponseHandler)));
            }
            catch (AssertionError e)
            {
                throw new AssertionError("Failed to handle fragmented delivery.\n" + "Messages: " + Arrays.ToString(_messages) + "\n" + "Chunk size: " + _chunkSize + "\n" + "Serialized data delivered in fragments: " + DescribeFragments(fragments) + "\n" + "Unfragmented data: " + HexPrinter.hex(unfragmented) + "\n", e);
            }
        }
Пример #2
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());
        }
Пример #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void unpack(byte[] input) throws java.io.IOException
        private void Unpack(sbyte[] input)
        {
            BoltStateMachine          stateMachine = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection connection   = new SynchronousBoltConnection(stateMachine);

            _channel = new EmbeddedChannel(NewDecoder(connection));

            _channel.writeInbound(Unpooled.wrappedBuffer(input));
            _channel.finishAndReleaseAll();
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDispatchPullAll() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDispatchPullAll()
        {
            BoltStateMachine          stateMachine = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection connection   = new SynchronousBoltConnection(stateMachine);

            _channel = new EmbeddedChannel(NewDecoder(connection));

            _channel.writeInbound(Unpooled.wrappedBuffer(serialize(PackerUnderTest, PullAllMessage.INSTANCE)));
            _channel.finishAndReleaseAll();

            verify(stateMachine).process(eq(PullAllMessage.INSTANCE), any());
        }
Пример #5
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());
        }
Пример #6
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());
        }
Пример #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDispatchRun() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDispatchRun()
        {
            BoltStateMachine          stateMachine = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection connection   = new SynchronousBoltConnection(stateMachine);

            _channel = new EmbeddedChannel(NewDecoder(connection));

            string   statement  = "RETURN 1";
            MapValue parameters = ValueUtils.asMapValue(MapUtil.map("param1", 1, "param2", "2", "param3", true, "param4", 5.0));

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

            verify(stateMachine).process(eq(new RunMessage(statement, parameters)), any());
        }
Пример #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDispatchInit() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDispatchInit()
        {
            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", "principal", "user", "credentials", "password");

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

            verify(stateMachine).process(refEq(new InitMessage(userAgent, authToken), "authToken"), any());
        }
//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);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDecodeKnownMessage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDecodeKnownMessage()
        {
            Neo4jPack_Unpacker unpacker = mock(typeof(Neo4jPack_Unpacker));

            when(unpacker.UnpackStructSignature()).thenReturn('a');

            RequestMessage        message         = mock(typeof(RequestMessage));
            BoltResponseHandler   responseHandler = ResponseHandlerMock();
            RequestMessageDecoder decoder         = new TestRequestMessageDecoder('a', responseHandler, message);

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

            BoltRequestMessageReader reader = new TestBoltRequestMessageReader(connection, ResponseHandlerMock(), singletonList(decoder));

            reader.Read(unpacker);

            verify(stateMachine).process(message, responseHandler);
        }