-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: java and kotlin support (#125)
* feat: java kafka protocol --------- Co-authored-by: a.ugodnikov <[email protected]>
- Loading branch information
Showing
25 changed files
with
840 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
31 changes: 31 additions & 0 deletions
31
src/main/java/ru/tinkoff/gatling/kafka/javaapi/KafkaDsl.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package ru.tinkoff.gatling.kafka.javaapi; | ||
|
||
import static io.gatling.javaapi.core.internal.Expressions.*; | ||
|
||
import io.gatling.core.check.CheckBuilder; | ||
import org.apache.avro.generic.GenericRecord; | ||
import ru.tinkoff.gatling.kafka.javaapi.checks.KafkaChecks; | ||
import ru.tinkoff.gatling.kafka.javaapi.protocol.*; | ||
import ru.tinkoff.gatling.kafka.javaapi.request.builder.*; | ||
import ru.tinkoff.gatling.kafka.request.KafkaProtocolMessage; | ||
import scala.Function1; | ||
|
||
public final class KafkaDsl { | ||
|
||
public static KafkaProtocolBuilderBase kafka() { | ||
return new KafkaProtocolBuilderBase(); | ||
} | ||
|
||
public static KafkaRequestBuilderBase kafka(String requestName) { | ||
return new KafkaRequestBuilderBase(ru.tinkoff.gatling.kafka.Predef.kafka(toStringExpression(requestName)), requestName); | ||
} | ||
|
||
public static KafkaChecks.KafkaCheckTypeWrapper simpleCheck(Function1<KafkaProtocolMessage, Boolean> f) { | ||
return new KafkaChecks.KafkaCheckTypeWrapper(new KafkaChecks.SimpleChecksScala().simpleCheck(f.andThen(Boolean::valueOf))); | ||
} | ||
|
||
public static CheckBuilder.Find<Object, KafkaProtocolMessage, GenericRecord> avroBody() { | ||
return new KafkaChecks.SimpleChecksScala().avroBody(ru.tinkoff.gatling.kafka.javaapi.checks.KafkaChecks.avroSerde()); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/ru/tinkoff/gatling/kafka/javaapi/checks/KafkaCheckType.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ru.tinkoff.gatling.kafka.javaapi.checks; | ||
|
||
import io.gatling.javaapi.core.CheckBuilder.CheckType; | ||
|
||
public enum KafkaCheckType implements CheckType { | ||
ResponseCode | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/ru/tinkoff/gatling/kafka/javaapi/checks/KafkaChecks.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package ru.tinkoff.gatling.kafka.javaapi.checks | ||
|
||
import io.gatling.core.check.Check | ||
import io.gatling.core.check._ | ||
import io.gatling.core.check.bytes.BodyBytesCheckType | ||
import io.gatling.core.check.jmespath.JmesPathCheckType | ||
import io.gatling.core.check.jsonpath.JsonPathCheckType | ||
import io.gatling.core.check.string.BodyStringCheckType | ||
import io.gatling.core.check.substring.SubstringCheckType | ||
import io.gatling.core.check.xpath.XPathCheckType | ||
import io.gatling.javaapi.core.internal.CoreCheckType | ||
import ru.tinkoff.gatling.kafka.checks.{KafkaCheckMaterializer, KafkaCheckSupport} | ||
import ru.tinkoff.gatling.kafka.request.KafkaProtocolMessage | ||
import ru.tinkoff.gatling.kafka.{KafkaCheck, checks} | ||
import net.sf.saxon.s9api.XdmNode | ||
import com.fasterxml.jackson.databind.JsonNode | ||
import io.confluent.kafka.streams.serdes.avro.GenericAvroSerde | ||
import org.apache.avro.generic.GenericRecord | ||
import org.apache.kafka.common.serialization.Serde | ||
|
||
import java.{util => ju} | ||
import scala.jdk.CollectionConverters._ | ||
|
||
object KafkaChecks { | ||
case class KafkaCheckTypeWrapper(value: Check[KafkaProtocolMessage]) | ||
class SimpleChecksScala extends KafkaCheckSupport {} | ||
|
||
val avroSerde: Serde[GenericRecord] = new GenericAvroSerde() | ||
|
||
private def toScalaCheck(javaCheck: Object): KafkaCheck = { | ||
javaCheck match { | ||
case _: io.gatling.javaapi.core.CheckBuilder => | ||
val checkBuilder = javaCheck.asInstanceOf[io.gatling.javaapi.core.CheckBuilder] | ||
val scalaCheck = checkBuilder.asScala | ||
checkBuilder.`type` match { | ||
case CoreCheckType.BodyBytes => | ||
scalaCheck | ||
.asInstanceOf[CheckBuilder[BodyBytesCheckType, Array[Byte]]] | ||
.build(KafkaCheckMaterializer.bodyBytes) | ||
case CoreCheckType.BodyString => | ||
scalaCheck | ||
.asInstanceOf[CheckBuilder[BodyStringCheckType, String]] | ||
.build(KafkaCheckMaterializer.bodyString(io.gatling.core.Predef.configuration)) | ||
case CoreCheckType.Substring => | ||
scalaCheck | ||
.asInstanceOf[CheckBuilder[SubstringCheckType, String]] | ||
.build(KafkaCheckMaterializer.substring(io.gatling.core.Predef.configuration)) | ||
case CoreCheckType.XPath => | ||
scalaCheck | ||
.asInstanceOf[CheckBuilder[XPathCheckType, XdmNode]] | ||
.build(KafkaCheckMaterializer.xpath(io.gatling.core.Predef.configuration)) | ||
case CoreCheckType.JsonPath => | ||
scalaCheck | ||
.asInstanceOf[CheckBuilder[JsonPathCheckType, JsonNode]] | ||
.build( | ||
KafkaCheckMaterializer.jsonPath(io.gatling.core.Predef.defaultJsonParsers, io.gatling.core.Predef.configuration), | ||
) | ||
case CoreCheckType.JmesPath => | ||
scalaCheck | ||
.asInstanceOf[CheckBuilder[JmesPathCheckType, JsonNode]] | ||
.build( | ||
KafkaCheckMaterializer.jmesPath(io.gatling.core.Predef.defaultJsonParsers, io.gatling.core.Predef.configuration), | ||
) | ||
case KafkaCheckType.ResponseCode => | ||
scalaCheck | ||
.asInstanceOf[CheckBuilder[checks.KafkaCheckMaterializer.KafkaMessageCheckType, KafkaProtocolMessage]] | ||
.build( | ||
KafkaCheckMaterializer.kafkaStatusCheck, | ||
) | ||
case unknown => throw new IllegalArgumentException(s"Kafka DSL doesn't support $unknown") | ||
} | ||
} | ||
} | ||
|
||
def toScalaChecks(javaChecks: ju.List[Object]): Seq[KafkaCheck] = | ||
javaChecks.asScala.map(toScalaCheck).toSeq | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/ru/tinkoff/gatling/kafka/javaapi/protocol/KPConsumeSettingsStep.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ru.tinkoff.gatling.kafka.javaapi.protocol; | ||
|
||
import java.time.Duration; | ||
import java.util.Map; | ||
|
||
import static scala.jdk.javaapi.CollectionConverters.asScala; | ||
import scala.jdk.javaapi.DurationConverters; | ||
|
||
public class KPConsumeSettingsStep { | ||
|
||
private final Map<String, Object> producerSettings; | ||
private final Map<String, Object> consumeSettings; | ||
|
||
public KPConsumeSettingsStep(Map<String, Object> producerSettings, Map<String, Object> consumeSettings) { | ||
this.producerSettings = producerSettings; | ||
this.consumeSettings = consumeSettings; | ||
} | ||
|
||
public KafkaProtocolBuilderNew timeout(Duration timeout) { | ||
scala.collection.immutable.Map<String, Object> ps = scala.collection.immutable.Map.from(asScala(this.producerSettings)); | ||
scala.collection.immutable.Map<String, Object> cs = scala.collection.immutable.Map.from(asScala(this.consumeSettings)); | ||
return new KafkaProtocolBuilderNew(ru.tinkoff.gatling.kafka.protocol.KafkaProtocolBuilderNew.apply(ps, cs, DurationConverters.toScala(timeout), ru.tinkoff.gatling.kafka.protocol.KafkaProtocol.KafkaKeyMatcher$.MODULE$)); | ||
} | ||
|
||
public KafkaProtocolBuilderNew withDefaultTimeout() { | ||
scala.collection.immutable.Map<String, Object> ps = scala.collection.immutable.Map.from(asScala(this.producerSettings)); | ||
scala.collection.immutable.Map<String, Object> cs = scala.collection.immutable.Map.from(asScala(this.consumeSettings)); | ||
return new KafkaProtocolBuilderNew(ru.tinkoff.gatling.kafka.protocol.KafkaProtocolBuilderNew.apply(ps, cs, DurationConverters.toScala(Duration.ofSeconds(60)), ru.tinkoff.gatling.kafka.protocol.KafkaProtocol.KafkaKeyMatcher$.MODULE$)); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/ru/tinkoff/gatling/kafka/javaapi/protocol/KPProducerSettingsStep.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package ru.tinkoff.gatling.kafka.javaapi.protocol; | ||
|
||
import java.util.Map; | ||
|
||
public class KPProducerSettingsStep { | ||
|
||
private final Map<String, Object> ps; | ||
|
||
public KPProducerSettingsStep(Map<String, Object> ps) { | ||
this.ps = ps; | ||
} | ||
|
||
public KPConsumeSettingsStep consumeSettings(Map<String, Object> cs) { | ||
return new KPConsumeSettingsStep(ps, cs); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/ru/tinkoff/gatling/kafka/javaapi/protocol/KafkaProtocolBuilder.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ru.tinkoff.gatling.kafka.javaapi.protocol; | ||
|
||
import io.gatling.core.protocol.Protocol; | ||
import io.gatling.javaapi.core.ProtocolBuilder; | ||
|
||
public class KafkaProtocolBuilder implements ProtocolBuilder { | ||
|
||
private final ru.tinkoff.gatling.kafka.protocol.KafkaProtocolBuilder wrapped; | ||
|
||
public KafkaProtocolBuilder(ru.tinkoff.gatling.kafka.protocol.KafkaProtocolBuilder wrapped) { | ||
this.wrapped = wrapped; | ||
} | ||
|
||
@Override | ||
public Protocol protocol() { | ||
return wrapped.build(); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/ru/tinkoff/gatling/kafka/javaapi/protocol/KafkaProtocolBuilderBase.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package ru.tinkoff.gatling.kafka.javaapi.protocol; | ||
|
||
import java.util.Collections; | ||
|
||
public class KafkaProtocolBuilderBase { | ||
|
||
public KafkaProtocolBuilderPropertiesStep topic(String name) { | ||
return new KafkaProtocolBuilderPropertiesStep(name, Collections.emptyMap()); | ||
} | ||
|
||
public KafkaProtocolBuilderNewBase requestReply() { | ||
return new KafkaProtocolBuilderNewBase(); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/ru/tinkoff/gatling/kafka/javaapi/protocol/KafkaProtocolBuilderNew.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package ru.tinkoff.gatling.kafka.javaapi.protocol; | ||
|
||
import io.gatling.core.protocol.Protocol; | ||
import io.gatling.javaapi.core.ProtocolBuilder; | ||
import ru.tinkoff.gatling.kafka.request.KafkaProtocolMessage; | ||
import scala.Function1; | ||
|
||
public class KafkaProtocolBuilderNew implements ProtocolBuilder { | ||
|
||
private ru.tinkoff.gatling.kafka.protocol.KafkaProtocolBuilderNew wrapped; | ||
|
||
public KafkaProtocolBuilderNew(ru.tinkoff.gatling.kafka.protocol.KafkaProtocolBuilderNew wrapped) { | ||
this.wrapped = wrapped; | ||
} | ||
|
||
public KafkaProtocolBuilderNew matchByValue() { | ||
this.wrapped = wrapped.matchByValue(); | ||
return this; | ||
} | ||
|
||
public KafkaProtocolBuilderNew matchByMessage(Function1<KafkaProtocolMessage, byte[]> keyExtractor) { | ||
this.wrapped = wrapped.matchByMessage(keyExtractor); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Protocol protocol() { | ||
return wrapped.build(); | ||
} | ||
|
||
} | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
src/main/java/ru/tinkoff/gatling/kafka/javaapi/protocol/KafkaProtocolBuilderNewBase.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ru.tinkoff.gatling.kafka.javaapi.protocol; | ||
|
||
import java.util.Map; | ||
|
||
public class KafkaProtocolBuilderNewBase { | ||
|
||
public KPProducerSettingsStep producerSettings(Map<String, Object> ps) { | ||
return new KPProducerSettingsStep(ps); | ||
} | ||
|
||
} | ||
|
26 changes: 26 additions & 0 deletions
26
...in/java/ru/tinkoff/gatling/kafka/javaapi/protocol/KafkaProtocolBuilderPropertiesStep.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ru.tinkoff.gatling.kafka.javaapi.protocol; | ||
|
||
import java.util.Map; | ||
import static scala.jdk.javaapi.CollectionConverters.asScala; | ||
|
||
public class KafkaProtocolBuilderPropertiesStep { | ||
|
||
private final String topic; | ||
private Map<String, Object> props; | ||
|
||
public KafkaProtocolBuilderPropertiesStep(String topic, Map<String, Object> props){ | ||
this.topic = topic; | ||
this.props = props; | ||
} | ||
|
||
public KafkaProtocolBuilder properties(Map<String, Object> props) { | ||
this.props = props; | ||
scala.collection.immutable.Map<String, Object> scalaMap = scala.collection.immutable.Map.from(asScala(this.props)); | ||
return new KafkaProtocolBuilder( | ||
ru.tinkoff.gatling.kafka.protocol.KafkaProtocolBuilderPropertiesStep.apply(this.topic, scalaMap) | ||
.properties(scalaMap) | ||
); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.