public void It_should_persist_successfully()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            var factory = new RavenSessionFactory(store);
            factory.ReleaseSession();
            var persister           = new SagaPersister(factory);
            var uniqueString        = Guid.NewGuid().ToString();
            var anotherUniqueString = Guid.NewGuid().ToString();

            var saga1 = new SagaData
            {
                Id              = Guid.NewGuid(),
                UniqueString    = uniqueString,
                NonUniqueString = "notUnique"
            };
            persister.Save(saga1);
            factory.SaveChanges();

            var saga = persister.Get <SagaData>(saga1.Id);
            saga.NonUniqueString = "notUnique2";
            saga.UniqueString    = anotherUniqueString;
            persister.Update(saga);
            factory.SaveChanges();
        }
    }
    public void It_should_enforce_uniqueness()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            var factory = new RavenSessionFactory(store);
            factory.ReleaseSession();
            var persister    = new SagaPersister(factory);
            var uniqueString = Guid.NewGuid().ToString();

            var saga1 = new SagaData
            {
                Id           = Guid.NewGuid(),
                UniqueString = uniqueString
            };

            persister.Save(saga1);
            factory.SaveChanges();
            factory.ReleaseSession();

            Assert.Throws <ConcurrencyException>(() =>
            {
                var saga2 = new SagaData
                {
                    Id           = Guid.NewGuid(),
                    UniqueString = uniqueString
                };
                persister.Save(saga2);
                factory.SaveChanges();
            });
        }
    }
    public void It_should_persist_successfully()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            var factory = new RavenSessionFactory(store);
            factory.ReleaseSession();
            var persister    = new SagaPersister(factory);
            var uniqueString = Guid.NewGuid().ToString();
            var saga1        = new SagaData
            {
                Id           = Guid.NewGuid(),
                UniqueString = uniqueString
            };
            persister.Save(saga1);
            factory.SaveChanges();
            factory.ReleaseSession();

            var saga = persister.Get <SagaData>(saga1.Id);
            persister.Complete(saga);
            factory.SaveChanges();
            factory.ReleaseSession();

            var saga2 = new SagaData
            {
                Id           = Guid.NewGuid(),
                UniqueString = uniqueString
            };

            persister.Save(saga2);
            factory.SaveChanges();
        }
    }
    public void It_should_allow_the_update()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            var factory = new RavenSessionFactory(store);
            factory.ReleaseSession();
            var persister    = new SagaPersister(factory);
            var uniqueString = Guid.NewGuid().ToString();
            var saga1        = new SagaData
            {
                Id           = Guid.NewGuid(),
                UniqueString = uniqueString
            };

            persister.Save(saga1);
            factory.SaveChanges();
            factory.ReleaseSession();

            var saga = persister.Get <SagaData>(saga1.Id);
            saga.UniqueString = Guid.NewGuid().ToString();
            persister.Update(saga);
            factory.SaveChanges();
            factory.ReleaseSession();

            var saga2 = new SagaData
            {
                Id           = Guid.NewGuid(),
                UniqueString = uniqueString
            };

            //this should not blow since we changed the unique value in the previous saga
            persister.Save(saga2);
            factory.SaveChanges();
        }
    }
        public void Should_delete_all_OutboxRecords_that_have_been_dispatched()
        {
            var id = Guid.NewGuid().ToString("N");

            var sessionFactory = new RavenSessionFactory(store);

            var persister = new OutboxPersister(sessionFactory) { DocumentStore = store, EndpointName = "TestEndpoint" };
            persister.Store("NotDispatched", Enumerable.Empty<TransportOperation>());
            persister.Store(id, new List<TransportOperation>
            {
                new TransportOperation(id, new Dictionary<string, string>(), new byte[1024*5], new Dictionary<string, string>()),
            });

            sessionFactory.SaveChanges();
            sessionFactory.ReleaseSession();

            persister.SetAsDispatched(id);
            Thread.Sleep(TimeSpan.FromSeconds(1)); //Need to wait for dispatch logic to finish

            WaitForIndexing(store);

            var cleaner = new OutboxRecordsCleaner { DocumentStore = store };
            cleaner.RemoveEntriesOlderThan(DateTime.UtcNow.AddMinutes(1));

            using (var session = store.OpenSession())
            {
                var result = session.Query<OutboxRecord>().ToList();

                Assert.AreEqual(1, result.Count);
                Assert.AreEqual("NotDispatched", result[0].MessageId);
            }
        }
Example #6
0
 public void WithASagaPersistenceUnitOfWork(Action <RavenSagaPersister> action)
 {
     using (var sessionFactory = new RavenSessionFactory(store))
     {
         var sagaPersister = new RavenSagaPersister(sessionFactory);
         action(sagaPersister);
         sessionFactory.SaveChanges();
     }
 }
