コード例 #1
0
ファイル: MessageBusTestBase.cs プロジェクト: vebin/Foundatio
        public virtual void CanSendDelayedMessage()
        {
            const int numConcurrentMessages = 10000;
            var messageBus = GetMessageBus();
            if (messageBus == null)
                return;

            using (messageBus) {
                var resetEvent = new CountDownLatch(numConcurrentMessages);

                messageBus.Subscribe<SimpleMessageA>(msg => {
                    Logger.Trace().Message("Got message").Write();
                    Assert.Equal("Hello", msg.Data);
                    resetEvent.Signal();
                    Logger.Trace().Message("Set event").Write();
                });

                var sw = new Stopwatch();
                sw.Start();

                Parallel.For(0, numConcurrentMessages, (_) => {
                    messageBus.Publish(new SimpleMessageA {
                        Data = "Hello"
                    }, TimeSpan.FromMilliseconds(RandomData.GetInt(0, 300)));
                    Logger.Trace().Message("Published one...").Write();
                });

                bool success = resetEvent.Wait(2000);
                sw.Stop();
                Logger.Trace().Message("Done waiting: " + success).Write();

                Assert.True(success, "Failed to receive message.");
                Assert.True(sw.Elapsed > TimeSpan.FromMilliseconds(80));
            }

            Thread.Sleep(50);
        }
コード例 #2
0
ファイル: RedisQueueTests.cs プロジェクト: vebin/Foundatio
        public void MeasureWorkerThroughput()
        {
            var queue = GetQueue(retries: 3, workItemTimeout: TimeSpan.FromSeconds(2), retryDelay: TimeSpan.FromSeconds(1));
            if (queue == null)
                return;

            FlushAll();

            using (queue) {
                queue.DeleteQueue();

                const int workItemCount = 1000;
                for (int i = 0; i < workItemCount; i++) {
                    queue.Enqueue(new SimpleWorkItem {
                        Data = "Hello"
                    });
                }
                Assert.Equal(workItemCount, queue.GetQueueStats().Queued);

                var countdown = new CountDownLatch(workItemCount);
                var metrics = new InMemoryMetricsClient();
                queue.StartWorking(workItem => {
                    Assert.Equal("Hello", workItem.Value.Data);
                    workItem.Complete();
                    metrics.Counter("work");
                    countdown.Signal();
                });
                countdown.Wait(60 * 1000);
                metrics.DisplayStats(_output);

                var stats = queue.GetQueueStats();
                Assert.Equal(workItemCount, stats.Dequeued);
                Assert.Equal(workItemCount, stats.Completed);
                Assert.Equal(0, stats.Queued);

                Trace.WriteLine(CountAllKeys());
            }
        }
コード例 #3
0
ファイル: MessageBusTestBase.cs プロジェクト: vebin/Foundatio
        public virtual void CanSendMessageToMultipleSubscribers()
        {
            var messageBus = GetMessageBus();
            if (messageBus == null)
                return;

            using (messageBus) {
                var latch = new CountDownLatch(3);
                messageBus.Subscribe<SimpleMessageA>(msg => {
                    Assert.Equal("Hello", msg.Data);
                    latch.Signal();
                });
                messageBus.Subscribe<SimpleMessageA>(msg => {
                    Assert.Equal("Hello", msg.Data);
                    latch.Signal();
                });
                messageBus.Subscribe<SimpleMessageA>(msg => {
                    Assert.Equal("Hello", msg.Data);
                    latch.Signal();
                });
                messageBus.Publish(new SimpleMessageA {
                    Data = "Hello"
                });

                bool success = latch.Wait(2000);
                Assert.True(success, "Failed to receive all messages.");
            }

            Thread.Sleep(50);
        }
コード例 #4
0
ファイル: MessageBusTestBase.cs プロジェクト: vebin/Foundatio
        public virtual void WillReceiveDerivedMessageTypes()
        {
            var messageBus = GetMessageBus();
            if (messageBus == null)
                return;

            using (messageBus) {
                var latch = new CountDownLatch(2);
                messageBus.Subscribe<ISimpleMessage>(msg => {
                    Assert.Equal("Hello", msg.Data);
                    latch.Signal();
                });
                messageBus.Publish(new SimpleMessageA {
                    Data = "Hello"
                });
                messageBus.Publish(new SimpleMessageB {
                    Data = "Hello"
                });
                messageBus.Publish(new SimpleMessageC {
                    Data = "Hello"
                });

                bool success = latch.Wait(5000);
                Assert.True(success, "Failed to receive all messages.");
            }

            Thread.Sleep(50);
        }
コード例 #5
0
ファイル: MessageBusTestBase.cs プロジェクト: vebin/Foundatio
        public virtual void CanTolerateSubscriberFailure()
        {
            var messageBus = GetMessageBus();
            if (messageBus == null)
                return;

            using (messageBus) {
                var latch = new CountDownLatch(2);
                messageBus.Subscribe<SimpleMessageA>(msg => {
                    throw new ApplicationException();
                });
                messageBus.Subscribe<SimpleMessageA>(msg => {
                    Assert.Equal("Hello", msg.Data);
                    latch.Signal();
                });
                messageBus.Subscribe<SimpleMessageA>(msg => {
                    Assert.Equal("Hello", msg.Data);
                    latch.Signal();
                });
                messageBus.Publish(new SimpleMessageA {
                    Data = "Hello"
                });

                bool success = latch.Wait(2000);
                Assert.True(success, "Failed to receive all messages.");
            }

            Thread.Sleep(50);
        }
コード例 #6
0
ファイル: MessageBusTestBase.cs プロジェクト: vebin/Foundatio
        public virtual void CanSubscribeToAllMessageTypes()
        {
            var messageBus = GetMessageBus();
            if (messageBus == null)
                return;

            using (messageBus) {
                var latch = new CountDownLatch(3);
                messageBus.Subscribe<object>(msg => {
                    latch.Signal();
                });
                messageBus.Publish(new SimpleMessageA {
                    Data = "Hello"
                });
                messageBus.Publish(new SimpleMessageB {
                    Data = "Hello"
                });
                messageBus.Publish(new SimpleMessageC {
                    Data = "Hello"
                });

                bool success = latch.Wait(2000);
                Assert.True(success, "Failed to receive all messages.");
            }

            Thread.Sleep(50);
        }