1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[aws|simpledb] fixes

more granular idempotency
convert specs to tests
This commit is contained in:
geemus 2011-01-03 18:55:24 -08:00
parent 724de430de
commit 9a52c94513
21 changed files with 154 additions and 358 deletions

View file

@ -18,6 +18,7 @@ module Fog
request(
'Action' => 'CreateDomain',
'DomainName' => domain_name,
:idempotent => true,
:parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string)
)
end

View file

@ -44,8 +44,6 @@ module Fog
@data[:domains][domain_name][key].delete('value')
end
end
else
@data[:domains].delete(domain_name)
end
response.status = 200
response.body = {

View file

@ -18,6 +18,7 @@ module Fog
request(
'Action' => 'DeleteDomain',
'DomainName' => domain_name,
:idempotent => true,
:parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string)
)
end

View file

@ -27,6 +27,7 @@ module Fog
request(
'Action' => 'DomainMetadata',
'DomainName' => domain_name,
:idempotent => true,
:parser => Fog::Parsers::AWS::SimpleDB::DomainMetadata.new(@nil_string)
)
end

View file

@ -31,6 +31,7 @@ module Fog
'Action' => 'GetAttributes',
'DomainName' => domain_name,
'ItemName' => item_name,
:idempotent => true,
:parser => Fog::Parsers::AWS::SimpleDB::GetAttributes.new(@nil_string)
}.merge!(encode_attribute_names(attributes)))
end

View file

@ -22,8 +22,9 @@ module Fog
# * 'RequestId'
def list_domains(options = {})
request({
'Action' => 'ListDomains',
:parser => Fog::Parsers::AWS::SimpleDB::ListDomains.new(@nil_string)
'Action' => 'ListDomains',
:idempotent => true,
:parser => Fog::Parsers::AWS::SimpleDB::ListDomains.new(@nil_string)
}.merge!(options))
end

View file

@ -30,8 +30,8 @@ module Fog
request({
'Action' => 'PutAttributes',
'DomainName' => domain_name,
:parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string),
'ItemName' => item_name
'ItemName' => item_name,
:parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string)
}.merge!(encode_attributes(attributes, options[:replace], options[:expect])))
end

View file

@ -24,6 +24,7 @@ module Fog
'Action' => 'Select',
'NextToken' => next_token,
'SelectExpression' => select_expression,
:idempotent => true,
:parser => Fog::Parsers::AWS::SimpleDB::Select.new(@nil_string)
)
end

View file

@ -130,6 +130,7 @@ module Fog
end
def request(params)
idempotent = params.delete(:idempotent)
parser = params.delete(:parser)
body = AWS.signed_params(
@ -149,7 +150,7 @@ module Fog
:expects => 200,
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
:host => @host,
:idempotent => true,
:idempotent => idempotent,
:method => 'POST',
:parser => parser
})

View file

@ -1,31 +0,0 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'SimpleDB.batch_put_attributes' do
describe 'success' do
before(:all) do
@domain_name = "fog_domain_#{Time.now.to_i}"
AWS[:sdb].create_domain(@domain_name)
end
after(:all) do
AWS[:sdb].delete_domain(@domain_name)
end
it 'should return proper attributes' do
actual = AWS[:sdb].batch_put_attributes(@domain_name, { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } })
actual.body['RequestId'].should be_a(String)
actual.body['BoxUsage'].should be_a(Float)
end
end
describe 'failure' do
it 'should raise a BadRequest error if the domain does not exist' do
lambda {
AWS[:sdb].batch_put_attributes('notadomain', { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } })
}.should raise_error(Excon::Errors::BadRequest)
end
end
end

View file

@ -1,29 +0,0 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'SimpleDB.create_domain' do
before(:each) do
@domain_name = "fog_domain_#{Time.now.to_i}"
end
after(:each) do
AWS[:sdb].delete_domain(@domain_name)
end
describe 'success' do
it 'should return proper attributes' do
actual = AWS[:sdb].create_domain(@domain_name)
actual.body['RequestId'].should be_a(String)
actual.body['BoxUsage'].should be_a(Float)
end
end
describe 'failure' do
it 'should not raise an error if the domain already exists' do
AWS[:sdb].create_domain(@domain_name)
AWS[:sdb].create_domain(@domain_name)
end
end
end

View file

