Skip to content

Commit

Permalink
RightAws: Tests fix (all are OK but SqsGen2 may be unhappy due to Ama…
Browse files Browse the repository at this point in the history
…zon hiccuping)
  • Loading branch information
Konstantin committed Mar 31, 2010
1 parent 6a06316 commit ee66adf
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 65 deletions.
28 changes: 10 additions & 18 deletions test/acf/test_right_acf.rb
Expand Up @@ -9,7 +9,7 @@ class TestAcf < Test::Unit::TestCase
def setup
@acf= Rightscale::AcfInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
@s3 = Rightscale::S3.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
@bucket_name = "right-acf-awesome-test-bucket-0001"
@bucket_name = "right-acf-awesome-test-bucket-xxx1"
@bucket_domain = "#{@bucket_name}.s3.amazonaws.com"
end

Expand All @@ -27,13 +27,18 @@ def test_02_try_to_create_for_bad_bucket
@acf.create_distribution("right-cloudfront-awesome-test-bucket-not-exist", "Mustn't to be born", true)
end
# a bucket is not a domain naming complied guy
bucket_name = 'right_cloudfront_awesome_test_bucket_BAD'
bucket_name = 'right_cloudfront_awesome_test_bucket_BAD_XXX'
@s3.bucket(bucket_name, :create)
assert_raise(Rightscale::AwsError) do
@acf.create_distribution(bucket_name, "Mustn't to be born", true)
end
end

def test_02_x_delete_bad_bucket
bucket_name = 'right_cloudfront_awesome_test_bucket_BAD_XXX'
@s3.bucket(bucket_name, false).delete
end

def test_03_create
comment = 'WooHoo!!!'
# create a test bucket
Expand Down Expand Up @@ -69,8 +74,8 @@ def test_06_get_and_set_config
end
# change a config
config[:enabled] = false
config[:cnames] << 'x1.myawesomesite.com'
config[:cnames] << 'x2.myawesomesite.com'
config[:cnames] << 'xxx1.myawesomesite.com'
config[:cnames] << 'xxx2.myawesomesite.com'
# set config
set_config_result = nil
assert_nothing_raised do
Expand All @@ -83,7 +88,7 @@ def test_06_get_and_set_config
new_config = @acf.get_distribution_config(old[:aws_id])
end
assert !new_config[:enabled]
assert_equal new_config[:cnames].sort, ['x1.myawesomesite.com', 'x2.myawesomesite.com']
assert_equal new_config[:cnames].sort, ['xxx1.myawesomesite.com', 'xxx2.myawesomesite.com']
assert_not_equal config[:e_tag], new_config[:e_tag]

# try to update the old config again (must fail because ETAG has changed)
Expand All @@ -92,19 +97,6 @@ def test_06_get_and_set_config
end
end

def test_07_caching
# enable caching
@acf.params[:cache] = true
# list distributions
@acf.list_distributions
# list the distributions again - cache should hit
assert_raise(Rightscale::AwsNoChange) do
@acf.list_distributions
end
# disable caching
@acf.params[:cache] = true
end

def test_08_delete_distribution
# we need ETAG so use get_distribution
distribution = @acf.get_distribution(get_test_distribution[:aws_id])
Expand Down
18 changes: 10 additions & 8 deletions test/s3/test_right_s3.rb
Expand Up @@ -6,8 +6,8 @@ class TestS3 < Test::Unit::TestCase

def setup
@s3 = Rightscale::S3Interface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
@bucket = 'right_s3_awesome_test_bucket_000A1'
@bucket2 = 'right_s3_awesome_test_bucket_000A2'
@bucket = 'right_s3_awesome_test_bucket_000B1'
@bucket2 = 'right_s3_awesome_test_bucket_000B2'
@key1 = 'test/woohoo1/'
@key2 = 'test1/key/woohoo2'
@key3 = 'test2/A%B@C_D&E?F+G=H"I'
Expand Down Expand Up @@ -403,17 +403,19 @@ def test_37_access_logging
assert grantee.grant(['READ_ACP', 'WRITE'])

assert bucket.enable_logging(:targetbucket => targetbucket, :targetprefix => "loggylogs/")
sleep 10

assert_equal(bucket.logging_info, {:enabled => true, :targetbucket => @bucket2, :targetprefix => "loggylogs/"})
assert_equal({:enabled => true, :targetbucket => @bucket2, :targetprefix => "loggylogs/"}, bucket.logging_info)

assert bucket.disable_logging

# check 'Drop' method
assert grantee.drop

# Delete bucket
bucket.delete(true)
targetbucket.delete(true)
assert grantee.drop
end

def test_40_delete_buckets
Rightscale::S3::Bucket.create(@s, @bucket, false).delete(true)
Rightscale::S3::Bucket.create(@s, @bucket2, false).delete(true)
end

end
10 changes: 6 additions & 4 deletions test/s3/test_right_s3_stubbed.rb
Expand Up @@ -81,15 +81,17 @@ def test_115_copy_key
def test_116_move_key
# move a key
Rightscale::HttpConnection.push(413, 'not found')
assert @s3.move(@bucket, @key1, @bucket, @key1_new_name)

assert_raise RightAws::AwsError do
@s3.move(@bucket, @key1, @bucket, @key1_new_name)
end
end

def test_117_rename_key
# rename a key
Rightscale::HttpConnection.push(500, 'not found')
assert @s3.rename(@bucket, @key2, @key2_new_name)

assert_raise RightAws::AwsError do
@s3.rename(@bucket, @key2, @key2_new_name)
end
end

end
10 changes: 8 additions & 2 deletions test/sdb/test_right_sdb.rb
Expand Up @@ -11,7 +11,7 @@ def setup
@sdb = Rightscale::SdbInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
end

SDB_DELAY = 2
SDB_DELAY = 7

def wait(delay, msg='')
print "waiting #{delay} seconds #{msg}"
Expand Down Expand Up @@ -104,6 +104,7 @@ def test_07_delete_item
assert_equal values, ['girls', 'vodka']
# delete an item
@sdb.delete_attributes @domain, @item
wait SDB_DELAY, 'after deleting attributes'
# get attributes (values must be empty)
values = @sdb.get_attributes(@domain, @item)[:attributes]['Volodya']
assert_equal values, nil
Expand Down Expand Up @@ -173,6 +174,7 @@ def test_14_nil_attrs
assert_nothing_thrown do
@sdb.put_attributes(@domain, item, {:one=>nil, :two=>nil, :three=>'chunder'})
end
wait SDB_DELAY, 'after putting attributes'
assert_nothing_thrown do
res = @sdb.get_attributes(@domain, item)
end
Expand All @@ -186,6 +188,7 @@ def test_15_url_escape
content = {:a=>"one & two & three",
:b=>"one ? two / three"}
@sdb.put_attributes(@domain, item, content)
wait SDB_DELAY, 'after putting attributes'

res = @sdb.get_attributes(@domain, item)
assert_equal(content[:a], res[:attributes]['a'][0])
Expand All @@ -201,6 +204,7 @@ def test_16_put_attrs_by_post
i += 1
end
@sdb.put_attributes(@domain, item, {:a => sa, :b => sa, :c => sa, :d => sa, :e => sa})
wait SDB_DELAY, 'after putting attributes'
end

def test_20_query_with_atributes
Expand All @@ -209,12 +213,13 @@ def test_20_query_with_atributes
items = {};
response[:items].each{ |item| items.merge!(item) }
# check we have receied all 5 items each full of attributes
assert_equal 5, items.keys.size
assert_equal 6, items.keys.size
assert items['toys'].size > 0
assert items['nils'].size > 0
assert items['urlescapes'].size > 0
assert items['multiples'].size > 0
assert items['reqgirth'].size > 0
assert items['zeroes'].size > 0
# fetch only Jon's attributes from all items
response = @sdb.query_with_attributes(@domain,['Jon'])
items = {};
Expand All @@ -227,6 +232,7 @@ def test_20_query_with_atributes
assert_equal 0, items['urlescapes'].size
assert_equal 0, items['multiples'].size
assert_equal 0, items['reqgirth'].size
assert_equal 0, items['zeroes'].size
# kust Jurgen's attriburs
response = @sdb.query_with_attributes(@domain,['Jurgen'], "['Jurgen'='piglet']")
items = {};
Expand Down
54 changes: 21 additions & 33 deletions test/sqs/test_right_sqs_gen2.rb
Expand Up @@ -10,7 +10,10 @@ def setup
$stdout.sync = true
@grantee_aws_id = '100000000001'
@sqs = Rightscale::SqsGen2Interface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
@queue_name = 'right_sqs_test_gen2_queue'
@queue_name = 'right_sqs_test_gen2_queue'
@queue2_name = @queue_name + '_2'
@queue3_name = @queue_name + '_3'
@queue4_name = @queue_name + '_4'
# for classes
@s = Rightscale::SqsGen2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
end
Expand All @@ -24,7 +27,7 @@ def wait_for_queue_url(queue_name)
do_sleep(180) do
queue_url = @sqs.queue_url_by_name(queue_name)
end
sleep 10
sleep 30
queue_url
end

Expand Down Expand Up @@ -83,8 +86,8 @@ def test_04_get_queue_attributes_forms

def test_05_add_permissions
queue_url = @sqs.queue_url_by_name(@queue_name)
assert @sqs.add_permissions(queue_url, 'test01', @grantee_aws_id => 'SendMessage')
assert @sqs.add_permissions(queue_url, 'test02', @grantee_aws_id => ['DeleteMessage','ReceiveMessage'])
assert @sqs.add_permissions(queue_url, 'test01', @grantee_aws_id, 'SendMessage')
assert @sqs.add_permissions(queue_url, 'test02', @grantee_aws_id, ['DeleteMessage','ReceiveMessage'])
do_sleep 60
end

