<commit_before>%% -------------------------------------------------------------------
%%
%% Copyright (c) 2007-2011 Basho Technologies, Inc.  All Rights Reserved.
%%
%% -------------------------------------------------------------------

%% @doc Module to write data to Riak.

-module(riak_moss_dummy_reader).

-behaviour(gen_server).

-include("riak_moss.hrl").

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

-endif.

%% API
-export([start_link/1,
         get_manifest/1,
         get_chunk/5]).

%% gen_server callbacks
-export([init/1,
         handle_call/3,
         handle_cast/2,
         handle_info/2,
         terminate/2,
         code_change/3]).

-record(state, {content_length :: integer(),
                block_size :: integer(),
                bucket :: binary(),
                key :: binary(),
                caller_pid :: pid()}).

-type state() :: #state{}.


%% ===================================================================
%% Public API
%% ===================================================================

%% @doc Start a `riak_moss_reader'.
-spec start_link(list()) -> {ok, pid()} | {error, term()}.
start_link(Args) ->
    gen_server:start_link(?MODULE, Args, []).

get_manifest(Pid) ->
    gen_server:call(Pid, get_manifest, infinity).

get_chunk(Pid, Bucket, Key, UUID, ChunkSeq) ->
    gen_server:cast(Pid, {get_chunk, Bucket, Key, UUID, ChunkSeq}).

%% TODO:
%% Add shutdown public function

%% ===================================================================
%% gen_server callbacks
%% ===================================================================

%% @doc Initialize the server.
-spec init([pid()] | {test, [pid()]}) -> {ok, state()} | {stop, term()}.
init([CallerPid, Bucket, Key, ContentLength, BlockSize]) ->
    %% Get a connection to riak
    {ok, #state{content_length=ContentLength,
                bucket=Bucket,
                key=Key,
                block_size=BlockSize,
                caller_pid=CallerPid}}.

%% @doc Unused
-spec handle_call(term(), {pid(), term()}, state()) ->
                         {reply, ok, state()}.
handle_call(get_manifest, _From, #state{bucket=Bucket,
                                               key=Key,
                                               content_length=ContentLength}=State) ->
    Manifest = riak_moss_lfs_utils:new_manifest(Bucket,
                                                Key,
                                                <<"uuid">>,
                                                ContentLength,
                                                "application/test",
                                                <<"md5">>,
                                                orddict:new(),
                                                riak_moss_lfs_utils:block_size(),
                                                riak_moss_acl_utils:default_acl("tester", "id123", "keyid123")),
    {reply, {ok, Manifest}, State};
handle_call(_Msg, _From, State) ->
    {reply, ok, State}.

handle_cast({get_block, _From, Bucket, Key, UUID, BlockNumber}, #state{caller_pid=CallerPid}=State) ->
    FakeData = <<BlockNumber:32/integer>>,
    RiakObject = riakc_obj:new_obj(Bucket,riak_moss_lfs_utils:block_name(Key, UUID, BlockNumber), [], [{dict:new(),FakeData}]),
    riak_moss_get_fsm:chunk(CallerPid, BlockNumber, {ok, RiakObject}),
    {noreply, State};
handle_cast(Event, State) ->
    lager:warning("Received unknown cast event: ~p", [Event]),
    {noreply, State}.

%% @doc @TODO
-spec handle_info(term(), state()) ->
                         {noreply, state()}.
handle_info(_Info, State) ->
    {noreply, State}.

%% @doc Unused.
-spec terminate(term(), state()) -> ok.
terminate(_Reason, _State) ->
    ok.

%% @doc Unused.
-spec code_change(term(), state(), term()) -><commit_msg>Add ClusterID pattern match to dummy block server<commit_after>%% -------------------------------------------------------------------
%%
%% Copyright (c) 2007-2011 Basho Technologies, Inc.  All Rights Reserved.
%%
%% -------------------------------------------------------------------

%% @doc Module to write data to Riak.

-module(riak_moss_dummy_reader).

-behaviour(gen_server).

-include("riak_moss.hrl").

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

-endif.

%% API
-export([start_link/1,
         get_manifest/1]).

%% gen_server callbacks
-export([init/1,
         handle_call/3,
         handle_cast/2,
         handle_info/2,
         terminate/2,
         code_change/3]).

-record(state, {content_length :: integer(),
                block_size :: integer(),
                bucket :: binary(),
                key :: binary(),
                caller_pid :: pid()}).

-type state() :: #state{}.


%% ===================================================================
%% Public API
%% ===================================================================

%% @doc Start a `riak_moss_reader'.
-spec start_link(list()) -> {ok, pid()} | {error, term()}.
start_link(Args) ->
    gen_server:start_link(?MODULE, Args, []).

