Service Virtualization

 View Only
  • 1.  Virtual Service to auto stop after reaching 500 calls

    Posted Mar 24, 2025 12:58 PM

    One of the virtual service needs to be stopped after it has reached 300/500 calls.

    How can we achieve this without much of coding intervention.

    thanks

    Vinay



  • 2.  RE: Virtual Service to auto stop after reaching 500 calls

    Broadcom Employee
    Posted Mar 24, 2025 01:57 PM
    HI Vinay
    Some amount of scripting becomes essential to achieve this
    requirement. May i know what would be the capacity of the VS ?

    At the end of reaching the target number of requests, do you want the VS to
    be shutdown or stay in running state but stop listening/Responding ?

    --
    regards
    Sankar Natarajan

    --
    This electronic communication and the information and any files transmitted
    with it, or attached to it, are confidential and are intended solely for
    the use of the individual or entity to whom it is addressed and may contain
    information that is confidential, legally privileged, protected by privacy
    laws, or otherwise restricted from disclosure to anyone else. If you are
    not the intended recipient or the person responsible for delivering the
    e-mail to the intended recipient, you are hereby notified that any use,
    copying, distributing, dissemination, forwarding, printing, or copying of
    this e-mail is strictly prohibited. If you received this e-mail in error,
    please return the e-mail to the sender, delete it from your computer, and
    destroy any printed copy of it.




  • 3.  RE: Virtual Service to auto stop after reaching 500 calls

    Posted Mar 24, 2025 02:17 PM
    Edited by Vinay Mar 24, 2025 02:39 PM

    Thank you Sankar.

    Either works for me, where I can make service to shutdown or stop listening to further requests until cleared off calls or restart the service.

    Since it is with 500 calls, the capaity would be at 1 thread.

    thanks

    Vinay




  • 4.  RE: Virtual Service to auto stop after reaching 500 calls

    Broadcom Employee
    Posted Mar 26, 2025 01:28 PM
    HI Vinay

    Your requirement could be met with a simple SCRIPTED Assertion as shown
    below.
























    *import com.itko.lisa.vse.SharedModelMap;import
    java.util.concurrent.atomic.AtomicInteger;_logger.info
    <http: logger.info>("******INSTANCE is " + testExec.getInstance()+"
    Staging ID=" +
    testExec.getStagingUniqueId());if(SharedModelMap.containsKey(testExec.getStagingUniqueId(),"hit_count")){
    AtomicInteger ai1 =
    (AtomicInteger)SharedModelMap.getObject(testExec.getStagingUniqueId(),"hit_count");
    _logger.info <http: logger.info>("Shared Model Map has hit_count alredy
    defined. Hit Count=ai1"+
    ai1.incrementAndGet());if(ai1.get()>=Integer.parseInt(testExec.getStateValue("maxLimit")))
    { _logger.info <http: logger.info>("Reached MAX LIMIT Quitting"+
    ai1.get());return true;}}else{ _logger.info <http: logger.info>("Shared
    Model Map Doesnt have hit_count. Defining it");
    SharedModelMap.putObject(testExec.getStagingUniqueId(),"hit_count",new
    AtomicInteger(0));}return false;*

    Please add the Assertion to the Http/s Listen Step (Assuming you have a
    HTTP Based VS as shown below:

    [image: image.png]

    With this script in place, the Virtual Service responds fine for the first
    N requests (configured by property maxLimit in project config).
    Once the number of transactions served by the VS crosses N, further
    requests are ignored even though the VS stays in running state. The admin
    has to intervene and Stop/Start the VS for the counter to be reset.

    [image: image.png]

    Please extend the idea to suit your specific requirements. You may consider
    using APIs to shutdown the VS once it reaches the Threshold. You could even
    send a custom HTTP Response once the threshold reaches.

    The MAR file has been attached for your reference.

    Please let me know if you have any questions. Happy to help.

    --
    regards
    Sankar Natarajan

    --
    This electronic communication and the information and any files transmitted
    with it, or attached to it, are confidential and are intended solely for
    the use of the individual or entity to whom it is addressed and may contain
    information that is confidential, legally privileged, protected by privacy
    laws, or otherwise restricted from disclosure to anyone else. If you are
    not the intended recipient or the person responsible for delivering the
    e-mail to the intended recipient, you are hereby notified that any use,
    copying, distributing, dissemination, forwarding, printing, or copying of
    this e-mail is strictly prohibited. If you received this e-mail in error,
    please return the e-mail to the sender, delete it from your computer, and
    destroy any printed copy of it.




  • 5.  RE: Virtual Service to auto stop after reaching 500 calls

    Broadcom Employee
    Posted Mar 26, 2025 01:32 PM
      |   view attached
    HI Vinay
    Your requirement could be met with a simple SCRIPTED Assertion as shown below.
    import com.itko.lisa.vse.SharedModelMap;
    import java.util.concurrent.atomic.AtomicInteger;

    _logger.info("******INSTANCE is " + testExec.getInstance()+" Staging ID=" + testExec.getStagingUniqueId());

    if(SharedModelMap.containsKey(testExec.getStagingUniqueId(),"hit_count"))
    {
        AtomicInteger ai1 = (AtomicInteger)SharedModelMap.getObject(testExec.getStagingUniqueId(),"hit_count");
        _logger.info("Shared Model Map has hit_count alredy defined. Hit Count=ai1"+ ai1.incrementAndGet());


    if(ai1.get()>=Integer.parseInt(testExec.getStateValue("maxLimit")))
    {
     _logger.info("Reached MAX LIMIT Quitting"+ ai1.get());
    return true;
    }

    }
    else
    {
        _logger.info("Shared Model Map Doesnt have hit_count. Defining it");
        SharedModelMap.putObject(testExec.getStagingUniqueId(),"hit_count",new AtomicInteger(0));
    }
    return false;
    Please add the Assertion to the Http/s Listen Step (Assuming you have a HTTP Based VS as shown below:
    With this script in place, the Virtual Service responds fine for the first N requests (configured by property maxLimit in project config). 
    Once the number of transactions served by the VS crosses N, further requests are ignored even though the VS stays in running state. The admin has to intervene and Stop/Start the VS for the counter to be reset.
    Please extend the idea to suit your specific requirements. You may consider using APIs to shutdown the VS once it reaches the Threshold. You could even send a custom HTTP Response once the threshold reaches.
    The MAR file has been attached for your reference. (Unzip and use it).
    Please let me know if you have any questions. Happy to help.
    --
    regards
    Sankar Natarajan


    ------------------------------
    Sankar Natarajan
    Service Virtualization Product Engineering Team
    Broadcom
    ------------------------------

    Attachment(s)

    zip
    LimitedVS.mar.zip   109 KB 1 version