Skip to content
Browse files

add service limit test - postgresql db size

Change-Id: I0a79965a37cceb9359962f7b72f8406221b5471d
  • Loading branch information...
1 parent e2f752a commit 8eb8fd94a46e2f9e4c5af86a9518640b0de938bb figo committed
2 assets
@@ -1 +1 @@
-Subproject commit abed65e2d2c99ea56024e256d83c02b7f65ffb5c
+Subproject commit ae01fbe1339f8984a42fd84cc37b28445a6da134
View
16 features/service_quota.feature
@@ -0,0 +1,16 @@
+Feature: services quota/limitation verification
+
+ @creates_postgresql_quota_service @creates_service_quota_app
+ Scenario: deploy service quota application with postgresql service
+ When I have postgresql max db size setting
+ Given I have registered and logged in
+ Given I have provisioned a postgresql service
+ Given I have deployed a service quota application that is bound to this service
+ Then I should be able to create a table
+ Then I should be able to insert data under quota
+ When I insert more data to be over quota
+ Then I should not be able to insert data any more
+ Then I should not be able to create objects any more
+ When I delete data from the table
+ Then I should be able to insert data again
+ Then I should be able to create objects
View
106 features/step_definitions/service_quota.rb
@@ -0,0 +1,106 @@
+When /^I have postgresql max db size setting$/ do
+ unless @service_quota_pg_maxdbsize
+ pending "service quota: postgresql max db size is not provided."
+ end
+end
+
+Given /^I have provisioned a postgresql service$/ do
+ pending unless find_service 'postgresql'
+ @postgresql_quota_service = provision_postgresql_quota_service
+ @postgresql_quota_service.should_not == nil
+end
+
+Given /^I have deployed a service quota application that is bound to this service$/ do
+ @app = create_app SERVICE_QUOTA_APP, @token
+ attach_provisioned_service @app, @postgresql_quota_service, @token
+ upload_app @app, @token
+ start_app @app, @token
+ expected_health = 1.0
+ health = poll_until_done @app, expected_health, @token
+ health.should == expected_health
+end
+
+Then /^I should be able to create a table$/ do
+ uri = get_uri(@app, '/service/postgresql/tables/quota_table')
+ r = post_uri(uri, '')
+ r.response_code.should == 200
+ r.body_str.should == 'quota_table'
+ r.close
+end
+
+Then /^I should be able to insert data under quota$/ do
+ mega = @service_quota_pg_maxdbsize.to_i - 1
+ uri = get_uri(@app, "/service/postgresql/tables/quota_table/#{mega}")
+ r = post_uri(uri, '')
+ r.response_code.should == 200
+ r.body_str.should == 'ok'
+ r.close
+end
+
+When /^I insert more data to be over quota$/ do
+ uri = get_uri(@app, '/service/postgresql/tables/quota_table/2')
+ r = post_uri(uri, '')
+ r.response_code.should == 200
+ r.close
+ sleep 2
+end
+
+Then /^I should not be able to insert data any more$/ do
+ uri = get_uri(@app, '/service/postgresql/tables/quota_table/2')
+ r = post_uri(uri, '')
+ r.response_code.should == 200
+ r.body_str.should == "ERROR: permission denied for relation quota_table\n"
+ r.close
+end
+
+Then /^I should not be able to create objects any more$/ do
+ uri = get_uri(@app, '/service/postgresql/tables/test_table')
+ r = post_uri(uri, '')
+ r.response_code.should == 200
+ r.body_str.should == "ERROR: permission denied for schema public\n"
+ #
+ uri = get_uri(@app, '/service/postgresql/functions/test_func')
+ r = post_uri(uri, '')
+ r.response_code.should == 200
+ r.body_str.should == "ERROR: permission denied for schema public\n"
+ #
+ uri = get_uri(@app, '/service/postgresql/sequences/test_seq')
+ r = post_uri(uri, '')
+ r.response_code.should == 200
+ r.body_str.should == "ERROR: permission denied for schema public\n"
+ r.close
+end
+
+When /^I delete data from the table$/ do
+ uri = get_uri(@app, '/service/postgresql/tables/quota_table/data')
+ r = delete_uri(uri)
+ r.response_code.should == 200
+ r.close
+ sleep 2
+end
+
+Then /^I should be able to insert data again$/ do
+ uri = get_uri(@app, '/service/postgresql/tables/quota_table/2')
+ r = post_uri(uri, '')
+ r.response_code.should == 200
+ r.body_str.should == 'ok'
+ r.close
+end
+
+Then /^I should be able to create objects$/ do
+ uri = get_uri(@app, '/service/postgresql/tables/test_table')
+ r = post_uri(uri, '')
+ r.response_code.should == 200
+ r.body_str.should == 'test_table'
+ #
+ uri = get_uri(@app, '/service/postgresql/functions/test_func')
+ r = post_uri(uri, '')
+ r.response_code.should == 200
+ r.body_str.should == 'test_func'
+ #
+ uri = get_uri(@app, '/service/postgresql/sequences/test_seq')
+ r = post_uri(uri, '')
+ r.response_code.should == 200
+ r.body_str.should == 'test_seq'
+ r.close
+end
View
24 features/support/env.rb
@@ -60,6 +60,7 @@
JAVA_APP_WITH_STARTUP_DELAY = "java_app_with_startup_delay"
RAILS_CONSOLE_TEST_APP = "rails_console_test_app"
VBLOB_APP = "vblob_app"
+SERVICE_QUOTA_APP = "service_quota_app"
class Fixnum
def to_json(options = nil)
@@ -91,6 +92,7 @@ def initialize
@resources_uri = "#{@base_uri}/resources"
@services_uri = "#{@base_uri}/services"
@suggest_url = @target
+ @service_quota_pg_maxdbsize = ENV['VCAP_BVT_SERVICE_PG_MAXDBSIZE']
puts "\n** VCAP_BVT_TARGET = '#{@target}' (set environment variable to override) **"
puts "** Running as user: '#{test_user}' (set environment variables VCAP_BVT_USER / VCAP_BVT_USER_PASSWD to override) **"
@@ -191,6 +193,7 @@ def cleanup
delete_app_internal(JAVA_APP_WITH_STARTUP_DELAY)
delete_app_internal(RAILS_CONSOLE_TEST_APP)
delete_app_internal(VBLOB_APP)
+ delete_app_internal(SERVICE_QUOTA_APP)
delete_services(all_my_services) unless @registered_user or !get_login_token
# This used to delete the entire user, but that now requires admin
# privs so it was removed, as was the delete_user method. See the
@@ -664,6 +667,19 @@ def provision_atmos_service token
}
end
+ def provision_postgresql_quota_service
+ name = "#{@namespace}#{@app || 'db_quota_app'}postgresql"
+ @client.create_service(:postgresql, name)
+ service_manifest = {
+ :type=>"database",
+ :vendor=>"postgresql",
+ :tier=>"free",
+ :version=>"9.0",
+ :name=>name,
+ :options=>{"size"=>"128MiB"},
+ }
+ end
+
def provision_brokered_service token
name = "#{@namespace}#{@app || 'brokered_service_app'}_#{@brokered_service_name}"
@client.create_service(@brokered_service_name.to_sym, name)
@@ -915,6 +931,14 @@ def put_record uri, data_hash
easy.close
end
+ def delete_uri uri
+ easy = Curl::Easy.new
+ easy.url = uri
+ easy.resolve_mode =:ipv4
+ easy.http_delete
+ easy
+ end
+
def delete_from_app app, relative_path
uri = get_uri app, relative_path
delete_record uri
View
10 features/support/hooks.rb
@@ -199,3 +199,13 @@
After("@creates_spring_env_app") do |scenario|
delete_app_services_check
end
+
+# service quota
+
+After("@creates_service_quota_app") do |scenario|
+ delete_app @app, @token if @app
+end
+
+After("@creates_postgresql_quota_service") do |scenario|
+ delete_service @postgresql_quota_service[:name] if @postgresql_quota_service
+end
View
6 features/support/testconfig.yml
@@ -303,6 +303,12 @@ vblob_app:
memory: 256
path: "assets/sinatra/vblob_app"
+service_quota_app:
+ framework: "http://b20nine.com/unknown"
+ startup: "ruby main.rb"
+ memory: 512
+ path: "assets/sinatra/app_sinatra_service_quota/"
+
standalone_ruby18_app:
framework: "standalone"
command: "bundle exec ruby main.rb -p $VCAP_APP_PORT"

0 comments on commit 8eb8fd9

Please sign in to comment.
Something went wrong with that request. Please try again.