[英]How should stale indexes be handled during testing?
我在內存模式下使用RavenDB進行單元測試。 我的查詢由靜態索引支持。 我沒有使用WaitForNonStaleResults()
API(我也不想)。
測試的典型工作流程是:
IndexCreation.CreateIndexes(Assembly, IDocumentStore)
集成索引 我注意到步驟1-3發生得如此之快,靜態索引沒有時間在步驟4之前得到更新 - 因此索引是陳舊的。
我為此創建了一個快速的解決方案。 在第3步之后,我執行:
while (documentStore.DocumentDatabase.Statistics.StaleIndexes.Length != 0)
Thread.Sleep(10);
這感覺很麻煩。 我想知道的是:
將此交叉發布到RavenDB用戶組並提供有效的解決方案。
在In-Memory模式下運行RavenDB時,索引是否過時是正常的?
是。 索引是索引。
在測試期間是否有更好的方法來避免過時的索引?
是。 初始化文檔存儲時配置全局約定:
var store = new EmbeddableDocumentStore();
store.RunInMemory = true;
store.Conventions = new DocumentConvention
{
DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites
};
store.Initialize();
注意: ConsistencyOptions.QueryYourWrites
不適用於Map / Reduce索引,即具有Reduce => ...
部分的索引。 對於這些,您必須在查詢時使用Customize(x => x.WaitForNonStale...())
更新:還有另一種方法 ,可能更好(尚未親自嘗試過)。 您可以實現IDocumentQueryListener以強制所有查詢返回非陳舊結果:
var store = new EmbeddableDocumentStore { RunInMemory = true };
store.Initialize();
store.RegisterListener(new ForceNonStaleQueryListener());
public class ForceNonStaleQueryListener : IDocumentQueryListener
{
public void BeforeQueryExecuted(IDocumentQueryCustomization customization)
{
queryCustomization.WaitForNonStaleResults();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.