Token Refresh - Java - Example

I see that lot of people asking about solution to refresh Token when expired.
I have prepared Case0022SetOrRefreshTokenSimulation where Token is refreshed every some period of time.

What you think about this solution @slandelle @sbrevet ?

1 Like

Hi @GeMi,

Thanks for this code suggestion! :heart:

Here my comments:

  • Create a pull request: it is easier to comment and discuss about code there.
  • I think it needs a disclaimer that is for a single load generator (in Gatling Enterprise, you can launch a single run with multiple load generators, but global variables are trickier to manage)
  • I’m on two minds about the scnForSetOrRefreshToken:
    Perhaps a scenario with a single user that loops with a pause?
    • In one hand, your code doesn’t need to have a max duration
    • In the other, it’s complicated to pre-compute the amount of requests this way
  • A small comment next to nothingFor(2) : “waiting for the first credentials”

Note:

  • Avoid string injection in the URL by using queryParam (personal taste)

Cheers!

1 Like

Hi @sbrevet,
Thank you for your valuable suggestions :hearts:
I have make huge changes in code including your suggerstions :slight_smile:
If it is possible please check my PR → Case0022SetOrRefreshTokenSimulation in new version by gemiusz · Pull Request #17 · gemiusz/gatling-examples-maven-java · GitHub

In few words what it’s going in Simulation now:

  • I changed injection profile to have dependencies on necessary steps: first get token → token refresh loop AND Core Scenario → after finish my simulation “shut down” token refresh loop.
  • Simulation time = time of getting first token + Core Scenario time + 1 second (shut down token refresh loop)
  • Don’t need set any tricky counters etc.
  • Set queryParam :smiling_face:
  • Silent request for token - that was from beginning but I want to mention about that here

Cheers!

Hi @GeMi,

Nice improvements!

Cheers!

@sbrevet thank you for review and comments in PR.
I will look closely at them at Sunday afternoon because I’m at trip :slight_smile:

Cheers!

Hi @GeMi Is it possible to provide the solution in Scala as well? Thank you in advance!

Sorry but not.
I’m not familiar with Scala.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.