blob: 05e5c315d22262699e543ca03a7cabca8d2fd887 [file] [log] [blame]
Jake Farrellee4aaae2012-10-23 00:48:17 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
Cameron Martincaef0ed2025-01-15 11:58:39 +010019var thrift = require("thrift"),
20 ttransport = require("thrift/transport");
Roger Meier5c819c02011-04-09 11:10:04 +000021
Cameron Martincaef0ed2025-01-15 11:58:39 +010022var UserStorage = require("./gen-nodejs/UserStorage"),
23 ttypes = require("./gen-nodejs/user_types");
Roger Meier5c819c02011-04-09 11:10:04 +000024
Cameron Martincaef0ed2025-01-15 11:58:39 +010025var f_conn = thrift.createConnection("localhost", 9090), // default: framed
26 f_client = thrift.createClient(UserStorage, f_conn);
27var b_conn = thrift.createConnection("localhost", 9091, {
28 transport: ttransport.TBufferedTransport,
29 }),
30 b_client = thrift.createClient(UserStorage, b_conn);
31var user1 = new ttypes.UserProfile({
32 uid: 1,
33 name: "Mark Slee",
34 blurb: "I'll find something to put here.",
35});
36var user2 = new ttypes.UserProfile({
37 uid: 2,
38 name: "Satoshi Tagomori",
39 blurb: "ok, let's test with buffered transport.",
40});
Roger Meier5c819c02011-04-09 11:10:04 +000041
Cameron Martincaef0ed2025-01-15 11:58:39 +010042f_conn.on("error", function (err) {
Roger Meier5c819c02011-04-09 11:10:04 +000043 console.error("framed:", err);
44});
45
Cameron Martincaef0ed2025-01-15 11:58:39 +010046f_client.store(user1, function (err, response) {
47 if (err) {
48 console.error(err);
49 return;
50 }
Roger Meier5c819c02011-04-09 11:10:04 +000051
52 console.log("stored:", user1.uid, " as ", user1.name);
Cameron Martincaef0ed2025-01-15 11:58:39 +010053 b_client.retrieve(user1.uid, function (err, responseUser) {
54 if (err) {
55 console.error(err);
56 return;
57 }
Roger Meier5c819c02011-04-09 11:10:04 +000058 console.log("retrieved:", responseUser.uid, " as ", responseUser.name);
59 });
60});
61
Cameron Martincaef0ed2025-01-15 11:58:39 +010062b_client.store(user2, function (err, response) {
63 if (err) {
64 console.error(err);
65 return;
66 }
Roger Meier5c819c02011-04-09 11:10:04 +000067
68 console.log("stored:", user2.uid, " as ", user2.name);
Cameron Martincaef0ed2025-01-15 11:58:39 +010069 f_client.retrieve(user2.uid, function (err, responseUser) {
70 if (err) {
71 console.error(err);
72 return;
73 }
Roger Meier5c819c02011-04-09 11:10:04 +000074 console.log("retrieved:", responseUser.uid, " as ", responseUser.name);
75 });
76});