Skip to content

Commit

Permalink
#340 update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jemacineiras committed Sep 21, 2023
1 parent 1994dff commit 88978ce
Show file tree
Hide file tree
Showing 25 changed files with 249 additions and 262 deletions.
62 changes: 27 additions & 35 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<artifactId>kloadgen</artifactId>

<version>5.6.7</version>
<version>5.6.8</version>

<name>KLoadGen</name>
<description>Load Generation Jmeter plugin for Kafka Cluster. Supporting AVRO, JSON Schema and Protobuf schema types. Generate Artificial
Expand Down Expand Up @@ -290,6 +290,17 @@
</roles>
<timezone>Europe/Madrid</timezone>
</developer>
<developer>
<id>enrique.gonzalo</id>
<name>Enrique Gonzalo Legarra</name>
<email>[email protected]</email>
<organization>Sngular</organization>
<organizationUrl>https://sngular.github.io/</organizationUrl>
<roles>
<role>Senior FullStack Developer</role>
</roles>
<timezone>Europe/Madrid</timezone>
</developer>
</developers>

<scm>
Expand All @@ -313,43 +324,32 @@
<assertj-core.version>3.24.2</assertj-core.version>
<assertj-json.version>1.2.0</assertj-json.version>
<jsonassert.version>1.5.1</jsonassert.version>
<avro.version>1.11.0</avro.version>
<avro.version>1.11.2</avro.version>
<commons-beanutils.version>1.9.4</commons-beanutils.version>
<commons-collections4.version>4.4</commons-collections4.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<gson.version>2.8.6</gson.version>
<guava.version>32.0.0-jre</guava.version>
<jaxb-api.version>2.4.0-b180830.0359</jaxb-api.version>
<jdk.version>11</jdk.version>
<jdk.version>17</jdk.version>
<jmeter.lib.scope>provided</jmeter.lib.scope>
<jmeter.version>5.6.2</jmeter.version>
<json-path.version>2.8.0</json-path.version>
<junit-jupiter-api.version>5.10.0</junit-jupiter-api.version>
<json-path.version>2.6.0</json-path.version>
<junit-jupiter-api.version>5.8.2</junit-jupiter-api.version>
<kafka-schema-registry-client.version>7.1.1</kafka-schema-registry-client.version>
<apicurio-registry.version>2.4.1.Final</apicurio-registry.version>
<kafka.version>3.1.0</kafka.version>
<apicurio-registry.version>2.4.3.Final</apicurio-registry.version>
<kafka.version>3.5.1</kafka.version>
<lombok.version>1.18.22</lombok.version>
<minimal-json.version>0.9.5</minimal-json.version>
<mockito-core.version>4.2.0</mockito-core.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<rest-assured.version>4.5.0</rest-assured.version>
<slf4j-api.version>2.0.0-alpha1</slf4j-api.version>
<wiremock-junit5.version>1.3.1</wiremock-junit5.version>
<wiremock.version>2.35.0</wiremock.version>
<wiremock.version>2.35.1</wiremock.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>jorphan</artifactId>
<version>${jmeter.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
Expand All @@ -365,11 +365,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.eclipsesource.minimal-json</groupId>
<artifactId>minimal-json</artifactId>
Expand All @@ -389,7 +384,12 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.1</version>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down Expand Up @@ -461,7 +461,7 @@
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-protobuf</artifactId>
<version>1.11.0</version>
<version>1.11.2</version>
</dependency>
<dependency>
<groupId>com.github.os72</groupId>
Expand Down Expand Up @@ -502,7 +502,7 @@
<dependency>
<groupId>com.github.everit-org.json-schema</groupId>
<artifactId>org.everit.json.schema</artifactId>
<version>1.14.0</version>
<version>1.14.2</version>
</dependency>
<!-- Options -->
<dependency>
Expand Down Expand Up @@ -748,10 +748,6 @@
<version>${jmeter.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.apache.jmeter</groupId>
<artifactId>jorphan</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
Expand Down Expand Up @@ -818,10 +814,6 @@
<artifactId>ApacheJMeter_java</artifactId>
<version>${jmeter.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.jmeter</groupId>
<artifactId>jorphan</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
Expand Down
21 changes: 8 additions & 13 deletions src/main/java/com/sngular/kloadgen/extractor/SchemaExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Stream;

import com.sngular.kloadgen.common.SchemaRegistryEnum;
import com.sngular.kloadgen.extractor.extractors.ExtractorFactory;
import com.sngular.kloadgen.model.FieldValueMapping;
import io.confluent.kafka.schemaregistry.ParsedSchema;
import lombok.Getter;
import org.apache.commons.lang3.tuple.Pair;

public class SchemaExtractor {
@Getter
public final class SchemaExtractor {

private SchemaRegistryEnum type;

public SchemaExtractor() {
}

public SchemaRegistryEnum getType(){
return type;
}

public void setType(SchemaRegistryEnum type){
public void setType(final SchemaRegistryEnum type) {
this.type = type;
}

Expand All @@ -33,11 +32,11 @@ public static Pair<String, List<FieldValueMapping>> flatPropertiesList(final Str
}

public static List<FieldValueMapping> flatPropertiesList(final ParsedSchema parserSchema) {
return ExtractorFactory.getExtractor(parserSchema.schemaType(), "CONFLUENT").processSchema(parserSchema, SchemaRegistryEnum.CONFLUENT);
return ExtractorFactory.getExtractor(parserSchema.schemaType()).processSchema(parserSchema, SchemaRegistryEnum.CONFLUENT);
}

public static List<String> schemaTypesList(final File schemaFile, final String schemaType, String registry) throws IOException {
return ExtractorFactory.getExtractor(schemaType, registry).getSchemaNameList(readLineByLine(schemaFile.getPath()),
public static List<String> schemaTypesList(final File schemaFile, final String schemaType, final String registry) throws IOException {
return ExtractorFactory.getExtractor(schemaType).getSchemaNameList(readLineByLine(schemaFile.getPath()),
ExtractorFactory.getSchemaRegistry(registry));
}

Expand All @@ -51,8 +50,4 @@ private static String readLineByLine(final String filePath) throws IOException {
return contentBuilder.toString();
}

private static List<FieldValueMapping> processSchema(final ParsedSchema schema) {
return ExtractorFactory.getExtractor(schema.schemaType(),SchemaRegistryEnum.CONFLUENT.name()).processSchema(schema.rawSchema().toString(), SchemaRegistryEnum.CONFLUENT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,45 @@
import java.util.List;
import java.util.Objects;
import java.util.Properties;

import com.sngular.kloadgen.common.SchemaRegistryEnum;
import com.sngular.kloadgen.common.SchemaTypeEnum;
import com.sngular.kloadgen.exception.KLoadGenException;
import com.sngular.kloadgen.extractor.extractors.avro.AvroExtractor;
import com.sngular.kloadgen.extractor.extractors.json.JsonExtractor;
import com.sngular.kloadgen.extractor.extractors.protobuff.ProtobuffExtractor;
import com.sngular.kloadgen.model.FieldValueMapping;
import com.sngular.kloadgen.schemaregistry.adapter.impl.ApicurioParsedSchemaMetadata;
import com.sngular.kloadgen.schemaregistry.adapter.impl.ParsedSchemaAdapter;
import com.sngular.kloadgen.schemaregistry.adapter.impl.AbstractParsedSchemaAdapter;
import com.sngular.kloadgen.schemaregistry.adapter.impl.ApicurioAbstractParsedSchemaMetadata;
import com.sngular.kloadgen.util.JMeterHelper;
import com.sngular.kloadgen.util.SchemaRegistryKeyHelper;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.jmeter.threads.JMeterContextService;

public final class ExtractorFactory {
private static AvroExtractor avroExtractor = new AvroExtractor();
private static final AvroExtractor AVRO_EXTRACTOR = new AvroExtractor();

private static JsonExtractor jsonExtractor = new JsonExtractor();
private static final JsonExtractor JSON_EXTRACTOR = new JsonExtractor();

private static ProtobuffExtractor protobuffExtractor = new ProtobuffExtractor();
private static final ProtobuffExtractor PROTOBUFF_EXTRACTOR = new ProtobuffExtractor();

private ExtractorFactory() {
}

public static ExtractorRegistry getExtractor(final String schemaType, final String schemaRegistryEnum) {

SchemaRegistryEnum registryEnum = getSchemaRegistry(schemaRegistryEnum);
public static ExtractorRegistry getExtractor(final String schemaType) {

if (schemaType != null && EnumUtils.isValidEnum(SchemaTypeEnum.class, schemaType.toUpperCase())) {
final ExtractorRegistry response;
switch (SchemaTypeEnum.valueOf(schemaType.toUpperCase())) {
case JSON:
response = jsonExtractor;
response = JSON_EXTRACTOR;
break;
case AVRO:
response = avroExtractor;
response = AVRO_EXTRACTOR;
break;
case PROTOBUF:
response = protobuffExtractor;
response = PROTOBUFF_EXTRACTOR;
break;
default:
throw new KLoadGenException(String.format("Schema type not supported %s", schemaType));
Expand All @@ -54,7 +53,7 @@ public static ExtractorRegistry getExtractor(final String schemaType, final Stri
}
}

public static SchemaRegistryEnum getSchemaRegistry(String schemaRegistryEnum) {
public static SchemaRegistryEnum getSchemaRegistry(final String schemaRegistryEnum) {
if (schemaRegistryEnum != null && EnumUtils.isValidEnum(SchemaRegistryEnum.class, schemaRegistryEnum.toUpperCase())) {
return SchemaRegistryEnum.valueOf(schemaRegistryEnum.toUpperCase());
} else {
Expand All @@ -66,27 +65,21 @@ public static Pair<String, List<FieldValueMapping>> flatPropertiesList(final Str
final Properties properties = JMeterContextService.getContext().getProperties();
final var schemaParsed = JMeterHelper.getParsedSchema(subjectName, properties);
final String registryName = properties.getProperty(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME);
String schemaType = null;
final ParsedSchemaAdapter parsedSchemaAdapter = schemaParsed.getParsedSchemaAdapter();
schemaType = parsedSchemaAdapter.getType();
final AbstractParsedSchemaAdapter abstractParsedSchemaAdapter = schemaParsed.getParsedSchemaAdapter();
final String schemaType = abstractParsedSchemaAdapter.getType();

List<FieldValueMapping> attributeList = new ArrayList<>();
SchemaRegistryEnum schemaRegistryEnum = SchemaRegistryEnum.valueOf(registryName.toUpperCase());
final List<FieldValueMapping> attributeList = new ArrayList<>();
final SchemaRegistryEnum schemaRegistryEnum = SchemaRegistryEnum.valueOf(registryName.toUpperCase());

Object schema = null;
final Object schema;
if (Objects.nonNull(registryName)) {
//TODO change parser
switch (schemaRegistryEnum) {
case APICURIO:
schema = ((ApicurioParsedSchemaMetadata) parsedSchemaAdapter).getSchema();
break;
case CONFLUENT:
schema = parsedSchemaAdapter.getRawSchema();
break;
default:
throw new KLoadGenException("Schema Registry Type nos supported " + registryName.toUpperCase());
}
attributeList = getExtractor(schemaType,registryName.toUpperCase()).processSchema(schema, schemaRegistryEnum);
schema = switch (schemaRegistryEnum) {
case APICURIO -> ((ApicurioAbstractParsedSchemaMetadata) abstractParsedSchemaAdapter).getSchema();
case CONFLUENT -> abstractParsedSchemaAdapter.getRawSchema();
default -> throw new KLoadGenException("Schema Registry Type nos supported " + registryName.toUpperCase());
};
attributeList.addAll(getExtractor(schemaType).processSchema(schema, schemaRegistryEnum));
}
return Pair.of(schemaType, attributeList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Set;

import com.sngular.kloadgen.extractor.extractors.SchemaExtractorUtil;
import com.sngular.kloadgen.model.FieldValueMapping;
import com.sngular.kloadgen.randomtool.random.RandomObject;
Expand All @@ -22,27 +23,25 @@ public abstract class AbstractAvroFileExtractor {
protected AbstractAvroFileExtractor() {
}

public List<FieldValueMapping> processSchemaDefault(final Schema schemaReceived) {
public final List<FieldValueMapping> processSchemaDefault(final Schema schemaReceived) {
final var attributeList = new ArrayList<FieldValueMapping>();
Schema aux = null;
if (checkIfUnion(schemaReceived)) {
aux = schemaReceived.getTypes().get(schemaReceived.getTypes().size() - 1);
} else if (checkIfRecord(schemaReceived)) {
aux = schemaReceived;
}
if(aux != null && (checkIfUnion(schemaReceived) || checkIfRecord(schemaReceived))){
if (aux != null && (checkIfUnion(schemaReceived) || checkIfRecord(schemaReceived))) {
aux.getFields().forEach(field -> processField(field, attributeList, true, true));
}
return attributeList;
}

public List<String> getSchemaNameList(Schema schema) {
List<String> result = new ArrayList<>();
result.addAll(extractSchemaNames(schema));
return result;
public final List<String> getSchemaNameList(final Schema schema) {
return new ArrayList<>(extractSchemaNames(schema));
}

public void processField(
public final void processField(
final Schema.Field innerField, final List<FieldValueMapping> completeFieldList, final boolean isAncestorRequired, final boolean isAncestor) {
if (checkIfRecord(innerField.schema())) {
processRecordFieldList(innerField.name(), ".", processFieldList(innerField.schema().getFields(), isAncestorRequired), completeFieldList);
Expand Down Expand Up @@ -353,8 +352,8 @@ private boolean checkIfRequiredField(final Schema innerSchema) {
return result;
}

private Set<String> extractSchemaNames(Schema schema) {
Set<String> schemaNames = new HashSet<>();
private Set<String> extractSchemaNames(final Schema schema) {
final Set<String> schemaNames = new HashSet<>();
if (checkIfRecord(schema)) {
schemaNames.add(schema.getName());
schema.getFields().forEach(field -> schemaNames.addAll(extractSchemaNames(field.schema())));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sngular.kloadgen.extractor.extractors.avro;

import java.util.List;

import com.sngular.kloadgen.extractor.extractors.Extractor;
import com.sngular.kloadgen.model.FieldValueMapping;
import io.apicurio.registry.utils.serde.avro.AvroSchemaUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import com.sngular.kloadgen.common.SchemaTypeEnum;
import com.sngular.kloadgen.model.FieldValueMapping;
import com.sngular.kloadgen.processor.model.SchemaProcessorPOJO;
Expand Down Expand Up @@ -223,7 +224,7 @@ private boolean searchFieldWithSharedPathAndMakeItProcessable(
if (otherFieldIsRequired) {
shouldProcess = false;
} else {
if (listFieldsSharingPath.size() > 0) {
if (!listFieldsSharingPath.isEmpty()) {
makeFieldValueMappingRequiredAndNotNullable(fetchFieldSharingPathToMakeItRequired(listFieldsSharingPath));
shouldProcess = fieldValueMapping.getRequired();
} else {
Expand Down
Loading

0 comments on commit 88978ce

Please sign in to comment.