-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implemented the `BatchGetItem` operation (#122). Co-authored-by: Juli Tera <terajul@amazon.com>
- Loading branch information
Showing
13 changed files
with
779 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# language: en | ||
|
||
@dynamodb @batch | ||
Feature: Amazon DynamoDB Batch | ||
This feature tests the ability to use the batch read and write item APIs via | ||
aws-record. To run these tests, you will need to have valid AWS credentials | ||
that are accessible with the AWS SDK for Ruby's standard credential provider | ||
chain. In practice, this means a shared credential file or environment | ||
variables with your credentials. These tests may have some AWS costs associated | ||
with running them since AWS resources are created and destroyed within | ||
these tests. | ||
|
||
Background: | ||
Given a Parent model with definition: | ||
""" | ||
set_table_name('FoodTable') | ||
integer_attr :id, hash_key: true, database_attribute_name: 'Food ID' | ||
string_attr :dish, range_key: true | ||
boolean_attr :spicy | ||
""" | ||
And a Parent model with TableConfig of: | ||
""" | ||
Aws::Record::TableConfig.define do |t| | ||
t.model_class(ParentTableModel) | ||
t.read_capacity_units(2) | ||
t.write_capacity_units(2) | ||
t.client_options(region: "us-east-1") | ||
end | ||
""" | ||
When we migrate the TableConfig | ||
Then eventually the table should exist in DynamoDB | ||
And a Child model with definition: | ||
""" | ||
set_table_name('DessertTable') | ||
boolean_attr :gluten_free | ||
""" | ||
And a Child model with TableConfig of: | ||
""" | ||
Aws::Record::TableConfig.define do |t| | ||
t.model_class(ChildTableModel) | ||
t.read_capacity_units(2) | ||
t.write_capacity_units(2) | ||
t.client_options(region: "us-east-1") | ||
end | ||
""" | ||
When we migrate the TableConfig | ||
Then eventually the table should exist in DynamoDB | ||
|
||
Scenario: Perform a batch set of writes and read | ||
When we make a batch write call with following Parent and Child model items: | ||
""" | ||
[ | ||
{ "model": "Parent", "id": 1, "dish": "Papaya Salad", "spicy": true }, | ||
{ "model": "Parent", "id": 2, "dish": "Hamburger", "spicy": false }, | ||
{ "model": "Child", "id": 1, "dish": "Apple Pie", "spicy": false, "gluten_free": false } | ||
] | ||
""" | ||
And we make a batch read call for the following Parent and Child model item keys: | ||
""" | ||
[ | ||
{ "model": "Parent", "id": 1, "dish": "Papaya Salad" }, | ||
{ "model": "Parent", "id": 2, "dish": "Hamburger" }, | ||
{ "model": "Child", "id": 1, "dish": "Apple Pie" } | ||
] | ||
""" | ||
Then we expect the batch read result to include the following items: | ||
""" | ||
[ | ||
{ "id": 1, "dish": "Papaya Salad", "spicy": true }, | ||
{ "id": 2, "dish": "Hamburger", "spicy": false }, | ||
{ "id": 1, "dish": "Apple Pie", "spicy": false, "gluten_free": false } | ||
] | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
And(/^a (Parent|Child) model with TableConfig of:$/) do |model, code_block| | ||
case model | ||
when 'Parent' | ||
ParentTableModel = @parent | ||
when 'Child' | ||
ChildTableModel = @model | ||
else | ||
raise 'Model must be either a Parent or Child' | ||
end | ||
|
||
@table_config = eval(code_block) | ||
end | ||
|
||
When(/^we make a batch write call with following Parent and Child model items:$/) do |string| | ||
item_data = JSON.parse(string, symbolize_names: true) | ||
|
||
Aws::Record::Batch.write do |db| | ||
item_data.each do |item| | ||
case item[:model] | ||
when 'Parent' | ||
db.put(@parent.new(remove_model_key(item))) | ||
when 'Child' | ||
db.put(@model.new(remove_model_key(item))) | ||
else | ||
raise 'Model must be either a Parent or Child' | ||
end | ||
end | ||
end | ||
end | ||
|
||
And(/^we make a batch read call for the following Parent and Child model item keys:$/) do |string| | ||
key_batch = JSON.parse(string, symbolize_names: true) | ||
|
||
@batch_read_result = Aws::Record::Batch.read do |db| | ||
key_batch.each do |item_key| | ||
case item_key[:model] | ||
when 'Parent' | ||
db.find(@parent, remove_model_key(item_key)) | ||
when 'Child' | ||
db.find(@model, remove_model_key(item_key)) | ||
else | ||
raise 'Model must be either a Parent or Child' | ||
end | ||
end | ||
end | ||
end | ||
|
||
Then(/^we expect the batch read result to include the following items:$/) do |string| | ||
expected = JSON.parse(string, symbolize_names: true) | ||
actual = @batch_read_result.items.map(&:to_h) | ||
expect(expected.count).to eq(actual.count) | ||
expect(expected.all? { |e| actual.include?(e) }).to be_truthy | ||
end | ||
|
||
private | ||
|
||
def remove_model_key(item) | ||
item.delete(:model) | ||
item | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.