Example #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");
        }
Example #3
0
 protected EventQueue(IEventQueueStorageStrategy <TEvent> storageStrategy) => this.storageStrategy = storageStrategy;
Example #4
0
 /// <summary>
 /// Instantiates a new TestConsumer which should interact with the given strategy.
 /// </summary>
 /// <param name="strategy">The strategy to interact with while consuming.</param>
 public TestConsumer(IEventQueueStorageStrategy <TestEvent> strategy)
 {
     this.strategy = strategy;
 }
Example #5
0
 public EventQueueImp(IEventQueueStorageStrategy <TestEvent> storageStrategy) : base(storageStrategy)
 {
 }
Example #6
0
 public SupportDeserializationEventQueueImp(IEventQueueStorageStrategy <TestEvent> storageStrategy) : base(storageStrategy)
 {
 }
Example #7
0
 protected SupportDeserializationEventQueue(IEventQueueStorageStrategy <T> storageStrategy) : base(storageStrategy)
 {
 }
Example #8
0
 /// <summary>
 /// Instantiates a new TestProducer for the given EventQueueStorageStrategy.
 /// </summary>
 /// <param name="strategy">The strategy to be interacted with by this producer.</param>
 public TestProducer(IEventQueueStorageStrategy <TestEvent> strategy)
 {
     this.strategy = strategy;
 }