function createTemplate(cb) { coux.del(testTemplate, function() { coux.put(testTemplate, e(function() { coux.put(testTemplate.concat('test-doc'), {foobar: "ok"}, e(cb)); })); }); }
test('should update the document with an error', function(test) { coux.waitForDoc(testDb, chId, 1, function(err, doc) { if (doc.state != "error") return true; test.is(doc.state, "error"); test.end(); }); });
function bindControlDb() { var control = docstate.control(); userChannelControl.bindToControlDb("test-control", "test-app", testConfig); control.start(); return coux.subscribeDb(testDb, function(change) { control.handle(change.doc); }); }
test("with a new channel document", function(test) { coux.post(testDb, newChannelDoc, function(err, ok) { chId = ok.id; test.ok(ok.id, "has an id"); console.log("chId", chId) test.end(); }); });
test('should update the document', function(test) { coux.waitForDoc(testDb, chId, 1, function(err, doc) { if (doc.state == "new") return true; if (doc.error) console.log("doc.error", doc.error) test.is(doc.state, "ready", "channel ready"); cloudDb = doc.cloud_database; test.end(); }); });
coux.del(db, function(err, ok) { if (err && err.error != "not_found") { console.log(err) } else { coux.put(db, e(function() { cb() })) } })
coux.put(testDb, e(function() { var control_ddoc = require('../lib/design/control'); coux.put(testDb.concat(control_ddoc._id), control_ddoc, function(err, ok) { if (err && err.error !== "conflict") { e()(err); } else { cb() } }) }));
test("with a new channel document without owner_id", function(test) { coux.post(testDb, { type: "channel", state: "new" }, function(err, ok) { chId = ok.id; test.ok(ok.id); test.end(); }); });
asyncFold(dbs, function(db, cb) { console.log("del", db) coux.del(db, function(err, ok) { if (err && err.error != "not_found") { console.log(err) } else { coux.put(db, e(function() { cb() })) } }) }, function() {
}, e(function() { var repdef = { continuous : CONTINUOUS, source : master, target : dbName }; if (FILTER) { repdef.filter = "filter/random"; repdef.query_params = {rand:Math.round(Math.random() * 100).toString()}; } coux.post(replicator, repdef, e(function() { cb() })); }))
exports._dependencies.getMeFromFB(pairingUserDoc.pairing_token, function(err, resp) { if (err) { pairingUserDoc.state = 'error'; pairingUserDoc.error = err; console.error("facebook error logged to session doc", err, pairingUserDoc._id); coux.put([config.host, config.users_db, pairingUserDoc._id], pairingUserDoc, e()); return; // the client has enough info to retry } function findOrCreateUserDoc() { console.log('findOrCreateUserDoc') // find or create a user that has this facebook_id and this app_id var userId = "sp_fb_"+resp.id+"_app_"+pairingUserDoc.pairing_app_id, userDocId = "org.couchdb.user:"******"user found", fb_user._id); } else { // make one fb_user = { _id : userDocId, fb_id : resp.id, app_id : pairingUserDoc.pairing_app_id, name : userId, full_name : resp.name, type : "user", state : "new", roles : [] }; console.log("making user: ", fb_user._id); } syncpointHelpers.activatePairingUser(pairingUserDoc, fb_user, config); }); } // kick off that long chain, if the if (resp.id && resp.name) { findOrCreateUserDoc(); } });
asyncFold(dbs2, function(db, cb) { var rpc = url.parse(db) , dbName = rpc.pathname.split('/')[1]; rpc.pathname = "/_replicate"; var replicator = url.format(rpc); coux.post(replicator, { continuous : CONTINUOUS, source : dbName, target : master }, e(function() { var repdef = { continuous : CONTINUOUS, source : master, target : dbName }; if (FILTER) { repdef.filter = "filter/random"; repdef.query_params = {rand:Math.round(Math.random() * 100).toString()}; } coux.post(replicator, repdef, e(function() { cb() })); })) }, function() {
}, function() { console.log("setting up replications"); // setup replication from devices <-> master var master = dbs[0] , dbs2 = dbs.slice(1) ; function triggerRepsAndGo() { asyncFold(dbs2, function(db, cb) { var rpc = url.parse(db) , dbName = rpc.pathname.split('/')[1]; rpc.pathname = "/_replicate"; var replicator = url.format(rpc); coux.post(replicator, { continuous : CONTINUOUS, source : dbName, target : master }, e(function() { var repdef = { continuous : CONTINUOUS, source : master, target : dbName }; if (FILTER) { repdef.filter = "filter/random"; repdef.query_params = {rand:Math.round(Math.random() * 100).toString()}; } coux.post(replicator, repdef, e(function() { cb() })); })) }, function() { console.log("replication is running, start the measurement") measure.start(dbs, function(notify) { console.log("measure is running, start the load: "+LOAD) load.start(notify, dbs2); }) }, 10); }; if (FILTER) { console.log("setting up filter fun"); var filterFun = 'fun(Doc, Req) -> GetFrom = fun(Key, {Plist}) -> proplists:get_value(Key, Plist, null) end, Rand = GetFrom(<<"rand">>, GetFrom(<<"query">>, Req)), case GetFrom(<<"rand">>, Doc) of Rand -> true; _ -> false end end.'; var ddoc = { language: "erlang", filters : { random : filterFun } } ; // var config = url.parse(master) // , dbName = config.pathname.split('/')[1]; // config.pathname = "/_config/native_query_servers/erlang"; // config = url.format(config); // coux.put(config,'{couch_native_process, start_link, []}') coux.put([master, "_design/filter"], ddoc, e(function(err, ok) { triggerRepsAndGo() })); } else { triggerRepsAndGo() } }, 5);