Skip to content

Instantly share code, notes, and snippets.

@tagomoris
Created April 8, 2011 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tagomoris/909351 to your computer and use it in GitHub Desktop.
Save tagomoris/909351 to your computer and use it in GitHub Desktop.
var thrift = require('thrift'),
ttransport = require('thrift/transport'),
ThriftHive = require('gen-nodejs/ThriftHive');
var connection1 = thrift.createConnection("localhost", 10000, {transport: ttransport.TBufferedTransport, timeout: 1*1000}),
client1 = thrift.createClient(ThriftHive, connection1);
var connection2 = thrift.createConnection("localhost", 10000, {transport: ttransport.TBufferedTransport, timeout: 1*1000}),
client2 = thrift.createClient(ThriftHive, connection2);
connection1.on('error', function(err){ console.error(err); });
connection2.on('error', function(err){ console.error(err); });
var query1 = 'select x, count(*) from p group by x';
var query2 = 'select x, count(*), "hoge" from p group by x';
var done1 = false;
var done2 = false;
var run_test = function(conn, client, query, label, callback) {
conn.addListener("connect", function(){
console.log(label, "connected.");
setTimeout(function(){
console.log(label, "executing.");
client.execute(query, function(err){
console.log(label, "executed.");
if (err){ console.error(label, "error on execute():", err); }
client.fetchAll(function(err, data){
console.log(label, "fetched.");
if (err){ console.error(label, "error on fetchAll():", err); }
console.log(label, "result:", data);
callback();
});
});
}, 2000);
});
};
run_test(connection1, client1, query1, "conn1:", function(){ done1 = true; });
run_test(connection2, client2, query2, "conn2:", function(){ done2 = true; });
setInterval(function(){
if (done1 && done2){
connection1.end();
connection2.end();
process.exit(0);
}
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment