Permalink
Browse files

- start with scott's commit 0d3acb0

- fix the issue introduced in 6c97173 more mininally
- ifdef out env reading even though it doesn't matter
  • Loading branch information...
evanmcc committed Jan 2, 2014
1 parent a00bfd8 commit 16284e46bf79f37b0da7f583654781a08f633943
Showing with 25 additions and 11 deletions.
  1. +2 −2 Makefile
  2. +2 −8 src/bitcask.erl
  3. +3 −1 src/bitcask_fileops.erl
  4. +18 −0 src/bitcask_io.erl
View
@@ -26,10 +26,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
NOW = $(shell date +%s)
COUNTER = $(PWD)/$(NOW).current_counterexample.eqc
View
@@ -1475,17 +1475,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"),
View
@@ -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),
View
@@ -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} ->
@@ -77,3 +94,4 @@ determine_file_module() ->
_ ->
bitcask_file
end.
+-endif.

0 comments on commit 16284e4

Please sign in to comment.