appshot 0.0.3 → 0.0.4

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.
@@ -52,6 +52,14 @@ class Appshot
52
52
  @callables << Appshot::Mysql.new(args)
53
53
  end
54
54
 
55
+ def mongodb(args={})
56
+ @callables << Appshot::MongoDB.new(args)
57
+ end
58
+
59
+ def redis(args={})
60
+ @callables << Appshot::Redis.new(args)
61
+ end
62
+
55
63
  def ebs_prune(args={})
56
64
  @callables << Appshot::EBS_Prune.new(args)
57
65
  end
@@ -0,0 +1,25 @@
1
+ class Appshot
2
+ class MongoDB
3
+
4
+ def initialize(opts={})
5
+ @port = opts[:port] || 27017
6
+ @mongo_binary = opts[:database_command] || "mongo"
7
+ end
8
+
9
+ def call(call_chain)
10
+ next_action = call_chain.shift
11
+ lock
12
+ next_action.call(call_chain) unless next_action.nil?
13
+ ensure
14
+ unlock
15
+ end
16
+
17
+ def lock
18
+ %x[#{@mongo_binary} --host localhost:#{@port} --eval "db.runCommand({ fsync:1, lock:1 })" admin ]
19
+ end
20
+
21
+ def unlock
22
+ %x[#{@mongo_binary} --host localhost:#{@port} --eval "db.$cmd.sys.unlock.findOne()" admin ]
23
+ end
24
+ end
25
+ end
@@ -19,6 +19,7 @@ class Appshot
19
19
 
20
20
  lock
21
21
  next_action.call(call_chain) unless next_action.nil?
22
+ ensure
22
23
  unlock
23
24
  end
24
25
 
@@ -0,0 +1,19 @@
1
+ class Appshot
2
+ class Redis
3
+
4
+ def initialize(opts={})
5
+ @save_before_snapshot = opts[:save_before_snapshot] || false
6
+ @redis_binary = opts[:database_command] || "redis-cli"
7
+ end
8
+
9
+ def call(call_chain)
10
+ next_action = call_chain.shift
11
+ invoke_save if @save_before_snapshot
12
+ next_action.call(call_chain) unless next_action.nil?
13
+ end
14
+
15
+ def invoke_save
16
+ %x[ #{redis_binary} bgsave ]
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  class Appshot
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,37 @@
1
+ require 'appshot/app/mongodb'
2
+
3
+ describe Appshot::MongoDB do
4
+ it { should be_a_kind_of Appshot::MongoDB }
5
+ it { should respond_to(:call) }
6
+
7
+ let(:callable1) { Appshot::MongoDB.new }
8
+ let(:callable2) { Appshot::MongoDB.new }
9
+ let(:items) { [ callable1, callable2 ] }
10
+ let(:mongo) { Appshot::MongoDB.new }
11
+
12
+ describe "#call" do
13
+ before do
14
+ Appshot::MongoDB.any_instance.stub(:lock).and_return(true)
15
+ Appshot::MongoDB.any_instance.stub(:unlock).and_return(true)
16
+ end
17
+ it "should require an argument to #call" do
18
+ lambda { mongo.call }.should raise_error(ArgumentError)
19
+ end
20
+ it "should invoke #call on the next object in the call_chain" do
21
+ callable1.should_receive(:call).with(items)
22
+ mongo.call(items)
23
+ end
24
+
25
+ it "should run #lock before call is invoked" do
26
+ callable1.should_receive(:call).with([callable2])
27
+ mongo.should_receive(:lock)
28
+ mongo.call(items)
29
+ end
30
+
31
+ it "should run #unlock after call is invoked" do
32
+ callable1.should_receive(:call).with([callable2])
33
+ mongo.should_receive(:unlock)
34
+ mongo.call(items)
35
+ end
36
+ end
37
+ end
@@ -2,36 +2,39 @@ require 'appshot/app/mysql'
2
2
  require 'mysql2'
3
3
 
4
4
  describe Appshot::Mysql do
5
- subject { Appshot::Mysql.new }
6
5
  it { should be_a_kind_of Appshot::Mysql }
7
- it { subject.respond_to?(:call).should be_true }
6
+ it { should respond_to(:call) }
7
+
8
+ let(:mysql) { Appshot::Mysql.new }
8
9
 
9
10
  describe "#call" do
10
11
  before do
11
12
  Mysql2::Client.stub(:new).and_return(mysql)
13
+ Appshot::Mysql.any_instance.stub(:lock).and_return(true)
14
+ Appshot::Mysql.any_instance.stub(:unlock).and_return(true)
12
15
  end
13
- let(:mysql) { double(:mysql2, query: true, close: true) }
16
+
17
+ let(:callable1) { Appshot::Mysql.new }
18
+ let(:callable2) { Appshot::Mysql.new }
19
+ let(:items) { [ callable1, callable2 ] }
14
20
 
15
21
  it "should require an argument to #call" do
16
- lambda { subject.call }.should raise_error(ArgumentError)
22
+ lambda { mysql.call }.should raise_error(ArgumentError)
17
23
  end
18
24
 
19
25
  it "should invoke #call on the next object in the call_chain" do
20
- items = [double(:appshot1), double(:appshot2)]
21
- items.first.should_receive(:call).with(items).and_return(true)
22
- subject.call(items)
26
+ mysql.should_receive(:call).with(items).and_return(true)
27
+ mysql.call(items)
23
28
  end
24
29
 
25
30
  it "should run #lock before call is invoked" do
26
- items = [Appshot::Mysql.new, Appshot::Mysql.new]
27
- items.first.should_receive(:lock)
28
- subject.call(items)
31
+ mysql.should_receive(:lock)
32
+ mysql.call(items)
29
33
  end
30
34
 
31
35
  it "should run #unlock after call is invoked" do
32
- items = [Appshot::Mysql.new, Appshot::Mysql.new]
33
- items.first.should_receive(:unlock)
34
- subject.call(items)
36
+ mysql.should_receive(:unlock)
37
+ mysql.call(items)
35
38
  end
36
39
  end
37
40
  end
@@ -0,0 +1,43 @@
1
+ require 'appshot/app/redis'
2
+
3
+ describe Appshot::Redis do
4
+ it { should be_a_kind_of Appshot::Redis }
5
+ it { should respond_to(:call) }
6
+
7
+ let(:redis) { Appshot::Redis.new }
8
+
9
+ describe "#call" do
10
+ before do
11
+ Appshot::Redis.any_instance.stub(:invoke_save).and_return(true)
12
+ end
13
+ let(:callable1) { Appshot::Redis.new }
14
+ let(:callable2) { Appshot::Redis.new }
15
+ let(:items) { [ callable1, callable2 ] }
16
+
17
+
18
+ it "should require an argument to #call" do
19
+ lambda { redis.call }.should raise_error(ArgumentError)
20
+ end
21
+
22
+ it "should invoke #call on the next object in the call_chain" do
23
+ redis.should_receive(:call).with(items).and_return(true)
24
+ redis.call(items)
25
+ end
26
+
27
+ describe "with save_before_snapshot" do
28
+ context "set to false" do
29
+ it "should not run #invoke_save" do
30
+ redis.should_not_receive(:invoke_save)
31
+ redis.call(items)
32
+ end
33
+ end
34
+ context "set to true" do
35
+ let(:redis) { Appshot::Redis.new(save_before_snapshot: true) }
36
+ it "should run #invoke_save" do
37
+ redis.should_receive(:invoke_save)
38
+ redis.call(items)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-08 00:00:00.000000000 Z
12
+ date: 2012-08-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
@@ -244,7 +244,9 @@ files:
244
244
  - features/support/env.rb
245
245
  - lib/appshot.rb
246
246
  - lib/appshot/app.rb
247
+ - lib/appshot/app/mongodb.rb
247
248
  - lib/appshot/app/mysql.rb
249
+ - lib/appshot/app/redis.rb
248
250
  - lib/appshot/filesystem.rb
249
251
  - lib/appshot/filesystem/dm.rb
250
252
  - lib/appshot/version.rb
@@ -253,7 +255,9 @@ files:
253
255
  - lib/appshot/volume/ebs_snapshot.rb
254
256
  - lib/appshot/volume/ebs_volume.rb
255
257
  - rvmrc.example
258
+ - spec/lib/appshot/app/mongodb_spec.rb
256
259
  - spec/lib/appshot/app/mysql_spec.rb
260
+ - spec/lib/appshot/app/redis_spec.rb
257
261
  - spec/lib/appshot/filesystem/dm_spec.rb
258
262
  - spec/lib/appshot/volume/ebs_prune_spec.rb
259
263
  - spec/lib/appshot/volume/ebs_snapshot_spec.rb
@@ -274,7 +278,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
274
278
  version: '0'
275
279
  segments:
276
280
  - 0
277
- hash: 4374607639784639822
281
+ hash: -2737267038638303815
278
282
  required_rubygems_version: !ruby/object:Gem::Requirement
279
283
  none: false
280
284
  requirements:
@@ -283,7 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
283
287
  version: '0'
284
288
  segments:
285
289
  - 0
286
- hash: 4374607639784639822
290
+ hash: -2737267038638303815
287
291
  requirements: []
288
292
  rubyforge_project:
289
293
  rubygems_version: 1.8.24
@@ -294,7 +298,9 @@ test_files:
294
298
  - features/appshot.feature
295
299
  - features/step_definitions/appshot_steps.rb
296
300
  - features/support/env.rb
301
+ - spec/lib/appshot/app/mongodb_spec.rb
297
302
  - spec/lib/appshot/app/mysql_spec.rb
303
+ - spec/lib/appshot/app/redis_spec.rb
298
304
  - spec/lib/appshot/filesystem/dm_spec.rb
299
305
  - spec/lib/appshot/volume/ebs_prune_spec.rb
300
306
  - spec/lib/appshot/volume/ebs_snapshot_spec.rb