Example #1
0
        public async Task Should_not_be_in_final_state()
        {
            Guid correlationId = Guid.NewGuid();

            await InputQueueSendEndpoint.Send(new RehersalBegins { CorrelationId = correlationId });

            var saga = await GetSagaRetry(correlationId, TestTimeout);

            Assert.IsNotNull(saga);

            await Task.WhenAll(
                InputQueueSendEndpoint.Send(new Bass {
                CorrelationId = correlationId, Name = "John"
            }),
                InputQueueSendEndpoint.Send(new Baritone {
                CorrelationId = correlationId, Name = "Mark"
            }),
                InputQueueSendEndpoint.Send(new Tenor {
                CorrelationId = correlationId, Name = "Anthony"
            }),
                InputQueueSendEndpoint.Send(new Countertenor {
                CorrelationId = correlationId, Name = "Tom"
            })
                );

            // Because concurrency exception's happened without retry middleware configured, we aren't in our final state/
            ChoirStateOptimistic instance = await GetSaga(correlationId);

            Assert.IsTrue(!instance.CurrentState.Equals("Harmony"));
        }
Example #2
0
        public async Task Should_capture_all_events_single_saga()
        {
            Guid correlationId = Guid.NewGuid();

            await InputQueueSendEndpoint.Send(new RehersalBegins { CorrelationId = correlationId });

            var saga = await GetSagaRetry(correlationId, TestTimeout);

            Assert.IsNotNull(saga);

            await Task.WhenAll(
                InputQueueSendEndpoint.Send(new Bass {
                CorrelationId = correlationId, Name = "John"
            }),
                InputQueueSendEndpoint.Send(new Baritone {
                CorrelationId = correlationId, Name = "Mark"
            }),
                InputQueueSendEndpoint.Send(new Tenor {
                CorrelationId = correlationId, Name = "Anthony"
            }),
                InputQueueSendEndpoint.Send(new Countertenor {
                CorrelationId = correlationId, Name = "Tom"
            })
                );

            saga = await GetSagaRetry(correlationId, TestTimeout, x => x.CurrentState == _machine.Harmony.Name);

            Assert.IsNotNull(saga);
            Assert.IsTrue(saga.CurrentState == _machine.Harmony.Name);

            ChoirStateOptimistic instance = await GetSaga(correlationId);

            Assert.IsTrue(instance.CurrentState.Equals("Harmony"));
        }
Example #3
0
        public async Task Some_should_not_be_in_final_state_all()
        {
            var tasks = new List <Task>();

            Guid[] sagaIds = new Guid[20];
            for (int i = 0; i < 20; i++)
            {
                Guid correlationId = NewId.NextGuid();

                await InputQueueSendEndpoint.Send(new RehersalBegins { CorrelationId = correlationId });

                sagaIds[i] = correlationId;
            }

            for (int i = 0; i < 20; i++)
            {
                var saga = await GetSagaRetry(sagaIds[i], TestTimeout);

                Assert.IsNotNull(saga);
            }

            for (int i = 0; i < 20; i++)
            {
                tasks.Add(InputQueueSendEndpoint.Send(new Bass {
                    CorrelationId = sagaIds[i], Name = "John"
                }));
                tasks.Add(InputQueueSendEndpoint.Send(new Baritone {
                    CorrelationId = sagaIds[i], Name = "Mark"
                }));
                tasks.Add(InputQueueSendEndpoint.Send(new Tenor {
                    CorrelationId = sagaIds[i], Name = "Anthony"
                }));
                tasks.Add(InputQueueSendEndpoint.Send(new Countertenor {
                    CorrelationId = sagaIds[i], Name = "Tom"
                }));
            }

            await Task.WhenAll(tasks);

            await Task.Delay(2000);

            tasks.Clear();

            var someNotInFinalState = false;

            foreach (var sid in sagaIds)
            {
                ChoirStateOptimistic instance = await GetSaga(sid);

                someNotInFinalState = !instance.CurrentState.Equals("Harmony");
                if (someNotInFinalState)
                {
                    break;
                }
            }

            Assert.IsTrue(someNotInFinalState);
        }
Example #4
0
        public async Task Should_capture_all_events_many_sagas()
        {
            var tasks = new List <Task>();

            Guid[] sagaIds = new Guid[20];
            for (int i = 0; i < 20; i++)
            {
                Guid correlationId = NewId.NextGuid();

                await InputQueueSendEndpoint.Send(new RehersalBegins { CorrelationId = correlationId });

                sagaIds[i] = correlationId;
            }

            for (int i = 0; i < 20; i++)
            {
                var saga = await GetSagaRetry(sagaIds[i], TestTimeout);

                Assert.IsNotNull(saga);
            }

            for (int i = 0; i < 20; i++)
            {
                tasks.Add(InputQueueSendEndpoint.Send(new Bass {
                    CorrelationId = sagaIds[i], Name = "John"
                }));
                tasks.Add(InputQueueSendEndpoint.Send(new Baritone {
                    CorrelationId = sagaIds[i], Name = "Mark"
                }));
                tasks.Add(InputQueueSendEndpoint.Send(new Tenor {
                    CorrelationId = sagaIds[i], Name = "Anthony"
                }));
                tasks.Add(InputQueueSendEndpoint.Send(new Countertenor {
                    CorrelationId = sagaIds[i], Name = "Tom"
                }));
            }

            await Task.WhenAll(tasks);

            await Task.Delay(100000);

            tasks.Clear();


            foreach (var sid in sagaIds)
            {
                ChoirStateOptimistic instance = await GetSagaRetry(sid, TestTimeout, x => x.CurrentState == _machine.Harmony.Name);

                Assert.IsNotNull(instance);
                Assert.IsTrue(instance.CurrentState.Equals("Harmony"));
            }
        }