right_support 2.8.0 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.8.0
1
+ 2.8.1
@@ -164,6 +164,18 @@ module RightSupport::DB
164
164
  result
165
165
  end
166
166
 
167
+ def namespace(env)
168
+ if env == 'test'
169
+ nspace = "testns"
170
+ else
171
+ nspace = nil
172
+ if File.file?("/etc/namespace")
173
+ nspace = File.read("/etc/namespace").strip
174
+ end
175
+ end
176
+ nspace
177
+ end
178
+
167
179
  # Return current keyspace names as Array of String (any keyspace that has been used this session).
168
180
  #
169
181
  # === Return
@@ -186,7 +198,10 @@ module RightSupport::DB
186
198
  # keyspace(String):: Set the default keyspace
187
199
 
188
200
  def keyspace=(kyspc)
189
- @@default_keyspace = (kyspc + "_" + (ENV['RACK_ENV'] || 'development'))
201
+ env = ENV['RACK_ENV'] || 'development'
202
+ nspace = namespace(env)
203
+ @@default_keyspace = "#{kyspc}_#{env}"
204
+ @@default_keyspace += "_#{nspace}" if nspace
190
205
  end
191
206
 
192
207
  # Temporarily change the working keyspace for this class for the duration of
@@ -200,8 +215,14 @@ module RightSupport::DB
200
215
  def with_keyspace(keyspace, append_env=true, &block)
201
216
  @@current_keyspace = keyspace
202
217
  env = ENV['RACK_ENV'] || 'development'
203
- if append_env && @@current_keyspace !~ /_#{env}$/
204
- @@current_keyspace = "#{@@current_keyspace}_#{env}"
218
+ nspace = namespace(env)
219
+ if append_env
220
+ if nspace
221
+ tail = "_#{env}_#{nspace}"
222
+ else
223
+ tail = "_#{env}"
224
+ end
225
+ @@current_keyspace += tail unless @@current_keyspace.end_with?(tail)
205
226
  end
206
227
  block.call
207
228
  ensure
@@ -247,7 +247,7 @@ module RightSupport::Stats
247
247
  #
248
248
  # @return [Fixnum, NilClass] Average rate or nil if no average rate data
249
249
  def self.avg_rate(stats, total)
250
- sum = stats.inject(nil) { |sum, stat| sum = (sum || 0.0) + (stat["rate"] * stat["total"]) if stat["rate"]; sum }
250
+ sum = stats.inject(nil) { |sum, stat| sum = (sum || 0.0) + (stat["rate"] * stat["total"]) if stat && stat["rate"]; sum }
251
251
  sum / total if sum
252
252
  end
253
253
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{right_support}
8
- s.version = "2.8.0"
8
+ s.version = "2.8.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tony Spataro", "Sergey Sergyenko", "Ryan Williamson", "Lee Kirchhoff", "Alexey Karpik", "Scott Messier"]
@@ -65,7 +65,7 @@ describe RightSupport::DB::CassandraModel do
65
65
  begin
66
66
  ENV['RACK_ENV'] = env
67
67
 
