public async Task TestUnhealthyChannelIsNotOffered() { var group = new MultithreadEventLoopGroup(); var addr = new LocalAddress(LOCAL_ADDR_ID); 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 CountingChannelPoolHandler(); var pool = new SimpleChannelPool(cb, handler); IChannel channel1 = await pool.AcquireAsync(); await pool.ReleaseAsync(channel1); IChannel channel2 = await pool.AcquireAsync(); //first check that when returned healthy then it actually offered back to the pool. Assert.Same(channel1, channel2); await channel1.CloseAsync(); await pool.ReleaseAsync(channel1); IChannel channel3 = await pool.AcquireAsync(); //channel1 was not healthy anymore so it should not get acquired anymore. Assert.NotSame(channel1, channel3); await sc.CloseAsync(); await channel3.CloseAsync(); await group.ShutdownGracefullyAsync(); }
public async Task TestCloseAsync() { var group = new DefaultEventLoopGroup(); 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 CountingChannelPoolHandler(); var pool = new SimpleChannelPool(cb, handler); var ch1 = await pool.AcquireAsync(); var ch2 = await pool.AcquireAsync(); pool.ReleaseAsync(ch1).Wait(TimeSpan.FromSeconds(1)); pool.ReleaseAsync(ch2).Wait(TimeSpan.FromSeconds(1)); // Assert that returned channels are open before close Assert.True(ch1.IsOpen); Assert.True(ch2.IsOpen); // Close asynchronously with timeout await pool.CloseAsync().WithTimeout(TimeSpan.FromSeconds(1)); // Assert channels were indeed closed Assert.False(ch1.IsOpen); Assert.False(ch2.IsOpen); await sc.CloseAsync(); pool.Close(); await group.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(5)); }
public void TestReleaseHealthCheck() { var healthCheckOnReleasePool = new SimpleChannelPool(new Bootstrap(), new CountingChannelPoolHandler(), ChannelActiveHealthChecker.Instance, true); try { Assert.True(healthCheckOnReleasePool.ReleaseHealthCheck); } finally { healthCheckOnReleasePool.Close(); } var noHealthCheckOnReleasePool = new SimpleChannelPool(new Bootstrap(), new CountingChannelPoolHandler(), ChannelActiveHealthChecker.Instance, false); try { Assert.False(noHealthCheckOnReleasePool.ReleaseHealthCheck); } finally { noHealthCheckOnReleasePool.Close(); } }
public async Task TestUnhealthyChannelIsOfferedWhenNoHealthCheckRequested() { var group = new MultithreadEventLoopGroup(); 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 CountingChannelPoolHandler(); var pool = new SimpleChannelPool(cb, handler, ChannelActiveHealthChecker.Instance, false); IChannel channel1 = await pool.AcquireAsync(); await channel1.CloseAsync(); await pool.ReleaseAsync(channel1); IChannel channel2 = await pool.AcquireAsync(); //verifying that in fact the channel2 is different that means is not pulled from the pool Assert.NotSame(channel1, channel2); await sc.CloseAsync(); await channel2.CloseAsync(); pool.Close(); await group.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(5)); }
public virtual ValueTask <IChannel> acquire(NettyFullAddress address) { SimpleChannelPool pool = PoolMapWrapper.PoolMap.Get(address); return(pool.AcquireAsync()); }