@ -1,39 +0,0 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'SimpleDB.delete_attributes' do
describe 'success' do
before(:each) do
@domain_name = "fog_domain_#{Time.now.to_i}"
AWS[:sdb].create_domain(@domain_name)
AWS[:sdb].put_attributes(@domain_name, 'foo', { :bar => :baz })
end
after(:each) do
AWS[:sdb].delete_domain(@domain_name)
end
it 'should return proper attributes from delete_attributes' do
actual = AWS[:sdb].delete_attributes(@domain_name, 'foo')
actual.body['RequestId'].should be_a(String)
actual.body['BoxUsage'].should be_a(Float)
end
end
describe 'failure' do
it 'shouild raise a BadRequest error if the domain does not exist' do
lambda {
AWS[:sdb].delete_attributes('notadomain', 'notanattribute')
}.should raise_error(Excon::Errors::BadRequest)
end
it 'should not raise an error if the attribute does not exist' do
@domain_name = "fog_domain_#{Time.now.to_i}"
AWS[:sdb].create_domain(@domain_name)
AWS[:sdb].delete_attributes(@domain_name, 'notanattribute')
AWS[:sdb].delete_domain(@domain_name)
end
end
end

View file

@ -1,28 +0,0 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'SimpleDB.delete_domain' do
describe 'success' do
before(:each) do
@domain_name = "fog_domain_#{Time.now.to_i}"
end
before(:each) do
AWS[:sdb].create_domain(@domain_name)
end
it 'should return proper attributes' do
actual = AWS[:sdb].delete_domain(@domain_name)
actual.body['RequestId'].should be_a(String)
actual.body['BoxUsage'].should be_a(Float)
end
end
describe 'failure' do
it 'should not raise an error if the domain does not exist' do
AWS[:sdb].delete_domain('notadomain')
end
end
end

View file

@ -1,52 +0,0 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'SimpleDB.domain_metadata' do
describe 'success' do
before(:each) do
@domain_name = "fog_domain_#{Time.now.to_i}"
AWS[:sdb].create_domain(@domain_name)
end
after(:each) do
AWS[:sdb].delete_domain(@domain_name)
end
it 'should return proper attributes when there are no items' do
results = AWS[:sdb].domain_metadata(@domain_name)
results.body['AttributeNameCount'].should == 0
results.body['AttributeNamesSizeBytes'].should == 0
results.body['AttributeValueCount'].should == 0
results.body['AttributeValuesSizeBytes'].should == 0
results.body['BoxUsage'].should be_a(Float)
results.body['ItemCount'].should == 0
results.body['ItemNamesSizeBytes'].should == 0
results.body['RequestId'].should be_a(String)
results.body['Timestamp'].should be_a(Time)
end
it 'should return proper attributes with items' do
AWS[:sdb].put_attributes(@domain_name, 'foo', { :bar => :baz })
results = AWS[:sdb].domain_metadata(@domain_name)
results.body['AttributeNameCount'].should == 1
results.body['AttributeNamesSizeBytes'].should == 3
results.body['AttributeValueCount'].should == 1
results.body['AttributeValuesSizeBytes'].should == 3
results.body['BoxUsage'].should be_a(Float)
results.body['ItemCount'].should == 1
results.body['ItemNamesSizeBytes'].should == 3
results.body['RequestId'].should be_a(String)
results.body['Timestamp'].should be_a(Time)
end
end
describe 'failure' do
it 'should raise a BadRequest error if the domain does not exist' do
lambda {
AWS[:sdb].domain_metadata('notadomain')
}.should raise_error(Excon::Errors::BadRequest)
end
end
end

View file

@ -1,67 +0,0 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'SimpleDB.get_attributes' do
describe 'success' do
before(:each) do
@domain_name = "fog_domain_#{Time.now.to_i}"
AWS[:sdb].create_domain(@domain_name)
end
after(:each) do
AWS[:sdb].delete_domain(@domain_name)
end
it 'should have no attributes for foo before put_attributes' do
Fog.wait_for do
actual = AWS[:sdb].get_attributes(@domain_name, 'foo')
actual.body['Attributes'].empty?
end
end
it 'should return multi-value attributes from get_attributes' do
AWS[:sdb].put_attributes(@domain_name, 'buzz', { "attr" => "foo" })
AWS[:sdb].put_attributes(@domain_name, 'buzz', { "attr" => "foo2" })
Fog.wait_for do
actual = AWS[:sdb].get_attributes(@domain_name, 'buzz')
actual.body["Attributes"]["attr"] == ['foo', 'foo2']
end
end
it 'should have attributes for foo after put_attributes' do
AWS[:sdb].put_attributes(@domain_name, 'foo', { :bar => :baz })
Fog.wait_for do
actual = AWS[:sdb].get_attributes(@domain_name, 'foo')
actual.body['Attributes'] == { 'bar' => ['baz'] }
end
end
context "foo item is put with bar attribute as an array" do
it "should return the array for foo's bar attribute" do
the_array = %w{A B C}
AWS[:sdb].put_attributes(@domain_name, 'foo', { :bar => the_array })
Fog.wait_for do
actual = AWS[:sdb].get_attributes(@domain_name, 'foo')
actual.body['Attributes']['bar'] == the_array
end
end
end
end
describe 'failure' do
it 'should raise a BadRequest error if the domain does not exist' do
lambda {
AWS[:sdb].get_attributes('notadomain', 'notanattribute')
}.should raise_error(Excon::Errors::BadRequest)
end
it 'should not raise an error if the attribute does not exist' do
@domain_name = "fog_domain_#{Time.now.to_i}"
AWS[:sdb].create_domain(@domain_name)
AWS[:sdb].get_attributes(@domain_name, 'notanattribute')
AWS[:sdb].delete_domain(@domain_name)
end
end
end

