Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Markedly improved unit tests. Added better exceptions. Added test for…

… real-life serialization using cut-down telescope struct.

backported tests.

Conflicts:

	lib/thrift/transport.js
  • Loading branch information...
commit 376b9291cdc3cfdb216506bb3f0a57e0938d2cbd 1 parent dba1a28
Ken wirehead authored
1  SConstruct
@@ -23,6 +23,7 @@ env["GENDIR"] = pjoin(cwd, 'test', 'generated')
23 23
24 24 THRIFT_TARGETS = {
25 25 'ThriftTest.thrift': [ 'js:node' ],
  26 + 'tel.thrift': [ 'js:node' ],
26 27 'mid.thrift': [ 'js:node' ]
27 28 }
28 29
1  lib/thrift/connection.js
@@ -137,6 +137,7 @@ exports.createConnection = function(host, port, options) {
137 137 }
138 138
139 139 exports.createClient = function(cls, connection) {
  140 +
140 141 if (cls.Client) {
141 142 cls = cls.Client;
142 143 }
17 test/ThriftTest-interface.js
@@ -374,4 +374,19 @@ exports['test_oneway'] = function (test, assert) {
374 374 }
375 375
376 376 client.testOneway(10);
377   -}
  377 +}
  378 +
  379 +exports['test_boguz'] = function(test, assert) {
  380 + test.skip();
  381 + var connection = thrift.createConnection('localhost', 9162),
  382 + client = thrift.createClient(ThriftTest, connection);
  383 +
  384 + var output = new client.pClass(client.output);
  385 + output.writeMessageBegin('store', thrift.Thrift.MessageType.CALL, 0);
  386 + output.writeStructBegin('ThriftTest_testVoid_args');
  387 + output.writeFieldStop();
  388 + output.writeStructEnd();
  389 + output.writeMessageEnd();
  390 + output.flush();
  391 +
  392 +}
34 test/generated/tel.thrift
... ... @@ -0,0 +1,34 @@
  1 +namespace cpp telescope.thrift
  2 +namespace java telescope.thrift
  3 +
  4 +
  5 +enum AlarmState {
  6 + OK = 1,
  7 + WARNING = 2,
  8 + CRITICAL = 6
  9 +}
  10 +
  11 +
  12 +struct Telescope
  13 +{
  14 + 1: string id,
  15 + 2: string checkId,
  16 + 3: string acctId,
  17 + 4: string checkModule,
  18 + 5: string entityId,
  19 + 6: string target,
  20 + 7: i64 timestamp,
  21 + 8: i32 consecutiveTrigger = 1,
  22 + 14: optional string dimensionKey;
  23 + 15: optional string collector;
  24 + 17: optional AlarmState criteriaState
  25 + 18: optional AlarmState computedState
  26 + 19: optional string alarmId
  27 + 20: optional byte availability
  28 + 21: optional byte state
  29 + 22: optional string status
  30 + 24: optional string monitoringZoneId
  31 + 25: optional string txnId
  32 + 26: optional string checkType
  33 + 27: optional AlarmState previousKnownState
  34 +}
36 test/protocol.js
... ... @@ -0,0 +1,36 @@
  1 +
  2 +var thrift = require('thrift');
  3 +var TMemoryBuffer = thrift.transport.TMemoryBuffer;
  4 +var TBinaryProtocol = thrift.protocol.TBinaryProtocol;
  5 +var Int64 = require('node-int64');
  6 +var async = require('async');
  7 +
  8 +var Telescope = require('./generated/gen-nodejs/tel_types').Telescope;
  9 +var AlarmState = require('./generated/gen-nodejs/tel_types').AlarmState;
  10 +
  11 +var binary = require('../lib/thrift/binary');
  12 +
  13 +
  14 +exports['test_binary_protocol'] = function(test, assert) {
  15 + var transport = new TMemoryBuffer(null, function(message) {
  16 + var input = new TBinaryProtocol(new TMemoryBuffer(message))
  17 + input.readStructBegin();
  18 + var ret = input.readFieldBegin();
  19 + assert.deepEqual(ret.fid, 1);
  20 + var str = input.readString();
  21 + assert.deepEqual('blah',str);
  22 + input.readFieldEnd();
  23 + ret = input.readFieldBegin();
  24 + assert.deepEqual(ret.ftype, thrift.Thrift.Type.STOP);
  25 + input.readStructEnd();
  26 + test.finish();
  27 + });
  28 + var output = new TBinaryProtocol(transport);
  29 + output.writeStructBegin('dummytel');
  30 + output.writeFieldBegin('id', thrift.Thrift.Type.STRING, 1);
  31 + output.writeString('blah');
  32 + output.writeFieldEnd();
  33 + output.writeFieldStop();
  34 + output.writeStructEnd();
  35 + output.flush();
  36 +};
