This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util | |
import io.gatling.commons.validation._ | |
import io.gatling.core.Predef._ | |
import io.gatling.http.client._ | |
object SignatureCalculatorRemoveHeader { | |
def apply(header: String): (Request, Session) => Validation[_] = (request, _) => { | |
request.getHeaders.remove(header) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util | |
import java.math._ | |
import java.security._ | |
object Sha256 { | |
def encode(raw: String): String = { | |
String.format("%032x", new BigInteger(1, MessageDigest.getInstance("SHA-256").digest(raw.getBytes("UTF-8")))) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util | |
import io.gatling.commons.util._ | |
object RoundRobin { | |
def apply[T](values: IndexedSeq[T]) = CircularIterator(values = values, threadSafe = true) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util | |
object Percentile { | |
// @see http://commons.apache.org/proper/commons-math/javadocs/api-3.6/org/apache/commons/math3/stat/descriptive/rank/Percentile.html | |
def apply(array: Seq[Double], p: Int) = { | |
require(p > 0) | |
require(p <= 100) | |
require(array.nonEmpty) | |
val n = array.length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util | |
import io.gatling.core.Predef._ | |
import scala.concurrent.duration._ | |
object PauseExceptFirstTime { | |
def apply(counter: String, duration: FiniteDuration) = | |
doIf(_(counter).asOption[Int].getOrElse(0) > 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util | |
import java.nio.charset._ | |
import java.util._ | |
object OAuth2BasicHeader { | |
def apply(key: String, secret: String) = { | |
val bytes = s"$key:$secret".getBytes(StandardCharsets.UTF_8) | |
"Basic " + Base64.getEncoder.encodeToString(bytes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util | |
import scala.math.min | |
object LevenshteinDistance { | |
def apply[A](expected: Iterable[A], actual: Iterable[A]) = round(100.0 * editDist(expected, actual) / expected.size) | |
def pair[A](expectedLeft: Iterable[A], actualLeft: Iterable[A], expectedRight: Iterable[A], actualRight: Iterable[A]) = { | |
val leftDistance = apply(expectedLeft, actualLeft) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util | |
import java.io._ | |
import java.util._ | |
object Base64File { | |
def encode(sourcePath: String, targetPath: String) = { | |
val inputStream = new FileInputStream(sourcePath) | |
val outputStream = new FileOutputStream(targetPath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util | |
import java.io._ | |
import java.nio.file._ | |
object SaveResponseBodyToFile { | |
def apply(body: InputStream, path: String) = { | |
val file = new File(path) | |
new File(file.getParent).mkdirs() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util | |
import io.gatling.core.session._ | |
object ElParser { | |
def apply[T](expression: Expression[T], session: Session): T = toOption(expression, session).get | |
def toOption[T](expression: Expression[T], session: Session): Option[T] = expression(session).toOption | |
} |