public void CannotInsertAnotherSagaWithDuplicateCorrelationId() { // arrange var theValue = "this just happens to be the same in two sagas"; var firstSaga = new SomeSaga { Id = Guid.NewGuid(), SomeCorrelationId = theValue }; var secondSaga = new SomeSaga { Id = Guid.NewGuid(), SomeCorrelationId = theValue }; var pathsToIndex = new[] { Reflect.Path <SomeSaga>(s => s.SomeCorrelationId) }; persister.Insert(firstSaga, pathsToIndex); // act // assert Assert.Throws <OptimisticLockingException>(() => persister.Insert(secondSaga, pathsToIndex)); }
public void CanUpdateSaga() { // arrange const string theValue = "this is just some value"; var persister = CreatePersister(createTables: true); var firstSaga = new SomeSaga { Id = Guid.NewGuid(), SomeCorrelationId = theValue }; var propertyPath = Reflect.Path <SomeSaga>(s => s.SomeCorrelationId); var pathsToIndex = new[] { propertyPath }; persister.Insert(firstSaga, pathsToIndex); var sagaToUpdate = persister.Find <SomeSaga>(propertyPath, theValue); Assert.DoesNotThrow(() => persister.Update(sagaToUpdate, pathsToIndex)); }
public void RunIt(int requestCount) { const string initiatingString = "Hello!"; var messagesSent = 0; var messagesHandled = 0; using (var debugInfoTimer = new Timer(5000)) { debugInfoTimer.Elapsed += (o, ea) => Console.WriteLine("{0} messages sent - {1} messages handled", messagesSent, messagesHandled); debugInfoTimer.Start(); // arrange adapter.Register(() => { var saga = new SomeSaga(adapter.Bus, allRepliesReceived, requestCount); saga.MessageSent += () => Interlocked.Increment(ref messagesSent); saga.MessageHandled += currentHandledMessagesCount => Interlocked.Exchange(ref messagesHandled, currentHandledMessagesCount); return(saga); }); // act adapter.Bus.SendLocal(initiatingString); // assert var timeout = 5.Seconds() + (requestCount / 2).Seconds(); allRepliesReceived.WaitUntilSetOrDie(timeout, "Did not receive all replies within {0} timeout", timeout); Thread.Sleep(2.Seconds()); var sagaDataPropertyPath = Reflect.Path <SomeSagaData>(d => d.InitiatingString); var data = sagaPersister.Find <SomeSagaData>(sagaDataPropertyPath, initiatingString); Assert.That(data, Is.Not.Null, "Could not find saga data!!!"); Assert.That(data.Requests.Count, Is.EqualTo(requestCount)); Assert.That(data.Requests.All(r => r.Value == 1), "The following requests were not replied to exactly once: {0}", string.Join(", ", data.Requests.Where(kvp => kvp.Value != 1).Select(kvp => string.Format("{0} ({1})", kvp.Key, kvp.Value)))); } }