# How to add a condition count \> 8 in Gatling script?

**URL:** https://community.gatling.io/t/how-to-add-a-condition-count-8-in-gatling-script/3322
**Category:** Gatling (Open-Source)
**Created:** [October 14, 2016, 2:03pm UTC](https://community.gatling.io/t/how-to-add-a-condition-count-8-in-gatling-script/3322 "2016-10-14T14:03:23Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@Peter](https://community.gatling.io/u/Peter)
#### Post date: [October 14, 2016, 2:03pm UTC](https://community.gatling.io/t/how-to-add-a-condition-count-8-in-gatling-script/3322/1 "2016-10-14T14:03:23Z")

</div>

I want to add a below condition in http request, which gives me KO status if that condition matches. My condition is `WorkflowFailed = True OR count > 8` then status will be failed.

For one of the above condition `WorkflowFailed = True` I have added below code and it works fine, but for `count > 8` it doesnt work.

```auto
.check(jsonPath("$.failed").transform(status => status == "true").is(false))

```

I have also tried with this code, but didn’t work and throws error.

```auto
.check(jsonPath("$.failed").transform(status => status == "true" || count > 8).is(false))

```

> 19:00:52.143 [ERROR] i.g.c.ZincCompiler$ - D:…\gatling-charts-highcharts-bundle-2.1.7\user-file s\simulations\LaunchResources.scala:83: value \> is not a member of java.util.concurrent.atomic.AtomicInteger 19:00:52.144 [ERROR] i.g.c.ZincCompiler$ -  
> .check(jsonPath(“$.failed”). transform(status =\> status == “true” || count \> 8).is(false)) 19:00:52.144 [ERROR] i.g.c.ZincCompiler$ - ^ 19:00:52.222 [ERROR] i.g.c.ZincCompiler$ - one error found

Here is the code,

```auto
class LaunchResources extends Simulation {

    val scenarioRepeatCount = Integer.getInteger("scenarioRepeatCount", 1).toInt
    val userCount = Integer.getInteger("userCount", 1).toInt
    val UUID = System.getProperty("UUID", "24d0e03")
    val username = System.getProperty("username", "p1")
    val password = System.getProperty("password", "P12")
    val testServerUrl = System.getProperty("testServerUrl", "https://someurl.net")
    val count = new java.util.concurrent.atomic.AtomicInteger(0)

    val httpProtocol = http
        .baseURL(testServerUrl)
        .basicAuth(username, password)
        .connection("""keep-alive""")
        .contentTypeHeader("""application/vnd+json""")

    val headers_0 = Map(
        """Cache-Control""" -> """no-cache""",
        """Origin""" -> """chrome-extension://fdmmgasdw1dojojpjoooidkmcomcm""")

    val scn = scenario("LaunchAction")
        .repeat (scenarioRepeatCount) {
            exec(http("LaunchAResources")
                .post( """/api/actions""")
                .headers(headers_0)
                .body(StringBody(s"""{"UUID": "$UUID", "stringVariables" : {"externalFilePath" : "/Test.mp4"}}"""))
                .check(jsonPath("$.id").saveAs("WorkflowID")))

        .exec(http("SaveWorkflowStatus")
                .get("""/api/actions/{$WorkflowID}""")
                .headers(headers_0)
                .check(jsonPath("$.status").saveAs("WorkflowStatus")))

        }

     .asLongAs(session => session.attributes("WorkflowStatus") != "false" && count.getAndIncrement() < 8) {
        doIf(session => session("WorkflowFailed").validate[String].map(WorkflowFailed => !WorkflowFailed.contains("true")).recover(true)) 
        {
        pause(pauseTime)
        .exec(http("SaveWorkflowStatus")
                .get("""/api/actions/${WorkflowID}""")
                .headers(headers_0)
                .check(jsonPath("$.running").saveAs("WorkflowStatus"))
                .check(jsonPath("$.failed").saveAs("WorkflowFailed"))
                .check(jsonPath("$.failed").transform(status => status == "true").is(false)) // Added this line to fail 1st condition which is (WorkflowFailed = True) then mark as KO. Works fine.
                )

        .exec(session => {
                val wflowStatus1 = session.get("WorkflowStatus").asOption[String]
                val wflowFailed1 = session.get("WorkflowFailed").asOption[String]
                println("Inner Loop Workflow Status: ========>>>>>>>> " + wflowStatus1.getOrElse("COULD NOT FIND STATUS"))
                println("Inner Loop Workflow Failed?? ========>>>>>>>> " + wflowFailed1.getOrElse("COULD NOT FIND STATUS"))
                println("Count =====>> " + count)
                session}) 
        }
        }   

    setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol)

}

```

---

<div class="post-metadata">

### Author: ![niharika\_varshney](https://avatars.discourse-cdn.com/v4/letter/n/3d9bf3/32.png) [@niharika\_varshney](https://community.gatling.io/u/niharika_varshney)
#### Post date: [October 17, 2016, 7:28am UTC](https://community.gatling.io/t/how-to-add-a-condition-count-8-in-gatling-script/3322/2 "2016-10-17T07:28:27Z")

</div>

" value \> is not a member of java.util.concurrent.atomic.AtomicInteger 19:00:52.144 [ERROR] i.g.c.ZincCompiler$ -"

AtomicInteger doesn’t support \>. Use count.get()

Regards,  
Niharika
