Permalink
Browse files

function test of mysql recover using cucumber.

Change-Id: Iad1d98abe5e9ddb66aa5d0833a0178e170069ca7
  • Loading branch information...
1 parent d972c64 commit 6208043296bd780a9df2150098b4ce7c449224af Andrew Liu committed May 30, 2011
View
@@ -0,0 +1,4 @@
+desc "Run integration tests."
+task "tests" do |t|
+ system "cd tests; bundle exec rake tests"
+end
View
@@ -0,0 +1,12 @@
+source "http://rubygems.org"
+
+gem "json"
+gem "httpclient"
+gem "rubyzip"
+gem "rake", "0.8.7"
+gem "rspec", "1.3.0"
+gem "cucumber", "0.9.0"
+gem "gherkin", "2.2.4"
+gem "curb"
+gem "nokogiri"
+gem "nats"
View
@@ -0,0 +1,46 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ builder (2.1.2)
+ cucumber (0.9.0)
+ builder (~> 2.1.2)
+ diff-lcs (~> 1.1.2)
+ gherkin (~> 2.2.2)
+ json (~> 1.4.6)
+ term-ansicolor (~> 1.0.5)
+ curb (0.7.15)
+ daemons (1.1.3)
+ diff-lcs (1.1.2)
+ eventmachine (0.12.10)
+ gherkin (2.2.4)
+ json (~> 1.4.6)
+ term-ansicolor (~> 1.0.5)
+ trollop (~> 1.16.2)
+ httpclient (2.2.0.2)
+ json (1.4.6)
+ json_pure (1.5.1)
+ nats (0.4.10)
+ daemons (>= 1.1.0)
+ eventmachine (>= 0.12.10)
+ json_pure (>= 1.5.1)
+ nokogiri (1.4.4)
+ rake (0.8.7)
+ rspec (1.3.0)
+ rubyzip (0.9.4)
+ term-ansicolor (1.0.5)
+ trollop (1.16.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ cucumber (= 0.9.0)
+ curb
+ gherkin (= 2.2.4)
+ httpclient
+ json
+ nats
+ nokogiri
+ rake (= 0.8.7)
+ rspec (= 1.3.0)
+ rubyzip
View
@@ -0,0 +1 @@
+Before run integration test of services repo. Make sure all components are running properly by running `bin/vcap status` at vcap repo.
View
@@ -0,0 +1,8 @@
+require 'rubygems'
+require 'bundler/setup'
+Bundler.require(:default, :test)
+
+# Integration test
+task :tests do
+ sh('bundle exec cucumber')
+end
@@ -0,0 +1,8 @@
+source :rubygems
+
+gem "thin"
+gem "sinatra"
+gem "datamapper"
+gem "yajl-ruby"
+gem "dm-mysql-adapter"
+gem "dm-sqlite-adapter"
@@ -0,0 +1,82 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ addressable (2.2.5)
+ bcrypt-ruby (2.1.4)
+ daemons (1.1.3)
+ data_objects (0.10.3)
+ addressable (~> 2.1)
+ datamapper (1.1.0)
+ dm-aggregates (= 1.1.0)
+ dm-constraints (= 1.1.0)
+ dm-core (= 1.1.0)
+ dm-migrations (= 1.1.0)
+ dm-serializer (= 1.1.0)
+ dm-timestamps (= 1.1.0)
+ dm-transactions (= 1.1.0)
+ dm-types (= 1.1.0)
+ dm-validations (= 1.1.0)
+ dm-aggregates (1.1.0)
+ dm-core (~> 1.1.0)
+ dm-constraints (1.1.0)
+ dm-core (~> 1.1.0)
+ dm-core (1.1.0)
+ addressable (~> 2.2.4)
+ dm-do-adapter (1.1.0)
+ data_objects (~> 0.10.2)
+ dm-core (~> 1.1.0)
+ dm-migrations (1.1.0)
+ dm-core (~> 1.1.0)
+ dm-mysql-adapter (1.1.0)
+ dm-do-adapter (~> 1.1.0)
+ do_mysql (~> 0.10.2)
+ dm-serializer (1.1.0)
+ dm-core (~> 1.1.0)
+ fastercsv (~> 1.5.4)
+ json (~> 1.4.6)
+ dm-sqlite-adapter (1.1.0)
+ dm-do-adapter (~> 1.1.0)
+ do_sqlite3 (~> 0.10.2)
+ dm-timestamps (1.1.0)
+ dm-core (~> 1.1.0)
+ dm-transactions (1.1.0)
+ dm-core (~> 1.1.0)
+ dm-types (1.1.0)
+ bcrypt-ruby (~> 2.1.4)
+ dm-core (~> 1.1.0)
+ fastercsv (~> 1.5.4)
+ json (~> 1.4.6)
+ stringex (~> 1.2.0)
+ uuidtools (~> 2.1.2)
+ dm-validations (1.1.0)
+ dm-core (~> 1.1.0)
+ do_mysql (0.10.3)
+ data_objects (= 0.10.3)
+ do_sqlite3 (0.10.3)
+ data_objects (= 0.10.3)
+ eventmachine (0.12.10)
+ fastercsv (1.5.4)
+ json (1.4.6)
+ rack (1.2.2)
+ sinatra (1.2.1)
+ rack (~> 1.1)
+ tilt (>= 1.2.2, < 2.0)
+ stringex (1.2.1)
+ thin (1.2.11)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+ tilt (1.2.2)
+ uuidtools (2.1.2)
+ yajl-ruby (0.8.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ datamapper
+ dm-mysql-adapter
+ dm-sqlite-adapter
+ sinatra
+ thin
+ yajl-ruby
@@ -0,0 +1,111 @@
+#!/usr/bin/env ruby
+ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __FILE__)
+require "rubygems"
+require "bundler/setup"
+require 'sinatra'
+require 'thin'
+require 'datamapper'
+require 'logger'
+require 'yajl'
+
+# VCAP environment
+port = ENV['VMC_APP_PORT']
+port ||= 8082
+
+class TestApp < Sinatra::Base
+ set :public, File.join(File.dirname(__FILE__) , '/static')
+ set :views, File.join(File.dirname(__FILE__) , '/template')
+
+ class User
+ include DataMapper::Resource
+ property :id, Serial, :key => true
+ property :name, String, :required => true
+ end
+
+ def initialize(opts)
+ super
+ @opts = opts
+ @logger = Logger.new(STDOUT, 'daily')
+ @logger.level = Logger::DEBUG
+ @db= false
+ if @opts[:mysql]
+ @db= true
+ DataMapper.setup(:default, @opts[:mysql])
+ DataMapper::auto_upgrade!
+ end
+ end
+
+ not_found do
+ halt 404
+ end
+
+ error do
+ @logger.error("Error: #{env['sinatra.erro']}")
+ halt 500
+ end
+
+ get '/' do
+ 'It works.'
+ end
+
+ before '/user/*' do
+ if not @db
+ halt 500, "database not enabled."
+ end
+ end
+
+ get '/user/:id' do
+ @logger.debug("Get user #{params[:id]}")
+ user = User.get(params[:id])
+ if user
+ user.name
+ else
+ halt 404
+ end
+ end
+
+ get '/user' do
+ users = User.all
+ res = ""
+ users.each do |user|
+ name = user.name
+ res += "#{name}\n"
+ end
+ res
+ end
+
+ post '/user' do
+ request.body.rewind
+ name = request.body.read
+ @logger.debug("Create a user #{name}")
+ user = User.new
+ user.name = name
+ if not user.save
+ @logger.error("Can't save to db:#{user.errors.pretty_inspect}")
+ halt 500
+ else
+ redirect ("/user/#{user.id}")
+ end
+ end
+
+end
+
+config = {}
+svcs = ENV['VMC_SERVICES']
+if svcs
+ # override db config if VMC_SERVICE atmos service is supplied.
+ svcs = Yajl::Parser.parse(svcs)
+ svcs.each do |svc|
+ if svc["name"] =~ /^mysql/
+ opts = svc["options"]
+ user,passwd,host,db,db_port = %w(user password hostname name port).map {|key|
+ opts[key]}
+ conn_string="mysql://#{user}:#{passwd}@#{host}:#{db_port}/#{db}"
+ config[:mysql] = conn_string
+ end
+ end
+end
+
+puts "Config: #{config.inspect}"
+instance = TestApp.new(config)
+Thin::Server.start('0.0.0.0', port , instance)
@@ -0,0 +1,2 @@
+---
+tmp_dir: /tmp
@@ -0,0 +1,22 @@
+# Copyright (c) 2009-2011 VMware, Inc.
+
+Feature: Service admin tasks
+ As service admin or operator
+ I want to perform admin tasks on serivces
+
+ @creates_service_test_app @provisions_service
+ Scenario: Recover a mysql instance
+ Given I have registered and logged in
+ Given I deploy a service demo application using the "mysql" service
+ When I add 3 user records to service demo application
+ Then I should have the same 3 user records on demo application
+ When I backup "mysql" service
+ When I shutdown "mysql" node
+ When I delete the service from "mysql" node
+ When I delete the service from the local database of "mysql" node
+ When I start "mysql" node
+ Then I should not able to read 3 user records on demo application
+ When I recover "mysql" service
+ # Restart application in case application have cache
+ When I restart the application
+ Then I should have the same 3 user records on demo application
Oops, something went wrong. Retry.

0 comments on commit 6208043

Please sign in to comment.