Ejemplo n.º 1
0
        public static void Assert_EnqueueSingleProducerBounded(IEventQueueStorageStrategy <TestEvent> strategy, int maxEventCount)
        {
            /* PRECONDITION */
            Debug.Assert(strategy != null);
            Debug.Assert(maxEventCount >= 0);
            Debug.Assert(strategy.IsClosed);

            /* GIVEN */
            var expectedEventCount = (maxEventCount < maxEvents) ? maxEventCount : maxEvents;
            var producer           = new TestProducer(strategy);
            var consumer           = new TestConsumer(strategy);

            using var produceEvent = new ManualResetEvent(false);
            using var consumeEvent = new ManualResetEvent(false);

            /* WHEN */
            strategy.Open();
            Assert.IsTrue(!strategy.IsClosed);

            consumer.Consume((@event, num) => num < expectedEventCount, result => result.EventSuccess(consumeEvent));
            producer.Produce(num => num < maxEvents, result => result.EventSuccess(produceEvent));

            /* THEN */
            Assert.IsTrue(produceEvent.WaitOne(maxWaitTime), "Producer did not complete successfully");
            Assert.IsTrue(consumeEvent.WaitOne(maxWaitTime), "Consumer did not complete successfully");
        }
        public static void Assert_EnqueueSingleProducerUnbounded(IEventQueueStorageStrategy <TestEvent> strategy)
        {
            /* PRECONDITION */
            Debug.Assert(strategy != null);
            Debug.Assert(strategy.IsClosed);

            /* GIVEN */
            strategy.Open();
            var producer = new TestProducer(strategy);
            var consumer = new TestConsumer(strategy);

            using var produceEvent = new ManualResetEvent(false);
            using var consumeEvent = new ManualResetEvent(false);

            /* WHEN */
            consumer.Consume((@event, num) => num < maxEvents, result => result.EventSuccess(consumeEvent));
            producer.Produce(num => num < maxEvents, result => result.EventSuccess(produceEvent));

            /* THEN */
            Assert.IsTrue(produceEvent.WaitOne(maxWaitTime), "Producer did not finish in time");
            Assert.IsTrue(consumeEvent.WaitOne(maxWaitTime), "Consumer did not receive events in time");
        }