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 canWriteLargestAtomAfterFillingBuffer()
        public virtual void CanWriteLargestAtomAfterFillingBuffer()
        {
            sbyte[]       bytes         = new sbyte[300];
            ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);

            wrappedBuffer.resetWriterIndex();
            BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer, (new Monitors()).newMonitor(typeof(ByteCounterMonitor)));

            sbyte[] bytesValue = new sbyte[255];
            bytesValue[0]   = 1;
            bytesValue[254] = -1;
            long longValue = 123456;

            buffer.Put(bytesValue, bytesValue.Length);
            buffer.PutLong(longValue);
            buffer.Dispose();

            ByteBuffer verificationBuffer = ByteBuffer.wrap(bytes);

            assertEquals(( sbyte )0, verificationBuffer.get());
            sbyte[] actualBytes = new sbyte[bytesValue.Length];
            verificationBuffer.get(actualBytes);
            assertThat(actualBytes, new ArrayMatches <>(this, bytesValue));
            assertEquals(( sbyte )8, verificationBuffer.get());
            assertEquals(longValue, verificationBuffer.Long);
        }
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 canReaderReallyLargeByteArray()
        public virtual void CanReaderReallyLargeByteArray()
        {
            sbyte[]       bytes         = new sbyte[650];
            ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);

            wrappedBuffer.resetWriterIndex();
            BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer, (new Monitors()).newMonitor(typeof(ByteCounterMonitor)));

            sbyte[] bytesValue = new sbyte[600];
            bytesValue[1]   = 1;
            bytesValue[99]  = 2;
            bytesValue[199] = 3;
            bytesValue[299] = 4;
            bytesValue[399] = 5;
            bytesValue[499] = 6;
            bytesValue[599] = 7;
            buffer.Put(bytesValue, bytesValue.Length);
            buffer.Dispose();

            sbyte[]        actual;
            BlockLogReader reader             = new BlockLogReader(wrappedBuffer);
            ByteBuffer     verificationBuffer = ByteBuffer.wrap(new sbyte[1000]);

            reader.Read(verificationBuffer);
            verificationBuffer.flip();
            actual = new sbyte[255];
            verificationBuffer.get(actual);
            assertThat(actual, new ArrayMatches <>(this, Arrays.copyOfRange(bytesValue, 0, 255)));
            actual = new sbyte[255];
            verificationBuffer.get(actual);
            assertThat(actual, new ArrayMatches <>(this, Arrays.copyOfRange(bytesValue, 255, 510)));
            actual = new sbyte[90];
            verificationBuffer.get(actual);
            assertThat(actual, new ArrayMatches <>(this, Arrays.copyOfRange(bytesValue, 510, 600)));
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void readSmallPortions() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ReadSmallPortions()
        {
            sbyte[]       bytes         = new sbyte[255];
            ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);

            wrappedBuffer.resetWriterIndex();
            BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer, (new Monitors()).newMonitor(typeof(ByteCounterMonitor)));

            sbyte byteValue = 5;
            int   intValue  = 1234;
            long  longValue = 574853;

            buffer.Put(byteValue);
            buffer.PutInt(intValue);
            buffer.PutLong(longValue);
            buffer.Dispose();

            ReadableByteChannel reader             = new BlockLogReader(wrappedBuffer);
            ByteBuffer          verificationBuffer = ByteBuffer.wrap(new sbyte[1]);

            reader.read(verificationBuffer);
            verificationBuffer.flip();
            assertEquals(byteValue, verificationBuffer.get());
            verificationBuffer = ByteBuffer.wrap(new sbyte[4]);
            reader.read(verificationBuffer);
            verificationBuffer.flip();
            assertEquals(intValue, verificationBuffer.Int);
            verificationBuffer = ByteBuffer.wrap(new sbyte[8]);
            reader.read(verificationBuffer);
            verificationBuffer.flip();
            assertEquals(longValue, verificationBuffer.Long);
        }
