2008-12-11 01:18:05 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% bdberl: Port Driver Thrash tests
|
|
|
|
%% Copyright (c) 2008 The Hive. All rights reserved.
|
|
|
|
%%
|
2009-06-23 19:22:11 +00:00
|
|
|
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
%% of this software and associated documentation files (the "Software"), to deal
|
|
|
|
%% in the Software without restriction, including without limitation the rights
|
|
|
|
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
%% copies of the Software, and to permit persons to whom the Software is
|
|
|
|
%% furnished to do so, subject to the following conditions:
|
|
|
|
%%
|
|
|
|
%% The above copyright notice and this permission notice shall be included in
|
|
|
|
%% all copies or substantial portions of the Software.
|
|
|
|
%%
|
|
|
|
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
%% THE SOFTWARE.
|
|
|
|
%%
|
2008-12-11 01:18:05 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
-module(thrash_SUITE).
|
|
|
|
|
|
|
|
-compile(export_all).
|
|
|
|
|
|
|
|
all() ->
|
|
|
|
[test_thrash].
|
|
|
|
|
2008-12-11 18:52:19 +00:00
|
|
|
-define(PROCS, 10).
|
2008-12-11 01:18:05 +00:00
|
|
|
|
|
|
|
test_thrash(_Config) ->
|
|
|
|
%% Spin up 15 processes (async thread pool is 10)
|
|
|
|
start_procs(?PROCS),
|
|
|
|
wait_for_finish(?PROCS).
|
|
|
|
|
2009-02-18 21:13:09 +00:00
|
|
|
start_procs(0) ->
|
2008-12-11 01:18:05 +00:00
|
|
|
ok;
|
|
|
|
start_procs(Count) ->
|
|
|
|
spawn_link(?MODULE, thrash_run, [self()]),
|
|
|
|
start_procs(Count-1).
|
|
|
|
|
|
|
|
wait_for_finish(0) ->
|
|
|
|
ok;
|
|
|
|
wait_for_finish(Count) ->
|
|
|
|
receive
|
|
|
|
{finished, Pid} ->
|
2008-12-15 20:52:35 +00:00
|
|
|
ct:print("~p is done; ~p remaining.\n", [Pid, Count-1]),
|
2008-12-11 01:18:05 +00:00
|
|
|
wait_for_finish(Count-1)
|
|
|
|
end.
|
|
|
|
|
|
|
|
thrash_run(Owner) ->
|
|
|
|
%% Seed the RNG
|
|
|
|
{A1, A2, A3} = now(),
|
|
|
|
random:seed(A1, A2, A3),
|
|
|
|
|
|
|
|
%% Open up a port and database
|
2008-12-12 20:43:09 +00:00
|
|
|
{ok, 0} = bdberl:open("thrash", btree),
|
2008-12-11 01:18:05 +00:00
|
|
|
|
|
|
|
%% Start thrashing
|
2008-12-12 20:43:09 +00:00
|
|
|
thrash_incr_loop(Owner, 1000).
|
2008-12-11 01:18:05 +00:00
|
|
|
|
2008-12-12 20:43:09 +00:00
|
|
|
thrash_incr_loop(Owner, 0) ->
|
2008-12-11 01:18:05 +00:00
|
|
|
Owner ! {finished, self()};
|
2008-12-12 20:43:09 +00:00
|
|
|
thrash_incr_loop(Owner, Count) ->
|
2008-12-16 22:22:04 +00:00
|
|
|
% ct:print("~p", [Count]),
|
2008-12-11 01:18:05 +00:00
|
|
|
%% Choose random key
|
2008-12-11 02:47:00 +00:00
|
|
|
Key = random:uniform(1200),
|
2009-02-18 21:13:09 +00:00
|
|
|
|
2008-12-11 01:18:05 +00:00
|
|
|
%% Start a txn that will read the current value of the key and increment by 1
|
2008-12-15 20:52:35 +00:00
|
|
|
F = fun(_Key, Value) ->
|
|
|
|
case Value of
|
|
|
|
not_found -> 0;
|
|
|
|
Value -> Value + 1
|
|
|
|
end
|
2008-12-11 01:18:05 +00:00
|
|
|
end,
|
2008-12-15 20:52:35 +00:00
|
|
|
{ok, _} = bdberl:update(0, Key, F),
|
2008-12-12 20:43:09 +00:00
|
|
|
thrash_incr_loop(Owner, Count-1).
|