Last active
December 17, 2015 13:59
-
-
Save kijanawoodard/5621591 to your computer and use it in GitHub Desktop.
concurrency issue
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
using System; | |
using System.Linq; | |
using Raven.Abstractions.Smuggler; | |
using Raven.Database.Smuggler; | |
using Raven.Tests.Helpers; | |
using Xunit; | |
namespace RavenTests | |
{ | |
public class ConcurrencyTests : RavenTestBase | |
{ | |
public static string FindTypeByTagName(Type type) | |
{ | |
string name = type.Name; | |
return name; | |
} | |
[Fact] | |
public void CanSaveImplicitChangesToDocumentsFromAQuery_UsingDunpFile() | |
{ | |
using (var store = NewDocumentStore()) | |
{ | |
store.Conventions.FindTypeTagName = FindTypeByTagName; | |
var options = new SmugglerOptions | |
{ | |
BackupPath = @"Dump of test-concurrency-exception2, 21 May 2013 14-36.ravendump" | |
}; | |
var dumper = new DataDumper(store.DocumentDatabase, options); | |
dumper.ImportData(options); | |
using (var session = store.OpenSession()) | |
{ | |
session.Advanced.UseOptimisticConcurrency = true; | |
var foos = | |
session.Query<SectionData>() | |
.Customize(x => x.WaitForNonStaleResults()) | |
.Take(1024) | |
.ToList(); | |
Assert.True(foos.Count > 200); | |
session.SaveChanges(); | |
} | |
} | |
} | |
} | |
public class SectionData | |
{ | |
public string Id { get; set; } | |
} | |
} |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Linq.Expressions; | |
using System.Text; | |
using System.Threading.Tasks; | |
using BusinessLogic_v4.Framework.DbObjects.Objects; | |
using BusinessLogic_v4.Framework.Multilingual; | |
using BusinessLogic_v4.Modules.Data.Sections; | |
using NUnit.Framework; | |
using Raven.Client.Document; | |
using Raven.Client.Indexes; | |
using Raven.Json.Linq; | |
using Xunit; | |
namespace RavenDb_ConcurrencyIssue | |
{ | |
[TestFixture] | |
public class FailingUnitTest | |
{ | |
public static string FindTypeByTagName(Type type) | |
{ | |
string name = type.Name; | |
//if (name.EndsWith("Base")) | |
//{ | |
// name = name.Substring(0, name.Length - 4); | |
//} | |
//name = Raven.Client.Util.Inflector.Pluralize(name); | |
return name; | |
} | |
[Fact] | |
public void testConcurrencyException() | |
{ | |
DocumentStore store = new DocumentStore(); | |
store.Url = "http://localhost:8080"; | |
store.DefaultDatabase = "test-concurrency-exception2"; | |
store.Conventions.FindTypeTagName = FindTypeByTagName; | |
store.Initialize(); | |
store.ExecuteIndex(new SectionDataIndex()); | |
//store.Conventions.CustomizeJsonSerializer = _customizeJsonSerializer; | |
//TestRavenDbManager.Instance.UseTestInMemoryDatabase = false; | |
var session = store.OpenSession(); | |
session.Advanced.UseOptimisticConcurrency = true; | |
var q = session.Query<SectionData>("SectionDataIndex"); | |
q = q.Customize(x => x.WaitForNonStaleResults()); | |
var allSections = q.Take(9999).ToList(); | |
var s48 = allSections.Where(x => x.Id == "SectionData/48").ToList(); | |
var metadata = session.Advanced.GetMetadataFor(s48.First()); | |
var data = RavenJObject.FromObject(s48.First()).ToString(); | |
// var val = session.Load<SectionData>("SectionData/48"); | |
session.SaveChanges(); //this throws a ConcurrencyException "PUT attempted on document 'SectionData/48' using a non current etag" | |
session.Dispose(); | |
} | |
[Fact] | |
public void SaveSomeData() | |
{ | |
//RUN THIS TEST TEST FIRST | |
//THEN UNCOMMENT NEW PROPERTY IN FOO | |
DocumentStore store = new DocumentStore(); | |
store.Url = "http://localhost:8080"; | |
store.DefaultDatabase = "test-concurrency-exception2"; | |
store.Initialize(); | |
var session = store.OpenSession(); | |
Enumerable.Range(1, 250) | |
.Select(x => new Foo()) | |
.ToList() | |
.ForEach(session.Store); | |
session.SaveChanges(); | |
} | |
[Fact] | |
public void ShouldBeAbleToSaveListWithImplicitChanges() | |
{ | |
DocumentStore store = new DocumentStore(); | |
store.Url = "http://localhost:8080"; | |
store.DefaultDatabase = "test-concurrency-exception2"; | |
store.Initialize(); | |
store.ExecuteIndex(new FooIndex()); | |
var session = store.OpenSession(); | |
session.Advanced.UseOptimisticConcurrency = true; | |
var foos = | |
session.Query<Foo>("FooIndex") | |
.Customize(x => x.WaitForNonStaleResults()) | |
.Take(9999) | |
.ToList(); | |
session.SaveChanges(); | |
session.Dispose(); | |
} | |
public class Foo | |
{ | |
public string Id { get; set; } | |
public string Bar { get; set; } | |
// public string Baz { get; set; } | |
// public MultilingualValue<string> Summary { get; set; } | |
// public IObjectSpecificFields SpecificFields { get; set; } | |
// public Foo() | |
// { | |
// Summary = new MultilingualValue<string>(); | |
// } | |
} | |
public class FooIndex : AbstractIndexCreationTask<Foo> | |
{ | |
public FooIndex() | |
{ | |
this.Map = (items => items.Select(item => new | |
{ | |
_ = "whatever", | |
item.Bar | |
})); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment