Wrap function usage in Grinder

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Wrap function usage in Grinder

Balaji
Hi,

I would like to measure the transaction time of one function which I defined inside the class.. In the following class, I wanted to measure only test_greeting function. I also need to verify the value which was returned by test_greeting. When I run the test, I am getting the following error.

net.grinder.scriptengine.jython.JythonScriptExecutionException: Java exception calling TestRunner
        grinder.statistics.forLastTest.success = success
        File "${NGRINDER_HOME}/script/user/Test_Wrap.py", line 28, in __call__
net.grinder.script.InvalidContextException: No tests have been performed by this thread.


#Test_wrap.py
from net.grinder.script import Test
from net.grinder.script.Grinder import grinder
from java.util import Date
from java.text import SimpleDateFormat
from java.lang import String
from java.util import Random, Properties


log = grinder.logger.info
class TestRunner:
        def test_Greeting(self, strMsg):
                grinder.sleep(1000)
                return strMsg

        def __init__(self):
                grinder.statistics.delayReports=True
                self.do_request_test = Test(1, "Perform service request").wrap(self.test_Greeting)
                log("Thread starting up")
                pass

        def __call__(self):
                replyMessage = None
                success = 0
                replyMessage = self.do_request_test("Hi")
                if replyMessage == "Hi":
                        success = 1
                grinder.sleep(1000)
                grinder.statistics.forLastTest.success = success

        def __del__(self):
                log("Thread shutting down")



Can any of you please suggest me whether I am doing it properly?.. Is there any other way to achieve this?

Regards,
Balaji

Reply | Threaded
Open this post in threaded view
|

RE: Wrap function usage in Grinder

junoyoon
Administrator

You should write a script like this.

 

#Test_wrap.py 
from net.grinder.script import Test 
from net.grinder.script.Grinder import grinder 
from java.util import Date 
from java.text import SimpleDateFormat 
from java.lang import String 
from java.util import Random, Properties 

def test_Greeting(strMsg): 
      grinder.sleep(1000) 
      return strMsg 

 

do_request_test = Test(1, "Perform service request").wrap(test_Greeting)  

 

log = grinder.logger.info 

class TestRunner:

        def __init__(self): 
                grinder.statistics.delayReports=True 
                log("Thread starting up") 
                pass 

        def __call__(self): 
                replyMessage = None 
                success = 0 
                replyMessage =do_request_test("Hi") 

                if replyMessage == "Hi": 
                        success = 1 
                grinder.sleep(1000) 
                grinder.statistics.forLastTest.success = success 

        def __del__(self): 
                log("Thread shutting down")  

  

-----Original Message-----
From: "Balaji [via ngrinder]"<[hidden email]>
To: "junoyoon"<[hidden email]>;
Cc:
Sent: 2013-02-14 (목) 00:46:38
Subject: Wrap function usage in Grinder

Hi,

I would like to measure the transaction time of one function which I defined inside the class.. In the following class, I wanted to measure only test_greeting function. I also need to verify the value which was returned by test_greeting. When I run the test, I am getting the following error.

net.grinder.scriptengine.jython.JythonScriptExecutionException: Java exception calling TestRunner
        grinder.statistics.forLastTest.success = success
        File "${NGRINDER_HOME}/script/user/Test_Wrap.py", line 28, in __call__
net.grinder.script.InvalidContextException: No tests have been performed by this thread.


#Test_wrap.py
from net.grinder.script import Test
from net.grinder.script.Grinder import grinder
from java.util import Date
from java.text import SimpleDateFormat
from java.lang import String
from java.util import Random, Properties


log = grinder.logger.info
class TestRunner:
        def test_Greeting(self, strMsg):
                grinder.sleep(1000)
                return strMsg

        def __init__(self):
                grinder.statistics.delayReports=True
                self.do_request_test = Test(1, "Perform service request").wrap(self.test_Greeting)
                log("Thread starting up")
                pass

        def __call__(self):
                replyMessage = None
                success = 0
                replyMessage = self.do_request_test("Hi")
                if replyMessage == "Hi":
                        success = 1
                grinder.sleep(1000)
                grinder.statistics.forLastTest.success = success

        def __del__(self):
                log("Thread shutting down")



Can any of you please suggest me whether I am doing it properly?.. Is there any other way to achieve this?

Regards,
Balaji




If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/Wrap-function-usage-in-Grinder-tp309.html
To start a new topic under ngrinder-user-en, email [hidden email]
To unsubscribe from ngrinder-user-en, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: Wrap function usage in Grinder

balajilinks
Hi Junoyoon,

