hessian2 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -10
  3. data/README.md +197 -197
  4. data/hessian2.gemspec +0 -2
  5. data/lib/hessian2/client.rb +57 -50
  6. data/lib/hessian2/constants.rb +164 -164
  7. data/lib/hessian2/fault.rb +3 -3
  8. data/lib/hessian2/handler.rb +18 -18
  9. data/lib/hessian2/hessian_client.rb +3 -3
  10. data/lib/hessian2/parser.rb +619 -619
  11. data/lib/hessian2/type_wrapper.rb +49 -49
  12. data/lib/hessian2/version.rb +3 -3
  13. data/lib/hessian2/writer.rb +499 -499
  14. data/lib/hessian2.rb +14 -14
  15. data/spec/binary_spec.rb +51 -51
  16. data/spec/boolean_spec.rb +26 -26
  17. data/spec/class_wrapper_spec.rb +52 -52
  18. data/spec/create_monkeys.rb +14 -14
  19. data/spec/date_spec.rb +45 -45
  20. data/spec/double_spec.rb +78 -78
  21. data/spec/int_spec.rb +54 -54
  22. data/spec/list_spec.rb +66 -66
  23. data/spec/long_spec.rb +68 -68
  24. data/spec/map_spec.rb +36 -36
  25. data/spec/null_spec.rb +17 -17
  26. data/spec/object_spec.rb +78 -78
  27. data/spec/ref_spec.rb +43 -43
  28. data/spec/spec_helper.rb +23 -23
  29. data/spec/string_spec.rb +61 -61
  30. data/spec/struct_wrapper_spec.rb +47 -47
  31. data/spec/type_wrapper_spec.rb +102 -102
  32. data/test/app.rb +24 -24
  33. data/test/async/em_http_asleep.rb +25 -25
  34. data/test/async/em_http_sleep.rb +25 -25
  35. data/test/async/monkey.asleep.rb +27 -27
  36. data/test/async/mysql2_aquery.rb +37 -37
  37. data/test/fault/monkey.undefined_method.rb +5 -5
  38. data/test/fault/monkey.wrong_arguments.rb +5 -5
  39. data/test/fiber_concurrency/em_http_asleep.rb +17 -17
  40. data/test/fiber_concurrency/em_http_sleep.rb +17 -17
  41. data/test/fiber_concurrency/monkey.asleep.fiber_aware.rb +18 -18
  42. data/test/fiber_concurrency/mysql2_query.rb +29 -29
  43. data/test/fiber_concurrency/net_http_asleep.rb +19 -19
  44. data/test/fiber_concurrency/net_http_sleep.rb +19 -19
  45. data/test/fibered_rainbows/Gemfile +15 -15
  46. data/test/fibered_rainbows/config.ru +11 -11
  47. data/test/fibered_rainbows/rainbows.rb +13 -13
  48. data/test/monkey_service.rb +16 -16
  49. data/test/prepare.rb +7 -7
  50. data/test/thread_concurrency/active_record_execute.rb +29 -29
  51. data/test/thread_concurrency/monkey.asleep.rb +22 -22
  52. data/test/thread_concurrency/net_http_asleep.rb +24 -24
  53. data/test/thread_concurrency/net_http_sleep.rb +24 -24
  54. data/test/threaded_rainbows/Gemfile +13 -13
  55. data/test/threaded_rainbows/config.ru +9 -9
  56. data/test/threaded_rainbows/rainbows.rb +13 -13
  57. metadata +4 -74
