public async Task TestAcquireTimeout() { var addr = new LocalAddress(LOCAL_ADDR_ID); Bootstrap cb = new Bootstrap().RemoteAddress(addr).Group(this.group).Channel <LocalChannel>(); ServerBootstrap sb = new ServerBootstrap() .Group(this.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, ChannelActiveHealthChecker.Instance, FixedChannelPool.AcquireTimeoutAction.Fail, TimeSpan.FromMilliseconds(500), 1, int.MaxValue); IChannel channel = await pool.AcquireAsync(); try { await Assert.ThrowsAsync <TimeoutException>(async() => await pool.AcquireAsync()); } finally { await sc.CloseAsync(); await channel.CloseAsync(); } }
public async Task TestReleaseDifferentPool() { var addr = new LocalAddress(LOCAL_ADDR_ID); Bootstrap cb = new Bootstrap().RemoteAddress(addr).Group(this.group).Channel <LocalChannel>(); ServerBootstrap sb = new ServerBootstrap() .Group(this.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(); } }
public async Task TestAcquireNewConnectionWhen() { var addr = new LocalAddress(LOCAL_ADDR_ID); Bootstrap cb = new Bootstrap().RemoteAddress(addr).Group(this.group).Channel <LocalChannel>(); ServerBootstrap sb = new ServerBootstrap() .Group(this.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); IChannel channel1 = await pool.AcquireAsync(); await channel1.CloseAsync(); pool.ReleaseAsync(channel1); IChannel channel2 = await pool.AcquireAsync(); Assert.NotSame(channel1, channel2); await sc.CloseAsync(); await channel2.CloseAsync(); }
public async Task TestAcquireBoundQueue() { 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); IChannel channel = await pool.AcquireAsync(); var future = pool.AcquireAsync(); Assert.False(future.IsCompleted); try { await Assert.ThrowsAsync<InvalidOperationException>(async () => await pool.AcquireAsync()); } finally { await sc.CloseAsync(); await channel.CloseAsync(); pool.Close(); } }
public async Task TestAcquireNewConnectionWhen() { 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); IChannel channel1 = await pool.AcquireAsync(); await channel1.CloseAsync(); #pragma warning disable CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法 pool.ReleaseAsync(channel1); #pragma warning restore CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法 IChannel channel2 = await pool.AcquireAsync(); Assert.NotSame(channel1, channel2); await sc.CloseAsync(); await channel2.CloseAsync(); pool.Close(); }
public async Task TestAcquireNewConnection() { 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, ChannelActiveHealthChecker.Instance, FixedChannelPool.AcquireTimeoutAction.New, TimeSpan.FromMilliseconds(500), 1, int.MaxValue); IChannel channel = await pool.AcquireAsync(); IChannel channel2 = await pool.AcquireAsync(); Assert.NotSame(channel, channel2); await sc.CloseAsync(); await channel.CloseAsync(); await channel2.CloseAsync(); pool.Close(); }