thrift-client 0.1.0 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/thrift_client.rb +6 -5
  3. data/lib/thrift_client/abstract_thrift_client.rb +106 -69
  4. data/lib/thrift_client/pool.rb +34 -0
  5. data/lib/thrift_client/pool/fiber_connection_pool.rb +67 -0
  6. data/lib/thrift_client/pool/thread_connection_pool.rb +69 -0
  7. data/lib/thrift_client/{abstract_server.rb → server.rb} +62 -60
  8. data/lib/thrift_client/thrift/client.rb +15 -0
  9. data/lib/thrift_client/thrift/processor.rb +44 -0
  10. data/lib/thrift_client/{thrift.rb → thrift/protocol.rb} +1 -72
  11. data/lib/thrift_client/thrift/struct.rb +15 -0
  12. data/lib/thrift_client/thrift/transport.rb +208 -0
  13. data/test/em_test.rb +1 -0
  14. data/test/foobar/bar_service.rb +133 -0
  15. data/test/foobar/common_service.rb +388 -0
  16. data/test/foobar/foo_service.rb +133 -0
  17. data/test/{foobar_constants.rb → foobar/foobar_constants.rb} +3 -3
  18. data/test/{foobar_types.rb → foobar/foobar_types.rb} +12 -10
  19. data/test/foobar/handler.rb +74 -0
  20. data/test/helper.rb +50 -0
  21. data/test/passport.rb +51 -0
  22. data/test/start_server.rb +8 -0
  23. data/test/test.rb +27 -0
  24. data/test/test_client.rb +111 -0
  25. data/test/test_config.rb +54 -0
  26. data/test/test_connection_pool.rb +43 -0
  27. data/test/test_eventmachine_transprot.rb +146 -0
  28. data/test/test_multiplexed.rb +62 -0
  29. metadata +47 -24
  30. data/lib/thrift_client/multi_client_server.rb +0 -59
  31. data/lib/thrift_client/single_client_server.rb +0 -37
  32. data/test/client_test.rb +0 -172
  33. data/test/foobar_service.rb +0 -282
  34. data/test/multiplexed_protocol_test.rb +0 -60
  35. data/test/multiplexed_server.rb +0 -102
  36. data/test/server.rb +0 -97