Thanks for your quick response.. Is there any way to measure function which I defined inside TestRunner class?..
Actually I am using grinder script to put messages in a Queue.. I defined multiple functions inside TestRunner class..

Regards,
Balaji


On Wed, Feb 13, 2013 at 3:58 PM, junoyoon [via ngrinder] <[hidden email]> wrote:

You should write a script like this.

 

#Test_wrap.py 
from net.grinder.script import Test 
from net.grinder.script.Grinder import grinder 
from java.util import Date 
from java.text import SimpleDateFormat 
from java.lang import String 
from java.util import Random, Properties 

def test_Greeting(strMsg): 
      grinder.sleep(1000) 
      return strMsg 

 

do_request_test = Test(1, "Perform service request").wrap(test_Greeting)  

 

log = grinder.logger.info 

class TestRunner:

        def __init__(self): 
                grinder.statistics.delayReports=True 


                log("Thread starting up") 
                pass 

        def __call__(self): 
                replyMessage = None 
                success = 0 
                replyMessage =do_request_test("Hi") 

                if replyMessage == "Hi": 
                        success = 1 
                grinder.sleep(1000) 
                grinder.statistics.forLastTest.success = success 

        def __del__(self): 
                log("Thread shutting down")  

  

-----Original Message-----
From: "Balaji [via ngrinder]"<[hidden email]>
To: "junoyoon"<[hidden email]>;
Cc:
Sent: 2013-02-14 (목) 00:46:38
Subject: Wrap function usage in Grinder

Hi,

I would like to measure the transaction time of one function which I defined inside the class.. In the following class, I wanted to measure only test_greeting function. I also need to verify the value which was returned by test_greeting. When I run the test, I am getting the following error.

net.grinder.scriptengine.jython.JythonScriptExecutionException: Java exception calling TestRunner
        grinder.statistics.forLastTest.success = success
        File "${NGRINDER_HOME}/script/user/Test_Wrap.py", line 28, in __call__
net.grinder.script.InvalidContextException: No tests have been performed by this thread.


#Test_wrap.py
from net.grinder.script import Test
from net.grinder.script.Grinder import grinder
from java.util import Date
from java.text import SimpleDateFormat
from java.lang import String
from java.util import Random, Properties


log = grinder.logger.info
class TestRunner:
        def test_Greeting(self, strMsg):
                grinder.sleep(1000)
                return strMsg

        def __init__(self):
                grinder.statistics.delayReports=True
                self.do_request_test = Test(1, "Perform service request").wrap(self.test_Greeting)
                log("Thread starting up")
                pass

        def __call__(self):
                replyMessage = None
                success = 0
                replyMessage = self.do_request_test("Hi")
                if replyMessage == "Hi":
                        success = 1
                grinder.sleep(1000)
                grinder.statistics.forLastTest.success = success

        def __del__(self):
                log("Thread shutting down")



Can any of you please suggest me whether I am doing it properly?.. Is there any other way to achieve this?

Regards,
Balaji




If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/Wrap-function-usage-in-Grinder-tp309.html
To start a new topic under ngrinder-user-en, email [hidden email]
To unsubscribe from ngrinder-user-en, click here.
NAML



If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/Wrap-function-usage-in-Grinder-tp309p310.html
To start a new topic under ngrinder-user-en, email [hidden email]
To unsubscribe from ngrinder-user-en, click here.
NAML


