Skip to content

Commit

Permalink
Merge pull request #129 from basho/fix-nif-mode
Browse files Browse the repository at this point in the history
Fix nif-mode and eunit_nif tests.
  • Loading branch information
evanmcc committed Jan 3, 2014
2 parents edd9a74 + fb5e962 commit a99f2f0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -23,10 +23,10 @@ clean:
test: deps compile eunit_erlang eunit_nif

eunit_erlang:
IOMODE="erlang" $(REBAR_BIN) skip_deps=true eunit
BITCASK_IO_MODE="erlang" $(REBAR_BIN) skip_deps=true eunit

eunit_nif:
IOMODE="nif" $(REBAR_BIN) skip_deps=true eunit
BITCASK_IO_MODE="nif" $(REBAR_BIN) skip_deps=true eunit


# Release tarball creation
Expand Down
10 changes: 2 additions & 8 deletions src/bitcask.erl
Expand Up @@ -1386,17 +1386,11 @@ default_dataset() ->
%% HACK: Terrible hack to ensure that the .app file for
%% bitcask is available on the code path. Assumption here
%% is that we're running in .eunit/ as part of rebar.
%% MORE HACK: init the io mode (nif or erlang) here.
a0_test() ->
code:add_pathz("../ebin"),
application:start(erlang),
Mode0 = case os:getenv("IOMODE") of
false -> "erlang";
Else -> Else
end,
Mode = list_to_atom(Mode0),
application:set_env(bitcask, io_mode, Mode),
error_logger:info_msg("Set IO mode to: ~p", [Mode]).
Mode = bitcask_io:determine_file_module(),
error_logger:info_msg("Bitcask IO mode is: ~p\n", [Mode]).

roundtrip_test() ->
os:cmd("rm -rf /tmp/bc.test.roundtrip"),
Expand Down
4 changes: 3 additions & 1 deletion src/bitcask_fileops.erl
Expand Up @@ -65,7 +65,9 @@
-spec create_file(Dirname :: string(), Opts :: [any()],
reference()) ->
{ok, #filestate{}}.
create_file(DirName, Opts, Keydir) ->

create_file(DirName, Opts0, Keydir) ->
Opts = [create|Opts0],
{ok, Lock} = get_create_lock(DirName),
try
{ok, Newest} = bitcask_nifs:increment_file_id(Keydir),
Expand Down
18 changes: 18 additions & 0 deletions src/bitcask_io.erl
Expand Up @@ -68,6 +68,23 @@ file_module() ->
Mod
end.

-ifdef(TEST).
determine_file_module() ->
case application:get_env(bitcask, io_mode) of
{ok, erlang} ->
bitcask_file;
{ok, nif} ->
bitcask_nifs;
_ ->
Mode = case os:getenv("BITCASK_IO_MODE") of
false -> 'erlang';
"erlang" -> 'erlang';
"nif" -> 'nif'
end,
application:set_env(bitcask, io_mode, Mode),
determine_file_module()
end.
-else.
determine_file_module() ->
case application:get_env(bitcask, io_mode) of
{ok, erlang} ->
Expand All @@ -77,3 +94,4 @@ determine_file_module() ->
_ ->
bitcask_file
end.
-endif.

0 comments on commit a99f2f0

Please sign in to comment.