public void ServiceQueue_1_Writer_1_Reader(ServiceQueueRotationAlgorithm algorithm)
        {
            using (var serviceQueue = new ServiceQueue(algorithm))
            using (var reader = new ServiceQueueReader())
            using (var writer = new ServiceQueueWriter())
            {
                var endpoint = GetEndpoint();
                serviceQueue.Bind(endpoint);

                var counterSignal = new CounterSignal(NumberOfMessages, 0);
                reader.MessageReceived += (s, m) => counterSignal.Increment();

                reader.Connect(endpoint);
                writer.Connect(endpoint);

                var messageSent = new TestMessage();

                var sw = Stopwatch.StartNew();
                for (var i = 0; i < NumberOfMessages; i++)
                {
                    writer.SendMessage(messageSent);
                }
                Assert.IsTrue(counterSignal.Wait(TimeOut), "Timeout waiting for message");
                sw.Stop();

                Assert.Inconclusive("{0} elapsed reading {1} messages ({2:N0} per second)", sw.Elapsed, NumberOfMessages, NumberOfMessages / sw.Elapsed.TotalSeconds);

            }
        }
        public void ServiceQueue_connect_Writer_send_multiple_message_received()
        {
            const int count = 1000;

            using (var serviceQueue = new ServiceQueue())
                using (var writer = new ServiceQueueWriter())
                {
                    var endpoint = new RedFoxEndpoint("/path");

                    var messageFrames = new List <MessageFrame>();
                    var counterSignal = new CounterSignal(count, 0);
                    serviceQueue.MessageFrameReceived += m =>
                    {
                        messageFrames.Add(m);
                        counterSignal.Increment();
                    };

                    serviceQueue.Bind(endpoint);
                    writer.Connect(endpoint);

                    for (var i = 0; i < count; i++)
                    {
                        writer.SendMessage(new TestMessage());
                    }

                    Assert.IsTrue(counterSignal.Wait(TimeSpan.FromSeconds(30)));
                    Assert.AreEqual(count, messageFrames.Count);
                }
        }
Beispiel #3
0
        private void ServiceQueue_1_Writer_n_Readers(ServiceQueueRotationAlgorithm algorithm, int readers)
        {
            using (var serviceQueue = new ServiceQueue(algorithm))
                using (var writer = new ServiceQueueWriter())
                {
                    var endpoint = GetEndpoint();
                    serviceQueue.Bind(endpoint);

                    var counterSignal = new CounterSignal(NumberOfMessages, 0);

                    for (var i = 0; i < readers; i++)
                    {
                        var reader = new ServiceQueueReader();
                        reader.MessageReceived += (s, m) => counterSignal.Increment();

                        reader.Connect(endpoint);
                    }

                    writer.Connect(endpoint);

                    var messageSent = new TestMessage();

                    var sw = Stopwatch.StartNew();
                    for (var i = 0; i < NumberOfMessages; i++)
                    {
                        writer.SendMessage(messageSent);
                    }
                    Assert.IsTrue(counterSignal.Wait(TimeOut), "Timeout waiting for message");
                    sw.Stop();

                    Assert.Inconclusive("{0} elapsed reading {1} messages ({2:N0} per second)", sw.Elapsed, NumberOfMessages, NumberOfMessages / sw.Elapsed.TotalSeconds);
                }
        }
        public void Connect_with_timeout_to_non_existing_endpoint_should_throw_TimeoutException()
        {
            using (var serviceQueueWriter = new ServiceQueueWriter())
            {
                var endpoint = TestHelpers.CreateEndpointForTransport(RedFoxTransport.Tcp);

                var sw = Stopwatch.StartNew();

                Assert.Throws<TimeoutException>(() =>
                    serviceQueueWriter.Connect(endpoint, TimeSpan.FromMilliseconds(100)));

                sw.Stop();
                Assert.GreaterOrEqual(sw.ElapsedMilliseconds, 100);
            }
        }
        public void Connect_with_timeout_to_non_existing_endpoint_should_throw_TimeoutException()
        {
            using (var serviceQueueWriter = new ServiceQueueWriter())
            {
                var endpoint = TestHelpers.CreateEndpointForTransport(RedFoxTransport.Tcp);

                var sw = Stopwatch.StartNew();

                Assert.Throws <TimeoutException>(() =>
                                                 serviceQueueWriter.Connect(endpoint, TimeSpan.FromMilliseconds(100)));

                sw.Stop();
                Assert.GreaterOrEqual(sw.ElapsedMilliseconds, 100);
            }
        }
        public void ServiceQueue_connect_Writer_send_single_message_MessageFramesCount_is_one()
        {
            using (var serviceQueue = new ServiceQueue())
            using (var writer = new ServiceQueueWriter())
            {
                var endpoint = new RedFoxEndpoint("/path");

                var received = new ManualResetEventSlim();
                serviceQueue.MessageFrameReceived += m => received.Set();

                serviceQueue.Bind(endpoint);
                writer.Connect(endpoint);

                Assert.AreEqual(0, serviceQueue.MessageFramesCount);
                writer.SendMessage(new TestMessage());

                Assert.IsTrue(received.Wait(TimeSpan.FromSeconds(1)));
                Assert.AreEqual(1, serviceQueue.MessageFramesCount);
            }
        }
        public void ServiceQueue_connect_Writer_send_single_message_MessageFramesCount_is_one()
        {
            using (var serviceQueue = new ServiceQueue())
                using (var writer = new ServiceQueueWriter())
                {
                    var endpoint = new RedFoxEndpoint("/path");

                    var received = new ManualResetEventSlim();
                    serviceQueue.MessageFrameReceived += m => received.Set();

                    serviceQueue.Bind(endpoint);
                    writer.Connect(endpoint);

                    Assert.AreEqual(0, serviceQueue.MessageFramesCount);
                    writer.SendMessage(new TestMessage());

                    Assert.IsTrue(received.Wait(TimeSpan.FromSeconds(1)));
                    Assert.AreEqual(1, serviceQueue.MessageFramesCount);
                }
        }
        public void ServiceQueue_connect_Writer_send_single_message_received_fires_MessageFrameReceived_event()
        {
            using (var serviceQueue = new ServiceQueue())
            using (var writer = new ServiceQueueWriter())
            {
                var endpoint = new RedFoxEndpoint("/path");

                MessageFrame messageFrame = null;
                var received = new ManualResetEventSlim();
                serviceQueue.MessageFrameReceived += m =>
                {
                    messageFrame = m;
                    received.Set();
                };

                serviceQueue.Bind(endpoint);
                writer.Connect(endpoint);

                writer.SendMessage(new TestMessage());

                Assert.IsTrue(received.Wait(TimeSpan.FromSeconds(1)));
                Assert.IsNotNull(messageFrame);
            }
        }
        public void ServiceQueue_connect_Writer_send_single_message_received_fires_MessageFrameReceived_event()
        {
            using (var serviceQueue = new ServiceQueue())
                using (var writer = new ServiceQueueWriter())
                {
                    var endpoint = new RedFoxEndpoint("/path");

                    MessageFrame messageFrame = null;
                    var          received     = new ManualResetEventSlim();
                    serviceQueue.MessageFrameReceived += m =>
                    {
                        messageFrame = m;
                        received.Set();
                    };

                    serviceQueue.Bind(endpoint);
                    writer.Connect(endpoint);

                    writer.SendMessage(new TestMessage());

                    Assert.IsTrue(received.Wait(TimeSpan.FromSeconds(1)));
                    Assert.IsNotNull(messageFrame);
                }
        }
        public void ServiceQueue_connect_Writer_send_multiple_message_received()
        {
            const int count = 1000;

            using (var serviceQueue = new ServiceQueue())
            using (var writer = new ServiceQueueWriter())
            {
                var endpoint = new RedFoxEndpoint("/path");

                var messageFrames = new List<MessageFrame>();
                var counterSignal = new CounterSignal(count, 0);
                serviceQueue.MessageFrameReceived += m =>
                {
                    messageFrames.Add(m);
                    counterSignal.Increment();
                };

                serviceQueue.Bind(endpoint);
                writer.Connect(endpoint);

                for (var i = 0; i < count; i++)
                    writer.SendMessage(new TestMessage());

                Assert.IsTrue(counterSignal.Wait(TimeSpan.FromSeconds(30)));
                Assert.AreEqual(count, messageFrames.Count);
            }
        }