RingyDingy 1.1.0 → 1.2.0

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/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ = 1.2.0
2
+
3
+ * Split RingyDingy::RingServer::list into ::list_services and
4
+ ::print_services for reuse.
5
+ * Services without the default name no longer reregister multiple times
6
+
1
7
  = 1.1.0
2
8
 
3
9
  * Added ring_server executable (Rinda::RingServer wrapper)
data/lib/ringy_dingy.rb CHANGED
@@ -21,7 +21,7 @@ $TESTING = defined? $TESTING
21
21
 
22
22
  class RingyDingy
23
23
 
24
- VERSION = '1.1.0'
24
+ VERSION = '1.2.0'
25
25
 
26
26
  ##
27
27
  # Interval to check the RingServer for our registration information.
@@ -78,7 +78,7 @@ class RingyDingy
78
78
  # RingServer can't be found or contacted, returns false.
79
79
 
80
80
  def registered?
81
- registrations = ring_server.read_all [:name, :RingyDingy, nil, @identifier]
81
+ registrations = ring_server.read_all [:name, @service, nil, @identifier]
82
82
  registrations.any? { |registration| registration[2] == @object }
83
83
  rescue DRb::DRbConnError
84
84
  @ring_server = nil
@@ -48,33 +48,47 @@ class RingyDingy::RingServer
48
48
 
49
49
  attr_reader :verbose
50
50
 
51
+ RF = Rinda::RingFinger.new
52
+
51
53
  ##
52
- # Print all available services on all available Rinda::RingServers to
53
- # stdout.
54
+ # Return a collection of all remote DRb services.
55
+ #
56
+ # Format:
57
+ #
58
+ # { Rinda::RingServer.__drburi => [ registration_tuple, ... ],
59
+ # ... }
54
60
 
55
- def self.list
61
+ def self.list_services
56
62
  DRb.start_service unless DRb.primary_server
57
63
 
58
- rf = Rinda::RingFinger.new
64
+ services = {}
59
65
 
60
- services = Hash.new { |h,k| h[k] = {} }
61
-
62
- rf.lookup_ring do |ts|
63
- found_services = ts.read_all [:name, nil, DRbObject, nil]
64
- found_services.each do |service|
65
- # #hash and #eql? will not always work
66
- ref = "#{service[2].__drburi}:#{service[2].__drbref}"
67
- services[ts.__drburi][ref] = service
68
- end
66
+ RF.lookup_ring do |ts|
67
+ services[ts.__drburi] = ts.read_all [:name, nil, DRbObject, nil]
69
68
  end
70
69
 
71
- services.each do |ring_server, services|
72
- puts "Services on #{ring_server}:"
73
- services.values.each do |s|
74
- puts "%p, %p\n\tURI: %s ref: %d" %
70
+ return services
71
+ end
72
+
73
+ ##
74
+ # Print all available services on all available Rinda::RingServers to
75
+ # stdout.
76
+
77
+ def self.print_services
78
+ out = []
79
+ list_services.each do |ring_server, services|
80
+ out << "Services on #{ring_server}"
81
+
82
+ values = services.sort_by { |s| [s[2].__drburi, -s[2].__drbref] }
83
+
84
+ values.each do |s|
85
+ out << "\t%p, %p\n\t\tURI: %s ref: %d" %
75
86
  [s[1], s[3], s[2].__drburi, s[2].__drbref]
87
+ out << nil
76
88
  end
77
89
  end
90
+
91
+ puts out.join("\n")
78
92
  end
79
93
 
80
94
  ##
@@ -84,9 +98,7 @@ class RingyDingy::RingServer
84
98
  def self.set_verbose(boolean)
85
99
  DRb.start_service unless DRb.primary_server
86
100
 
87
- rf = Rinda::RingFinger.new
88
-
89
- rf.lookup_ring do |ts|
101
+ RF.lookup_ring do |ts|
90
102
  ts.write [:RingyDingy, :verbose, boolean]
91
103
  end
92
104
  end
@@ -150,7 +162,7 @@ class RingyDingy::RingServer
150
162
  options = process_args args
151
163
 
152
164
  if options.include? :List then
153
- list
165
+ print_services
154
166
  exit
155
167
  elsif options.include? :SetVerbose then
156
168
  set_verbose options[:SetVerbose]
@@ -9,19 +9,119 @@ require 'ringy_dingy/ring_server'
9
9
 
10
10
  DRb.start_service
11
11
 
12
+ class FakeTupleSpace
13
+
14
+ attr_writer :read_all
15
+ attr_accessor :__drburi
16
+
17
+ def read_all(template)
18
+ @read_all
19
+ end
20
+
21
+ end
22
+
12
23
  class RingyDingy::RingServer
24
+
13
25
  attr_accessor :expirations, :registrations, :ts
14
26
  attr_reader :verbose
27
+
28
+ remove_const :RF
29
+
30
+ RF = Object.new
31
+
32
+ def RF.lookup_ring
33
+ ts1 = FakeTupleSpace.new
34
+ ts1.__drburi = 'druby://localhost:10000'
35
+ ts1.read_all = TestRingServer::SERVICES[ts1.__drburi]
36
+ yield ts1
37
+
38
+ ts2 = FakeTupleSpace.new
39
+ ts2.__drburi = 'druby://localhost:10002'
40
+ ts2.read_all = TestRingServer::SERVICES[ts2.__drburi]
41
+ yield ts2 # IPv4
42
+ yield ts2 # IPv6
43
+ end
44
+
15
45
  end
16
46
 
17
47
  class TestRingServer < Test::Unit::TestCase
18
48
 
49
+ OBJS = [Object.new, Object.new, Object.new]
50
+
51
+ OBJS.each_with_index { |obj, i| const_set "OBJ#{i}", obj }
52
+
53
+ SERVICES = {
54
+ 'druby://localhost:10000' => [
55
+ [:name, :RingyDingy, DRbObject.new(OBJ0, 'druby://localhost:10001'),
56
+ 'localhost_9607_obj0'],
57
+ [:name, :RingyDingy, DRbObject.new(OBJ1, 'druby://localhost:10001'),
58
+ 'localhost_9607_obj1'],
59
+ ],
60
+ 'druby://localhost:10002' => [
61
+ [:name, :RingyDingy, DRbObject.new(OBJ2, 'druby://localhost:10003'),
62
+ 'localhost_9607_obj2'],
63
+ ],
64
+ }
65
+
19
66
  def setup
20
67
  util_capture do
21
68
  @rs = RingyDingy::RingServer.new :Verbose => true
22
69
  end
23
70
  end
24
71
 
72
+ def test_self_list_services
73
+ assert_equal SERVICES, RingyDingy::RingServer.list_services
74
+ end
75
+
76
+ def test_self_print_services
77
+ rf = Object.new
78
+
79
+ def rf.lookup_ring
80
+ fts = FakeTupleSpace.new
81
+ fts.__drburi = 'druby://localhost:10000'
82
+ fts.read_all = [
83
+ [:name, :RingyDingy, DRbObject.new(OBJ0, 'druby://localhost:10001'),
84
+ 'localhost_9607_obj0'],
85
+ [:name, :RingyDingy, DRbObject.new(OBJ1, 'druby://localhost:10001'),
86
+ 'localhost_9607_obj1'],
87
+ ]
88
+ yield fts
89
+ fts = FakeTupleSpace.new
90
+ fts.__drburi = 'druby://localhost:10002'
91
+ fts.read_all = [
92
+ [:name, :RingyDingy, DRbObject.new(OBJ2, 'druby://localhost:10003'),
93
+ 'localhost_9607_obj2'],
94
+ ]
95
+ yield fts
96
+ end
97
+
98
+ RingyDingy::RingServer.send :remove_const, :RF
99
+ RingyDingy::RingServer.send :const_set, :RF, rf
100
+
101
+ out, err = util_capture do
102
+ RingyDingy::RingServer.print_services
103
+ end
104
+
105
+ expected = <<-EOF
106
+ Services on druby://localhost:10000
107
+ \t:RingyDingy, "localhost_9607_obj0"
108
+ \t\tURI: druby://localhost:10001 ref: #{OBJ0.object_id}
109
+
110
+ \t:RingyDingy, "localhost_9607_obj1"
111
+ \t\tURI: druby://localhost:10001 ref: #{OBJ1.object_id}
112
+
113
+ Services on druby://localhost:10002
114
+ \t:RingyDingy, "localhost_9607_obj2"
115
+ \t\tURI: druby://localhost:10003 ref: #{OBJ2.object_id}
116
+ EOF
117
+
118
+ assert_equal expected, out.string
119
+ assert_equal '', err.string
120
+ ensure
121
+ RingyDingy::RingServer.send :remove_const, :RF
122
+ RingyDingy::RingServer.send :const_set, :RF, Rinda::RingFinger
123
+ end
124
+
25
125
  def test_initialize_verbose_daemon
26
126
  rs = RingyDingy::RingServer.new :Verbose => true, :Daemon => true
27
127
  assert_equal false, rs.verbose
@@ -31,8 +31,8 @@ class StubRingServer
31
31
  @tuples << args
32
32
  end
33
33
 
34
- def read_all(*args)
35
- @tuples.map { |t,r| t }
34
+ def read_all(template)
35
+ @tuples.map { |t,r| t }.select { |t| t[1] == template[1] }
36
36
  end
37
37
 
38
38
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.99
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: RingyDingy
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.0
7
- date: 2006-10-21 00:00:00 -06:00
6
+ version: 1.2.0
7
+ date: 2006-11-04 00:00:00 -08:00
8
8
  summary: RingyDingy is a little boat that keeps your DRb service afloat!
9
9
  require_paths:
10
10
  - lib