Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tobias Oberstein
committed
Apr 19, 2014
1 parent
f168dd5
commit 9830a6e
Showing
6 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// AutobahnJS - http://autobahn.ws, http://wamp.ws | ||
// | ||
// A JavaScript library for WAMP ("The Web Application Messaging Protocol"). | ||
// | ||
// Copyright (C) 2011-2014 Tavendo GmbH, http://tavendo.com | ||
// | ||
// Licensed under the MIT License. | ||
// http://www.opensource.org/licenses/mit-license.php | ||
// | ||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
var autobahn = require('./../index.js'); | ||
var testutil = require('./testutil.js'); | ||
|
||
|
||
exports.testPubsubComplex = function (testcase) { | ||
|
||
testcase.expect(1); | ||
|
||
var test = new testutil.Testlog("test/test_pubsub_complex.txt"); | ||
|
||
var dl = testutil.connect_n(2); | ||
|
||
autobahn.when.all(dl).then( | ||
function (res) { | ||
test.log("all sessions connected"); | ||
|
||
var session1 = res[0]; | ||
var session2 = res[1]; | ||
|
||
var counter = 0; | ||
|
||
var t1 = setInterval(function () { | ||
var lst = []; | ||
for (var i = 0; i < counter; ++i) { | ||
lst.push(i); | ||
} | ||
var obj = { | ||
'counter': counter, | ||
'foo': [1, counter, 2 * counter], | ||
'bar': 'This is a test text.', | ||
'baz': { | ||
'a': 1.23456, 'b': 10000, 'c': null, 'd': 'foo' | ||
} | ||
}; | ||
session1.publish('com.myapp.topic1', lst, obj); | ||
|
||
counter += 1; | ||
|
||
test.log("events published", counter); | ||
}, 1000); | ||
|
||
|
||
var received = 0; | ||
|
||
function on_topic1(args, kwargs) { | ||
test.log("got event:", args, kwargs); | ||
received += 1; | ||
if (received > 5) { | ||
test.log("closing .."); | ||
|
||
clearInterval(t1); | ||
|
||
session1.leave(); | ||
session2.leave(); | ||
|
||
var chk = test.check() | ||
testcase.ok(!chk, chk); | ||
testcase.done(); | ||
} | ||
} | ||
|
||
session2.subscribe('com.myapp.topic1', on_topic1); | ||
}, | ||
function (err) { | ||
test.log(err); | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
0 "all sessions connected" | ||
1 "events published" 1 | ||
2 "got event:" [] {"baz":{"a":1.23456,"c":null,"b":10000,"d":"foo"},"counter":0,"bar":"This is a test text.","foo":[1,0,0]} | ||
3 "events published" 2 | ||
4 "got event:" [0] {"baz":{"a":1.23456,"c":null,"b":10000,"d":"foo"},"counter":1,"bar":"This is a test text.","foo":[1,1,2]} | ||
5 "events published" 3 | ||
6 "got event:" [0,1] {"baz":{"a":1.23456,"c":null,"b":10000,"d":"foo"},"counter":2,"bar":"This is a test text.","foo":[1,2,4]} | ||
7 "events published" 4 | ||
8 "got event:" [0,1,2] {"baz":{"a":1.23456,"c":null,"b":10000,"d":"foo"},"counter":3,"bar":"This is a test text.","foo":[1,3,6]} | ||
9 "events published" 5 | ||
10 "got event:" [0,1,2,3] {"baz":{"a":1.23456,"c":null,"b":10000,"d":"foo"},"counter":4,"bar":"This is a test text.","foo":[1,4,8]} | ||
11 "events published" 6 | ||
12 "got event:" [0,1,2,3,4] {"baz":{"a":1.23456,"c":null,"b":10000,"d":"foo"},"counter":5,"bar":"This is a test text.","foo":[1,5,10]} | ||
13 "closing .." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// AutobahnJS - http://autobahn.ws, http://wamp.ws | ||
// | ||
// A JavaScript library for WAMP ("The Web Application Messaging Protocol"). | ||
// | ||
// Copyright (C) 2011-2014 Tavendo GmbH, http://tavendo.com | ||
// | ||
// Licensed under the MIT License. | ||
// http://www.opensource.org/licenses/mit-license.php | ||
// | ||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
var autobahn = require('./../index.js'); | ||
var testutil = require('./testutil.js'); | ||
|
||
|
||
exports.testPubsubOptions = function (testcase) { | ||
|
||
testcase.expect(1); | ||
|
||
var test = new testutil.Testlog("test/test_pubsub_options.txt"); | ||
|
||
var dl = testutil.connect_n(2); | ||
|
||
autobahn.when.all(dl).then( | ||
function (res) { | ||
test.log("all sessions connected"); | ||
|
||
var session1 = res[0]; | ||
var session2 = res[1]; | ||
|
||
var counter = 0; | ||
|
||
var t1 = setInterval(function () { | ||
var options = {acknowledge: true, disclose_me: true}; | ||
|
||
session1.publish('com.myapp.topic1', [counter], {}, options).then( | ||
function (pub) { | ||
test.log("event published", typeof(pub), typeof(pub.id)); | ||
} | ||
); | ||
counter += 1; | ||
}, 1000); | ||
|
||
var received = 0; | ||
|
||
var sub; | ||
|
||
function onevent1(args, kwargs, details) { | ||
test.log("got event:", typeof(details), typeof(details.publication), typeof(details.publisher), details.publisher == session1.id, args[0]); | ||
|
||
received += 1; | ||
if (received > 5) { | ||
test.log("Closing .."); | ||
|
||
clearInterval(t1); | ||
|
||
session1.leave(); | ||
session2.leave(); | ||
|
||
var chk = test.check() | ||
testcase.ok(!chk, chk); | ||
testcase.done(); | ||
} | ||
} | ||
|
||
sub = session2.subscribe('com.myapp.topic1', onevent1); | ||
}, | ||
function (err) { | ||
test.log(err); | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
0 "all sessions connected" | ||
1 "event published" "object" "number" | ||
2 "got event:" "object" "number" "number" true 0 | ||
3 "event published" "object" "number" | ||
4 "got event:" "object" "number" "number" true 1 | ||
5 "event published" "object" "number" | ||
6 "got event:" "object" "number" "number" true 2 | ||
7 "event published" "object" "number" | ||
8 "got event:" "object" "number" "number" true 3 | ||
9 "event published" "object" "number" | ||
10 "got event:" "object" "number" "number" true 4 | ||
11 "event published" "object" "number" | ||
12 "got event:" "object" "number" "number" true 5 | ||
13 "Closing .." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters