protobuf 2.0.0.rc2 → 2.0.0.rc3

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 (46) hide show
  1. data/.gitignore +1 -0
  2. data/ext/ruby_generator/Makefile +10 -0
  3. data/ext/ruby_generator/RubyGenerator.cpp +85 -70
  4. data/ext/ruby_generator/RubyGenerator.h +23 -4
  5. data/lib/protobuf.rb +33 -26
  6. data/lib/protobuf/cli.rb +18 -13
  7. data/lib/protobuf/enum.rb +39 -34
  8. data/lib/protobuf/enum_value.rb +29 -0
  9. data/lib/protobuf/field/base_field.rb +34 -5
  10. data/lib/protobuf/field/enum_field.rb +6 -14
  11. data/lib/protobuf/field/extension_fields.rb +13 -5
  12. data/lib/protobuf/field/field_array.rb +17 -7
  13. data/lib/protobuf/field/varint_field.rb +4 -6
  14. data/lib/protobuf/message.rb +44 -148
  15. data/lib/protobuf/rpc/server.rb +2 -2
  16. data/lib/protobuf/version.rb +1 -1
  17. data/spec/benchmark/tasks.rb +7 -8
  18. data/spec/functional/evented_server_spec.rb +9 -9
  19. data/spec/functional/socket_server_spec.rb +8 -8
  20. data/spec/functional/zmq_server_spec.rb +8 -8
  21. data/spec/lib/protobuf/cli_spec.rb +30 -11
  22. data/spec/lib/protobuf/enum_spec.rb +90 -0
  23. data/spec/lib/protobuf/enum_value_spec.rb +13 -0
  24. data/spec/lib/protobuf/message/encoder_spec.rb +1 -1
  25. data/spec/lib/protobuf/message_spec.rb +50 -0
  26. data/spec/lib/protobuf/rpc/client_spec.rb +23 -23
  27. data/spec/lib/protobuf/rpc/servers/evented_server_spec.rb +1 -1
  28. data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +1 -1
  29. data/spec/lib/protobuf/rpc/service_spec.rb +18 -18
  30. data/spec/lib/protobuf_spec.rb +62 -0
  31. data/spec/spec_helper.rb +12 -1
  32. data/spec/support/all.rb +0 -1
  33. data/spec/support/server.rb +1 -1
  34. data/spec/support/test/enum.pb.rb +32 -0
  35. data/spec/support/test/enum.proto +12 -0
  36. data/spec/support/test/resource.pb.rb +52 -0
  37. data/spec/{proto/test.proto → support/test/resource.proto} +2 -2
  38. data/spec/support/test/resource_service.rb +14 -0
  39. metadata +51 -48
  40. data/ext/Makefile +0 -11
  41. data/spec/lib/protobuf/message/enum_spec.rb +0 -13
  42. data/spec/lib/protobuf/message/message_spec.rb +0 -67
  43. data/spec/proto/test.pb.rb +0 -54
  44. data/spec/proto/test_service.rb +0 -30
  45. data/spec/proto/test_service_impl.rb +0 -18
  46. data/spec/support/silent_constants.rb +0 -44
@@ -1,24 +1,24 @@
1
1
  require 'spec_helper'
2
- require 'spec/proto/test_service_impl'
2
+ require 'spec/support/test/resource_service'
3
3
 
4
4
  describe Protobuf::Rpc::Client do
5
5
  before(:each) do
6
6
  load 'protobuf/evented.rb'
7
7
  ::Protobuf::Rpc::Connector.connector_for_client(true)
8
- ::Spec::Proto::TestService.configure(::Spec::Proto::TestService::DEFAULT_LOCATION)
8
+ ::Test::ResourceService.configure(::Test::ResourceService::DEFAULT_LOCATION)
9
9
  end
10
10
 
11
11
  context "when using fiber based calls" do
12
12
  it "waits for response when running synchronously" do
13
13
  EventMachine.fiber_run do
14
14
  StubServer.new(:delay => 3) do |server|
