Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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
            }
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void checkSize(int additional) throws MessageTooBigException
        private void CheckSize(int additional)
        {
            int writtenSoFar = @delegate.writerIndex() - _initialWriterIndex;
            int countToCheck = writtenSoFar + additional;

            if (countToCheck > _sizeLimit)
            {
                throw new MessageTooBigException(format("Size limit exceeded. Limit is %d, wanted to write %d with the writer index at %d (started at %d), written so far %d", _sizeLimit, additional, @delegate.writerIndex(), _initialWriterIndex, writtenSoFar));
            }
        }
Exemplo n.º 4
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());
        }
Exemplo n.º 5
0
 public BoundedNetworkWritableChannel(ByteBuf @delegate, long sizeLimit)
 {
     this.@delegate           = @delegate;
     this._initialWriterIndex = @delegate.writerIndex();
     this._sizeLimit          = sizeLimit;
 }