68
- flexmock(Cassandra).should_receive(:new).with(default_keyspace + '_' + env, congig_test , {:timeout=>10}).and_return(default_keyspace_connection)
68
+ flexmock(Cassandra).should_receive(:new).with(/#{default_keyspace}_#{env}/, congig_test , {:timeout=>10}).and_return(default_keyspace_connection)
69
69
  default_keyspace_connection.should_receive(:disable_node_auto_discovery!).and_return(true)
70
70
 
71
71
 
@@ -43,8 +43,8 @@ describe RightSupport::DB::CassandraModel do
43
43
  default_keyspace_connection.should_receive(:disable_node_auto_discovery!).and_return(true)
44
44
  default_keyspace_connection.should_receive(:name).and_return('connection2')
45
45
 
46
- flexmock(Cassandra).should_receive(:new).with(keyspace + '_' + (ENV['RACK_ENV'] || 'development'), "localhost:9160", {:timeout=>10}).and_return(current_keyspace_connection)
47
- flexmock(Cassandra).should_receive(:new).with(default_keyspace + '_' + (ENV['RACK_ENV'] || 'development'), "localhost:9160", {:timeout=>10}).and_return(default_keyspace_connection)
46
+ flexmock(Cassandra).should_receive(:new).with(keyspace + '_' + (ENV['RACK_ENV'] || 'development') + "_testns", "localhost:9160", {:timeout=>10}).and_return(current_keyspace_connection)
47
+ flexmock(Cassandra).should_receive(:new).with(default_keyspace + '_' + (ENV['RACK_ENV'] || 'development') + "_testns", "localhost:9160", {:timeout=>10}).and_return(default_keyspace_connection)
48
48
  end
49
49
 
50
50
  it 'raises a meaningful exception when a config stanza is missing' do
@@ -141,14 +141,14 @@ describe RightSupport::DB::CassandraModel do
141
141
 
142
142
  it 'appends the environment to the keyspace provided' do
143
143
  RightSupport::DB::CassandraModel.keyspace = keyspace
144
- RightSupport::DB::CassandraModel.send(:class_variable_get, :@@default_keyspace).should == (keyspace + "_" + (ENV['RACK_ENV'] || 'development'))
144
+ RightSupport::DB::CassandraModel.send(:class_variable_get, :@@default_keyspace).should == (keyspace + "_" + (ENV['RACK_ENV'] || 'development') + "_testns")
145
145
  end
146
146
  end
147
147
 
148
148
  # If a current keyspace is provided it takes precedence over the default keyspace. If none is
149
149
  # provided, the default keyspace should be returned.
150
150
  context :keyspace do
151
- let(:keyspace) { 'SatelliteService_' + ENV['RACK_ENV'] }
151
+ let(:keyspace) { 'SatelliteService_' + ENV['RACK_ENV'] + "_testns"}
152
152
 
153
153
  it 'returns the default keyspace if no current keyspace is set' do
154
154
  RightSupport::DB::CassandraModel.send(:class_variable_set, :@@current_keyspace, nil)
@@ -177,24 +177,24 @@ describe RightSupport::DB::CassandraModel do
177
177
 
178
178
  it 'sets the current keyspace to the keyspace provided for execution within the block' do
179
179
  RightSupport::DB::CassandraModel.with_keyspace(keyspace) do
180
- RightSupport::DB::CassandraModel.keyspace.should == keyspace + "_" + 'test'
180
+ RightSupport::DB::CassandraModel.keyspace.should == keyspace + "_test_testns"
181
181
  end
182
182
  end
183
183
 
184
184
  it 'resets back to the default keyspace for execution outside of the block' do
185
185
  RightSupport::DB::CassandraModel.with_keyspace(keyspace) {}
186
- RightSupport::DB::CassandraModel.keyspace.should == default_keyspace + "_" + 'test'
186
+ RightSupport::DB::CassandraModel.keyspace.should == default_keyspace + "_test_testns"
187
187
  end
188
188
  context 'append_env parameter' do
189
189
  it 'appends the environment by default' do
190
190
  RightSupport::DB::CassandraModel.with_keyspace('Monkey') do
191
- RightSupport::DB::CassandraModel.keyspace.should == 'Monkey_test'
191
+ RightSupport::DB::CassandraModel.keyspace.should == 'Monkey_test_testns'
192
192
  end
193
193
  end
194
194
 
195
195
  it 'appends the environment when append_env == true' do
196
196
  RightSupport::DB::CassandraModel.with_keyspace('Monkey', true) do
197
- RightSupport::DB::CassandraModel.keyspace.should == 'Monkey_test'
197
+ RightSupport::DB::CassandraModel.keyspace.should == 'Monkey_test_testns'
198
198
  end
199
199
  end
200
200
 
@@ -205,8 +205,8 @@ describe RightSupport::DB::CassandraModel do
205
205
  end
206
206
 
207
207
  it 'avoids double-appending the environment' do
208
- RightSupport::DB::CassandraModel.with_keyspace('Monkey_test') do
209
- RightSupport::DB::CassandraModel.keyspace.should == 'Monkey_test'
208
+ RightSupport::DB::CassandraModel.with_keyspace('Monkey_test_testns') do
209
+ RightSupport::DB::CassandraModel.keyspace.should == 'Monkey_test_testns'
210
210
  end
211
211
  end
212
212
  end
@@ -259,6 +259,14 @@ describe RightSupport::Stats::Activity do
259
259
  {"last" => {"elapsed" => 10, "type" => "foo"}, "total" => 5, "percent" => {"foo" => 20.0, "bar" => 80.0}, "rate" => 0.18}
260
260
  end
261
261
 
262
+ it "handles nil stat" do
263
+ stats = [{"last" => {"elapsed" => 10, "type" => "foo"}, "total" => 1, "percent" => {"foo" => 100.0}},
264
+ nil,
265
+ {"last" => {"elapsed" => 20, "type" => "bar"}, "total" => 4, "percent" => {"bar" => 100.0}}]
266
+ RightSupport::Stats::Activity.all(stats).should ==
267
+ {"last" => {"elapsed" => 10, "type" => "foo"}, "total" => 5, "percent" => {"foo" => 20.0, "bar" => 80.0}}
268
+ end
269
+
262
270
  it "returns nil if there are no stats" do
263
271
  RightSupport::Stats::Activity.all([]).should be_nil
264
272
  end
@@ -272,6 +280,15 @@ describe RightSupport::Stats::Activity do
272
280
  RightSupport::Stats::Activity.percentage(stats, 10).should == {"total" => 10, "percent" => {"foo" => 40.0, "bar" => 60.0}}
273
281
  end
274
282
 
283
+ it "handles nil stat" do
284
+ stats = [{"total" => 1, "percent" => {"foo" => 100.0}},
285
+ nil,
286
+ {"total" => 5, "percent" => {"bar" => 100.0}},
287
+ nil,
288
+ {"total" => 4, "percent" => {"foo" => 75.0, "bar" => 25.0}}]
289
+ RightSupport::Stats::Activity.percentage(stats, 10).should == {"total" => 10, "percent" => {"foo" => 40.0, "bar" => 60.0}}
290
+ end
291
+
275
292
  it "returns only total if there is no data" do
276
293
  RightSupport::Stats::Activity.percentage([], 0).should == {"total" => 0}
277
294
  end
@@ -285,6 +302,15 @@ describe RightSupport::Stats::Activity do
285
302
  RightSupport::Stats::Activity.avg_rate(stats, 10).should == 0.18
286
303
  end
287
304
 
305
+ it "handles nil stat" do
306
+ stats = [{"total" => 1, "rate" => 0.5},
307
+ nil,
308
+ {"total" => 5, "rate" => 0.1},
309
+ nil,
310
+ {"total" => 4, "rate" => 0.2}]
311
+ RightSupport::Stats::Activity.avg_rate(stats, 10).should == 0.18
312
+ end
313
+
288
314
  it "returns nil if there is no data" do
289
315
  RightSupport::Stats::Activity.avg_rate([], 0).should be_nil
290
316
  end
@@ -296,6 +322,12 @@ describe RightSupport::Stats::Activity do
296
322
  {"last" => {"elapsed" => 0, "type" => "foo"}, "total" => 1, "percent" => {"foo" => 100.0}}]