Test_01.py (9K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Wrap function usage in Grinder

junoyoon
Administrator

If so, you should pass the current instance as parameter of the method..

like..

 

def method_to_be_measured(runner, strMsg) :

      runner.method1()

 

def method_to_be_measured2(runner, strMsg) :

      runner.method2()


 

class TestRunner...

     def __call__(self):

          method_to_be_measured(self, "WOW");

      def method1(self) :

          .....

 

-----Original Message-----
From: "balajilinks [via ngrinder]"<[hidden email]>
To: "junoyoon"<[hidden email]>;
Cc:
Sent: 2013-02-14 (목) 01:13:00
Subject: Re: Wrap function usage in Grinder

Hi Junoyoon,
 
Thanks for your quick response.. Is there any way to measure function which I defined inside TestRunner class?.. 
Actually I am using grinder script to put messages in a Queue.. I defined multiple functions inside TestRunner class..
 
Regards, 
Balaji 


On Wed, Feb 13, 2013 at 3:58 PM, junoyoon [via ngrinder] <[hidden email]> wrote:

You should write a script like this.

#Test_wrap.py
from net.grinder.script import Test
from net.grinder.script.Grinder import grinder
from java.util import Date
from java.text import SimpleDateFormat
from java.lang import String
from java.util import Random, Properties
 
def test_Greeting(strMsg):
grinder.sleep(1000)
return strMsg

do_request_test = Test(1, "Perform service request").wrap(test_Greeting)

log = grinder.logger.info

class TestRunner:

def __init__(self):
grinder.statistics.delayReports=True


log("Thread starting up")
pass

def __call__(self):
replyMessage = None
success = 0
replyMessage =do_request_test("Hi")

if replyMessage == "Hi":
success = 1
grinder.sleep(1000)
grinder.statistics.forLastTest.success = success

def __del__(self):
log("Thread shutting down")

-----Original Message-----
From: "Balaji [via ngrinder]"<[hidden email]>
To: "junoyoon"<[hidden email]>;
Cc:
Sent: 2013-02-14 (목) 00:46:38
Subject: Wrap function usage in Grinder

Hi,

I would like to measure the transaction time of one function which I defined inside the class.. In the following class, I wanted to measure only test_greeting function. I also need to verify the value which was returned by test_greeting. When I run the test, I am getting the following error.

net.grinder.scriptengine.jython.JythonScriptExecutionException: Java exception calling TestRunner
grinder.statistics.forLastTest.success = success
File "${NGRINDER_HOME}/script/user/Test_Wrap.py", line 28, in __call__
net.grinder.script.InvalidContextException: No tests have been performed by this thread.


#Test_wrap.py
from net.grinder.script import Test
from net.grinder.script.Grinder import grinder
from java.util import Date
from java.text import SimpleDateFormat
from java.lang import String
from java.util import Random, Properties


log = grinder.logger.info
class TestRunner:
def test_Greeting(self, strMsg):
grinder.sleep(1000)
return strMsg

def __init__(self):
grinder.statistics.delayReports=True
self.do_request_test = Test(1, "Perform service request").wrap(self.test_Greeting)
log("Thread starting up")
pass

def __call__(self):
replyMessage = None
success = 0
replyMessage = self.do_request_test("Hi")
if replyMessage == "Hi":
success = 1
grinder.sleep(1000)
grinder.statistics.forLastTest.success = success

def __del__(self):
log("Thread shutting down")



Can any of you please suggest me whether I am doing it properly?.. Is there any other way to achieve this?

Regards,
Balaji




If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/Wrap-function-usage-in-Grinder-tp309.html
To start a new topic under ngrinder-user-en, email [hidden email]
To unsubscribe from ngrinder-user-en, click here.
NAML



If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/Wrap-function-usage-in-Grinder-tp309p310.html
To start a new topic under ngrinder-user-en, email [hidden email]
To unsubscribe from ngrinder-user-en, click here.
NAML
 

Test_01.py (9K) Download Attachment



If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/Wrap-function-usage-in-Grinder-tp309p311.html
To start a new topic under ngrinder-user-en, email [hidden email]
To unsubscribe from ngrinder-user-en, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: Wrap function usage in Grinder

balajilinks
Thanks a lot.. For time being, I created a separate class and I defined all my functions inside that.. Now everything is working fine..

I tried the runner method like below but didn't work.. Can you please confirm whether I used runner method properly?.

from net.grinder.script import Test
from net.grinder.script.Grinder import grinder
from java.util import Date
from java.text import SimpleDateFormat
from java.lang import String
from java.util import Random, Properties


log = grinder.logger.info

def method_to_be_measured(runner, strMsg) :
      runner.test_Greeting(strMsg)

test1 = Test(1,"test1").wrap(method_to_be_measured)

class TestRunner:   
    def test_Greeting(self, strMsg):
        grinder.sleep(1000)
        log("Inside greeting")
        log(strMsg)
        return strMsg

    def __init__(self):
        grinder.statistics.delayReports=True
        log("Thread starting up")
        pass

    def __call__(self):
        replyMessage = None
        success = 0
        replyMessage = test1(self,"WOW");
        if replyMessage == "WOW":
            success = 1
        grinder.sleep(1000)
        grinder.statistics.forLastTest.success = success

    def __del__(self):
        log("Thread shutting down")



On Wed, Feb 13, 2013 at 4:19 PM, junoyoon [via ngrinder] <[hidden email]> wrote:

If so, you should pass the current instance as parameter of the method..

like..

 

def method_to_be_measured(runner, strMsg) :

      runner.method1()

 

def method_to_be_measured2(runner, strMsg) :

      runner.method2()


 

class TestRunner...

     def __call__(self):

          method_to_be_measured(self, "WOW");

      def method1(self) :

          .....

 

-----Original Message-----
From: "balajilinks [via ngrinder]"<[hidden email]>
To: "junoyoon"<[hidden email]>;
Cc:
Sent: 2013-02-14 (목) 01:13:00
Subject: Re: Wrap function usage in Grinder

Hi Junoyoon,
 
Thanks for your quick response.. Is there any way to measure function which I defined inside TestRunner class?.. 
Actually I am using grinder script to put messages in a Queue.. I defined multiple functions inside TestRunner class..
 
Regards, 
Balaji 


On Wed, Feb 13, 2013 at 3:58 PM, junoyoon [via ngrinder] <[hidden email]> wrote:

You should write a script like this.

#Test_wrap.py
from net.grinder.script import Test
from net.grinder.script.Grinder import grinder
from java.util import Date
from java.text import SimpleDateFormat
from java.lang import String
from java.util import Random, Properties
 
def test_Greeting(strMsg):
grinder.sleep(1000)
return strMsg

do_request_test = Test(1, "Perform service request").wrap(test_Greeting)

log = grinder.logger.info

class TestRunner:

def __init__(self):
grinder.statistics.delayReports=True


log("Thread starting up")
pass

def __call__(self):
replyMessage = None
success = 0
replyMessage =do_request_test("Hi")

if replyMessage == "Hi":
success = 1
grinder.sleep(1000)
grinder.statistics.forLastTest.success = success

def __del__(self):
log("Thread shutting down")

-----Original Message-----
From: "Balaji [via ngrinder]"<[hidden email]>
To: "junoyoon"<[hidden email]>;
Cc:
Sent: 2013-02-14 (목) 00:46:38
Subject: Wrap function usage in Grinder

Hi,

I would like to measure the transaction time of one function which I defined inside the class.. In the following class, I wanted to measure only test_greeting function. I also need to verify the value which was returned by test_greeting. When I run the test, I am getting the following error.

net.grinder.scriptengine.jython.JythonScriptExecutionException: Java exception calling TestRunner
grinder.statistics.forLastTest.success = success
File "${NGRINDER_HOME}/script/user/Test_Wrap.py", line 28, in __call__
net.grinder.script.InvalidContextException: No tests have been performed by this thread.


#Test_wrap.py
from net.grinder.script import Test
from net.grinder.script.Grinder import grinder
from java.util import Date
from java.text import SimpleDateFormat
from java.lang import String
from java.util import Random, Properties


log = grinder.logger.info
class TestRunner:
def test_Greeting(self, strMsg):
grinder.sleep(1000)
return strMsg

def __init__(self):
grinder.statistics.delayReports=True
self.do_request_test = Test(1, "Perform service request").wrap(self.test_Greeting)
log("Thread starting up")
pass

def __call__(self):
replyMessage = None
success = 0
replyMessage = self.do_request_test("Hi")
if replyMessage == "Hi":
success = 1
grinder.sleep(1000)
grinder.statistics.forLastTest.success = success

def __del__(self):
log("Thread shutting down")



Can any of you please suggest me whether I am doing it properly?.. Is there any other way to achieve this?

Regards,
Balaji




If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/Wrap-function-usage-in-Grinder-tp309.html
To start a new topic under ngrinder-user-en, email [hidden email]
To unsubscribe from ngrinder-user-en, click here.
NAML



If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/Wrap-function-usage-in-Grinder-tp309p310.html
To start a new topic under ngrinder-user-en, email [hidden email]
To unsubscribe from ngrinder-user-en, click here.
NAML
 

Test_01.py (9K) Download Attachment



If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/Wrap-function-usage-in-Grinder-tp309p311.html
To start a new topic under ngrinder-user-en, email [hidden email]
To unsubscribe from ngrinder-user-en, click here.
NAML



If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/Wrap-function-usage-in-Grinder-tp309p312.html
To start a new topic under ngrinder-user-en, email [hidden email]
To unsubscribe from ngrinder-user-en, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Wrap function usage in Grinder

junoyoon
Administrator
You should fix the following method

def method_to_be_measured(runner, strMsg) :
      runner.test_Greeting(strMsg)

like this.

def method_to_be_measured(runner, strMsg) :
      return  runner.test_Greeting(strMsg)
Reply | Threaded
Open this post in threaded view
|

Re: Wrap function usage in Grinder

balajilinks
Thanks again.. The script is working now..


On Thu, Feb 14, 2013 at 1:33 AM, junoyoon [via ngrinder] <[hidden email]> wrote:
You should fix the following method

def method_to_be_measured(runner, strMsg) :
      runner.test_Greeting(strMsg)

like this.

def method_to_be_measured(runner, strMsg) :
      return  runner.test_Greeting(strMsg)


If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/Wrap-function-usage-in-Grinder-tp309p316.html
To start a new topic under ngrinder-user-en, email [hidden email]
To unsubscribe from ngrinder-user-en, click here.
NAML