View file

@ -1,29 +0,0 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'SimpleDB.list_domains' do
describe 'success' do
before(:each) do
@domain_name = "fog_domain_#{Time.now.to_i}"
end
after(:each) do
AWS[:sdb].delete_domain(@domain_name)
end
it 'should return proper attributes' do
results = AWS[:sdb].list_domains
results.body['BoxUsage'].should be_a(Float)
results.body['Domains'].should be_an(Array)
results.body['RequestId'].should be_a(String)
end
it 'should include created domains' do
AWS[:sdb].create_domain(@domain_name)
Fog.wait_for do
AWS[:sdb].list_domains.body['Domains'].include?(@domain_name)
end
end
end
end

View file

@ -1,49 +0,0 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'SimpleDB.put_attributes' do
describe 'success' do
before(:each) do
@domain_name = "fog_domain_#{Time.now.to_i}"
AWS[:sdb].create_domain(@domain_name)
end
after(:each) do
AWS[:sdb].delete_domain(@domain_name)
end
it 'should return proper attributes from put_attributes' do
actual = AWS[:sdb].put_attributes(@domain_name, 'foo', { 'bar' => 'baz' })
actual.body['RequestId'].should be_a(String)
actual.body['BoxUsage'].should be_a(Float)
end
it 'conditional put should succeed' do
AWS[:sdb].put_attributes(@domain_name, 'foo', { 'version' => '1' })
AWS[:sdb].put_attributes(@domain_name, 'foo', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version'])
actual = AWS[:sdb].put_attributes(@domain_name, 'foo', { 'version' => '3' }, :expect => { 'version' => '2' }, :replace => ['version'])
actual.body['RequestId'].should be_a(String)
actual.body['BoxUsage'].should be_a(Float)
end
it 'conditional put should raise Conflict error' do
actual = AWS[:sdb].put_attributes(@domain_name, 'foo', { 'version' => '2' }, :replace => ['version'])
actual.body['RequestId'].should be_a(String)
actual.body['BoxUsage'].should be_a(Float)
lambda {
actual = AWS[:sdb].put_attributes(@domain_name, 'foo', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version'])
}.should raise_error(Excon::Errors::Conflict)
end
end
describe 'failure' do
it 'should raise a BadRequest error if the domain does not exist' do
lambda {
AWS[:sdb].put_attributes(@domain_name, 'notadomain', { 'notanattribute' => 'value' })
}.should raise_error(Excon::Errors::BadRequest)
end
end
end

View file

@ -1,27 +0,0 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'SimpleDB.select' do
describe 'success' do
before(:each) do
@domain_name = "fog_domain_#{Time.now.to_i}"
AWS[:sdb].create_domain(@domain_name)
end
after(:each) do
AWS[:sdb].delete_domain(@domain_name)
end
it 'should return multi-value attributes when present' do
pending if Fog.mocking?
@item = "someitem_fog_domain_#{Time.now.to_i}"
AWS[:sdb].put_attributes(@domain_name, @item, { "attr" => "foo" })
AWS[:sdb].put_attributes(@domain_name, @item, { "attr" => "foo2" })
Fog.wait_for do
actual = AWS[:sdb].select("select * from #{@domain_name}")
actual.body['Items'][@item]["attr"] == ['foo','foo2']
end
end
end
end

View file

@ -0,0 +1,75 @@
Shindo.tests('AWS::SimpleDB | attributes requests', ['aws']) do
@domain_name = "fog_domain_#{Time.now.to_f.to_s.gsub('.','')}"
AWS[:sdb].create_domain(@domain_name)
tests('success') do
tests("#batch_put_attributes('#{@domain_name}', { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } }).body").formats(AWS::SimpleDB::Formats::BASIC) do
AWS[:sdb].batch_put_attributes(@domain_name, { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } }).body
end
tests("#get_attributes('#{@domain_name}', 'a').body['Attributes']").returns({'b' => ['c']}) do
attributes = {}
Fog.wait_for {
attributes = AWS[:sdb].get_attributes(@domain_name, 'a').body['Attributes']
attributes != {}
}
attributes
end
tests("#get_attributes('#{@domain_name}', 'notanattribute')").succeeds do
AWS[:sdb].get_attributes(@domain_name, 'notanattribute')
end
tests("#select('select * from #{@domain_name}').body['Items']").returns({ 'a' => { 'b' => ['c'] }, 'x' => { 'y' => ['z'] } }) do
pending if Fog.mocking?
AWS[:sdb].select("select * from #{@domain_name}").body['Items']
end
tests("#put_attributes('#{@domain_name}', 'conditional', { 'version' => '1' }).body").formats(AWS::SimpleDB::Formats::BASIC) do
AWS[:sdb].put_attributes(@domain_name, 'conditional', { 'version' => '1' }).body
end
tests("#put_attributes('#{@domain_name}', 'conditional', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version']).body").formats(AWS::SimpleDB::Formats::BASIC) do
AWS[:sdb].put_attributes(@domain_name, 'conditional', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version']).body
end
tests("#delete_attributes('#{@domain_name}', 'a').body").formats(AWS::SimpleDB::Formats::BASIC) do
AWS[:sdb].delete_attributes(@domain_name, 'a').body
end
tests("#delete_attributes('#{@domain_name}', 'a').body").succeeds do
AWS[:sdb].delete_attributes(@domain_name, 'a').body
end
end
tests('failure') do
tests("#batch_put_attributes('notadomain', { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } })").raises(Excon::Errors::BadRequest) do
AWS[:sdb].batch_put_attributes('notadomain', { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } })
end
tests("#get_attributes('notadomain', 'a')").raises(Excon::Errors::BadRequest) do
AWS[:sdb].get_attributes('notadomain', 'a')
end
tests("#put_attributes('notadomain', 'conditional', { 'version' => '1' })").raises(Excon::Errors::BadRequest) do
AWS[:sdb].put_attributes('notadomain', 'foo', { 'version' => '1' })
end
tests("#put_attributes('#{@domain_name}', 'conditional', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version'])").raises(Excon::Errors::Conflict) do
AWS[:sdb].put_attributes(@domain_name, 'conditional', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version'])
end
tests("#delete_attributes('notadomain', 'a')").raises(Excon::Errors::BadRequest) do
AWS[:sdb].delete_attributes('notadomain', 'a')
end
end
AWS[:sdb].delete_domain(@domain_name)
end

View file

@ -0,0 +1,51 @@
Shindo.tests('AWS::SimpleDB | domain requests', ['aws']) do
@domain_metadata_format = AWS::SimpleDB::Formats::BASIC.merge({
'AttributeNameCount' => Integer,
'AttributeNamesSizeBytes' => Integer,
'AttributeValueCount' => Integer,
'AttributeValuesSizeBytes' => Integer,
'ItemCount' => Integer,
'ItemNamesSizeBytes' => Integer,
'Timestamp' => Time
})
@domain_name = "fog_domain_#{Time.now.to_f.to_s.gsub('.','')}"
tests('success') do
tests("#create_domain(#{@domain_name})").formats(AWS::SimpleDB::Formats::BASIC) do
AWS[:sdb].create_domain(@domain_name).body
end
tests("#create_domain(#{@domain_name})").succeeds do
AWS[:sdb].create_domain(@domain_name)
end
tests("#domain_metadata(#{@domain_name})").formats(@domain_metadata_format) do
AWS[:sdb].domain_metadata(@domain_name).body
end
tests("#list_domains").formats(AWS::SimpleDB::Formats::BASIC.merge('Domains' => [String])) do
AWS[:sdb].list_domains.body
end
tests("#delete_domain(#{@domain_name})").formats(AWS::SimpleDB::Formats::BASIC) do
AWS[:sdb].delete_domain(@domain_name).body
end
tests("#delete_domain(#{@domain_name})").succeeds do
AWS[:sdb].delete_domain(@domain_name)
end
end
tests('failure') do
tests("#domain_metadata('notadomain')").raises(Excon::Errors::BadRequest) do
AWS[:sdb].domain_metadata('notadomain')
end
end
end

View file

@ -0,0 +1,16 @@
class AWS
module SimpleDB
module Formats
BASIC = {
'BoxUsage' => Float,
'RequestId' => String
}
end
end
end