Ejemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSupportOpenSSLOnSupportedPlatforms() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSupportOpenSSLOnSupportedPlatforms()
        {
            // depends on the statically linked uber-jar with boring ssl: http://netty.io/wiki/forked-tomcat-native.html
            assumeTrue(SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC_OSX);
            assumeThat(System.getProperty("os.arch"), equalTo("x86_64"));
            assumeThat(SystemUtils.JAVA_VENDOR, isOneOf("Oracle Corporation", "Sun Microsystems Inc."));

            // given
            SslResource sslServerResource = selfSignedKeyId(0).trustKeyId(1).install(TestDir.directory("server"));
            SslResource sslClientResource = selfSignedKeyId(1).trustKeyId(0).install(TestDir.directory("client"));

            _server = new SecureServer(SslContextFactory.MakeSslPolicy(sslServerResource, SslProvider.OPENSSL));

            _server.start();
            _client = new SecureClient(SslContextFactory.MakeSslPolicy(sslClientResource, SslProvider.OPENSSL));
            _client.connect(_server.port());

            // when
            ByteBuf request = ByteBufAllocator.DEFAULT.buffer().writeBytes(_request);

            _client.channel().writeAndFlush(request);

            // then
            _expected = ByteBufAllocator.DEFAULT.buffer().writeBytes(SecureServer.Response);
            _client.sslHandshakeFuture().get(1, MINUTES);
            _client.assertResponse(_expected);
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProvideExpectedMetaData() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProvideExpectedMetaData()
        {
            ChunkedInput <ByteBuf> replicatedContent = ChunkedReplicatedContent.Chunked(( sbyte )1, new ThreeChunks(this, -1, 8));

            UnpooledByteBufAllocator allocator = UnpooledByteBufAllocator.DEFAULT;

            ByteBuf byteBuf = replicatedContent.readChunk(allocator);

            // is not last
            assertFalse(byteBuf.readBoolean());
            // first chunk has content
            assertEquals(( sbyte )1, byteBuf.readByte());
            byteBuf.release();

            byteBuf = replicatedContent.readChunk(allocator);
            // is not last
            assertFalse(byteBuf.readBoolean());
            byteBuf.release();

            byteBuf = replicatedContent.readChunk(allocator);
            // is last
            assertTrue(byteBuf.readBoolean());
            byteBuf.release();

            assertNull(replicatedContent.readChunk(allocator));
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void marshal(org.neo4j.storageengine.api.WritableChannel writableChannel, TransactionRepresentationReplicatedTransaction replicatedTransaction) throws java.io.IOException
        public static void Marshal(WritableChannel writableChannel, TransactionRepresentationReplicatedTransaction replicatedTransaction)
        {
            if (writableChannel is ByteBufBacked)
            {
                /*
                 * Marshals more efficiently if Channel is going over the network. In practice, this means maintaining support for
                 * RaftV1 without loosing performance
                 */
                ByteBuf buffer        = (( ByteBufBacked )writableChannel).byteBuf();
                int     metaDataIndex = buffer.writerIndex();
                int     txStartIndex  = metaDataIndex + Integer.BYTES;
                // leave room for length to be set later.
                buffer.writerIndex(txStartIndex);
                WriteTx(writableChannel, replicatedTransaction.Tx());
                int txLength = buffer.writerIndex() - txStartIndex;
                buffer.setInt(metaDataIndex, txLength);
            }
            else
            {
                /*
                 * Unknown length. This should only be reached in tests. When a ReplicatedTransaction is marshaled to file it has already passed over the network
                 * and is of a different type. More efficient marshalling is used in ByteArrayReplicatedTransaction.
                 */
                MemoryStream outputStream = new MemoryStream(1024);
                OutputStreamWritableChannel outputStreamWritableChannel = new OutputStreamWritableChannel(outputStream);
                WriteTx(outputStreamWritableChannel, replicatedTransaction.Tx());
                int length = outputStream.size();
                writableChannel.PutInt(length);
                writableChannel.Put(outputStream.toByteArray(), length);
            }
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowExceptionForHalfWrittenInstance() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowExceptionForHalfWrittenInstance()
        {
            // given
            // a CoreMember and a ByteBuffer to write it to
            MemberId.Marshal marshal = new MemberId.Marshal();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId aRealMember = new org.neo4j.causalclustering.identity.MemberId(java.util.UUID.randomUUID());
            MemberId aRealMember = new MemberId(System.Guid.randomUUID());

            ByteBuf buffer = Unpooled.buffer(1000);

            // and the CoreMember is serialized but for 5 bytes at the end
            marshal.MarshalConflict(aRealMember, new BoundedNetworkWritableChannel(buffer));
            ByteBuf bufferWithMissingBytes = buffer.copy(0, buffer.writerIndex() - 5);

            // when
            try
            {
                marshal.Unmarshal(new NetworkReadableClosableChannelNetty4(bufferWithMissingBytes));
                fail("Should have thrown exception");
            }
            catch (EndOfStreamException)
            {
                // expected
            }
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotCountBytesAlreadyInBuffer() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotCountBytesAlreadyInBuffer()
        {
            // Given
            int     sizeLimit = 100;
            ByteBuf buffer    = Unpooled.buffer();

            int padding = Long.BYTES;

            buffer.writeLong(0);

            BoundedNetworkWritableChannel channel = new BoundedNetworkWritableChannel(buffer, sizeLimit);

            // When
            for (int i = 0; i < sizeLimit - padding; i++)
            {
                channel.Put(( sbyte )0);
            }
            // then it should be ok
            // again, when
            for (int i = 0; i < padding; i++)
            {
                channel.Put(( sbyte )0);
            }
            // then again, it should work
            // finally, when we pass the limit
            try
            {
                channel.Put(( sbyte )0);
                fail("Should not allow more bytes than what the limit dictates");
            }
            catch (MessageTooBigException)
            {
                // then
            }
        }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static byte[] chunk(int maxChunkSize, byte[][] messages) throws java.io.IOException
        public static sbyte[] Chunk(int maxChunkSize, sbyte[][] messages)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ByteBuffer outputBuffer = ByteBuffer.allocate(1024 * 8);
            ByteBuffer outputBuffer = ByteBuffer.allocate(1024 * 8);

            Channel ch = mock(typeof(Channel));

            when(ch.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
            when(ch.writeAndFlush(any(), Null)).then(inv =>
            {
                ByteBuf buf = inv.getArgument(0);
                outputBuffer.limit(outputBuffer.position() + buf.readableBytes());
                buf.readBytes(outputBuffer);
                buf.release();
                return(null);
            });

            int           maxBufferSize = maxChunkSize + CHUNK_HEADER_SIZE;
            ChunkedOutput @out          = new ChunkedOutput(ch, maxBufferSize, maxBufferSize, TransportThrottleGroup.NO_THROTTLE);

            foreach (sbyte[] message in messages)
            {
                @out.BeginMessage();
                @out.WriteBytes(message, 0, message.Length);
                @out.MessageSucceeded();
            }
            @out.Flush();
            @out.Dispose();

            sbyte[] bytes = new sbyte[outputBuffer.limit()];
            outputBuffer.position(0);
            outputBuffer.get(bytes);
            return(bytes);
        }
Ejemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleHandshakeFollowedImmediatelyByMessage()
        public virtual void ShouldHandleHandshakeFollowedImmediatelyByMessage()
        {
            // Given
            BoltProtocol        protocol       = NewBoltProtocol(1);
            BoltProtocolFactory handlerFactory = NewProtocolFactory(1, protocol);
            EmbeddedChannel     channel        = new EmbeddedChannel(new ProtocolHandshaker(handlerFactory, _boltChannel, _logProvider, false, true));

            // When
            ByteBuf input = Unpooled.wrappedBuffer(new sbyte[] { ( sbyte )0x60, ( sbyte )0x60, unchecked (( sbyte )0xB0), ( sbyte )0x17 }, new sbyte[] { 0, 0, 0, 0 }, new sbyte[] { 0, 0, 0, 1 }, new sbyte[] { 0, 0, 0, 0 }, new sbyte[] { 0, 0, 0, 0 }, new sbyte[] { 1, 2, 3, 4 });                // this is a message

            channel.writeInbound(input);

            // Then
            assertEquals(1, channel.outboundMessages().size());
            assertByteBufEquals(Unpooled.buffer().writeInt(1), channel.readOutbound());

            assertEquals(1, channel.inboundMessages().size());
            assertByteBufEquals(Unpooled.wrappedBuffer(new sbyte[] { 1, 2, 3, 4 }), channel.readInbound());

            Thrown.expect(typeof(NoSuchElementException));
            channel.pipeline().remove(typeof(ProtocolHandshaker));

            assertTrue(channel.Active);
            verify(protocol).install();
        }
Ejemplo n.º 8
0
 private static void ReleaseIfPossible(ByteBuf buf)
 {
     if (buf.refCnt() > 0)
     {
         buf.release();
     }
 }
Ejemplo n.º 9
0
        private static void SendToChannel(GetIndexFilesRequest expectedIndexSnapshotRequest, EmbeddedChannel embeddedChannel)
        {
            embeddedChannel.writeOutbound(expectedIndexSnapshotRequest);

            ByteBuf @object = embeddedChannel.readOutbound();

            embeddedChannel.writeInbound(@object);
        }
Ejemplo n.º 10
0
        public static ReplicatedTransaction Decode(ByteBuf byteBuf)
        {
            int length = byteBuf.readableBytes();

            sbyte[] bytes = new sbyte[length];
            byteBuf.readBytes(bytes);
            return(ReplicatedTransaction.from(bytes));
        }
Ejemplo n.º 11
0
        private static void SendToChannel(PrepareStoreCopyResponse prepareStoreCopyResponse, EmbeddedChannel embeddedChannel)
        {
            embeddedChannel.writeOutbound(prepareStoreCopyResponse);

            ByteBuf @object = embeddedChannel.readOutbound();

            embeddedChannel.writeInbound(@object);
        }
Ejemplo n.º 12
0
        public static DummyRequest Decode(ByteBuf byteBuf)
        {
            int length = byteBuf.readableBytes();

            sbyte[] array = new sbyte[length];
            byteBuf.readBytes(array);
            return(new DummyRequest(array));
        }
Ejemplo n.º 13
0
        public static void SendToChannel <E>(E e, EmbeddedChannel embeddedChannel)
        {
            embeddedChannel.writeOutbound(e);

            ByteBuf @object = embeddedChannel.readOutbound();

            embeddedChannel.writeInbound(@object);
        }
Ejemplo n.º 14
0
        private static void SendToChannel(GetStoreFileRequest getStoreFileRequest, EmbeddedChannel embeddedChannel)
        {
            embeddedChannel.writeOutbound(getStoreFileRequest);

            ByteBuf @object = embeddedChannel.readOutbound();

            embeddedChannel.writeInbound(@object);
        }
Ejemplo n.º 15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void encode(io.netty.buffer.ByteBuf buffer, io.netty.handler.stream.ChunkedInput<io.netty.buffer.ByteBuf> marshal) throws Exception
        private static void Encode(ByteBuf buffer, ChunkedInput <ByteBuf> marshal)
        {
            while (!marshal.EndOfInput)
            {
                ByteBuf tmp = marshal.readChunk(UnpooledByteBufAllocator.DEFAULT);
                if (tmp != null)
                {
                    buffer.writeBytes(tmp);
                    tmp.release();
                }
            }
        }
Ejemplo n.º 16
0
 public static void AssertByteBufEquals(ByteBuf expected, ByteBuf actual)
 {
     try
     {
         assertEquals(expected, actual);
     }
     finally
     {
         ReleaseIfPossible(expected);
         ReleaseIfPossible(actual);
     }
 }
Ejemplo n.º 17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDecodeEmptyChunk()
        public virtual void ShouldDecodeEmptyChunk()
        {
            // chunk contains just the size header which is zero
            ByteBuf input = copyShort(0);

            assertTrue(_channel.writeInbound(input));
            assertTrue(_channel.finish());

            // there should only be a single chunk available for reading
            assertEquals(1, _channel.inboundMessages().size());
            // it should have no size header and empty body
            assertByteBufEquals(wrappedBuffer(new sbyte[0]), _channel.readInbound());
        }
Ejemplo n.º 18
0
 public static void Marshal(ByteBuf buffer, string @string)
 {
     if (string.ReferenceEquals(@string, null))
     {
         buffer.writeInt(NULL_STRING_LENGTH);
     }
     else
     {
         sbyte[] bytes = @string.GetBytes(UTF_8);
         buffer.writeInt(bytes.Length);
         buffer.writeBytes(bytes);
     }
 }
Ejemplo n.º 19
0
        internal static ByteBuf SerializeTerms(RaftLogEntry[] raftLogEntries, ByteBufAllocator byteBufAllocator)
        {
            int     capacity = (sizeof(sbyte) * 8) + (sizeof(int) * 8) + (sizeof(long) * 8) * raftLogEntries.Length;
            ByteBuf buffer   = byteBufAllocator.buffer(capacity, capacity);

            buffer.writeByte(ContentType.RaftLogEntryTerms.get());
            buffer.writeInt(raftLogEntries.Length);
            foreach (RaftLogEntry raftLogEntry in raftLogEntries)
            {
                buffer.writeLong(raftLogEntry.Term());
            }
            return(buffer);
        }
Ejemplo n.º 20
0
        public static string Unmarshal(ByteBuf buffer)
        {
            int len = buffer.readInt();

            if (len == NULL_STRING_LENGTH)
            {
                return(null);
            }

            sbyte[] bytes = new sbyte[len];
            buffer.readBytes(bytes);
            return(StringHelper.NewString(bytes, UTF_8));
        }
Ejemplo n.º 21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSerializeAndDeserializeNull()
        public virtual void ShouldSerializeAndDeserializeNull()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final io.netty.buffer.ByteBuf buffer = buffers.buffer();
            ByteBuf buffer = Buffers.buffer();

            // when
            StringMarshal.Marshal(buffer, null);
            string reconstructed = StringMarshal.Unmarshal(buffer);

            // then
            assertNull(reconstructed);
        }
Ejemplo n.º 22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDecodeMaxSizeChunk()
        public virtual void ShouldDecodeMaxSizeChunk()
        {
            sbyte[] message = new sbyte[0xFFFF];

            ByteBuf input = buffer();

            input.writeShort(message.Length);
            input.writeBytes(message);

            assertTrue(_channel.writeInbound(input));
            assertTrue(_channel.finish());

            assertEquals(1, _channel.inboundMessages().size());
            assertByteBufEquals(wrappedBuffer(message), _channel.readInbound());
        }
Ejemplo n.º 23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSerializeAndDeserializeEmptyString()
        public virtual void ShouldSerializeAndDeserializeEmptyString()
        {
            // given
            const string testString = "";
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final io.netty.buffer.ByteBuf buffer = buffers.buffer();
            ByteBuf buffer = Buffers.buffer();

            // when
            StringMarshal.Marshal(buffer, testString);
            string reconstructed = StringMarshal.Unmarshal(buffer);

            // then
            assertNotSame(testString, reconstructed);
            assertEquals(testString, reconstructed);
        }
Ejemplo n.º 24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRejectIfInsecureWhenEncryptionRequired()
        public virtual void ShouldRejectIfInsecureWhenEncryptionRequired()
        {
            // Given
            BoltProtocol        protocol       = NewBoltProtocol(1);
            BoltProtocolFactory handlerFactory = NewProtocolFactory(1, protocol);
            EmbeddedChannel     channel        = new EmbeddedChannel(new ProtocolHandshaker(handlerFactory, _boltChannel, _logProvider, true, false));

            // When
            ByteBuf input = Unpooled.wrappedBuffer(new sbyte[] { ( sbyte )0x60, ( sbyte )0x60, unchecked (( sbyte )0xB0), ( sbyte )0x17 }, new sbyte[] { 0, 0, 0, 1 }, new sbyte[] { 0, 0, 0, 2 }, new sbyte[] { 0, 0, 0, 3 }, new sbyte[] { 0, 0, 0, 4 });                 // fourth choice - no protocol

            channel.writeInbound(input);

            // Then
            assertEquals(0, channel.outboundMessages().size());
            assertFalse(channel.Active);
            verify(protocol, never()).install();
        }
Ejemplo n.º 25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFallbackToNoProtocolIfNoMatch()
        public virtual void ShouldFallbackToNoProtocolIfNoMatch()
        {
            // Given
            BoltProtocol        protocol       = NewBoltProtocol(1);
            BoltProtocolFactory handlerFactory = NewProtocolFactory(1, protocol);
            EmbeddedChannel     channel        = new EmbeddedChannel(new ProtocolHandshaker(handlerFactory, _boltChannel, _logProvider, false, true));

            // When
            ByteBuf input = Unpooled.wrappedBuffer(new sbyte[] { ( sbyte )0x60, ( sbyte )0x60, unchecked (( sbyte )0xB0), ( sbyte )0x17 }, new sbyte[] { 0, 0, 0, 0 }, new sbyte[] { 0, 0, 0, 2 }, new sbyte[] { 0, 0, 0, 3 }, new sbyte[] { 0, 0, 0, 4 });                 // fourth choice - no protocol

            channel.writeInbound(input);

            // Then
            assertEquals(1, channel.outboundMessages().size());
            assertByteBufEquals(Unpooled.buffer().writeInt(0), channel.readOutbound());

            assertFalse(channel.Active);
            verify(protocol, never()).install();
        }
Ejemplo n.º 26
0
 public override void ChannelRead(ChannelHandlerContext ctx, object msg)
 {
     if (msg is ByteBuf)
     {
         ByteBuf buffer = ( ByteBuf )msg;
         if (_contentTypeProtocol.isExpecting(ContentType.ContentType))
         {
             sbyte       messageCode = buffer.readByte();
             ContentType contentType = GetContentType(messageCode);
             _contentTypeProtocol.expect(contentType);
             if (buffer.readableBytes() == 0)
             {
                 ReferenceCountUtil.release(msg);
                 return;
             }
         }
     }
     ctx.fireChannelRead(msg);
 }
Ejemplo n.º 27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDecodeSplitChunk()
        public virtual void ShouldDecodeSplitChunk()
        {
            // first part of the chunk contains size header and some bytes
            ByteBuf input1 = buffer();

            input1.writeShort(9);
            input1.writeByte(1);
            input1.writeByte(11);
            input1.writeByte(2);
            // nothing should be available for reading
            assertFalse(_channel.writeInbound(input1));

            // second part contains just a single byte
            ByteBuf input2 = buffer();

            input2.writeByte(22);
            // nothing should be available for reading
            assertFalse(_channel.writeInbound(input2));

            // third part contains couple more bytes
            ByteBuf input3 = buffer();

            input3.writeByte(3);
            input3.writeByte(33);
            input3.writeByte(4);
            // nothing should be available for reading
            assertFalse(_channel.writeInbound(input3));

            // fourth part contains couple more bytes, and the chunk is now complete
            ByteBuf input4 = buffer();

            input4.writeByte(44);
            input4.writeByte(5);
            // there should be something to read now
            assertTrue(_channel.writeInbound(input4));

            assertTrue(_channel.finish());

            // there should only be a single chunk available for reading
            assertEquals(1, _channel.inboundMessages().size());
            // it should have no size header and expected body
            assertByteBufEquals(wrappedBuffer(new sbyte[] { 1, 11, 2, 22, 3, 33, 4, 44, 5 }), _channel.readInbound());
        }
Ejemplo n.º 28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldMarshalToSameByteIfByteBufBackedOrNot() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldMarshalToSameByteIfByteBufBackedOrNot()
        {
            PhysicalTransactionRepresentation expectedTx = new PhysicalTransactionRepresentation(Collections.singleton(new Command.NodeCommand(new NodeRecord(1), new NodeRecord(2))));

            expectedTx.SetHeader(new sbyte[0], 1, 2, 3, 4, 5, 6);
            TransactionRepresentationReplicatedTransaction replicatedTransaction = ReplicatedTransaction.from(expectedTx);

            MemoryStream stream = new MemoryStream();
            ByteBuf      buffer = Buffers.buffer();
            OutputStreamWritableChannel outputStreamWritableChannel = new OutputStreamWritableChannel(stream);
            NetworkWritableChannel      networkWritableChannel      = new NetworkWritableChannel(buffer);

            replicatedTransaction.Marshal(outputStreamWritableChannel);
            replicatedTransaction.Marshal(networkWritableChannel);

            sbyte[] bufferArray = Arrays.copyOf(buffer.array(), buffer.writerIndex());

            Assertions.assertArrayEquals(bufferArray, stream.toByteArray());
        }
Ejemplo n.º 29
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSerializeAndDeserialize() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSerializeAndDeserialize()
        {
            // given
            MemberId.Marshal marshal = new MemberId.Marshal();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId member = new org.neo4j.causalclustering.identity.MemberId(java.util.UUID.randomUUID());
            MemberId member = new MemberId(System.Guid.randomUUID());

            // when
            ByteBuf buffer = Unpooled.buffer(1_000);

            marshal.MarshalConflict(member, new BoundedNetworkWritableChannel(buffer));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId recovered = marshal.unmarshal(new org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4(buffer));
            MemberId recovered = marshal.Unmarshal(new NetworkReadableClosableChannelNetty4(buffer));

            // then
            assertEquals(member, recovered);
        }
Ejemplo n.º 30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldWriteToBufferInChunks()
        public virtual void ShouldWriteToBufferInChunks()
        {
            int chunkSize = 5;

            sbyte[] data     = new sbyte[] { 1, 2, 3, 4, 5, 6 };
            sbyte[] readData = new sbyte[6];
            ByteArrayChunkedEncoder byteArraySerializer = new ByteArrayChunkedEncoder(data, chunkSize);

            ByteBuf buffer = byteArraySerializer.ReadChunk(Buffers);

            buffer.readBytes(readData, 0, chunkSize);
            assertEquals(0, buffer.readableBytes());

            buffer = byteArraySerializer.ReadChunk(Buffers);
            buffer.readBytes(readData, chunkSize, 1);
            assertArrayEquals(data, readData);
            assertEquals(0, buffer.readableBytes());

            assertNull(byteArraySerializer.ReadChunk(Buffers));
        }