Forum Discussion

LostInSpace's avatar
LostInSpace
New Contributor
14 years ago

Any way to create a unique id to send in soapUI requests?

Hi!

(I am not the actual user of soapUI at my work place, I am sending this to try to help a colleague which is working on a fairly thing schedule...)

We're currently trying to generate a unique id to communicate with a web service we need to test and we can't seem to generate something unique enough to do load testing.

We're currently using the current date and time (down to the milliseconds) to generate a string that we pass to the web service.

Unfortunately, for our needs (we're doing a load test), it's still not unique enough.

We saw an example (using a regular groovy script but we're using a DataGen one...) that used the "thread index" to make the id more unique.

Unfortunately even though there's a notice on the screen that says that the context should be available in the script using we don't seem to be able to access it.

How can we access the thread index from a Datagen script?

Thank you!

Nick

PS: We actually have Soap UI pro if that makes any difference...
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Can you use a UUID, like 13619c78-1907-47f0-a169-6879a4c2cba0? Put this in the DataGen script

    return java.util.UUID.randomUUID()

    Or you can embed it directly in a request, e.g.:

    <myIdElement>${=java.util.UUID.randomUUID()}</myIdElement>

    Thread index can be accessed with

    context.ThreadIndex
  • Hi and thank you!

    M McDonald wrote:
    Can you use a UUID, like 13619c78-1907-47f0-a169-6879a4c2cba0?


    Unfortunately the UUID is too long, the string we pass to that web service must be 17 characters long, no more, no less...

    M McDonald wrote:
    Thread index can be accessed with

    context.ThreadIndex


    We got an error message that said the context didn't exist when we tried to retrieve it (even though the edit screen said the context is supposed to be accessible).

    We're not using the latest version though (my guess is the people who made this test were afraid to upgrade the tool fearing the test might stop working), we're using Soap UI Pro 2.5.1 even though we're entitled to use the latest version.

    Thank you and have a nice day!

    Nick
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    I don't know if you can live with the delay that this would introduce (at least 1 ms per call to the function) or if 2.5 supports this or if it is really correct (how's that for a disclaimer!), but you could try to put the following in your project Load Script:

    class IdGen { 
    static def synchronized getId() {
    sleep(1)
    return new java.util.Date().time
    }
    }

    project.metaClass.IdGen = new IdGen()

    What I think the getId method should do is wait for 1 ms before returning the current time in ms, and since it is synchronized, each thread should wait it's turn to go through the method thus ensuring a unique time. Then when you want a unique ID in a request, you can put in the following:

    ${=context.testCase.testSuite.project.IdGen.getId()}

    Of course if you had a thousand threads that could introduce at least a 1 second delay for a thread to get an id in the worst case.

    Good luck.
  • (Sorry for the delayed reply...

    Hi!

    My colleague has not yet had time to test this but I am confident this will work.

    Thank you for your help!

    Nicolas