Service Virtualization

 View Only
Expand all | Collapse all

How to create a conditional expiration statement on match script?

  • 1.  How to create a conditional expiration statement on match script?

    Posted Feb 11, 2016 10:19 AM

    All,

     

    I need help creating a conditional expiration statement on match script. So I have a property that I set called {{Timestamp_Response}} = 2016-02-10T09:08:06-0500 and I want the match script to check if the {{Timestamp_Response}} is more than current timestamp + 30 minutes, If yes, return false, Here's what I have so far but can't get it to work:

     

    /*long currentTimestamp = System.currentTimeMillis();

    long searchTimestamp = {{Timestamp_Response}};

    long difference = Math.abs(searchTimestamp - currentTimestamp);

    if ((difference > 30 * 60 * 1000))

        return false;->default response

    else

        return true;

    */

     

    Is there a better way on doing this in VSI or matchscript? Any help or ideas is greatly appreciated.

    Thank you.



  • 2.  Re: How to create a conditional expiration statement on match script?

    Posted Feb 16, 2016 12:08 PM

    Hi hartojoe, given the question, your Timestamp_Response property is really a string containing the value "2016-02-10T09:08:06-0500", correct?  I am guessing that your match script is throwing an exception.  If the value is a string, you need to convert it in order to obtain the millis.  Have you tried something like this (plz pardon syntax errors):

    import java.util.Date;

    import java.text.SimpleDateFormat;

    String searchTime = testExec.getStateValue("Timestamp_Response");                       // get the property value for the key

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:SSSZ");   // I do not recall if this format matches yours above so fix accordingly

    Date sd = sdf.parse(searchTime);           // convert the string to a date

    long searchTimestamp = sd.getTime();    // get the millis from Date

    :

    Thanks, Joel