Permalink
Browse files

add new dynamic variable to get server hostname and port

  • Loading branch information...
1 parent fac7bde commit 77acf5e4475b61a9a9d0ca651ecdcf6a73d68419 @nniclausse nniclausse committed Jun 12, 2012
View
@@ -96,7 +96,7 @@
<!--CUT DEF section 1 --><H1 ALIGN=center>Tsung User’s manual</H1><DIV CLASS="center">
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1><TR><TD ALIGN=left NOWRAP bgcolor="#F2F2F2"> Version:</TD><TD ALIGN=left NOWRAP>1.4.2</TD></TR>
-<TR><TD ALIGN=left NOWRAP bgcolor="#F2F2F2"> Date :</TD><TD ALIGN=left NOWRAP>April 1, 2012</TD></TR>
+<TR><TD ALIGN=left NOWRAP bgcolor="#F2F2F2"> Date :</TD><TD ALIGN=left NOWRAP>June 12, 2012</TD></TR>
</TABLE>
</DIV><!--TOC section Contents-->
<H2 CLASS="section"><!--SEC ANCHOR -->Contents</H2><!--SEC END --><UL CLASS="toc"><LI CLASS="li-toc">
@@ -2848,7 +2848,7 @@ <H5 CLASS="paragraph"><!--SEC ANCHOR -->PostgreSQL</H5><!--SEC END --><P>
</TABLE><P>So in the example, the <TT>row</TT> variable equals "aid".</P><!--TOC paragraph set_dynvars-->
<H5 CLASS="paragraph"><!--SEC ANCHOR -->set_dynvars</H5><!--SEC END --><P><B>Since version 1.3.0</B>, more powerful dynamic variables are implemented:</P><P>You can set dynamic variables not only while parsing server data, but
you can build them using external files or generate them with a function
-or generate random numbers/strings:</P><P>Six types of dynamic variables are currently implemented (<TT>sourcetype</TT> tag):
+or generate random numbers/strings:</P><P>Several types of dynamic variables are implemented (<TT>sourcetype</TT> tag):
</P><OL CLASS="enumerate" type=1><LI CLASS="li-enumerate">
Dynamic variables defined by calling an erlang function:
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD><TABLE BORDER=0 CELLPADDING=0
@@ -2974,6 +2974,26 @@ <H5 CLASS="paragraph"><!--SEC ANCHOR -->set_dynvars</H5><!--SEC END --><P><B>Sin
</TD></TR>
</TABLE></TD></TR>
</TABLE></TD></TR>
+</TABLE></LI><LI CLASS="li-enumerate">You can create dynamic variables to get the hostname and port of
+the current server
+<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD><TABLE BORDER=0 CELLPADDING=0
+CELLSPACING=0><TR><TD BGCOLOR=black COLSPAN="3"><TABLE CELLSPACING="1" CELLPADDING=0 BORDER=0><TR><TD>
+</TD></TR>
+</TABLE></TD></TR>
+<TR><TD BGCOLOR=black COLSPAN="1"><TABLE CELLSPACING="1" CELLPADDING=0 BORDER=0><TR><TD>
+</TD></TR>
+</TABLE></TD><TD><TABLE BORDER=0 CELLPADDING="1" CELLSPACING=0><TR><TD><PRE CLASS="verbatim"> &lt;setdynvars sourcetype="server"&gt;
+ &lt;var name="host" /&gt;
+ &lt;var name="port" /&gt;
+ &lt;/setdynvars&gt;
+</PRE></TD></TR>
+</TABLE></TD><TD BGCOLOR=black COLSPAN="1"><TABLE CELLSPACING="1" CELLPADDING=0 BORDER=0><TR><TD>
+</TD></TR>
+</TABLE></TD></TR>
+<TR><TD BGCOLOR=black COLSPAN="3"><TABLE CELLSPACING="1" CELLPADDING=0 BORDER=0><TR><TD>
+</TD></TR>
+</TABLE></TD></TR>
+</TABLE></TD></TR>
</TABLE></LI></OL><P>A <TT>setdynvars</TT> can be defined anywhere in a session.</P><!--TOC subsubsection Checking the server’s response-->
<H4 CLASS="subsubsection"><!--SEC ANCHOR --><A NAME="htoc67">6.7.4</A>  Checking the server’s response</H4><!--SEC END --><P>With the tag <TT>match</TT> in a <TT>request</TT> tag, you can check
the server’s response against a given string, and do some actions
View
@@ -2255,7 +2255,7 @@ \subsubsection{Dynamic variables}\label{Dynamic variables}
you can build them using external files or generate them with a function
or generate random numbers/strings:
-Six types of dynamic variables are currently implemented (\varname{sourcetype} tag):
+Several types of dynamic variables are implemented (\varname{sourcetype} tag):
\begin{enumerate}
\item Dynamic variables defined by calling an erlang function:
\begin{Verbatim}
@@ -2310,6 +2310,14 @@ \subsubsection{Dynamic variables}\label{Dynamic variables}
<var name="deployed" />
</setdynvars>
\end{Verbatim}
+\item You can create dynamic variables to get the hostname and port of
+ the current server
+\begin{Verbatim}
+ <setdynvars sourcetype="server">
+ <var name="host" />
+ <var name="port" />
+ </setdynvars>
+\end{Verbatim}
\end{enumerate}
View
@@ -418,7 +418,7 @@ handle_next_action(State) ->
handle_next_action(NewState);
{setdynvars,SourceType,Args,VarNames} ->
DynData=State#state_rcv.dyndata,
- Result = set_dynvars(SourceType,Args,VarNames,DynData),
+ Result = set_dynvars(SourceType,Args,VarNames,DynData,{State#state_rcv.host,State#state_rcv.port}),
NewDynVars = ts_dynvars:set(VarNames,Result,DynData#dyndata.dynvars),
NewDynData = DynData#dyndata{dynvars=NewDynVars},
?DebugF("set dynvars: ~p ~p~n",[NewDynVars, NewDynData]),
@@ -463,33 +463,37 @@ handle_next_action(State) ->
%%----------------------------------------------------------------------
%% @spec set_dynvars (Type::erlang|random|urandom|file, Args::tuple(),
-%% Variables::list(), DynData::#dyndata{}) -> integer()|binary()|list()
+%% Variables::list(), DynData::#dyndata{},
+%% Server::string(),Port:integer()}) -> integer()|binary()|list()
%% @doc setting the value of several dynamic variables at once.
%% @end
%%----------------------------------------------------------------------
-set_dynvars(erlang,{Module,Callback},_Vars,DynData) ->
+set_dynvars(erlang,{Module,Callback},_Vars,DynData,_) ->
Module:Callback({self(),DynData#dyndata.dynvars});
-set_dynvars(code,Fun,_Vars,DynData) ->
+set_dynvars(code,Fun,_Vars,DynData,_) ->
Fun({self(),DynData#dyndata.dynvars});
-set_dynvars(random,{number,Start,End},Vars,_DynData) ->
+set_dynvars(random,{number,Start,End},Vars,_DynData,_) ->
lists:map(fun(_) -> ts_stats:uniform(Start,End) end,Vars);
-set_dynvars(random,{string,Length},Vars,_DynData) ->
+set_dynvars(random,{string,Length},Vars,_DynData,_) ->
R = fun(_) -> ts_utils:randombinstr(Length) end,
lists:map(R,Vars);
-set_dynvars(urandom,{string,Length},Vars,_DynData) ->
+set_dynvars(urandom,{string,Length},Vars,_DynData,_) ->
%% not random, but much faster
R = fun(_) -> ts_utils:urandombinstr(Length) end,
lists:map(R,Vars);
-set_dynvars(file,{random,FileId,Delimiter},_Vars,_DynData) ->
+set_dynvars(file,{random,FileId,Delimiter},_Vars,_DynData,_) ->
{ok,Line} = ts_file_server:get_random_line(FileId),
ts_utils:split(Line,Delimiter);
-set_dynvars(file,{iter,FileId,Delimiter},_Vars,_DynData) ->
+set_dynvars(file,{iter,FileId,Delimiter},_Vars,_DynData,_) ->
{ok,Line} = ts_file_server:get_next_line(FileId),
ts_utils:split(Line,Delimiter);
-set_dynvars(jsonpath,{JSONPath, From},_Vars,DynData) ->
+set_dynvars(jsonpath,{JSONPath, From},_Vars,DynData,_) ->
{ok, Val} = ts_dynvars:lookup(From,DynData#dyndata.dynvars),
JSON=mochijson2:decode(Val),
- ts_utils:jsonpath(JSONPath, JSON).
+ ts_utils:jsonpath(JSONPath, JSON);
+set_dynvars(server,_,_,_,{Host,Port}) ->
+ [Host,Port].
+
%% @spec ctrl_struct(CtrlData::term(),State::#state_rcv{},Count::integer) ->
%% {next_state, NextStateName::atom(), NextState::#state_rcv{}} |
@@ -831,7 +831,9 @@ parse(Element = #xmlElement{name=setdynvars, attributes=Attrs},
"jsonpath" ->
From = getAttr(atom, Attrs,from),
JSONPath = getAttr(Attrs,jsonpath),
- {setdynvars,jsonpath,{JSONPath, From},Vars}
+ {setdynvars,jsonpath,{JSONPath, From},Vars};
+ "server" ->
+ {setdynvars,server,{},Vars}
end,
?LOGF("Add setdynvars in session ~p as id ~p",[CurS#session.id,Id+1],?INFO),
ets:insert(Tab, {{CurS#session.id, Id+1}, Action}),
@@ -66,11 +66,11 @@ start_phase(load_config, _StartType, _PhaseArgs) ->
File ->
T = case file:read_file_info(File) of
{ok, #file_info{size=Size}} when Size > 10000000 -> % > 10MB
- io:format(standard_error,"Can take up to 5mn to read config ~p~n ",[Size]),
- 300000; % 10mn
+ io:format(standard_error,"Can take up to 5mn to read config file of size ~p~n ",[Size]),
+ 300000; % 5mn
{ok, #file_info{size=Size}} when Size > 1000000 -> % > 1MB
- io:format(standard_error,"Can take up to 3mn to read config ~p~n ",[Size]),
- 180000; % 5mn
+ io:format(standard_error,"Can take up to 3mn to read config file of size ~p~n ",[Size]),
+ 180000; % 3mn
{ok, #file_info{size=_}} ->
120000 % 2mn
end,
View
@@ -324,7 +324,7 @@ repeat | if | change_type | foreach | set_option)*>
<!ELEMENT setdynvars (var*) >
<!ATTLIST setdynvars
sourcetype (random_string | urandom_string | random_number |
- file | erlang | eval| jsonpath) #REQUIRED
+ file | erlang | eval| jsonpath |server) #REQUIRED
callback CDATA #IMPLIED
code CDATA #IMPLIED
fileid CDATA #IMPLIED

0 comments on commit 77acf5e

Please sign in to comment.