Expand All @@ -108,7 +111,7 @@ def test_14_send_message
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
do_sleep 30
do_sleep 60
end

def test_15_get_queue_length
Expand Down Expand Up @@ -144,7 +147,7 @@ def test_20_sqs_create_queue
# get queues list
queues_size = @s.queues.size
# create new queue
queue = @s.queue("#{@queue_name}_20", true)
queue = @s.queue(@queue2_name, true)
# check that it is created
assert queue.is_a?(Rightscale::SqsGen2::Queue)
wait_for_queue_url(queue.name)
Expand All @@ -154,21 +157,21 @@ def test_20_sqs_create_queue
end

def test_21_sqs_delete_queue
queue = @s.queue("#{@queue_name}_20", false)
queue = @s.queue(@queue2_name, false)
assert queue.delete
end

def test_22_queue_create
# create new queue
queue = Rightscale::SqsGen2::Queue.create(@s, "#{@queue_name}_21", true)
queue = Rightscale::SqsGen2::Queue.create(@s, @queue3_name, true)
# check that it is created
assert queue.is_a?(Rightscale::SqsGen2::Queue)
wait_for_queue_url(@queue_name)
wait_for_queue_url("#{@queue_name}_21")
do_sleep 10
end

def test_23_queue_attributes
queue = Rightscale::SqsGen2::Queue.create(@s, "#{@queue_name}_21", false)
queue = Rightscale::SqsGen2::Queue.create(@s, @queue3_name, false)
# get a list of attrinutes
attributes = queue.get_attribute
assert attributes.is_a?(Hash) && attributes.size>0
Expand All @@ -177,7 +180,7 @@ def test_23_queue_attributes
# set attribute
assert queue.set_attribute('VisibilityTimeout', v)
# wait a bit
do_sleep 30
do_sleep 60
# check that attribute has changed
assert_equal v, queue.get_attribute('VisibilityTimeout')
# get queue visibility timeout
Expand All @@ -189,32 +192,32 @@ def test_23_queue_attributes
end

def test_24
queue = Rightscale::SqsGen2::Queue.create(@s, "#{@queue_name}_21", false)
queue = Rightscale::SqsGen2::Queue.create(@s, @queue3_name, false)
assert queue.delete
end

def test_25_send_size
queue = Rightscale::SqsGen2::Queue.create(@s, "#{@queue_name}_24", true)
queue = Rightscale::SqsGen2::Queue.create(@s, @queue4_name, true)
# send 5 messages
assert queue.push('a1')
assert queue.push('a2')
assert queue.push('a3')
assert queue.push('a4')
assert queue.push('a5')
#
do_sleep 15
do_sleep(300){ queue.size == 5 }
# check queue size
assert_equal 5, queue.size
# send one more
assert queue.push('a6')
#
do_sleep 15
do_sleep(300){ queue.size == 6 }
# check queue size again
assert_equal 6, queue.size
end

def test_26_message_receive_pop_delete
queue = Rightscale::SqsGen2::Queue.create(@s, "#{@queue_name}_24", false)
queue = Rightscale::SqsGen2::Queue.create(@s, @queue4_name, false)
# get queue size
size = queue.size
# get first message
Expand All @@ -224,7 +227,7 @@ def test_26_message_receive_pop_delete
m2 = queue.pop
assert m2.is_a?(Rightscale::SqsGen2::Message)
#
do_sleep 15
do_sleep 30
# make sure that queue size has decreased
assert_equal size-1, queue.size
# delete messsage
Expand All @@ -236,7 +239,7 @@ def test_26_message_receive_pop_delete
end

def test_27
queue = Rightscale::SqsGen2::Queue.create(@s, "#{@queue_name}_24", false)
queue = Rightscale::SqsGen2::Queue.create(@s, @queue4_name, false)
# lock message
queue.receive(100)
# clear queue
Expand All @@ -257,20 +260,5 @@ def test_28_set_amazon_problems
Rightscale::SqsGen2Interface.amazon_problems= nil
assert_nil(Rightscale::SqsGen2Interface.amazon_problems)
end

def test_29_check_threading_model
assert(!@sqs.multi_thread)
newsqs = Rightscale::SqsGen2Interface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, {:multi_thread => true})
assert(newsqs.multi_thread)
end

def test_30_signature_version_0
sqs = Rightscale::SqsInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :signature_version => '0')
assert_nothing_raised do
sqs.list_queues
end
# check that the request has correct signature version
assert sqs.last_request.path.include?('SignatureVersion=0')
end

end

0 comments on commit ee66adf

Please sign in to comment.