Measure bytesize of strings as if encoded in UTF-8.
Previous implementation took the conservative estimate that every char is two bytes. While this may fit the JVM model, it violates user expectations that, for instance, base64-encoded binary files take 1 byte per character.
Adapted tests to new way of measuring String sizes.
diff --git a/tests/src/whisk/core/controller/test/ActionsApiTests.scala b/tests/src/whisk/core/controller/test/ActionsApiTests.scala
index 81f8321..c2b6d18 100644
--- a/tests/src/whisk/core/controller/test/ActionsApiTests.scala
+++ b/tests/src/whisk/core/controller/test/ActionsApiTests.scala
@@ -226,7 +226,7 @@
it should "reject create with exec which is too big" in {
implicit val tid = transid()
- val code = "a" * ((actionLimit.toBytes / 2L).toInt + 1)
+ val code = "a" * (actionLimit.toBytes.toInt + 1)
val content = s"""{"exec":{"kind":"python","code":"$code"}}""".stripMargin.parseJson.asJsObject
Put(s"$collectionPath/${aname}", content) ~> sealRoute(routes(creds)) ~> check {
status should be(RequestEntityTooLarge)
@@ -237,7 +237,7 @@
it should "reject update with exec which is too big" in {
implicit val tid = transid()
val oldCode = "function main()"
- val code = "a" * ((actionLimit.toBytes / 2L).toInt + 1)
+ val code = "a" * (actionLimit.toBytes.toInt + 1)
val action = WhiskAction(namespace, aname, Exec.js("??"))
val content = s"""{"exec":{"kind":"python","code":"$code"}}""".stripMargin.parseJson.asJsObject
put(entityStore, action)
@@ -249,7 +249,7 @@
it should "reject create with parameters which are too big" in {
implicit val tid = transid()
- val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 2 / 20 + Math.pow(10, 9) + 2) toLong)
+ val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 20 + Math.pow(10, 9) + 2) toLong)
val parameters = keys map { key =>
Parameters(key.toString, "a" * 10)
} reduce (_ ++ _)
@@ -262,7 +262,7 @@
it should "reject create with annotations which are too big" in {
implicit val tid = transid()
- val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 2 / 20 + Math.pow(10, 9) + 2) toLong)
+ val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 20 + Math.pow(10, 9) + 2) toLong)
val parameters = keys map { key =>
Parameters(key.toString, "a" * 10)
} reduce (_ ++ _)
diff --git a/tests/src/whisk/core/controller/test/PackagesApiTests.scala b/tests/src/whisk/core/controller/test/PackagesApiTests.scala
index c7a392f..465c2e0 100644
--- a/tests/src/whisk/core/controller/test/PackagesApiTests.scala
+++ b/tests/src/whisk/core/controller/test/PackagesApiTests.scala
@@ -435,7 +435,7 @@
it should "reject create package reference when annotations are too big" in {
implicit val tid = transid()
- val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 2 / 20 + Math.pow(10, 9) + 2) toLong)
+ val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 20 + Math.pow(10, 9) + 2) toLong)
val parameters = keys map { key =>
Parameters(key.toString, "a" * 10)
} reduce (_ ++ _)
@@ -448,7 +448,7 @@
it should "reject create package reference when parameters are too big" in {
implicit val tid = transid()
- val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 2 / 20 + Math.pow(10, 9) + 2) toLong)
+ val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 20 + Math.pow(10, 9) + 2) toLong)
val parameters = keys map { key =>
Parameters(key.toString, "a" * 10)
} reduce (_ ++ _)
@@ -461,7 +461,7 @@
it should "reject update package reference when parameters are too big" in {
implicit val tid = transid()
- val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 2 / 20 + Math.pow(10, 9) + 2) toLong)
+ val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 20 + Math.pow(10, 9) + 2) toLong)
val parameters = keys map { key =>
Parameters(key.toString, "a" * 10)
} reduce (_ ++ _)
diff --git a/tests/src/whisk/core/controller/test/RulesApiTests.scala b/tests/src/whisk/core/controller/test/RulesApiTests.scala
index 5c7a658..70a1ad0 100644
--- a/tests/src/whisk/core/controller/test/RulesApiTests.scala
+++ b/tests/src/whisk/core/controller/test/RulesApiTests.scala
@@ -387,7 +387,7 @@
val trigger = WhiskTrigger(namespace, aname())
val action = WhiskAction(namespace, aname(), Exec.js("??"))
- val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (Parameters.sizeLimit.toBytes / 2 / 20 + Math.pow(10, 9) + 2) toLong)
+ val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (Parameters.sizeLimit.toBytes / 20 + Math.pow(10, 9) + 2) toLong)
val parameters = keys map { key =>
Parameters(key.toString, "a" * 10)
} reduce (_ ++ _)
@@ -412,7 +412,7 @@
val action = WhiskAction(namespace, aname(), Exec.js("??"))
val rule = WhiskRule(namespace, aname(), trigger.fullyQualifiedName(false), action.fullyQualifiedName(false))
- val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (Parameters.sizeLimit.toBytes / 2 / 20 + Math.pow(10, 9) + 2) toLong)
+ val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (Parameters.sizeLimit.toBytes / 20 + Math.pow(10, 9) + 2) toLong)
val parameters = keys map { key =>
Parameters(key.toString, "a" * 10)
} reduce (_ ++ _)
diff --git a/tests/src/whisk/core/controller/test/TriggersApiTests.scala b/tests/src/whisk/core/controller/test/TriggersApiTests.scala
index 7db4e74..ee5e4e3 100644
--- a/tests/src/whisk/core/controller/test/TriggersApiTests.scala
+++ b/tests/src/whisk/core/controller/test/TriggersApiTests.scala
@@ -196,7 +196,7 @@
it should "reject create with parameters which are too big" in {
implicit val tid = transid()
- val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 2 / 20 + Math.pow(10, 9) + 2) toLong)
+ val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 20 + Math.pow(10, 9) + 2) toLong)
val parameters = keys map { key =>
Parameters(key.toString, "a" * 10)
} reduce (_ ++ _)
@@ -209,7 +209,7 @@
it should "reject create with annotations which are too big" in {
implicit val tid = transid()
- val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 2 / 20 + Math.pow(10, 9) + 2) toLong)
+ val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 20 + Math.pow(10, 9) + 2) toLong)
val parameters = keys map { key =>
Parameters(key.toString, "a" * 10)
} reduce (_ ++ _)
@@ -223,7 +223,7 @@
it should "reject update with parameters which are too big" in {
implicit val tid = transid()
val trigger = WhiskTrigger(namespace, aname)
- val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 2 / 20 + Math.pow(10, 9) + 2) toLong)
+ val keys: List[Long] = List.range(Math.pow(10, 9) toLong, (parametersLimit.toBytes / 20 + Math.pow(10, 9) + 2) toLong)
val parameters = keys map { key =>
Parameters(key.toString, "a" * 10)
} reduce (_ ++ _)
diff --git a/tests/src/whisk/core/limits/ActionLimitsTests.scala b/tests/src/whisk/core/limits/ActionLimitsTests.scala
index 29eae78..940f670 100644
--- a/tests/src/whisk/core/limits/ActionLimitsTests.scala
+++ b/tests/src/whisk/core/limits/ActionLimitsTests.scala
@@ -146,7 +146,7 @@
val actionCode = new File(s"$testActionsDir${File.separator}$name.js")
actionCode.createNewFile()
val pw = new PrintWriter(actionCode)
- pw.write("a" * ((actionCodeLimit.toBytes / 2) + 1).toInt)
+ pw.write("a" * (actionCodeLimit.toBytes + 1).toInt)
pw.close
assetHelper.withCleaner(wsk.action, name, confirmDelete = false) {