Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
View
@@ -23,6 +23,7 @@ env["GENDIR"] = pjoin(cwd, 'test', 'generated')
THRIFT_TARGETS = {
'ThriftTest.thrift': [ 'js:node' ],
+ 'tel.thrift': [ 'js:node' ],
'mid.thrift': [ 'js:node' ]
}
1  lib/thrift/connection.js
View
@@ -137,6 +137,7 @@ exports.createConnection = function(host, port, options) {
}
exports.createClient = function(cls, connection) {
+
if (cls.Client) {
cls = cls.Client;
}
17 test/ThriftTest-interface.js
View
@@ -374,4 +374,19 @@ exports['test_oneway'] = function (test, assert) {
}
client.testOneway(10);
-}
+}
+
+exports['test_boguz'] = function(test, assert) {
+ test.skip();
+ var connection = thrift.createConnection('localhost', 9162),
+ client = thrift.createClient(ThriftTest, connection);
+
+ var output = new client.pClass(client.output);
+ output.writeMessageBegin('store', thrift.Thrift.MessageType.CALL, 0);
+ output.writeStructBegin('ThriftTest_testVoid_args');
+ output.writeFieldStop();
+ output.writeStructEnd();
+ output.writeMessageEnd();
+ output.flush();
+
+}
34 test/generated/tel.thrift
View
@@ -0,0 +1,34 @@
+namespace cpp telescope.thrift
+namespace java telescope.thrift
+
+
+enum AlarmState {
+ OK = 1,
+ WARNING = 2,
+ CRITICAL = 6
+}
+
+
+struct Telescope
+{
+ 1: string id,
+ 2: string checkId,
+ 3: string acctId,
+ 4: string checkModule,
+ 5: string entityId,
+ 6: string target,
+ 7: i64 timestamp,
+ 8: i32 consecutiveTrigger = 1,
+ 14: optional string dimensionKey;
+ 15: optional string collector;
+ 17: optional AlarmState criteriaState
+ 18: optional AlarmState computedState
+ 19: optional string alarmId
+ 20: optional byte availability
+ 21: optional byte state
+ 22: optional string status
+ 24: optional string monitoringZoneId
+ 25: optional string txnId
+ 26: optional string checkType
+ 27: optional AlarmState previousKnownState
+}
36 test/protocol.js
View
@@ -0,0 +1,36 @@
+
+var thrift = require('thrift');
+var TMemoryBuffer = thrift.transport.TMemoryBuffer;
+var TBinaryProtocol = thrift.protocol.TBinaryProtocol;
+var Int64 = require('node-int64');
+var async = require('async');
+
+var Telescope = require('./generated/gen-nodejs/tel_types').Telescope;
+var AlarmState = require('./generated/gen-nodejs/tel_types').AlarmState;
+
+var binary = require('../lib/thrift/binary');
+
+
+exports['test_binary_protocol'] = function(test, assert) {
+ var transport = new TMemoryBuffer(null, function(message) {
+ var input = new TBinaryProtocol(new TMemoryBuffer(message))
+ input.readStructBegin();
+ var ret = input.readFieldBegin();
+ assert.deepEqual(ret.fid, 1);
+ var str = input.readString();
+ assert.deepEqual('blah',str);
+ input.readFieldEnd();
+ ret = input.readFieldBegin();
+ assert.deepEqual(ret.ftype, thrift.Thrift.Type.STOP);
+ input.readStructEnd();
+ test.finish();
+ });
+ var output = new TBinaryProtocol(transport);
+ output.writeStructBegin('dummytel');
+ output.writeFieldBegin('id', thrift.Thrift.Type.STRING, 1);
+ output.writeString('blah');
+ output.writeFieldEnd();
+ output.writeFieldStop();
+ output.writeStructEnd();
+ output.flush();
+};
36 test/tel.js
View
@@ -0,0 +1,36 @@
+
+var thrift = require('thrift');
+var TMemoryBuffer = thrift.transport.TMemoryBuffer;
+var TBinaryProtocol = thrift.protocol.TBinaryProtocol;
+var Int64 = require('node-int64');
+var async = require('async');
+
+var Telescope = require('./generated/gen-nodejs/tel_types').Telescope;
+var AlarmState = require('./generated/gen-nodejs/tel_types').AlarmState;
+
+var binary = require('../lib/thrift/binary');
+
+
+exports['test_telescope_framed'] = function(test, assert) {
+ var telescope = new Telescope({
+ acctId: 'acOneTwo',
+ entityId: 'enOneTwo',
+ checkId: 'chOneTwo',
+ timestamp: new Int64(Date.now()),
+ computedState: AlarmState.WARNING,
+ alarmId: 'alOneTwo',
+ txnId: 'sometransaction',
+ });
+
+ var transport = new TMemoryBuffer(null, function(message) {
+ var input = new TBinaryProtocol(new TMemoryBuffer(message)),
+ telescope2 = new Telescope();
+ telescope2.read(input);
+ assert.deepEqual(telescope,telescope2);
+ test.finish();
+ });
+ output = new TBinaryProtocol(transport);
+ telescope.write(output);
+ output.flush();
+
+};
50 test/transport.js
View
@@ -0,0 +1,50 @@
+
+var thrift = require('thrift');
+var TMemoryBuffer = thrift.transport.TMemoryBuffer;
+var TBinaryProtocol = thrift.protocol.TBinaryProtocol;
+var Int64 = require('node-int64');
+var async = require('async');
+
+var Telescope = require('./generated/gen-nodejs/tel_types').Telescope;
+var AlarmState = require('./generated/gen-nodejs/tel_types').AlarmState;
+
+var binary = require('../lib/thrift/binary');
+
+exports['test_binary_transport'] = function(test, assert) {
+ var transport = new TMemoryBuffer(null, function(message) {
+ var input = new TBinaryProtocol(new TMemoryBuffer(message))
+ assert.deepEqual(input.readByte(),1);
+ assert.deepEqual(input.readI16(),2490);
+ assert.deepEqual(input.readI32(),91199);
+ test.finish();
+ });
+ transport.write(new Buffer([1]));
+ transport.write(binary.writeI16(new Buffer(2), 2490));
+ transport.write(binary.writeI32(new Buffer(4), 91199));
+ transport.flush();
+};
+
+
+exports['test_binary_write'] = function(test, assert) {
+ var transport = new TMemoryBuffer(null, function(message) {
+ var input = new TMemoryBuffer(message);
+ var type = input.readByte();
+ var id = input.readI16();
+ assert.deepEqual(type,thrift.Thrift.Type.STRING);
+ assert.deepEqual(id,1);
+ var len = input.readI32();
+ var str = input.readString(len);
+ assert.deepEqual('blah',str);
+ type = input.readByte();
+ assert.deepEqual(type, thrift.Thrift.Type.STOP);
+ test.finish();
+ });
+ var output = new TBinaryProtocol(transport);
+ output.writeStructBegin('dummytel');
+ output.writeFieldBegin('id', thrift.Thrift.Type.STRING, 1);
+ output.writeString('blah');
+ output.writeFieldEnd();
+ output.writeFieldStop();
+ output.writeStructEnd();
+ output.flush();
+};
Please sign in to comment.
Something went wrong with that request. Please try again.