Ejemplo n.º 1
0
        public void ShouldWaitForBuffer()
        {
            var receiveCalled = false;
            var receiveWaiter = new ManualResetEvent(false);
            var worker        = new TestWorkScheduler();

            worker.QueueForeverAction = (action, span) =>
            {
                Task.Factory.StartNew(() =>
                {
                    while (true)
                    {
                        action();
                    }
                });
            };
            var bufferAllocator = new TestBufferAllocator();
            var connection      = new TestConnection();
            var io = new ConnectionIoActor(worker, bufferAllocator);

            bufferAllocator.AllocateFunc = i => null;
            connection.ReceiveAction     = (buffer, callback) => {
                receiveCalled = true;
                receiveWaiter.Set();
            };
            io.Receive(128, connection, new BandwidthController(), null, null);
            bufferAllocator.AllocateFunc = i => new Buffer(new byte[128]);
            receiveWaiter.WaitOne(100);

            Assert.IsTrue(receiveCalled, "Receive was not called.");
        }
Ejemplo n.º 2
0
        public void ShouldFailBecauseTimeout()
        {
            var connected = false;
            var timeout   = false;

            var connectWaiter = new ManualResetEvent(false);
            var worker        = new TestWorkScheduler {
                QueueOneTimeAction = (action, interval) => {
                    Thread.Sleep(50);
                    action();
                    timeout = true;
                }
            };

            var io       = new ConnectionIoActor(worker, _dummyBufferAllocator);
            var endpoint = new IPEndPoint(IPAddress.Parse("217.87.23.53"), 9999);
            Action <IConnection, bool> callback = (connection, success) =>
            {
                connected = success;
                connectWaiter.Set();
            };

            io.Connect(new Connection(endpoint), c => callback(c, true), c => callback(c, false));
            connectWaiter.WaitOne();
            Assert.IsFalse(connected);
            Assert.IsTrue(timeout);
        }
        public void ShouldFailBecauseTimeout()
        {
            var connected = false;
            var timeout = false;

            var connectWaiter = new ManualResetEvent(false);
            var worker = new TestWorkScheduler{
                QueueOneTimeAction = (action, interval) =>{
                    Thread.Sleep(50);
                    action();
                    timeout = true;
                }
            };

            var io = new ConnectionIoActor(worker, _dummyBufferAllocator);
            var endpoint = new IPEndPoint(IPAddress.Parse("217.87.23.53"), 9999);
            Action<IConnection, bool> callback = (connection, success) =>
            {
                connected = success;
                connectWaiter.Set();
            };

            io.Connect(new Connection(endpoint), c => callback(c, true), c => callback(c, false));
            connectWaiter.WaitOne();
            Assert.IsFalse(connected);
            Assert.IsTrue(timeout);
        }
Ejemplo n.º 4
0
        public void ShouldInvokeFailureCallback()
        {
            var connected     = false;
            var connectWaiter = new ManualResetEvent(false);
            var worker        = new TestWorkScheduler();
            var io            = new ConnectionIoActor(worker, _dummyBufferAllocator);
            var endpoint      = new IPEndPoint(IPAddress.Loopback, 9999);
            Action <IConnection, bool> callback = (connection, success) => {
                connected = success;
                connectWaiter.Set();
            };

            io.Connect(new Connection(endpoint), c => callback(c, true), c => callback(c, false));
            connectWaiter.WaitOne();
            Assert.IsFalse(connected);
        }
        public void ShouldWaitForBuffer()
        {
            var receiveCalled = false;
            var receiveWaiter = new ManualResetEvent(false);
            var worker = new TestWorkScheduler();
            worker.QueueForeverAction = (action, span) =>
            {
                Task.Factory.StartNew(() =>
                {
                    while (true) action();
                });
            };
            var bufferAllocator = new TestBufferAllocator();
            var connection = new TestConnection();
            var io = new ConnectionIoActor(worker, bufferAllocator);

            bufferAllocator.AllocateFunc= i => null;
            connection.ReceiveAction = (buffer, callback) => {
                receiveCalled = true;
                receiveWaiter.Set();
            };
            io.Receive(128, connection, new BandwidthController(), null, null );
            bufferAllocator.AllocateFunc = i => new Buffer(new byte[128]);
            receiveWaiter.WaitOne(100);

            Assert.IsTrue(receiveCalled, "Receive was not called.");
        }
 public void ShouldInvokeFailureCallback()
 {
     var connected = false;
     var connectWaiter = new ManualResetEvent(false);
     var worker = new TestWorkScheduler();
     var io = new ConnectionIoActor(worker, _dummyBufferAllocator);
     var endpoint = new IPEndPoint(IPAddress.Loopback, 9999);
     Action<IConnection, bool> callback = (connection, success) =>{
         connected = success;
         connectWaiter.Set();
     };
     io.Connect(new Connection(endpoint), c => callback(c, true), c => callback(c, false));
     connectWaiter.WaitOne();
     Assert.IsFalse(connected);
 }