hessian2 2.0.5 → 2.0.6

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -10
  3. data/README.md +203 -199
  4. data/lib/hessian2.rb +14 -14
  5. data/lib/hessian2/client.rb +57 -57
  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 +506 -504
  14. data/spec/binary_spec.rb +51 -51
  15. data/spec/boolean_spec.rb +26 -26
  16. data/spec/class_wrapper_spec.rb +52 -52
  17. data/spec/create_monkeys.rb +14 -14
  18. data/spec/date_spec.rb +45 -45
  19. data/spec/double_spec.rb +78 -78
  20. data/spec/int_spec.rb +54 -54
  21. data/spec/list_spec.rb +66 -66
  22. data/spec/long_spec.rb +68 -68
  23. data/spec/map_spec.rb +36 -36
  24. data/spec/null_spec.rb +17 -17
  25. data/spec/object_spec.rb +78 -78
  26. data/spec/ref_spec.rb +43 -43
  27. data/spec/spec_helper.rb +23 -23
  28. data/spec/string_spec.rb +61 -61
  29. data/spec/struct_wrapper_spec.rb +47 -47
  30. data/spec/type_wrapper_spec.rb +102 -102
  31. data/test/app.rb +24 -24
  32. data/test/async/em_http_asleep.rb +25 -25
  33. data/test/async/em_http_sleep.rb +25 -25
  34. data/test/async/monkey.asleep.rb +27 -27
  35. data/test/async/mysql2_aquery.rb +37 -37
  36. data/test/fault/monkey.undefined_method.rb +5 -5
  37. data/test/fault/monkey.wrong_arguments.rb +5 -5
  38. data/test/fiber_concurrency/em_http_asleep.rb +17 -17
  39. data/test/fiber_concurrency/em_http_sleep.rb +17 -17
  40. data/test/fiber_concurrency/monkey.asleep.fiber_aware.rb +18 -18
  41. data/test/fiber_concurrency/mysql2_query.rb +29 -29
  42. data/test/fiber_concurrency/net_http_asleep.rb +19 -19
  43. data/test/fiber_concurrency/net_http_sleep.rb +19 -19
  44. data/test/fibered_rainbows/Gemfile +15 -15
  45. data/test/fibered_rainbows/config.ru +11 -11
  46. data/test/fibered_rainbows/rainbows.rb +13 -13
  47. data/test/monkey_service.rb +16 -16
  48. data/test/prepare.rb +7 -7
  49. data/test/thread_concurrency/active_record_execute.rb +29 -29
  50. data/test/thread_concurrency/monkey.asleep.rb +22 -22
  51. data/test/thread_concurrency/net_http_asleep.rb +24 -24
  52. data/test/thread_concurrency/net_http_sleep.rb +24 -24
  53. data/test/threaded_rainbows/Gemfile +13 -13
  54. data/test/threaded_rainbows/config.ru +9 -9
  55. data/test/threaded_rainbows/rainbows.rb +13 -13
  56. metadata +46 -4
@@ -1,102 +1,102 @@
1
- require File.expand_path('../spec_helper', __FILE__)
2
-
3
- module Hessian2
4
- describe TypeWrapper do
5
- hash = { id: nil, born_at: Time.new(2009, 5, 8), name: '大鸡', price: 99.99 }
6
-
7
- it "should raise error" do
8
- expect(lambda{ Hessian2::TypeWrapper.new(:unknown) }).to raise_error
9
- end
10
-
11
-
12
- it "should wrap nil" do
13
- bin = Hessian2.write(Hessian2::TypeWrapper.new(:unknown, nil))
14
-
15
- expect(bin).to eq('N')
16
- expect(Hessian2.parse(bin)).to eq(nil)
17
- end
18
-
19
-
20
- it "should wrap long" do
21
- [ 59, '59' ].each do |val|
22
- [ 'L', 'l', 'Long', 'long', :long ].each do |type|
23
- bin = Hessian2.write(Hessian2::TypeWrapper.new(type, val))
24
-
25
- b1, b0 = bin[0, 2].unpack('CC')
26
- expect(((b1 - 0xf8) << 8) + b0).to eq(Integer(val))
27
- expect(Hessian2.parse(bin)).to eq(Integer(val))
28
- end
29
- end
30
- end
31
-
32
-
33
- it "should wrap int" do
34
- [ 0x7f_fff_fff, '0x7f_fff_fff' ].each do |val|
35
- [ 'I', 'i', 'Integer', 'int', :int ].each do |type|
36
- bin = Hessian2.write(Hessian2::TypeWrapper.new(type, val))
37
-
38
- expect(bin[0]).to eq('I')
39
- expect(bin[1, 4].unpack('l>').first).to eq(Integer(val))
40
- expect(Hessian2.parse(bin)).to eq(Integer(val))
41
- end
42
- end
43
- end
44
-
45
-
46
- it "should wrap binary" do
47
- val = 'b' * 59
48
- [ 'B', 'b', 'Binary', 'bin', :bin ].each do |type|
49
- bin = Hessian2.write(Hessian2::TypeWrapper.new(type, val))
50
-
51
- b1, b0 = bin[0, 2].unpack('CC')
52
- expect(256 * (b1 - 0x34) + b0).to eq(val.size)
53
- expect(bin.size).to eq(2 + val.size)
54
- expect(Hessian2.parse(bin)).to eq(val)
55
- end
56
- end
57
-
58
-
59
- it "should wrap monkey" do
60
- [ Monkey.new(hash), AnotherMonkey.new(hash) ].each do |val|
61
- bin = Hessian2.write(Hessian2::TypeWrapper.new('com.sun.java.Monkey', val))
62
-
63
- _hash = Hessian2.parse(bin, nil, symbolize_keys: true)
64
- expect([ _hash[:born_at], _hash[:name], _hash[:price] ]).to eq([ hash[:born_at], hash[:name], hash[:price] ])
65
- end
66
- end
67
-
68
-
69
- it "should wrap long array" do
70
- bin = Hessian2.write(Hessian2::TypeWrapper.new('[long', [ 59, 69, 79, 89, 99 ]))
71
-
72
- expect(Hessian2.parse(bin)).to eq([ 59, 69, 79, 89, 99 ])
73
- end
74
-
75
-
76
- it "should wrap int array" do
77
- bin = Hessian2.write(Hessian2::TypeWrapper.new('[int', [ 0x7f_fff_ffb, 0x7f_fff_ffc, 0x7f_fff_ffd, 0x7f_fff_ffe, 0x7f_fff_fff ]))
78
-
79
- expect(Hessian2.parse(bin)).to eq([ 0x7f_fff_ffb, 0x7f_fff_ffc, 0x7f_fff_ffd, 0x7f_fff_ffe, 0x7f_fff_fff ])
80
- end
81
-
82
-
83
- it "should wrap binary array" do
84
- bin = Hessian2.write(Hessian2::TypeWrapper.new('[bin', [ 'b' * 59, 'b' * 69, 'b' * 79, 'b' * 89, 'b' * 99 ]))
85
-
86
- expect(Hessian2.parse(bin)).to eq([ 'b' * 59, 'b' * 69, 'b' * 79, 'b' * 89, 'b' * 99 ])
87
- end
88
-
89
-
90
- it "should wrap monkey array" do
91
- bin = Hessian2.write(Hessian2::TypeWrapper.new('[com.sun.java.Monkey', [ nil, Monkey.new(hash), AnotherMonkey.new(hash) ]))
92
-
93
- _hash1, _hash2, _hash3 = Hessian2.parse(bin, nil, symbolize_keys: true)
94
- expect(_hash1).to eq(nil)
95
- [ _hash2, _hash3 ].each do |_hash|
96
- expect([ _hash[:born_at], _hash[:name], _hash[:price] ]).to eq([ hash[:born_at], hash[:name], hash[:price] ])
97
- end
98
- end
99
-
100
-
101
- end
102
- end
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Hessian2
4
+ describe TypeWrapper do
5
+ hash = { id: nil, born_at: Time.new(2009, 5, 8), name: '大鸡', price: 99.99 }
6
+
7
+ it "should raise error" do
8
+ expect(lambda{ Hessian2::TypeWrapper.new(:unknown) }).to raise_error
9
+ end
10
+
11
+
12
+ it "should wrap nil" do
13
+ bin = Hessian2.write(Hessian2::TypeWrapper.new(:unknown, nil))
14
+
15
+ expect(bin).to eq('N')
16
+ expect(Hessian2.parse(bin)).to eq(nil)
17
+ end
18
+
19
+
20
+ it "should wrap long" do
21
+ [ 59, '59' ].each do |val|
22
+ [ 'L', 'l', 'Long', 'long', :long ].each do |type|
23
+ bin = Hessian2.write(Hessian2::TypeWrapper.new(type, val))
24
+
25
+ b1, b0 = bin[0, 2].unpack('CC')
26
+ expect(((b1 - 0xf8) << 8) + b0).to eq(Integer(val))
27
+ expect(Hessian2.parse(bin)).to eq(Integer(val))
28
+ end
29
+ end
30
+ end
31
+
32
+
33
+ it "should wrap int" do
34
+ [ 0x7f_fff_fff, '0x7f_fff_fff' ].each do |val|
35
+ [ 'I', 'i', 'Integer', 'int', :int ].each do |type|
36
+ bin = Hessian2.write(Hessian2::TypeWrapper.new(type, val))
37
+
38
+ expect(bin[0]).to eq('I')
39
+ expect(bin[1, 4].unpack('l>').first).to eq(Integer(val))
40
+ expect(Hessian2.parse(bin)).to eq(Integer(val))
41
+ end
42
+ end
43
+ end
44
+
45
+
46
+ it "should wrap binary" do
47
+ val = 'b' * 59
48
+ [ 'B', 'b', 'Binary', 'bin', :bin ].each do |type|
49
+ bin = Hessian2.write(Hessian2::TypeWrapper.new(type, val))
50
+
51
+ b1, b0 = bin[0, 2].unpack('CC')
52
+ expect(256 * (b1 - 0x34) + b0).to eq(val.size)
53
+ expect(bin.size).to eq(2 + val.size)
54
+ expect(Hessian2.parse(bin)).to eq(val)
55
+ end
56
+ end
57
+
58
+
59
+ it "should wrap monkey" do
60
+ [ Monkey.new(hash), AnotherMonkey.new(hash) ].each do |val|
61
+ bin = Hessian2.write(Hessian2::TypeWrapper.new('com.sun.java.Monkey', val))
62
+
63
+ _hash = Hessian2.parse(bin, nil, symbolize_keys: true)
64
+ expect([ _hash[:born_at], _hash[:name], _hash[:price] ]).to eq([ hash[:born_at], hash[:name], hash[:price] ])
65
+ end
66
+ end
67
+
68
+
69
+ it "should wrap long array" do
70
+ bin = Hessian2.write(Hessian2::TypeWrapper.new('[long', [ 59, 69, 79, 89, 99 ]))
71
+
72
+ expect(Hessian2.parse(bin)).to eq([ 59, 69, 79, 89, 99 ])
73
+ end
74
+
75
+
76
+ it "should wrap int array" do
77
+ bin = Hessian2.write(Hessian2::TypeWrapper.new('[int', [ 0x7f_fff_ffb, 0x7f_fff_ffc, 0x7f_fff_ffd, 0x7f_fff_ffe, 0x7f_fff_fff ]))
78
+
79
+ expect(Hessian2.parse(bin)).to eq([ 0x7f_fff_ffb, 0x7f_fff_ffc, 0x7f_fff_ffd, 0x7f_fff_ffe, 0x7f_fff_fff ])
80
+ end
81
+
82
+
83
+ it "should wrap binary array" do
84
+ bin = Hessian2.write(Hessian2::TypeWrapper.new('[bin', [ 'b' * 59, 'b' * 69, 'b' * 79, 'b' * 89, 'b' * 99 ]))
85
+
86
+ expect(Hessian2.parse(bin)).to eq([ 'b' * 59, 'b' * 69, 'b' * 79, 'b' * 89, 'b' * 99 ])
87
+ end
88
+
89
+
90
+ it "should wrap monkey array" do
91
+ bin = Hessian2.write(Hessian2::TypeWrapper.new('[com.sun.java.Monkey', [ nil, Monkey.new(hash), AnotherMonkey.new(hash) ]))
92
+
93
+ _hash1, _hash2, _hash3 = Hessian2.parse(bin, nil, symbolize_keys: true)
94
+ expect(_hash1).to eq(nil)
95
+ [ _hash2, _hash3 ].each do |_hash|
96
+ expect([ _hash[:born_at], _hash[:name], _hash[:price] ]).to eq([ hash[:born_at], hash[:name], hash[:price] ])
97
+ end
98
+ end
99
+
100
+
101
+ end
102
+ end
@@ -1,24 +1,24 @@
1
- require File.expand_path('../monkey_service', __FILE__)
2
-
3
- set :logging, false
4
-
5
- get '/' do
6
- status 405
7
- 'post me'
8
- end
9
-
10
- post '/' do
11
- MonkeyService.handle(request.body.read)
12
- end
13
-
14
- route :get, :post, '/sleep' do
15
- sleep 1
16
-
17
- 'wake'
18
- end
19
-
20
- route :get, :post, '/asleep' do
21
- EM::Synchrony.sleep(1)
22
-
23
- 'awake'
24
- end
1
+ require File.expand_path('../monkey_service', __FILE__)
2
+
3
+ set :logging, false
4
+
5
+ get '/' do
6
+ status 405
7
+ 'post me'
8
+ end
9
+
10
+ post '/' do
11
+ MonkeyService.handle(request.body.read)
12
+ end
13
+
14
+ route :get, :post, '/sleep' do
15
+ sleep 1
16
+
17
+ 'wake'
18
+ end
19
+
20
+ route :get, :post, '/asleep' do
21
+ EM::Synchrony.sleep(1)
22
+
23
+ 'awake'
24
+ end
@@ -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/asleep").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/asleep").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,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快