예제 #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);
            }
        }
예제 #2
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());
        }