Ejemplo n.º 4
0
 public override void Write(ChannelBuffer buffer)
 {
     buffer.writeInt(Type.typeId());
     buffer.writeInt(ResourceIds.Length);
     foreach (long entity in ResourceIds)
     {
         buffer.writeLong(entity);
     }
 }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static org.jboss.netty.buffer.ChannelBuffer triggerOperationCompleteCallback(BufferReusingChunkingChannelBuffer buffer) throws Exception
        private static ChannelBuffer TriggerOperationCompleteCallback(BufferReusingChunkingChannelBuffer buffer)
        {
            ChannelBuffer reusedBuffer = spy(ChannelBuffers.dynamicBuffer());

            ChannelFuture channelFuture = mock(typeof(ChannelFuture));

            when(channelFuture.Done).thenReturn(true);
            when(channelFuture.Success).thenReturn(true);

            buffer.NewChannelFutureListener(reusedBuffer).operationComplete(channelFuture);
            return(reusedBuffer);
        }
Ejemplo n.º 6
0
        private static BufferReusingChunkingChannelBuffer NewBufferReusingChunkingChannelBuffer(int capacity, CountingChannelBufferFactory bufferFactory)
        {
            ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();

            Channel       channel       = mock(typeof(Channel));
            ChannelFuture channelFuture = mock(typeof(ChannelFuture));

            when(channel.Open).thenReturn(true);
            when(channel.Connected).thenReturn(true);
            when(channel.Bound).thenReturn(true);
            when(channel.write(any())).thenReturn(channelFuture);

            return(new BufferReusingChunkingChannelBuffer(buffer, bufferFactory, channel, capacity, ( sbyte )1, ( sbyte )1));
        }
Ejemplo n.º 7
0
        protected internal override StoreId ReadStoreId(ChannelBuffer source, ByteBuffer byteBuffer)
        {
            byteBuffer.clear();
            byteBuffer.limit(8 + 8 + 8 + 8 + 8);                 // creation time, random id, store version, upgrade time, upgrade id
            source.readBytes(byteBuffer);
            byteBuffer.flip();
            // read order matters - see Server.writeStoreId() for version 2.1.4
            long creationTime = byteBuffer.Long;
            long randomId     = byteBuffer.Long;
            long storeVersion = byteBuffer.Long;
            long upgradeTime  = byteBuffer.Long;
            long upgradeId    = byteBuffer.Long;

            return(new StoreId(creationTime, randomId, storeVersion, upgradeTime, upgradeId));
        }
Ejemplo n.º 8
0
        private static IdAllocation ReadIdAllocation(ChannelBuffer buffer)
        {
            int numberOfDefragIds = buffer.readInt();

            long[] defragIds = new long[numberOfDefragIds];
            for (int i = 0; i < numberOfDefragIds; i++)
            {
                defragIds[i] = buffer.readLong();
            }
            long rangeStart  = buffer.readLong();
            int  rangeLength = buffer.readInt();
            long highId      = buffer.readLong();
            long defragCount = buffer.readLong();

            return(new IdAllocation(new IdRange(defragIds, rangeStart, rangeLength), highId, defragCount));
        }
Ejemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void onlyOneFullBlock()
        public virtual void OnlyOneFullBlock()
        {
            sbyte[]       bytes         = new sbyte[256];
            ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);

            wrappedBuffer.resetWriterIndex();
            BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer, (new Monitors()).newMonitor(typeof(ByteCounterMonitor)));

            sbyte[] bytesValue = new sbyte[255];
            bytesValue[0]   = 1;
            bytesValue[254] = -1;
            buffer.Put(bytesValue, bytesValue.Length);
            buffer.Dispose();

            ByteBuffer verificationBuffer = ByteBuffer.wrap(bytes);

            assertEquals(unchecked (( sbyte )255), verificationBuffer.get());
            sbyte[] actualBytes = new sbyte[bytesValue.Length];
            verificationBuffer.get(actualBytes);
            assertThat(actualBytes, new ArrayMatches <>(this, bytesValue));
        }
