Browse files

Merge pull request #1 from anha0825/master

Various minor fixes
  • Loading branch information...
2 parents a4e4f7b + 18dd2e0 commit c91e023bbf224c643e07fb22c94ebbd417002b83 @knutin knutin committed Apr 26, 2013
Showing with 6 additions and 109 deletions.
  1. +3 −3 README.md
  2. +2 −2 include/dinerl_types.hrl
  3. +1 −2 src/dinerl.app.src
  4. +0 −102 test/dinerl_test.erl~
View
6 README.md
@@ -1,10 +1,10 @@
Here's how you use this thing without using any macro help:
dinerl:setup("AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "us-east-1b").
- dinerl:create_table(<<"TestTable">>, [{<<"HashKeyElement">>, [{<<"AttributeName">>, <<"Key">>}, {<<"AttributeType">>, <<"S">>}]}], 50, 50).
+ dinerl:create_table(<<"TestTable">>, {[{<<"HashKeyElement">>, {[{<<"AttributeName">>, <<"Key">>}, {<<"AttributeType">>, <<"S">>}]}}]}, 50, 50).
dinerl:list_tables().
- dinerl:put_item(<<"TestTable">>, [{<<"Key">>, [{<<"S">>, <<"jello">>}]}], []).
- dinerl:get_item(<<"TestTable">>, [{<<"HashKeyElement">>, [{<<"S">>, <<"jello">>}]}], []).
+ dinerl:put_item(<<"TestTable">>, {[{<<"Key">>, {[{<<"S">>, <<"jello">>}]}}]}, []).
+ dinerl:get_item(<<"TestTable">>, {[{<<"HashKeyElement">>, {[{<<"S">>, <<"jello">>}]}}]}, []).
put(Key, Value, TTL, Now) ->
dinerl:put_item(<<"Attributions">>, [{<<"UserKey">>, [{<<"S">>, Key}]},
View
4 include/dinerl_types.hrl
@@ -33,8 +33,8 @@
-define(HASHKEYSCHEMA(N, T), {<<"HashKeyElement">>, [{<<"AttributeName">>, N}, {<<"AttributeType">>, T}]}).
-define(RANGEKEYSCHEMA(N, T), {<<"RangeKeyElement">>, [{<<"AttributeName">>, N}, {<<"AttributeType">>, T}]}).
--define(HASHKEY(N, V), {<<"HashKeyElement">>, [V]}).
--define(RANGEKEY(N, V), {<<"RangeKeyElement">>, [V]}).
+-define(HASHKEY(N, V), {<<"HashKeyElement">>, {[{N, V}]}}).
+-define(RANGEKEY(N, V), {<<"RangeKeyElement">>, {[{N, V}]}}).
-define(NONE, <<"NONE">>).
View
3 src/dinerl.app.src
@@ -4,6 +4,5 @@
{vsn, "0.1"},
{modules, []},
{registered, []},
- {mod, {'dinerl_app', []}},
{env, []},
- {applications, [kernel, stdlib, crypto, inets, ssl, xmerl, timer]}]}.
+ {applications, [kernel, stdlib, crypto, inets, ssl, xmerl, lhttpc, jiffy]}]}.
View
102 test/dinerl_test.erl~
@@ -1,102 +0,0 @@
--module(dinerl_test).
--include_lib("eunit/include/eunit.hrl").
-
--define(HASH_TABLE, <<"dinerl-unit-test-table-hash">>).
--define(RANGE_TABLE, <<"dinerl-unit-test-table-range">>).
-
-dinerl_test_() ->
- case file:consult(filename:join([code:priv_dir(dinerl), "aws_credentials.term"])) of
- {ok, Config} ->
- Setup =
- fun () ->
- AccessKey = proplists:get_value(access_key, Config),
- SecretAccessKey = proplists:get_value(secret_access_key,
- Config),
-
- inets:start(),
- application:start(crypto),
- application:start(public_key),
- application:start(ssl),
- application:start(lhttpc),
- dinerl:setup(AccessKey, SecretAccessKey, "us-east-1a"),
-
- %% Create tables if necessary
- %% Wait for tables to become active
- create_tables()
-
- end,
-
- Teardown = fun (_) ->
- ok
- end,
-
- {setup, Setup, Teardown,
- [
- ?_test(get_put())
- ]};
- {error, enoent} ->
- []
- end.
-
-create_tables() ->
- {ok, {[{<<"TableNames">>, Tables}]}} = dinerl:list_tables(),
-
- Config = [{?HASH_TABLE,
- {[{<<"HashKeyElement">>, {[{<<"AttributeName">>, <<"key">>},
- {<<"AttributeType">>, <<"S">>}]}}]}},
- {?RANGE_TABLE,
- {[{<<"HashKeyElement">>, {[{<<"AttributeName">>, <<"hash">>},
- {<<"AttributeType">>, <<"S">>}]}},
- {<<"RangeKeyElement">>, {[{<<"AttributeName">>, <<"range">>},
- {<<"AttributeType">>, <<"N">>}]}}]}}
- ],
-
- lists:foreach(
- fun ({Name, Key}) ->
- case lists:member(Name, Tables) of
- true ->
- wait_for_active(Name),
- ok;
- false ->
- case dinerl:create_table(Name, Key, 10, 5) of
- {ok, _} ->
- wait_for_active(Name),
- ok;
- {error, _, Reason} ->
- throw({create_table_failed, Reason})
- end
- end
- end, Config).
-
-wait_for_active(Name) ->
- case dinerl:describe_table(Name) of
- {ok, {Response}} ->
- {Table} = proplists:get_value(<<"Table">>, Response),
- case proplists:get_value(<<"TableStatus">>, Table) of
- <<"ACTIVE">> ->
- ok;
- _ ->
- error_logger:info_msg("Waiting for table ~p..~n", [Name]),
- timer:sleep(10000),
- wait_for_active(Name)
- end;
- {error, _, Reason} ->
- throw({wait_for_active_failed, Reason})
- end.
-
-
-
-%%
-%% TESTS
-%%
-
-get_put() ->
- Key = base64:encode(crypto:rand_bytes(10)),
-
- ?assertEqual({ok, {[{<<"ReadsUsed">>, 1}]}},
- dinerl:get_item(?HASH_TABLE,
- {[{<<"HashKeyElement">>, {[{<<"S">>, Key}]}}]}, [])),
-
- ?assertEqual({ok, {[{<<"WritesUsed">>, 1}]}},
- dinerl:put_item(?HASH_TABLE,
- {[{<<"HashKeyElement">>, {[{<<"S">>, Key}]}}]}, [])).

0 comments on commit c91e023

Please sign in to comment.