Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew Kerrigan committed Dec 6, 2013
1 parent 512b57d commit 447e85c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
8 changes: 4 additions & 4 deletions examples/http.config
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
% Generators: list() - list of generators, can be key_generator or value_generator for default
{targets, [
{base_uri_t, {"localhost", 4567, "/"}},
{with_key_t, {"localhost", 4567, {"/~p", key_generator}}},
{with_another_key_t, {"localhost", 4567, {"another/~p", string_g}}},
{smallbin_t, {"localhost", 4567, {"smallbin/~p", key_generator}}},
{upload_t, {"localhost", 4567, {"upload/~p", key_generator}}}
{with_key_t, {"localhost", 4567, {"/~s", [key_generator]}}},
{with_another_key_t, {"localhost", 4567, {"another/~s", [string_g]}}},
{smallbin_t, {"localhost", 4567, {"smallbin/~s", [key_generator]}}},
{upload_t, {"localhost", 4567, {"upload/~s", [key_generator]}}}
]}.

%%% Operations: {{get|delete, Target}, Weight}
Expand Down
46 changes: 22 additions & 24 deletions src/basho_bench_driver_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ build_generators([{Name, {value_generator, ValGenSpec}}|Rest], Generators, Id) -
ValGen = basho_bench_valgen:new(ValGenSpec, Id),
build_generators(Rest, [{Name, ValGen}|Generators], Id);
build_generators([], Generators, _) ->
{ok, Generators}.
Generators.

new(Id) ->
?DEBUG("ID: ~p\n", [Id]),
Expand Down Expand Up @@ -91,80 +91,77 @@ run({get, Target}, KeyGen, ValueGen, State) ->
run({get, Target, undefined}, KeyGen, ValueGen, State);
run({get, Target, HeaderName}, KeyGen, ValueGen, State) ->
Url = build_url(Target, KeyGen, ValueGen, State),
Headers = proplists:get(HeaderName, State#state.headers, []),
Headers = proplists:get_value(HeaderName, State#state.headers, []),

case do_get(Url, Headers) of
{not_found, _Url} ->
{ok, 1};
{ok, State};
{ok, _Url, _Header} ->
{ok, 1};
{ok, State};
{error, Reason} ->
{error, Reason, 1}
{error, Reason, State}
end;

run({put, Target, ValueName}, KeyGen, ValueGen, State) ->
run({put, Target, ValueName, undefined}, KeyGen, ValueGen, State);
run({put, Target, ValueName, HeaderName}, KeyGen, ValueGen, State) ->
Url = build_url(Target, KeyGen, ValueGen, State),
Headers = proplists:get(HeaderName, State#state.headers, []),
Headers = proplists:get_value(HeaderName, State#state.headers, []),
Data = build_value(ValueName, KeyGen, ValueGen, State),

case do_put(Url, Headers, Data) of
ok ->
{ok, 1};
{ok, State};
{error, Reason} ->
{error, Reason, 1}
{error, Reason, State}
end;

run({post, Target, ValueName}, KeyGen, ValueGen, State) ->
run({post, Target, ValueName, undefined}, KeyGen, ValueGen, State);
run({post, Target, ValueName, HeaderName}, KeyGen, ValueGen, State) ->
Url = build_url(Target, KeyGen, ValueGen, State),
Headers = proplists:get(HeaderName, State#state.headers, []),
Headers = proplists:get_value(HeaderName, State#state.headers, []),
Data = build_value(ValueName, KeyGen, ValueGen, State),

case do_post(Url, Headers, Data) of
ok ->
{ok, 1};
{ok, State};
{error, Reason} ->
{error, Reason, 1}
{error, Reason, State}
end;

run({delete, Target}, KeyGen, ValueGen, State) ->
run({delete, Target, undefined}, KeyGen, ValueGen, State);
run({delete, Target, HeaderName}, KeyGen, ValueGen, State) ->
Url = build_url(Target, KeyGen, ValueGen, State),
Headers = proplists:get(HeaderName, State#state.headers, []),
Headers = proplists:get_value(HeaderName, State#state.headers, []),

case do_delete(Url, Headers) of
ok ->
{ok, 1};
{ok, State};
{error, Reason} ->
{error, Reason, 1}
{error, Reason, State}
end.

%% ====================================================================
%% Internal functions
%% ====================================================================

evaluate_generator(Name, Generators, KeyGen, ValueGen) ->
io:format("build_formatted_value_yeah2~n Name: ~p~n Generators: ~p~n Keygen: ~p~n ValueGen: ~p~n", [Name, Generators, KeyGen, ValueGen]),

case Name of
key_generator -> KeyGen();
value_generator -> ValueGen();
N when is_atom(N) -> proplists:get(N, Generators);
N when is_atom(N) ->
Fun = proplists:get_value(N, Generators),
Fun();
Value -> Value
end.

build_formatted_value(String, GeneratorNames, Generators, KeyGen, ValueGen) ->

%% F = fun(Name) ->
%% evaluate_generator(Name, Generators, KeyGen, ValueGen)
%% end,

%% Values = lists:map(F, GeneratorNames),

Values = [evaluate_generator(Name, Generators, KeyGen, ValueGen) || Name <- GeneratorNames],

io:format("build_formatted_value_yeah1~n String: ~p~n GeneratorNames: ~p~n Generators: ~p~n KeyGen: ~p~n ValueGen: ~p~n", [String, GeneratorNames, Generators, KeyGen, ValueGen]),
Values = lists:map(fun (Name) -> evaluate_generator(Name, Generators, KeyGen, ValueGen) end, GeneratorNames),
io_lib:format(String, Values).

build_url({Host, Port, {FormattedPath, GeneratorNames}}, Generators, KeyGen, ValueGen) ->
Expand All @@ -173,6 +170,7 @@ build_url({Host, Port, {FormattedPath, GeneratorNames}}, Generators, KeyGen, Val
build_url({Host, Port, Path}, _, _, _) ->
#url{host=Host, port=Port, path=Path};
build_url(Target, KeyGen, ValueGen, State) ->
io:format("build_url~n Target: ~p~n State: ~p~n", [Target, State]),
build_url(proplists:get_value(Target, State#state.targets), State#state.generators, KeyGen, ValueGen).

build_value(ValueName, KeyGen, ValueGen, State) ->
Expand Down

0 comments on commit 447e85c

Please sign in to comment.