Inheritance: BasicExecutor
        public void Should_pipe_remaining_operations_when_exception_thrown()
        {
            //arrange
            var handledException = false;
            var remainingJobsCalled = true;
            var remainingJobsCount = 0;
            Action<Exception> exCallback = exception => { handledException = true; };
            Action exOperation = () => { throw new Exception("Plain old exception"); };
            Executor = new TryCatchExecutor(exCallback);

            var wasCalled = 3.Of(false).ToList();
            var callbacks = new Action[wasCalled.Count];

            for (var i = 0; i < wasCalled.Count; i++)
            {
                var i1 = i;
                callbacks[i] = new Action(() => { wasCalled[i1] = true; });
            }
            callbacks[1] = exOperation;

            //act
            Executor.Execute(callbacks, actions =>
            {
                remainingJobsCalled = true;
                remainingJobsCount = actions.Count();
            });

            //assert
            Assert.IsFalse(wasCalled.All(x => x));
            Assert.IsTrue(handledException);
            Assert.IsTrue(remainingJobsCalled);
            Assert.AreEqual(1, remainingJobsCount);
        }
Exemple #2
0
        private static void Main(string[] args)
        {
            var host = IPAddress.Any;
            var port = 9991;
            Console.Title = "Server";
            Console.WriteLine("Starting server on {0}:{1}", host, port);
            var executor = new TryCatchExecutor(exception => Console.WriteLine("Unhandled exception: {0}", exception));

            var bootstrapper =
                new ServerBootstrap()
                    .WorkerThreads(2)
                    .Executor(executor)
                    .SetTransport(TransportType.Tcp)
                    .Build();
            var server = bootstrapper.NewReactor(NodeBuilder.BuildNode().Host(host).WithPort(port));
            server.OnConnection += (address, connection) =>
            {
                Console.WriteLine("Connected: {0}", address);
                connection.BeginReceive(Receive);
            };
            server.OnDisconnection += (reason, address) =>
                Console.WriteLine("Disconnected: {0}; Reason: {1}", address.RemoteHost, reason.Type);
            server.Start();
            Console.WriteLine("Running, press any key to exit");
            Console.ReadKey();
            Console.WriteLine("Shutting down...");
            server.Stop();
            Console.WriteLine("Terminated");
        }
        public void Should_report_exception_when_thrown()
        {
            //arrange
            var handledException = false;
            Action<Exception> exCallback = exception => { handledException = true; };
            Action exOperation = () => { throw new Exception("Plain old exception"); };
            Executor = new TryCatchExecutor(exCallback);

            //act
            Executor.Execute(exOperation);

            //assert
            Assert.IsTrue(handledException);
        }
        public void Should_not_report_exception_when_not_thrown()
        {
            //arrange
            var handledException = false;
            var called = false;
            Action<Exception> exCallback = exception => { handledException = true; };
            Action exOperation = () => { called = true; };
            Executor = new TryCatchExecutor(exCallback);

            //act
            Executor.Execute(exOperation);

            //assert
            Assert.IsFalse(handledException);
            Assert.IsTrue(called);
        }
Exemple #5
0
 protected HeliosTransport(ActorSystem system, Config config)
 {
     Config = config;
     System = system;
     Settings = new HeliosTransportSettings(config);
     Log = Logging.GetLogger(System, GetType());
     Executor = new TryCatchExecutor(exception => Log.Error(exception, "Unknown network error"));
 }
 public override void SetUp()
 {
     Executor = new TryCatchExecutor();
 }
 public TryCatchExecutorTests()
 {
     Executor = new TryCatchExecutor();
 }