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

[aws|simpledb] provide for using ConsistentRead on get_attributes and select

closes #386
This commit is contained in:
geemus 2011-07-08 16:43:25 -05:00
parent a51f42c9e3
commit b7f54bbd2d
3 changed files with 47 additions and 32 deletions

View file

@ -13,11 +13,13 @@ module Fog
# * item_name<~String> - Name of the item. May use any UTF-8 characters valid
# in xml. Control characters and sequences not allowed in xml are not
# valid. Can be up to 1024 bytes long.
# * attributes<~Array> - Attributes to return from the item. Defaults to
# {}, which will return all attributes. Attribute names and values may use
# any UTF-8 characters valid in xml. Control characters and sequences not
# allowed in xml are not valid. Each name and value can be up to 1024
# bytes long.
# * options<~Hash>:
# * AttributeName<~Array> - Attributes to return from the item. Defaults to
# {}, which will return all attributes. Attribute names and values may use
# any UTF-8 characters valid in xml. Control characters and sequences not
# allowed in xml are not valid. Each name and value can be up to 1024
# bytes long.
# * ConsistentRead<~Boolean> - When set to true, ensures most recent data is returned. Defaults to false.
#
# ==== Returns
# * response<~Excon::Response>:
@ -25,27 +27,37 @@ module Fog
# * 'Attributes' - list of attribute name/values for the item
# * 'BoxUsage'
# * 'RequestId'
def get_attributes(domain_name, item_name, attributes = {})
def get_attributes(domain_name, item_name, options = {})
if options.is_a?(Array)
Formatador.display_line("[yellow][WARN] get_attributes with array attributes param is deprecated, use 'AttributeName' => attributes) instead[/] [light_black](#{caller.first})[/]")
options = {'AttributeName' => options}
end
options['AttributeName'] ||= []
request({
'Action' => 'GetAttributes',
'DomainName' => domain_name,
'ItemName' => item_name,
:idempotent => true,
:parser => Fog::Parsers::AWS::SimpleDB::GetAttributes.new(@nil_string)
}.merge!(encode_attribute_names(attributes)))
'Action' => 'GetAttributes',
'ConsistentRead' => !!options['ConsistentRead'],
'DomainName' => domain_name,
'ItemName' => item_name,
:idempotent => true,
:parser => Fog::Parsers::AWS::SimpleDB::GetAttributes.new(@nil_string)
}.merge!(encode_attribute_names(options['AttributeName'])))
end
end
class Mock
def get_attributes(domain_name, item_name, attributes = nil)
def get_attributes(domain_name, item_name, options = {})
unless options.empty? || options['AttributeName']
Formatador.display_line("[yellow][WARN] get_attributes with array attributes param is deprecated, use 'AttributeName' => attributes) instead[/] [light_black](#{caller.first})[/]")
options['AttributeName'] ||= options
end
option['AttributeName'] ||= []
response = Excon::Response.new
if self.data[:domains][domain_name]
object = {}
if attributes
for attribute in attributes
if options['AttributeName']
for attribute in options['AttributeName']
if self.data[:domains][domain_name][item_name] && self.data[:domains][domain_name][item_name]
object[attribute] = self.data[:domains][domain_name][item_name][attribute]
end

View file

@ -9,7 +9,9 @@ module Fog
#
# ==== Parameters
# * select_expression<~String> - Expression to query domain with.
# * next_token<~String> - Offset token to start list, defaults to nil.
# * options<~Hash>:
# * ConsistentRead<~Boolean> - When set to true, ensures most recent data is returned. Defaults to false.
# * NextToken<~String> - Offset token to start list, defaults to nil.
#
# ==== Returns
# * response<~Excon::Response>:
@ -19,10 +21,16 @@ module Fog
# * 'Items'<~Hash> - list of attribute name/values for the items formatted as
# { 'item_name' => { 'attribute_name' => ['attribute_value'] }}
# * 'NextToken'<~String> - offset to start with if there are are more domains to list
def select(select_expression, next_token = nil)
def select(select_expression, options = {})
if options.is_a?(String)
Formatador.display_line("[yellow][WARN] get_attributes with string next_token param is deprecated, use 'AttributeName' => attributes) instead[/] [light_black](#{caller.first})[/]")
options = {'NextToken' => options}
end
options['NextToken'] ||= nil
request(
'Action' => 'Select',
'NextToken' => next_token,
'ConsistentRead' => !!options['ConsistentRead'],
'NextToken' => options['NextToken'],
'SelectExpression' => select_expression,
:idempotent => true,
:parser => Fog::Parsers::AWS::SimpleDB::Select.new(@nil_string)

View file

@ -10,22 +10,17 @@ Shindo.tests('AWS::SimpleDB | attributes requests', ['aws']) do
AWS[:sdb].batch_put_attributes(@domain_name, { 'a' => { 'b' => 'c', 'd' => 'e' }, 'x' => { 'y' => 'z' } }).body
end
tests("#get_attributes('#{@domain_name}', 'a').body['Attributes']").returns({'b' => ['c'], 'd' => ['e']}) do
attributes = {}
Fog.wait_for {
attributes = AWS[:sdb].get_attributes(@domain_name, 'a').body['Attributes']
attributes != {}
}
attributes
tests("#get_attributes('#{@domain_name}', 'a', {'ConsistentRead' => true}).body['Attributes']").returns({'b' => ['c'], 'd' => ['e']}) do
AWS[:sdb].get_attributes(@domain_name, 'a', {'ConsistentRead' => true}).body['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'], 'd' => ['e']}, 'x' => { 'y' => ['z'] } }) do
tests("#select('select * from #{@domain_name}', {'ConsistentRead' => true}).body['Items']").returns({'a' => { 'b' => ['c'], 'd' => ['e']}, 'x' => { 'y' => ['z'] } }) do
pending if Fog.mocking?
AWS[:sdb].select("select * from #{@domain_name}").body['Items']
AWS[:sdb].select("select * from #{@domain_name}", {'ConsistentRead' => true}).body['Items']
end
tests("#put_attributes('#{@domain_name}', 'conditional', { 'version' => '1' }).body").formats(AWS::SimpleDB::Formats::BASIC) do
@ -42,8 +37,8 @@ Shindo.tests('AWS::SimpleDB | attributes requests', ['aws']) do
end
# Verify that individually deleted attributes are actually removed.
tests("#get_attributes('#{@domain_name}', 'a', ['d']).body['Attributes']").returns({'d' => nil}) do
AWS[:sdb].get_attributes(@domain_name, 'a', ['d']).body['Attributes']
tests("#get_attributes('#{@domain_name}', 'a', {'AttributeName' => ['d'], 'ConsistentRead' => true}).body['Attributes']").returns({}) do
AWS[:sdb].get_attributes(@domain_name, 'a', {'AttributeName' => ['d'], 'ConsistentRead' => true}).body['Attributes']
end
tests("#delete_attributes('#{@domain_name}', 'a').body").formats(AWS::SimpleDB::Formats::BASIC) do
@ -56,8 +51,8 @@ Shindo.tests('AWS::SimpleDB | attributes requests', ['aws']) do
end
# Verify that deleting a domain, item combination removes all related attributes.
tests("#get_attributes('#{@domain_name}', 'a').body['Attributes']").returns({}) do
AWS[:sdb].get_attributes(@domain_name, 'a').body['Attributes']
tests("#get_attributes('#{@domain_name}', 'a', {'ConsistentRead' => true}).body['Attributes']").returns({}) do
AWS[:sdb].get_attributes(@domain_name, 'a', {'ConsistentRead' => true}).body['Attributes']
end
end