36 test/tel.js
... ... @@ -0,0 +1,36 @@
  1 +
  2 +var thrift = require('thrift');
  3 +var TMemoryBuffer = thrift.transport.TMemoryBuffer;
  4 +var TBinaryProtocol = thrift.protocol.TBinaryProtocol;
  5 +var Int64 = require('node-int64');
  6 +var async = require('async');
  7 +
  8 +var Telescope = require('./generated/gen-nodejs/tel_types').Telescope;
  9 +var AlarmState = require('./generated/gen-nodejs/tel_types').AlarmState;
  10 +
  11 +var binary = require('../lib/thrift/binary');
  12 +
  13 +
  14 +exports['test_telescope_framed'] = function(test, assert) {
  15 + var telescope = new Telescope({
  16 + acctId: 'acOneTwo',
  17 + entityId: 'enOneTwo',
  18 + checkId: 'chOneTwo',
  19 + timestamp: new Int64(Date.now()),
  20 + computedState: AlarmState.WARNING,
  21 + alarmId: 'alOneTwo',
  22 + txnId: 'sometransaction',
  23 + });
  24 +
  25 + var transport = new TMemoryBuffer(null, function(message) {
  26 + var input = new TBinaryProtocol(new TMemoryBuffer(message)),
  27 + telescope2 = new Telescope();
  28 + telescope2.read(input);
  29 + assert.deepEqual(telescope,telescope2);
  30 + test.finish();
  31 + });
  32 + output = new TBinaryProtocol(transport);
  33 + telescope.write(output);
  34 + output.flush();
  35 +
  36 +};
50 test/transport.js
... ... @@ -0,0 +1,50 @@
  1 +
  2 +var thrift = require('thrift');
  3 +var TMemoryBuffer = thrift.transport.TMemoryBuffer;
  4 +var TBinaryProtocol = thrift.protocol.TBinaryProtocol;
  5 +var Int64 = require('node-int64');
  6 +var async = require('async');
  7 +
  8 +var Telescope = require('./generated/gen-nodejs/tel_types').Telescope;
  9 +var AlarmState = require('./generated/gen-nodejs/tel_types').AlarmState;
  10 +
  11 +var binary = require('../lib/thrift/binary');
  12 +
  13 +exports['test_binary_transport'] = function(test, assert) {
  14 + var transport = new TMemoryBuffer(null, function(message) {
  15 + var input = new TBinaryProtocol(new TMemoryBuffer(message))
  16 + assert.deepEqual(input.readByte(),1);
  17 + assert.deepEqual(input.readI16(),2490);
  18 + assert.deepEqual(input.readI32(),91199);
  19 + test.finish();
  20 + });
  21 + transport.write(new Buffer([1]));
  22 + transport.write(binary.writeI16(new Buffer(2), 2490));
  23 + transport.write(binary.writeI32(new Buffer(4), 91199));
  24 + transport.flush();
  25 +};
  26 +
  27 +
  28 +exports['test_binary_write'] = function(test, assert) {
  29 + var transport = new TMemoryBuffer(null, function(message) {
  30 + var input = new TMemoryBuffer(message);
  31 + var type = input.readByte();
  32 + var id = input.readI16();
  33 + assert.deepEqual(type,thrift.Thrift.Type.STRING);
  34 + assert.deepEqual(id,1);
  35 + var len = input.readI32();
  36 + var str = input.readString(len);
  37 + assert.deepEqual('blah',str);
  38 + type = input.readByte();
  39 + assert.deepEqual(type, thrift.Thrift.Type.STOP);
  40 + test.finish();
  41 + });
  42 + var output = new TBinaryProtocol(transport);
  43 + output.writeStructBegin('dummytel');
  44 + output.writeFieldBegin('id', thrift.Thrift.Type.STRING, 1);
  45 + output.writeString('blah');
  46 + output.writeFieldEnd();
  47 + output.writeFieldStop();
  48 + output.writeStructEnd();
  49 + output.flush();
  50 +};

0 comments on commit 376b929

Please sign in to comment.
Something went wrong with that request. Please try again.