summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fabric/src/fabric_db_delete.erl6
-rw-r--r--src/mango/src/mango_cursor_view.erl8
-rw-r--r--src/mango/test/19-find-conflicts.py41
-rw-r--r--src/mango/test/mango.py5
-rwxr-xr-xtest/javascript/run8
-rw-r--r--test/javascript/tests-cluster/with-quorum/db_deletion.js12
-rw-r--r--test/javascript/tests-cluster/without-quorum/db_creation.js3
-rw-r--r--test/javascript/tests-cluster/without-quorum/db_deletion.js16
-rw-r--r--test/javascript/tests-cluster/without-quorum/db_deletion_overridden_quorum.js8
9 files changed, 78 insertions, 29 deletions
diff --git a/src/fabric/src/fabric_db_delete.erl b/src/fabric/src/fabric_db_delete.erl
index 9ba55fbb8..c146cb6cd 100644
--- a/src/fabric/src/fabric_db_delete.erl
+++ b/src/fabric/src/fabric_db_delete.erl
@@ -79,12 +79,12 @@ maybe_stop(W, Counters) ->
case {Ok + NotFound, Ok, NotFound} of
{W, 0, W} ->
{#shard{dbname=Name}, _} = hd(Counters),
- couch_log:warning("~p not_found ~s", [?MODULE, Name]),
+ couch_log:warning("~p not_found ~d", [?MODULE, Name]),
{stop, not_found};
{W, _, _} ->
{stop, ok};
- {N, M, _} when N >= (W div 2 + 1), M > 0 ->
- {stop, accepted};
+ {_, M, _} when M > 0 ->
+ {stop,accepted};
_ ->
{error, internal_server_error}
end
diff --git a/src/mango/src/mango_cursor_view.erl b/src/mango/src/mango_cursor_view.erl
index 1e2108b7d..dbea36e77 100644
--- a/src/mango/src/mango_cursor_view.erl
+++ b/src/mango/src/mango_cursor_view.erl
@@ -70,7 +70,8 @@ explain(Cursor) ->
{end_key, maybe_replace_max_json(Args#mrargs.end_key)},
{direction, Args#mrargs.direction},
{stable, Args#mrargs.stable},
- {update, Args#mrargs.update}
+ {update, Args#mrargs.update},
+ {conflicts, Args#mrargs.conflicts}
]}}].
@@ -283,9 +284,8 @@ apply_opts([{r, RStr} | Rest], Args) ->
NewArgs = Args#mrargs{include_docs = IncludeDocs},
apply_opts(Rest, NewArgs);
apply_opts([{conflicts, true} | Rest], Args) ->
- % I need to patch things so that views can specify
- % parameters when loading the docs from disk
- apply_opts(Rest, Args);
+ NewArgs = Args#mrargs{conflicts = true},
+ apply_opts(Rest, NewArgs);
apply_opts([{conflicts, false} | Rest], Args) ->
% Ignored cause default
apply_opts(Rest, Args);
diff --git a/src/mango/test/19-find-conflicts.py b/src/mango/test/19-find-conflicts.py
new file mode 100644
index 000000000..c6d59f00d
--- /dev/null
+++ b/src/mango/test/19-find-conflicts.py
@@ -0,0 +1,41 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+import mango
+import copy
+
+DOC = [
+ {
+ "_id": "doc",
+ "a": 2
+ }
+]
+
+CONFLICT = [
+ {
+ "_id": "doc",
+ "_rev": "1-23202479633c2b380f79507a776743d5",
+ "a": 1
+ }
+]
+
+class ChooseCorrectIndexForDocs(mango.DbPerClass):
+ def setUp(self):
+ self.db.recreate()
+ self.db.save_docs(copy.deepcopy(DOC))
+ self.db.save_docs_with_conflicts(copy.deepcopy(CONFLICT))
+
+ def test_retrieve_conflicts(self):
+ self.db.create_index(["_conflicts"])
+ result = self.db.find({"_conflicts": { "$exists": True}}, conflicts=True)
+ self.assertEqual(result[0]['_conflicts'][0], '1-23202479633c2b380f79507a776743d5')
+ self.assertEqual(result[0]['_rev'], '1-3975759ccff3842adf690a5c10caee42')
diff --git a/src/mango/test/mango.py b/src/mango/test/mango.py
index 9b6b998cd..bc12bbc68 100644
--- a/src/mango/test/mango.py
+++ b/src/mango/test/mango.py
@@ -95,6 +95,11 @@ class Database(object):
def save_doc(self, doc):
self.save_docs([doc])
+ def save_docs_with_conflicts(self, docs, **kwargs):
+ body = json.dumps({"docs": docs, "new_edits": False})
+ r = self.sess.post(self.path("_bulk_docs"), data=body, params=kwargs)
+ r.raise_for_status()
+
def save_docs(self, docs, **kwargs):
body = json.dumps({"docs": docs})
r = self.sess.post(self.path("_bulk_docs"), data=body, params=kwargs)
diff --git a/test/javascript/run b/test/javascript/run
index 8ae424467..ca69e1ff2 100755
--- a/test/javascript/run
+++ b/test/javascript/run
@@ -134,10 +134,11 @@ def main():
tmp.append(name)
tests = tmp
- fmt = mkformatter(tests)
passed = 0
failed = 0
- for test in tests:
+ if len(tests) > 0 :
+ fmt = mkformatter(tests)
+ for test in tests:
result = run_couchjs(test, fmt)
if result == 0:
passed += 1
@@ -169,8 +170,7 @@ def build_test_case_paths(path,args=None):
elif os.path.isfile(pname + ".js"):
tests.append(pname + ".js")
else:
- sys.stderr.write("Unknown test: " + name + os.linesep)
- exit(1)
+ sys.stderr.write("Waring - Unknown test: " + name + os.linesep)
return tests
diff --git a/test/javascript/tests-cluster/with-quorum/db_deletion.js b/test/javascript/tests-cluster/with-quorum/db_deletion.js
index bef4cae43..079fb493d 100644
--- a/test/javascript/tests-cluster/with-quorum/db_deletion.js
+++ b/test/javascript/tests-cluster/with-quorum/db_deletion.js
@@ -10,15 +10,21 @@
// License for the specific language governing permissions and limitations under
// the License.
-// Do DB deletion in a cluster with quorum conditions.
+// Do DB deletion under cluster with quorum conditions.
couchTests.db_deletion = function(debug) {
if (debug) debugger;
var db_name = get_random_db_name()
var db = new CouchDB(db_name, {"X-Couch-Full-Commit":"false"});
+
db.createDb();
- db.deleteDb();
- T(db.last_req.status="200","Should return 200");
+ // DB Deletion should return 202 - Acceted as the custer is not complete
+ xhr = CouchDB.request("DELETE", "/" + db_name + "/");
+ T(xhr.status == 202);
+
+// DB Deletion should return 404 - Not found
+ xhr = CouchDB.request("DELETE", "/not-existing-db/");
+ T(xhr.status == 404);
};
diff --git a/test/javascript/tests-cluster/without-quorum/db_creation.js b/test/javascript/tests-cluster/without-quorum/db_creation.js
index 0d8ff8367..a21d37746 100644
--- a/test/javascript/tests-cluster/without-quorum/db_creation.js
+++ b/test/javascript/tests-cluster/without-quorum/db_creation.js
@@ -23,6 +23,5 @@ couchTests.db_creation = function(debug) {
T(xhr.status == 202);
// cleanup
- // TODO DB deletions fails if the quorum is not met.
- xhr = CouchDB.request("DELETE", "/" + db_name + "/");
+ db.deleteDb();
};
diff --git a/test/javascript/tests-cluster/without-quorum/db_deletion.js b/test/javascript/tests-cluster/without-quorum/db_deletion.js
index 04b15c058..006345e30 100644
--- a/test/javascript/tests-cluster/without-quorum/db_deletion.js
+++ b/test/javascript/tests-cluster/without-quorum/db_deletion.js
@@ -10,19 +10,21 @@
// License for the specific language governing permissions and limitations under
// the License.
-// Do DB deletion in a cluster with quorum conditions.
+// Do DB creation under cluster with quorum conditions.
couchTests.db_deletion = function(debug) {
if (debug) debugger;
var db_name = get_random_db_name()
var db = new CouchDB(db_name, {"X-Couch-Full-Commit":"false"});
- db.createDb();
- //db.deleteDb();
- // TODO DB deletions fails if the quorum is not met.
+ db.createDb();
+
+ // DB Deletion should return 202 - Acepted
xhr = CouchDB.request("DELETE", "/" + db_name + "/");
- //T(db.last_req.status="202","Should return 202");
- console.log("Skipped-TODO: Fix issue 500 Error on delete. 202->"+xhr.status)
-
+ T(xhr.status == 202);
+
+ // DB Deletion should return 404 - Not found
+ xhr = CouchDB.request("DELETE", "/not-existing-db/");
+ T(xhr.status == 404);
};
diff --git a/test/javascript/tests-cluster/without-quorum/db_deletion_overridden_quorum.js b/test/javascript/tests-cluster/without-quorum/db_deletion_overridden_quorum.js
index 4a1efce23..11b344cfb 100644
--- a/test/javascript/tests-cluster/without-quorum/db_deletion_overridden_quorum.js
+++ b/test/javascript/tests-cluster/without-quorum/db_deletion_overridden_quorum.js
@@ -19,11 +19,7 @@ couchTests.db_deletion_overridden_quorum = function(debug) {
var db = new CouchDB(db_name, {"X-Couch-Full-Commit":"false"},{"w":1});
db.createDb();
-
- //db.deleteDb();
- // TODO DB deletions fails if the quorum is not met.
+ // DB deletions does not consider overriden quorum param.
xhr = CouchDB.request("DELETE", "/" + db_name + "/");
- //T(db.last_req.status="200","Should return 200");
- console.log("Skipped-TODO: Fix issue 500 Error on delete - Not considering overriden quorum. 200->"+xhr.status);
-
+ T(db.last_req.status="202","Should return 202");
};