toystore 0.13.1 → 0.13.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/Changelog.md +5 -3
- data/Gemfile +3 -1
- data/README.md +29 -1
- data/gemfiles/rails_3_0.gemfile +2 -0
- data/gemfiles/rails_3_1.gemfile +2 -0
- data/lib/toy.rb +10 -13
- data/lib/toy/callbacks.rb +1 -1
- data/lib/toy/dirty_store.rb +2 -2
- data/lib/toy/identity_map.rb +2 -2
- data/lib/toy/instrumentation/active_support_notifications.rb +5 -0
- data/lib/toy/instrumentation/log_subscriber.rb +49 -0
- data/lib/toy/instrumentation/metriks.rb +5 -0
- data/lib/toy/instrumentation/metriks_subscriber.rb +16 -0
- data/lib/toy/instrumentation/statsd.rb +5 -0
- data/lib/toy/instrumentation/statsd_subscriber.rb +22 -0
- data/lib/toy/instrumentation/subscriber.rb +38 -0
- data/lib/toy/instrumenters/memory.rb +27 -0
- data/lib/toy/instrumenters/noop.rb +9 -0
- data/lib/toy/middleware/identity_map.rb +10 -21
- data/lib/toy/object.rb +0 -1
- data/lib/toy/persistence.rb +22 -4
- data/lib/toy/querying.rb +46 -18
- data/lib/toy/version.rb +1 -1
- data/perf/reads.rb +1 -4
- data/perf/writes.rb +0 -3
- data/spec/helper.rb +4 -12
- data/spec/support/fake_udp_socket.rb +27 -0
- data/spec/support/instrumenter_helpers.rb +14 -0
- data/spec/toy/instrumentation/log_subscriber_spec.rb +85 -0
- data/spec/toy/instrumentation/metriks_subscriber_spec.rb +37 -0
- data/spec/toy/instrumentation/statsd_subscriber_spec.rb +47 -0
- data/spec/toy/instrumenters/memory_spec.rb +26 -0
- data/spec/toy/instrumenters/noop_spec.rb +22 -0
- data/spec/toy/persistence_spec.rb +45 -3
- data/spec/toy/querying_spec.rb +121 -36
- data/spec/toy_spec.rb +14 -16
- metadata +27 -7
- data/lib/toy/logger.rb +0 -15
- data/spec/toy/logger_spec.rb +0 -21
data/spec/toy/querying_spec.rb
CHANGED
@@ -8,13 +8,53 @@ describe Toy::Querying do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
shared_examples_for "adapter read and load instance" do |method_name|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
context "when document found" do
|
12
|
+
before do
|
13
|
+
setup_memory_instrumenter
|
14
|
+
|
15
|
+
@user = User.create(:name => 'John')
|
16
|
+
@result = User.send(method_name, @user.id, {some: 'thing'})
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns document" do
|
20
|
+
@result.should eq(@user)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "is instrumented and sets payload hit to true" do
|
24
|
+
event = instrumenter.events.last
|
25
|
+
event.should_not be_nil
|
26
|
+
event.name.should eq('read.toystore')
|
27
|
+
event.payload.should eq({
|
28
|
+
:id => @user.id,
|
29
|
+
:options => {some: 'thing'},
|
30
|
+
:model => User,
|
31
|
+
:hit => true,
|
32
|
+
})
|
33
|
+
end
|
14
34
|
end
|
15
35
|
|
16
|
-
|
17
|
-
|
36
|
+
context "when document not found" do
|
37
|
+
before do
|
38
|
+
setup_memory_instrumenter
|
39
|
+
|
40
|
+
@id = 'blah'
|
41
|
+
@result = User.send(method_name, @id, {some: 'thing'})
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns nil" do
|
45
|
+
@result.should be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it "is instrumented and sets payload :hit to false" do
|
49
|
+
event = instrumenter.events.last
|
50
|
+
event.should_not be_nil
|
51
|
+
event.payload.should eq({
|
52
|
+
:id => @id,
|
53
|
+
:options => {some: 'thing'},
|
54
|
+
:model => User,
|
55
|
+
:hit => false,
|
56
|
+
})
|
57
|
+
end
|
18
58
|
end
|
19
59
|
|
20
60
|
it "passes options to adapter read" do
|
@@ -54,6 +94,36 @@ describe Toy::Querying do
|
|
54
94
|
}
|
55
95
|
end
|
56
96
|
|
97
|
+
it "is instrumented" do
|
98
|
+
setup_memory_instrumenter
|
99
|
+
|
100
|
+
john = User.create(:name => 'John')
|
101
|
+
steve = User.create(:name => 'Steve')
|
102
|
+
|
103
|
+
ids = [
|
104
|
+
john.id,
|
105
|
+
steve.id,
|
106
|
+
'foo',
|
107
|
+
]
|
108
|
+
|
109
|
+
User.send(method_name, ids, some: 'thing').should == {
|
110
|
+
john.id => john,
|
111
|
+
steve.id => steve,
|
112
|
+
'foo' => nil,
|
113
|
+
}
|
114
|
+
|
115
|
+
event = instrumenter.events.last
|
116
|
+
event.should_not be_nil
|
117
|
+
event.name.should eq('read_multiple.toystore')
|
118
|
+
event.payload.should eq({
|
119
|
+
:ids => ids,
|
120
|
+
:options => {some: 'thing'},
|
121
|
+
:model => User,
|
122
|
+
:hits => 2,
|
123
|
+
:misses => 1,
|
124
|
+
})
|
125
|
+
end
|
126
|
+
|
57
127
|
it "passes options to adapter read_multiple" do
|
58
128
|
john = User.create(:name => 'John')
|
59
129
|
User.adapter.should_receive(:read_multiple).with([john.id], my: 'options').and_return({john.id => {'name' => 'John'}})
|
@@ -62,13 +132,54 @@ describe Toy::Querying do
|
|
62
132
|
end
|
63
133
|
|
64
134
|
shared_examples_for "adapter key?" do |method_name|
|
65
|
-
|
66
|
-
|
67
|
-
|
135
|
+
context "when found" do
|
136
|
+
before do
|
137
|
+
setup_memory_instrumenter
|
138
|
+
|
139
|
+
@user = User.create(:name => 'John')
|
140
|
+
@result = User.send(method_name, @user.id, {some: 'thing'})
|
141
|
+
end
|
142
|
+
|
143
|
+
it "returns true" do
|
144
|
+
@result.should be_true
|
145
|
+
end
|
146
|
+
|
147
|
+
it "is instrumented and sets hit to true" do
|
148
|
+
event = instrumenter.events.last
|
149
|
+
event.should_not be_nil
|
150
|
+
event.name.should eq('key.toystore')
|
151
|
+
event.payload.should eq({
|
152
|
+
:id => @user.id,
|
153
|
+
:options => {some: 'thing'},
|
154
|
+
:model => User,
|
155
|
+
:hit => true,
|
156
|
+
})
|
157
|
+
end
|
68
158
|
end
|
69
159
|
|
70
|
-
|
71
|
-
|
160
|
+
context "when not found" do
|
161
|
+
before do
|
162
|
+
setup_memory_instrumenter
|
163
|
+
|
164
|
+
@id = 'taco:bell:tacos'
|
165
|
+
@result = User.send(method_name, @id, {some: 'thing'})
|
166
|
+
end
|
167
|
+
|
168
|
+
it "returns false" do
|
169
|
+
@result.should be_false
|
170
|
+
end
|
171
|
+
|
172
|
+
it "is instrumented and sets hit to false" do
|
173
|
+
event = instrumenter.events.last
|
174
|
+
event.should_not be_nil
|
175
|
+
event.name.should eq('key.toystore')
|
176
|
+
event.payload.should eq({
|
177
|
+
:id => @id,
|
178
|
+
:options => {some: 'thing'},
|
179
|
+
:model => User,
|
180
|
+
:hit => false,
|
181
|
+
})
|
182
|
+
end
|
72
183
|
end
|
73
184
|
end
|
74
185
|
|
@@ -108,32 +219,6 @@ describe Toy::Querying do
|
|
108
219
|
include_examples "adapter read_multiple and load instances", :find_multiple
|
109
220
|
end
|
110
221
|
|
111
|
-
describe ".get_or_new" do
|
112
|
-
it "returns found" do
|
113
|
-
user = User.create
|
114
|
-
User.get_or_new(user.id).should == user
|
115
|
-
end
|
116
|
-
|
117
|
-
it "creates new with id set if not found" do
|
118
|
-
user = User.get_or_new('foo')
|
119
|
-
user.should be_instance_of(User)
|
120
|
-
user.id.should == 'foo'
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe ".get_or_create" do
|
125
|
-
it "returns found" do
|
126
|
-
user = User.create
|
127
|
-
User.get_or_create(user.id).should == user
|
128
|
-
end
|
129
|
-
|
130
|
-
it "creates new with id set if not found" do
|
131
|
-
user = User.get_or_create('foo')
|
132
|
-
user.should be_instance_of(User)
|
133
|
-
user.id.should == 'foo'
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
222
|
describe ".key?" do
|
138
223
|
include_examples "adapter key?", :key?
|
139
224
|
end
|
data/spec/toy_spec.rb
CHANGED
@@ -3,22 +3,6 @@ require 'helper'
|
|
3
3
|
describe Toy do
|
4
4
|
uses_constants('User', 'Game')
|
5
5
|
|
6
|
-
describe ".logger" do
|
7
|
-
before do
|
8
|
-
@logger = Toy.logger
|
9
|
-
end
|
10
|
-
|
11
|
-
after do
|
12
|
-
Toy.logger = @logger
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should set the default logger" do
|
16
|
-
logger = stub
|
17
|
-
Toy.logger = logger
|
18
|
-
Toy.logger.should == logger
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
6
|
describe ".key_factory" do
|
23
7
|
it "should set the default key_factory" do
|
24
8
|
key_factory = stub
|
@@ -31,4 +15,18 @@ describe Toy do
|
|
31
15
|
Toy.key_factory.should be_instance_of(Toy::Identity::UUIDKeyFactory)
|
32
16
|
end
|
33
17
|
end
|
18
|
+
|
19
|
+
describe ".instrumenter" do
|
20
|
+
it "defaults to noop" do
|
21
|
+
described_class.instrumenter.should eq(Toy::Instrumenters::Noop)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe ".instrumenter=" do
|
26
|
+
it "sets instrumenter" do
|
27
|
+
instrumenter = double('Instrumenter')
|
28
|
+
Toy.instrumenter = instrumenter
|
29
|
+
Toy.instrumenter.should be(instrumenter)
|
30
|
+
end
|
31
|
+
end
|
34
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toystore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-04-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: adapter
|
@@ -140,9 +140,17 @@ files:
|
|
140
140
|
- lib/toy/identity_map.rb
|
141
141
|
- lib/toy/inheritance.rb
|
142
142
|
- lib/toy/inspect.rb
|
143
|
+
- lib/toy/instrumentation/active_support_notifications.rb
|
144
|
+
- lib/toy/instrumentation/log_subscriber.rb
|
145
|
+
- lib/toy/instrumentation/metriks.rb
|
146
|
+
- lib/toy/instrumentation/metriks_subscriber.rb
|
147
|
+
- lib/toy/instrumentation/statsd.rb
|
148
|
+
- lib/toy/instrumentation/statsd_subscriber.rb
|
149
|
+
- lib/toy/instrumentation/subscriber.rb
|
150
|
+
- lib/toy/instrumenters/memory.rb
|
151
|
+
- lib/toy/instrumenters/noop.rb
|
143
152
|
- lib/toy/list.rb
|
144
153
|
- lib/toy/lists.rb
|
145
|
-
- lib/toy/logger.rb
|
146
154
|
- lib/toy/mass_assignment_security.rb
|
147
155
|
- lib/toy/middleware/identity_map.rb
|
148
156
|
- lib/toy/object.rb
|
@@ -165,7 +173,9 @@ files:
|
|
165
173
|
- spec/helper.rb
|
166
174
|
- spec/spec.opts
|
167
175
|
- spec/support/constants.rb
|
176
|
+
- spec/support/fake_udp_socket.rb
|
168
177
|
- spec/support/identity_map_matcher.rb
|
178
|
+
- spec/support/instrumenter_helpers.rb
|
169
179
|
- spec/support/name_and_number_key_factory.rb
|
170
180
|
- spec/support/objects.rb
|
171
181
|
- spec/support/shared_active_model_lint.rb
|
@@ -198,9 +208,13 @@ files:
|
|
198
208
|
- spec/toy/identity_spec.rb
|
199
209
|
- spec/toy/inheritance_spec.rb
|
200
210
|
- spec/toy/inspect_spec.rb
|
211
|
+
- spec/toy/instrumentation/log_subscriber_spec.rb
|
212
|
+
- spec/toy/instrumentation/metriks_subscriber_spec.rb
|
213
|
+
- spec/toy/instrumentation/statsd_subscriber_spec.rb
|
214
|
+
- spec/toy/instrumenters/memory_spec.rb
|
215
|
+
- spec/toy/instrumenters/noop_spec.rb
|
201
216
|
- spec/toy/list_spec.rb
|
202
217
|
- spec/toy/lists_spec.rb
|
203
|
-
- spec/toy/logger_spec.rb
|
204
218
|
- spec/toy/mass_assignment_security_spec.rb
|
205
219
|
- spec/toy/middleware/identity_map_spec.rb
|
206
220
|
- spec/toy/object_spec.rb
|
@@ -230,7 +244,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
230
244
|
version: '0'
|
231
245
|
segments:
|
232
246
|
- 0
|
233
|
-
hash:
|
247
|
+
hash: 4223268135797679612
|
234
248
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
235
249
|
none: false
|
236
250
|
requirements:
|
@@ -239,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
253
|
version: '0'
|
240
254
|
segments:
|
241
255
|
- 0
|
242
|
-
hash:
|
256
|
+
hash: 4223268135797679612
|
243
257
|
requirements: []
|
244
258
|
rubyforge_project:
|
245
259
|
rubygems_version: 1.8.23
|
@@ -250,7 +264,9 @@ test_files:
|
|
250
264
|
- spec/helper.rb
|
251
265
|
- spec/spec.opts
|
252
266
|
- spec/support/constants.rb
|
267
|
+
- spec/support/fake_udp_socket.rb
|
253
268
|
- spec/support/identity_map_matcher.rb
|
269
|
+
- spec/support/instrumenter_helpers.rb
|
254
270
|
- spec/support/name_and_number_key_factory.rb
|
255
271
|
- spec/support/objects.rb
|
256
272
|
- spec/support/shared_active_model_lint.rb
|
@@ -283,9 +299,13 @@ test_files:
|
|
283
299
|
- spec/toy/identity_spec.rb
|
284
300
|
- spec/toy/inheritance_spec.rb
|
285
301
|
- spec/toy/inspect_spec.rb
|
302
|
+
- spec/toy/instrumentation/log_subscriber_spec.rb
|
303
|
+
- spec/toy/instrumentation/metriks_subscriber_spec.rb
|
304
|
+
- spec/toy/instrumentation/statsd_subscriber_spec.rb
|
305
|
+
- spec/toy/instrumenters/memory_spec.rb
|
306
|
+
- spec/toy/instrumenters/noop_spec.rb
|
286
307
|
- spec/toy/list_spec.rb
|
287
308
|
- spec/toy/lists_spec.rb
|
288
|
-
- spec/toy/logger_spec.rb
|
289
309
|
- spec/toy/mass_assignment_security_spec.rb
|
290
310
|
- spec/toy/middleware/identity_map_spec.rb
|
291
311
|
- spec/toy/object_spec.rb
|
data/lib/toy/logger.rb
DELETED
data/spec/toy/logger_spec.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Toy::Logger do
|
4
|
-
uses_objects('User')
|
5
|
-
|
6
|
-
before do
|
7
|
-
@logger = Toy.logger
|
8
|
-
end
|
9
|
-
|
10
|
-
after do
|
11
|
-
Toy.logger = @logger
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should use Toy.logger for class" do
|
15
|
-
User.logger.should == Toy.logger
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should use Toy.logger for instance" do
|
19
|
-
User.new.logger.should == Toy.logger
|
20
|
-
end
|
21
|
-
end
|