get_manifest(Pid) ->
    gen_server:call(Pid, get_manifest, infinity).

%% TODO:
%% Add shutdown public function

%% ===================================================================
%% gen_server callbacks
%% ===================================================================

%% @doc Initialize the server.
-spec init([pid()] | {test, [pid()]}) -> {ok, state()} | {stop, term()}.
init([CallerPid, Bucket, Key, ContentLength, BlockSize]) ->
    %% Get a connection to riak
    {ok, #state{content_length=ContentLength,
                bucket=Bucket,
                key=Key,
                block_size=BlockSize,
                caller_pid=CallerPid}}.

%% @doc Unused
-spec handle_call(term(), {pid(), term()}, state()) ->
                         {reply, ok, state()}.
handle_call(get_manifest, _From, #state{bucket=Bucket,
                                               key=Key,
                                               content_length=ContentLength}=State) ->
    Manifest = riak_moss_lfs_utils:new_manifest(Bucket,
                                                Key,
                                                <<"uuid">>,
                                                ContentLength,
                                                "application/test",
                                                <<"md5">>,
                                                orddict:new(),
                                                riak_moss_lfs_utils:block_size(),
                                                riak_moss_acl_utils:default_acl("tester", "id123", "keyid123")),
    {reply, {ok, Manifest}, State};
handle_call(_Msg, _From, State) ->
    {reply, ok, State}.

handle_cast({get_block, _From, Bucket, Key, UUID, BlockNumber}, #state{caller_pid=CallerPid}=State) ->
    FakeData = <<BlockNumber:32/integer>>,
    RiakObject = riakc_obj:new_obj(Bucket,riak_moss_lfs_utils:block_name(Key, UUID, BlockNumber), [], [{dict:new(),FakeData}]),
    riak_moss_get_fsm:chunk(CallerPid, BlockNumber, {ok, RiakObject}),
    {noreply, State};
handle_cast({get_block, _From, Bucket, Key, _CLusterID, UUID, BlockNumber}, #state{caller_pid=CallerPid}=State) ->
    FakeData = <<BlockNumber:32/integer>>,
    RiakObject = riakc_obj:new_obj(Bucket,riak_moss_lfs_utils:block_name(Key, UUID, BlockNumber), [], [{dict:new(),FakeData}]),
    riak_moss_get_fsm:chunk(CallerPid, BlockNumber, {ok, RiakObject}),
    {noreply, State};
handle_cast(Event, State) ->
    lager:warning("Received unknown cast event: ~p", [Event]),
    {noreply, State}.

%% @doc @TODO
-spec handle_info(term(), state()) ->
                         {noreply, state()}.
handle_info(_Info, State) ->
    {noreply, State}.

%% @doc Unused.
-spec terminate(term(), state()) -> ok.
terminate(_Reason, _State) ->
    ok.

%% @doc Unused.
-spec code_change(term(), state(), term()) ->
{'fraction_non_alphanumeric': 0.2396610598204123, 'fraction_numerical': 0.0067029214619957, 'mean_word_length': 2.056822574410514, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6178640', 'n_tokens_mistral': 2296, 'n_tokens_neox': 2175, 'n_words': 430}