draft compression config

Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/83cca5f6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/83cca5f6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/83cca5f6

Branch: refs/heads/2876-js-tests
Commit: 83cca5f6935dc9339c39df5baf6e03c1812be062
Parents: 2434997
Author: sebastianro <[email protected]>
Authored: Wed Nov 11 22:36:23 2015 +0100
Committer: sebastianro <[email protected]>
Committed: Thu Nov 12 21:56:05 2015 +0100

----------------------------------------------------------------------
 test/javascript/tests/replication.js | 84 +++++++++++++++++++++----------
 1 file changed, 57 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/83cca5f6/test/javascript/tests/replication.js
----------------------------------------------------------------------
diff --git a/test/javascript/tests/replication.js 
b/test/javascript/tests/replication.js
index 5b65e38..b2eafeb 100644
--- a/test/javascript/tests/replication.js
+++ b/test/javascript/tests/replication.js
@@ -58,39 +58,69 @@ couchTests.replication = function(debug) {
     return data;
   }
 
-
-  function enableAttCompression(level, types) {
-    var xhr = CouchDB.request(
-      "PUT",
-      "/_config/attachments/compression_level",
-      {
-        body: JSON.stringify(level),
-        headers: {"X-Couch-Persist": "false"}
-      }
-    );
+  
+  function runAllNodes(callback) {
+    // new and fancy: clustered version: pull cluster_members and walk over 
all of them
+    var xhr = CouchDB.request("GET", "/_membership"); 
     T(xhr.status === 200);
-    xhr = CouchDB.request(
-      "PUT",
-      "/_config/attachments/compressible_types",
-      {
-        body: JSON.stringify(types),
-        headers: {"X-Couch-Persist": "false"}
-      }
-    );
+    JSON.parse(xhr.responseText).cluster_nodes.forEach(callback);
+  }
+
+  function runFirstNode(callback) {
+    // new and fancy: clustered version: pull cluster_members and walk over 
all of them
+    var xhr = CouchDB.request("GET", "/_membership"); 
     T(xhr.status === 200);
+    var node = JSON.parse(xhr.responseText).cluster_nodes[0];
+    return callback(node);
   }
 
+  function getCompressionInfo() {
+    return runFirstNode(function(node) {
+      var xhr = CouchDB.request(
+        "GET",
+        "_node/" + node + "/_config/attachments"
+      );
+      T(xhr.status === 200);
+      var res = JSON.parse(xhr.responseText);
+      return {"level": res.compression_level, "types": res.compressible_types};
+    });
+  }
+
+  function enableAttCompression(level, types) {
+    runAllNodes(function(node) {
+      var xhr = CouchDB.request(
+        "PUT",
+        "_node/" + node + "/_config/attachments/compression_level",
+        {
+          body: JSON.stringify(level),
+          headers: {"X-Couch-Persist": "false"}
+        }
+      );
+      T(xhr.status === 200);
+      xhr = CouchDB.request(
+        "PUT",
+        "_node/" + node + "/_config/attachments/compressible_types",
+        {
+          body: JSON.stringify(types),
+          headers: {"X-Couch-Persist": "false"}
+        }
+      );
+      T(xhr.status === 200);
+    });
+  }
 
   function disableAttCompression() {
-    var xhr = CouchDB.request(
-      "PUT",
-      "/_config/attachments/compression_level",
-      {
-        body: JSON.stringify("0"),
-        headers: {"X-Couch-Persist": "false"}
-      }
-    );
-    T(xhr.status === 200);
+    runAllNodes(function(node) {
+      var xhr = CouchDB.request(
+        "PUT",
+        "_node/" + node + "/_config/attachments/compression_level",
+        {
+          body: JSON.stringify("0"),
+          headers: {"X-Couch-Persist": "false"}
+        }
+      );
+      T(xhr.status === 200);
+    });
   }
 
 

Reply via email to