应该如何陈旧的指标在测试过程中如何处理? [英] How should stale indexes be handled during testing?

查看:117
本文介绍了应该如何陈旧的指标在测试过程中如何处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在内存模式使用RavenDB的单元测试。我的查询是由静态指标支持。我不使用 WaitForNonStaleResults() API(我也不想要)。



有关测试的典型工作流程




  1. 初始化RavenDB在内存模式

  2. 使用集成指数 IndexCreation.CreateIndexes(大会,IDocumentStore)

  3. 插入测试数据(验证查询行为)

  4. 运行查询

  5. 验证查询输出



我注意到步骤1-3发生的如此之快,静态指标唐'T有时间在步骤4之前得到更新 - 因此指标是陈旧



我创建了一个快速的解决方法这一点。步骤3之后,我执行:

 而(!documentStore.DocumentDatabase.Statistics.StaleIndexes.Length = 0)
Thread.sleep代码(10);

这感觉累赘。我想知道的是:




  • 这是正常的索引在内存模式运行RavenDB当是过时

  • 有没有一种更好的办法测试过程中避免旧索引吗?


解决方案

跨张贴这 RavenDB所在的用户组并有一个工作的解决方案。




这是正常的,在内存
模式下运行RavenDB当索引过时?




是的。索引是一个索引。




有没有更好的办法测试过程中避免旧索引吗?




是的。初始化文件存储时配置全局约定:

  VAR店=新EmbeddableDocumentStore(); 
store.RunInMemory = TRUE;
store.Conventions =新DocumentConvention
{
DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites
};

store.Initialize();

注意: ConsistencyOptions.QueryYourWrites 不与地图工作/缩小指标,即用减少=>指标; ... 部分。对于这些,你必须使用自定义(X => x.WaitForNonStale ...())查询



<当
点> 更新:另一种方法,该可能会更好(没有亲自尝试过呢)。你可以实现IDocumentQueryListener强制所有的查询返回未失效的结果:

  VAR店=新EmbeddableDocumentStore {RunInMemory =真}; 
store.Initialize();

store.RegisterListener(新ForceNonStaleQueryListener());

公共类ForceNonStaleQueryListener:IDocumentQueryListener
{
公共无效BeforeQueryExecuted(IDocumentQueryCustomization定制)
{
queryCustomization.WaitForNonStaleResults();
}
}


I am using RavenDB in In-Memory mode for unit testing. My queries are backed by static indexes. I am not using WaitForNonStaleResults() API (nor do I want to).

Typical workflow for a test is:

  1. Initialise RavenDB in In-Memory mode
  2. Integrate indexes using IndexCreation.CreateIndexes(Assembly, IDocumentStore)
  3. Insert test data (for verifying query behaviour)
  4. Run query
  5. Verify query output

I have noticed steps 1-3 happen so quickly, that static indexes don't have time to get updated before step 4 - therefore the indexes are stale.

I have created a quick work-around for this. After step 3, I execute:

while (documentStore.DocumentDatabase.Statistics.StaleIndexes.Length != 0)
    Thread.Sleep(10);

This feels cumbersome. What I would like to know is:

  • Is it normal for indexes to be stale when running RavenDB in In-Memory mode?
  • Is there a better way to avoid stale indexes during testing?

解决方案

Cross-posted this to RavenDB usergroup and have a working solution.

Is it normal for indexes to be stale when running RavenDB in In-Memory mode?

Yes. An index is an index.

Is there a better way to avoid stale indexes during testing?

Yes. Configure global conventions when initialising document store:

var store = new EmbeddableDocumentStore();
store.RunInMemory = true;
store.Conventions = new DocumentConvention
{
    DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites
};

store.Initialize();

Note: ConsistencyOptions.QueryYourWrites doesn't work with Map/Reduce indexes, i.e. indexes with a Reduce => ... section. For these you have to use Customize(x => x.WaitForNonStale...()) when querying

Update: There is another approach, which may be better (haven't personally tried it yet). You could implement IDocumentQueryListener to force all queries to return non-stale results:

var store = new EmbeddableDocumentStore { RunInMemory = true };
store.Initialize();

store.RegisterListener(new ForceNonStaleQueryListener());

public class ForceNonStaleQueryListener : IDocumentQueryListener
{
    public void BeforeQueryExecuted(IDocumentQueryCustomization customization)
    {
        queryCustomization.WaitForNonStaleResults();
    }
}

这篇关于应该如何陈旧的指标在测试过程中如何处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