Ejemplo n.º 1
0
        public async Task TestEnqueueDequeueEvents()
        {
            int numMessages = 10000;
            var logger      = new TestOutputLogger(this.TestOutput, false);

            using var queue = new TestEventQueue(logger, (notification, evt, _) => { });

            var enqueueTask = Task.Run(() =>
            {
                for (int i = 0; i < numMessages; i++)
                {
                    queue.Enqueue(new E1(), null, null);
                }
            });

            var dequeueTask = Task.Run(() =>
            {
                for (int i = 0; i < numMessages; i++)
                {
                    var(deqeueStatus, e, g, info) = queue.Dequeue();
                    if (deqeueStatus is DequeueStatus.Success)
                    {
                        Assert.IsType <E1>(e);
                    }
                }
            });

            await Task.WhenAny(Task.WhenAll(enqueueTask, dequeueTask), Task.Delay(3000));

            Assert.True(enqueueTask.IsCompleted);
            Assert.True(dequeueTask.IsCompleted);
        }
Ejemplo n.º 2
0
        public void TestEnqueueEventWithHandlerNotRunning()
        {
            var logger = new TestOutputLogger(this.TestOutput, false);

            using var queue = new TestEventQueue(logger, (notification, evt, _) => { });
            var(deqeueStatus, e, group, info) = queue.Dequeue();
            Assert.Equal(DequeueStatus.Unavailable, deqeueStatus);
            Assert.Equal(0, queue.Size);

            var enqueueStatus = queue.Enqueue(new E1(), null, null);

            Assert.Equal(EnqueueStatus.EventHandlerNotRunning, enqueueStatus);
            Assert.Equal(1, queue.Size);
        }
Ejemplo n.º 3
0
        public void TestRaiseEvent()
        {
            var logger = new TestOutputLogger(this.TestOutput, false);

            using var queue = new TestEventQueue(logger, (notification, evt, _) => { });
            queue.RaiseEvent(new E1(), null);
            Assert.True(queue.IsEventRaised);
            Assert.Equal(0, queue.Size);

            var(deqeueStatus, e, group, info) = queue.Dequeue();
            Assert.IsType <E1>(e);
            Assert.Equal(DequeueStatus.Raised, deqeueStatus);
            Assert.False(queue.IsEventRaised);
            Assert.Equal(0, queue.Size);
        }
Ejemplo n.º 4
0
        public void TestDequeueEvent()
        {
            var logger = new TestOutputLogger(this.TestOutput, false);

            using var queue = new TestEventQueue(logger, (notification, evt, _) => { });
            var(deqeueStatus, e, group, info) = queue.Dequeue();
            Assert.Equal(DequeueStatus.Unavailable, deqeueStatus);
            Assert.Equal(0, queue.Size);

            queue.Enqueue(new E1(), null, null);
            (deqeueStatus, e, group, info) = queue.Dequeue();
            Assert.IsType <E1>(e);
            Assert.Equal(DequeueStatus.Success, deqeueStatus);
            Assert.Equal(0, queue.Size);

            queue.Enqueue(new E3(), null, null);
            queue.Enqueue(new E2(), null, null);
            queue.Enqueue(new E1(), null, null);

            (deqeueStatus, e, group, info) = queue.Dequeue();
            Assert.IsType <E3>(e);
            Assert.Equal(DequeueStatus.Success, deqeueStatus);
            Assert.Equal(2, queue.Size);

            (deqeueStatus, e, group, info) = queue.Dequeue();
            Assert.IsType <E2>(e);
            Assert.Equal(DequeueStatus.Success, deqeueStatus);
            Assert.Equal(1, queue.Size);

            (deqeueStatus, e, group, info) = queue.Dequeue();
            Assert.IsType <E1>(e);
            Assert.Equal(DequeueStatus.Success, deqeueStatus);
            Assert.Equal(0, queue.Size);

            (deqeueStatus, e, group, info) = queue.Dequeue();
            Assert.Equal(DequeueStatus.Unavailable, deqeueStatus);
            Assert.Equal(0, queue.Size);
        }