Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add optimize command/function and tests, fix Makefile test runner

  • Loading branch information...
commit 42434482b6f7aa663ed83b95ca64f7df61bd058e 1 parent f4ac387
Jim McCoy authored
Showing with 36 additions and 8 deletions.
  1. +5 −5 Makefile
  2. +21 −3 src/principe.erl
  3. +10 −0 test/principe_test.erl
View
10 Makefile
@@ -16,10 +16,10 @@ clean:
rm -fv test/*.beam
# Testing with a Tokyo Tyrant server instance
-test: clean ttclean tt_normal testbuild run_basic_test ttstopd tt_table run_table_test ttstopd ttclean
+test: clean ttclean tt_normal testbuild run_basic_test tt_table run_table_test ttstopd #ttclean
testbuild:
erlc -o ebin/ src/*.erl
- erlc test/*.erl
+ erlc -o test/ test/*.erl
run_basic_test:
erl -pa ebin/ -pa test/ -noshell -s principe_test test -s init stop
run_table_test:
@@ -27,8 +27,8 @@ run_table_test:
ttclean:
rm -f /tmp/ttserver.pid /tmp/ttserver.*
tt_normal:
- ttserver -dmn -pid /tmp/ttserver.pid /tmp/ttserver.tcb
+ ttserver -dmn -kl -pid /tmp/ttserver.pid /tmp/ttserver.tch
tt_table:
- ttserver -dmn -pid /tmp/ttserver.pid /tmp/ttserver.tct
+ ttserver -dmn -kl -pid /tmp/ttserver.pid /tmp/ttserver.tct
ttstopd:
- kill -TERM `cat /tmp/ttserver.pid`
+ kill -TERM `head -1 /tmp/ttserver.pid`
View
24 src/principe.erl
@@ -64,7 +64,8 @@
size/1,
stat/1,
copy/2,
- restore/3,
+ restore/3,
+ restore_with_check/3,
setmst/3,
misc/3,
misc/4,
@@ -545,16 +546,33 @@ copy(Socket, Key) when is_binary(Key) ->
%% @spec restore(Socket::port(),
%% PathName::iolist(),
-%% TimeStamp::integer) -> ok | error()
+%% TimeStamp::integer,
+%% Options::) -> ok | error()
%%
%% @doc Restore the database to a particular point in time from the update log.
restore(Socket, PathName, TimeStamp) ->
gen_tcp:send(Socket, [<<?RESTORE:16>>,
<<(iolist_size(PathName)):32>>,
- <<TimeStamp:64>>,
+ <<TimeStamp:64>>,
+ <<0:32>>,
PathName]),
?R_SUCCESS.
+%% @spec restore_with_check(Socket::port(),
+%% PathName::iolist(),
+%% TimeStamp::integer) -> ok | error()
+%%
+%% @doc Restore the database to a particular point in time from the update log and
+%% perform a consistency check
+%% @end
+restore_with_check(Socket, PathName, TimeStamp) ->
+ gen_tcp:send(Socket, [<<?RESTORE:16>>,
+ <<(iolist_size(PathName)):32>>,
+ <<TimeStamp:64>>,
+ <<1:32>>,
+ PathName]),
+ ?R_SUCCESS.
+
%% @spec setmst(Socket::port(),
%% HostName::iolist(),
%% Port::integer) -> ok | error()
View
10 test/principe_test.erl
@@ -26,6 +26,7 @@ test(ConnectParams) ->
ok = rnum_test(ConnectParams),
ok = size_test(ConnectParams),
ok = stat_test(ConnectParams),
+ ok = optimize_test(ConnectParams),
ok = misc_test(ConnectParams),
ok.
@@ -68,6 +69,7 @@ putkeep_test(ConnectParams) ->
{ok, Socket} = principe:connect(ConnectParams),
ok = principe:vanish(Socket),
ok = principe:put(Socket, <<"test">>, <<"foo">>),
+ <<"foo">> = principe:get(Socket, <<"test">>),
{error, _} = principe:putkeep(Socket, <<"test">>, <<"bar">>),
<<"foo">> = principe:get(Socket, <<"test">>), % no effect if key already exists before putkeep
ok = principe:putkeep(Socket, <<"another">>, <<"baz">>),
@@ -208,6 +210,14 @@ stat_test(ConnectParams) ->
principe:stat(Socket),
ok.
+optimize_test(ConnectParams) ->
+ {ok, Socket} = principe:connect(ConnectParams),
+ OldSize = list_to_integer(proplists:get_value(size, principe:stat(Socket))),
+ ok = principe:optimize(Socket, "#bnum=1000000#opts=ld"),
+ NewSize = list_to_integer(proplists:get_value(size, principe:stat(Socket))),
+ true = NewSize > OldSize,
+ ok.
+
misc_test(ConnectParams) ->
{ok, Socket} = principe:connect(ConnectParams),
ok = principe:vanish(Socket),
Please sign in to comment.
Something went wrong with that request. Please try again.