//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private <T extends org.neo4j.bolt.messaging.RequestMessage> T serializeAndDeserialize(T msg) throws Exception
        private T SerializeAndDeserialize <T>(T msg) where T : Org.Neo4j.Bolt.messaging.RequestMessage
        {
            RecordingByteChannel channel = new RecordingByteChannel();

            Org.Neo4j.Bolt.messaging.Neo4jPack_Packer packer = _neo4jPack.newPacker(new BufferedChannelOutput(channel));
            BoltRequestMessageWriter writer = new BoltRequestMessageWriter(packer);

            writer.Write(msg).flush();
            channel.Eof();

            return(Unpack(channel));
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private <T extends org.neo4j.bolt.messaging.ResponseMessage> T serializeAndDeserialize(T msg) throws java.io.IOException
        private T SerializeAndDeserialize <T>(T msg) where T : Org.Neo4j.Bolt.messaging.ResponseMessage
        {
            RecordingByteChannel        channel = new RecordingByteChannel();
            BoltResponseMessageReader   reader  = new BoltResponseMessageReader(_neo4jPack.newUnpacker((new BufferedChannelInput(16)).reset(channel)));
            BufferedChannelOutput       output  = new BufferedChannelOutput(channel);
            BoltResponseMessageWriterV1 writer  = new BoltResponseMessageWriterV1(_neo4jPack.newPacker, output, NullLogService.Instance);

            writer.Write(msg);
            writer.Flush();

            channel.Eof();
            return(Unpack(reader, channel));
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToWriteToThenReadFromChannel()
        public virtual void ShouldBeAbleToWriteToThenReadFromChannel()
        {
            // Given
            RecordingByteChannel channel = new RecordingByteChannel();

            // When
            sbyte[] data = new sbyte[] { 1, 2, 3, 4, 5 };
            channel.Write(ByteBuffer.wrap(data));
            ByteBuffer buffer    = ByteBuffer.allocate(10);
            int        bytesRead = channel.Read(buffer);

            // Then
            assertThat(bytesRead, equalTo(5));
            assertThat(buffer.array(), equalTo(new sbyte[] { 1, 2, 3, 4, 5, 0, 0, 0, 0, 0 }));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") private <T extends org.neo4j.bolt.messaging.ResponseMessage> T unpack(BoltResponseMessageReader reader, RecordingByteChannel channel)
        private T Unpack <T>(BoltResponseMessageReader reader, RecordingByteChannel channel) where T : Org.Neo4j.Bolt.messaging.ResponseMessage
        {
            // Unpack
            string serialized = HexPrinter.hex(channel.Bytes);
            BoltResponseMessageRecorder messages = new BoltResponseMessageRecorder();

            try
            {
                reader.Read(messages);
            }
            catch (Exception e)
            {
                throw new AssertionError("Failed to unpack message, wire data was:\n" + serialized + "[" + channel.Bytes.Length + "b]", e);
            }

            return(( T )messages.AsList()[0]);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private <T extends org.neo4j.bolt.messaging.RequestMessage> T unpack(RecordingByteChannel channel) throws Exception
        private T Unpack <T>(RecordingByteChannel channel) where T : Org.Neo4j.Bolt.messaging.RequestMessage
        {
            IList <RequestMessage> messages     = new List <RequestMessage>();
            BoltStateMachine       stateMachine = mock(typeof(BoltStateMachine));

            doAnswer(new AnswerAnonymousInnerClass(this, messages)) BoltRequestMessageReader reader = new BoltRequestMessageReaderV1(new SynchronousBoltConnection(stateMachine), mock(typeof(BoltResponseMessageWriter)), NullLogService.Instance);