15
- client = Spec::Proto::TestService.client(:async => false)
15
+ client = Test::ResourceService.client(:async => false)
16
16
  start = now
17
17
 
18
18
  client.find(:name => "Test Name", :active => true) do |c|
19
19
  c.on_success do |succ|
20
20
  succ.name.should eq("Test Name")
21
- succ.status.should eq(Spec::Proto::StatusType::ENABLED)
21
+ succ.status.should eq(Test::StatusType::ENABLED)
22
22
  end
23
23
 
24
24
  c.on_failure do |err|
@@ -36,7 +36,7 @@ describe Protobuf::Rpc::Client do
36
36
  it "doesn't wait for response when running async call inside fiber" do
37
37
  EventMachine.fiber_run do
38
38
  StubServer.new(:delay => 3) do |server|
39
- client = Spec::Proto::TestService.client(:async => true)
39
+ client = Test::ResourceService.client(:async => true)
40
40
  start = now
41
41
  client.find(:name => "Test Name", :active => true)
42
42
 
@@ -50,7 +50,7 @@ describe Protobuf::Rpc::Client do
50
50
  subject = Proc.new do
51
51
  EventMachine.run do
52
52
  StubServer.new(:delay => 1) do |server|
53
- client = Spec::Proto::TestService.client(:async => false)
53
+ client = Test::ResourceService.client(:async => false)
54
54
  client.find(:name => "Test Name", :active => true)
55
55
  end
56
56
  end
@@ -64,7 +64,7 @@ describe Protobuf::Rpc::Client do
64
64
  test_proc = Proc.new do
65
65
  EventMachine.fiber_run do
66
66
  StubServer.new(:delay => 2) do |server|
67
- client = Spec::Proto::TestService.client(:async => false, :timeout => 1)
67
+ client = Test::ResourceService.client(:async => false, :timeout => 1)
68
68
  client.find(:name => "Test Name", :active => true) do |cl|
69
69
  cl.on_success {}
70
70
  cl.on_failure {|f| error = f}
@@ -83,7 +83,7 @@ describe Protobuf::Rpc::Client do
83
83
  it "throws a timeout when client timeout is exceeded" do
84
84
  subject = Proc.new do
85
85
  StubServer.new(:delay => 2) do |server|
86
- client = Spec::Proto::TestService.client(:async => false, :timeout => 1)
86
+ client = Test::ResourceService.client(:async => false, :timeout => 1)
87
87
  client.find(:name => "Test Name", :active => true)
88
88
  end
89
89
  end
@@ -96,7 +96,7 @@ describe Protobuf::Rpc::Client do
96
96
 
97
97
  subject = Proc.new do
98
98
  StubServer.new(:delay => 2) do |server|
99
- client = Spec::Proto::TestService.client(:async => false, :timeout => 1)
99
+ client = Test::ResourceService.client(:async => false, :timeout => 1)
100
100
  client.find(:name => "Test Name", :active => true) do |c|
101
101
  c.on_failure do |f|
102
102
  failure_message = f.message
@@ -116,38 +116,38 @@ describe Protobuf::Rpc::Client do
116
116
  context 'when creating a client from a service' do
117
117
 
118
118
  it 'should be able to get a client through the Service#client helper method' do
119
- Spec::Proto::TestService.client(:port => 9191).should eq(Protobuf::Rpc::Client.new(:service => Spec::Proto::TestService, :port => 9191))
119
+ Test::ResourceService.client(:port => 9191).should eq(Protobuf::Rpc::Client.new(:service => Test::ResourceService, :port => 9191))
120
120
  end
121
121
 
122
122
  it "should be able to override a service location's host and port" do
123
- Spec::Proto::TestService.located_at 'somewheregreat.com:12345'
124
- clean_client = Spec::Proto::TestService.client
123
+ Test::ResourceService.located_at 'somewheregreat.com:12345'
124
+ clean_client = Test::ResourceService.client
125
125
  clean_client.options[:host].should eq('somewheregreat.com')
126
126
  clean_client.options[:port].should eq(12345)
127
127
 
128
- updated_client = Spec::Proto::TestService.client(:host => 'amazing.com', :port => 54321)
128
+ updated_client = Test::ResourceService.client(:host => 'amazing.com', :port => 54321)
129
129
  updated_client.options[:host].should eq('amazing.com')
130
130
  updated_client.options[:port].should eq(54321)
131
131
  end
132
132
 
133
133
  it 'should be able to define the syncronicity of the client request' do
134
- client = Spec::Proto::TestService.client(:async => false)
134
+ client = Test::ResourceService.client(:async => false)
135
135
  client.options[:async].should be_false
136
136
  client.async?.should be_false
137
137
 
138
- client = Spec::Proto::TestService.client(:async => true)
138
+ client = Test::ResourceService.client(:async => true)
139
139
  client.options[:async].should be_true
140
140
  client.async?.should be_true
141
141
  end
142
142
 
143
143
  it 'should be able to define which service to create itself for' do
144
- client = Protobuf::Rpc::Client.new :service => Spec::Proto::TestService
145
- client.options[:service].should eq(Spec::Proto::TestService)
144
+ client = Protobuf::Rpc::Client.new :service => Test::ResourceService
145
+ client.options[:service].should eq(Test::ResourceService)
146
146
  end
147
147
 
148
148
  it 'should have a hard default for host and port on a service that has not been configured' do
149
- reset_service_location Spec::Proto::TestService
150
- client = Spec::Proto::TestService.client
149
+ reset_service_location Test::ResourceService
150
+ client = Test::ResourceService.client
151
151
  client.options[:host].should eq(Protobuf::Rpc::Service::DEFAULT_LOCATION[:host])
152
152
  client.options[:port].should eq(Protobuf::Rpc::Service::DEFAULT_LOCATION[:port])
153
153
  end
@@ -161,7 +161,7 @@ describe Protobuf::Rpc::Client do
161
161
  # namely the :find method
162
162
 
163
163
  it 'should respond to defined service methods' do
164
- client = Spec::Proto::TestService.client
164
+ client = Test::ResourceService.client
165
165
  client.should_receive(:send_request).and_return(nil)
166
166
  expect { client.find(nil) }.to_not raise_error
167
167
  end
@@ -173,7 +173,7 @@ describe Protobuf::Rpc::Client do
173
173
  it 'should be able to set and get local variables within client response blocks' do
174
174
  outer_value = 'OUTER'
175
175
  inner_value = 'INNER'
176
- client = Spec::Proto::TestService.client(:async => true)
176
+ client = Test::ResourceService.client(:async => true)
177
177
 
178
178
  EM.should_receive(:reactor_running?).and_return(true)
179
179
  EM.stub!(:next_tick) do
@@ -194,10 +194,10 @@ describe Protobuf::Rpc::Client do
194
194
  context 'when receiving request objects' do
195
195
 
196
196
  it 'should be able to create the correct request object if passed a hash' do
197
- client = Spec::Proto::TestService.client
197
+ client = Test::ResourceService.client
198
198
  client.should_receive(:send_request)
199
199
  client.find({:name => 'Test Name', :active => false})
200
- client.options[:request].should be_a(Spec::Proto::ResourceFindRequest)
200
+ client.options[:request].should be_a(Test::ResourceFindRequest)
201
201
  client.options[:request].name.should eq('Test Name')
202
202
  client.options[:request].active.should eq(false)
203
203
  end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'spec/proto/test_service_impl'
2
+ require 'spec/support/test/resource_service'
3
3
  require 'protobuf/rpc/servers/evented_runner'
4
4
  require 'protobuf/evented'
5
5
 
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'spec/proto/test_service_impl'
2
+ require 'spec/support/test/resource_service'
3
3
  require 'protobuf/rpc/servers/socket_runner'
4
4
  require 'protobuf/evented'
5
5
  require 'protobuf/socket'
@@ -1,45 +1,45 @@
1
1
  require 'spec_helper'
2
- require 'spec/proto/test_service_impl'
2
+ require 'spec/support/test/resource_service'
3
3
 
4
4
  describe Protobuf::Rpc::Service do
5
5
 
6
6
  context 'when configuring' do
7
7
  before :each do
8
- reset_service_location Spec::Proto::TestService
8
+ reset_service_location Test::ResourceService
9
9
  end
10
10
 
11
11
  it 'should have a default location configured' do
12
- Spec::Proto::TestService.host.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:host]
13
- Spec::Proto::TestService.port.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:port]
12
+ Test::ResourceService.host.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:host]
13
+ Test::ResourceService.port.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:port]
14
14
  end
15
15
 
16
16
  it "should be able to pre-configure a service location for clients" do
17
- Spec::Proto::TestService.located_at 'google.com:12345'
18
- client = Spec::Proto::TestService.client
17
+ Test::ResourceService.located_at 'google.com:12345'
18
+ client = Test::ResourceService.client
19
19
  client.options[:host].should == 'google.com'
20
20
  client.options[:port].should == 12345
21
21
  end
22
22
 
23
23
  context 'configuring host' do
24
- before(:each) { Spec::Proto::TestService.configure :host => 'somehost.com' }
25
- after(:each) { Spec::Proto::TestService.configure :host => '127.0.0.1' }
24
+ before(:each) { Test::ResourceService.configure :host => 'somehost.com' }
25
+ after(:each) { Test::ResourceService.configure :host => '127.0.0.1' }
26
26
 
27
27
  it 'should be able to configure and read the host' do
28
- Spec::Proto::TestService.host.should == 'somehost.com'
28
+ Test::ResourceService.host.should == 'somehost.com'
29
29
  end
30
30
  end
31
31
 
32
32
  it 'should be able to configure and read the port' do
33
- Spec::Proto::TestService.configure :port => 12345
34
- Spec::Proto::TestService.port.should == 12345
33
+ Test::ResourceService.configure :port => 12345
34
+ Test::ResourceService.port.should == 12345
35
35
  end
36
36
 
37
37
  it 'should skip configuring location if the location passed does not match host:port syntax' do
38
38
  invalid_locations = [nil, 'myhost:', ':9939', 'badhost123']
39
39
  invalid_locations.each do |location|
40
- Spec::Proto::TestService.located_at location
41
- Spec::Proto::TestService.host.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:host]
42
- Spec::Proto::TestService.port.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:port]
40
+ Test::ResourceService.located_at location
41
+ Test::ResourceService.host.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:host]
42
+ Test::ResourceService.port.should == Protobuf::Rpc::Service::DEFAULT_LOCATION[:port]
43
43
  end
44
44
  end
45
45
  end
@@ -48,8 +48,8 @@ describe Protobuf::Rpc::Service do
48
48
 
49
49
  before(:all) do
50
50
  class ::NewTestService < Protobuf::Rpc::Service
51
- rpc :bad_method, Spec::Proto::ResourceFindRequest, Spec::Proto::Resource
52
- rpc :bad_var, Spec::Proto::ResourceFindRequest, Spec::Proto::Resource
51
+ rpc :bad_method, Test::ResourceFindRequest, Test::Resource
52
+ rpc :bad_var, Test::ResourceFindRequest, Test::Resource
53
53
  def bad_method
54
54
  hash = {}
55
55
  hash[:one].explode
@@ -62,14 +62,14 @@ describe Protobuf::Rpc::Service do
62
62
 
63
63
  it 'raises an undefined method name error when calling a method on a non-existant object' do
64
64
  expect {
65
- req = mock('RequestWrapper', :request_proto => Spec::Proto::ResourceFindRequest.new(:name => 'mmeh').to_s)
65
+ req = mock('RequestWrapper', :request_proto => Test::ResourceFindRequest.new(:name => 'mmeh').to_s)
66
66
  ::NewTestService.new.bad_method(req)
67
67
  }.to raise_error(NoMethodError)
68
68
  end
69
69
 
70
70
  it 'raises a name error when accessing a non-existant object' do
71
71
  expect {
72
- req = mock('RequestWrapper', :request_proto => Spec::Proto::ResourceFindRequest.new(:name => 'mmeh').to_s)
72
+ req = mock('RequestWrapper', :request_proto => Test::ResourceFindRequest.new(:name => 'mmeh').to_s)
73
73
  ::NewTestService.new.bad_var(req)
74
74
  }.to raise_error(NameError)
75
75
  end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ require 'protobuf'
3
+
4
+ describe ::Protobuf do
5
+
6
+ describe '.connector_type' do
7
+ before { described_class.instance_variable_set(:@_connector_type, nil) }
8
+
9
+ it 'defaults to socket' do
10
+ described_class.connector_type.should eq :socket
11
+ end
12
+
13
+ it 'accepts socket, evented, or zmq' do
14
+ [:socket, :evented, :zmq].each do |type|
15
+ described_class.connector_type = type
16
+ described_class.connector_type.should eq type
17
+ end
18
+ end
19
+
20
+ it 'does not accept other types' do
21
+ [:hello, :world].each do |type|
22
+ expect {
23
+ described_class.connector_type = type
24
+ }.to raise_error(ArgumentError)
25
+ end
26
+ end
27
+ end
28
+
29
+ describe '.gc_pause_server_request?' do
30
+ before { described_class.instance_variable_set(:@_gc_pause_server_request, nil) }
31
+
32
+ it 'defaults to a false value' do
33
+ described_class.gc_pause_server_request?.should be_false
34
+ end
35
+
36
+ it 'is settable' do
37
+ described_class.gc_pause_server_request = true
38
+ described_class.gc_pause_server_request?.should be_true
39
+ end
40
+ end
41
+
42
+ describe '.print_deprecation_warnings?' do
43
+ before { described_class.instance_variable_set(:@_print_deprecation_warnings, nil) }
44
+
45
+ it 'defaults to a true value' do
46
+ described_class.print_deprecation_warnings?.should be_true
47
+ end
48
+
49
+ it 'is settable' do
50
+ described_class.print_deprecation_warnings = false
51
+ described_class.print_deprecation_warnings?.should be_false
52
+ end
53
+
54
+ context 'when ENV["PB_IGNORE_DEPRECATIONS"] present' do
55
+ it 'defaults to a false value' do
56
+ ENV['PB_IGNORE_DEPRECATIONS'] = '1'
57
+ described_class.print_deprecation_warnings?.should be_false
58
+ end
59
+ end
60
+ end
61
+
62
+ end
data/spec/spec_helper.rb CHANGED
@@ -19,9 +19,20 @@ if ENV["DEBUG"]
19
19
  end
20
20
 
21
21
  ::RSpec.configure do |c|
22
- c.include(::SilentConstants)
23
22
  c.include(::Sander6::CustomMatchers)
24
23
  c.mock_with :rspec
24
+
25
+ c.before(:suite) do
26
+ unless ENV['NO_COMPILE_TEST_PROTOS']
27
+ $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)'
28
+ proto_path = File.expand_path("../support/", __FILE__)
29
+ %x{ rprotoc --proto_path=#{proto_path} --ruby_out=#{proto_path} #{File.join(proto_path, '**', '*.proto')} }
30
+ end
31
+ end
32
+ end
33
+
34
+ Dir[File.expand_path('../support/**/*.pb.rb', __FILE__)].each do |proto_file|
35
+ require proto_file
25
36
  end
26
37
 
27
38
  class ::Protobuf::Rpc::Client
data/spec/support/all.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'support/tolerance_matcher'
2
2
  require 'support/server'
3
- require 'support/silent_constants'
4
3
 
5
4
  def now
6
5
  Time.new.to_f
@@ -5,7 +5,7 @@ require 'protobuf/rpc/servers/socket/server'
5
5
  require 'protobuf/rpc/servers/socket_runner'
6
6
  require 'protobuf/rpc/servers/zmq/server'
7
7
  require 'protobuf/rpc/servers/zmq_runner'
8
- require 'spec/proto/test_service_impl'
8
+ require 'spec/support/test/resource_service'
9
9
 
10
10
  # Want to abort if server dies?
11
11
  Thread.abort_on_exception = true
@@ -0,0 +1,32 @@
1
+ ##
2
+ # This file is auto-generated. DO NOT EDIT!
3
+ #
4
+ require 'protobuf/message'
5
+
6
+ module Test
7
+ ##
8
+ # Enum Classes
9
+ #
10
+ class EnumTestType < ::Protobuf::Enum; end
11
+
12
+ ##
13
+ # Message Classes
14
+ #
15
+ class EnumTestMessage < ::Protobuf::Message; end
16
+
17
+ ##
18
+ # Enum Values
19
+ #
20
+ ::Test::EnumTestType.define :ONE, 1
21
+ ::Test::EnumTestType.define :TWO, 2
22
+
23
+
24
+ ##
25
+ # Message Fields
26
+ #
27
+ ::Test::EnumTestMessage.optional(::Test::EnumTestType, :non_default_enum, 1)
28
+ ::Test::EnumTestMessage.optional(::Test::EnumTestType, :default_enum, 2, :default => ::Test::EnumTestType::ONE)
29
+ ::Test::EnumTestMessage.repeated(::Test::EnumTestType, :repeated_enums, 3)
30
+
31
+
32
+ end
@@ -0,0 +1,12 @@
1
+ package test;
2
+
3
+ enum EnumTestType {
4
+ ONE = 1;
5
+ TWO = 2;
6
+ }
7
+
8
+ message EnumTestMessage {
9
+ optional EnumTestType non_default_enum = 1;
10
+ optional EnumTestType default_enum = 2 [default=ONE];
11
+ repeated EnumTestType repeated_enums = 3;
12
+ }
@@ -0,0 +1,52 @@
1
+ ##
2
+ # This file is auto-generated. DO NOT EDIT!
3
+ #
4
+ require 'protobuf/message'
5
+ require 'protobuf/rpc/service'
6
+
7
+ module Test
8
+ ##
9
+ # Enum Classes
10
+ #
11
+ class StatusType < ::Protobuf::Enum; end
12
+
13
+ ##
14
+ # Message Classes
15
+ #
16
+ class ResourceFindRequest < ::Protobuf::Message; end
17
+ class Resource < ::Protobuf::Message; end
18
+ class Nested < ::Protobuf::Message; end
19
+
20
+ ##
21
+ # Enum Values
22
+ #
23
+ ::Test::StatusType.define :PENDING, 0
24
+ ::Test::StatusType.define :ENABLED, 1
25
+ ::Test::StatusType.define :DISABLED, 2
26
+ ::Test::StatusType.define :DELETED, 3
27
+
28
+
29
+ ##
30
+ # Message Fields
31
+ #
32
+ ::Test::ResourceFindRequest.required(::Protobuf::Field::StringField, :name, 1)
33
+ ::Test::ResourceFindRequest.optional(::Protobuf::Field::BoolField, :active, 2)
34
+
35
+ ::Test::Resource.required(::Protobuf::Field::StringField, :name, 1)
36
+ ::Test::Resource.optional(::Protobuf::Field::Int64Field, :date_created, 2)
37
+ ::Test::Resource.optional(::Test::StatusType, :status, 3)
38
+ ::Test::Resource.repeated(::Test::StatusType, :repeated_enum, 4)
39
+
40
+ ::Test::Nested.optional(::Protobuf::Field::StringField, :name, 1)
41
+ ::Test::Nested.optional(::Test::Resource, :resource, 2)
42
+ ::Test::Nested.repeated(::Test::Resource, :multiple_resources, 3)
43
+ ::Test::Nested.optional(::Test::StatusType, :status, 4)
44
+
45
+
46
+ ##
47
+ # Services
48
+ #
49
+ class ResourceService < ::Protobuf::Rpc::Service
50
+ rpc :find, ::Test::ResourceFindRequest, ::Test::Resource
51
+ end
52
+ end