Adding test code; cleanup whitespace in driver

This commit is contained in:
Dave Smith 2008-12-08 06:59:04 -07:00
parent ade3f99f81
commit 56ece164c7
2 changed files with 50 additions and 2 deletions

View file

@ -34,6 +34,7 @@ static void* zalloc(unsigned int size);
*/
static DB_ENV* G_DB_ENV;
/**
* Global variable to track the return code from opening the DB_ENV. We track this
* value so as to provide a useful error code when the user attempts to open the
@ -162,8 +163,7 @@ static void bdberl_drv_finish()
{
// Driver is unloading -- cleanup and shut down the BDB environment. Note that we assume
// all ports have been released and thuse all databases/txns/etc are also gone.
G_DB_ENV->close(G_DB_ENV, 0);
G_DB_ENV->close(G_DB_ENV, 0);
driver_free(G_DATABASES);
erl_drv_rwlock_destroy(G_DATABASES_RWLOCK);
hive_hash_destroy(G_DATABASES_NAMES);

48
test/port_SUITE.erl Normal file
View file

@ -0,0 +1,48 @@
%% -------------------------------------------------------------------
%%
%% bdberl: Port Tests
%% Copyright (c) 2008 The Hive. All rights reserved.
%%
%% -------------------------------------------------------------------
-module(port_SUITE).
-compile(export_all).
all() ->
[test_db].
init_per_testcase(TestCase, Config) ->
Config.
end_per_testcase(TestCase, _Config) ->
ok.
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).