Skip to content

Commit

Permalink
hibari >> GH51 - Update for Erlang/OTP 18
Browse files Browse the repository at this point in the history
- Add "18" to require_otp_vsn of rebar.config.
- Replace deprecated erlang:now/0 with gmt_time_otp18 functions
  such as monotonic_time/0 and erlang_system_time/1.
  • Loading branch information
tatsuya6502 committed Nov 10, 2015
1 parent 0e7f955 commit 2e425f7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
16 changes: 8 additions & 8 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
%%% -*- mode: erlang -*-

%% Require OTP version R15, R16, or 17
{require_otp_vsn, "R15|R16|17"}.
{require_otp_vsn, "R15|R16|17|18"}.

%% Depends
{deps_dir, "../"}.
Expand All @@ -11,12 +10,13 @@
{erl_first_files, ["src/ubf_gdss_plugin.erl", "src/tbf_gdss_plugin.erl"]}.

%% Erlang compiler options
{erl_opts, [debug_info, warnings_as_errors
, {parse_transform, lager_transform}
, {i, "./ebin/"}
, {i, "../ubf/include/"}
, {i, "../gmt_util/include/"}
, {platform_define, "R13", 'old_filename'}
{erl_opts, [debug_info,
warnings_as_errors,
{parse_transform, lager_transform},
{i, "./ebin/"},
{i, "../ubf/include/"},
{i, "../gmt_util/include/"},
{platform_define, "R13", 'old_filename'}
]}.

%% EUnit options
Expand Down
27 changes: 17 additions & 10 deletions src/tbf_gdss_plugin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
-compile({parse_transform,contract_parser}).
-add_contract("./src/tbf_gdss_plugin").

-define(TIME, gmt_time_otp18).

%% NOTE defines and records are generated by thrift, see gdss-tbf-proto
-define(hibari_UNKNOWN, 1).
Expand Down Expand Up @@ -291,10 +292,11 @@ add(_) ->
unknown_args.

add(Table, Key, Value) ->
StartTime = erlang:now(),
StartTime = ?TIME:monotonic_time(),
case catch brick_simple:add(Table, Key, Value) of
{ok, _} ->
{ok, timer:now_diff(erlang:now(), StartTime)};
EndTime = ?TIME:monotonic_time(),
{ok, ?TIME:convert_time_unit(EndTime - StartTime, native, micro_seconds)};

{key_exists, _} ->
key_exists;
Expand Down Expand Up @@ -322,10 +324,11 @@ replace(_) ->
unknown_args.

replace(Table, Key, Value) ->
StartTime = erlang:now(),
StartTime = ?TIME:monotonic_time(),
case catch brick_simple:replace(Table, Key, Value) of
{ok, _} ->
{ok, timer:now_diff(erlang:now(), StartTime)};
EndTime = ?TIME:monotonic_time(),
{ok, ?TIME:convert_time_unit(EndTime - StartTime, native, micro_seconds)};

key_not_exist ->
key_not_exist;
Expand All @@ -352,10 +355,11 @@ set(_) ->
unknown_args.

set(Table, Key, Value) ->
StartTime = erlang:now(),
StartTime = ?TIME:monotonic_time(),
case catch brick_simple:set(Table, Key, Value) of
{ok, _} ->
{ok, timer:now_diff(erlang:now(), StartTime)};
EndTime = ?TIME:monotonic_time(),
{ok, ?TIME:convert_time_unit(EndTime - StartTime, native, micro_seconds)};

{ts_error, _} ->
ts_error;
Expand Down Expand Up @@ -394,10 +398,11 @@ delete(_) ->
unknown_args.

delete(Table, Key, Flags) ->
StartTime = erlang:now(),
StartTime = ?TIME:monotonic_time(),
case catch brick_simple:delete(Table, Key, Flags) of
ok ->
{ok, timer:now_diff(erlang:now(), StartTime)};
EndTime = ?TIME:monotonic_time(),
{ok, ?TIME:convert_time_unit(EndTime - StartTime, native, micro_seconds)};

key_not_exist ->
key_not_exist;
Expand Down Expand Up @@ -437,10 +442,12 @@ get(_) ->
unknown_args.

get(Table, Key, Flags) ->
StartTime = erlang:now(),
StartTime = ?TIME:monotonic_time(),
case catch brick_simple:get(Table, Key, Flags) of
{ok, Timestamp, Value} ->
{ok, Key, Timestamp, Value, timer:now_diff(erlang:now(), StartTime)};
EndTime = ?TIME:monotonic_time(),
ElapseTime = ?TIME:convert_time_unit(EndTime - StartTime, native, micro_seconds),
{ok, Key, Timestamp, Value, ElapseTime};

key_not_exist ->
key_not_exist;
Expand Down
4 changes: 3 additions & 1 deletion src/ubf_gdss_stub_plugin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
-define(S(X),
#'#S'{value=X}).

-define(TIME, gmt_time_otp18).

info() ->
"I am a stateless server".

Expand Down Expand Up @@ -148,7 +150,7 @@ get_cached_get_value(Size) ->
Key = {?MODULE,cached_get_value,Size},
case erlang:get(Key) of
undefined ->
_ = random:seed(erlang:now()),
_ = r1andom:seed(?TIME:monotonic_time(), ?TIME:unique_integer(), ?TIME:time_offset()),
Val = erlang:list_to_binary([ random:uniform(255) || _ <- lists:seq(1,Size) ]),
erlang:put(Key, Val),
Val;
Expand Down
3 changes: 2 additions & 1 deletion test/eunit/brick_eunit_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

-define(MYNODE, 'gdss_eunit@localhost').

-define(TIME, gmt_time_otp18).

%%%----------------------------------------------------------------------
%%% TEST UTILS
Expand Down Expand Up @@ -54,7 +55,7 @@ setup(Verbose) ->
true ->
error_logger:delete_report_handler(error_logger_tty_h)
end,
random:seed(erlang:now()),
random:seed(?TIME:monotonic_time(), ?TIME:unique_integer(), ?TIME:time_offset()),
ok.

setup_and_bootstrap() ->
Expand Down
5 changes: 3 additions & 2 deletions test/eunit/ubf_gdss_plugin_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ test_status(Service, ServerId, Proto) ->

-spec make_exp(non_neg_integer()) -> exp_time().
make_exp(StepMillis) ->
{MSec, Sec, USec} = now(),
NowX = (MSec * 1000000 * 1000000) + (Sec * 1000000) + USec,
NowX = gmt_time_otp18:system_time(micro_seconds),
%% TODO: FIXME: This should read (NowX div 1000).
%% https://github.com/hibari/gdss-admin/issues/11
(NowX * 1000) + StepMillis.

0 comments on commit 2e425f7

Please sign in to comment.