示例#1
0
        public void TestFilterBigDataPacket()
        {
            ChannelOptions channelOptions = new ChannelOptions()
            {
                MaxPackageLength = 2048
            };

            byte[] data;
            ReadOnlySequence <byte> sequence;

            byte[]       beginMark      = new byte[] { (byte)'(' };
            byte[]       endMark        = new byte[] { (byte)')' };
            string       beginMarkStr   = GetMarkString(beginMark);
            string       endMarkStr     = GetMarkString(endMark);
            FilterInfo   filterInfo     = CreateFilterInfo(beginMark, endMark);
            IFilter      pipelineFilter = new BeginEndMarkPipelineFilter(channelOptions, filterInfo);
            BaizeSession baizeSession   = new BaizeSession(Guid.NewGuid().ToString());

            data = new byte[3000];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = (byte)'1';
            }
            sequence = new ReadOnlySequence <byte>(data);
            Assert.False(pipelineFilter.FilterData(baizeSession, sequence));

            data = new byte[2040];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = (byte)'2';
            }
            sequence = new ReadOnlySequence <byte>(data);
            Assert.False(pipelineFilter.FilterData(baizeSession, sequence));

            data = new byte[1024];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = (byte)'3';
            }
            data[2]    = (byte)'(';
            data[3]    = (byte)'!';
            data[4]    = (byte)'4';
            data[998]  = (byte)'4';
            data[999]  = (byte)'@';
            data[1000] = (byte)')';
            byte[] contentData = new byte[997];
            Array.Copy(data, 3, contentData, 0, contentData.Length);
            sequence = new ReadOnlySequence <byte>(data);
            if (pipelineFilter.FilterData(baizeSession, sequence))
            {
                string str        = baizeSession.Data.GetString(Encoding.ASCII);
                string contentStr = GetMarkString(contentData);
                Assert.Equal(beginMarkStr + contentStr + endMarkStr, str);
            }
        }
示例#2
0
        public void TestFilterHighFreq()
        {
            ChannelOptions channelOptions = new ChannelOptions()
            {
                MaxPackageLength = 2048
            };

            byte[] data;
            ReadOnlySequence <byte> sequence;

            byte[]       beginMark      = new byte[] { (byte)'(', (byte)'!' };
            byte[]       endMark        = new byte[] { (byte)'@', (byte)')' };
            string       beginMarkStr   = GetMarkString(beginMark);
            string       endMarkStr     = GetMarkString(endMark);
            FilterInfo   filterInfo     = CreateFilterInfo(beginMark, endMark);
            IFilter      pipelineFilter = new BeginEndMarkPipelineFilter(channelOptions, filterInfo);
            BaizeSession baizeSession   = new BaizeSession(Guid.NewGuid().ToString());

            data = new byte[1001];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = (byte)'3';
            }
            data[2]    = (byte)'(';
            data[3]    = (byte)'!';
            data[4]    = (byte)'4';
            data[998]  = (byte)'4';
            data[999]  = (byte)'@';
            data[1000] = (byte)')';
            byte[] contentData = new byte[995];
            Array.Copy(data, 4, contentData, 0, contentData.Length);
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            for (int k = 0; k < 100000; k++)
            {
                sequence = new ReadOnlySequence <byte>(data);
                if (pipelineFilter.FilterData(baizeSession, sequence))
                {
                    string str        = baizeSession.Data.GetString(Encoding.ASCII);
                    string contentStr = GetMarkString(contentData);
                    Assert.Equal(beginMarkStr + contentStr + endMarkStr, str);
                }
            }
            stopwatch.Stop();
            Console.WriteLine($"运行时间:{stopwatch.ElapsedMilliseconds / 1000}s");
        }