@@ -1,25 +1,25 @@
1
- require File.expand_path('../../prepare', __FILE__)
2
- require 'eventmachine'
3
- require 'em-synchrony/em-http'
4
-
5
- EM.run do
6
- @number_of.times do |i|
7
- puts i
8
- http = EM::HttpRequest.new("http://127.0.0.1:8080/sleep").apost
9
- http.callback do |r|
10
- puts 'callback'
11
- @results << r.response
12
- EM.stop if @results.size >= @number_of
13
- end
14
-
15
- http.errback do |r|
16
- puts "errback #{r.error}"
17
- EM.stop
18
- end
19
- end
20
-
21
- puts "results.size #{@results.size}"
22
- end
23
-
24
- puts @results.inspect
25
- puts "results.size #{@results.size}"
1
+ require File.expand_path('../../prepare', __FILE__)
2
+ require 'eventmachine'
3
+ require 'em-synchrony/em-http'
4
+
5
+ EM.run do
6
+ @number_of.times do |i|
7
+ puts i
8
+ http = EM::HttpRequest.new("http://127.0.0.1:8080/sleep").apost
9
+ http.callback do |r|
10
+ puts 'callback'
11
+ @results << r.response
12
+ EM.stop if @results.size >= @number_of
13
+ end
14
+
15
+ http.errback do |r|
16
+ puts "errback #{r.error}"
17
+ EM.stop
18
+ end
19
+ end
20
+
21
+ puts "results.size #{@results.size}"
22
+ end
23
+
24
+ puts @results.inspect
25
+ puts "results.size #{@results.size}"
@@ -1,27 +1,27 @@
1
- require File.expand_path('../../prepare', __FILE__)
2
- require 'eventmachine'
3
-
4
- client = Hessian2::Client.new('http://127.0.0.1:8080/', async: true)
5
-
6
- EM.run do
7
- @number_of.times do |i|
8
- puts i
9
- http = client.asleep
10
- http.callback do |r|
11
- puts 'callback'
12
- @results << Hessian2.parse_rpc(r.response)
13
- EM.stop if @results.size >= @number_of
14
- end
15
-
16
- http.errback do |r|
17
- puts "errback #{r.error}"
18
- @results << nil
19
- EM.stop
20
- end
21
- end
22
-
23
- puts "results.size #{@results.size}"
24
- end
25
-
26
- puts @results.inspect
27
- puts "results.size #{@results.size}"
1
+ require File.expand_path('../../prepare', __FILE__)
2
+ require 'eventmachine'
3
+
4
+ client = Hessian2::Client.new('http://127.0.0.1:8080/', async: true)
5
+
6
+ EM.run do
7
+ @number_of.times do |i|
8
+ puts i
9
+ http = client.asleep
10
+ http.callback do |r|
11
+ puts 'callback'
12
+ @results << Hessian2.parse_rpc(r.response)
13
+ EM.stop if @results.size >= @number_of
14
+ end
15
+
16
+ http.errback do |r|
17
+ puts "errback #{r.error}"
18
+ @results << nil
19
+ EM.stop
20
+ end
21
+ end
22
+
23
+ puts "results.size #{@results.size}"
24
+ end
25
+
26
+ puts @results.inspect
27
+ puts "results.size #{@results.size}"
@@ -1,37 +1,37 @@
1
- require 'em-synchrony'
2
- require 'em-synchrony/mysql2'
3
- require 'em-synchrony/fiber_iterator'
4
- require 'yaml'
5
-
6
- options = YAML.load_file(File.expand_path('../../../spec/database.yml', __FILE__))
7
- puts options.inspect
8
-
9
- number_of = 10
10
- concurrency = 2
11
- connection_pool_size = 4
12
- results = []
13
-
14
- db = EM::Synchrony::ConnectionPool.new(size: connection_pool_size) do
15
- Mysql2::EM::Client.new(options)
16
- end
17
-
18
- EM.synchrony do
19
- EM::Synchrony::FiberIterator.new(0...number_of, concurrency).each do |i|
20
- puts i
21
- aquery = db.aquery('select sleep(1)')
22
- aquery.callback do |r|
23
- puts 'callback'
24
- results << r.first
25
- EM.stop if results.size >= number_of
26
- end
27
- end
28
-
29
- puts "results.size #{results.size}"
30
- end
31
-
32
- puts results.inspect
33
- puts "results.size #{results.size}"
34
-
35
- # time ruby test/async/mysql2_aquery.rb
36
- # 并发数 >= db连接池的场合,aquery要等空闲连接出来,耗时和query一样
37
- # 并发数 < db连接池的场合,aquery可以马上用空闲连接发起下一波查询,也就更早拿到callback,比query快
1
+ require 'em-synchrony'
2
+ require 'em-synchrony/mysql2'
3
+ require 'em-synchrony/fiber_iterator'
4
+ require 'yaml'
5
+
6
+ options = YAML.load_file(File.expand_path('../../../spec/database.yml', __FILE__))
7
+ puts options.inspect
8
+
9
+ number_of = 10
10
+ concurrency = 2
11
+ connection_pool_size = 4
12
+ results = []
13
+
14
+ db = EM::Synchrony::ConnectionPool.new(size: connection_pool_size) do
15
+ Mysql2::EM::Client.new(options)
16
+ end
17
+
18
+ EM.synchrony do
19
+ EM::Synchrony::FiberIterator.new(0...number_of, concurrency).each do |i|
20
+ puts i
21
+ aquery = db.aquery('select sleep(1)')
22
+ aquery.callback do |r|
23
+ puts 'callback'
24
+ results << r.first
25
+ EM.stop if results.size >= number_of
26
+ end
27
+ end
28
+
29
+ puts "results.size #{results.size}"
30
+ end
31
+
32
+ puts results.inspect
33
+ puts "results.size #{results.size}"
34
+
35
+ # time ruby test/async/mysql2_aquery.rb
36
+ # 并发数 >= db连接池的场合,aquery要等空闲连接出来,耗时和query一样
37
+ # 并发数 < db连接池的场合,aquery可以马上用空闲连接发起下一波查询,也就更早拿到callback,比query快
@@ -1,5 +1,5 @@
1
- require File.expand_path('../../prepare', __FILE__)
2
-
3
- client = Hessian2::Client.new('http://127.0.0.1:8080/')
4
-
5
- puts client.undefined_method
1
+ require File.expand_path('../../prepare', __FILE__)
2
+
3
+ client = Hessian2::Client.new('http://127.0.0.1:8080/')
4
+
5
+ puts client.undefined_method
@@ -1,5 +1,5 @@
1
- require File.expand_path('../../prepare', __FILE__)
2
-
3
- client = Hessian2::Client.new('http://127.0.0.1:8080/')
4
-
5
- puts client.sleep('wrong', 'arguments')
1
+ require File.expand_path('../../prepare', __FILE__)
2
+
3
+ client = Hessian2::Client.new('http://127.0.0.1:8080/')
4
+
5
+ puts client.sleep('wrong', 'arguments')
@@ -1,17 +1,17 @@
1
- require File.expand_path('../../prepare', __FILE__)
2
- require 'em-synchrony'
3
- require 'em-synchrony/em-http'
4
- require 'em-synchrony/fiber_iterator'
5
-
6
- EM.synchrony do
7
- EM::Synchrony::FiberIterator.new(0...@number_of, @concurrency).each do |i|
8
- puts i
9
- @results << EM::HttpRequest.new("http://127.0.0.1:8080/asleep").post.response
10
- end
11
-
12
- puts "results.size #{@results.size}"
13
- EM.stop
14
- end
15
-
16
- puts @results.inspect
17
- puts "results.size #{@results.size}"
1
+ require File.expand_path('../../prepare', __FILE__)
2
+ require 'em-synchrony'
3
+ require 'em-synchrony/em-http'
4
+ require 'em-synchrony/fiber_iterator'
5
+
6
+ EM.synchrony do
7
+ EM::Synchrony::FiberIterator.new(0...@number_of, @concurrency).each do |i|
8
+ puts i
9
+ @results << EM::HttpRequest.new("http://127.0.0.1:8080/asleep").post.response
10
+ end
11
+
12
+ puts "results.size #{@results.size}"
13
+ EM.stop
14
+ end
15
+
16
+ puts @results.inspect
17
+ puts "results.size #{@results.size}"
@@ -1,17 +1,17 @@
1
- require File.expand_path('../../prepare', __FILE__)
2
- require 'em-synchrony'
3
- require 'em-synchrony/em-http'
4
- require 'em-synchrony/fiber_iterator'
5
-
6
- EM.synchrony do
7
- EM::Synchrony::FiberIterator.new(0...@number_of, @concurrency).each do |i|
8
- puts i
9
- @results << EM::HttpRequest.new("http://127.0.0.1:8080/sleep").post.response
10
- end
11
-
12
- puts "results.size #{@results.size}"
13
- EM.stop
14
- end
15
-
16
- puts @results.inspect
17
- puts "results.size #{@results.size}"
1
+ require File.expand_path('../../prepare', __FILE__)
2
+ require 'em-synchrony'
3
+ require 'em-synchrony/em-http'
4
+ require 'em-synchrony/fiber_iterator'
5
+
6
+ EM.synchrony do
7
+ EM::Synchrony::FiberIterator.new(0...@number_of, @concurrency).each do |i|
8
+ puts i
9
+ @results << EM::HttpRequest.new("http://127.0.0.1:8080/sleep").post.response
10
+ end
11
+
12
+ puts "results.size #{@results.size}"
13
+ EM.stop
14
+ end
15
+
16
+ puts @results.inspect
17
+ puts "results.size #{@results.size}"
@@ -1,18 +1,18 @@
1
- require File.expand_path('../../prepare', __FILE__)
2
- require 'em-synchrony'
3
- require 'em-synchrony/fiber_iterator'
4
-
5
- client = Hessian2::Client.new('http://127.0.0.1:8080/', fiber_aware: true)
6
-
7
- EM.synchrony do
8
- EM::Synchrony::FiberIterator.new(0...@number_of, @concurrency).each do |i|
9
- puts i
10
- @results << client.asleep
11
- end
12
-
13
- puts "results.size #{@results.size}"
14
- EM.stop
15
- end
16
-
17
- puts @results.inspect
18
- puts "results.size #{@results.size}"
1
+ require File.expand_path('../../prepare', __FILE__)
2
+ require 'em-synchrony'
3
+ require 'em-synchrony/fiber_iterator'
4
+
5
+ client = Hessian2::Client.new('http://127.0.0.1:8080/', fiber_aware: true)
6
+
7
+ EM.synchrony do
8
+ EM::Synchrony::FiberIterator.new(0...@number_of, @concurrency).each do |i|
9
+ puts i
10
+ @results << client.asleep
11
+ end
12
+
13
+ puts "results.size #{@results.size}"
14
+ EM.stop
15
+ end
16
+
17
+ puts @results.inspect
18
+ puts "results.size #{@results.size}"
@@ -1,29 +1,29 @@
1
- require 'em-synchrony'
2
- require 'em-synchrony/mysql2'
3
- require 'em-synchrony/fiber_iterator'
4
- require 'yaml'
5
-
6
- options = YAML.load_file(File.expand_path('../../../spec/database.yml', __FILE__))
7
- puts options.inspect
8
-
9
- number_of = 10
10
- concurrency = 2
11
- connection_pool_size = 4
12
- results = []
13
-
14
- db = EM::Synchrony::ConnectionPool.new(size: connection_pool_size) do
15
- Mysql2::EM::Client.new(options)
16
- end
17
-
18
- EM.synchrony do
19
- EM::Synchrony::FiberIterator.new(0...number_of, concurrency).each do |i|
20
- puts i
21
- results << db.query('select sleep(1)').first
22
- end
23
-
24
- puts "results.size #{results.size}"
25
- EM.stop
26
- end
27
-
28
- puts results.inspect
29
- puts "results.size #{results.size}"
1
+ require 'em-synchrony'
2
+ require 'em-synchrony/mysql2'
3
+ require 'em-synchrony/fiber_iterator'
4
+ require 'yaml'
5
+
6
+ options = YAML.load_file(File.expand_path('../../../spec/database.yml', __FILE__))
7
+ puts options.inspect
8
+
9
+ number_of = 10
10
+ concurrency = 2
11
+ connection_pool_size = 4
12
+ results = []
13
+
14
+ db = EM::Synchrony::ConnectionPool.new(size: connection_pool_size) do
15
+ Mysql2::EM::Client.new(options)
16
+ end
17
+
18
+ EM.synchrony do
19
+ EM::Synchrony::FiberIterator.new(0...number_of, concurrency).each do |i|
20
+ puts i
21
+ results << db.query('select sleep(1)').first
22
+ end
23
+
24
+ puts "results.size #{results.size}"
25
+ EM.stop
26
+ end
27
+
28
+ puts results.inspect
29
+ puts "results.size #{results.size}"
@@ -1,19 +1,19 @@
1
- require File.expand_path('../../prepare', __FILE__)
2
- require 'em-synchrony'
3
- require 'em-synchrony/fiber_iterator'
4
- require 'net/http'
5
-
6
- EM.synchrony do
7
- EM::Synchrony::FiberIterator.new(0...@number_of, @concurrency).each do |i|
8
- puts i
9
- Net::HTTP.new('127.0.0.1', 8080).start do |http|
10
- @results << http.request(Net::HTTP::Post.new('/asleep')).body
11
- end
12
- end
13
-
14
- puts "results.size #{@results.size}"
15
- EM.stop
16
- end
17
-
18
- puts @results.inspect
19
- puts "results.size #{@results.size}"
1
+ require File.expand_path('../../prepare', __FILE__)
2
+ require 'em-synchrony'
3
+ require 'em-synchrony/fiber_iterator'
4
+ require 'net/http'
5
+
6
+ EM.synchrony do
7
+ EM::Synchrony::FiberIterator.new(0...@number_of, @concurrency).each do |i|
8
+ puts i
9
+ Net::HTTP.new('127.0.0.1', 8080).start do |http|
10
+ @results << http.request(Net::HTTP::Post.new('/asleep')).body
11
+ end
12
+ end
13
+
14
+ puts "results.size #{@results.size}"
15
+ EM.stop
16
+ end
17
+
18
+ puts @results.inspect
19
+ puts "results.size #{@results.size}"
@@ -1,19 +1,19 @@
1
- require File.expand_path('../../prepare', __FILE__)
2
- require 'em-synchrony'
3
- require 'em-synchrony/fiber_iterator'
4
- require 'net/http'
5
-
6
- EM.synchrony do
7
- EM::Synchrony::FiberIterator.new(0...@number_of, @concurrency).each do |i|
8
- puts i
9
- Net::HTTP.new('127.0.0.1', 8080).start do |http|
10
- @results << http.request(Net::HTTP::Post.new('/sleep')).body
11
- end
12
- end
13
-
14
- puts "results.size #{@results.size}"
15
- EM.stop
16
- end
17
-
18
- puts @results.inspect
19
- puts "results.size #{@results.size}"
1
+ require File.expand_path('../../prepare', __FILE__)
2
+ require 'em-synchrony'
3
+ require 'em-synchrony/fiber_iterator'
4
+ require 'net/http'
5
+
6
+ EM.synchrony do
7
+ EM::Synchrony::FiberIterator.new(0...@number_of, @concurrency).each do |i|
8
+ puts i
9
+ Net::HTTP.new('127.0.0.1', 8080).start do |http|
10
+ @results << http.request(Net::HTTP::Post.new('/sleep')).body
11
+ end
12
+ end
13
+
14
+ puts "results.size #{@results.size}"
15
+ EM.stop
16
+ end
17
+
18
+ puts @results.inspect
19
+ puts "results.size #{@results.size}"
@@ -1,15 +1,15 @@
1
- source "http://ruby.taobao.org"
2
-
3
- gem 'em-synchrony', require: ['em-synchrony']
4
-
5
- gem 'activerecord'
6
-
7
- gem 'bigdecimal'
8
-
9
- gem 'rack-fiber_pool'
10
-
11
- gem 'rainbows'
12
-
13
- gem 'sinatra'
14
-
15
- gem 'sinatra-contrib'
1
+ source "http://ruby.taobao.org"
2
+
3
+ gem 'em-synchrony', require: ['em-synchrony']
4
+
5
+ gem 'activerecord'
6
+
7
+ gem 'bigdecimal'
8
+
9
+ gem 'rack-fiber_pool'
10
+
11
+ gem 'rainbows'
12
+
13
+ gem 'sinatra'
14
+
15
+ gem 'sinatra-contrib'
@@ -1,11 +1,11 @@
1
- lib_path = File.expand_path('../../../lib', __FILE__)
2
- $:.unshift(lib_path)
3
-
4
- require 'hessian2'
5
- require 'bundler'
6
- Bundler.require
7
-
8
- use Rack::FiberPool
9
-
10
- require ::File.expand_path('../../app', __FILE__)
11
- run Sinatra::Application
1
+ lib_path = File.expand_path('../../../lib', __FILE__)
2
+ $:.unshift(lib_path)
3
+
4
+ require 'hessian2'
5
+ require 'bundler'
6
+ Bundler.require
7
+
8
+ use Rack::FiberPool
9
+
10
+ require ::File.expand_path('../../app', __FILE__)
11
+ run Sinatra::Application
@@ -1,13 +1,13 @@
1
- Rainbows! do
2
- use :EventMachine
3
- end
4
-
5
- worker_processes 1
6
-
7
- timeout 30
8
-
9
- pid '/tmp/monkey.pid'
10
-
11
- preload_app true
12
- GC.respond_to?(:copy_on_write_friendly=) and
13
- GC.copy_on_write_friendly = true
1
+ Rainbows! do
2
+ use :EventMachine
3
+ end
4
+
5
+ worker_processes 1
6
+
7
+ timeout 30
8
+
9
+ pid '/tmp/monkey.pid'
10
+
11
+ preload_app true
12
+ GC.respond_to?(:copy_on_write_friendly=) and
13
+ GC.copy_on_write_friendly = true
@@ -1,16 +1,16 @@
1
- class MonkeyService
2
- extend Hessian2::Handler
3
-
4
- def self.sleep(name = '')
5
- Kernel.sleep 1
6
-
7
- "wake #{name}"
8
- end
9
-
10
- def self.asleep(name = '')
11
- EM::Synchrony.sleep(1)
12
-
13
- "awake #{name}"
14
- end
15
-
16
- end
1
+ class MonkeyService
2
+ extend Hessian2::Handler
3
+
4
+ def self.sleep(name = '')
5
+ Kernel.sleep 1
6
+
7
+ "wake #{name}"
8
+ end
9
+
10
+ def self.asleep(name = '')
11
+ EM::Synchrony.sleep(1)
12
+
13
+ "awake #{name}"
14
+ end
15
+
16
+ end
data/test/prepare.rb CHANGED
@@ -1,7 +1,7 @@
1
- lib_path = File.expand_path('../../lib', __FILE__)
2
- $:.unshift(lib_path)
3
- require 'hessian2'
4
-
5
- @number_of = 10
6
- @concurrency = 2
7
- @results = []
1
+ lib_path = File.expand_path('../../lib', __FILE__)
2
+ $:.unshift(lib_path)
3
+ require 'hessian2'
4
+
5
+ @number_of = 10
6
+ @concurrency = 2
7
+ @results = []
@@ -1,29 +1,29 @@
1
- require 'active_record'
2
- require 'thread/pool'
3
- require 'yaml'
4
-
5
- options = YAML.load_file(File.expand_path('../../../spec/database.yml', __FILE__))
6
- puts options.inspect
7
-
8
- number_of = 10
9
- concurrency = 2
10
- connection_pool_size = 4
11
- results = []
12
-
13
- thread_pool = Thread.pool(concurrency)
14
- db = ActiveRecord::Base.establish_connection(options.merge('pool' => connection_pool_size))
15
-
16
- number_of.times do |i|
17
- thread_pool.process do
18
- puts i
19
- results << ActiveRecord::Base.connection_pool.with_connection do |conn|
20
- conn.execute('select sleep(1)').first
21
- end
22
- end
23
- end
24
-
25
- puts "results.size #{results.size}"
26
- thread_pool.shutdown
27
-
28
- puts results.inspect
29
- puts "results.size #{results.size}"
1
+ require 'active_record'
2
+ require 'thread/pool'
3
+ require 'yaml'
4
+
5
+ options = YAML.load_file(File.expand_path('../../../spec/database.yml', __FILE__))
6
+ puts options.inspect
7
+
8
+ number_of = 10
9
+ concurrency = 2
10
+ connection_pool_size = 4
11
+ results = []
12
+
13
+ thread_pool = Thread.pool(concurrency)
14
+ db = ActiveRecord::Base.establish_connection(options.merge('pool' => connection_pool_size))
15
+
16
+ number_of.times do |i|
17
+ thread_pool.process do
18
+ puts i
19
+ results << ActiveRecord::Base.connection_pool.with_connection do |conn|
20
+ conn.execute('select sleep(1)').first
21
+ end
22
+ end
23
+ end
24
+
25
+ puts "results.size #{results.size}"
26
+ thread_pool.shutdown
27
+
28
+ puts results.inspect
29
+ puts "results.size #{results.size}"