Example #7
0
    public void It_should_set_the_attribute_and_allow_the_update()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            var factory = new RavenSessionFactory(store);
            factory.ReleaseSession();
            var persister    = new SagaPersister(factory);
            var uniqueString = Guid.NewGuid().ToString();

            var anotherUniqueString = Guid.NewGuid().ToString();

            var saga1 = new SagaData
            {
                Id              = Guid.NewGuid(),
                UniqueString    = uniqueString,
                NonUniqueString = "notUnique"
            };

            persister.Save(saga1);
            factory.SaveChanges();
            factory.ReleaseSession();

            using (var session = store.OpenSession())
            {
                //fake that the attribute was just added by removing the metadata
                session.Advanced.GetMetadataFor(saga1).Remove(SagaPersister.UniqueValueMetadataKey);
                session.SaveChanges();
            }

            var saga = persister.Get <SagaData>(saga1.Id);
            saga.UniqueString = anotherUniqueString;
            persister.Update(saga);
            factory.SaveChanges();
            factory.ReleaseSession();

            using (var session = store.OpenSession())
            {
                var value = session.Advanced.GetMetadataFor(saga1)[SagaPersister.UniqueValueMetadataKey].ToString();
                Assert.AreEqual(anotherUniqueString, value);
            }
        }
    }
        public void Should_throw_if__trying_to_insert_same_messageid2()
        {
            var sessionFactory = new RavenSessionFactory(store);
            var persister = new OutboxPersister(sessionFactory) { EndpointName = "TestEndpoint" };

            persister.Store("MySpecialId", Enumerable.Empty<TransportOperation>());
            sessionFactory.SaveChanges();
            sessionFactory.ReleaseSession();

            persister.Store("MySpecialId", Enumerable.Empty<TransportOperation>());
            Assert.Throws<ConcurrencyException>(sessionFactory.SaveChanges);
        }
    public void Should_delete_the_saga()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            var sagaId = Guid.NewGuid();

            var factory = new RavenSessionFactory(store);
            factory.ReleaseSession();
            var persister = new SagaPersister(factory);
            persister.Save(new SagaData
            {
                Id = sagaId
            });
            factory.SaveChanges();

            var saga = persister.Get <SagaData>(sagaId);
            persister.Complete(saga);
            factory.SaveChanges();

            Assert.Null(persister.Get <SagaData>(sagaId));
        }
    }
        public void Should_throw_if__trying_to_insert_same_messageid()
        {
            var sessionFactory = new RavenSessionFactory(store);
            var persister = new OutboxPersister(sessionFactory) { EndpointName = "TestEndpoint" };
            persister.EndpointName = "TestEndpoint";

            using (sessionFactory.Session)
            {
                persister.Store("MySpecialId", Enumerable.Empty<TransportOperation>());
                Assert.Throws<NonUniqueObjectException>(() => persister.Store("MySpecialId", Enumerable.Empty<TransportOperation>()));

                sessionFactory.SaveChanges();
            }
        }
Example #11
0
        public void WithASagaPersistenceUnitOfWork(Action <RavenSagaPersister> action)
        {
            var sessionFactory = new RavenSessionFactory(new StoreAccessor(store));

            try
            {
                var sagaPersister = new RavenSagaPersister(sessionFactory);
                action(sagaPersister);

                sessionFactory.SaveChanges();
            }
            finally
            {
                sessionFactory.ReleaseSession();
            }
        }
    public void should_throw_a_ArgumentNullException()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            var saga1 = new SagaWithUniqueProperty
            {
                Id           = Guid.NewGuid(),
                UniqueString = null
            };

            var factory   = new RavenSessionFactory(store);
            var persister = new SagaPersister(factory);
            persister.Save(saga1);
            factory.SaveChanges();
        }
    }
Example #13
0
 public void Should_not_generate_a_to_long_unique_property_id()
 {
     using (var store = DocumentStoreBuilder.Build())
     {
         var factory = new RavenSessionFactory(store);
         factory.ReleaseSession();
         var persister    = new SagaPersister(factory);
         var uniqueString = Guid.NewGuid().ToString();
         var saga         = new SagaWithUniquePropertyAndALongNamespace
         {
             Id           = Guid.NewGuid(),
             UniqueString = uniqueString
         };
         persister.Save(saga);
         factory.SaveChanges();
     }
 }
    public void Datetime_property_should_be_persisted()
    {
        var entity = new SagaData
        {
            Id = Guid.NewGuid(),
            DateTimeProperty = DateTime.Parse("12/02/2010 12:00:00.01")
        };

        using (var store = DocumentStoreBuilder.Build())
        {
            var factory = new RavenSessionFactory(store);
            factory.ReleaseSession();
            var persister = new SagaPersister(factory);
            persister.Save(entity);
            factory.SaveChanges();
            var savedEntity = persister.Get <SagaData>(entity.Id);
            Assert.AreEqual(entity.DateTimeProperty, savedEntity.DateTimeProperty);
        }
    }
    public void Enums_should_be_persisted()
    {
        var entity = new SagaData
        {
            Id     = Guid.NewGuid(),
            Status = StatusEnum.AnotherStatus
        };

        using (var store = DocumentStoreBuilder.Build())
        {
            var factory = new RavenSessionFactory(store);
            factory.ReleaseSession();
            var persister = new SagaPersister(factory);
            persister.Save(entity);
            factory.SaveChanges();

            var savedEntity = persister.Get <SagaData>(entity.Id);
            Assert.AreEqual(entity.Status, savedEntity.Status);
        }
    }
        public void Should_save_with_not_dispatched()
        {
            var id = Guid.NewGuid().ToString("N");
            var sessionFactory = new RavenSessionFactory(store);

            var persister = new OutboxPersister(sessionFactory) { DocumentStore = store, EndpointName = "TestEndpoint" };
            persister.Store(id, new List<TransportOperation>
            {
                new TransportOperation(id, new Dictionary<string, string>(), new byte[1024*5], new Dictionary<string, string>()),
            });

            sessionFactory.SaveChanges();
            sessionFactory.ReleaseSession();

            OutboxMessage result;
            persister.TryGet(id, out result);

            var operation = result.TransportOperations.Single();

            Assert.AreEqual(id, operation.MessageId);
        }
 public void Public_setters_and_getters_of_concrete_classes_should_be_persisted()
 {
     using (var store = DocumentStoreBuilder.Build())
     {
         var entity = new SagaData
         {
             Id            = Guid.NewGuid(),
             TestComponent = new TestComponent
             {
                 Property = "Prop"
             }
         };
         var factory = new RavenSessionFactory(store);
         factory.ReleaseSession();
         var persister = new SagaPersister(factory);
         persister.Save(entity);
         factory.SaveChanges();
         var savedEntity = persister.Get <SagaData>(entity.Id);
         Assert.AreEqual(entity.TestComponent.Property, savedEntity.TestComponent.Property);
         Assert.AreEqual(entity.TestComponent.AnotherProperty, savedEntity.TestComponent.AnotherProperty);
     }
 }
Example #18
0
    public void Inherited_property_classes_should_be_persisted()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            var factory = new RavenSessionFactory(store);
            factory.ReleaseSession();
            var persister = new SagaPersister(factory);
            var entity    = new SagaData
            {
                Id = Guid.NewGuid(),
                PolymorphicRelatedProperty = new PolymorphicProperty
                {
                    SomeInt = 9
                }
            };
            persister.Save(entity);
            factory.SaveChanges();

            var savedEntity = persister.Get <SagaData>(entity.Id);
            var expected    = (PolymorphicProperty)entity.PolymorphicRelatedProperty;
            var actual      = (PolymorphicProperty)savedEntity.PolymorphicRelatedProperty;
            Assert.AreEqual(expected.SomeInt, actual.SomeInt);
        }
    }
        public void Should_set_messages_as_dispatched_with_old_and_new_recordId_format(string outboxRecordIdPrefix)
        {
            var sessionFactory = new RavenSessionFactory(store);
            var persister = new OutboxPersister(sessionFactory) { DocumentStore = store, EndpointName = "TestEndpoint" };

            var messageId = Guid.NewGuid().ToString();

            //manually store an OutboxRecord to control the OutboxRecordId format
            sessionFactory.Session.Store(new OutboxRecord
            {
                MessageId = messageId,
                Dispatched = false,
                TransportOperations = new List<OutboxRecord.OutboxOperation>
                {
                    new OutboxRecord.OutboxOperation
                    {
                        Message = new byte[1024 * 5],
                        Headers = new Dictionary<string, string>(),
                        MessageId = messageId,
                        Options = new Dictionary<string, string>()
                    }
                }
            }, outboxRecordIdPrefix + messageId);

            sessionFactory.SaveChanges();
            sessionFactory.ReleaseSession();

            persister.SetAsDispatched(messageId);
            sessionFactory.ReleaseSession();

            var result = sessionFactory.Session.Load<OutboxRecord>(outboxRecordIdPrefix + messageId);

            Assert.NotNull(result);
            Assert.True(result.Dispatched);
        }
        public void Should_update_dispatched_flag()
        {
            var id = Guid.NewGuid().ToString("N");

            var sessionFactory = new RavenSessionFactory(store);
            var persister = new OutboxPersister(sessionFactory) { DocumentStore = store, EndpointName = "TestEndpoint" };
            persister.Store(id, new List<TransportOperation>
            {
                new TransportOperation(id, new Dictionary<string, string>(), new byte[1024*5], new Dictionary<string, string>()),
            });

            sessionFactory.SaveChanges();
            sessionFactory.ReleaseSession();

            persister.SetAsDispatched(id);

            WaitForIndexing(store);

            using (var session = store.OpenSession())
            {
                var result = session.Query<OutboxRecord>().Where(o => o.MessageId == id)
                    .SingleOrDefault();

                Assert.NotNull(result);
                Assert.True(result.Dispatched);
            }
        }