示例#3
0
        public void TestFilterDifferentSingleMark()
        {
            ChannelOptions channelOptions = new ChannelOptions();

            byte[] data;
            ReadOnlySequence <byte> sequence;

            byte[]       beginMark      = new byte[] { (byte)'(' };
            byte[]       endMark        = new byte[] { (byte)')' };
            string       beginMarkStr   = GetMarkString(beginMark);
            string       endMarkStr     = GetMarkString(endMark);
            FilterInfo   filterInfo     = CreateFilterInfo(beginMark, endMark);
            IFilter      pipelineFilter = new BeginEndMarkPipelineFilter(channelOptions, filterInfo);
            BaizeSession baizeSession   = new BaizeSession(Guid.NewGuid().ToString());

            data     = new byte[] { (byte)'(', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)')' };
            sequence = new ReadOnlySequence <byte>(data);
            if (pipelineFilter.FilterData(baizeSession, sequence))
            {
                string str = baizeSession.Data.GetString(Encoding.ASCII);
                Assert.Equal(beginMarkStr + "123456" + endMarkStr, str);
            }

            data     = new byte[] { (byte)'(', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5' };
            sequence = new ReadOnlySequence <byte>(data);
            Assert.False(pipelineFilter.FilterData(baizeSession, sequence));

            data     = new byte[] { (byte)'7', (byte)'8', (byte)'9', (byte)')' };
            sequence = new ReadOnlySequence <byte>(data);
            if (pipelineFilter.FilterData(baizeSession, sequence))
            {
                string str = baizeSession.Data.GetString(Encoding.ASCII);
                Assert.Equal(beginMarkStr + "12345789" + endMarkStr, str);
            }

            data     = new byte[] { (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'(' };
            sequence = new ReadOnlySequence <byte>(data);
            Assert.False(pipelineFilter.FilterData(baizeSession, sequence));

            data     = new byte[] { (byte)'7', (byte)'8', (byte)'9', (byte)')' };
            sequence = new ReadOnlySequence <byte>(data);
            if (pipelineFilter.FilterData(baizeSession, sequence))
            {
                string str = baizeSession.Data.GetString(Encoding.ASCII);
                Assert.Equal(beginMarkStr + "789" + endMarkStr, str);
            }


            data     = new byte[] { (byte)'(', (byte)'1', (byte)'2', (byte)'3', (byte)'(', (byte)'5', (byte)'6', (byte)')' };
            sequence = new ReadOnlySequence <byte>(data);
            if (pipelineFilter.FilterData(baizeSession, sequence))
            {
                string str = baizeSession.Data.GetString(Encoding.ASCII);
                Assert.Equal(beginMarkStr + "123(56" + endMarkStr, str);
            }

            data     = new byte[] { (byte)'0', (byte)'(', (byte)'2', (byte)'3', (byte)'(', (byte)'5', (byte)'6', (byte)')', (byte)'7', (byte)'8' };
            sequence = new ReadOnlySequence <byte>(data);
            if (pipelineFilter.FilterData(baizeSession, sequence))
            {
                string str = baizeSession.Data.GetString(Encoding.ASCII);
                Assert.Equal(beginMarkStr + "23(56" + endMarkStr, str);
            }


            data     = new byte[] { (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'3', (byte)'5', (byte)'6' };
            sequence = new ReadOnlySequence <byte>(data);
            Assert.False(pipelineFilter.FilterData(baizeSession, sequence));
            data     = new byte[] { (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'(', (byte)'5', (byte)'6', (byte)'7' };
            sequence = new ReadOnlySequence <byte>(data);
            Assert.False(pipelineFilter.FilterData(baizeSession, sequence));

            data     = new byte[] { (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'5', (byte)'5', (byte)'6', (byte)'7', (byte)'8' };
            sequence = new ReadOnlySequence <byte>(data);
            Assert.False(pipelineFilter.FilterData(baizeSession, sequence));

            data     = new byte[] { (byte)'1', (byte)'(', (byte)'2', (byte)'3', (byte)'4', (byte)')', (byte)'6', (byte)'7', (byte)'6', (byte)'7' };
            sequence = new ReadOnlySequence <byte>(data);
            if (pipelineFilter.FilterData(baizeSession, sequence))
            {
                string str = baizeSession.Data.GetString(Encoding.ASCII);
                Assert.Equal(beginMarkStr + "5670123556781(234" + endMarkStr, str);
            }
        }