# Timestamp Gatling

**URL:** <https://community.gatling.io/t/timestamp-gatling/964>\
**Category:** Gatling (Open-Source)\
**Created:** [April 17, 2014, 4:48pm UTC](https://community.gatling.io/t/timestamp-gatling/964 "2014-04-17T16:48:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maxime\_Tual](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Maxime\_Tual](https://community.gatling.io/u/Maxime_Tual)\
**Post date:** [April 17, 2014, 4:48pm UTC](https://community.gatling.io/t/timestamp-gatling/964/1 "2014-04-17T16:48:06Z")

</div>

Hi,

I’m trying to get an unique email for each of my created user with Gatling.  
So when i create the user I use this function:

def emailUnique(email: String): String = {  
var emailUnique = “testGatling” + “+” + System.currentTimeMillis+ “@example.com”

return emailUnique  
}

When my first user is created he got this email : [testGatling+292843029197921@example.com](mailto:testGatling+292843029197921@example.com) BUT  
when my second user is created he got the same email: [testGatling+292843029197921@example.com](mailto:testGatling+292843029197921@example.com)

The timestamp has not change between the two users. Here’s my simulation:

setUp(  
ProvisioningUser.scn.inject(  
atOnceUsers(1),  
nothingFor(4 seconds),  
atOnceUsers(1)  
).protocols(httpConf)  
)

Why the timestamp did not change ? Or how can I’ve got unique email every time (without clear the database) ?

---

<div class="post-metadata">

**Author:** ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)\
**Post date:** [April 17, 2014, 5:03pm UTC](https://community.gatling.io/t/timestamp-gatling/964/2 "2014-04-17T17:03:20Z")

</div>

Use a UUID.

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [April 17, 2014, 6:16pm UTC](https://community.gatling.io/t/timestamp-gatling/964/3 "2014-04-17T18:16:43Z")

</div>

My2cents: you’re calling emailUnique directly instead of calling it from a function, so it’s only called once.

---

<div class="post-metadata">

**Author:** ![Maxime\_Tual](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Maxime\_Tual](https://community.gatling.io/u/Maxime_Tual)\
**Post date:** [April 18, 2014, 7:46am UTC](https://community.gatling.io/t/timestamp-gatling/964/4 "2014-04-18T07:46:26Z")

</div>

I try with UUID but i’ve got exactly the same issue, the two users have the same UUID.

I think it’s about what Stéphane say but I don’t understand your Answer Stéphane. Why my function is called once ? How can i do ?

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [April 18, 2014, 7:51am UTC](https://community.gatling.io/t/timestamp-gatling/964/5 "2014-04-18T07:51:30Z")

</div>

Call you show the way you're using your emailUnique method, please?

---

<div class="post-metadata">

**Author:** ![Maxime\_Tual](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Maxime\_Tual](https://community.gatling.io/u/Maxime_Tual)\
**Post date:** [April 18, 2014, 7:52am UTC](https://community.gatling.io/t/timestamp-gatling/964/6 "2014-04-18T07:52:41Z")

</div>

Maybe I’ve got an idea. How can I store a static variable for all my users ? A variable starting to System.currentTimeMillis and I will increment each time a user is created ?

---

<div class="post-metadata">

**Author:** ![Maxime\_Tual](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Maxime\_Tual](https://community.gatling.io/u/Maxime_Tual)\
**Post date:** [April 18, 2014, 7:56am UTC](https://community.gatling.io/t/timestamp-gatling/964/7 "2014-04-18T07:56:22Z")

</div>

/\*\*

- Provision the base with a new user base on user\_provisioning feeder
- param access\_token\_basic
- return access\_token Auth token for the created user  
\*/  
val provisioning = exec().feed(provisioningUsers)  
.exec(http(“Create a new user”)  
.post("/users")  
.header(“Content-Type”, “application/json”)  
.header(“Authorization”, “Bearer ${access\_token\_basic}”)  
.body(StringBody("""{“login”: “”"" + emailUnique("${login}") + “”"", “password”: “${password}”, “user”: {“firstname”: “${firstname}”, “lastname”: “${lastname}”, “gender”: “${gender}”, “locale”: “${locale}”, “country”: {“code”: “${country\_code}”}, “facebookID”: “”"" + fbIdUnique("${facebookID}") + “”""}}"""))  
.check(status.is(201), jsonPath("$.accessToken").saveAs(“access\_token”)))

//Return unique email base on timestamp  
def emailUnique(email: String): String = {  
var emailUnique = “testGatling” + “+” + System.currentTimeMillis + “@example.com”  
return emailUnique  
}

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [April 18, 2014, 8:07am UTC](https://community.gatling.io/t/timestamp-gatling/964/8 "2014-04-18T08:07:14Z")

</div>

OK, so that will never work. read this: [https://github.com/excilys/gatling/blob/master/src/sphinx/session/expression\_el.rst](https://github.com/excilys/gatling/blob/master/src/sphinx/session/expression_el.rst)

One solution would be:

val provisioning =feed(provisioningUsers)

.exec(session =\> session.set(“email”, emailUnique(session(“login”).as[String]))  
…  
.body(StringBody("""{“login”: “${email}”, “password”: “${password}”, …

Same thing goes with fbIdUnique.

---

<div class="post-metadata">

**Author:** ![Maxime\_Tual](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Maxime\_Tual](https://community.gatling.io/u/Maxime_Tual)\
**Post date:** [April 18, 2014, 8:17am UTC](https://community.gatling.io/t/timestamp-gatling/964/9 "2014-04-18T08:17:06Z")

</div>

Thanx you very much ! It works ! 🙂

I found this old post related answer: [https://groups.google.com/forum/#!msg/gatling/ycR9LtoU1\_c/eoJDXyQ-BgUJ](https://groups.google.com/forum/#!msg/gatling/ycR9LtoU1_c/eoJDXyQ-BgUJ)
