Exemple #1
0
        public void DifferentClassesAreNotEqual()
        {
            // all objects here have EMPTY_BUFFER data but are instances of different classes
            // so we want to check that none of them are equal to another.
            IByteBufferHolder dflt      = new DefaultByteBufferHolder(Unpooled.Empty);
            IByteBufferHolder other     = new OtherByteBufHolder(Unpooled.Empty, 123);
            IByteBufferHolder constant1 = new DefaultByteBufferHolder1(Unpooled.Empty);
            IByteBufferHolder constant2 = new DefaultByteBufferHolder2(Unpooled.Empty);

            try
            {
                // not using 'assertNotEquals' to be explicit about which object we are calling .equals() on
                Assert.False(dflt.Equals(other));
                Assert.False(dflt.Equals(constant1));
                Assert.False(constant1.Equals(dflt));
                Assert.False(constant1.Equals(other));
                Assert.False(constant1.Equals(constant2));
            }
            finally
            {
                dflt.Release();
                other.Release();
                constant1.Release();
                constant2.Release();
            }
        }
        public void TestReadFlowManagement()
        {
            ReadCounter       counter = new ReadCounter();
            IByteBufferHolder first   = Message("first");
            IByteBufferHolder chunk   = Message("chunk");
            IByteBufferHolder last    = Message("last");

            var             agg      = new MockMessageAggregator(first, chunk, last);
            EmbeddedChannel embedded = new EmbeddedChannel(counter, agg);

            embedded.Configuration.IsAutoRead = false;

            Assert.False(embedded.WriteInbound(first));
            Assert.False(embedded.WriteInbound(chunk));
            Assert.True(embedded.WriteInbound(last));

            Assert.Equal(3, counter.Value); // 2 reads issued from MockMessageAggregator
                                            // 1 read issued from EmbeddedChannel constructor

            IByteBufferHolder all = new DefaultByteBufferHolder(Unpooled.WrappedBuffer(
                                                                    (IByteBuffer)first.Content.Retain(), (IByteBuffer)chunk.Content.Retain(), (IByteBuffer)last.Content.Retain()));
            var output = embedded.ReadInbound <IByteBufferHolder>();

            Assert.Equal(all, output);
            Assert.True(all.Release() && output.Release());
            Assert.False(embedded.Finish());
        }
Exemple #3
0
        public void ConvertToString()
        {
            var holder = new DefaultByteBufferHolder(Unpooled.Buffer());

            Assert.Equal(1, holder.ReferenceCount);
            Assert.NotNull(holder.ToString());
            Assert.True(holder.Release());
            Assert.NotNull(holder.ToString());
        }
Exemple #4
0
        public void EqualsAndHashCode()
        {
            var holder             = new DefaultByteBufferHolder(Unpooled.Empty);
            IByteBufferHolder copy = holder.Copy();

            try
            {
                Assert.Equal(holder, copy);
                Assert.Equal(holder.GetHashCode(), copy.GetHashCode());
            }
            finally
            {
                holder.Release();
                copy.Release();
            }
        }
        public void TestEqualOperation()
        {
            // in this case, 'goAwayFrame' and 'unknownFrame' will also have an EMPTY_BUFFER data
            // so we want to check that 'dflt' will not consider them equal.
            DefaultHttp2GoAwayFrame  goAwayFrame  = new DefaultHttp2GoAwayFrame(Http2Error.ProtocolError);
            DefaultHttp2UnknownFrame unknownFrame = new DefaultHttp2UnknownFrame(Http2FrameTypes.Headers, new Http2Flags(1));
            var dflt = new DefaultByteBufferHolder(Unpooled.Empty);

            try
            {
                // not using 'assertNotEquals' to be explicit about which object we are calling .equals() on
                Assert.False(dflt.Equals(goAwayFrame));
                Assert.False(dflt.Equals(unknownFrame));
            }
            finally
            {
                goAwayFrame.Release();
                unknownFrame.Release();
                dflt.Release();
            }
        }