Created
July 9, 2012 21:22
-
-
Save darkiri/3079035 to your computer and use it in GitHub Desktop.
Optimistic Concurrency in RavenDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Subject("Raven Experiments")] | |
public class when_storing_two_objects_with_same_id_in_separate_sessions : raven_persistence_context | |
{ | |
static Exception Exception; | |
Because of = () => Exception = Catch.Exception(CreateTwoObjectsInTwoSessions); | |
It should_throw_concurrency_exception = () => Exception.ShouldBeOfType<ConcurrencyException>(); | |
static void CreateTwoObjectsInTwoSessions() | |
{ | |
using (var session = Store.OpenSession()) | |
{ | |
StoreOnce(session, "first"); | |
} | |
using (var session = Store.OpenSession()) | |
{ | |
StoreOnce(session, "another first"); | |
} | |
} | |
static void StoreOnce(IDocumentSession session, string text) | |
{ | |
session.Advanced.UseOptimisticConcurrency = true; | |
session.Store(new MyEvent {Revision = 1, Payload = text}); | |
session.SaveChanges(); | |
} | |
public class MyEvent | |
{ | |
public int Id { get { return Revision; } } | |
public int Revision { get; set; } | |
public string Payload { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment