From c504e06c7dfb4105bbe7d57d421e36444b5db247 Mon Sep 17 00:00:00 2001 From: Qing Wang Date: Mon, 23 Sep 2013 10:22:45 -0400 Subject: [PATCH 1/2] =?UTF-8?q?driven=E5=87=BAurl=E4=B8=BA=E6=96=B0locatio?= =?UTF-8?q?n=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/business/locations-manager.ls | 8 +- src/web-monitor/web-monitor.ls | 5 +- ...est-create-a-new-ip-on-a-new-url-helper.ls | 7 +- ...results-of-create-a-new-ip-on-a-new-url.ls | 93 ++++++++++++------- ...orkflow-of-create-a-new-ip-on-a-new-url.ls | 52 +++++------ 5 files changed, 99 insertions(+), 66 deletions(-) diff --git a/src/business/locations-manager.ls b/src/business/locations-manager.ls index 6e9a9d6..6684953 100644 --- a/src/business/locations-manager.ls +++ b/src/business/locations-manager.ls @@ -47,7 +47,7 @@ get-old-or-create-new-location = !(url-data, callback)-> else current-time = new Date! (db) <-! database.get-db - (err, location) <-! db.at-plus.locations.insert { + (err, locations) <-! db.at-plus.locations.insert { type: 'web' name: url-data.name is-existing: true @@ -56,10 +56,10 @@ get-old-or-create-new-location = !(url-data, callback)-> from: current-time to: current-time urls: [url-data.url] - retrieved-html: new-web-page.retrieved-html + server-retrieved-html: new-web-page.retrieved-html } - place-web-page-snapshot new-web-page.snapshot, location._id - callback true, location + place-web-page-snapshot new-web-page.snapshot, locations[0]._id + callback true, locations[0] place-web-page-snapshot = !(snapshot, lid)-> debug "*************** place-web-page-snapshot 尚未实现 ***************" diff --git a/src/web-monitor/web-monitor.ls b/src/web-monitor/web-monitor.ls index 41b6662..9bf0c17 100644 --- a/src/web-monitor/web-monitor.ls +++ b/src/web-monitor/web-monitor.ls @@ -1,8 +1,9 @@ require! ['./database','./testing-helper-channel'.get-testing-control] find-location-for-url = !(url-data, callback)-> - debug "*************** find-location-for-url 尚未实现,现在是个mock,通过testing-helper频道控制 ***************" - if not get-testing-control!.locations-manager.get-old-or-create-new-location.is-new + can-find = not get-testing-control!.locations-manager.get-old-or-create-new-location.is-new + debug "*************** find-location-for-url 尚未实现,现在是个mock,通过testing-helper频道控制。能找到?#{can-find} ***************" + if can-find (db) <-! database.get-db (err, location) <-! db.at-plus.locations.find-one callback location, null diff --git a/test/helpers/test-create-a-new-ip-on-a-new-url-helper.ls b/test/helpers/test-create-a-new-ip-on-a-new-url-helper.ls index d31dcce..a4d10f3 100644 --- a/test/helpers/test-create-a-new-ip-on-a-new-url-helper.ls +++ b/test/helpers/test-create-a-new-ip-on-a-new-url-helper.ls @@ -13,7 +13,7 @@ open-client-with-testing-helper = !(is-url-new-location, callback)-> open-two-clients = !(is-url-new-location, done, callback)-> - (a-locations-channel, a-ip-channel, data) <-! open-client-with-testing-helper is-url-new-location = false + (a-locations-channel, a-ip-channel, data) <-! open-client-with-testing-helper is-url-new-location (b-locations-channel, b-ip-channel, data) <-! open-client-without-testing-helper done-waiter = new utils.All-done-waiter done callback {locations: a-locations-channel, ip: a-ip-channel}, {locations: b-locations-channel, ip: b-ip-channel}, done-waiter.add-waiting-function @@ -37,7 +37,12 @@ open-client = !(testing-helper-channel-config, callback)-> channels := cs debug "客户端初始化完毕" +fake-figure-out-location-internality = (url, server-retrieved-html)-> + # debug ' .... 真实的client会在这里将server-retrieved-html和自己打开的location(url)中的源码进行比较,确定是否一致。一致则是not internal,否则是internal ...' + true # 测试用true,激发服务器响应行为 + module.exports = open-client-without-testing-helper: open-client-without-testing-helper open-client-with-testing-helper: open-client-with-testing-helper open-two-clients: open-two-clients + fake-figure-out-location-internality: fake-figure-out-location-internality diff --git a/test/integrated/test-results-of-create-a-new-ip-on-a-new-url.ls b/test/integrated/test-results-of-create-a-new-ip-on-a-new-url.ls index 479457c..198d8c6 100644 --- a/test/integrated/test-results-of-create-a-new-ip-on-a-new-url.ls +++ b/test/integrated/test-results-of-create-a-new-ip-on-a-new-url.ls @@ -1,8 +1,8 @@ require! H: './test-create-a-new-ip-on-a-new-url-helper' +testing-data = total-locations-in-db = total-interestiong-points-in-db = null describe '测试在新URL上创建新兴趣点时,Locations Channel与Interesting Points Channel的协同', !-> describe '创建兴趣点后,客户端接收到正确的数据,服务端正确保存了兴趣点', !-> - testing-data = total-locations-in-db = total-interestiong-points-in-db = null before-each !-> count-locaitons-in-db !(amount)-> total-locations-in-db := amount count-interesting-points-in-db !(amount)-> total-interestiong-points-in-db := amount @@ -10,36 +10,13 @@ describe '测试在新URL上创建新兴趣点时,Locations Channel与Interest describe 'url为已有locatoin的alias时,消息内容正确,兴趣点正确保存', !-> can '创建者收到response-create-a-new-ip-on-a-new-url,之前在此页面的用户收到push-location-updated', !(done)-> - (creator, observer, wait) <-! H.open-two-clients is-url-new-location = false, done - creator.ip.on 'response-create-a-new-ip-on-a-new-url', wait !(data)-> - debug "创建者收到创建成功消息" - data.should.have.property 'lid' - data.should.have.property 'ipid' - data.result.should.eql 'success' - - done-waiter = wait! - <-! should-db-not-include-any-new-location total-locations-in-db - <-! should-new-location-url-added-as-alias testing-data.request-create-a-new-ip-on-a-new-url - <-! should-db-include-a-new-interesting-point total-interestiong-points-in-db - <-! should-db-include-the-requested-new-ip testing-data.request-create-a-new-ip-on-a-new-url - done-waiter! - - observer.locations.on 'push-location-updated', wait !(data)-> - debug "观察者收到location更新消息" - data.type.should.eql 'new-ip-added' - data.should.have.property '_id' - data.added-interesting-point.should.have.property '_id' - data.added-interesting-point.created-by.should.have.property '_id' - (utils.chop-off-id data).should.eql (utils.chop-off-id testing-data.push-location-updated) - - creator.locations.on 'push-location-updated', !(data)-> - should.fail "创建者收到了'push-location-updated'" - - observer.ip.on 'response-create-a-new-ip-on-a-new-url', !(data)-> - should.fail "观察者收到了'response-create-a-new-ip-on-a-new-url'" - - creator.ip.emit 'request-create-a-new-ip-on-a-new-url', testing-data.request-create-a-new-ip-on-a-new-url + should-creator-and-observer-recieved-correct-messages-AND-location-and-interesting-point-created \ + is-url-new-location = false, done + describe 'url为新location时,消息内容正确,兴趣点正确保存', !-> + can '创建者收到response-create-a-new-ip-on-a-new-url,之前在此页面的用户收到push-location-updated', !(done)-> + should-creator-and-observer-recieved-correct-messages-AND-location-and-interesting-point-created \ + is-url-new-location = true, done before-each !(done)-> <-! server.start @@ -59,20 +36,74 @@ prepare-testing-data = -> request-create-a-new-ip-on-a-new-url: utils.load-fixture 'request-create-a-new-ip-on-a-new-url' push-location-updated: utils.load-fixture 'push-location-updated' +should-creator-and-observer-recieved-correct-messages-AND-location-and-interesting-point-created = !(is-url-new-location, done)-> + request = testing-data.request-create-a-new-ip-on-a-new-url + (creator, observer, wait) <-! H.open-two-clients is-url-new-location, done + creator.ip.on 'response-create-a-new-ip-on-a-new-url', wait !(data)-> + debug "创建者收到创建成功消息" + data.should.have.property 'lid' + data.should.have.property 'ipid' + data.result.should.eql 'success' + + done-waiter = wait! + <-! (if is-url-new-location then should-db-in-clude-a-new-location else should-db-not-include-any-new-location) total-locations-in-db + <-! (if is-url-new-location then should-db-in-clude-the-new-location else should-url-added-as-location-alias) request + <-! should-db-include-a-new-interesting-point total-interestiong-points-in-db + <-! should-db-include-the-requested-new-ip request + done-waiter! + + if is-url-new-location + creator.locations.on 'ask-location-internality', wait !(data)-> + debug "创建者收到查询internality消息" + data.should.have.property 'lid' + data.should.have.property 'url', request.within-location.url + data.should.have.property 'serverRetrievedHtml' + + creator.locations.emit 'answer-location-internality', + {lid: data.lid, url: data.url, is-internal: H.fake-figure-out-location-internality!} + + observer.locations.on 'push-location-updated', wait !(data)-> + debug "观察者收到location更新消息" + data.type.should.eql 'new-ip-added' + data.should.have.property '_id' + data.added-interesting-point.should.have.property '_id' + data.added-interesting-point.created-by.should.have.property '_id' + (utils.chop-off-id data).should.eql (utils.chop-off-id testing-data.push-location-updated) + + creator.locations.on 'push-location-updated', !(data)-> + should.fail "创建者收到了'push-location-updated'" + + observer.ip.on 'response-create-a-new-ip-on-a-new-url', !(data)-> + should.fail "观察者收到了'response-create-a-new-ip-on-a-new-url'" + + creator.ip.emit 'request-create-a-new-ip-on-a-new-url', request + count-locaitons-in-db = !(callback)-> count-amount-of-docs-in-a-collection 'locations', callback count-interesting-points-in-db = !(callback)-> count-amount-of-docs-in-a-collection 'interesting-points', callback +should-db-in-clude-a-new-location = !(old-amount, callback)-> + (locations) <-! query-collection 'locations', {} + locations.length.should.eql old-amount + 1 + callback! + should-db-not-include-any-new-location = !(old-amount, callback)-> (locations) <-! query-collection 'locations', {} locations.length.should.eql old-amount callback! -should-new-location-url-added-as-alias = !(new-ip, callback)-> +should-db-in-clude-the-new-location = !(new-ip, callback)-> + (locations) <-! query-collection 'locations', {urls: new-ip.within-location.url} + locations.length.should.eql 1 + locations[0].urls.length.should.eql 1 # 新location只有这一个url + callback! + +should-url-added-as-location-alias = !(new-ip, callback)-> (locations) <-! query-collection 'locations', {urls: new-ip.within-location.url} locations.length.should.eql 1 + locations[0].urls.length.should.above 1 # 原有url,加上这个,超过1个 callback! diff --git a/test/integrated/test-workflow-of-create-a-new-ip-on-a-new-url.ls b/test/integrated/test-workflow-of-create-a-new-ip-on-a-new-url.ls index 933a7d2..f14106b 100644 --- a/test/integrated/test-workflow-of-create-a-new-ip-on-a-new-url.ls +++ b/test/integrated/test-workflow-of-create-a-new-ip-on-a-new-url.ls @@ -4,15 +4,18 @@ describe '创建的整个流程,有按照http://my.ss.sysu.edu.cn/wiki/pages/v debug ''' ************ 请注意,本测例需要人工观察,判断是否正确 ************** ''' - # can '提交创建请求后,按照设计,服务端各模块执行了流程(url被解析为已有location的alias)', !(done)-> - # H.open-client-with-testing-helper is-url-new-location = false, !(locations-channel, ip-channel, data)-> - # debug-output-client-request-and-response-steps locations-channel, ip-channel, done + can '提交创建请求后,按照设计,服务端各模块执行了流程(url被解析为已有location的alias)', !(done)-> + H.open-client-with-testing-helper is-url-new-location = false, !(locations-channel, ip-channel, data)-> + debug-output-client-request-and-response-steps locations-channel, ip-channel, done - # can '提交创建请求后,按照设计,服务端各模块执行了流程(url被解析为新location的情况)', !(done)-> - # H.open-client-with-testing-helper is-url-new-location = true, !(locations-channel, ip-channel, data)-> - # debug-output-client-request-and-response-steps locations-channel, ip-channel, done + can '提交创建请求后,按照设计,服务端各模块执行了流程(url被解析为新location的情况)', !(done)-> + H.open-client-with-testing-helper is-url-new-location = true, !(locations-channel, ip-channel, data)-> + debug-output-client-request-and-response-steps locations-channel, ip-channel, done describe '多人交互时,消息发送和接收正确', !-> + request-data = null + before-each !-> request-data := utils.load-fixture 'request-create-a-new-ip-on-a-new-url' + describe 'url为已有locatoin的alias时,消息次序正确', !-> can '创建者收到response-create-a-new-ip-on-a-new-url,之前在此页面的用户收到push-location-updated', !(done)-> (creator, observer, wait) <-! H.open-two-clients is-url-new-location = false, done @@ -22,24 +25,24 @@ describe '创建的整个流程,有按照http://my.ss.sysu.edu.cn/wiki/pages/v observer.locations.on 'push-location-updated', wait !(data)-> debug "观察者收到location更新消息" creator.locations.on 'push-location-updated', !(data)-> should.fail "创建者收到了'push-location-updated'" - creator.ip.emit 'request-create-a-new-ip-on-a-new-url', utils.load-fixture 'request-create-a-new-ip-on-a-new-url' + creator.ip.emit 'request-create-a-new-ip-on-a-new-url', request-data - # describe 'url为新的locatoin时,消息次序正确', !-> - # can '创建者收到response-create-a-new-ip-on-a-new-url,之前在此页面的用户收到push-location-updated', !(done)-> - # (creator, observer, wait) <-! H.open-two-clients is-url-new-location = true, done - # creator.ip.on 'response-create-a-new-ip-on-a-new-url', wait !(data)-> debug "创建者收到创建成功消息" - # observer.ip.on 'response-create-a-new-ip-on-a-new-url', !(data)-> should.fail "观察者收到了'response-create-a-new-ip-on-a-new-url'" + describe 'url为新的locatoin时,消息次序正确', !-> + can '创建者收到response-create-a-new-ip-on-a-new-url,之前在此页面的用户收到push-location-updated', !(done)-> + (creator, observer, wait) <-! H.open-two-clients is-url-new-location = true, done + creator.ip.on 'response-create-a-new-ip-on-a-new-url', wait !(data)-> debug "创建者收到创建成功消息" + observer.ip.on 'response-create-a-new-ip-on-a-new-url', !(data)-> should.fail "观察者收到了'response-create-a-new-ip-on-a-new-url'" - # observer.locations.on 'push-location-updated', wait !(data)-> debug "观察者收到location更新消息" - # creator.locations.on 'push-location-updated', !(data)-> should.fail "创建者收到了'push-location-updated'" + observer.locations.on 'push-location-updated', wait !(data)-> debug "观察者收到location更新消息" + creator.locations.on 'push-location-updated', !(data)-> should.fail "创建者收到了'push-location-updated'" - # creator.locations.on 'ask-location-internality', !(data)-> - # debug "创建者收到了查询location internality消息" - # creator.locations.emit 'answer-location-internality', is-internal: fake-figure-out-location-internality data.url, data.server-retrieved-html - # observer.locations.on 'ask-location-internality', !(data)-> - # should.fail "观察者收到了查询location internality消息" + creator.locations.on 'ask-location-internality', !(data)-> + debug "创建者收到了查询location internality消息" + creator.locations.emit 'answer-location-internality', is-internal: H.fake-figure-out-location-internality data.url, data.server-retrieved-html + observer.locations.on 'ask-location-internality', !(data)-> + should.fail "观察者收到了查询location internality消息" - # creator.ip.emit 'request-create-a-new-ip-on-a-new-url' + creator.ip.emit 'request-create-a-new-ip-on-a-new-url', request-data before-each !(done)-> <-! server.start @@ -58,7 +61,7 @@ debug-output-client-request-and-response-steps = !(locations-channel, ip-channel locations-channel.on 'ask-location-internality', !(data)-> debug "@+ Client: ======== locations-channel in 'ask-location-internality' ==========" debug "@+ Client: ======== locations-channel emit 'answer-location-internality' ==========" - locations-channel.emit 'answer-location-internality', is-internal: fake-figure-out-location-internality data.url, data.server-retrieved-html + locations-channel.emit 'answer-location-internality', is-internal: H.fake-figure-out-location-internality data.url, data.server-retrieved-html locations-channel.on 'push-location-updated', !(data)-> debug "@+ Client: ======== in 'push-location-updated' ==========, channel id: ", locations-channel.socket.sessionid @@ -69,10 +72,3 @@ debug-output-client-request-and-response-steps = !(locations-channel, ip-channel set-timeout (!-> done!), 300 # 等待所有通信完成。 debug "@+ Client: ======== ip-channelemit 'request-create-a-new-ip-on-a-new-url' ==========" ip-channel.emit 'request-create-a-new-ip-on-a-new-url', utils.load-fixture 'request-create-a-new-ip-on-a-new-url' - - -fake-figure-out-location-internality = (url, server-retrieved-html)-> - # debug ' .... 真实的client会在这里将server-retrieved-html和自己打开的location(url)中的源码进行比较,确定是否一致。一致则是not internal,否则是internal ...' - true # 测试用true,激发服务器响应行为 - - From 3ea1a46b6b8cc9ba905b08f3c117a7545fbc13c4 Mon Sep 17 00:00:00 2001 From: Qing Wang Date: Mon, 23 Sep 2013 10:27:04 -0400 Subject: [PATCH 2/2] =?UTF-8?q?driven=E5=87=BAurl=E4=B8=BA=E6=96=B0locatio?= =?UTF-8?q?n=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/business/interesting-points-manager.ls | 4 ---- src/business/messages-manager.ls | 2 -- 2 files changed, 6 deletions(-) diff --git a/src/business/interesting-points-manager.ls b/src/business/interesting-points-manager.ls index 32f5a77..7d570b0 100644 --- a/src/business/interesting-points-manager.ls +++ b/src/business/interesting-points-manager.ls @@ -40,14 +40,10 @@ create-interesting-point = !(location, interesting-point-data, callback)-> interesting-point = utils.clone interesting-point-data interesting-point.within-location.lid = location._id interesting-point.within-location.is-exist = true - # interesting-point.within-location.at-position = position-within-web-page: interesting-point.within-location.at-position - # delete interesting-point.within-location.at-position (db) <-! database.get-db (err, result) <-! db.at-plus['interesting-points'].insert interesting-point callback summarize interesting-point - - module.exports = get-interesting-points-summaries-map: get-interesting-points-summaries-map visit-uids-of-interesting-points-summaries-map: visit-uids-of-interesting-points-summaries-map diff --git a/src/business/messages-manager.ls b/src/business/messages-manager.ls index 19cad18..10a7819 100644 --- a/src/business/messages-manager.ls +++ b/src/business/messages-manager.ls @@ -3,9 +3,7 @@ _ = require 'underscore' get-recent-messages-map = !(ipids, callback)-> (db) <-! database.get-db - # cursor = db.at-plus.messages.find {ipid: "$in": ipids} (err, messages) <-! db.at-plus.messages.find {ipid: "$in": ipids} - # .limit config.locations-channel.amount-of-recent-messages-in-interesting-points .sort create-time: -1 .to-array callback create-brief-recent-messages-map messages