Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowErrorWithRemoteAddressWhenClosed() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowErrorWithRemoteAddressWhenClosed()
        {
            Channel          channel   = mock(typeof(Channel));
            ByteBufAllocator allocator = mock(typeof(ByteBufAllocator));

            when(allocator.buffer(anyInt())).thenReturn(Unpooled.buffer());
            when(channel.alloc()).thenReturn(allocator);
            SocketAddress remoteAddress       = mock(typeof(SocketAddress));
            string        remoteAddressString = "client.server.com:7687";

            when(remoteAddress.ToString()).thenReturn(remoteAddressString);
            when(channel.remoteAddress()).thenReturn(remoteAddress);

            ChunkedOutput output = new ChunkedOutput(channel, DEFAULT_TEST_BUFFER_SIZE, DEFAULT_TEST_BUFFER_SIZE, NO_THROTTLE);

            output.Dispose();

            try
            {
                output.WriteInt(42);
                fail("Exception expected");
            }
            catch (PackOutputClosedException e)
            {
                assertThat(e.Message, containsString(remoteAddressString));
            }
        }
Пример #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public io.netty.buffer.ByteBuf readChunk(io.netty.buffer.ByteBufAllocator allocator) throws Exception
        public override ByteBuf ReadChunk(ByteBufAllocator allocator)
        {
            if (_endOfInput)
            {
                return(null);
            }
            ByteBuf data = _byteBufAwareMarshal.readChunk(allocator);

            if (data == null)
            {
                return(null);
            }
            _endOfInput = _byteBufAwareMarshal.EndOfInput;
            CompositeByteBuf allData = new CompositeByteBuf(allocator, false, 2);

            allData.addComponent(true, data);
            try
            {
                bool    isFirstChunk     = Progress() == 0;
                int     metaDataCapacity = MetadataSize(isFirstChunk);
                ByteBuf metaDataBuffer   = allocator.buffer(metaDataCapacity, metaDataCapacity);
                allData.addComponent(true, 0, WriteMetadata(isFirstChunk, _byteBufAwareMarshal.EndOfInput, _contentType, metaDataBuffer));
                _progress += allData.readableBytes();
                Debug.Assert(_progress > 0);                           // logic relies on this
                return(allData);
            }
            catch (Exception e)
            {
                allData.release();
                throw e;
            }
        }
Пример #3
0
            public override ByteBuf ReadChunk(ByteBufAllocator allocator)
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                int?size = Sizes.next();

                if (size == null)
                {
                    return(null);
                }
                return(allocator.buffer(size).writerIndex(size));
            }
Пример #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Object readChunk(io.netty.buffer.ByteBufAllocator allocator) throws Exception
        public override object ReadChunk(ByteBufAllocator allocator)
        {
            Debug.Assert(!_endOfInput);

            if (_pending != null)
            {
                if (_noMoreTransactions)
                {
                    _endOfInput = true;
                }

                return(ConsumePending());
            }
            else if (_noMoreTransactions)
            {
                /* finalization should always have a last ending message */
                throw new System.InvalidOperationException();
            }
            else if (_txCursor.next())
            {
                Debug.Assert(_pending == null);

                CommittedTransactionRepresentation tx = _txCursor.get();
                _lastTxId = tx.CommitEntry.TxId;
                if (_lastTxId != _expectedTxId)
                {
                    string msg = format("Transaction cursor out of order. Expected %d but was %d", _expectedTxId, _lastTxId);
                    throw new System.InvalidOperationException(msg);
                }
                _expectedTxId++;
                _pending = new TxPullResponse(_storeId, tx);
                return(ResponseMessageType.TX);
            }
            else
            {
                Debug.Assert(_pending == null);

                _noMoreTransactions = true;
                _protocol.expect(CatchupServerProtocol.State.MESSAGE_TYPE);
                CatchupResult result;
                if (_lastTxId >= _txIdPromise)
                {
                    result = SUCCESS_END_OF_STREAM;
                }
                else
                {
                    result = E_TRANSACTION_PRUNED;
                    _log.warn("Transaction cursor fell short. Expected at least %d but only got to %d.", _txIdPromise, _lastTxId);
                }
                _pending = new TxStreamFinishedResponse(result, _lastTxId);
                return(ResponseMessageType.TX_STREAM_FINISHED);
            }
        }
