blob: 5c9e109fbba92bc90bbc9d7922ecf753d118250a [file] [log] [blame]
Roger Meier5c819c02011-04-09 11:10:04 +00001var thrift = require('thrift'),
2 ttransport = require('thrift/transport');
3
4var UserStorage = require('./gen-nodejs/UserStorage'),
5 ttypes = require('./gen-nodejs/user_types');
6
7var f_conn = thrift.createConnection('localhost', 9090), // default: framed
8 f_client = thrift.createClient(UserStorage, f_conn);
9var b_conn = thrift.createConnection('localhost', 9091, {transport: ttransport.TBufferedTransport}),
10 b_client = thrift.createClient(UserStorage, b_conn);
11var user1 = new ttypes.UserProfile({uid: 1,
12 name: "Mark Slee",
13 blurb: "I'll find something to put here."});
14var user2 = new ttypes.UserProfile({uid: 2,
15 name: "Satoshi Tagomori",
16 blurb: "ok, let's test with buffered transport."});
17
18f_conn.on('error', function(err) {
19 console.error("framed:", err);
20});
21
22f_client.store(user1, function(err, response) {
23 if (err) { console.error(err); return; }
24
25 console.log("stored:", user1.uid, " as ", user1.name);
26 b_client.retrieve(user1.uid, function(err, responseUser) {
27 if (err) { console.error(err); return; }
28 console.log("retrieved:", responseUser.uid, " as ", responseUser.name);
29 });
30});
31
32b_client.store(user2, function(err, response) {
33 if (err) { console.error(err); return; }
34
35 console.log("stored:", user2.uid, " as ", user2.name);
36 f_client.retrieve(user2.uid, function(err, responseUser) {
37 if (err) { console.error(err); return; }
38 console.log("retrieved:", responseUser.uid, " as ", responseUser.name);
39 });
40});