vendredi 3 juillet 2015

Cannot use transactions in RavenDB 3 unittests

We have a couple of tests that relies on transactions to work. We are trying to move from RavenDB 2.5 to 3.0 now and in doing so all tests using transactions started to fail. We are using NUnit as our test framework.

I wrote a small example of the error we are getting:

[TestFixture]
public class TransactionTest : RavenTestBase
{
    [Test]
    public void TransactionTest1()
    {
        using (var store = NewDocumentStore(configureStore: ConfigureTestStore))
        {
            using (var transaction = new TransactionScope())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new SampleData { Id = "RavenDB" });
                    session.SaveChanges();
                    transaction.Complete();
                }
            }
        }
    }

    public void ConfigureTestStore(EmbeddableDocumentStore documentStore)
    {
        documentStore.RunInMemory = true;
        documentStore.Configuration.RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true;
        documentStore.EnlistInDistributedTransactions = true;
    }
}
public class SampleData
{
    public string Id { get; set; }
}

This results in the exception:

System.InvalidOperationException : The database <system> cannot be used with distributed transactions

I can set:

documentStore.EnlistInDistributedTransactions = false;

But then none of my transactions acctually works. The test above works fine in RavenDB 2.5. Is it not supposed to work in RavenDB 3 too?

Aucun commentaire:

Enregistrer un commentaire