Ejemplo n.º 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void readOnlyOneNonFullBlock() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ReadOnlyOneNonFullBlock()
        {
            sbyte[]       bytes         = new sbyte[255];
            ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);

            wrappedBuffer.resetWriterIndex();
            BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer, (new Monitors()).newMonitor(typeof(ByteCounterMonitor)));

            sbyte  byteValue   = 5;
            int    intValue    = 1234;
            long   longValue   = 574853;
            float  floatValue  = 304985.5f;
            double doubleValue = 48493.22d;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final byte[] bytesValue = new byte[] { 1, 5, 2, 6, 3 };
            sbyte[] bytesValue = new sbyte[] { 1, 5, 2, 6, 3 };
            buffer.Put(byteValue);
            buffer.PutInt(intValue);
            buffer.PutLong(longValue);
            buffer.PutFloat(floatValue);
            buffer.PutDouble(doubleValue);
            buffer.Put(bytesValue, bytesValue.Length);
            buffer.Dispose();

            ReadableByteChannel reader             = new BlockLogReader(wrappedBuffer);
            ByteBuffer          verificationBuffer = ByteBuffer.wrap(new sbyte[1000]);

            reader.read(verificationBuffer);
            verificationBuffer.flip();
            assertEquals(byteValue, verificationBuffer.get());
            assertEquals(intValue, verificationBuffer.Int);
            assertEquals(longValue, verificationBuffer.Long);
            assertEquals(floatValue, verificationBuffer.Float, 0.0);
            assertEquals(doubleValue, verificationBuffer.Double, 0.0);
            sbyte[] actualBytes = new sbyte[bytesValue.Length];
            verificationBuffer.get(actualBytes);
            assertThat(actualBytes, new ArrayMatches <>(this, bytesValue));
        }
Ejemplo n.º 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test @SuppressWarnings("unchecked") public void freeBuffersAreReused() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void FreeBuffersAreReused()
        {
            CountingChannelBufferFactory       bufferFactory = new CountingChannelBufferFactory();
            BufferReusingChunkingChannelBuffer buffer        = NewBufferReusingChunkingChannelBuffer(10, bufferFactory);

            buffer.WriteLong(1);
            buffer.WriteLong(2);

            // return 2 buffers to the pool
            ChannelBuffer reusedBuffer1 = TriggerOperationCompleteCallback(buffer);
            ChannelBuffer reusedBuffer2 = TriggerOperationCompleteCallback(buffer);

            buffer.WriteLong(3);
            buffer.WriteLong(4);

            // 2 buffers were created
            assertEquals(2, bufferFactory.InstancesCreated);

            // and 2 buffers were reused
            verify(reusedBuffer1).writeLong(3);
            verify(reusedBuffer2).writeLong(4);
        }
Ejemplo n.º 12
0
 public abstract Response <R> Call(T requestTarget, RequestContext context, ChannelBuffer input, ChannelBuffer target);
Ejemplo n.º 13
0
 public ChannelContext(Channel channel, ChannelBuffer output, ByteBuffer input)
 {
     this._channel = requireNonNull(channel);
     this._output  = requireNonNull(output);
     this._input   = requireNonNull(input);
 }
Ejemplo n.º 14
0
 protected internal override ChunkingChannelBuffer NewChunkingBuffer(ChannelBuffer bufferToWriteTo, Channel channel, int capacity, sbyte internalProtocolVersion, sbyte applicationProtocolVersion)
 {
     return(new BufferReusingChunkingChannelBuffer(bufferToWriteTo, channel, capacity, internalProtocolVersion, applicationProtocolVersion));
 }
Ejemplo n.º 15
0
        protected internal static System.IndexOutOfRangeException WithInvalidOrdinalMessage(ChannelBuffer buffer, sbyte statusOrdinal, System.IndexOutOfRangeException e)
        {
            int maxBytesToPrint = 1024 * 40;

            return(Exceptions.withMessage(e, format("%s | read invalid ordinal %d. First %db of this channel buffer is:%n%s", e.Message, statusOrdinal, maxBytesToPrint, BeginningOfBufferAsHexString(buffer, maxBytesToPrint))));
        }
Ejemplo n.º 16
0
 public NetworkReadableClosableChannel(ChannelBuffer input)
 {
     this.@delegate = input;
 }
Ejemplo n.º 17
0
        public ToNetworkStoreWriter(ChannelBuffer targetBuffer, Monitors monitors)
        {
            this._targetBuffer = targetBuffer;
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            _bufferMonitor = monitors.NewMonitor(typeof(ByteCounterMonitor), this.GetType().FullName, STORE_COPIER_MONITOR_TAG);
        }
Ejemplo n.º 18
0
        public override Response <LockResult> Call(Master master, RequestContext context, ChannelBuffer input, ChannelBuffer target)
        {
            ResourceType type = ResourceTypes.fromId(input.readInt());

            long[] ids = new long[input.readInt()];
            for (int i = 0; i < ids.Length; i++)
            {
                ids[i] = input.readLong();
            }
            return(Lock(master, context, type, ids));
        }
Ejemplo n.º 19
0
 public NetworkFlushableChannel(ChannelBuffer @delegate)
 {
     this.@delegate = @delegate;
 }