@@ -1,60 +0,0 @@
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
- transport = Thrift::Socket.new('127.0.0.1', 9999)
16
- transport = Thrift::FramedTransport.new(transport)
17
- protocol = Thrift::BinaryProtocol.new(transport)
18
- # protocol = Thrift::MultiplexedProtocol.new(protocol,"foobar")
19
- @client = Foo::FoobarService::Client.new(protocol)
20
- transport.open
21
- puts "setup"
22
- end
23
-
24
- def test_multiprotocol
25
- puts "test start"
26
-
27
- @client.ping
28
-
29
-
30
- assert_nothing_raised do @client.ping
31
- end
32
-
33
- bar = @client.getBar
34
-
35
- assert_not_nil(bar)
36
- # puts bar.to_hash.class
37
- # hash_bar = bar.to_hash
38
- # puts hash_bar['first']
39
- # puts hash_bar['second']
40
- # puts hash_bar['third']
41
- # puts hash_bar['fourth']
42
-
43
- foo = Foo::Foo.new
44
- foo.first = 1
45
- foo.second = 2
46
- foo.third = 3.0
47
- foo.fourth = "4"
48
- assert(@client.putFoo(foo))
49
-
50
- assert_nothing_raised do @client.ping
51
- end
52
-
53
- puts "test stop"
54
- end
55
-
56
- def teardown
57
- super
58
- puts "teardown"
59
- end
60
- end
@@ -1,102 +0,0 @@
1
- $:.unshift File.expand_path("../../test", __FILE__)
2
- $:.unshift File.expand_path("../../lib", __FILE__)
3
- require 'thrift'
4
- require 'foobar_service'
5
- require 'foobar_types'
6
- require 'thrift_client'
7
-
8
- module Server
9
- include Thrift
10
-
11
- class FooHandler
12
-
13
- def ping
14
- puts "ping"
15
- end
16
-
17
- def getBar
18
- bar = Foo::Bar.new
19
- bar.fourth = "4"
20
- bar.third = 3.0
21
- bar.second = 2
22
- bar.first = 1
23
- return bar
24
- end
25
-
26
- def putFoo(foo)
27
- puts foo.inspect
28
- return true
29
- end
30
-
31
- def getTimeout
32
- sleep(2)
33
- return false
34
- end
35
-
36
- def getError()
37
- puts "error"
38
- raise ApplicationException.new("Exception")
39
- return true
40
- end
41
-
42
- end
43
-
44
- def self.start_server(host, port, serverClass)
45
- handler = FooHandler.new
46
- foo_processor = Foo::FoobarService::Processor.new(handler)
47
- # puts foo_processor.class.name.split("::")[-2].downcase.gsub("service","")
48
- # multi_processor = Thrift::MultiplexedProcessor.new
49
- # multi_processor.register(foo_processor.class.name.split("::")[-2].downcase.gsub("service",""), foo_processor)
50
- transport = ServerSocket.new(host, port)
51
- # transport = FramedTransport.new(transport)
52
- transport_factory = FramedTransportFactory.new
53
- args = [foo_processor, transport, transport_factory]
54
- if serverClass == NonblockingServer
55
- # logger = Logger.new(STDOUT)
56
- # logger.level = Logger::WARN
57
- # args << logger
58
- end
59
- server = serverClass.new(*args)
60
- @server_thread = Thread.new do
61
- server.serve
62
- end
63
- @server = server
64
- end
65
-
66
- def self.shutdown
67
- return if @server.nil?
68
- if @server.respond_to? :shutdown
69
- @server.shutdown
70
- else
71
- @server_thread.kill
72
- end
73
- end
74
- end
75
-
76
- def resolve_const(const)
77
- const and const.split('::').inject(Object) { |k,c| k.const_get(c) }
78
- end
79
-
80
- host = '127.0.0.1'
81
- port = ARGV[0] || 9999
82
-
83
- #serverklass = 'Thrift::SimpleServer'
84
- #serverklass = 'Thrift::ThreadedServer'
85
- serverklass = 'Thrift::ThreadPoolServer'
86
- # serverklass = 'Thrift::NonblockingServer'
87
-
88
- Server.start_server(host, port.to_i, resolve_const(serverklass))
89
- # let our host know that the interpreter has started
90
- # ideally we'd wait until the server was serving, but we don't have a hook for that
91
-
92
- puts "multiplexed server start on #{host}:#{port}"
93
- puts ""
94
-
95
- # STDOUT.flush
96
-
97
- Marshal.load(STDIN) # wait until we're instructed to shut down
98
-
99
- Server.shutdown
100
-
101
- puts "server shutdown"
102
-
@@ -1,97 +0,0 @@
1
- $:.unshift File.expand_path("../../test", __FILE__)
2
- require 'thrift'
3
- require 'foobar_service'
4
- require 'foobar_types'
5
-
6
- module Server
7
- include Thrift
8
-
9
- class FooHandler
10
-
11
- def ping
12
- puts "ping"
13
- end
14
-
15
- def getBar
16
- bar = Foo::Bar.new
17
- bar.fourth = "4"
18
- bar.third = 3.0
19
- bar.second = 2
20
- bar.first = 1
21
- return bar
22
- end
23
-
24
- def putFoo(foo)
25
- puts foo.inspect
26
- return true
27
- end
28
-
29
- def getTimeout
30
- sleep(2)
31
- return false
32
- end
33
-
34
- def getError()
35
- puts "error"
36
- raise ApplicationException.new("Exception")
37
- return true
38
- end
39
-
40
- end
41
-
42
- def self.start_server(host, port, serverClass)
43
- handler = FooHandler.new
44
- processor = Foo::FoobarService::Processor.new(handler)
45
- transport = ServerSocket.new(host, port)
46
- # transport = FramedTransport.new(transport)
47
- transport_factory = FramedTransportFactory.new
48
- args = [processor, transport, transport_factory]
49
- if serverClass == NonblockingServer
50
- # logger = Logger.new(STDOUT)
51
- # logger.level = Logger::WARN
52
- # args << logger
53
- end
54
- server = serverClass.new(*args)
55
- @server_thread = Thread.new do
56
- server.serve
57
- end
58
- @server = server
59
- end
60
-
61
- def self.shutdown
62
- return if @server.nil?
63
- if @server.respond_to? :shutdown
64
- @server.shutdown
65
- else
66
- @server_thread.kill
67
- end
68
- end
69
- end
70
-
71
- def resolve_const(const)
72
- const and const.split('::').inject(Object) { |k,c| k.const_get(c) }
73
- end
74
-
75
- host = '127.0.0.1'
76
- port = ARGV[0] || 9999
77
-
78
- #serverklass = 'Thrift::SimpleServer'
79
- #serverklass = 'Thrift::ThreadedServer'
80
- serverklass = 'Thrift::ThreadPoolServer'
81
- # serverklass = 'Thrift::NonblockingServer'
82
-
83
- Server.start_server(host, port.to_i, resolve_const(serverklass))
84
- # let our host know that the interpreter has started
85
- # ideally we'd wait until the server was serving, but we don't have a hook for that
86
-
87
- puts "server start on #{host}:#{port}"
88
- puts ""
89
-
90
- # STDOUT.flush
91
-
92
- Marshal.load(STDIN) # wait until we're instructed to shut down
93
-
94
- Server.shutdown
95
-
96
- puts "server shutdown"
97
-