Hi Deepak,


>> by loading the string form of all the ids into properties object , where
based on the thread number one gets picked



Well in the beginning I tried using the setproperty() and __P() functions to
set and get the request Ids. I observed some weird errors.



I used WRS_Property to set the Request Ids which were chosen for approval
and I initially set it to 0 in the test plan.



+ThreadGroup ( 5threads, 2loops)
++Http sampler 1 (This  sampler  will fetch all the requests that are
waiting for approval)
+++ BSF Post Processor 1

                [

                                Var prevRequestId=read WRS_Property;



                                If WRS_Property is 0

                                                Then select the first
request id

                                Else

                                                Loop:

                                                                Generate a
random number and get the request Id corresponding to that random number.

                                                                If this
request Id is not same as prevRequestId


Break;



                                                Vars.put(“curRequestId”,
selectedRequestId);



                ]
++ Http Sampler 2 (The sampler sends the request id which has to be
approved)
+++ BSF Post Processor 2

                [



                                Var requestIdList=read WRS_Property;



                                If requestIdList is 0

                                                Set WRS_Property to current
request Id

                                Else

                                                Set
WRS_Property=requestIdList+”;”+vars.get(currentRequestId);

                ]





With this script in place I got the output to be

--------------------------------------------------------------

Prev WRS id: 0

Cur WRS id150399

RequestId Set To: 150399

--------------------------------------------------------------

Prev WRS id: undefined;150399

Found curRequestId: 150399

RequestId Set To: undefined;150399;150399

--------------------------------------------------------------

Prev WRS id: undefined;null

Found curRequestId: null

RequestId Set To: undefined;null;null

--------------------------------------------------------------

Prev WRS id: undefined;null

Found curRequestId: null

RequestId Set To: undefined;null;null



I’m not able to figure out why is this happening.



I have also attached the code in the BSF post processor 1 and BSF post
processor 2 in the mail.



In the mean time I will try other options you have pointed out.



Thanks for your time.



Regards,

Prasanna




On Sat, May 8, 2010 at 9:32 PM, Deepak Shetty <[email protected]> wrote:

> Hi
>  If it isnt possible to choose a simple scheme (like map a thread number to
> the id picked i.e. thread1 always picks first id , thread 2 picks second
> id)
>
> or by loading the string form of all the ids into properties object , where
> based on the thread number one gets picked
>
> then you'd have to either
> split the fetching of ids separate to the approval process
> Thread Group 1
> +Sampler 1
> ++Write all ids to CSV
> Thread Group 2
> +Sampler 2
> ++CSV DataSet Config
>
> Its also possible to combine the two thread groups into one (this needs
> some
> custom java code)
> Thread Group
> +Sampler1
> ++Each writes to their own CSV
> +Ensure only one thread writes a combined file , while the rest wait
> +Sampler 2
> CSV Data Set Config
>
> or some custom java object which allows concurrent access and can keep a
> list of ids fetched(static) and hand out  a different one to whoever
> requests it
>
> regards
> deepak
>
>
> On Sat, May 8, 2010 at 6:18 AM, prasanna bhat <[email protected]
> >wrote:
>
> > Hi,
> >
> > I have interesting use case in which the value of a given variable has to
> > be
> > compared across threads. I will try my best to illustrate it below.
> >
> > TestPlan
> > +ThreadGroup ( 5threads, 2loops)
> > ++Http sampler 1 (This  sampler  will fetch all the requests that are
> > waiting for approval)
> > +++ BSF Post Processor 1
> > ++ Http Sampler 2 (The sampler sends the request id which has to be
> > approved)
> > +++ BSF Post Processor 2
> >
> > The response of Http sampler 1 will contain a list of ids of the requests
> > to
> > be approved. I'm fetching the first request id and sending it as a
> > parameter
> > to Http Sampler 2 for approval.
> >
> > The problem occurs when the 1st thread has picked a certain request id
> (say
> > request id 1101) and send it as a parameter to Http Sampler 2 for
> approval,
> > but before this request has been approved the second thread gets active
> and
> > send a http request (Http Sampler 1) and receives all the request ids to
> be
> > approved as a response, therefore the second thread also sees request id
> > 1101 (Since it has not been approved yet) and picks it up for approval
> i.e.
> > the same request id is passed to Http Sampler 2 for second thread also.
> >  Now
> > there is clash of multiple threads trying to approve the same request and
> > the server responds with an error.
> >
> >
> >
> > So my question is, how do I ensure different threads pick different
> request
> > id (i.e one that is not picked up by any of the other active threads)??
> >
> >
> >
> > Please let me know if I have to make it more clearer.
> >
> >
> >
> > Thanks,
> >
> > Prasanna
> >
>
OUT.println("--------------------------------------------------------------");

var i=1;
var prevWRSId=${__P(WRS_Property)};
var curWRSId="";

var foundUniqueRequestId="true";
var randomRequestId;

OUT.println("Prev WRS id: " + prevWRSId);

if(prevWRSId==0){
        vars.put("myWRS", vars.get("WRS_1"));
        OUT.println("Cur WRS id" + vars.get("WRS_1"));  
}
else{

        while(foundUniqueRequestId=="true"){    
                
randomRequestId=Math.floor(Math.random()*vars.get("WRS_matchNr"));
                curWRSId=vars.get("WRS_"+randomRequestId);                      
        

                if(prevWRSId.search(curWRSId)!= -1){
                        foundUniqueRequestId="false";
                        OUT.println("Found curRequestId: "+curWRSId);
                }
                
                i++;
        }

        vars.put("myWRS", curWRSId);
}
var prevWRSId=${__P(WRS_Property)};

if(prevWRSId==0)
{
        ${__setProperty(WRS_Property, vars.get("myWRS"))};
        OUT.println("RequestId Set To: "+${__P(WRS_Property)});
}
else{
        ${__setProperty(WRS_Property, prevWRSId+";"+vars.get("myWRS"))};
        OUT.println("RequestId Set To: "+${__P(WRS_Property)});
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to