You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by fd...@apache.org on 2011/05/17 21:16:32 UTC
svn commit: r1104476 - in /couchdb/branches/1.0.x:
share/www/script/test/replication.js src/couchdb/couch_rep_writer.erl
Author: fdmanana
Date: Tue May 17 19:16:31 2011
New Revision: 1104476
URL: http://svn.apache.org/viewvc?rev=1104476&view=rev
Log:
Fix and test for COUCHDB-885, replication of attachments causing conflicts
Modified:
couchdb/branches/1.0.x/share/www/script/test/replication.js
couchdb/branches/1.0.x/src/couchdb/couch_rep_writer.erl
Modified: couchdb/branches/1.0.x/share/www/script/test/replication.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/share/www/script/test/replication.js?rev=1104476&r1=1104475&r2=1104476&view=diff
==============================================================================
--- couchdb/branches/1.0.x/share/www/script/test/replication.js (original)
+++ couchdb/branches/1.0.x/share/www/script/test/replication.js Tue May 17 19:16:31 2011
@@ -740,6 +740,70 @@ couchTests.replication = function(debug)
TEquals('string', typeof repResult._local_id);
+ // COUCHDB-885 - push replication of a doc with attachment causes a
+ // conflict in the target.
+ dbA = new CouchDB("test_suite_db_a");
+ dbB = new CouchDB("test_suite_db_b");
+
+ dbA.deleteDb();
+ dbA.createDb();
+ dbB.deleteDb();
+ dbB.createDb();
+
+ var doc = {
+ _id: "doc1"
+ };
+ TEquals(true, dbA.save(doc).ok);
+
+ repResult = CouchDB.replicate(
+ dbA.name,
+ "http://" + host + "/" + dbB.name
+ );
+ TEquals(true, repResult.ok);
+ TEquals(true, repResult.history instanceof Array);
+ TEquals(1, repResult.history.length);
+ TEquals(1, repResult.history[0].docs_written);
+ TEquals(1, repResult.history[0].docs_read);
+ TEquals(0, repResult.history[0].doc_write_failures);
+
+ doc["_attachments"] = {
+ "hello.txt": {
+ "content_type": "text/plain",
+ "data": "aGVsbG8gd29ybGQ=" // base64:encode("hello world")
+ },
+ "foo.dat": {
+ "content_type": "not/compressible",
+ "data": "aSBhbSBub3QgZ3ppcGVk" // base64:encode("i am not gziped")
+ }
+ };
+
+ TEquals(true, dbA.save(doc).ok);
+ repResult = CouchDB.replicate(
+ dbA.name,
+ "http://" + host + "/" + dbB.name
+ );
+ TEquals(true, repResult.ok);
+ TEquals(true, repResult.history instanceof Array);
+ TEquals(2, repResult.history.length);
+ TEquals(1, repResult.history[0].docs_written);
+ TEquals(1, repResult.history[0].docs_read);
+ TEquals(0, repResult.history[0].doc_write_failures);
+
+ var copy = dbB.open(doc._id, {
+ conflicts: true, deleted_conflicts: true, attachments: true,
+ att_encoding_info: true});
+ T(copy !== null);
+ TEquals("undefined", typeof copy._conflicts);
+ TEquals("undefined", typeof copy._deleted_conflicts);
+ TEquals("text/plain", copy._attachments["hello.txt"]["content_type"]);
+ TEquals("aGVsbG8gd29ybGQ=", copy._attachments["hello.txt"]["data"]);
+ TEquals("gzip", copy._attachments["hello.txt"]["encoding"]);
+ TEquals("not/compressible", copy._attachments["foo.dat"]["content_type"]);
+ TEquals("aSBhbSBub3QgZ3ppcGVk", copy._attachments["foo.dat"]["data"]);
+ TEquals("undefined", typeof copy._attachments["foo.dat"]["encoding"]);
+ // end of test for COUCHDB-885
+
+
// cleanup
dbA.deleteDb();
dbB.deleteDb();
Modified: couchdb/branches/1.0.x/src/couchdb/couch_rep_writer.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/src/couchdb/couch_rep_writer.erl?rev=1104476&r1=1104475&r2=1104476&view=diff
==============================================================================
--- couchdb/branches/1.0.x/src/couchdb/couch_rep_writer.erl (original)
+++ couchdb/branches/1.0.x/src/couchdb/couch_rep_writer.erl Tue May 17 19:16:31 2011
@@ -71,7 +71,7 @@ write_bulk_docs(_Db, []) ->
[];
write_bulk_docs(#http_db{headers = Headers} = Db, Docs) ->
JsonDocs = [
- couch_doc:to_json_obj(Doc, [revs, att_gzip_length]) || Doc <- Docs
+ couch_doc:to_json_obj(Doc, [revs]) || Doc <- Docs
],
Request = Db#http_db{
resource = "_bulk_docs",
@@ -91,7 +91,7 @@ write_multi_part_doc(#http_db{headers=He
JsonBytes = ?JSON_ENCODE(
couch_doc:to_json_obj(
Doc,
- [follows, att_encoding_info, attachments]
+ [follows, att_encoding_info, attachments, revs]
)
),
Boundary = couch_uuids:random(),