Esempio n. 1
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();
        }
Esempio n. 2
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)));
        }
Esempio n. 3
0
        public virtual void Connect(int port)
        {
            ChannelFuture channelFuture = _bootstrap.connect("localhost", port).awaitUninterruptibly();

            _channel = channelFuture.channel();
            if (!channelFuture.Success)
            {
                throw new Exception("Failed to connect", channelFuture.cause());
            }
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void start() throws Throwable
        public override void Start()
        {
            bool useEpoll = _useEpoll && Epoll.Available;
            ServerConfigurationProvider configurationProvider = useEpoll ? EpollConfigurationProvider.INSTANCE : NioConfigurationProvider.INSTANCE;

            _bossGroup = configurationProvider.CreateEventLoopGroup(1, _tf);

            // These threads handle live channels. Each thread has a set of channels it is responsible for, and it will
            // continuously run a #select() loop to react to new events on these channels.
            _selectorGroup = configurationProvider.CreateEventLoopGroup(_numSelectorThreads, _tf);

            // Bootstrap the various ports and protocols we want to handle

            foreach (KeyValuePair <BoltConnector, ProtocolInitializer> bootstrapEntry in _bootstrappersMap.SetOfKeyValuePairs())
            {
                try
                {
                    ProtocolInitializer protocolInitializer = bootstrapEntry.Value;
                    BoltConnector       boltConnector       = bootstrapEntry.Key;
                    ServerBootstrap     serverBootstrap     = CreateServerBootstrap(configurationProvider, protocolInitializer);
                    ChannelFuture       channelFuture       = serverBootstrap.bind(protocolInitializer.Address().socketAddress()).sync();
                    InetSocketAddress   localAddress        = ( InetSocketAddress )channelFuture.channel().localAddress();
                    _connectionRegister.register(boltConnector.Key(), localAddress);
                    string host = protocolInitializer.Address().Hostname;
                    int    port = localAddress.Port;
                    if (host.Contains(":"))
                    {
                        // IPv6
                        _log.info("Bolt enabled on [%s]:%s.", host, port);
                    }
                    else
                    {
                        // IPv4
                        _log.info("Bolt enabled on %s:%s.", host, port);
                    }
                }
                catch (Exception e)
                {
                    // We catch throwable here because netty uses clever tricks to have method signatures that look like they do not
                    // throw checked exceptions, but they actually do. The compiler won't let us catch them explicitly because in theory
                    // they shouldn't be possible, so we have to catch Throwable and do our own checks to grab them
                    throw new PortBindException(bootstrapEntry.Value.address(), e);
                }
            }
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("SameParameterValue") void connect(int port)
            internal virtual void Connect(int port)
            {
                ChannelFuture channelFuture = Bootstrap.connect("localhost", port).syncUninterruptibly();

                Channel = channelFuture.channel();
            }