Skip to content

Commit

Permalink
Add more Jruby versions to Travis build
Browse files Browse the repository at this point in the history
- Adds testing Java 7 and Java 8 under oraclejdk and openjdk

- Skip requests and TLS specs, pending for now since failing
  and need more tweaks :/

- Updates usage of rspec throughout
  • Loading branch information
Waldemar Quevedo committed Jul 31, 2016
1 parent ce0a17d commit e03bf2b
Show file tree
Hide file tree
Showing 22 changed files with 409 additions and 332 deletions.
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,32 @@ matrix:
include:
- rvm: jruby
env: JRUBY_OPTS='--server -Xcompile.invokedynamic=false'
script: "bundle exec rake spec:client:jruby"
jdk: openjdk7
- rvm: jruby
env: JRUBY_OPTS='--server -Xcompile.invokedynamic=false'
script: "bundle exec rake spec:client:jruby"
jdk: oraclejdk7
- rvm: jruby
env: JRUBY_OPTS='--server -Xcompile.invokedynamic=false'
script: "bundle exec rake spec:client:jruby"
jdk: openjdk8
- rvm: jruby
env: JRUBY_OPTS='--server -Xcompile.invokedynamic=false'
script: "bundle exec rake spec:client:jruby"
jdk: oraclejdk8
allow_failures:
- rvm: jruby
env: JRUBY_OPTS='--server -Xcompile.invokedynamic=false'
jdk: openjdk7
- rvm: jruby
env: JRUBY_OPTS='--server -Xcompile.invokedynamic=false'
jdk: oraclejdk7
- rvm: jruby
env: JRUBY_OPTS='--server -Xcompile.invokedynamic=false'
jdk: openjdk8
- rvm: jruby
env: JRUBY_OPTS='--server -Xcompile.invokedynamic=false'
jdk: oraclejdk8
- rvm: ruby-head
- rvm: 2.4.0-preview1
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ RSpec::Core::RakeTask.new('spec:client') do |spec|
spec.rspec_opts = ["--format", "documentation", "--colour"]
end

desc 'Run spec from client on jruby using gnatsd as the server'
RSpec::Core::RakeTask.new('spec:client:jruby') do |spec|
spec.pattern = FileList['spec/client/*_spec.rb']
spec.rspec_opts = ["--format", "documentation", "--colour", "--tag", "~jruby_excluded"]
end

desc 'Run spec from server'
RSpec::Core::RakeTask.new('spec:server') do |spec|
spec.pattern = FileList['spec/server/*_spec.rb']
Expand Down
6 changes: 3 additions & 3 deletions lib/nats/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def on_disconnect(&callback)
end

# Set the default on_closed callback.
# @param [Block] &callback called when will reach a state when will no longer be connected.
# @param [Block] &callback called when will reach a state when will no longer be connected.
def on_close(&callback)
@close_cb = callback
@client.on_close(&callback) unless @client.nil?
Expand Down Expand Up @@ -707,7 +707,7 @@ def connection_completed #:nodoc:
# Mark that we established already TCP connection to the server. In case of TLS,
# prepare commands which will be dispatched to server and delay flushing until
# we have processed the INFO line sent by the server and done the handshake.
@connected = true
@connected = true
process_connect
end

Expand All @@ -716,7 +716,7 @@ def ssl_handshake_completed
process_connect
end

def process_connect #:nodoc:
def process_connect #:nodoc:
# Reset reconnect attempts since TCP connection has been successful at this point.
current = server_pool.first
current[:was_connected] = true
Expand Down
15 changes: 9 additions & 6 deletions spec/client/attack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

before (:each) do
@s = NatsServerControl.new(TEST_SERVER, "/tmp/nats_attack.pid")
@s.start_server
@s.start_server(true)
end

after (:each) do
Expand Down Expand Up @@ -62,11 +62,14 @@
end

it "should complain if we can't kill our server that we started" do
unless @s.was_running?
@s.kill_server
expect do
NATS.start(:uri => TEST_SERVER) { NATS.stop }
end.to raise_error NATS::ConnectError
errors = []
@s.kill_server
with_em_timeout(5) do
NATS.on_error do |e|
errors << e
end
NATS.connect(:uri => TEST_SERVER)
end
expect(errors.first).to be_a(NATS::ConnectError)
end
end
12 changes: 6 additions & 6 deletions spec/client/auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@

NATS.connect(:uri => TEST_AUTH_SERVER_NO_CRED)
end
auth_error_callbacks.should == 1
connect_error_callbacks.should == 1
expect(auth_error_callbacks).to eql(1)
expect(connect_error_callbacks).to eql(1)
end

