Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove duplicated spec and make backup test items independent

Change-Id: I5f82b4dcc0b576b3d6076873320222577e56057e
  • Loading branch information...
commit 4cd055d8c183ab9d135b1588331b33f5e0a6235b 1 parent 5c0cc39
@cliffwang cliffwang authored
View
115 mongodb/spec/mongodb_backup_spec.rb
@@ -5,29 +5,48 @@
describe "mongodb backup/restore" do
before :all do
- EM.run do
- @app_id = "myapp"
- @opts = get_node_config()
- @logger = @opts[:logger]
+ @app_id = "myapp"
+ @opts = get_node_config()
+ @logger = @opts[:logger]
- BINARY_DIR = File.dirname(@opts[:mongod_path])
- @node = Node.new(@opts)
- @resp = @node.provision("free")
+ BINARY_DIR = File.dirname(@opts[:mongod_path])
- @config_template = ERB.new(File.read(TEMPLATE_FILE))
- config = @config_template.result(binding)
- FileUtils.rm_f(CONFIG_FILE)
- File.open(CONFIG_FILE, "w") {|f| f.write(config)}
+ @config_template = ERB.new(File.read(TEMPLATE_FILE))
+ config = @config_template.result(binding)
+ FileUtils.rm_f(CONFIG_FILE)
+ File.open(CONFIG_FILE, "w") {|f| f.write(config)}
+ FileUtils.rm_rf(BACKUP_DIR)
- FileUtils.rm_rf(BACKUP_DIR)
+ EM.run do
+ @node = Node.new(@opts)
+ EM.add_timer(3) { EM.stop }
+ end
+ end
- EM.add_timer(1) do
- @bind_resp = @node.bind(@resp['name'], 'rw')
- EM.add_timer(1) do
- EM.stop
- end
- end
+ before :each do
+ @resp = @node.provision("free")
+ sleep 1
+ @bind_resp = @node.bind(@resp['name'], 'rw')
+ # Write some data in database
+ conn = Mongo::Connection.new(@bind_resp['hostname'], @bind_resp['port']).db(@resp['db'])
+ conn.authenticate(@bind_resp['username'], @bind_resp['password'])
+ coll = conn.collection(TEST_COLL)
+ row = { TEST_KEY => TEST_VAL }
+ coll.insert(row)
+ end
+
+ after :each do
+ @node.unbind(@bind_resp).should be_true
+ EM.run do
+ @node.unprovision(@resp['name'], [])
+ EM.add_timer(3) { EM.stop }
+ end
+ e = nil
+ begin
+ conn = Mongo::Connection.new('localhost', @resp['port']).db('db')
+ rescue => e
end
+ e.should_not be_nil
end
after :all do
@@ -36,22 +55,23 @@
end
it "should be able to backup the database" do
- # Write some data in database
- conn = Mongo::Connection.new(@bind_resp['hostname'], @bind_resp['port']).db(@resp['db'])
- conn.authenticate(@bind_resp['username'], @bind_resp['password'])
- coll = conn.collection(TEST_COLL)
- row = { TEST_KEY => TEST_VAL }
- coll.insert(row)
+ # Run mongodb_backup
+ res = Kernel.system("../bin/mongodb_backup -c #{CONFIG_FILE} -t > /dev/null")
+ res.should == true
+ end
+ it "should be able to restore the database" do
# Run mongodb_backup
res = Kernel.system("../bin/mongodb_backup -c #{CONFIG_FILE} -t > /dev/null")
raise 'mongodb_backup failed' unless res
# Change value after backup
+ conn = Mongo::Connection.new(@bind_resp['hostname'], @bind_resp['port']).db(@resp['db'])
+ conn.authenticate(@bind_resp['username'], @bind_resp['password'])
+ coll = conn.collection(TEST_COLL)
+ row = { TEST_KEY => TEST_VAL }
coll.update(row, { TEST_KEY => TEST_VAL_2 })
- end
- it "should be able to restore the database" do
# Get backup file location
dir = get_backup_dir(BACKUP_DIR)
@@ -62,38 +82,35 @@
sleep 10
# Should be the same like what it was before backup
- conn = Mongo::Connection.new(@bind_resp['hostname'], @bind_resp['port']).db(@resp['db'])
- conn.authenticate(@bind_resp['username'], @bind_resp['password'])
- coll = conn.collection(TEST_COLL)
doc = coll.find_one()
doc[TEST_KEY].should == TEST_VAL
end
- # unbind here
- it "should be able to unbind it" do
- EM.run do
- resp = @node.unbind(@bind_resp)
- resp.should be_true
- EM.add_timer(1) do
- EM.stop
- end
- end
- end
+ it "should be able to recover the backup instance" do
+ # Run mongodb_backup
+ res = Kernel.system("../bin/mongodb_backup -c #{CONFIG_FILE} -t > /dev/null")
+ raise 'mongodb_backup failed' unless res
+
+ # Get backup file location
+ dir = get_backup_dir(BACKUP_DIR)
- # unprovision here
- it "should be able to unprovision an existing instance" do
+ @node.unbind(@bind_resp)
EM.run do
@node.unprovision(@resp['name'], [])
-
- e = nil
- begin
- conn = Mongo::Connection.new('localhost', @resp['port']).db('db')
- rescue => e
- end
- e.should_not be_nil
- EM.stop
+ EM.add_timer(5) { EM.stop }
end
+ @node.provision('free', @resp)
+ @node.restore(@resp['name'], dir)
+ @node.bind(@resp['name'], 'rw', @bind_resp)
+
+ # Should be the same like what it was before backup
+ conn = Mongo::Connection.new(@bind_resp['hostname'], @bind_resp['port']).db(@resp['db'])
+ conn.authenticate(@bind_resp['username'], @bind_resp['password'])
+ coll = conn.collection(TEST_COLL)
+ doc = coll.find_one()
+ doc[TEST_KEY].should == TEST_VAL
end
+
end
View
142 mongodb/spec/mongodb_recovery_spec.rb
@@ -1,142 +0,0 @@
-# Copyright (c) 2009-2011 VMware, Inc.
-$:.unshift(File.dirname(__FILE__))
-require "spec_helper"
-
-describe "mongodb backup/recovery" do
-
- before :all do
- EM.run do
- @app_id = "myapp"
- @opts = get_node_config()
- @logger = @opts[:logger]
-
- @node = Node.new(@opts)
- @resp = @node.provision("free")
-
- @config_template = ERB.new(File.read(TEMPLATE_FILE))
- config = @config_template.result(binding)
- FileUtils.rm_f(CONFIG_FILE)
- File.open(CONFIG_FILE, "w") {|f| f.write(config)}
-
- FileUtils.rm_rf(BACKUP_DIR)
-
- EM.add_timer(1) do
- @bind_resp = @node.bind(@resp['name'], 'rw')
- EM.add_timer(1) do
- EM.stop
- end
- end
- end
- end
-
- after :all do
- FileUtils.rm_f(CONFIG_FILE)
- FileUtils.rm_rf(BACKUP_DIR)
- end
-
- it "should be able to backup the database" do
- # Write some data in database
- conn = Mongo::Connection.new(@bind_resp['hostname'], @bind_resp['port']).db(@resp['db'])
- conn.authenticate(@bind_resp['username'], @bind_resp['password'])
- coll = conn.collection(TEST_COLL)
- row = { TEST_KEY => TEST_VAL }
- coll.insert(row)
-
- # Run mongodb_backup
- res = Kernel.system("../bin/mongodb_backup -c #{CONFIG_FILE} -t > /dev/null")
- raise 'mongodb_backup failed' unless res
-
- # Change value after backup
- coll.update(row, { TEST_KEY => TEST_VAL_2 })
- end
-
- it "should be able to restore the database" do
- # Get backup file location
- dir = get_backup_dir(BACKUP_DIR)
-
- # Run restore
- @node.restore(@resp['name'], dir)
-
- # wait for restore to happen
- sleep 10
-
- # Should be the same like what it was before backup
- conn = Mongo::Connection.new(@bind_resp['hostname'], @bind_resp['port']).db(@resp['db'])
- conn.authenticate(@bind_resp['username'], @bind_resp['password'])
- coll = conn.collection(TEST_COLL)
- doc = coll.find_one()
- doc[TEST_KEY].should == TEST_VAL
- end
-
- # unbind here
- it "should be able to unbind it" do
- EM.run do
- resp = @node.unbind(@bind_resp)
- resp.should be_true
- EM.add_timer(1) do
- EM.stop
- end
- end
- end
-
- # unprovision here
- it "should be able to unprovision an existing instance" do
- EM.run do
- @node.unprovision(@resp['name'], [])
-
- e = nil
- begin
- conn = Mongo::Connection.new('localhost', @resp['port']).db('db')
- rescue => e
- end
- e.should_not be_nil
- EM.stop
- end
- end
-
- it "should be able to recover the backup instance" do
- dir = get_backup_dir(BACKUP_DIR)
- EM.run do
- EM.add_timer(0) { @node.provision('free', @resp) }
- EM.add_timer(2) { @node.restore(@resp['name'], dir) }
- EM.add_timer(10) { @node.bind(@resp['name'], 'rw', @bind_resp) }
- EM.add_timer(11) {
- # Should be the same like what it was before backup
- conn = Mongo::Connection.new(@bind_resp['hostname'], @bind_resp['port']).db(@resp['db'])
- conn.authenticate(@bind_resp['username'], @bind_resp['password'])
- coll = conn.collection(TEST_COLL)
- doc = coll.find_one()
- doc[TEST_KEY].should == TEST_VAL
- EM.stop
- }
- end
- end
-
- # unbind here
- it "should be able to unbind it" do
- EM.run do
- resp = @node.unbind(@bind_resp)
- resp.should be_true
- EM.add_timer(1) do
- EM.stop
- end
- end
- end
-
- # unprovision here
- it "should be able to unprovision an existing instance" do
- EM.run do
- @node.unprovision(@resp['name'], [])
-
- e = nil
- begin
- conn = Mongo::Connection.new('localhost', @resp['port']).db('db')
- rescue => e
- end
- e.should_not be_nil
- EM.stop
- end
- end
-end
-
-
Please sign in to comment.
Something went wrong with that request. Please try again.