297
323
  end
298
324
 
325
+ it "handles nil stat" do
326
+ stats = [{"last" => {"elapsed" => 0, "type" => "foo"}, "total" => 1, "percent" => {"foo" => 100.0}},
327
+ nil,
328
+ {"last" => {"elapsed" => 0, "type" => "foo"}, "total" => 1, "percent" => {"foo" => 100.0}}]
329
+ end
330
+
299
331
  it "returns nil if there is no data" do
300
332
  RightSupport::Stats::Activity.last([]).should be_nil
301
333
  end
@@ -178,6 +178,7 @@ describe RightSupport::Stats::Exceptions do
178
178
  "when" => @now + 15, "where" => "there"},
179
179
  {"count" => 2, "type" => "ArgumentError", "message" => "badarg",
180
180
  "when" => @now + 30, "where" => "everywhere"}]}},
181
+ nil,
181
182
  {"testing" => {"total" => 1,
182
183
  "recent" => [{"count" => 1, "type" => "ArgumentError", "message" => "awfularg",
183
184
  "when" => @now + 10, "where" => "here"}]}},
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_support
3
3
  version: !ruby/object:Gem::Version
4
- hash: 47
5
- prerelease:
4
+ hash: 45
5
+ prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 8
9
- - 0
10
- version: 2.8.0
9
+ - 1
10
+ version: 2.8.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Spataro
@@ -20,12 +20,11 @@ autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
22
 
23
- date: 2013-08-28 00:00:00 -07:00
23
+ date: 2013-09-06 00:00:00 -07:00
24
24
  default_executable:
25
25
  dependencies:
26
26
  - !ruby/object:Gem::Dependency
27
- type: :development
28
- requirement: &id001 !ruby/object:Gem::Requirement
27
+ version_requirements: &id001 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ~>
@@ -35,12 +34,12 @@ dependencies:
35
34
  - 0
36
35
  - 9
37
36
  version: "0.9"
38
- version_requirements: *id001
37
+ requirement: *id001
38
+ type: :development
39
39
  name: rake
40
40
  prerelease: false
41
41
  - !ruby/object:Gem::Dependency
42
- type: :development
43
- requirement: &id002 !ruby/object:Gem::Requirement
42
+ version_requirements: &id002 !ruby/object:Gem::Requirement
44
43
  none: false
45
44
  requirements:
46
45
  - - ~>
@@ -51,12 +50,12 @@ dependencies:
51
50
  - 8
