예제 #1
0
        public async Task TestReleaseClosed()
        {
            var addr = new LocalAddress(ChannelPoolTestUtils.GetLocalAddrId());
            Bootstrap cb = new Bootstrap().RemoteAddress(addr).Group(_group).Channel<LocalChannel>();

            ServerBootstrap sb = new ServerBootstrap()
                .Group(_group)
                .Channel<LocalServerChannel>()
                .ChildHandler(
                    new ActionChannelInitializer<LocalChannel>(
                        ch => ch.Pipeline.AddLast(new ChannelHandlerAdapter()))
                );

            // Start server
            IChannel sc = await sb.BindAsync(addr);

            var pool = new FixedChannelPool(cb, new TestChannelPoolHandler(), 2);
            IChannel channel = await pool.AcquireAsync();
            await channel.CloseAsync();
            await pool.ReleaseAsync(channel);

            await sc.CloseAsync();
            pool.Close();
        }
예제 #2
0
        public async Task TestReleaseDifferentPool()
        {
            var       addr = new LocalAddress(ChannelPoolTestUtils.GetLocalAddrId());
            Bootstrap cb   = new Bootstrap().RemoteAddress(addr).Group(_group).Channel <LocalChannel>();

            ServerBootstrap sb = new ServerBootstrap()
                                 .Group(_group)
                                 .Channel <LocalServerChannel>()
                                 .ChildHandler(
                new ActionChannelInitializer <LocalChannel>(
                    ch => ch.Pipeline.AddLast(new ChannelHandlerAdapter()))
                );

            // Start server
            IChannel sc = await sb.BindAsync(addr);

            var handler = new TestChannelPoolHandler();
            var pool    = new FixedChannelPool(cb, handler, 1, 1);
            var pool2   = new FixedChannelPool(cb, handler, 1, 1);

            IChannel channel = await pool.AcquireAsync();

            try
            {
                await Assert.ThrowsAsync <ArgumentException>(async() => await pool2.ReleaseAsync(channel));
            }
            finally
            {
                await sc.CloseAsync();

                await channel.CloseAsync();

                pool.Close();
                pool2.Close();
            }
        }