2008-12-08 13:59:04 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% bdberl: Port Tests
|
|
|
|
%% Copyright (c) 2008 The Hive. All rights reserved.
|
|
|
|
%%
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
-module(port_SUITE).
|
|
|
|
|
|
|
|
-compile(export_all).
|
|
|
|
|
|
|
|
all() ->
|
2008-12-09 20:19:31 +00:00
|
|
|
% [test_db].
|
2008-12-09 20:46:33 +00:00
|
|
|
[test_put, test_txn].
|
2008-12-08 13:59:04 +00:00
|
|
|
|
2008-12-10 16:59:40 +00:00
|
|
|
init_per_testcase(_TestCase, Config) ->
|
2008-12-08 13:59:04 +00:00
|
|
|
Config.
|
|
|
|
|
2008-12-10 16:59:40 +00:00
|
|
|
end_per_testcase(_TestCase, _Config) ->
|
2008-12-08 13:59:04 +00:00
|
|
|
ok.
|
2008-12-10 16:59:40 +00:00
|
|
|
|
2008-12-08 13:59:04 +00:00
|
|
|
|
|
|
|
test_db(_Config) ->
|
|
|
|
{ok, P} = bdberl_port:new(),
|
|
|
|
|
|
|
|
%% Create two databases
|
|
|
|
{ok, 0} = bdberl_port:open_database(P, "test1", hash),
|
|
|
|
{ok, 1} = bdberl_port:open_database(P, "test2", btree),
|
|
|
|
|
|
|
|
%% Open another port and open the same databases in reverse order. The ref system should
|
|
|
|
%% ensure that the databases return the same refs as previously
|
|
|
|
{ok, P2} = bdberl_port:new(),
|
|
|
|
{ok, 1} = bdberl_port:open_database(P2, "test2", btree),
|
|
|
|
{ok, 0} = bdberl_port:open_database(P2, "test1", hash),
|
|
|
|
|
|
|
|
%% Close one of the databases
|
|
|
|
ok = bdberl_port:close_database(P, 0),
|
|
|
|
ok = bdberl_port:close_database(P2, 0),
|
|
|
|
|
|
|
|
%% Attempt to close an invalid ref
|
|
|
|
{error, invalid_dbref} = bdberl_port:close_database(P, 21000),
|
|
|
|
|
|
|
|
%% Open up another db -- should re-use dbref 0 as that's the first available
|
|
|
|
{ok, 0} = bdberl_port:open_database(P, "test3", btree),
|
|
|
|
|
|
|
|
%% Close both ports
|
|
|
|
true = port_close(P),
|
|
|
|
true = port_close(P2).
|
|
|
|
|
|
|
|
|
2008-12-09 20:19:31 +00:00
|
|
|
test_put(_Config) ->
|
|
|
|
{ok, P} = bdberl_port:new(),
|
|
|
|
{ok, 0} = bdberl_port:open_database(P, "test1", hash),
|
|
|
|
|
|
|
|
ok = bdberl_port:txn_begin(P),
|
|
|
|
ok = bdberl_port:put(P, 0, akey, avalue),
|
|
|
|
ok = bdberl_port:txn_commit(P),
|
|
|
|
|
2008-12-09 20:46:33 +00:00
|
|
|
ok = bdberl_port:txn_begin(P),
|
|
|
|
{ok, avalue} = bdberl_port:get(P, 0, akey),
|
|
|
|
ok = bdberl_port:txn_commit(P).
|
|
|
|
|
|
|
|
|
|
|
|
test_txn(_Config) ->
|
|
|
|
{ok, P} = bdberl_port:new(),
|
|
|
|
{ok, 0} = bdberl_port:open_database(P, "test2", btree),
|
2008-12-09 20:19:31 +00:00
|
|
|
|
2008-12-09 20:46:33 +00:00
|
|
|
ok = bdberl_port:txn_begin(P),
|
|
|
|
ok = bdberl_port:put(P, 0, akey, avalue),
|
|
|
|
ok = bdberl_port:txn_abort(P),
|
|
|
|
|
|
|
|
ok = bdberl_port:txn_begin(P),
|
|
|
|
not_found = bdberl_port:get(P, 0, akey),
|
2008-12-09 20:19:31 +00:00
|
|
|
ok = bdberl_port:txn_commit(P).
|