From 52e2fa2edb826691e63283d6b0a8409dd6ade4b5 Mon Sep 17 00:00:00 2001 From: Scott Lystig Fritchie Date: Sat, 30 Aug 2014 18:05:32 +0900 Subject: [PATCH] Start WIP on tango_oid.erl --- prototype/tango-prototype/src/tango_oid.erl | 80 +++++++++++++++++++ .../tango-prototype/test/tango_oid_test.erl | 39 +++++++++ 2 files changed, 119 insertions(+) create mode 100644 prototype/tango-prototype/src/tango_oid.erl create mode 100644 prototype/tango-prototype/test/tango_oid_test.erl diff --git a/prototype/tango-prototype/src/tango_oid.erl b/prototype/tango-prototype/src/tango_oid.erl new file mode 100644 index 0000000..5679570 --- /dev/null +++ b/prototype/tango-prototype/src/tango_oid.erl @@ -0,0 +1,80 @@ +%% ------------------------------------------------------------------- +%% +%% Copyright (c) 2014 Basho Technologies, Inc. All Rights Reserved. +%% +%% This file is provided to you under the Apache License, +%% Version 2.0 (the "License"); you may not use this file +%% except in compliance with the License. You may obtain +%% a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, +%% software distributed under the License is distributed on an +%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +%% KIND, either express or implied. See the License for the +%% specific language governing permissions and limitations +%% under the License. +%% +%% ------------------------------------------------------------------- + +-module(tango_oid). + +-behaviour(gen_server). + +%% API +-export([start_link/2, stop/1]). + +%% gen_server callbacks +-export([init/1, handle_call/3, handle_cast/2, handle_info/2, + terminate/2, code_change/3]). + +-define(SERVER, ?MODULE). +-define(OID_STREAM_NUMBER, 0). + +-define(LONG_TIME, 5*1000). +%% -define(LONG_TIME, 30*1000). + +-record(state, { + seq :: pid(), + proj :: term() + }). + +start_link(SequencerPid, Proj) -> + gen_server:start_link({local, ?SERVER}, ?MODULE, [SequencerPid, Proj], []). + +stop(Pid) -> + gen_server:call(Pid, {stop}, ?LONG_TIME). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +init([SequencerPid, Proj]) -> + {ok, CurrentLPN} = corfurl_sequencer:get(SequencerPid, 0), + LastLPN = CurrentLPN - 1, +io:format(user, "LastLPN = ~p\n", [LastLPN]), + LPNandPages = tango:scan_backward(Proj, ?OID_STREAM_NUMBER, LastLPN, false), + {_LPNS, Pages} = lists:unzip(LPNandPages), + io:format("Pages = ~p\n", [Pages]), + {ok, #state{seq=SequencerPid, + proj=Proj}}. + +handle_call({stop}, _From, State) -> + {stop, normal, ok, State}; +handle_call(_Request, _From, State) -> + Reply = whaaaaaaaaaaaa, + {reply, Reply, State}. + +handle_cast(_Msg, State) -> + {noreply, State}. + +handle_info(_Info, State) -> + {noreply, State}. + +terminate(_Reason, _State) -> + ok. + +code_change(_OldVsn, State, _Extra) -> + {ok, State}. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + diff --git a/prototype/tango-prototype/test/tango_oid_test.erl b/prototype/tango-prototype/test/tango_oid_test.erl new file mode 100644 index 0000000..f0f3e9a --- /dev/null +++ b/prototype/tango-prototype/test/tango_oid_test.erl @@ -0,0 +1,39 @@ +%% ------------------------------------------------------------------- +%% +%% Copyright (c) 2014 Basho Technologies, Inc. All Rights Reserved. +%% +%% This file is provided to you under the Apache License, +%% Version 2.0 (the "License"); you may not use this file +%% except in compliance with the License. You may obtain +%% a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, +%% software distributed under the License is distributed on an +%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +%% KIND, either express or implied. See the License for the +%% specific language governing permissions and limitations +%% under the License. +%% +%% ------------------------------------------------------------------- + +-module(tango_oid_test). + +-ifdef(TEST). +-include_lib("eunit/include/eunit.hrl"). +-compile(export_all). +-ifdef(PULSE). +-compile({parse_transform, pulse_instrument}). +-endif. +-endif. + +tango_oid_smoke_test() -> + ok = tango_test:run_test("/tmp", "tango_oid_smoke", 4096, 5*1024, 1, + fun tango_oid_smoke_test_int/3). + +tango_oid_smoke_test_int(_PageSize, Seq, Proj) -> + {ok, OID_Map} = tango_oid:start_link(Seq, Proj), + ok = tango_oid:stop(OID_Map), + + ok.