예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLogOnlyTheFirstCaughtException() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLogOnlyTheFirstCaughtException()
        {
            AssertableLogProvider logProvider = new AssertableLogProvider();
            BoltConnection        connection  = mock(typeof(BoltConnection));
            HouseKeeper           houseKeeper = new HouseKeeper(connection, logProvider.GetLog(typeof(HouseKeeper)));
            Bootstrap             bootstrap   = NewBootstrap(houseKeeper);

            Exception error1 = new Exception("error #1");
            Exception error2 = new Exception("error #2");
            Exception error3 = new Exception("error #3");

            try
            {
                using (ServerSocket serverSocket = new ServerSocket(0))
                {
                    ChannelFuture future  = bootstrap.connect("localhost", serverSocket.LocalPort).sync();
                    Channel       channel = future.channel();

                    // fire multiple errors
                    channel.pipeline().fireExceptionCaught(error1);
                    channel.pipeline().fireExceptionCaught(error2);
                    channel.pipeline().fireExceptionCaught(error3);

                    // await for the channel to be closed by the HouseKeeper
                    channel.closeFuture().sync();
                }
            }
            finally
            {
                // make sure event loop group is always terminated
                bootstrap.config().group().shutdownGracefully().sync();
            }

            logProvider.AssertExactly(inLog(typeof(HouseKeeper)).error(startsWith("Fatal error occurred when handling a client connection"), equalTo(error1)));
        }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotLogExceptionsWhenEvenLoopIsShuttingDown() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotLogExceptionsWhenEvenLoopIsShuttingDown()
        {
            AssertableLogProvider logProvider = new AssertableLogProvider();
            BoltConnection        connection  = mock(typeof(BoltConnection));
            HouseKeeper           houseKeeper = new HouseKeeper(connection, logProvider.GetLog(typeof(HouseKeeper)));
            Bootstrap             bootstrap   = NewBootstrap(houseKeeper);

            try
            {
                using (ServerSocket serverSocket = new ServerSocket(0))
                {
                    ChannelFuture future  = bootstrap.connect("localhost", serverSocket.LocalPort).sync();
                    Channel       channel = future.channel();

                    // write some messages without flushing
                    for (int i = 0; i < 100; i++)
                    {
                        // use void promise which should redirect all write errors back to the pipeline and the HouseKeeper
                        channel.write(writeUtf8(channel.alloc(), "Hello"), channel.voidPromise());
                    }

                    // stop the even loop to make all pending writes fail
                    bootstrap.config().group().shutdownGracefully();
                    // await for the channel to be closed by the HouseKeeper
                    channel.closeFuture().sync();
                }
            }
            finally
            {
                // make sure event loop group is always terminated
                bootstrap.config().group().shutdownGracefully().sync();
            }

            logProvider.AssertNoLoggingOccurred();
        }
예제 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotLogConnectionResetErrors() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotLogConnectionResetErrors()
        {
            // Given
            AssertableLogProvider logProvider = new AssertableLogProvider();
            HouseKeeper           keeper      = new HouseKeeper(null, logProvider.GetLog(typeof(HouseKeeper)));
            Channel channel = mock(typeof(Channel));

            when(channel.ToString()).thenReturn("[some channel info]");
            ChannelHandlerContext ctx = mock(typeof(ChannelHandlerContext));

            when(ctx.channel()).thenReturn(channel);
            when(ctx.executor()).thenReturn(mock(typeof(EventExecutor)));
            IOException connResetError = new IOException("Connection reset by peer");

            // When
            keeper.ExceptionCaught(ctx, connResetError);

            // Then
            logProvider.AssertExactly(AssertableLogProvider.inLog(typeof(HouseKeeper)).warn("Fatal error occurred when handling a client connection, " + "remote peer unexpectedly closed connection: %s", channel));
        }
예제 #4
0
 private static Bootstrap NewBootstrap(HouseKeeper houseKeeper)
 {
     return((new Bootstrap()).group(new NioEventLoopGroup(1)).channel(typeof(NioSocketChannel)).handler(new ChannelInitializerAnonymousInnerClass(houseKeeper)));
 }