Skip to content

Instantly share code, notes, and snippets.

@andreasohlund
Created March 20, 2012 11:10
Show Gist options
  • Select an option

  • Save andreasohlund/2134140 to your computer and use it in GitHub Desktop.

Select an option

Save andreasohlund/2134140 to your computer and use it in GitHub Desktop.
namespace NServiceBus.Persistence.Raven.Tests
{
using System;
using System.IO;
using System.Messaging;
using System.Threading;
using System.Transactions;
using NUnit.Framework;
using global::Raven.Client;
using global::Raven.Client.Document;
public class PotentialRavenBug
{
static string QueueAddress = "FormatName:DIRECT=OS:win2008r2\\private$\\test";
protected IDocumentStore store;
[SetUp]
public void SetUp()
{
//store = new EmbeddableDocumentStore { RunInMemory = true };
store = new DocumentStore { Url = "http://localhost:8080" };
store.Initialize();
}
[TearDown]
public void TearDown()
{
store.Dispose();
}
[Test]
public void Raven_dtc_bug()
{
new MessageQueue(QueueAddress, QueueAccessMode.ReceiveAndAdmin)
.Purge();
for (int i = 0; i < 40; i++)
{
var id = Guid.NewGuid();
using (var tx = new TransactionScope())
using (var session = store.OpenSession())
{
using (var q = new MessageQueue(QueueAddress, QueueAccessMode.Send))
{
var toSend = new Message { BodyStream = new MemoryStream(new byte[8]) };
//if you remove the send the problem goes away as well
q.Send(toSend, MessageQueueTransactionType.Automatic);
}
session.Store(new TestDocument
{
Id = id
});
session.SaveChanges();
tx.Complete();
}
//remove this to expose the bug
//Thread.Sleep(200);
using (var session = store.OpenSession())
Assert.NotNull(session.Load<TestDocument>(id));
}
}
}
public class TestDocument
{
public Guid Id { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment