beetle 0.3.11 → 0.3.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad7f15bcc3fc114046b8b145690fa981063556e9
4
- data.tar.gz: 9ff40b62cb8df60c788a940c70c59a8daa200443
3
+ metadata.gz: e3bc6495593a123c118fea16b8c9ae46c938dde1
4
+ data.tar.gz: 7f669e64e8369dd0cbe253a59200b9aab15d7334
5
5
  SHA512:
6
- metadata.gz: 657f1cd730ec4e339f77cd23037af84f8809fdd2166b4ab5b16e879121149c976dd465c4bd84a7a40eec1c0bacb500d29e01c8921939e5b3228800f08375f461
7
- data.tar.gz: 1c1faeda610d8fc937ff63a4e7c664be4971e329f00bd120a857e8ec732450fb194c9d9cad5885b4bc8fc04dab005bbf6d72868308c8f020cad2a154a14db9e9
6
+ metadata.gz: 78eeefefc0f8726363c1e396625542f48e21f1bfba9a4e748d4669c4c5ebd718fdd3b2a7dfaf15333fc7a8c7205c528e9fbb8d13e7fad7a0a71a57010e40b3a0
7
+ data.tar.gz: f99c20a06c42abe3a645ae04529789b738562e6b466c977d0f990fbc799a9f7ee1ea3cee7ee4971d3eded438a7eac9cad7882ea78f32fdfd4a226521d3beaea4
data/lib/beetle/client.rb CHANGED
@@ -267,6 +267,18 @@ module Beetle
267
267
  end
268
268
  end
269
269
 
270
+ def reset
271
+ stop_publishing if @publisher
272
+ stop_listening if @subscriber
273
+ config.reload
274
+ rescue Exception => e
275
+ logger.warn("Error resetting client")
276
+ logger.warn(e)
277
+ ensure
278
+ @publisher = nil
279
+ @subscriber = nil
280
+ end
281
+
270
282
  private
271
283
 
272
284
  def determine_queue_names(queues)
@@ -58,6 +58,14 @@ module Beetle
58
58
  # external config file (defaults to <tt>no file</tt>)
59
59
  attr_reader :config_file
60
60
 
61
+ # returns the configured amqp brokers
62
+ def brokers
63
+ {
64
+ 'servers' => self.servers,
65
+ 'additional_subscription_servers' => self.additional_subscription_servers
66
+ }
67
+ end
68
+
61
69
  def initialize #:nodoc:
62
70
  self.system_name = "system"
63
71
 
@@ -90,6 +98,12 @@ module Beetle
90
98
  load_config
91
99
  end
92
100
 
101
+ # reloads the configuration from the configuration file
102
+ # if one is configured
103
+ def reload
104
+ load_config if @config_file
105
+ end
106
+
93
107
  def logger
94
108
  @logger ||=
95
109
  begin
@@ -103,7 +117,12 @@ module Beetle
103
117
 
104
118
  private
105
119
  def load_config
106
- hash = YAML::load(ERB.new(IO.read(config_file)).result)
120
+ raw = ERB.new(IO.read(config_file)).result
121
+ hash = if config_file =~ /\.json$/
122
+ JSON.parse(raw)
123
+ else
124
+ YAML.load(raw)
125
+ end
107
126
  hash.each do |key, value|
108
127
  send("#{key}=", value)
109
128
  end
@@ -39,12 +39,26 @@ module Beetle
39
39
  server_status(response, "plain")
40
40
  when '/initiate_master_switch'
41
41
  initiate_master_switch(response)
42
+ when '/brokers'
43
+ list_brokers(response)
42
44
  else
43
45
  not_found(response)
44
46
  end
45
47
  response.send_response
46
48
  end
47
49
 
50
+ def list_brokers(response)
51
+ brokers = config_server.config.brokers
52
+ response.status = 200
53
+ if @http_headers =~ %r(application/json)
54
+ response.content_type 'application/json'
55
+ response.content = brokers.to_json
56
+ else
57
+ response.content_type 'text/yaml'
58
+ response.content = brokers.to_yaml
59
+ end
60
+ end
61
+
48
62
  def server_status(response, type)
49
63
  response.status = 200
50
64
  status = config_server.status
@@ -1,3 +1,3 @@
1
1
  module Beetle
2
- VERSION = "0.3.11"
2
+ VERSION = "0.3.12"
3
3
  end
@@ -204,6 +204,25 @@ module Beetle
204
204
  end
205
205
 
206
206
  class ClientTest < MiniTest::Unit::TestCase
207
+ test "#reset should stop subscriber and publisher" do
208
+ client = Client.new
209
+ client.send(:publisher).expects(:stop)
210
+ client.send(:subscriber).expects(:stop!)
211
+ client.reset
212
+ end
213
+
214
+ test "#reset should reload the configuration" do
215
+ client = Client.new
216
+ client.config.expects(:reload)
217
+ client.reset
218
+ end
219
+
220
+ test "#reset should not propagate exceptions" do
221
+ client = Client.new
222
+ client.expects(:config).raises(ArgumentError)
223
+ client.reset
224
+ end
225
+
207
226
  test "instantiating a client should not instantiate the subscriber/publisher" do
208
227
  Publisher.expects(:new).never
209
228
  Subscriber.expects(:new).never
@@ -32,5 +32,40 @@ module Beetle
32
32
  Logger.expects(:new).with(file).returns(stub_everything)
33
33
  config.logger
34
34
  end
35
+
36
+ test "#brokers returns a hash of the configured brokers" do
37
+ config = Configuration.new
38
+ assert_equal({"servers"=>"localhost:5672", "additional_subscription_servers"=>""}, config.brokers)
39
+ end
40
+
41
+ test "#config_file can be a JSON file" do
42
+ file = '/path/to/file.json'
43
+ config = Configuration.new
44
+ IO.expects(:read).with(file).returns(
45
+ {
46
+ servers: 'localhost:5772',
47
+ additional_subscription_servers: '10.0.0.1:3001'
48
+ }.to_json)
49
+
50
+ config.config_file = file
51
+
52
+ assert_equal "localhost:5772", config.servers
53
+ assert_equal "10.0.0.1:3001", config.additional_subscription_servers
54
+ end
55
+
56
+ test "#config_file can be a YAML file" do
57
+ file = '/path/to/file.yml'
58
+ config = Configuration.new
59
+ IO.expects(:read).with(file).returns(
60
+ {
61
+ servers: 'localhost:5772',
62
+ additional_subscription_servers: '10.0.0.1:3001'
63
+ }.to_yaml)
64
+
65
+ config.config_file = file
66
+
67
+ assert_equal "localhost:5772", config.servers
68
+ assert_equal "10.0.0.1:3001", config.additional_subscription_servers
69
+ end
35
70
  end
36
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beetle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.11
4
+ version: 0.3.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kaes
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-03-03 00:00:00.000000000 Z
15
+ date: 2015-03-17 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: uuid4r