public Task<CompletableSynchronizedStorageSession> TryAdapt(OutboxTransaction transaction, ContextBag context) { var ravenTransaction = transaction as RavenDBOutboxTransaction; if (ravenTransaction != null) { CompletableSynchronizedStorageSession session = new RavenDBSynchronizedStorageSession(ravenTransaction.AsyncSession, false); return Task.FromResult(session); } return EmptyResult; }
public void CanGetNormalSession() { var store = NewDocumentStore().Initialize(); var session = store.OpenAsyncSession(); var storageSession = new RavenDBSynchronizedStorageSession(session, true); var session2 = storageSession.RavenSession(); Assert.AreEqual(session, session2); }
public Task<CompletableSynchronizedStorageSession> TryAdapt(TransportTransaction transportTransaction, ContextBag context) { Transaction ambientTransaction; if (transportTransaction.TryGet(out ambientTransaction)) { var session = context.GetAsyncSession(); CompletableSynchronizedStorageSession completableSynchronizedStorageSession = new RavenDBSynchronizedStorageSession(session, true); return Task.FromResult(completableSynchronizedStorageSession); } return EmptyResult; }
public async Task It_should_load_successfully() { var unique = Guid.NewGuid().ToString(); CreateLegacySagaDocuments(store, unique); IAsyncDocumentSession session; var options = this.CreateContextWithAsyncSessionPresent(out session); var persister = new SagaPersister(); var synchronizedSession = new RavenDBSynchronizedStorageSession(session, true); var saga = await persister.Get<SagaWithUniqueProperty>("UniqueString", unique, synchronizedSession, options); Assert.IsNotNull(saga, "Saga is null"); await persister.Complete(saga, synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); Assert.IsNull(await persister.Get<SagaWithUniqueProperty>("UniqueString", unique, synchronizedSession, options), "Saga was not completed"); }
public async Task TestStoringSagas(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 updates 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(); Console.WriteLine($"Retrieving SagaId {saga.Id} by SagaId"); using (var session = store.OpenAsyncSession()) { var ravenDBSynchronizedStorageSession = new RavenDBSynchronizedStorageSession(session, false); var byId = await persister.Get<TestSagaData>(saga.Id, ravenDBSynchronizedStorageSession, null); Assert.IsNotNull(byId); byId.Counter++; await persister.Update(byId, ravenDBSynchronizedStorageSession, null); await session.SaveChangesAsync(); Console.WriteLine($"Retrieving SagaId {saga.Id} by Correlation Property OrderId={saga.OrderId}"); var byOrderId = await persister.Get<TestSagaData>("OrderId", saga.OrderId, ravenDBSynchronizedStorageSession, new ContextBag()); Assert.IsNotNull(byOrderId); byOrderId.Counter++; await persister.Update(byOrderId, ravenDBSynchronizedStorageSession, null); await session.SaveChangesAsync(); } } Console.WriteLine("Retrieving each saga again by SagaId and making sure Counter == 3"); foreach (var saga in sagas) { var persister = new SagaPersister(); using (var session = store.OpenAsyncSession()) { Console.WriteLine($"Retrieving SagaId {saga.Id} by SagaId"); var byId = await persister.Get<TestSagaData>(saga.Id, new RavenDBSynchronizedStorageSession(session, false), null); Assert.IsNotNull(byId); Assert.AreEqual(3, byId.Counter); } } } } }
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 static RavenDBSynchronizedStorageSession CreateSynchronizedStorageSession(this RavenDBPersistenceTestBase testBase) { var session = testBase.OpenAsyncSession(); var synchronizedSession = new RavenDBSynchronizedStorageSession(session, true); return synchronizedSession; }