In my last post, I added
store.Conventions.DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites;to the SpecsForRavenDb<T> class so that we can query data we have just inserted into Raven. The problem with this is DefaultQueryingConsistency property does not apply to indexes.
To instruct Raven to wait for non-stale results when querying indexes, we can add add a listener our SpecsForRavenDb<T> class.
public class NoStaleQueriesListener : IDocumentQueryListener { public void BeforeQueryExecuted(IDocumentQueryCustomization queryCustomization) { queryCustomization.WaitForNonStaleResults(); } }This simple class tells RavenDB before each query is executed wait for non stale results. To hook it into our test base class, we just need to add one line to SpecsForRavenDb<T> before we initialize our EmbeddableDocumentStore:
.RegisterListener(NoStaleQueriesListener())Since we are only applying our listener when testing, Raven will wait for non stale results in a test scenario, but will still use the default behavior of returning results as fast as possible when running in production.
Now our final SpecsForRavenDb<T> class looks like this:
public abstract class SpecsForRavenDb<T> : SpecsFor<T> where T : class { private IDocumentStore _store; public IDocumentSession RavenSession { get; set; } public override void SetupEachSpec() { _store = new EmbeddableDocumentStore { RunInMemory = true } .RegisterListener(NoStaleQueriesListener()) .Initialize(); _store.Conventions.DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites; IndexCreation.CreateIndexes(typeof(MyProject.MyIndex).Assembly, _store); RavenSession = _store.OpenSession(); base.SetupEachSpec(); } protected override void ConfigureContainer(StructureMap.IContainer container) { container.Configure(cfg => cfg.For<IDocumentSession>().Use(RavenSession)); } protected override void AfterSpec() { base.AfterSpec(); RavenSession.Dispose(); _store.Dispose(); } }
Poker Online - JTG Hub
ReplyDeletePoker online 고양 출장안마 is legal in Nevada 양산 출장샵 and Colorado. 충청북도 출장안마 Poker is a casino-style game that is fun 속초 출장안마 for players to win in order 성남 출장안마 to get the most out of