it 'should remove server from the pool on unauthorized access' do
Expand All @@ -78,10 +78,10 @@
EM.stop
end
end
error_cb.should == 1
connect_cb.should be_truthy
NATS.client.should_not == nil
NATS.client.server_pool.size.should == 1
expect(error_cb).to eql(1)
expect(connect_cb).to eql(true)
expect(NATS.client).to_not be(nil)
expect(NATS.client.server_pool.size).to eql(1)
NATS.stop # clears err_cb
end

Expand Down
33 changes: 16 additions & 17 deletions spec/client/autounsub_spec.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
require 'spec_helper'

describe 'Client - max responses and auto-unsubscribe' do
describe 'Client - max responses and auto-unsubscribe', :jruby_excluded do

before(:all) do
@s = NatsServerControl.new
@s.start_server
before(:each) do
@s = NatsServerControl.new("nats://127.0.0.1:4222")
@s.start_server(true)
end

after(:all) do
after(:each) do
@s.kill_server
end

it "should only receive N msgs when requested: client support" do
WANT = 10
SEND = 20
received = 0
NATS.start do
NATS.start(:servers => [@s.uri]) do
NATS.subscribe('foo', :max => WANT) { received += 1 }
(0...SEND).each { NATS.publish('foo', 'hello') }
NATS.publish('done') { NATS.stop }
end
received.should == WANT
expect(received).to eql(WANT)
end

it "should only receive N msgs when auto-unsubscribed" do
Expand All @@ -31,7 +31,7 @@
(0...SEND).each { NATS.publish('foo', 'hello') }
NATS.publish('done') { NATS.stop }
end
received.should == WANT
expect(received).to eql(WANT)
end

it "should not complain when unsubscribing an auto-unsubscribed sid" do
Expand All @@ -44,7 +44,7 @@
NATS.stop
}
end
received.should == 1
expect(received).to eql(1)
end

it "should allow proper override of auto-unsubscribe max variables to lesser value" do
Expand All @@ -58,7 +58,7 @@
(0...SEND).each { NATS.publish('foo', 'hello') }
NATS.publish('done') { NATS.stop }
end
received.should == 1
expect(received).to eql(1)
end

it "should allow proper override of auto-unsubscribe max variables to higher value" do
Expand All @@ -70,7 +70,7 @@
(0...SEND).each { NATS.publish('foo', 'hello') }
NATS.publish('done') { NATS.stop }
end
received.should == WANT
expect(received).to eql(WANT)
end

it "should only receive N msgs using request mode with multiple helpers" do
Expand All @@ -81,7 +81,7 @@
NATS.request('help', nil, :max => 1) { received += 1 }
EM.add_timer(0.1) { NATS.stop }
end
received.should == 1
expect(received).to eql(1)
end

it "should not leak subscriptions on request that auto-unsubscribe properly with :max" do
Expand All @@ -94,12 +94,12 @@
NATS.flush do
EM.add_timer(0.1) do
NATS.unsubscribe(sid)
NATS.client.subscription_count.should == 0
expect(NATS.client.subscription_count).to eql(0)
NATS.stop
end
end
end
received.should == 100
expect(received).to eql(100)
end

it "should not complain when unsubscribe called on auto-cleaned up subscription" do
Expand All @@ -108,14 +108,13 @@
rsid = NATS.request('help', 'help request', :max => 1) {}
NATS.flush do
EM.add_timer(0.1) do
NATS.client.subscription_count.should == 1
expect(NATS.client.subscription_count).to eql(1)
NATS.unsubscribe(sid)
NATS.client.subscription_count.should == 0
expect(NATS.client.subscription_count).to eql(0)
NATS.unsubscribe(rsid)
NATS.stop
end
end
end
end

end
4 changes: 2 additions & 2 deletions spec/client/binary_msg_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
got_error = false
NATS.on_error { got_error = true; NATS.stop }
NATS.start(:reconnect => false) do
NATS.connected?.should == true
expect(NATS.connected?).to eql(true)
NATS.publish('dont_disconnect_me', "\006")
NATS.flush { NATS.stop }
end
got_error.should == false
expect(got_error).to eql(false)
end

end
50 changes: 27 additions & 23 deletions spec/client/client_cluster_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@
it 'should properly process :uri option for multiple servers' do
NATS.start(:uri => ['nats://127.0.0.1:4222', 'nats://127.0.0.1:4223'], :dont_randomize_servers => true) do
options = NATS.options
options.should be_an_instance_of Hash
options.should have_key :uri
options[:uri].should == ['nats://127.0.0.1:4222', 'nats://127.0.0.1:4223']
expect(options).to be_a(Hash)
expect(options).to have_key(:uri)
expect(options[:uri]).to eql(['nats://127.0.0.1:4222', 'nats://127.0.0.1:4223'])
NATS.stop
end
end

it 'should allow :uris and :servers as aliases' do
NATS.start(:uris => ['nats://127.0.0.1:4222', 'nats://127.0.0.1:4223'], :dont_randomize_servers => true) do
options = NATS.options
options.should be_an_instance_of Hash
options.should have_key :uris
options[:uris].should == ['nats://127.0.0.1:4222', 'nats://127.0.0.1:4223']
expect(options).to be_a(Hash)
expect(options).to have_key(:uris)
expect(options[:uris]).to eql(['nats://127.0.0.1:4222', 'nats://127.0.0.1:4223'])
NATS.stop
end
NATS.start(:servers => ['nats://127.0.0.1:4222', 'nats://127.0.0.1:4223'], :dont_randomize_servers => true) do
options = NATS.options
options.should be_an_instance_of Hash
options.should have_key :servers
options[:servers].should == ['nats://127.0.0.1:4222', 'nats://127.0.0.1:4223']
expect(options).to be_a(Hash)
expect(options).to have_key(:servers)
expect(options[:servers]).to eql(['nats://127.0.0.1:4222', 'nats://127.0.0.1:4223'])
NATS.stop
end
end
Expand All @@ -60,8 +60,8 @@
c2 = NATS.connect(:servers => ['nats://127.0.0.1:4222', 'nats://127.0.0.1:4222'])
timeout_nats_on_failure
end
c1.should_not be_nil
c2.should_not be_nil
expect(c1).to_not be(nil)
expect(c2).to_not be(nil)
end

it 'should randomize server pool list by default' do
Expand All @@ -72,7 +72,7 @@
NATS.connect(:uri => servers.dup) do |c|
sp_servers = []
c.server_pool.each { |s| sp_servers << s[:uri].to_s }
sp_servers.should_not == servers
expect(sp_servers).to_not eql(servers)
end
timeout_nats_on_failure
end
Expand All @@ -94,22 +94,26 @@

it 'should connect to first entry if available' do
NATS.start(:dont_randomize_servers => true, :uri => ['nats://127.0.0.1:4222', 'nats://127.0.0.1:4223']) do
NATS.client.connected_server.should == URI.parse('nats://127.0.0.1:4222')
expect(NATS.client.connected_server).to eql(URI.parse('nats://127.0.0.1:4222'))
NATS.stop
end
end

it 'should fail to connect if no servers available' do
expect do
NATS.start(:uri => ['nats://127.0.0.1:4223']) do
NATS.stop
errors = []
with_em_timeout do
NATS.on_error do |e|
errors << e
end
end.to raise_error NATS::Error

NATS.start(:uri => ['nats://127.0.0.1:4223'])
end
expect(errors.first).to be_a(NATS::Error)
end

it 'should connect to another server if first is not available' do
NATS.start(:dont_randomize_servers => true, :uri => ['nats://127.0.0.1:4224', 'nats://127.0.0.1:4222']) do
NATS.client.connected_server.should == URI.parse('nats://127.0.0.1:4222')
expect(NATS.client.connected_server).to eql(URI.parse('nats://127.0.0.1:4222'))
NATS.stop
end
end
Expand Down Expand Up @@ -201,10 +205,10 @@

EM.add_timer(1) do
time_diff = Time.now - kill_time
time_diff.should < 2
expect(time_diff < 2).to eql(true)

# Confirm that it has connected to the second server
nc.connected_server.should == URI.parse(@s2_uri)
expect(nc.connected_server).to eql(URI.parse(@s2_uri))

# Restart the first server again...
@s1.start_server
Expand All @@ -215,12 +219,12 @@

EM.add_timer(0.25) do
time_diff = Time.now - kill_time2
time_diff.should < 1
expect(time_diff < 1).to eql(true)

# Confirm we are reconnecting to the first one again
nc.flush do
nc.connected_server.should == URI.parse(@s1_uri)
end
expect(nc.connected_server).to eql(URI.parse(@s1_uri))
end
end
end
end
Expand Down
Loading

0 comments on commit e03bf2b

Please sign in to comment.