diff --git a/pom.xml b/pom.xml
index ec0f061a..e1586d1d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
kloadgen
- 5.6.7
+ 5.6.8
KLoadGen
Load Generation Jmeter plugin for Kafka Cluster. Supporting AVRO, JSON Schema and Protobuf schema types. Generate Artificial
@@ -290,6 +290,17 @@
Europe/Madrid
+
+ enrique.gonzalo
+ Enrique Gonzalo Legarra
+ enrique.gonzalo@sngular.com
+ Sngular
+ https://sngular.github.io/
+
+ Senior FullStack Developer
+
+ Europe/Madrid
+
@@ -313,21 +324,21 @@
3.24.2
1.2.0
1.5.1
- 1.11.0
+ 1.11.2
1.9.4
4.4
3.12.0
2.8.6
32.0.0-jre
2.4.0-b180830.0359
- 11
+ 17
provided
5.6.2
- 2.8.0
- 5.10.0
+ 2.6.0
+ 5.8.2
7.1.1
- 2.4.1.Final
- 3.1.0
+ 2.4.3.Final
+ 3.5.1
1.18.22
0.9.5
4.2.0
@@ -335,21 +346,10 @@
4.5.0
2.0.0-alpha1
1.3.1
- 2.35.0
+ 2.35.1
-
- org.apache.jmeter
- jorphan
- ${jmeter.version}
-
-
- org.slf4j
- slf4j-api
-
-
-
org.apache.kafka
kafka-clients
@@ -365,11 +365,6 @@
-
- com.google.guava
- guava
- ${guava.version}
-
com.eclipsesource.minimal-json
minimal-json
@@ -389,7 +384,12 @@
com.fasterxml.jackson.core
jackson-core
- 2.13.1
+ 2.15.2
+
+
+ com.fasterxml.jackson.core
+ jackson-annotations
+ 2.15.2
org.projectlombok
@@ -461,7 +461,7 @@
org.apache.avro
avro-protobuf
- 1.11.0
+ 1.11.2
com.github.os72
@@ -502,7 +502,7 @@
com.github.everit-org.json-schema
org.everit.json.schema
- 1.14.0
+ 1.14.2
@@ -748,10 +748,6 @@
${jmeter.version}
provided
-
- org.apache.jmeter
- jorphan
-
org.apache.logging.log4j
log4j-slf4j-impl
@@ -818,10 +814,6 @@
ApacheJMeter_java
${jmeter.version}
-
- org.apache.jmeter
- jorphan
-
org.apache.logging.log4j
log4j-slf4j-impl
diff --git a/src/main/java/com/sngular/kloadgen/extractor/SchemaExtractor.java b/src/main/java/com/sngular/kloadgen/extractor/SchemaExtractor.java
index bab1aee1..a7a7b760 100644
--- a/src/main/java/com/sngular/kloadgen/extractor/SchemaExtractor.java
+++ b/src/main/java/com/sngular/kloadgen/extractor/SchemaExtractor.java
@@ -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;
}
@@ -33,11 +32,11 @@ public static Pair> flatPropertiesList(final Str
}
public static List 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 schemaTypesList(final File schemaFile, final String schemaType, String registry) throws IOException {
- return ExtractorFactory.getExtractor(schemaType, registry).getSchemaNameList(readLineByLine(schemaFile.getPath()),
+ public static List schemaTypesList(final File schemaFile, final String schemaType, final String registry) throws IOException {
+ return ExtractorFactory.getExtractor(schemaType).getSchemaNameList(readLineByLine(schemaFile.getPath()),
ExtractorFactory.getSchemaRegistry(registry));
}
@@ -51,8 +50,4 @@ private static String readLineByLine(final String filePath) throws IOException {
return contentBuilder.toString();
}
- private static List processSchema(final ParsedSchema schema) {
- return ExtractorFactory.getExtractor(schema.schemaType(),SchemaRegistryEnum.CONFLUENT.name()).processSchema(schema.rawSchema().toString(), SchemaRegistryEnum.CONFLUENT);
- }
-
}
diff --git a/src/main/java/com/sngular/kloadgen/extractor/extractors/ExtractorFactory.java b/src/main/java/com/sngular/kloadgen/extractor/extractors/ExtractorFactory.java
index 452b9b9a..9ff5903f 100644
--- a/src/main/java/com/sngular/kloadgen/extractor/extractors/ExtractorFactory.java
+++ b/src/main/java/com/sngular/kloadgen/extractor/extractors/ExtractorFactory.java
@@ -4,6 +4,7 @@
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;
@@ -11,8 +12,8 @@
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;
@@ -20,30 +21,28 @@
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));
@@ -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 {
@@ -66,27 +65,21 @@ public static Pair> 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 attributeList = new ArrayList<>();
- SchemaRegistryEnum schemaRegistryEnum = SchemaRegistryEnum.valueOf(registryName.toUpperCase());
+ final List 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);
}
diff --git a/src/main/java/com/sngular/kloadgen/extractor/extractors/avro/AbstractAvroFileExtractor.java b/src/main/java/com/sngular/kloadgen/extractor/extractors/avro/AbstractAvroFileExtractor.java
index 2346533d..5c48fff4 100644
--- a/src/main/java/com/sngular/kloadgen/extractor/extractors/avro/AbstractAvroFileExtractor.java
+++ b/src/main/java/com/sngular/kloadgen/extractor/extractors/avro/AbstractAvroFileExtractor.java
@@ -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;
@@ -22,7 +23,7 @@ public abstract class AbstractAvroFileExtractor {
protected AbstractAvroFileExtractor() {
}
- public List processSchemaDefault(final Schema schemaReceived) {
+ public final List processSchemaDefault(final Schema schemaReceived) {
final var attributeList = new ArrayList();
Schema aux = null;
if (checkIfUnion(schemaReceived)) {
@@ -30,19 +31,17 @@ public List processSchemaDefault(final Schema schemaReceived)
} 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 getSchemaNameList(Schema schema) {
- List result = new ArrayList<>();
- result.addAll(extractSchemaNames(schema));
- return result;
+ public final List getSchemaNameList(final Schema schema) {
+ return new ArrayList<>(extractSchemaNames(schema));
}
- public void processField(
+ public final void processField(
final Schema.Field innerField, final List completeFieldList, final boolean isAncestorRequired, final boolean isAncestor) {
if (checkIfRecord(innerField.schema())) {
processRecordFieldList(innerField.name(), ".", processFieldList(innerField.schema().getFields(), isAncestorRequired), completeFieldList);
@@ -353,8 +352,8 @@ private boolean checkIfRequiredField(final Schema innerSchema) {
return result;
}
- private Set extractSchemaNames(Schema schema) {
- Set schemaNames = new HashSet<>();
+ private Set extractSchemaNames(final Schema schema) {
+ final Set schemaNames = new HashSet<>();
if (checkIfRecord(schema)) {
schemaNames.add(schema.getName());
schema.getFields().forEach(field -> schemaNames.addAll(extractSchemaNames(field.schema())));
diff --git a/src/main/java/com/sngular/kloadgen/extractor/extractors/avro/AvroApicurioExtractor.java b/src/main/java/com/sngular/kloadgen/extractor/extractors/avro/AvroApicurioExtractor.java
index 411b7392..af440bf2 100644
--- a/src/main/java/com/sngular/kloadgen/extractor/extractors/avro/AvroApicurioExtractor.java
+++ b/src/main/java/com/sngular/kloadgen/extractor/extractors/avro/AvroApicurioExtractor.java
@@ -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;
diff --git a/src/main/java/com/sngular/kloadgen/processor/SchemaProcessor.java b/src/main/java/com/sngular/kloadgen/processor/SchemaProcessor.java
index 31848647..b5f44f6a 100644
--- a/src/main/java/com/sngular/kloadgen/processor/SchemaProcessor.java
+++ b/src/main/java/com/sngular/kloadgen/processor/SchemaProcessor.java
@@ -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;
@@ -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 {
diff --git a/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/ObjectCreatorFactoryHelper.java b/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/ObjectCreatorFactoryHelper.java
index fa5722b6..380fba6c 100644
--- a/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/ObjectCreatorFactoryHelper.java
+++ b/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/ObjectCreatorFactoryHelper.java
@@ -1,6 +1,7 @@
package com.sngular.kloadgen.processor.objectcreatorfactory;
import java.io.IOException;
+
import com.google.protobuf.Descriptors.DescriptorValidationException;
import com.sngular.kloadgen.common.SchemaTypeEnum;
import com.sngular.kloadgen.exception.KLoadGenException;
@@ -19,19 +20,12 @@ private ObjectCreatorFactoryHelper() {}
public static ObjectCreatorFactory getInstance(final SchemaTypeEnum schemaType, final Object schema, final BaseSchemaMetadata extends SchemaMetadataAdapter> metadata) {
final ObjectCreatorFactory objectCreatorFactory;
try {
- switch (schemaType) {
- case JSON:
- objectCreatorFactory = new JsonObjectCreatorFactory();
- break;
- case AVRO:
- objectCreatorFactory = new AvroObjectCreatorFactory(schema, metadata);
- break;
- case PROTOBUF:
- objectCreatorFactory = new ProtobufObjectCreatorFactory(schema, metadata);
- break;
- default:
- throw new KLoadGenException("Unsupported schema type");
- }
+ objectCreatorFactory = switch (schemaType) {
+ case JSON -> new JsonObjectCreatorFactory();
+ case AVRO -> new AvroObjectCreatorFactory(schema, metadata);
+ case PROTOBUF -> new ProtobufObjectCreatorFactory(schema, metadata);
+ default -> throw new KLoadGenException("Unsupported schema type");
+ };
} catch (KLoadGenException | DescriptorValidationException | IOException e) {
final String logMsg = "Please, make sure that the schema sources fed are correct";
log.error(logMsg, e);
diff --git a/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/impl/AvroObjectCreatorFactory.java b/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/impl/AvroObjectCreatorFactory.java
index 303d51c0..c92f8344 100644
--- a/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/impl/AvroObjectCreatorFactory.java
+++ b/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/impl/AvroObjectCreatorFactory.java
@@ -11,16 +11,17 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
+
import com.sngular.kloadgen.exception.KLoadGenException;
import com.sngular.kloadgen.model.ConstraintTypeEnum;
import com.sngular.kloadgen.processor.model.SchemaProcessorPOJO;
import com.sngular.kloadgen.processor.objectcreatorfactory.ObjectCreatorFactory;
import com.sngular.kloadgen.processor.util.SchemaProcessorUtils;
import com.sngular.kloadgen.randomtool.generator.AvroGeneratorTool;
-import com.sngular.kloadgen.schemaregistry.adapter.impl.ApicurioParsedSchemaMetadata;
+import com.sngular.kloadgen.schemaregistry.adapter.impl.AbstractParsedSchemaAdapter;
+import com.sngular.kloadgen.schemaregistry.adapter.impl.ApicurioAbstractParsedSchemaMetadata;
import com.sngular.kloadgen.schemaregistry.adapter.impl.BaseParsedSchema;
import com.sngular.kloadgen.schemaregistry.adapter.impl.BaseSchemaMetadata;
-import com.sngular.kloadgen.schemaregistry.adapter.impl.ParsedSchemaAdapter;
import com.sngular.kloadgen.schemaregistry.adapter.impl.SchemaMetadataAdapter;
import com.sngular.kloadgen.serializer.EnrichedRecord;
import io.confluent.kafka.schemaregistry.ParsedSchema;
@@ -30,7 +31,7 @@
import org.apache.avro.generic.GenericRecord;
import org.apache.commons.collections4.IteratorUtils;
-public class AvroObjectCreatorFactory implements ObjectCreatorFactory {
+public final class AvroObjectCreatorFactory implements ObjectCreatorFactory {
private static final AvroGeneratorTool AVRO_GENERATOR_TOOL = new AvroGeneratorTool();
@@ -49,9 +50,9 @@ public AvroObjectCreatorFactory(final Object schema, final BaseSchemaMetadata
this.schema = (Schema) schema;
} else if (schema instanceof BaseParsedSchema) {
final BaseParsedSchema schemaParse = (BaseParsedSchema) schema;
- final ParsedSchemaAdapter adapterParse = schemaParse.getParsedSchemaAdapter();
- if (adapterParse instanceof ApicurioParsedSchemaMetadata) {
- this.schema = (Schema) ((ApicurioParsedSchemaMetadata) adapterParse).getSchema();
+ final AbstractParsedSchemaAdapter adapterParse = schemaParse.getParsedSchemaAdapter();
+ if (adapterParse instanceof ApicurioAbstractParsedSchemaMetadata) {
+ this.schema = (Schema) ((ApicurioAbstractParsedSchemaMetadata) adapterParse).getSchema();
} else {
this.schema = adapterParse.getRawSchema();
}
@@ -63,7 +64,7 @@ public AvroObjectCreatorFactory(final Object schema, final BaseSchemaMetadata
}
@Override
- public final Object createMap(final SchemaProcessorPOJO pojo, final Function generateFunction, final boolean isInnerMap) {
+ public Object createMap(final SchemaProcessorPOJO pojo, final Function generateFunction, final boolean isInnerMap) {
Map