Created
July 9, 2012 21:11
-
-
Save darkiri/3078953 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_updating_same_object_in_separate_sessions : raven_persistence_context | |
{ | |
static Exception Exception; | |
Establish context = () => StoreSingleObject(new MyClass {Text = "this one"}); | |
Because of = () => Exception = Catch.Exception(UpdateTwoObjectsInTwoSessions); | |
It should_throw_concurrency_exception = () => Exception.ShouldBeOfType<ConcurrencyException>(); | |
static void UpdateTwoObjectsInTwoSessions() | |
{ | |
using (var session = Store.OpenSession()) | |
{ | |
session.Advanced.UseOptimisticConcurrency = true; | |
session | |
.Query<MyClass>() | |
.First() | |
.Text = "still one"; | |
AtTheSameTimeInAnotherSession(); | |
session.SaveChanges(); | |
} | |
} | |
static void AtTheSameTimeInAnotherSession() | |
{ | |
using (var anotherSession = Store.OpenSession()) | |
{ | |
anotherSession | |
.Query<MyClass>() | |
.First() | |
.Text = "ha ha"; | |
anotherSession.SaveChanges(); | |
} | |
} | |
public class MyClass | |
{ | |
public string Id { get; set; } | |
public string Text; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment