jerbil 1.2.2
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.
- data/Bugs.rdoc +66 -0
- data/Gemfile +12 -0
- data/History.txt +359 -0
- data/Intro.txt +5 -0
- data/LICENCE.rdoc +159 -0
- data/README.md +335 -0
- data/README_SERVICES.md +410 -0
- data/README_TESTING.md +47 -0
- data/bin/jerbil +62 -0
- data/bin/jerbil-install +56 -0
- data/etc/conf.d/jerbild +15 -0
- data/etc/conf.d/jserviced +39 -0
- data/etc/init.d/jerbild +55 -0
- data/etc/init.d/jserviced +59 -0
- data/etc/jerbil/jerbil-client.rb +2 -0
- data/etc/jerbil/jerbil.rb +83 -0
- data/lib/jerbil.rb +636 -0
- data/lib/jerbil/config.md +49 -0
- data/lib/jerbil/config.rb +67 -0
- data/lib/jerbil/errors.rb +74 -0
- data/lib/jerbil/jerbil_service/base.rb +191 -0
- data/lib/jerbil/jerbil_service/client.rb +325 -0
- data/lib/jerbil/jerbil_service/config.md +119 -0
- data/lib/jerbil/jerbil_service/config.rb +72 -0
- data/lib/jerbil/jerbil_service/sclient.rb +343 -0
- data/lib/jerbil/jerbil_service/support.rb +58 -0
- data/lib/jerbil/jerbil_service/utils.rb +35 -0
- data/lib/jerbil/servers.rb +230 -0
- data/lib/jerbil/service.rb +216 -0
- data/lib/jerbil/support.rb +160 -0
- data/lib/jerbil/thor/server.rb +76 -0
- data/lib/jerbil/thor/service.rb +74 -0
- data/lib/jerbil/version.rb +13 -0
- data/sbin/jerbil-status +120 -0
- data/sbin/jerbil-stop +139 -0
- data/sbin/jerbild +186 -0
- data/sbin/jservice-status +107 -0
- data/sbin/jservice-stop +94 -0
- data/sbin/jserviced +111 -0
- data/spec/jerbil_2_jerbil_spec.rb +87 -0
- data/spec/jerbil_client1_spec.rb +80 -0
- data/spec/jerbil_client_spec.rb +114 -0
- data/spec/jerbil_client_stop_spec.rb +24 -0
- data/spec/jerbil_daemonised/jerbil_local_spec.rb +81 -0
- data/spec/jerbil_daemonised/jerbil_remote_spec.rb +116 -0
- data/spec/jerbil_load.rb +48 -0
- data/spec/jerbil_local_spec.rb +91 -0
- data/spec/jerbil_missing_spec.rb +98 -0
- data/spec/jerbil_remote_spec.rb +117 -0
- data/spec/jerbil_remote_spec_bup.rb +168 -0
- data/spec/jerbil_service_error_spec.rb +56 -0
- data/spec/jerbil_service_spec.rb +41 -0
- data/spec/jerbil_support_spec.rb +69 -0
- data/spec/jservice_utils_spec.rb +38 -0
- data/spec/server_spec.rb +69 -0
- data/spec/server_update_spec.rb +28 -0
- data/spec/service_spec.rb +72 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/test_env_spec.rb +53 -0
- data/test/bad_test_service.rb +31 -0
- data/test/conf.d/jerbil +36 -0
- data/test/conf.d/jerbil.conf +39 -0
- data/test/conf.d/jerbil.rb +55 -0
- data/test/conf.d/jerbil_local.rb +33 -0
- data/test/conf.d/jerbil_no_local.conf +39 -0
- data/test/conf.d/jerbil_old.rb +47 -0
- data/test/conf.d/jerbil_test.rb +35 -0
- data/test/conf.d/malformed +1 -0
- data/test/conf.d/missing_services +39 -0
- data/test/conf.d/ruby_test.rb +8 -0
- data/test/init.d/jerbild +14 -0
- data/test/jerbil.rb +51 -0
- data/test/jerbil_config.rb +8 -0
- data/test/jstop.rb +36 -0
- data/test/key.asc +1 -0
- data/test/lib/ruby_test.rb +37 -0
- data/test/lib/ruby_test/config.rb +56 -0
- data/test/lib/ruby_test/version.rb +13 -0
- data/test/pids/jerbil-prod.asc +1 -0
- data/test/pids/jerbil-prod.pid +1 -0
- data/test/pids/jerbil.pid +1 -0
- data/test/private_key_file.asc +3 -0
- data/test/service-stop.rb +86 -0
- data/test/service_mock.rb +94 -0
- data/test/test_service_client.rb +25 -0
- metadata +265 -0
@@ -0,0 +1,87 @@
|
|
1
|
+
#
|
2
|
+
# Description
|
3
|
+
#
|
4
|
+
# Author:: Robert Sharp
|
5
|
+
# Copyright:: Copyright (c) 2010 Robert Sharp
|
6
|
+
# License:: Open Software Licence v3.0
|
7
|
+
#
|
8
|
+
# This software is licensed for use under the Open Software Licence v. 3.0
|
9
|
+
# The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
|
10
|
+
# and in the file copyright.txt. Under the terms of this licence, all derivative works
|
11
|
+
# must themselves be licensed under the Open Software Licence v. 3.0
|
12
|
+
#
|
13
|
+
#
|
14
|
+
|
15
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
16
|
+
require 'jerbil/server'
|
17
|
+
require 'jerbil/service'
|
18
|
+
require 'jerbil'
|
19
|
+
require 'jellog'
|
20
|
+
require 'socket'
|
21
|
+
require 'syslog'
|
22
|
+
require 'drb'
|
23
|
+
|
24
|
+
config = File.expand_path(File.dirname(__FILE__) + '/../test/conf.d/jerbil.conf')
|
25
|
+
log_dir = File.expand_path(File.dirname(__FILE__) + '/../log')
|
26
|
+
key_file = File.expand_path(File.dirname(__FILE__) + '/../test/private_key_file.asc')
|
27
|
+
|
28
|
+
describe "Jerbil to Jerbil tests" do
|
29
|
+
|
30
|
+
before(:all) do
|
31
|
+
hostname = Socket.gethostname
|
32
|
+
@options = Jerbil::Config.new(config)
|
33
|
+
@options[:servers].each do |server|
|
34
|
+
if server.fqdn == hostname then
|
35
|
+
@remote_jerbil_server = server
|
36
|
+
else
|
37
|
+
@jerbil_server ||= server
|
38
|
+
end
|
39
|
+
end
|
40
|
+
DRb.start_service
|
41
|
+
Jellog::Logger.disable_syslog
|
42
|
+
#@remote_jerbil_server = Jerbil::ServerRecord.new(hostname, 'ABCDE')
|
43
|
+
#@jerbil_server = Jerbil::ServerRecord.new(hostname, @my_key)
|
44
|
+
@a_service = Jerbil::ServiceRecord.new(:rubytest, :test)
|
45
|
+
@b_service = Jerbil::ServiceRecord.new(:rubytest, :prod)
|
46
|
+
@remote_jerbil = @remote_jerbil_server.connect
|
47
|
+
@remote_jerbil.register(@a_service)
|
48
|
+
@remote_jerbil.register(@b_service)
|
49
|
+
@jerbil_key = "djrtuefgf"
|
50
|
+
@ant_fqdn = 'antonia.osburn-sharp.ath.cx'
|
51
|
+
end
|
52
|
+
|
53
|
+
after(:all) do
|
54
|
+
@remote_jerbil.remove(@a_service)
|
55
|
+
@remote_jerbil.remove(@b_service)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should be easy to configure a live server" do
|
59
|
+
@remote_jerbil.services.should == 2
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should be possible to start another server" do
|
63
|
+
servers = [@jerbil_server, @remote_jerbil_server]
|
64
|
+
my_options = {:log_dir=>log_dir, :log_level=>:debug, :key_file=>key_file}
|
65
|
+
jerbil = Jerbil::Broker.new(@jerbil_server, servers, my_options, @jerbil_key)
|
66
|
+
jerbil.verify.should be_true
|
67
|
+
jerbil.find({}).length.should == 2
|
68
|
+
aservice = jerbil.get({:name=>:rubytest, :env=>:test}, true)
|
69
|
+
aservice.should == @a_service
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should be possible to add a service to the local server and see it remotely" do
|
73
|
+
servers = [@jerbil_server, @remote_jerbil_server]
|
74
|
+
my_options = {:log_dir=>log_dir, :log_level=>:debug, :key_file=>key_file}
|
75
|
+
Socket.stub(:gethostname).and_return(@ant_fqdn)
|
76
|
+
jerbil = Jerbil::Broker.new(@jerbil_server, servers, my_options, @jerbil_key)
|
77
|
+
jerbil.verify.should be_true
|
78
|
+
another_service = Jerbil::ServiceRecord.new(:numbat, :dev)
|
79
|
+
jerbil.register(another_service)
|
80
|
+
Socket.unstub(:gethostname)
|
81
|
+
aservice = @remote_jerbil.get({:name=>:numbat}, true)
|
82
|
+
aservice.should == another_service
|
83
|
+
jerbil.remove(another_service)
|
84
|
+
@remote_jerbil.find({}).length.should == 2
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#
|
2
|
+
# Description
|
3
|
+
#
|
4
|
+
# Author:: Robert Sharp
|
5
|
+
# Copyright:: Copyright (c) 2010 Robert Sharp
|
6
|
+
# License:: Open Software Licence v3.0
|
7
|
+
#
|
8
|
+
# This software is licensed for use under the Open Software Licence v. 3.0
|
9
|
+
# The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
|
10
|
+
# and in the file copyright.txt. Under the terms of this licence, all derivative works
|
11
|
+
# must themselves be licensed under the Open Software Licence v. 3.0
|
12
|
+
#
|
13
|
+
#
|
14
|
+
|
15
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
16
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test/lib/ruby_test')
|
17
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test/lib/ruby_test/config')
|
18
|
+
require 'jerbil/jerbil_service/client'
|
19
|
+
require 'jerbil/errors'
|
20
|
+
require 'socket'
|
21
|
+
|
22
|
+
config_file = File.expand_path(File.dirname(__FILE__) + '/../test/conf.d/test')
|
23
|
+
localhost = Socket.gethostname
|
24
|
+
|
25
|
+
describe "Test Jerbil Client Interface" do
|
26
|
+
|
27
|
+
before(:all) do
|
28
|
+
@client_opts = {:local=>true, :config_file=>config_file, :quiet=>true, :jerbil_env=>:test}
|
29
|
+
end
|
30
|
+
it "should respond to the action method" do
|
31
|
+
JerbilService::Client.connect(RubyTest, @client_opts) do |rubytest|
|
32
|
+
rubytest.action.should == 'Hello'
|
33
|
+
rubytest.verify.should be_true
|
34
|
+
rubytest.host.should == localhost
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should work with multiple client call" do
|
39
|
+
JerbilService::Client.find_services(:all, RubyTest, @client_opts) do |a_service|
|
40
|
+
a_service.connect do |rubytest|
|
41
|
+
rubytest.action.should == 'Hello'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not respond to an unknown method" do
|
47
|
+
JerbilService::Client.connect(RubyTest, @client_opts) do |rubytest|
|
48
|
+
lambda{rubytest.unlikely_method}.should raise_error(NoMethodError)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not allow the stop_callback to be called" do
|
53
|
+
JerbilService::Client.connect(RubyTest, @client_opts) do |rubytest|
|
54
|
+
lambda{rubytest.stop_callback}.should raise_error(Jerbil::UnauthorizedMethod)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "Jerbil Clients that do different things" do
|
61
|
+
before(:all) do
|
62
|
+
@client_opts = {:local=>true, :config_file=>config_file, :quiet=>true, :jerbil_env=>:test}
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should not find an invalid service" do
|
66
|
+
lambda{JerbilService::Client.connect(Blabla)}.should raise_error(NameError)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should find a local service" do
|
70
|
+
JerbilService::Client.connect(RubyTest, @client_opts) do |client|
|
71
|
+
client.action.should == 'Hello'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should not find a local service if it thinks it is somewhere else" do
|
76
|
+
Socket.stub(:gethostname).and_return('germanicus.osburn-sharp.ath.cx', 'lucius.osburn-sharp.ath.cx')
|
77
|
+
lambda{JerbilService::Client.connect(RubyTest, @client_opts)}.should raise_error(Jerbil::ServiceNotFound)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
#
|
2
|
+
# Description
|
3
|
+
#
|
4
|
+
# Author:: Robert Sharp
|
5
|
+
# Copyright:: Copyright (c) 2010 Robert Sharp
|
6
|
+
# License:: Open Software Licence v3.0
|
7
|
+
#
|
8
|
+
# This software is licensed for use under the Open Software Licence v. 3.0
|
9
|
+
# The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
|
10
|
+
# and in the file copyright.txt. Under the terms of this licence, all derivative works
|
11
|
+
# must themselves be licensed under the Open Software Licence v. 3.0
|
12
|
+
#
|
13
|
+
#
|
14
|
+
|
15
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
16
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test/lib/ruby_test')
|
17
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test/lib/ruby_test/config')
|
18
|
+
require 'jerbil/jerbil_service/client'
|
19
|
+
require 'jerbil/errors'
|
20
|
+
require 'socket'
|
21
|
+
|
22
|
+
config_file = File.expand_path(File.dirname(__FILE__) + '/../test/conf.d/ruby_test.rb')
|
23
|
+
jerbil_config = File.expand_path(File.dirname(__FILE__) + '/../test/conf.d/jerbil.conf')
|
24
|
+
log_filename = File.expand_path(File.dirname(__FILE__) + '/../log/client.log')
|
25
|
+
localhost = Socket.gethostname
|
26
|
+
|
27
|
+
describe "Test Jerbil Client Interface" do
|
28
|
+
|
29
|
+
before(:all) do
|
30
|
+
@client_opts = {:local=>true, :config_file=>config_file, :environment=>:dev, :quiet=>true, :jerbil_env=>:test}
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should respond to the old connect method" do
|
34
|
+
client_opts = {:local=>true, :config_file=>config_file, :quiet=>true, :jerbil_env=>:test}
|
35
|
+
JerbilService::Client.connect(RubyTest, client_opts) do |rubytest|
|
36
|
+
rubytest.action.should == 'Hello'
|
37
|
+
rubytest.host.should == localhost
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should respond to the new find_services method" do
|
42
|
+
JerbilService::Client.find_services(:first, RubyTest, @client_opts) do |rubytest|
|
43
|
+
rubytest.action.should == 'Hello'
|
44
|
+
rubytest.host.should == localhost
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should respond to the new find_services method with local service" do
|
49
|
+
JerbilService::Client.find_services(:local, RubyTest, @client_opts) do |rubytest|
|
50
|
+
rubytest.action.should == 'Hello'
|
51
|
+
rubytest.host.should == localhost
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should work with multiple client call" do
|
56
|
+
JerbilService::Client.find_services(:all, RubyTest, @client_opts) do |rubytest|
|
57
|
+
rubytest.action.should == 'Hello'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should work output welcome things with the welcome option" do
|
62
|
+
|
63
|
+
log_file = File.open(log_filename, "w")
|
64
|
+
options = @client_opts.dup
|
65
|
+
options[:welcome] = true
|
66
|
+
options[:output] = log_file
|
67
|
+
options[:quiet] = false
|
68
|
+
JerbilService::Client.find_services(:local, RubyTest, options) do |rubytest|
|
69
|
+
rubytest.action.should == 'Hello'
|
70
|
+
end
|
71
|
+
log_file.close
|
72
|
+
log = File.readlines(log_filename)
|
73
|
+
log[0].should match(/^Welcome/)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should not respond to an unknown method" do
|
77
|
+
JerbilService::Client.find_services(:first, RubyTest, @client_opts) do |rubytest|
|
78
|
+
lambda{rubytest.unlikely_method}.should raise_error(NoMethodError)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should not respond to an unknown search key" do
|
83
|
+
lambda{JerbilService::Client.find_services(:last, RubyTest, @client_opts)}.should raise_error(ArgumentError)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should not allow the stop_callback to be called" do
|
87
|
+
JerbilService::Client.find_services(:first, RubyTest, @client_opts) do |rubytest|
|
88
|
+
lambda{rubytest.stop_callback}.should raise_error(Jerbil::UnauthorizedMethod)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "Jerbil Clients that do different things" do
|
95
|
+
before(:all) do
|
96
|
+
@client_opts = {:local=>true, :config_file=>config_file, :quiet=>true, :jerbil_env=>:test}
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should not find an invalid service" do
|
100
|
+
lambda{JerbilService::Client.connect(Blabla)}.should raise_error(NameError)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should find a local service" do
|
104
|
+
JerbilService::Client.connect(RubyTest, @client_opts) do |client|
|
105
|
+
client.action.should == 'Hello'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should not find a local service if it thinks it is somewhere else" do
|
110
|
+
Socket.stub(:gethostname).and_return('germanicus.osburn-sharp.ath.cx', 'lucius.osburn-sharp.ath.cx')
|
111
|
+
lambda{JerbilService::Client.connect(RubyTest, @client_opts)}.should raise_error(Jerbil::ServiceNotFound)
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#
|
2
|
+
# Description
|
3
|
+
#
|
4
|
+
# Author:: Robert Sharp
|
5
|
+
# Copyright:: Copyright (c) 2010 Robert Sharp
|
6
|
+
# License:: Open Software Licence v3.0
|
7
|
+
#
|
8
|
+
# This software is licensed for use under the Open Software Licence v. 3.0
|
9
|
+
# The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
|
10
|
+
# and in the file copyright.txt. Under the terms of this licence, all derivative works
|
11
|
+
# must themselves be licensed under the Open Software Licence v. 3.0
|
12
|
+
#
|
13
|
+
#
|
14
|
+
|
15
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
16
|
+
require 'jerbil/jerbil_service/client'
|
17
|
+
|
18
|
+
describe "Stopping Jerbil Client" do
|
19
|
+
|
20
|
+
it "should stop" do
|
21
|
+
client = JerbilService::Client.new(:rubytest, :test)
|
22
|
+
client.stop.should be_true
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#
|
2
|
+
# Description
|
3
|
+
#
|
4
|
+
# Author:: Robert Sharp
|
5
|
+
# Copyright:: Copyright (c) 2010 Robert Sharp
|
6
|
+
# License:: Open Software Licence v3.0
|
7
|
+
#
|
8
|
+
# This software is licensed for use under the Open Software Licence v. 3.0
|
9
|
+
# The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
|
10
|
+
# and in the file copyright.txt. Under the terms of this licence, all derivative works
|
11
|
+
# must themselves be licensed under the Open Software Licence v. 3.0
|
12
|
+
#
|
13
|
+
# The purpose of these tests is to check the local interface to a Jerbil Broker only
|
14
|
+
#
|
15
|
+
require 'rubygems'
|
16
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
17
|
+
require 'rspec/mocks/standalone'
|
18
|
+
require 'jerbil/servers'
|
19
|
+
require 'jerbil/service'
|
20
|
+
require 'jerbil/config'
|
21
|
+
require 'jerbil'
|
22
|
+
require 'jellog'
|
23
|
+
|
24
|
+
|
25
|
+
conf_file = File.expand_path(File.dirname(__FILE__) + '/../../test/conf.d/jerbil_test.rb')
|
26
|
+
|
27
|
+
|
28
|
+
describe "A local Jerbil Session running under a daemon" do
|
29
|
+
|
30
|
+
before(:all) do
|
31
|
+
Jellog::Logger.disable_syslog
|
32
|
+
end
|
33
|
+
|
34
|
+
before(:each) do
|
35
|
+
|
36
|
+
my_conf = Jerbil::Config.new(conf_file)
|
37
|
+
test_server = Jerbil::Servers.get_local_server(my_conf[:environment])
|
38
|
+
@my_session = test_server.connect
|
39
|
+
@start_count = @my_session.service_count
|
40
|
+
@registrations = @my_session.registrations
|
41
|
+
@my_service = Jerbil::ServiceRecord.new(:rubytest, :dev)
|
42
|
+
@a_service = Jerbil::ServiceRecord.new(:rubytest, :test)
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
it "should be easily created" do
|
47
|
+
@my_session.started.should be_true
|
48
|
+
@my_session.registrations.should == @registrations
|
49
|
+
@my_session.service_count.should == @start_count
|
50
|
+
@my_session.get_all.should == []
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should be easy to add a service" do
|
54
|
+
@my_session.register(@my_service)
|
55
|
+
@my_session.registrations.should == @registrations + 1
|
56
|
+
@my_session.service_count.should == @start_count + 1
|
57
|
+
services = @my_session.get_all(:ignore_access => true)
|
58
|
+
services[0].should == @my_service
|
59
|
+
service = @my_session.get_local(:ignore_access => true)
|
60
|
+
service.should == @my_service
|
61
|
+
@my_session.find(:name=>'Another', :ignore_access => true).should == []
|
62
|
+
@my_session.remove(@my_service)
|
63
|
+
end
|
64
|
+
|
65
|
+
# cannot stub on a live server so cannot test registration twice without a live service!
|
66
|
+
|
67
|
+
it "should be easy to remove a service" do
|
68
|
+
@my_session.register(@my_service)
|
69
|
+
@my_session.remove(@my_service)
|
70
|
+
@my_session.service_count.should == @start_count
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should do nothing if you remove an unregistered service" do
|
74
|
+
@my_session.register(@my_service)
|
75
|
+
@my_session.remove(@a_service)
|
76
|
+
@my_session.service_count.should == @start_count + 1
|
77
|
+
@my_session.remove(@my_service)
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
#
|
2
|
+
# Description
|
3
|
+
#
|
4
|
+
# Author:: Robert Sharp
|
5
|
+
# Copyright:: Copyright (c) 2010 Robert Sharp
|
6
|
+
# License:: Open Software Licence v3.0
|
7
|
+
#
|
8
|
+
# This software is licensed for use under the Open Software Licence v. 3.0
|
9
|
+
# The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
|
10
|
+
# and in the file copyright.txt. Under the terms of this licence, all derivative works
|
11
|
+
# must themselves be licensed under the Open Software Licence v. 3.0
|
12
|
+
#
|
13
|
+
# The purpose of these tests is to check the remote interface to the Jerbil Server
|
14
|
+
#
|
15
|
+
|
16
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
17
|
+
require 'jerbil/servers'
|
18
|
+
require 'jerbil/service'
|
19
|
+
require 'jerbil/config'
|
20
|
+
require 'jerbil'
|
21
|
+
require 'socket'
|
22
|
+
require 'syslog'
|
23
|
+
require 'jellog'
|
24
|
+
require 'rspec/mocks/standalone'
|
25
|
+
|
26
|
+
conf_file = File.expand_path(File.dirname(__FILE__) + '/../../test/conf.d/jerbil_test.rb')
|
27
|
+
|
28
|
+
|
29
|
+
describe "A Remote Jerbil Session running under a daemon" do
|
30
|
+
|
31
|
+
before(:all) do |variable|
|
32
|
+
@calling_key = 'JKLMNOP'
|
33
|
+
@third_key = 'GFHNBDUC'
|
34
|
+
@pkey = '123456'
|
35
|
+
@calling_server = Jerbil::Servers.new('germanicus.osburn-sharp.ath.cx', @calling_key, :test, 49902)
|
36
|
+
@third_server = Jerbil::Servers.new('antonia.osburn-sharp.ath.cx', @third_key, :test, 49902)
|
37
|
+
@my_service = Jerbil::ServiceRecord.new(:rubytest, :dev)
|
38
|
+
@another_service = Jerbil::ServiceRecord.new(:rubytest, :test)
|
39
|
+
@my_conf = Jerbil::Config.new(conf_file)
|
40
|
+
@secret = @my_conf[:secret]
|
41
|
+
puts @secret
|
42
|
+
@env = @my_conf[:environment]
|
43
|
+
|
44
|
+
test_server = Jerbil::Servers.get_local_server(@my_conf[:environment])
|
45
|
+
@my_session = test_server.connect
|
46
|
+
|
47
|
+
@remote_host = 'germanicus.osburn-sharp.ath.cx'
|
48
|
+
Socket.stub(:gethostname).and_return(@remote_host)
|
49
|
+
@a_service = Jerbil::ServiceRecord.new(:rubytest, :test)
|
50
|
+
Socket.stub(:gethostname).and_return('antonia.osburn-sharp.ath.cx')
|
51
|
+
@b_service = Jerbil::ServiceRecord.new(:rubytest, :prod)
|
52
|
+
Socket.unstub(:gethostname)
|
53
|
+
Jellog::Logger.disable_syslog
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should be easily created" do
|
57
|
+
@my_session.service_count.should == 0
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should be easy to add a remote service" do
|
61
|
+
rkey = @my_session.register_server(@calling_server, @secret, @env)
|
62
|
+
@my_session.register_remote(rkey, @a_service)
|
63
|
+
@my_session.service_count.should == 1
|
64
|
+
@my_session.remote_service_count.should == 1
|
65
|
+
@my_session.detach_server(rkey, @calling_server)
|
66
|
+
@my_session.service_count.should == 0
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should not be possible to register a remote server without a valid secret" do
|
70
|
+
#Syslog.should_not_receive(:info)
|
71
|
+
lambda{@my_session.register_server(@calling_server, 'INVALID', @env)}.should raise_error{Jerbil::JerbilAuthenticationError}
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should not be possible to register a remote service without a valid key" do
|
75
|
+
rkey = @my_session.register_server(@calling_server, @secret, @env)
|
76
|
+
#lambda{@my_session.register_remote('INVALID', @a_service)}.should raise_error{Jerbil::InvalidServerKey}
|
77
|
+
@my_session.register_remote('INVALID', @a_service)
|
78
|
+
@my_session.service_count.should == 0
|
79
|
+
@my_session.detach_server(rkey, @calling_server)
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
it "should be easy to remove a remote service" do
|
84
|
+
rkey = @my_session.register_server(@calling_server, @secret, @env)
|
85
|
+
@my_session.register_remote(rkey, @a_service)
|
86
|
+
@my_session.service_count.should == 1
|
87
|
+
@my_session.remove_remote(rkey, @a_service)
|
88
|
+
@my_session.service_count.should == 0
|
89
|
+
@my_session.detach_server(rkey, @calling_server)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should do nothing if you remove an unregistered remote service" do
|
93
|
+
rkey = @my_session.register_server(@calling_server, @secret, @env)
|
94
|
+
@my_session.register(@my_service)
|
95
|
+
@my_session.remove_remote(rkey, @a_service)
|
96
|
+
@my_session.service_count.should == 1
|
97
|
+
@my_session.detach_server(rkey, @calling_server)
|
98
|
+
@my_session.remove(@my_service)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return a locally registered service when asked" do
|
102
|
+
@my_session.register(@my_service)
|
103
|
+
rkey = @my_session.register_server(@calling_server, @secret, @env)
|
104
|
+
services = @my_session.get_local_services(rkey)
|
105
|
+
services[0].should == @my_service
|
106
|
+
@my_session.register(@another_service)
|
107
|
+
@my_session.local_service_count.should == 2
|
108
|
+
services.length.should == 1
|
109
|
+
#@my_session.detach_server(rkey, @calling_server)
|
110
|
+
@my_session.remove(@my_service)
|
111
|
+
@my_session.remove(@another_service)
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
end
|