如何在不使用复制的情况下模拟 CouchDB 中的冲突?
我想为我的应用程序编写一个单元测试来模拟复制期间的冲突。有没有办法仅使用单个 CouchDB 数据库和服务器来模拟冲突?
I'd like to write a unit test for my app that simulates a conflict during replication. Is there a way to simulate a conflict using only a single CouchDB database and server?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您想要获取数据库中包含冲突的文档,而不是 409 冲突响应?
因此,在数据库中创建一个具有已知 _id 的文档:
然后使用带有 all_or_nothing: true 选项的批量文档 API 来更新带有故意错误或无 _rev 的同一文档,添加一些不同的文档属性以实现良好的测量:
然后您应该文档中存在冲突:
您还可以使用
?new_edits=false
作为 描述CouchDB 提交者 Randall Leeds。I assume you want to get a document containing a conflict in your database, rather than a 409 Conflict response?
So, create a document in the database with a known _id:
Then use the bulk docs API with the all_or_nothing: true option to update the same document with a deliberately bad or no _rev, adding some different document attributes for good measure:
You should then have a conflict in the document:
You can also perform a normal query with
?new_edits=false
as described by CouchDB committer Randall Leeds.提出问题后进一步 Google 了一下,答案似乎是使用批量文档 API 的
全有或全无
模式。http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
查看页面末尾附近。
Googled further after asking the question, and it looks like the answer is to use the
all-or-nothing
mode of the bulk document API.http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
Look near the end of the page.
只需发布两个具有相同 _id 属性的文档即可。这会产生冲突,因为第二个文档将不包含正确的 _rev 属性。请记住,您需要在每个后续帖子中包含最新的 _rev 属性,以便 CouchDB 知道您是最新的。
此外,您可以在同一服务器上创建两个数据库并在它们之间进行复制。
Just post two documents with the same _id attribute. This creates a conflict since the 2nd doc will not contain the proper _rev attribute. Remember, you need to include the latest _rev attribute in each subsequent post so that CouchDB knows you are up to date.
Also, you can create two databases on the same server and replicate between those.