Exemplo n.º 1
0
        public void Should_process_the_messages_in_order_and_not_at_the_same_time()
        {
            UnsubscribeAction unsubscribeAction = LocalBus.SubscribeSaga(_sagaRepository);

            Guid transactionId = NewId.NextGuid();

            Trace.WriteLine("Creating transaction for " + transactionId);

            int startValue = 1;

            var startConcurrentSaga = new StartConcurrentSaga
            {
                CorrelationId = transactionId, Name = "Chris", Value = startValue
            };

            LocalBus.Publish(startConcurrentSaga);

            var saga = _sagaRepository.ShouldContainSaga(transactionId, 8.Seconds());

            Assert.IsNotNull(saga);

            int nextValue = 2;
            var continueConcurrentSaga = new ContinueConcurrentSaga {
                CorrelationId = transactionId, Value = nextValue
            };

            LocalBus.Publish(continueConcurrentSaga);

            saga = _sagaRepository.ShouldContainSaga(x => x.CorrelationId == transactionId && x.Value == nextValue, 8.Seconds());
            Assert.IsNotNull(saga);

            unsubscribeAction();

            Assert.AreEqual(nextValue, saga.Value);
        }
Exemplo n.º 2
0
        public virtual void Consume(ContinueConcurrentSaga message)
        {
            Trace.WriteLine("Consuming " + message.GetType());
            Thread.Sleep(1000);

            if (Value == -1)
            {
                throw new InvalidOperationException("Should not be a -1 dude!!");
            }

            Value = message.Value;
            Trace.WriteLine("Completed " + message.GetType());
        }
Exemplo n.º 3
0
        public void Should_process_the_messages_in_order_and_not_at_the_same_time()
        {
            Guid transactionId = NewId.NextGuid();

            _log.Info("Creating transaction for " + transactionId);

            const int startValue = 1;

            var startConcurrentSaga = new StartConcurrentSaga
            {
                CorrelationId = transactionId, Name = "Chris", Value = startValue
            };

            LocalBus.Endpoint.Send(startConcurrentSaga);
            LocalBus.Endpoint.Send(startConcurrentSaga);

            _log.Info("Just published the start message");

            UnsubscribeAction unsubscribeAction = LocalBus.SubscribeSaga(_sagaRepository);

            Thread.Sleep(1500);

            const int nextValue = 2;
            var       continueConcurrentSaga = new ContinueConcurrentSaga {
                CorrelationId = transactionId, Value = nextValue
            };

            LocalBus.Publish(continueConcurrentSaga);
            _log.Info("Just published the continue message");
            Thread.Sleep(8000);

            unsubscribeAction();
            foreach (ConcurrentLegacySaga saga in _sagaRepository.Where(x => true))
            {
                _log.Info("Found saga: " + saga.CorrelationId);
            }

            int currentValue = _sagaRepository.Where(x => x.CorrelationId == transactionId).First().Value;

            Assert.AreEqual(nextValue, currentValue);
        }
Exemplo n.º 4
0
        public void Should_process_the_messages_in_order_and_not_at_the_same_time()
        {
            UnsubscribeAction unsubscribeAction = LocalBus.SubscribeSaga(_sagaRepository);

            Guid transactionId = CombGuid.Generate();

            Trace.WriteLine("Creating transaction for " + transactionId);

            int startValue = 1;

            var startConcurrentSaga = new StartConcurrentSaga {
                CorrelationId = transactionId, Name = "Chris", Value = startValue
            };

            LocalBus.Publish(startConcurrentSaga);
            Trace.WriteLine("Just published the start message");

            Thread.Sleep(1500);

            int nextValue = 2;
            var continueConcurrentSaga = new ContinueConcurrentSaga {
                CorrelationId = transactionId, Value = nextValue
            };

            LocalBus.Publish(continueConcurrentSaga);
            Trace.WriteLine("Just published the continue message");
            Thread.Sleep(8000);

            unsubscribeAction();
            foreach (ConcurrentSaga saga in _sagaRepository.Where(x => true))
            {
                Trace.WriteLine("Found saga: " + saga.CorrelationId);
            }

            int currentValue = _sagaRepository.Where(x => x.CorrelationId == transactionId).First().Value;

            Assert.AreEqual(nextValue, currentValue);
        }