52
51
  - 3
53
52
  version: 1.8.3
54
- version_requirements: *id002
53
+ requirement: *id002
54
+ type: :development
55
55
  name: jeweler
56
56
  prerelease: false
57
57
  - !ruby/object:Gem::Dependency
58
- type: :development
59
- requirement: &id003 !ruby/object:Gem::Requirement
58
+ version_requirements: &id003 !ruby/object:Gem::Requirement
60
59
  none: false
61
60
  requirements:
62
61
  - - ~>
@@ -66,12 +65,12 @@ dependencies:
66
65
  - 1
67
66
  - 0
68
67
  version: "1.0"
69
- version_requirements: *id003
68
+ requirement: *id003
69
+ type: :development
70
70
  name: right_develop
71
71
  prerelease: false
72
72
  - !ruby/object:Gem::Dependency
73
- type: :development
74
- requirement: &id004 !ruby/object:Gem::Requirement
73
+ version_requirements: &id004 !ruby/object:Gem::Requirement
75
74
  none: false
76
75
  requirements:
77
76
  - - ">="
@@ -81,12 +80,12 @@ dependencies:
81
80
  - 0
82
81
  - 10
83
82
  version: "0.10"
84
- version_requirements: *id004
83
+ requirement: *id004
84
+ type: :development
85
85
  name: ruby-debug
86
86
  prerelease: false
87
87
  - !ruby/object:Gem::Dependency
88
- type: :development
89
- requirement: &id005 !ruby/object:Gem::Requirement
88
+ version_requirements: &id005 !ruby/object:Gem::Requirement
90
89
  none: false
91
90
  requirements:
92
91
  - - ">="
@@ -97,12 +96,12 @@ dependencies:
97
96
  - 11
98
97
  - 6
99
98
  version: 0.11.6
100
- version_requirements: *id005
99
+ requirement: *id005
100
+ type: :development
101
101
  name: ruby-debug19
102
102
  prerelease: false
103
103
  - !ruby/object:Gem::Dependency
104
- type: :development
105
- requirement: &id006 !ruby/object:Gem::Requirement
104
+ version_requirements: &id006 !ruby/object:Gem::Requirement
106
105
  none: false
107
106
  requirements:
108
107
  - - ">="
@@ -113,12 +112,12 @@ dependencies:
113
112
  - 4
114
113
  - 2
115
114
  version: 2.4.2
116
- version_requirements: *id006
115
+ requirement: *id006
116
+ type: :development
117
117
  name: rdoc
118
118
  prerelease: false
119
119
  - !ruby/object:Gem::Dependency
120
- type: :development
121
- requirement: &id007 !ruby/object:Gem::Requirement
120
+ version_requirements: &id007 !ruby/object:Gem::Requirement
122
121
  none: false
123
122
  requirements:
124
123
  - - ~>
@@ -128,12 +127,12 @@ dependencies:
128
127
  - 1
129
128
  - 0
130
129
  version: "1.0"
131
- version_requirements: *id007
130
+ requirement: *id007
131
+ type: :development
132
132
  name: flexmock
133
133
  prerelease: false
134
134
  - !ruby/object:Gem::Dependency
135
- type: :development
136
- requirement: &id008 !ruby/object:Gem::Requirement
135
+ version_requirements: &id008 !ruby/object:Gem::Requirement
137
136
  none: false
138
137
  requirements:
139
138
  - - ~>
@@ -144,12 +143,12 @@ dependencies:
144
143
  - 0
145
144
  - 0
146
145
  version: 1.0.0
147
- version_requirements: *id008
146
+ requirement: *id008
147
+ type: :development
148
148
  name: syntax
149
149
  prerelease: false
150
150
  - !ruby/object:Gem::Dependency
151
- type: :development
152
- requirement: &id009 !ruby/object:Gem::Requirement
151
+ version_requirements: &id009 !ruby/object:Gem::Requirement
153
152
  none: false
154
153
  requirements:
155
154
  - - ~>
@@ -159,7 +158,8 @@ dependencies:
159
158
  - 1
160
159
  - 5
161
160
  version: "1.5"
162
- version_requirements: *id009
161
+ requirement: *id009
162
+ type: :development
163
163
  name: nokogiri
164
164
  prerelease: false
165
165
  description: A toolkit of useful, reusable foundation code created by RightScale.
@@ -320,7 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
320
320
  requirements: []
321
321
 
322
322
  rubyforge_project:
323
- rubygems_version: 1.6.2
323
+ rubygems_version: 1.3.7
324
324
  signing_key:
325
325
  specification_version: 3
326
326
  summary: Reusable foundation code.