Service Virtualization

  • 1.  custom java test step, when did the test run end? solved

    Posted May 17, 2016 08:51 AM

    I have created some custom test steps to support the webSockets protocol.. I am sharing the connection across multiple classes in a test run

     

    I want to close the connection when the test ends.

     

    How do the extension classes get notified of end of test run?  I don't see that in the spec anywhere..



  • 2.  Re: custom java test step, when did the test run end?

    Posted May 19, 2016 07:27 AM

    Anybody?



  • 3.  Re: custom java test step, when did the test run end?

    Posted May 19, 2016 01:16 PM

    How did you create your custom test steps?  What is the base class?  There are a couple of ways to make these things and the answer depends on how you did it.



  • 4.  Re: custom java test step, when did the test run end?

    Posted May 19, 2016 01:27 PM

    Rather than be vague as above, let me take a stab at answering anyway...

     

    If you created your custom test step using the instructions here: Custom Java Test Steps - DevTest Solutions - 9.1 - CA Technologies Documentation Then there really isn't a way.  You might be able to get somewhat close using the java finalize() method, but that is outside the scope of DevTest APIs and may or may not offer the granularity or predictability you want.

     

    If, instead, you created your custom test step using the instructions here: Native Test Steps - DevTest Solutions - 9.1 - CA Technologies Documentation Then, you can override the destroy() method on TestNode.  Here are the JavaDocs and signature:
    /**
    * This method gives the test node the ability to do final cleanup of
    * resources when the test has ended and will no longer be calling the node.
    *
    * @param ts the TestExec that we're ending (why we're being destroyed)
    */
    public void destroy( TestExec ts )

     

    It is worth keeping in mind that this method will get called every time an instance shuts down.  So, say your staging doc was a stair-step pattern that ramped up to 10 in increments of 5, then back down the same way.  When the 5 instances stop on the back side of the pattern, the destroy method will be called for each of them (each having a different TestExec argument in the call).  Then when the final 5 stop, you'll get called by each of those threads as well.

     

    That allows you to do the cleanup you need to do, so long as you take a bit of care about when you actually do the cleanup since your destroy might be called for one thread while 9 are still running.



  • 5.  Re: custom java test step, when did the test run end?

    Posted May 19, 2016 01:55 PM

    see DT Support for WebSockets API

     

    I used the Custom Java test Steps..

    dtextension.jpg

    the 'send msg' step implicitly opens the connection to the server..

    if the user forgets to add the Close connection step, the connection lives on..  I want to fix that..

    when the testcase ends.. there has to be some class I can hook to get notified..



  • 6.  Re: custom java test step, when did the test run end?

    Posted May 19, 2016 02:03 PM

    Possibility 1: Make your steps be Native Test Steps and use the mechanism I mentioned.

     

    Possibility 2: Custom Companions - DevTest Solutions - 9.1 - CA Technologies Documentation



  • 7.  Re: custom java test step, when did the test run end?

    Posted May 19, 2016 05:42 PM

    thanks.. I've built a companion, but can't seem to get it to fire.. I added a constructor, but it is never called..

     

    I did NOT implement the serializable  requirement.. as I am just trying to proof it out.

     

    the doc is confusing on deploying companions,..

     

    test step jar files got in hotdeploy, but companions go in lib?

     

    test step FAIL if NOT in hotdeploy..

     

    ok, companion working.. problem was the naming of the lisaextensions  file

     

    my custom test steps worked with

     

    lisaextensions

     

    the companion doesn't.. the lisaextensions doc says the file EXTENSION name must be lisaextensions..

     

    so, I renamed the file to c.lisaextensions, and restarted Workstation..    works now.. but companion isn't what I want (see following post)



  • 8.  Re: custom java test step, when did the test run end?

    Posted May 20, 2016 03:49 PM

    I don't think companion is what I want either.. the user would have to configure it..

     

    there has got to be some DT class that gets notified when a test ends.. like a hook, but again without having to configure it

    if the user didn't add the close connection, why would I assume they would configure these other archaic things..



  • 9.  Re: custom java test step, when did the test run end?
    Best Answer

    Posted May 22, 2016 10:27 AM

    ok, solved this..

     

    add a TestEventListener and listen for TestEvent.EVENT_NORMALEND, TestEvent.EVENT_ABEND, or TestEvent.EVENT_STOPTESTSIGNAL

    ts.getTestEventMgr().addListener(tt, null);