Repository: usergrid Updated Branches: refs/heads/USERGRID-1044 2757e905d -> 9e8138107
USERGRID-1044: fix direct access on query failure and log when name/uuid error/mismatch in payload occurs Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/9e813810 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/9e813810 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/9e813810 Branch: refs/heads/USERGRID-1044 Commit: 9e813810756a1b48a23b1bac4d7cec6bc326f186 Parents: 2757e90 Author: Mike Dunker <mdun...@apigee.com> Authored: Thu Oct 15 13:16:04 2015 -0700 Committer: Mike Dunker <mdun...@apigee.com> Committed: Thu Oct 15 13:16:04 2015 -0700 ---------------------------------------------------------------------- .../apache/usergrid/helpers/Extractors.scala | 18 ++++- .../usergrid/scenarios/AuditScenarios.scala | 84 +++++++++++++++----- .../scenarios/EntityCollectionScenarios.scala | 6 +- .../org/apache/usergrid/settings/Settings.scala | 19 +++++ 4 files changed, 100 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/9e813810/stack/loadtests/src/main/scala/org/apache/usergrid/helpers/Extractors.scala ---------------------------------------------------------------------- diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/helpers/Extractors.scala b/stack/loadtests/src/main/scala/org/apache/usergrid/helpers/Extractors.scala index 8a18053..136a561 100644 --- a/stack/loadtests/src/main/scala/org/apache/usergrid/helpers/Extractors.scala +++ b/stack/loadtests/src/main/scala/org/apache/usergrid/helpers/Extractors.scala @@ -41,9 +41,9 @@ object Extractors { } /** - * Will extract the uuid from the create response. If the uuid is not present, an empty string will be set + * Will extract the uuid from the response. If the uuid is not present, an empty string will be set */ - def extractCreateUuid(saveAsName: String) = { + def extractEntityUuid(saveAsName: String) = { jsonPath("$.entities[0].uuid").transformOption(extract => { //it may or may not be present. If it is, save it, otherwise save it as an empty string extract.orElse(Some("")) @@ -51,9 +51,19 @@ object Extractors { } /** - * Will extract the modified date from the create response. If the modified field is not present, -1 will be set + * Will extract the name from the response. If the name is not present, an empty string will be set */ - def extractCreateModified(saveAsName: String) = { + def extractEntityName(saveAsName: String) = { + jsonPath("$.entities[0].name").transformOption(extract => { + //it may or may not be present. If it is, save it, otherwise save it as an empty string + extract.orElse(Some("")) + }).saveAs(saveAsName) + } + + /** + * Will extract the modified date from the response. If the modified field is not present, -1 will be set + */ + def extractEntityModified(saveAsName: String) = { jsonPath("$.entities[0].modified").ofType[Long].transformOption(extract => { //it may or may not be present. If it is, save it, otherwise save it as -1 extract.orElse(Some(-1)) http://git-wip-us.apache.org/repos/asf/usergrid/blob/9e813810/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/AuditScenarios.scala ---------------------------------------------------------------------- diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/AuditScenarios.scala b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/AuditScenarios.scala index 905c652..0b798a8 100644 --- a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/AuditScenarios.scala +++ b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/AuditScenarios.scala @@ -32,7 +32,8 @@ object AuditScenarios { //The value for the cursor val SessionVarCursor: String = "cursor" - val SessionVarUuid: String = "entityUuid" + val SessionVarEntityUuid: String = "entityUuid" + val SessionVarEntityName: String = "entityName" val SessionVarDeletedUuid: String = "deletedUuid" val SessionVarCollectionName: String = "collectionName" val SessionVarCollectionEntities: String = "collectionEntities" @@ -117,7 +118,7 @@ object AuditScenarios { http("DELETE audited entity") .delete("/${collectionName}/${uuid}") .headers(Headers.authToken) - .check(extractCreateUuid(SessionVarDeletedUuid))) + .check(extractEntityUuid(SessionVarDeletedUuid))) .exec(session => { val uuid = session(SessionVarDeletedUuid).as[String] @@ -136,28 +137,50 @@ object AuditScenarios { .get("/${collectionName}/${uuid}") .headers(Headers.authToken) .headers(Headers.auditRegionHeaders) - .check(status.is(200),jsonPath("$.count").optional.saveAs("count"),extractAuditEntities(SessionVarCollectionEntities))) + .check() + .check(status.in(Seq(200,404)),extractAuditEntities(SessionVarCollectionEntities), + extractEntityUuid(SessionVarEntityUuid),extractEntityName(SessionVarEntityName))) .exec(session => { - val count = session("count").as[String].toInt val uuid = session("uuid").as[String] - val entityName = session("name").as[String] + val reqName = session("name").as[String] val modified = session("modified").as[String].toLong val collectionName = session(SessionVarCollectionName).as[String] + val collectionEntities = session(SessionVarCollectionEntities).as[Seq[Any]) + val entityUuid = session(SessionVarEntityUuid).as[String] + val entityName = session(SessionVarEntityName).as[String] + val count = collectionEntities.length if (count < 1) { - Settings.addAuditUuid(uuid, collectionName, entityName, modified) + Settings.addAuditUuid(uuid, collectionName, reqName, modified) Settings.incAuditNotFoundAtAll() - println(s"NOT FOUND AT ALL: $collectionName.$entityName ($uuid)") - } else if (count == 1) { - // found via direct access but not query - Settings.addAuditUuid(uuid, collectionName, entityName, modified) - Settings.incAuditNotFoundViaQuery() - println(s"NOT FOUND VIA QUERY: $collectionName.$entityName ($uuid)") - } else { - // count > 1 -> invalid - Settings.addAuditUuid(uuid, collectionName, entityName, modified) + println(s"NOT FOUND AT ALL: $collectionName.$reqName ($uuid)") + } else if (count > 1) { + // invalid + Settings.addAuditUuid(uuid, collectionName, reqName, modified) Settings.incAuditBadResponse() - println(s"INVALID RESPONSE (count=$count): $collectionName.$entityName ($uuid)") + println(s"INVALID RESPONSE (count=$count): $collectionName.$reqName ($uuid)") + } else { + // count == 1 -> found via direct access but not query + + // will count as found directly even if there is a uuid or name mismatch + if (entityUuid == null || entityUuid.isEmpty) { + Settings.incAuditPayloadUuidError() + println(s"PAYLOAD UUID MISSING (DIRECT): requestedUuid=$uuid") + } else if (uuid.equalsIgnoreCase(entityUuid)) { + Settings.incAuditPayloadUuidError() + println(s"PAYLOAD UUID MISMATCH (DIRECT): requestedUuid=$uuid returnedUuid=$entityUuid") + } + if (entityName == null || entityName.isEmpty) { + Settings.incAuditPayloadNameError() + println(s"PAYLOAD NAME MISSING (DIRECT): requestedName=$reqName") + } else if (reqName.equalsIgnoreCase(entityName)) { + Settings.incAuditPayloadNameError() + println(s"PAYLOAD NAME MISMATCH (DIRECT): requestedName=$reqName returnedName=$entityName") + } + + Settings.addAuditUuid(uuid, collectionName, reqName, modified) + Settings.incAuditNotFoundViaQuery() + println(s"NOT FOUND VIA QUERY: $collectionName.$reqName ($uuid)") } session @@ -168,23 +191,44 @@ object AuditScenarios { .get("/${collectionName}?ql=uuid=${uuid}") .headers(Headers.authToken) .headers(Headers.auditRegionHeaders) - .check(status.is(200),jsonPath("$.count").optional.saveAs("count"),extractAuditEntities(SessionVarCollectionEntities))) + .check(status.is(200),jsonPath("$.count").optional.saveAs("count"), + extractAuditEntities(SessionVarCollectionEntities), + extractEntityUuid(SessionVarEntityUuid),extractEntityName(SessionVarEntityName))) .exec(session => { val count = session("count").as[String].toInt val uuid = session("uuid").as[String] - val entityName = session("name").as[String] + val reqName = session("name").as[String] val modified = session("modified").as[String].toLong val collectionName = session(SessionVarCollectionName).as[String] + val entityUuid = session(SessionVarEntityUuid).as[String] + val entityName = session(SessionVarEntityName).as[String] if (count < 1) { // will check to see whether accessible directly } else if (count > 1) { - Settings.addAuditUuid(uuid, collectionName, entityName, modified) + Settings.addAuditUuid(uuid, collectionName, reqName, modified) Settings.incAuditBadResponse() - println(s"INVALID RESPONSE (count=$count): $collectionName.$entityName ($uuid)") + println(s"INVALID RESPONSE (count=$count): $collectionName.$reqName ($uuid)") } else { // count == 1 -> success // println(s"FOUND: $collectionName.$entityName ($uuid)") + + // will count as success even if there is a uuid or name mismatch + if (entityUuid == null || entityUuid.isEmpty) { + Settings.incAuditPayloadUuidError() + println(s"PAYLOAD UUID MISSING (QUERY): requestedUuid=$uuid") + } else if (uuid.equalsIgnoreCase(entityUuid)) { + Settings.incAuditPayloadUuidError() + println(s"PAYLOAD UUID MISMATCH (QUERY): requestedUuid=$uuid returnedUuid=$entityUuid") + } + if (entityName == null || entityName.isEmpty) { + Settings.incAuditPayloadNameError() + println(s"PAYLOAD NAME MISSING (QUERY): requestedName=$reqName") + } else if (reqName.equalsIgnoreCase(entityName)) { + Settings.incAuditPayloadNameError() + println(s"PAYLOAD NAME MISMATCH (QUERY): requestedName=$reqName returnedName=$entityName") + } + Settings.incAuditSuccess() } http://git-wip-us.apache.org/repos/asf/usergrid/blob/9e813810/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/EntityCollectionScenarios.scala ---------------------------------------------------------------------- diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/EntityCollectionScenarios.scala b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/EntityCollectionScenarios.scala index 1b15103..de95920 100644 --- a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/EntityCollectionScenarios.scala +++ b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/EntityCollectionScenarios.scala @@ -209,7 +209,7 @@ object EntityCollectionScenarios { .headers(Headers.authToken) .body(StringBody("""${entity}""")) // 200 for success, 400 if already exists - .check(status.in(Seq(200)), extractCreateUuid(SessionVarUuid), extractCreateModified(SessionVarModified))) + .check(status.in(Seq(200)), extractEntityUuid(SessionVarUuid), extractEntityModified(SessionVarModified))) .exec(session => { val uuid = session(SessionVarUuid).as[String] val entityName = session("entityName").as[String] @@ -299,7 +299,7 @@ object EntityCollectionScenarios { .get("/" + Settings.collection + "/${entityName}") .queryParamMap(Settings.queryParamMap) .headers(Headers.authAnonymous) - .check(status.is(200), extractCreateUuid(SessionVarUuid), extractCreateModified(SessionVarModified))) + .check(status.is(200), extractEntityUuid(SessionVarUuid), extractEntityModified(SessionVarModified))) .exec(session => { val uuid = session(SessionVarUuid).as[String] val entityName = session("entityName").as[String] @@ -317,7 +317,7 @@ object EntityCollectionScenarios { .get("/" + Settings.collection + "/${entityName}") .queryParamMap(Settings.queryParamMap) .headers(Headers.authToken) - .check(status.is(200), extractCreateUuid(SessionVarUuid), extractCreateModified(SessionVarModified))) + .check(status.is(200), extractEntityUuid(SessionVarUuid), extractEntityModified(SessionVarModified))) .exec(session => { val uuid = session(SessionVarUuid).as[String] val entityName = session("entityName").as[String] http://git-wip-us.apache.org/repos/asf/usergrid/blob/9e813810/stack/loadtests/src/main/scala/org/apache/usergrid/settings/Settings.scala ---------------------------------------------------------------------- diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/settings/Settings.scala b/stack/loadtests/src/main/scala/org/apache/usergrid/settings/Settings.scala index 374440d..b9ba86d 100755 --- a/stack/loadtests/src/main/scala/org/apache/usergrid/settings/Settings.scala +++ b/stack/loadtests/src/main/scala/org/apache/usergrid/settings/Settings.scala @@ -432,6 +432,8 @@ object Settings { private val countAuditNotFoundViaQuery = new AtomicInteger(0) private val countAuditNotFoundAtAll = new AtomicInteger(0) private val countAuditBadResponse = new AtomicInteger(0) + private val countAuditPayloadUuidError = new AtomicInteger(0) + private val countAuditPayloadNameError = new AtomicInteger(0) private val countAuditEntryDeleteSuccess = new AtomicInteger(0) private val countAuditEntryDeleteFailure = new AtomicInteger(0) @@ -451,6 +453,14 @@ object Settings { countAuditBadResponse.incrementAndGet() } + def incAuditPayloadUuidError(): Unit = { + countAuditPayloadUuidError.incrementAndGet() + } + + def incAuditPayloadNameError(): Unit = { + countAuditPayloadNameError.incrementAndGet() + } + def incAuditEntryDeleteSuccess(): Unit = { countAuditEntryDeleteSuccess.incrementAndGet() } @@ -465,6 +475,8 @@ object Settings { val countNotFoundViaQuery = countAuditNotFoundViaQuery.get val countNotFoundAtAll = countAuditNotFoundAtAll.get val countBadResponse = countAuditBadResponse.get + val countPayloadUuidErrors = countAuditPayloadUuidError.get + val countPayloadNameErrors = countAuditPayloadNameError.get val countDeleteSuccess = countAuditEntryDeleteSuccess.get val countDeleteFailure = countAuditEntryDeleteFailure.get val countTotal = countSuccess + countNotFoundViaQuery + countBadResponse @@ -485,9 +497,16 @@ object Settings { println(s"Not Found at all: $countNotFoundAtAll") println(s"Bad Response: $countBadResponse") if (deleteAfterSuccessfulAudit) { + println() println(s"Delete Successes: $countDeleteSuccess") println(s"Delete Failures: $countDeleteFailure") } + if (countPayloadUuidErrors > 0 || countPayloadNameErrors > 0) { + println() + println(s"Payload Mismatches/Errors") + println(s" UUID: $countPayloadUuidErrors") + println(s" Name: $countPayloadNameErrors") + } println(s"Total: $countTotal") println() println(s"Start Timestamp(ms): $testStartTime")