thrift-client 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,172 @@
1
+ $:.unshift File.expand_path("../../lib", __FILE__)
2
+ $:.unshift File.expand_path("../../test", __FILE__)
3
+
4
+ require "test/unit"
5
+ require "thrift_client"
6
+ require "foobar_service"
7
+ require 'foobar_types'
8
+ require 'thrift'
9
+ require 'yaml'
10
+
11
+ class ClientTest < Test::Unit::TestCase
12
+ include Test::Unit::Assertions
13
+ def setup
14
+ super
15
+ root = File.expand_path("../..", __FILE__)
16
+ @config = YAML.load_file(File.join(root, 'test/thrift_config.yaml'))
17
+ puts "setup"
18
+ end
19
+
20
+ def test_connection_close
21
+ puts "test_connection_close start"
22
+ client = ThriftClient.new(@config['thrift_test'])
23
+
24
+ assert_nothing_raised do client.ping
25
+ end
26
+
27
+ client.destroy
28
+
29
+ assert_nothing_raised do client.ping
30
+ end
31
+ bar = client.getBar
32
+ assert_not_nil(bar)
33
+
34
+ client.destroy
35
+
36
+ foo = Foo::Foo.new
37
+ foo.first = 1
38
+ foo.second = 2
39
+ foo.third = 3.0
40
+ foo.fourth = "4"
41
+ assert(client.putFoo(foo))
42
+
43
+ client.destroy
44
+
45
+ assert_nothing_raised do client.ping
46
+ end
47
+
48
+ puts "test_connection_close stop"
49
+ end
50
+
51
+ def test_application_error
52
+ client = ThriftClient.new(@config['thrift_test'])
53
+
54
+ client.ping
55
+ assert_raise do client.getError end
56
+
57
+ bar = client.getBar
58
+ assert_not_nil(bar)
59
+
60
+ foo = Foo::Foo.new
61
+ foo.first = 1
62
+ foo.second = 2
63
+ foo.third = 3.0
64
+ foo.fourth = "4"
65
+ assert(client.putFoo(foo))
66
+ end
67
+
68
+ def test_read_timeout
69
+ puts "test_read_timeout start"
70
+ client = ThriftClient.new(@config['thrift_test'])
71
+ assert_raise do client.getTimeout end
72
+
73
+ assert_nothing_raised do client.ping end
74
+
75
+ foo = Foo::Foo.new
76
+ foo.first = 1
77
+ foo.second = 2
78
+ foo.third = 3.0
79
+ foo.fourth = "4"
80
+ assert(client.putFoo(foo))
81
+
82
+ assert_nothing_raised do client.ping end
83
+ assert_nothing_raised do bar = client.getBar end
84
+ bar = client.getBar
85
+ assert_not_nil(bar)
86
+ puts "test_read_timeout stop"
87
+ end
88
+
89
+ def test_server_restart
90
+ puts "test_server_restart start"
91
+ client = ThriftClient.new(@config['thrift_test'])
92
+ client.ping
93
+
94
+ foo = Foo::Foo.new
95
+ foo.first = 1
96
+ foo.second = 2
97
+ foo.third = 3.0
98
+ foo.fourth = "4"
99
+ assert(client.putFoo(foo))
100
+ client.ping
101
+ puts "restart server!!!!!!!!!!"
102
+ sleep(5)
103
+ assert_raise do bar = client.getBar end
104
+ bar = client.getBar
105
+ assert_not_nil(bar)
106
+ puts "test_server_restart stop"
107
+ end
108
+
109
+ def test_server_graceful_restart
110
+ puts "test_server_graceful_restart start"
111
+
112
+ client = ThriftClient.new(@config['thrift_test'])
113
+ client.ping
114
+
115
+ foo = Foo::Foo.new
116
+ foo.first = 1
117
+ foo.second = 2
118
+ foo.third = 3.0
119
+ foo.fourth = "4"
120
+ assert(client.putFoo(foo))
121
+ client.ping
122
+ puts "restart server!!!!!!!!!!"
123
+ sleep(5)
124
+ assert_raise do bar = client.getBar end
125
+ bar = client.getBar
126
+ assert_not_nil(bar)
127
+
128
+ puts "test_server_graceful_restart stop"
129
+ end
130
+
131
+ def test_client_parameter_error
132
+ puts "test_client_parameter_error start"
133
+ client = ThriftClient.new(@config['thrift_test'])
134
+
135
+ foo = Foo::Foo.new
136
+ foo.first = 1
137
+ foo.second = "2"
138
+ foo.third = 3.0
139
+ foo.fourth = "4"
140
+ assert_raise do client.putFoo(foo) end
141
+
142
+ bar = client.getBar
143
+ assert_not_nil(bar)
144
+ puts "test_client_parameter_error stop"
145
+ end
146
+
147
+ def test_add_callback
148
+ puts "test_add_callback start"
149
+ client = ThriftClient.new(@config['thrift_test'])
150
+
151
+ client.add_callback(:before_method) { |method_name|
152
+ puts "call method #{method_name}"
153
+ }
154
+
155
+ foo = Foo::Foo.new
156
+ foo.first = 1
157
+ foo.second = "2"
158
+ foo.third = 3.0
159
+ foo.fourth = "4"
160
+ assert_raise do client.putFoo(foo) end
161
+
162
+ bar = client.getBar
163
+ assert_not_nil(bar)
164
+
165
+ puts "test_add_callback stop"
166
+ end
167
+
168
+ def teardown
169
+ super
170
+ puts "teardown"
171
+ end
172
+ end
@@ -0,0 +1,11 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.9.0)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift'
8
+ require 'foobar_types'
9
+
10
+ module Foo
11
+ end
@@ -0,0 +1,282 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.9.0)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift'
8
+ require 'foobar_types'
9
+
10
+ module Foo
11
+ module FoobarService
12
+ class Client
13
+ include ::Thrift::Client
14
+
15
+ def ping()
16
+ send_ping()
17
+ end
18
+
19
+ def send_ping()
20
+ send_message('ping', Ping_args)
21
+ end
22
+ def getBar()
23
+ send_getBar()
24
+ return recv_getBar()
25
+ end
26
+
27
+ def send_getBar()
28
+ send_message('getBar', GetBar_args)
29
+ end
30
+
31
+ def recv_getBar()
32
+ result = receive_message(GetBar_result)
33
+ return result.success unless result.success.nil?
34
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'getBar failed: unknown result')
35
+ end
36
+
37
+ def putFoo(foo)
38
+ send_putFoo(foo)
39
+ return recv_putFoo()
40
+ end
41
+
42
+ def send_putFoo(foo)
43
+ send_message('putFoo', PutFoo_args, :foo => foo)
44
+ end
45
+
46
+ def recv_putFoo()
47
+ result = receive_message(PutFoo_result)
48
+ return result.success unless result.success.nil?
49
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'putFoo failed: unknown result')
50
+ end
51
+
52
+ def getTimeout()
53
+ send_getTimeout()
54
+ return recv_getTimeout()
55
+ end
56
+
57
+ def send_getTimeout()
58
+ send_message('getTimeout', GetTimeout_args)
59
+ end
60
+
61
+ def recv_getTimeout()
62
+ result = receive_message(GetTimeout_result)
63
+ return result.success unless result.success.nil?
64
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'getTimeout failed: unknown result')
65
+ end
66
+
67
+ def getError()
68
+ send_getError()
69
+ return recv_getError()
70
+ end
71
+
72
+ def send_getError()
73
+ send_message('getError', GetError_args)
74
+ end
75
+
76
+ def recv_getError()
77
+ result = receive_message(GetError_result)
78
+ return result.success unless result.success.nil?
79
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'getError failed: unknown result')
80
+ end
81
+
82
+ end
83
+
84
+ class Processor
85
+ include ::Thrift::Processor
86
+
87
+ def process_ping(seqid, iprot, oprot)
88
+ args = read_args(iprot, Ping_args)
89
+ @handler.ping()
90
+ return
91
+ end
92
+
93
+ def process_getBar(seqid, iprot, oprot)
94
+ args = read_args(iprot, GetBar_args)
95
+ result = GetBar_result.new()
96
+ result.success = @handler.getBar()
97
+ write_result(result, oprot, 'getBar', seqid)
98
+ end
99
+
100
+ def process_putFoo(seqid, iprot, oprot)
101
+ args = read_args(iprot, PutFoo_args)
102
+ result = PutFoo_result.new()
103
+ result.success = @handler.putFoo(args.foo)
104
+ write_result(result, oprot, 'putFoo', seqid)
105
+ end
106
+
107
+ def process_getTimeout(seqid, iprot, oprot)
108
+ args = read_args(iprot, GetTimeout_args)
109
+ result = GetTimeout_result.new()
110
+ result.success = @handler.getTimeout()
111
+ write_result(result, oprot, 'getTimeout', seqid)
112
+ end
113
+
114
+ def process_getError(seqid, iprot, oprot)
115
+ args = read_args(iprot, GetError_args)
116
+ result = GetError_result.new()
117
+ result.success = @handler.getError()
118
+ write_result(result, oprot, 'getError', seqid)
119
+ end
120
+
121
+ end
122
+
123
+ # HELPER FUNCTIONS AND STRUCTURES
124
+
125
+ class Ping_args
126
+ include ::Thrift::Struct, ::Thrift::Struct_Union
127
+
128
+ FIELDS = {
129
+
130
+ }
131
+
132
+ def struct_fields; FIELDS; end
133
+
134
+ def validate
135
+ end
136
+
137
+ ::Thrift::Struct.generate_accessors self
138
+ end
139
+
140
+ class Ping_result
141
+ include ::Thrift::Struct, ::Thrift::Struct_Union
142
+
143
+ FIELDS = {
144
+
145
+ }
146
+
147
+ def struct_fields; FIELDS; end
148
+
149
+ def validate
150
+ end
151
+
152
+ ::Thrift::Struct.generate_accessors self
153
+ end
154
+
155
+ class GetBar_args
156
+ include ::Thrift::Struct, ::Thrift::Struct_Union
157
+
158
+ FIELDS = {
159
+
160
+ }
161
+
162
+ def struct_fields; FIELDS; end
163
+
164
+ def validate
165
+ end
166
+
167
+ ::Thrift::Struct.generate_accessors self
168
+ end
169
+
170
+ class GetBar_result
171
+ include ::Thrift::Struct, ::Thrift::Struct_Union
172
+ SUCCESS = 0
173
+
174
+ FIELDS = {
175
+ SUCCESS => {:type => ::Thrift::Types::STRUCT, :name => 'success', :class => ::Foo::Bar}
176
+ }
177
+
178
+ def struct_fields; FIELDS; end
179
+
180
+ def validate
181
+ end
182
+
183
+ ::Thrift::Struct.generate_accessors self
184
+ end
185
+
186
+ class PutFoo_args
187
+ include ::Thrift::Struct, ::Thrift::Struct_Union
188
+ FOO = 1
189
+
190
+ FIELDS = {
191
+ FOO => {:type => ::Thrift::Types::STRUCT, :name => 'foo', :class => ::Foo::Foo}
192
+ }
193
+
194
+ def struct_fields; FIELDS; end
195
+
196
+ def validate
197
+ end
198
+
199
+ ::Thrift::Struct.generate_accessors self
200
+ end
201
+
202
+ class PutFoo_result
203
+ include ::Thrift::Struct, ::Thrift::Struct_Union
204
+ SUCCESS = 0
205
+
206
+ FIELDS = {
207
+ SUCCESS => {:type => ::Thrift::Types::BOOL, :name => 'success'}
208
+ }
209
+
210
+ def struct_fields; FIELDS; end
211
+
212
+ def validate
213
+ end
214
+
215
+ ::Thrift::Struct.generate_accessors self
216
+ end
217
+
218
+ class GetTimeout_args
219
+ include ::Thrift::Struct, ::Thrift::Struct_Union
220
+
221
+ FIELDS = {
222
+
223
+ }
224
+
225
+ def struct_fields; FIELDS; end
226
+
227
+ def validate
228
+ end
229
+
230
+ ::Thrift::Struct.generate_accessors self
231
+ end
232
+
233
+ class GetTimeout_result
234
+ include ::Thrift::Struct, ::Thrift::Struct_Union
235
+ SUCCESS = 0
236
+
237
+ FIELDS = {
238
+ SUCCESS => {:type => ::Thrift::Types::BOOL, :name => 'success'}
239
+ }
240
+
241
+ def struct_fields; FIELDS; end
242
+
243
+ def validate
244
+ end
245
+
246
+ ::Thrift::Struct.generate_accessors self
247
+ end
248
+
249
+ class GetError_args
250
+ include ::Thrift::Struct, ::Thrift::Struct_Union
251
+
252
+ FIELDS = {
253
+
254
+ }
255
+
256
+ def struct_fields; FIELDS; end
257
+
258
+ def validate
259
+ end
260
+
261
+ ::Thrift::Struct.generate_accessors self
262
+ end
263
+
264
+ class GetError_result
265
+ include ::Thrift::Struct, ::Thrift::Struct_Union
266
+ SUCCESS = 0
267
+
268
+ FIELDS = {
269
+ SUCCESS => {:type => ::Thrift::Types::BOOL, :name => 'success'}
270
+ }
271
+
272
+ def struct_fields; FIELDS; end
273
+
274
+ def validate
275
+ end
276
+
277
+ ::Thrift::Struct.generate_accessors self
278
+ end
279
+
280
+ end
281
+
282
+ end