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

[simpleDB] changing put_attributes so it doesn't use batch mode.

This commit is contained in:
Jeremy Deininger 2010-06-21 16:56:04 -07:00 committed by geemus
parent 9d42221815
commit e4ff36c842
3 changed files with 43 additions and 25 deletions

View file

@ -22,11 +22,12 @@ module Fog
# * 'BoxUsage' # * 'BoxUsage'
# * 'RequestId' # * 'RequestId'
def put_attributes(domain_name, item_name, attributes, replace_attributes = []) def put_attributes(domain_name, item_name, attributes, replace_attributes = [])
batch_put_attributes( request({
domain_name, 'Action' => 'PutAttributes',
{ item_name => attributes }, 'DomainName' => domain_name,
{ item_name => replace_attributes } :parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string),
) 'ItemName' => item_name
}.merge!(encode_attributes(attributes, replace_attributes, {})))
end end
def put_conditional(domain_name, item_name, attributes, expected_attributes = {}) def put_conditional(domain_name, item_name, attributes, expected_attributes = {})
@ -35,7 +36,7 @@ module Fog
'DomainName' => domain_name, 'DomainName' => domain_name,
:parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string), :parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string),
'ItemName' => item_name 'ItemName' => item_name
}.merge!(encode_attributes(attributes, {}, expected_attributes))) }.merge!(encode_attributes(attributes, expected_attributes.keys, expected_attributes)))
end end
end end
@ -43,33 +44,49 @@ module Fog
class Mock class Mock
def put_attributes(domain_name, item_name, attributes, replace_attributes = []) def put_attributes(domain_name, item_name, attributes, replace_attributes = [])
batch_put_attributes(
domain_name,
{ item_name => attributes },
{ item_name => replace_attributes }
)
end
def put_conditional(domain_name, item_name, attributes, expected_attributes = {})
response = Excon::Response.new response = Excon::Response.new
# TODO: mock out replace_attributes support
if @data[:domains][domain_name] if @data[:domains][domain_name]
expected_attributes.each do |ck, cv|
if @data[:domains][domain_name][item_name][ck] != cv
response.status = 409
raise(Excon::Errors.status_error({:expects => 200}, response))
end
end
attributes.each do |key, value| attributes.each do |key, value|
@data[:domains][domain_name][item_name] ||= {} @data[:domains][domain_name][item_name] ||= {}
@data[:domains][domain_name][item_name][key.to_s] = value @data[:domains][domain_name][item_name][key.to_s] = [value.to_s]
end end
response.status = 200 response.status = 200
response.body = { response.body = {
'BoxUsage' => Fog::AWS::Mock.box_usage, 'BoxUsage' => Fog::AWS::Mock.box_usage,
'RequestId' => Fog::AWS::Mock.request_id 'RequestId' => Fog::AWS::Mock.request_id
} }
else
response.status = 400
raise(Excon::Errors.status_error({:expects => 200}, response))
end
response response
end end
def put_conditional(domain_name, item_name, attributes, expected_attributes = {})
response = Excon::Response.new
if @data[:domains][domain_name]
expected_attributes.each do |ck, cv|
if @data[:domains][domain_name][item_name][ck] != [cv]
response.status = 409
raise(Excon::Errors.status_error({:expects => 200}, response))
end
end
attributes.each do |key, value|
@data[:domains][domain_name][item_name] ||= {}
@data[:domains][domain_name][item_name][key.to_s] = [value.to_s]
end
response.status = 200
response.body = {
'BoxUsage' => Fog::AWS::Mock.box_usage,
'RequestId' => Fog::AWS::Mock.request_id
}
else
response.status = 400
raise(Excon::Errors.status_error({:expects => 200}, response))
end
response
end end
end end

View file

@ -73,7 +73,7 @@ module Fog
private private
def encode_attributes(attributes, replace_attributes = {}, expected_attributes = {}) def encode_attributes(attributes, replace_attributes = [], expected_attributes = {})
encoded_attributes = {} encoded_attributes = {}
if attributes if attributes

View file

@ -19,8 +19,9 @@ describe 'SimpleDB.put_attributes' do
end end
it 'conditional put should succeed' do it 'conditional put should succeed' do
actual = AWS[:sdb].put_conditional(@domain_name, 'foo', { 'version' => '1' }, { 'version' => nil }) AWS[:sdb].put_attributes(@domain_name, 'foo', { 'version' => '1' })
actual = AWS[:sdb].put_conditional(@domain_name, 'foo', { 'version' => '2' }, { 'version' => '1' }) AWS[:sdb].put_conditional(@domain_name, 'foo', { 'version' => '2' }, { 'version' => '1' })
actual = AWS[:sdb].put_conditional(@domain_name, 'foo', { 'version' => '3' }, { 'version' => '2' })
actual.body['RequestId'].should be_a(String) actual.body['RequestId'].should be_a(String)
actual.body['BoxUsage'].should be_a(Float) actual.body['BoxUsage'].should be_a(Float)
end end