Permalink
Browse files

Added simple get & put test. Removed mochijson, started rewriting to …

…use jiffy.
  • Loading branch information...
1 parent f736d0e commit fe4441b38fa1b29e7d6e584b34574c43729f1e6e @knutin knutin committed Jan 15, 2013
Showing with 246 additions and 909 deletions.
  1. +2 −1 .gitignore
  2. +5 −2 rebar.config
  3. +17 −14 src/dinerl.erl
  4. +3 −2 src/dinerl_client.erl
  5. +0 −889 src/dmochijson2.erl
  6. +1 −1 src/dynamodb.erl
  7. +116 −0 test/dinerl_test.erl
  8. +102 −0 test/dinerl_test.erl~
View
@@ -7,4 +7,5 @@
/TEST-*.xml
/deps
*.swp
-*.pyc
+*.pyc
+aws_credentials.term
View
@@ -1,8 +1,11 @@
%% -*- erlang -*-
{erl_opts, [debug_info]}.
{deps, [
- {lhttpc, ".*",
- {git, "git://github.com/ferd/lhttpc.git", "master"}}]}.
+ {lhttpc, ".*",
+ {git, "git://github.com/ferd/lhttpc.git", "master"}},
+ {jiffy, "",
+ {git, "https://github.com/davisp/jiffy.git", "master"}}
+ ]}.
{cover_enabled, true}.
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
View
@@ -62,10 +62,11 @@ create_table(Name, Key, ReadsPerSecond, WritesPerSecond) ->
-spec create_table(string()|binary(), keyschema(), integer(), integer(), integer()) -> jsonf().
create_table(Name, Key, ReadsPerSecond, WritesPerSecond, Timeout) ->
api(create_table,
- [{<<"TableName">>, Name},
- {<<"KeySchema">>, Key},
- {<<"ProvisionedThroughput">>, [{<<"ReadsPerSecond">>, ReadsPerSecond},
- {<<"WritesPerSecond">>, WritesPerSecond}]}], Timeout).
+ {[{<<"TableName">>, Name},
+ {<<"KeySchema">>, Key},
+ {<<"ProvisionedThroughput">>,
+ {[{<<"ReadsPerSecond">>, ReadsPerSecond},
+ {<<"WritesPerSecond">>, WritesPerSecond}]}}]}, Timeout).
delete_table(Name) ->
describe_table(Name, undefined).
@@ -76,16 +77,18 @@ delete_table(Name, Timeout) ->
describe_table(Name) ->
describe_table(Name, undefined).
describe_table(Name, Timeout) ->
- api(describe_table, [{<<"TableName">>, Name}], Timeout).
+ api(describe_table, {[{<<"TableName">>, Name}]}, Timeout).
update_table(Name, ReadsPerSecond, WritesPerSecond) ->
update_table(Name, ReadsPerSecond, WritesPerSecond, undefined).
update_table(Name, ReadsPerSecond, WritesPerSecond, Timeout) ->
- api(update_table, [{<<"TableName">>, Name},
- {<<"ProvisionedThroughput">>, [{<<"ReadsPerSecond">>, ReadsPerSecond},
- {<<"WritesPerSecond">>, WritesPerSecond}]}],
+ api(update_table,
+ {[{<<"TableName">>, Name},
+ {<<"ProvisionedThroughput">>,
+ {[{<<"ReadsPerSecond">>, ReadsPerSecond},
+ {<<"WritesPerSecond">>, WritesPerSecond}]}}]},
Timeout).
@@ -97,10 +100,8 @@ list_tables(List) ->
list_tables(List, Timeout) ->
list_tables(List, [], Timeout).
-list_tables([], [], Timeout) ->
- list_tables([], {}, Timeout);
list_tables([], Body, Timeout) ->
- api(list_tables, Body, Timeout);
+ api(list_tables, {Body}, Timeout);
list_tables([{start_name, Name}|Rest], Acc, Timeout) ->
list_tables(Rest, [{<<"ExclusiveStartTableName">>, Name}|Acc], Timeout);
list_tables([{limit, N}|Rest], Acc, Timeout) ->
@@ -113,7 +114,8 @@ put_item(Table, Attributes, Options, Timeout) ->
put_item(Table, Attributes, Options, [], Timeout).
put_item(Table, Attributes, [], PartialBody, Timeout) ->
- api(put_item, [{<<"TableName">>, Table}, {<<"Item">>, Attributes}|PartialBody], Timeout);
+ api(put_item, {[{<<"TableName">>, Table},
+ {<<"Item">>, Attributes} | PartialBody]}, Timeout);
put_item(T, A, [{return, all_old}|Rest], Acc, Timeout) ->
put_item(T, A, Rest, [{<<"ReturnValues">>, ?ALL_OLD}|Acc], Timeout);
put_item(T, A, [{return, none}|Rest], Acc, Timeout) ->
@@ -130,7 +132,8 @@ delete_item(Table, Key, Options, Timeout) ->
delete_item(Table, Key, Options, [], Timeout).
delete_item(Table, Key, [], PartialBody, Timeout) ->
- api(delete_item, [{<<"TableName">>, Table}, {<<"Key">>, Key}|PartialBody], Timeout);
+ api(delete_item, {[{<<"TableName">>, Table},
+ {<<"Key">>, Key} | PartialBody]}, Timeout);
delete_item(T, K, [{return, all_old}|Rest], Acc, Timeout) ->
delete_item(T, K, Rest, [{<<"ReturnValues">>, ?ALL_OLD}|Acc], Timeout);
delete_item(T, K, [{return, none}|Rest], Acc, Timeout) ->
@@ -147,7 +150,7 @@ get_item(Table, Key, Options, Timeout) ->
get_item(Table, Key, Options, [], Timeout).
get_item(T, K, [], Acc, Timeout) ->
- api(get_item, [{<<"TableName">>, T}, {<<"Key">>, K}|Acc], Timeout);
+ api(get_item, {[{<<"TableName">>, T}, {<<"Key">>, K}|Acc]}, Timeout);
get_item(T, K, [{consistent, V}|Rest], Acc, Timeout) ->
get_item(T, K, Rest, [{<<"ConsistentRead">>, V}|Acc], Timeout);
get_item(T, K, [{attrs, V}|Rest], Acc, Timeout) ->
View
@@ -56,10 +56,11 @@ api(AccessKeyId, SecretAccessKey, Zone, Token, RFCDate, Name, Body, Timeout) ->
-spec api(access_key_id(), secret_access_key(), zone(),
token(), rfcdate(), method(), any(), integer(), options()) -> result().
api(AccessKeyId, SecretAccessKey, Zone, Token, RFCDate, Name, Body, Timeout, Options) ->
+ %%error_logger:info_msg("json: ~p~n", [Body]),
case dynamodb:call(AccessKeyId, SecretAccessKey, Zone, method_name(Name),
- Token, RFCDate, dmochijson2:encode(Body), Timeout, Options) of
+ Token, RFCDate, jiffy:encode(Body), Timeout, Options) of
{ok, Response} ->
- {ok, dmochijson2:decode(Response)};
+ {ok, jiffy:decode(Response)};
{error, Code, Reason} ->
{error, Code, Reason}
end.
Oops, something went wrong.

0 comments on commit fe4441b

Please sign in to comment.