Skip to content

Instantly share code, notes, and snippets.

View Amerousful's full-sized avatar

Pavel Bairov Amerousful

View GitHub Profile
@Amerousful
Amerousful / gatling-jsonpath.scala
Created October 7, 2024 13:56
Gatling JsonPath
package utils
import com.fasterxml.jackson.databind.node.TextNode
import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper}
import io.gatling.jsonpath.JsonPath
object JsonPathUtil {
private lazy val mapper = new ObjectMapper
// <!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka-clients -->
// <dependency>
// <groupId>org.apache.kafka</groupId>
// <artifactId>kafka-clients</artifactId>
// <version>3.3.2</version>
// </dependency>
import org.apache.kafka.clients.consumer.KafkaConsumer
import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}
@Amerousful
Amerousful / randomIPv4.scala
Created July 27, 2023 09:04
Scala, generate random IPv4
import java.util.concurrent.ThreadLocalRandom
def random(max: Int): Int = {
ThreadLocalRandom.current().nextInt(max + 1)
}
def generateIpV4():String =
(Seq.fill(3)(random(255)) ++ Seq(random(254))).mkString(".")
println(generateIpV4())
@Amerousful
Amerousful / kafka.scala
Last active May 27, 2023 14:57
Kafka | Producer and Consumer with update `value`
import org.apache.kafka.clients.consumer.KafkaConsumer
import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}
import java.time.Duration
import scala.jdk.CollectionConverters._
object ConsumerExample extends App {
import java.util.Properties
@Amerousful
Amerousful / MultipleLevelFilter.scala
Created October 12, 2022 14:09
Scala, Logback Multiply Level Filter
class MultipleLevelFilter extends AbstractMatcherFilter[ILoggingEvent] {
private var levels: Set[Level] = _
def setLevels(levels: String): Unit = {
this.levels = levels.split('|').map(Level.toLevel(_, Level.OFF)).toSet
}
def getLevels = levels
@Amerousful
Amerousful / gatling-pass-scenario-variables.md
Last active March 7, 2025 14:31
Gatling: How to pass the session variables between two scenarios?

Gatling: How to pass the session variables between two scenarios?

I have a general solution which can easy to use. There are several steps how to do it.

Create methods which get all session variable from one scenario and another method which sets this variables:

import scala.collection.concurrent.{Map => ConcurrentMap}

def passAnotherSession(implicit transferVariable: ConcurrentMap[String, Any]): Expression[Session] =
@Amerousful
Amerousful / randomIPv6.scala
Created June 9, 2022 14:41
Scala, generate random IPv6
import java.util.concurrent.ThreadLocalRandom
val scope = (0 to 9) ++ ('a' to 'f')
def randomElement[T](seq: T*): T = {
seq(ThreadLocalRandom.current.nextInt(seq.size))
}
def generateIp: String = (1 to 32).foldLeft("") { (acc, _) =>
acc + randomElement(scope: _*)
@Amerousful
Amerousful / usAreaCodes.txt
Last active October 20, 2020 08:55
US and Canadian phone area codes
205
251
256
334
938
907
684
480
520
602