public async Task TestMarkingAsComplete(ConventionType seedType) { using (var db = new ReusableDB()) { List <TestSagaData> sagas; using (var store = db.NewStore()) { ApplyPrefillConventions(store, seedType); store.Initialize(); sagas = await Prefill(store, seedType); } using (var store = db.NewStore()) { Console.WriteLine($"Testing saga lookups with DocumentStore initially configured for {seedType} conventions."); ApplyTestConventions(store, seedType); store.Initialize(); // Update each saga, once by id and once by correlation property foreach (var saga in sagas) { var persister = new SagaPersister(); using (var session = store.OpenAsyncSession()) { Console.WriteLine($"Retrieving SagaId {saga.Id} by Correlation Property OrderId={saga.OrderId} and completing."); var ravenDBSynchronizedStorageSession = new RavenDBSynchronizedStorageSession(session, false); var contextBag = new ContextBag(); var byOrderId = await persister.Get <TestSagaData>("OrderId", saga.OrderId, ravenDBSynchronizedStorageSession, contextBag); Assert.IsNotNull(byOrderId); await persister.Complete(byOrderId, ravenDBSynchronizedStorageSession, contextBag); await session.SaveChangesAsync(); } } db.WaitForIndexing(store); // Ensure terms are still the saga type and unique identity type var terms = store.DatabaseCommands.GetTerms("Raven/DocumentsByEntityName", "Tag", null, 1024).ToList(); Assert.AreEqual(2, terms.Count); foreach (var term in terms) { var query = new IndexQuery { Query = "Tag:" + term, PageSize = 0 }; // Ensure there are none left var queryResult = store.DatabaseCommands.Query("Raven/DocumentsByEntityName", query); Assert.AreEqual(0, queryResult.TotalResults); } } } }
public async Task TestReceivingTimeouts(ConventionType seedType) { using (var db = new ReusableDB()) { string prefillIndex; using (var store = db.NewStore()) { ApplyPrefillConventions(store, seedType); store.Initialize(); await Prefill(store, seedType); prefillIndex = CreateTimeoutIndex(store); } // Need to ensure multiple runs will work, after conventions document is stored for (var i = 0; i < 3; i++) { using (var store = db.NewStore()) { Console.WriteLine($"Testing receives with DocumentStore initially configured for {seedType} conventions."); ApplyTestConventions(store, seedType); store.Initialize(); var index = CreateTimeoutIndex(store); db.WaitForIndexing(store); Assert.AreEqual(index, prefillIndex, "Index definitions must match or previous timeouts will not be found."); var query = new QueryTimeouts(store, EndpointName); var chunkTuples = (await query.GetNextChunk(DateTime.UtcNow.AddYears(-10))).DueTimeouts.ToArray(); Assert.AreEqual(10, chunkTuples.Length); foreach (var tuple in chunkTuples) { Console.WriteLine($"Received timeout {tuple.Id}"); Assert.AreEqual(dueTimeout, tuple.DueTime); } } } } }
public async Task TestMarkingAsComplete(ConventionType seedType) { using (var db = new ReusableDB()) { List<TestSagaData> sagas; using (var store = db.NewStore()) { ApplyPrefillConventions(store, seedType); store.Initialize(); sagas = await Prefill(store, seedType); } using (var store = db.NewStore()) { Console.WriteLine($"Testing saga lookups with DocumentStore initially configured for {seedType} conventions."); ApplyTestConventions(store, seedType); store.Initialize(); // Update each saga, once by id and once by correlation property foreach (var saga in sagas) { var persister = new SagaPersister(); using (var session = store.OpenAsyncSession()) { Console.WriteLine($"Retrieving SagaId {saga.Id} by Correlation Property OrderId={saga.OrderId} and completing."); var ravenDBSynchronizedStorageSession = new RavenDBSynchronizedStorageSession(session, false); var contextBag = new ContextBag(); var byOrderId = await persister.Get<TestSagaData>("OrderId", saga.OrderId, ravenDBSynchronizedStorageSession, contextBag); Assert.IsNotNull(byOrderId); await persister.Complete(byOrderId, ravenDBSynchronizedStorageSession, contextBag); await session.SaveChangesAsync(); } } db.WaitForIndexing(store); // Ensure terms are still the saga type and unique identity type var terms = store.DatabaseCommands.GetTerms("Raven/DocumentsByEntityName", "Tag", null, 1024).ToList(); Assert.AreEqual(2, terms.Count); foreach (var term in terms) { var query = new IndexQuery { Query = "Tag:" + term, PageSize = 0 }; // Ensure there are none left var queryResult = store.DatabaseCommands.Query("Raven/DocumentsByEntityName", query); Assert.AreEqual(0, queryResult.TotalResults); } } } }
public async Task EnsureOldAndNewTimeoutsCanBeReceived(ConventionType seedType) { using (var db = new ReusableDB()) { using (var store = db.NewStore()) { ApplyPrefillConventions(store, seedType); store.Initialize(); await Prefill(store, seedType); } using (var store = db.NewStore()) { ApplyTestConventions(store, seedType); store.Initialize(); CreateTimeoutIndex(store); var persister = new TimeoutPersister(store); for (var i = 1; i <= 10; i++) { await persister.Add(new TimeoutData { Destination = EndpointName, Headers = new Dictionary<string, string>(), OwningTimeoutManager = EndpointName, SagaId = Guid.NewGuid(), Time = dueTimeout }, new ContextBag()); } db.WaitForIndexing(store); var query = new QueryTimeouts(store, EndpointName); var chunkTuples = (await query.GetNextChunk(DateTime.UtcNow.AddYears(-10))).DueTimeouts.ToArray(); Assert.AreEqual(20, chunkTuples.Length); foreach (var tuple in chunkTuples) { Console.WriteLine($"Received timeout {tuple.Id}"); Assert.AreEqual(dueTimeout, tuple.DueTime); } } } }