Пример #5
0
 /// <param name="allocator"> used to allocated <seealso cref="ByteBuf"/> </param> </param>
 /// <param name="maxChunkSize"> when reached the current buffer will be moved to the <param name="outputQueue"> and a new <seealso cref="ByteBuf"/> is allocated </param>
 /// <param name="outputQueue"> full or flushed buffers are added here. If this queue is bounded then writing to this channel may block! </param>
 public ChunkingNetworkChannel(ByteBufAllocator allocator, int maxChunkSize, LinkedList <ByteBuf> outputQueue)
 {
     Objects.requireNonNull(allocator, "allocator cannot be null");
     Objects.requireNonNull(outputQueue, "outputQueue cannot be null");
     this._allocator    = allocator;
     this._maxChunkSize = maxChunkSize;
     this._initSize     = min(DEFAULT_INIT_CHUNK_SIZE, maxChunkSize);
     if (maxChunkSize < Double.BYTES)
     {
         throw new System.ArgumentException("Chunk size must be at least 8. Got " + maxChunkSize);
     }
     this._byteBufs = outputQueue;
 }
Пример #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public io.netty.buffer.ByteBuf readChunk(io.netty.buffer.ByteBufAllocator allocator) throws Exception
            public override ByteBuf ReadChunk(ByteBufAllocator allocator)
            {
                if (IsEndOfInput)
                {
                    return(null);
                }
                ByteBuf buffer = allocator.buffer();

                Marshaller.accept(new BoundedNetworkWritableChannel(buffer));
                IsEndOfInput = true;
                Offset       = buffer.readableBytes();
                return(buffer);
            }
Пример #7
0
        public override ByteBuf ReadChunk(ByteBufAllocator allocator)
        {
            _hasRead = true;
            if (EndOfInput)
            {
                return(null);
            }
            int     toWrite = Math.Min(Available(), _chunkSize);
            ByteBuf buffer  = allocator.buffer(toWrite);

            try
            {
                buffer.writeBytes(_content, _pos, toWrite);
                _pos += toWrite;
                return(buffer);
            }
            catch (Exception t)
            {
                buffer.release();
                throw t;
            }
        }
Пример #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public io.netty.buffer.ByteBuf readChunk(io.netty.buffer.ByteBufAllocator allocator) throws Exception
        public override ByteBuf ReadChunk(ByteBufAllocator allocator)
        {
            if (EndOfInput)
            {
                return(null);
            }
            if (_channel == null)
            {
                // Ensure that the written buffers does not overflow the allocators chunk size.
                _channel = new ChunkingNetworkChannel(allocator, CHUNK_SIZE, _chunks);
            }

            // write to chunks if empty and there is more to write
            while (_txWriter.canWrite() && _chunks.Count == 0)
            {
                _txWriter.write(_channel);
            }
            // nothing more to write, close the channel to get the potential last buffer
            if (_chunks.Count == 0)
            {
                _channel.close();
            }
            return(_chunks.RemoveFirst());
        }
Пример #9
0
 public Buffers(ByteBufAllocator allocator)
 {
     this._allocator = allocator;
 }
Пример #10
0
 public override ByteBuf Cumulate(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf @in)
 {
     outerInstance.isLast = @in.readBoolean();
     return(COMPOSITE_CUMULATOR.cumulate(alloc, cumulation, @in));
 }
Пример #11
0
 internal Handler(RaftMessageContentEncoder outerInstance, IList <object> @out, ByteBufAllocator alloc)
 {
     this._outerInstance = outerInstance;
     this.Out            = @out;
     this.Alloc          = alloc;
 }