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 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 generateFunction, final boolean isInnerMap) { + public Object createMap(final SchemaProcessorPOJO pojo, final Function generateFunction, final boolean isInnerMap) { Map map = new HashMap<>(); if (pojo.isLastFilterTypeOfLastElement()) { @@ -92,7 +93,7 @@ private String generateString(final Integer valueLength) { } @Override - public final Object createArray(final SchemaProcessorPOJO pojo, final Function generateFunction, final boolean isInnerArray) { + public Object createArray(final SchemaProcessorPOJO pojo, final Function generateFunction, final boolean isInnerArray) { List list = new ArrayList<>(); if (pojo.isLastFilterTypeOfLastElement()) { @@ -111,7 +112,7 @@ public final Object createArray(final SchemaProcessorPOJO pojo, final Function createFinalArray(final SchemaProcessorPOJO pojo) { pojo.getFieldValuesList(), pojo.getFieldSize(), Collections.emptyMap()); } - public final Object assignObject(final String targetObjectName, final String fieldName, final Object objectToAssign) { + public Object assignObject(final String targetObjectName, final String fieldName, final Object objectToAssign) { final GenericRecord entityObject = entity.get(targetObjectName); entityObject.put(fieldName, objectToAssign); return entityObject; diff --git a/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/impl/ProtobufObjectCreatorFactory.java b/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/impl/ProtobufObjectCreatorFactory.java index 892c4673..abab03c3 100644 --- a/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/impl/ProtobufObjectCreatorFactory.java +++ b/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/impl/ProtobufObjectCreatorFactory.java @@ -10,6 +10,7 @@ import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; + import com.google.protobuf.Descriptors; import com.google.protobuf.Descriptors.Descriptor; import com.google.protobuf.Descriptors.DescriptorValidationException; @@ -23,9 +24,9 @@ import com.sngular.kloadgen.processor.objectcreatorfactory.ObjectCreatorFactory; import com.sngular.kloadgen.processor.util.SchemaProcessorUtils; import com.sngular.kloadgen.randomtool.generator.ProtoBufGeneratorTool; +import com.sngular.kloadgen.schemaregistry.adapter.impl.AbstractParsedSchemaAdapter; 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 com.squareup.wire.schema.internal.parser.ProtoFileElement; @@ -49,7 +50,7 @@ public ProtobufObjectCreatorFactory(final Object schema, final BaseSchemaMetadat this.schema = SchemaProcessorUtils.buildProtoDescriptor((ProtoFileElement) schema, metadata); } else if (schema instanceof BaseParsedSchema) { final BaseParsedSchema schemaParse = (BaseParsedSchema) schema; - final ParsedSchemaAdapter adapterParse = schemaParse.getParsedSchemaAdapter(); + final AbstractParsedSchemaAdapter adapterParse = schemaParse.getParsedSchemaAdapter(); final Object schemaParsed = adapterParse.getRawSchema(); this.schema = SchemaProcessorUtils.buildProtoDescriptor((ProtoFileElement) schemaParsed, metadata); } else { @@ -170,7 +171,7 @@ public final boolean isOptionalFieldAccordingToSchema(final String completeField } @Override - public Object getRootNode(final String rootNode) { + public final Object getRootNode(final String rootNode) { return entity.get(rootNode); } diff --git a/src/main/java/com/sngular/kloadgen/processor/util/SchemaProcessorUtils.java b/src/main/java/com/sngular/kloadgen/processor/util/SchemaProcessorUtils.java index af608b25..2a5e3d22 100644 --- a/src/main/java/com/sngular/kloadgen/processor/util/SchemaProcessorUtils.java +++ b/src/main/java/com/sngular/kloadgen/processor/util/SchemaProcessorUtils.java @@ -17,6 +17,7 @@ import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; + import com.github.os72.protobuf.dynamic.DynamicSchema; import com.github.os72.protobuf.dynamic.EnumDefinition; import com.github.os72.protobuf.dynamic.MessageDefinition; @@ -24,8 +25,8 @@ import com.google.protobuf.Descriptors; import com.google.protobuf.Descriptors.DescriptorValidationException; import com.sngular.kloadgen.model.FieldValueMapping; +import com.sngular.kloadgen.schemaregistry.adapter.impl.AbstractParsedSchemaAdapter; 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.util.JMeterHelper; import com.sngular.kloadgen.util.ProtobufHelper; @@ -167,8 +168,8 @@ public static Descriptors.Descriptor buildProtoDescriptor(final ProtoFileElement schemaBuilder.addSchema(importedSchema); } } else { - final ParsedSchemaAdapter protoFileElement = JMeterHelper.getParsedSchema(getSubjectName(importedClass, metadata), - JMeterContextService.getContext().getProperties()).getParsedSchemaAdapter(); + final AbstractParsedSchemaAdapter protoFileElement = JMeterHelper.getParsedSchema(getSubjectName(importedClass, metadata), + JMeterContextService.getContext().getProperties()).getParsedSchemaAdapter(); final var importedProtobufSchema = new ProtobufSchema(protoFileElement.getRawSchema(), metadata.getSchemaMetadataAdapter().getReferences(), new HashMap<>()); if (!ProtobufHelper.NOT_ACCEPTED_IMPORTS.contains(importedClass)) { schemaBuilder.addDependency(importedProtobufSchema.toDescriptor().getFullName()); @@ -381,8 +382,7 @@ private static void addDefinition( final MessageDefinition.Builder msgDef, final String typeName, final TypeElement typeElement, final HashMap>> globalNestedTypesByLevelAndMessage, final int deepLevel) { - if (typeElement instanceof EnumElement) { - final var enumElement = (EnumElement) typeElement; + if (typeElement instanceof final EnumElement enumElement) { final EnumDefinition.Builder builder = EnumDefinition.newBuilder(enumElement.getName()); for (final var constant : enumElement.getConstants()) { builder.addValue(constant.getName(), constant.getTag()); diff --git a/src/main/java/com/sngular/kloadgen/schemaregistry/SchemaRegistryManagerFactory.java b/src/main/java/com/sngular/kloadgen/schemaregistry/SchemaRegistryManagerFactory.java index cbdd0206..ddd75acf 100644 --- a/src/main/java/com/sngular/kloadgen/schemaregistry/SchemaRegistryManagerFactory.java +++ b/src/main/java/com/sngular/kloadgen/schemaregistry/SchemaRegistryManagerFactory.java @@ -2,9 +2,6 @@ import java.util.Map; -import static com.sngular.kloadgen.common.SchemaRegistryEnum.APICURIO; -import static com.sngular.kloadgen.common.SchemaRegistryEnum.CONFLUENT; - import com.sngular.kloadgen.common.SchemaRegistryEnum; import com.sngular.kloadgen.exception.KLoadGenException; import com.sngular.kloadgen.schemaregistry.impl.ApicurioSchemaRegistry; @@ -14,12 +11,16 @@ @Slf4j public class SchemaRegistryManagerFactory { - static Map schemaRegistryMap = Map.of(CONFLUENT, new ConfluentSchemaRegistry(), APICURIO, new ApicurioSchemaRegistry()); + private static final Map SCHEMA_REGISTRY_MAP = + Map.of(SchemaRegistryEnum.CONFLUENT, new ConfluentSchemaRegistry(), SchemaRegistryEnum.APICURIO, new ApicurioSchemaRegistry()); + + protected SchemaRegistryManagerFactory() { + } - public static SchemaRegistryAdapter getSchemaRegistry(String registry) { + public static SchemaRegistryAdapter getSchemaRegistry(final String registry) { try { - SchemaRegistryEnum schemaRegistryEnum = SchemaRegistryEnum.valueOf(registry.toUpperCase()); - return schemaRegistryMap.get(schemaRegistryEnum); + final SchemaRegistryEnum schemaRegistryEnum = SchemaRegistryEnum.valueOf(registry.toUpperCase()); + return SCHEMA_REGISTRY_MAP.get(schemaRegistryEnum); } catch (final IllegalArgumentException e) { final String logMsg = "Can not parse the registry " + registry; log.error(logMsg, e); diff --git a/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/AbstractParsedSchemaAdapter.java b/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/AbstractParsedSchemaAdapter.java new file mode 100644 index 00000000..527f6ee4 --- /dev/null +++ b/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/AbstractParsedSchemaAdapter.java @@ -0,0 +1,8 @@ +package com.sngular.kloadgen.schemaregistry.adapter.impl; + +public abstract class AbstractParsedSchemaAdapter { + + public abstract T getType(); + + public abstract T getRawSchema(); +} diff --git a/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/ApicurioParsedSchemaMetadata.java b/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/ApicurioAbstractParsedSchemaMetadata.java similarity index 58% rename from src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/ApicurioParsedSchemaMetadata.java rename to src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/ApicurioAbstractParsedSchemaMetadata.java index 72ef8f66..f18cdb15 100644 --- a/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/ApicurioParsedSchemaMetadata.java +++ b/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/ApicurioAbstractParsedSchemaMetadata.java @@ -8,7 +8,7 @@ @Getter @Setter @NoArgsConstructor -public class ApicurioParsedSchemaMetadata extends ParsedSchemaAdapter { +public class ApicurioAbstractParsedSchemaMetadata extends AbstractParsedSchemaAdapter { private Object schema; @@ -16,12 +16,13 @@ public class ApicurioParsedSchemaMetadata extends ParsedSchemaAdapter { private String type; - public ApicurioParsedSchemaMetadata(ParsedSchema parsedSchema){ + public ApicurioAbstractParsedSchemaMetadata(final ParsedSchema parsedSchema) { this.rawSchema = parsedSchema.canonicalString(); this.type = parsedSchema.schemaType(); this.schema = parsedSchema.rawSchema(); } - public static ParsedSchemaAdapter parse(final ParsedSchema parsedSchema) { - return new ApicurioParsedSchemaMetadata(parsedSchema); + + public static AbstractParsedSchemaAdapter parse(final ParsedSchema parsedSchema) { + return new ApicurioAbstractParsedSchemaMetadata(parsedSchema); } } diff --git a/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/BaseParsedSchema.java b/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/BaseParsedSchema.java index 55df89e6..407c1339 100644 --- a/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/BaseParsedSchema.java +++ b/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/BaseParsedSchema.java @@ -2,7 +2,7 @@ import org.apache.avro.Schema.Parser; -public class BaseParsedSchema extends Parser { +public class BaseParsedSchema extends Parser { private final T parsedSchemaAdapter; @@ -10,7 +10,7 @@ public BaseParsedSchema(final T parsedSchemaAdapter) { this.parsedSchemaAdapter = parsedSchemaAdapter; } - public T getParsedSchemaAdapter(){ + public final T getParsedSchemaAdapter() { return parsedSchemaAdapter; } } diff --git a/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/ConfluentParsedSchemaMetadata.java b/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/ConfluentAbstractParsedSchemaMetadata.java similarity index 53% rename from src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/ConfluentParsedSchemaMetadata.java rename to src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/ConfluentAbstractParsedSchemaMetadata.java index a24ea866..42e1f5e3 100644 --- a/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/ConfluentParsedSchemaMetadata.java +++ b/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/ConfluentAbstractParsedSchemaMetadata.java @@ -6,7 +6,7 @@ import org.apache.avro.Schema; @Getter -public class ConfluentParsedSchemaMetadata extends ParsedSchemaAdapter { +public final class ConfluentAbstractParsedSchemaMetadata extends AbstractParsedSchemaAdapter { private String schemaType; @@ -14,40 +14,41 @@ public class ConfluentParsedSchemaMetadata extends ParsedSchemaAdapter { private String canonicalString; - private Object rawSchema; + private Object rawSchema; - private ConfluentParsedSchemaMetadata(ParsedSchema parsedSchema){ + private ConfluentAbstractParsedSchemaMetadata(final ParsedSchema parsedSchema) { this.schemaType = parsedSchema.schemaType(); this.name = parsedSchema.name(); this.canonicalString = parsedSchema.canonicalString(); this.rawSchema = parsedSchema.rawSchema(); } - private ConfluentParsedSchemaMetadata(Schema schema){ + private ConfluentAbstractParsedSchemaMetadata(final Schema schema) { this.schemaType = schema.getType().getName(); this.name = schema.getName(); } - public ConfluentParsedSchemaMetadata(ProtobufSchema schema){ + public ConfluentAbstractParsedSchemaMetadata(final ProtobufSchema schema) { this.schemaType = schema.schemaType(); this.name = schema.name(); this.rawSchema = schema.rawSchema(); this.canonicalString = schema.canonicalString(); } - public ConfluentParsedSchemaMetadata() { + public ConfluentAbstractParsedSchemaMetadata() { } - public static ParsedSchemaAdapter parse(final ParsedSchema parsedSchema) { - return new ConfluentParsedSchemaMetadata(parsedSchema); + public static AbstractParsedSchemaAdapter parse(final ParsedSchema parsedSchema) { + return new ConfluentAbstractParsedSchemaMetadata(parsedSchema); } - public static ParsedSchemaAdapter parse(final Schema schema) { - return new ConfluentParsedSchemaMetadata(schema); + public static AbstractParsedSchemaAdapter parse(final Schema schema) { + return new ConfluentAbstractParsedSchemaMetadata(schema); } - public static ParsedSchemaAdapter parse (final ProtobufSchema schema){ - return new ConfluentParsedSchemaMetadata(schema); + + public static AbstractParsedSchemaAdapter parse(final ProtobufSchema schema) { + return new ConfluentAbstractParsedSchemaMetadata(schema); } @Override diff --git a/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/GenericSchemaRegistry.java b/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/GenericSchemaRegistry.java index 2ad7c68b..b8bbaca5 100644 --- a/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/GenericSchemaRegistry.java +++ b/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/GenericSchemaRegistry.java @@ -11,9 +11,10 @@ @Setter @AllArgsConstructor @NoArgsConstructor -public class GenericSchemaRegistry{ +public class GenericSchemaRegistry { private GenericSchemaRegistryAdapter genericSchemaRegistryAdapter; + private T id; private T version; diff --git a/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/GenericSchemaRegistryAdapter.java b/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/GenericSchemaRegistryAdapter.java index b1ef073a..c04b8c6d 100644 --- a/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/GenericSchemaRegistryAdapter.java +++ b/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/GenericSchemaRegistryAdapter.java @@ -1,11 +1,12 @@ package com.sngular.kloadgen.schemaregistry.adapter.impl; -public interface GenericSchemaRegistryAdapter { - T getId(); +public interface GenericSchemaRegistryAdapter { - T getVersion(); + T getId(); - U getSchemaType(); + T getVersion(); + + U getSchemaType(); } diff --git a/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/ParsedSchemaAdapter.java b/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/ParsedSchemaAdapter.java deleted file mode 100644 index 2d1848b9..00000000 --- a/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/ParsedSchemaAdapter.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.sngular.kloadgen.schemaregistry.adapter.impl; - -public abstract class ParsedSchemaAdapter { - public abstract T getType(); - - public abstract T getRawSchema(); -} diff --git a/src/main/java/com/sngular/kloadgen/schemaregistry/impl/ApicurioSchemaRegistry.java b/src/main/java/com/sngular/kloadgen/schemaregistry/impl/ApicurioSchemaRegistry.java index b0797090..ad990e80 100644 --- a/src/main/java/com/sngular/kloadgen/schemaregistry/impl/ApicurioSchemaRegistry.java +++ b/src/main/java/com/sngular/kloadgen/schemaregistry/impl/ApicurioSchemaRegistry.java @@ -8,17 +8,16 @@ import java.util.List; import java.util.Map; import java.util.Objects; + import com.google.protobuf.Message; import com.sngular.kloadgen.common.SchemaTypeEnum; import com.sngular.kloadgen.exception.KLoadGenException; import com.sngular.kloadgen.schemaregistry.SchemaRegistryAdapter; -import com.sngular.kloadgen.schemaregistry.SchemaRegistryConstants; -import com.sngular.kloadgen.schemaregistry.adapter.impl.ApicurioParsedSchemaMetadata; +import com.sngular.kloadgen.schemaregistry.adapter.impl.ApicurioAbstractParsedSchemaMetadata; import com.sngular.kloadgen.schemaregistry.adapter.impl.ApicurioSchemaMetadata; import com.sngular.kloadgen.schemaregistry.adapter.impl.BaseParsedSchema; import com.sngular.kloadgen.schemaregistry.adapter.impl.BaseSchemaMetadata; import com.sngular.kloadgen.schemaregistry.adapter.impl.SchemaMetadataAdapter; -import com.sngular.kloadgen.util.SchemaRegistryKeyHelper; import io.apicurio.registry.resolver.SchemaParser; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.RegistryClientFactory; @@ -36,30 +35,25 @@ public final class ApicurioSchemaRegistry implements SchemaRegistryAdapter { - private static final Map propertiesMap = Map.of(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME, SchemaRegistryConstants.SCHEMA_REGISTRY_APICURIO, - SchemaRegistryKeyHelper.SCHEMA_REGISTRY_URL_KEY, SerdeConfig.REGISTRY_URL); - private RegistryClient schemaRegistryClient; - private ApicurioParsedSchemaMetadata apicurioParsedSchemaMetadata; - - public final String getSchemaRegistryUrlKey() { + public String getSchemaRegistryUrlKey() { return SerdeConfig.REGISTRY_URL; } @Override - public final void setSchemaRegistryClient(final String url, final Map properties) { + public void setSchemaRegistryClient(final String url, final Map properties) { this.schemaRegistryClient = RegistryClientFactory.create(url); } @Override - public final void setSchemaRegistryClient(final Map properties) { + public void setSchemaRegistryClient(final Map properties) { final String url = Objects.toString(properties.get(this.getSchemaRegistryUrlKey()), ""); this.schemaRegistryClient = RegistryClientFactory.create(url); } @Override - public final Collection getAllSubjects() throws KLoadGenException { + public Collection getAllSubjects() throws KLoadGenException { final Collection subjects = new ArrayList<>(); try { final List artifacts = this.schemaRegistryClient.searchArtifacts(null, null, null, @@ -75,7 +69,7 @@ public final Collection getAllSubjects() throws KLoadGenException { } @Override - public final BaseSchemaMetadata getLatestSchemaMetadata(final String artifactId) throws KLoadGenException { + public BaseSchemaMetadata getLatestSchemaMetadata(final String artifactId) throws KLoadGenException { try { final SearchedArtifact searchedArtifact = getLastestSearchedArtifact(artifactId); final ArtifactMetaData artifactMetaData = this.schemaRegistryClient.getArtifactMetaData(searchedArtifact.getGroupId(), searchedArtifact.getId()); @@ -86,8 +80,8 @@ public final BaseSchemaMetadata getLatestSchemaMetadata( } @Override - public final BaseParsedSchema getSchemaBySubject(final String artifactId) { - final ApicurioParsedSchemaMetadata schema = new ApicurioParsedSchemaMetadata(); + public BaseParsedSchema getSchemaBySubject(final String artifactId) { + final ApicurioAbstractParsedSchemaMetadata schema = new ApicurioAbstractParsedSchemaMetadata(); try { final SearchedArtifact searchedArtifact = getLastestSearchedArtifact(artifactId); final InputStream inputStream = this.schemaRegistryClient.getLatestArtifact(searchedArtifact.getGroupId(), searchedArtifact.getId()); @@ -100,7 +94,7 @@ public final BaseParsedSchema getSchemaBySubject(f } } - private static void setSchemaBySchemaType(final ApicurioParsedSchemaMetadata schema, final byte[] result, final String searchedArtifactType) { + private static void setSchemaBySchemaType(final ApicurioAbstractParsedSchemaMetadata schema, final byte[] result, final String searchedArtifactType) { switch (SchemaTypeEnum.valueOf(searchedArtifactType)) { case AVRO: @@ -122,9 +116,9 @@ private static void setSchemaBySchemaType(final ApicurioParsedSchemaMetadata sch } @Override - public final BaseParsedSchema getSchemaBySubjectAndId( + public final BaseParsedSchema getSchemaBySubjectAndId( final String subjectName, final BaseSchemaMetadata metadata) { - final ApicurioParsedSchemaMetadata schema = new ApicurioParsedSchemaMetadata(); + final ApicurioAbstractParsedSchemaMetadata schema = new ApicurioAbstractParsedSchemaMetadata(); final SchemaMetadataAdapter schemaMetadataAdapter = metadata.getSchemaMetadataAdapter(); try { diff --git a/src/main/java/com/sngular/kloadgen/schemaregistry/impl/ConfluentSchemaRegistry.java b/src/main/java/com/sngular/kloadgen/schemaregistry/impl/ConfluentSchemaRegistry.java index c516ec84..1f112843 100644 --- a/src/main/java/com/sngular/kloadgen/schemaregistry/impl/ConfluentSchemaRegistry.java +++ b/src/main/java/com/sngular/kloadgen/schemaregistry/impl/ConfluentSchemaRegistry.java @@ -5,16 +5,15 @@ import java.util.Collection; import java.util.List; import java.util.Map; + import com.sngular.kloadgen.exception.KLoadGenException; import com.sngular.kloadgen.schemaregistry.SchemaRegistryAdapter; -import com.sngular.kloadgen.schemaregistry.SchemaRegistryConstants; +import com.sngular.kloadgen.schemaregistry.adapter.impl.AbstractParsedSchemaAdapter; import com.sngular.kloadgen.schemaregistry.adapter.impl.BaseParsedSchema; import com.sngular.kloadgen.schemaregistry.adapter.impl.BaseSchemaMetadata; -import com.sngular.kloadgen.schemaregistry.adapter.impl.ConfluentParsedSchemaMetadata; +import com.sngular.kloadgen.schemaregistry.adapter.impl.ConfluentAbstractParsedSchemaMetadata; import com.sngular.kloadgen.schemaregistry.adapter.impl.ConfluentSchemaMetadata; -import com.sngular.kloadgen.schemaregistry.adapter.impl.ParsedSchemaAdapter; import com.sngular.kloadgen.schemaregistry.adapter.impl.SchemaMetadataAdapter; -import com.sngular.kloadgen.util.SchemaRegistryKeyHelper; import io.confluent.kafka.schemaregistry.ParsedSchema; import io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider; import io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient; @@ -23,21 +22,15 @@ import io.confluent.kafka.schemaregistry.json.JsonSchemaProvider; import io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider; import io.confluent.kafka.serializers.AbstractKafkaSchemaSerDeConfig; +import lombok.extern.slf4j.Slf4j; import org.apache.jmeter.threads.JMeterContextService; -public class ConfluentSchemaRegistry implements SchemaRegistryAdapter { +@Slf4j +public final class ConfluentSchemaRegistry implements SchemaRegistryAdapter { private SchemaRegistryClient schemaRegistryClient; - private Map propertiesMap; - public ConfluentSchemaRegistry() { - this.propertiesMap = Map.of(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME, SchemaRegistryConstants.SCHEMA_REGISTRY_CONFLUENT, - SchemaRegistryKeyHelper.SCHEMA_REGISTRY_URL_KEY, AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, - SchemaRegistryConstants.BASIC_AUTH_CREDENTIALS, AbstractKafkaSchemaSerDeConfig.BASIC_AUTH_CREDENTIALS_SOURCE, - SchemaRegistryConstants.USER_INFO_CONFIG, AbstractKafkaSchemaSerDeConfig.USER_INFO_CONFIG, - SchemaRegistryConstants.BEARER_AUTH_CREDENTIALS, AbstractKafkaSchemaSerDeConfig.BEARER_AUTH_CREDENTIALS_SOURCE, - SchemaRegistryConstants.BEARER_AUTH_TOKEN_CONFIG, AbstractKafkaSchemaSerDeConfig.BEARER_AUTH_TOKEN_CONFIG); } @Override @@ -47,12 +40,14 @@ public String getSchemaRegistryUrlKey() { @Override public void setSchemaRegistryClient(final String url, final Map properties) { + log.debug("CREATEION"); this.schemaRegistryClient = new CachedSchemaRegistryClient(List.of(checkPropertyOrVariable(url)), 1000, List.of(new AvroSchemaProvider(), new JsonSchemaProvider(), new ProtobufSchemaProvider()), properties); } @Override public void setSchemaRegistryClient(final Map properties) { + log.debug("CREATITIN"); final String url = properties.get(this.getSchemaRegistryUrlKey()).toString(); this.schemaRegistryClient = new CachedSchemaRegistryClient(List.of(checkPropertyOrVariable(url)), 1000, List.of(new AvroSchemaProvider(), new JsonSchemaProvider(), new ProtobufSchemaProvider()), properties); @@ -78,22 +73,23 @@ public BaseSchemaMetadata getLatestSchemaMetadata(final } } - public BaseParsedSchema getSchemaBySubject(final String subjectName) { + public BaseParsedSchema getSchemaBySubject(final String subjectName) { try { final ConfluentSchemaMetadata schemaMetadata = ConfluentSchemaMetadata.parse(this.schemaRegistryClient.getLatestSchemaMetadata(subjectName)); final ParsedSchema parsedSchema = this.schemaRegistryClient.getSchemaBySubjectAndId(subjectName, schemaMetadata.getId()); - final ParsedSchemaAdapter parsedSchemaAdapter = ConfluentParsedSchemaMetadata.parse(parsedSchema); - return new BaseParsedSchema(parsedSchemaAdapter); + final AbstractParsedSchemaAdapter abstractParsedSchemaAdapter = ConfluentAbstractParsedSchemaMetadata.parse(parsedSchema); + return new BaseParsedSchema(abstractParsedSchemaAdapter); } catch (RestClientException | IOException e) { throw new KLoadGenException(e.getMessage()); } } - public BaseParsedSchema getSchemaBySubjectAndId(final String subjectName, BaseSchemaMetadata metadata) { + public BaseParsedSchema getSchemaBySubjectAndId(final String subjectName, + final BaseSchemaMetadata metadata) { try { final ParsedSchema parsedSchema = this.schemaRegistryClient.getSchemaBySubjectAndId(subjectName, metadata.getSchemaMetadataAdapter().getId()); - final ParsedSchemaAdapter parsedSchemaAdapter = ConfluentParsedSchemaMetadata.parse(parsedSchema); - return new BaseParsedSchema(parsedSchemaAdapter); + final AbstractParsedSchemaAdapter abstractParsedSchemaAdapter = ConfluentAbstractParsedSchemaMetadata.parse(parsedSchema); + return new BaseParsedSchema(abstractParsedSchemaAdapter); } catch (RestClientException | IOException e) { throw new KLoadGenException(e.getMessage()); } diff --git a/src/main/java/com/sngular/kloadgen/util/JMeterHelper.java b/src/main/java/com/sngular/kloadgen/util/JMeterHelper.java index 444f3186..ba029b23 100644 --- a/src/main/java/com/sngular/kloadgen/util/JMeterHelper.java +++ b/src/main/java/com/sngular/kloadgen/util/JMeterHelper.java @@ -7,14 +7,17 @@ package com.sngular.kloadgen.util; import java.util.Properties; + import com.sngular.kloadgen.exception.KLoadGenException; import com.sngular.kloadgen.schemaregistry.SchemaRegistryAdapter; import com.sngular.kloadgen.schemaregistry.SchemaRegistryManagerFactory; import com.sngular.kloadgen.schemaregistry.adapter.impl.BaseParsedSchema; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.threads.JMeterContextService; @SuppressWarnings("checkstyle:AbbreviationAsWordInName") +@Slf4j public final class JMeterHelper { private JMeterHelper() { diff --git a/src/test/java/com/sngular/kloadgen/extractor/SchemaExtractorTest.java b/src/test/java/com/sngular/kloadgen/extractor/SchemaExtractorTest.java index 1baabf55..9f62af25 100644 --- a/src/test/java/com/sngular/kloadgen/extractor/SchemaExtractorTest.java +++ b/src/test/java/com/sngular/kloadgen/extractor/SchemaExtractorTest.java @@ -13,9 +13,9 @@ import com.sngular.kloadgen.common.SchemaRegistryEnum; import com.sngular.kloadgen.exception.KLoadGenException; -import com.sngular.kloadgen.schemaregistry.adapter.impl.ApicurioParsedSchemaMetadata; +import com.sngular.kloadgen.schemaregistry.adapter.impl.ApicurioAbstractParsedSchemaMetadata; import com.sngular.kloadgen.schemaregistry.adapter.impl.BaseParsedSchema; -import com.sngular.kloadgen.schemaregistry.adapter.impl.ConfluentParsedSchemaMetadata; +import com.sngular.kloadgen.schemaregistry.adapter.impl.ConfluentAbstractParsedSchemaMetadata; import com.sngular.kloadgen.testutil.FileHelper; import com.sngular.kloadgen.testutil.ParsedSchemaUtil; import com.sngular.kloadgen.testutil.SchemaParseUtil; @@ -75,7 +75,7 @@ void testFlatPropertiesListWithAVRO() throws IOException { properties.setProperty(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME, SchemaRegistryEnum.APICURIO.toString()); final ParsedSchema parsedSchema = SchemaParseUtil.getParsedSchema(testFile, "AVRO"); - final var baseParsedSchema = new BaseParsedSchema<>(ApicurioParsedSchemaMetadata.parse(parsedSchema)); + final var baseParsedSchema = new BaseParsedSchema<>(ApicurioAbstractParsedSchemaMetadata.parse(parsedSchema)); jmeterHelperMockedStatic.when(() -> JMeterHelper.getParsedSchema(Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(baseParsedSchema); jmeterContextServiceMockedStatic.when(() -> JMeterContextService.getContext().getProperties()).thenReturn(properties); final var result = SchemaExtractor.flatPropertiesList("avroSubject"); @@ -91,7 +91,7 @@ void testFlatPropertiesListWithJson() throws IOException { properties.setProperty(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME, SchemaRegistryEnum.CONFLUENT.toString()); final var parsedSchema = SchemaParseUtil.getParsedSchema(testFile, "JSON"); - final var baseParsedSchema = new BaseParsedSchema<>(ConfluentParsedSchemaMetadata.parse(parsedSchema)); + final var baseParsedSchema = new BaseParsedSchema<>(ConfluentAbstractParsedSchemaMetadata.parse(parsedSchema)); jmeterContextServiceMockedStatic.when(() -> JMeterContextService.getContext().getProperties()).thenReturn(properties); jmeterHelperMockedStatic.when(() -> JMeterHelper.getParsedSchema(Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(baseParsedSchema); final var result = SchemaExtractor.flatPropertiesList("jsonSubject"); @@ -107,7 +107,7 @@ void testFlatPropertiesListWithProtobuf() throws IOException { properties.setProperty(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME, SchemaRegistryEnum.CONFLUENT.toString()); final var parsedSchema = SchemaParseUtil.getParsedSchema(testFile, "PROTOBUF"); - final var baseParsedSchema = new BaseParsedSchema<>(ConfluentParsedSchemaMetadata.parse(parsedSchema)); + final var baseParsedSchema = new BaseParsedSchema<>(ConfluentAbstractParsedSchemaMetadata.parse(parsedSchema)); jmeterContextServiceMockedStatic.when(() -> JMeterContextService.getContext().getProperties()).thenReturn(properties); jmeterHelperMockedStatic.when(() -> JMeterHelper.getParsedSchema(Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(baseParsedSchema); final var result = SchemaExtractor.flatPropertiesList("protobufSubject"); @@ -119,7 +119,7 @@ void testFlatPropertiesListWithProtobuf() throws IOException { void testFlatPropertiesListWithException() { final var parsedSchema = new ParsedSchemaUtil(); - final var baseParsedSchema = new BaseParsedSchema<>(ConfluentParsedSchemaMetadata.parse(parsedSchema)); + final var baseParsedSchema = new BaseParsedSchema<>(ConfluentAbstractParsedSchemaMetadata.parse(parsedSchema)); properties.setProperty(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME, SchemaRegistryEnum.CONFLUENT.toString()); jmeterContextServiceMockedStatic.when(() -> JMeterContextService.getContext().getProperties()).thenReturn(properties); diff --git a/src/test/java/com/sngular/kloadgen/processor/ProtobufSchemaProcessorTest.java b/src/test/java/com/sngular/kloadgen/processor/ProtobufSchemaProcessorTest.java index 4c6f3a37..40e1ba83 100644 --- a/src/test/java/com/sngular/kloadgen/processor/ProtobufSchemaProcessorTest.java +++ b/src/test/java/com/sngular/kloadgen/processor/ProtobufSchemaProcessorTest.java @@ -7,18 +7,22 @@ import java.util.List; import java.util.Locale; import java.util.Map; + import com.google.protobuf.Descriptors; -import com.google.protobuf.Descriptors.DescriptorValidationException; import com.google.protobuf.DynamicMessage; import com.sngular.kloadgen.common.SchemaTypeEnum; import com.sngular.kloadgen.exception.KLoadGenException; import com.sngular.kloadgen.extractor.SchemaExtractor; import com.sngular.kloadgen.model.FieldValueMapping; +import com.sngular.kloadgen.schemaregistry.SchemaRegistryAdapter; +import com.sngular.kloadgen.schemaregistry.SchemaRegistryManagerFactory; import com.sngular.kloadgen.schemaregistry.adapter.impl.BaseSchemaMetadata; import com.sngular.kloadgen.schemaregistry.adapter.impl.ConfluentSchemaMetadata; import com.sngular.kloadgen.serializer.EnrichedRecord; import com.sngular.kloadgen.testutil.FileHelper; import com.sngular.kloadgen.testutil.SchemaParseUtil; +import com.sngular.kloadgen.util.SchemaRegistryKeyHelper; +import org.apache.commons.collections.MapUtils; import org.apache.jmeter.threads.JMeterContext; import org.apache.jmeter.threads.JMeterContextService; import org.apache.jmeter.threads.JMeterVariables; @@ -45,18 +49,20 @@ public void setUp() { final JMeterContext jmcx = JMeterContextService.getContext(); jmcx.setVariables(new JMeterVariables()); JMeterUtils.setLocale(Locale.ENGLISH); + JMeterContextService.getContext().getProperties().put(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME, "CONFLUENT"); + } @Test @DisplayName("Be able to process embedded schema") - void textEmbeddedTypeTestSchemaProcessor() throws KLoadGenException, IOException, DescriptorValidationException { + void textEmbeddedTypeTestSchemaProcessor() throws KLoadGenException, IOException { final File testFile = fileHelper.getFile("/proto-files/embeddedTypeTest.proto"); final List fieldValueMappingList = List.of( FieldValueMapping.builder().fieldName("phones.addressesPhone[1:].id[1]").fieldType("string-array").fieldValueList("Pablo").required(true).isAncestorRequired(true).build(), FieldValueMapping.builder().fieldName("phones.phoneType").fieldType("enum").fieldValueList("[MOBILE, HOME, WORK]").required(true).isAncestorRequired(true).build()); final SchemaProcessor protobufSchemaProcessor = new SchemaProcessor(); - protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, SchemaParseUtil.getParsedSchema(testFile,SchemaTypeEnum.PROTOBUF.name()), + protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, SchemaParseUtil.getParsedSchema(testFile, SchemaTypeEnum.PROTOBUF.name()), confluentBaseSchemaMetadata, fieldValueMappingList); final EnrichedRecord message = (EnrichedRecord) protobufSchemaProcessor.next(); final DynamicMessage genericRecord = (DynamicMessage) message.getGenericRecord(); @@ -83,14 +89,14 @@ private String getIdFieldForEmbeddedTypeTest(final List assertValues) { @Test @DisplayName("Be able to process complex types like StringValue or Int32Value and get values by default") - void testProtobufGoogleTypes() throws IOException, DescriptorValidationException { + void testProtobufGoogleTypes() throws IOException { final File testFile = fileHelper.getFile("/proto-files/googleTypesTest.proto"); final List fieldValueMappingList = List.of( FieldValueMapping.builder().fieldName("id").fieldType("Int32Value").required(true).isAncestorRequired(true).build(), FieldValueMapping.builder().fieldName("occurrence_id").fieldType("StringValue").fieldValueList("Isabel").required(true).isAncestorRequired(true).build(), FieldValueMapping.builder().fieldName("load_number").fieldType("Int32Value").required(true).isAncestorRequired(true).build()); final SchemaProcessor protobufSchemaProcessor = new SchemaProcessor(); - protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, SchemaParseUtil.getParsedSchema(testFile,SchemaTypeEnum.PROTOBUF.name()), + protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, SchemaParseUtil.getParsedSchema(testFile, SchemaTypeEnum.PROTOBUF.name()), confluentBaseSchemaMetadata, fieldValueMappingList); final EnrichedRecord message = (EnrichedRecord) protobufSchemaProcessor.next(); final DynamicMessage genericRecord = (DynamicMessage) message.getGenericRecord(); @@ -113,12 +119,12 @@ void testProtobufGoogleTypes() throws IOException, DescriptorValidationException @Test @DisplayName("Be able to process enum in the schema") - void testProtoBufEnumSchemaProcessor() throws IOException, DescriptorValidationException { + void testProtoBufEnumSchemaProcessor() throws IOException { final File testFile = fileHelper.getFile("/proto-files/enumTest.proto"); final List fieldValueMappingList = schemaExtractor.flatPropertiesList(SchemaParseUtil.getParsedSchema(testFile, "PROTOBUF")); fieldValueMappingList.get(0).setFieldValuesList("HOME, WORK"); final SchemaProcessor protobufSchemaProcessor = new SchemaProcessor(); - protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, SchemaParseUtil.getParsedSchema(testFile,SchemaTypeEnum.PROTOBUF.name()), + protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, SchemaParseUtil.getParsedSchema(testFile, SchemaTypeEnum.PROTOBUF.name()), confluentBaseSchemaMetadata, fieldValueMappingList); final EnrichedRecord message = (EnrichedRecord) protobufSchemaProcessor.next(); final DynamicMessage genericRecord = (DynamicMessage) message.getGenericRecord(); @@ -152,11 +158,11 @@ void testProtoBufEnumSchemaProcessor() throws IOException, DescriptorValidationE @Test @DisplayName("Be able to process easy schema") - void testProtoBufEasyTestProcessor() throws IOException, DescriptorValidationException { + void testProtoBufEasyTestProcessor() throws IOException { final File testFile = fileHelper.getFile("/proto-files/easyTest.proto"); final List fieldValueMappingList = schemaExtractor.flatPropertiesList(SchemaParseUtil.getParsedSchema(testFile, "PROTOBUF")); final SchemaProcessor protobufSchemaProcessor = new SchemaProcessor(); - protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, SchemaParseUtil.getParsedSchema(testFile,SchemaTypeEnum.PROTOBUF.name()), + protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, SchemaParseUtil.getParsedSchema(testFile, SchemaTypeEnum.PROTOBUF.name()), confluentBaseSchemaMetadata, fieldValueMappingList); final EnrichedRecord message = (EnrichedRecord) protobufSchemaProcessor.next(); final DynamicMessage genericRecord = (DynamicMessage) message.getGenericRecord(); @@ -182,12 +188,12 @@ void testProtoBufEasyTestProcessor() throws IOException, DescriptorValidationExc @Test @DisplayName("Be able to process oneOf fields") - void testProtoBufOneOfProcessor() throws IOException, DescriptorValidationException { + void testProtoBufOneOfProcessor() throws IOException { final File testFile = fileHelper.getFile("/proto-files/oneOfTest.proto"); final List fieldValueMappingList = schemaExtractor.flatPropertiesList(SchemaParseUtil.getParsedSchema(testFile, "PROTOBUF")); final SchemaProcessor protobufSchemaProcessor = new SchemaProcessor(); - protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, SchemaParseUtil.getParsedSchema(testFile,SchemaTypeEnum.PROTOBUF.name()), + protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, SchemaParseUtil.getParsedSchema(testFile, SchemaTypeEnum.PROTOBUF.name()), confluentBaseSchemaMetadata, fieldValueMappingList); final EnrichedRecord message = (EnrichedRecord) protobufSchemaProcessor.next(); final DynamicMessage genericRecord = (DynamicMessage) message.getGenericRecord(); @@ -213,7 +219,7 @@ void testProtoBufOneOfProcessor() throws IOException, DescriptorValidationExcept @Test @DisplayName("Be able to process map in schema") - void testProtoBufMapTestProcessor() throws IOException, DescriptorValidationException { + void testProtoBufMapTestProcessor() throws IOException { final File testFile = fileHelper.getFile("/proto-files/mapTest.proto"); final List fieldValueMappingList = Arrays.asList( FieldValueMapping.builder().fieldName("name[:]").fieldType("string-map").fieldValueList("Pablo").required(true).isAncestorRequired(true).build(), @@ -269,8 +275,11 @@ private Object getSubFieldForMapTestProcessor(final DynamicMessage dynamicMessag @Test @DisplayName("Be able to process complex schema") - void testProtoBufComplexTestProcessor() throws IOException, DescriptorValidationException { + void testProtoBufComplexTestProcessor() throws IOException { final File testFile = fileHelper.getFile("/proto-files/complexTest.proto"); + final SchemaRegistryAdapter schemaRegistryManager = SchemaRegistryManagerFactory.getSchemaRegistry("CONFLUENT"); + schemaRegistryManager.setSchemaRegistryClient("http://localhost:8080", MapUtils.EMPTY_MAP); + final List fieldValueMappingList = Arrays.asList( FieldValueMapping.builder().fieldName("phone_types[].phone").fieldType("long").required(true).isAncestorRequired(true).build(), FieldValueMapping.builder().fieldName("phone_types[].principal").fieldType("boolean").required(true).isAncestorRequired(true).build(), @@ -319,7 +328,7 @@ void testProtoBufComplexTestProcessor() throws IOException, DescriptorValidation @Test @DisplayName("Be able to process provided complex schema") - void testProtoBufProvidedComplexTestProcessor() throws IOException, DescriptorValidationException { + void testProtoBufProvidedComplexTestProcessor() throws IOException { final File testFile = fileHelper.getFile("/proto-files/providedTest.proto"); final List fieldValueMappingList = Arrays.asList( FieldValueMapping.builder().fieldName("id").fieldType("int").required(true).isAncestorRequired(true).build(), @@ -400,7 +409,7 @@ void testProtoBufProvidedComplexTestProcessor() throws IOException, DescriptorVa } @Test - void testFailing() throws IOException, DescriptorValidationException { + void testFailing() throws IOException { final File testFile = fileHelper.getFile("/proto-files/deveTest.proto"); final List fieldValueMappingList = Arrays.asList( FieldValueMapping.builder().fieldName("load_type").fieldType("string").required(true).isAncestorRequired(true).build(), @@ -462,7 +471,8 @@ void testFailing() throws IOException, DescriptorValidationException { ); final SchemaProcessor protobufSchemaProcessor = new SchemaProcessor(); - protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, SchemaParseUtil.getParsedSchema(testFile,SchemaTypeEnum.PROTOBUF.name()), confluentBaseSchemaMetadata, fieldValueMappingList); + protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, + SchemaParseUtil.getParsedSchema(testFile, SchemaTypeEnum.PROTOBUF.name()), confluentBaseSchemaMetadata, fieldValueMappingList); final EnrichedRecord message = (EnrichedRecord) protobufSchemaProcessor.next(); final DynamicMessage genericRecord = (DynamicMessage) message.getGenericRecord(); final List assertKeys = new ArrayList<>(); @@ -493,7 +503,8 @@ void testProtoBufProvidedWithNotNestedTypeProcessor() throws IOException { FieldValueMapping.builder().fieldName("customer_account.billing_party.address.address_line_one").fieldType("string").required(true).isAncestorRequired(true).build(), FieldValueMapping.builder().fieldName("customer_account.billing_party.address.address_line_two").fieldType("string").required(true).isAncestorRequired(true).build()); final SchemaProcessor protobufSchemaProcessor = new SchemaProcessor(); - protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, SchemaParseUtil.getParsedSchema(testFile,SchemaTypeEnum.PROTOBUF.name()), confluentBaseSchemaMetadata, fieldValueMappingList); + protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, + SchemaParseUtil.getParsedSchema(testFile, SchemaTypeEnum.PROTOBUF.name()), confluentBaseSchemaMetadata, fieldValueMappingList); final EnrichedRecord message = (EnrichedRecord) protobufSchemaProcessor.next(); final DynamicMessage genericRecord = (DynamicMessage) message.getGenericRecord(); final List assertKeys = new ArrayList<>(); @@ -519,14 +530,15 @@ void testProtoBufProvidedWithNotNestedTypeProcessor() throws IOException { @Test @DisplayName("Be able to process Date and TimeOfDay types") - void testDateTimeTypes() throws IOException, DescriptorValidationException { + void testDateTimeTypes() throws IOException { final File testFile = fileHelper.getFile("/proto-files/dateTimeTest.proto"); final List fieldValueMappingList = List.of( FieldValueMapping.builder().fieldName("incident_date").fieldType(".google.type.Date").fieldValueList("2022-05-30").required(true).isAncestorRequired(true).build(), FieldValueMapping.builder().fieldName("incident_time").fieldType(".google.type.TimeOfDay").fieldValueList("14:20:30-05:00").required(true).isAncestorRequired(true) .build()); final SchemaProcessor protobufSchemaProcessor = new SchemaProcessor(); - protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, SchemaParseUtil.getParsedSchema(testFile,SchemaTypeEnum.PROTOBUF.name()), confluentBaseSchemaMetadata, fieldValueMappingList); + protobufSchemaProcessor.processSchema(SchemaTypeEnum.PROTOBUF, + SchemaParseUtil.getParsedSchema(testFile, SchemaTypeEnum.PROTOBUF.name()), confluentBaseSchemaMetadata, fieldValueMappingList); final EnrichedRecord message = (EnrichedRecord) protobufSchemaProcessor.next(); final DynamicMessage genericRecord = (DynamicMessage) message.getGenericRecord(); final Map map = genericRecord.getAllFields(); diff --git a/src/test/java/com/sngular/kloadgen/serializer/ProtobufSerializerTest.java b/src/test/java/com/sngular/kloadgen/serializer/ProtobufSerializerTest.java index 2a55a409..79e16c1d 100644 --- a/src/test/java/com/sngular/kloadgen/serializer/ProtobufSerializerTest.java +++ b/src/test/java/com/sngular/kloadgen/serializer/ProtobufSerializerTest.java @@ -3,30 +3,23 @@ import java.io.File; import java.io.IOException; import java.util.List; +import java.util.Locale; import java.util.stream.Stream; import java.util.stream.Stream.Builder; -import static com.sngular.kloadgen.serializer.ProtobuffSerializerTestFixture.TEST_COMPLETE_PROTO; -import static com.sngular.kloadgen.serializer.ProtobuffSerializerTestFixture.TEST_COMPLEX; -import static com.sngular.kloadgen.serializer.ProtobuffSerializerTestFixture.TEST_DATE_TIME; -import static com.sngular.kloadgen.serializer.ProtobuffSerializerTestFixture.TEST_DEVE; -import static com.sngular.kloadgen.serializer.ProtobuffSerializerTestFixture.TEST_EASY; -import static com.sngular.kloadgen.serializer.ProtobuffSerializerTestFixture.TEST_EMBEDDED_TYPE; -import static com.sngular.kloadgen.serializer.ProtobuffSerializerTestFixture.TEST_ENUM; -import static com.sngular.kloadgen.serializer.ProtobuffSerializerTestFixture.TEST_GOOGLE_TYPES; -import static com.sngular.kloadgen.serializer.ProtobuffSerializerTestFixture.TEST_ISSUE_311; -import static com.sngular.kloadgen.serializer.ProtobuffSerializerTestFixture.TEST_MAP; -import static com.sngular.kloadgen.serializer.ProtobuffSerializerTestFixture.TEST_ONE_OF; -import static com.sngular.kloadgen.serializer.ProtobuffSerializerTestFixture.TEST_PROVIDED; - import com.sngular.kloadgen.common.SchemaTypeEnum; import com.sngular.kloadgen.model.FieldValueMapping; import com.sngular.kloadgen.processor.SchemaProcessor; import com.sngular.kloadgen.schemaregistry.adapter.impl.BaseSchemaMetadata; import com.sngular.kloadgen.schemaregistry.adapter.impl.ConfluentSchemaMetadata; import com.sngular.kloadgen.testutil.SchemaParseUtil; +import com.sngular.kloadgen.util.SchemaRegistryKeyHelper; import io.confluent.kafka.schemaregistry.ParsedSchema; import lombok.extern.slf4j.Slf4j; +import org.apache.jmeter.threads.JMeterContext; +import org.apache.jmeter.threads.JMeterContextService; +import org.apache.jmeter.threads.JMeterVariables; +import org.apache.jmeter.util.JMeterUtils; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Named; @@ -42,42 +35,49 @@ class ProtobufSerializerTest { @BeforeEach void setUp() { protobufSerializer = new ProtobufSerializer(); + final File file = new File("src/test/resources"); + final String absolutePath = file.getAbsolutePath(); + JMeterUtils.loadJMeterProperties(absolutePath + "/kloadgen.properties"); + final JMeterContext jmcx = JMeterContextService.getContext(); + jmcx.setVariables(new JMeterVariables()); + JMeterUtils.setLocale(Locale.ENGLISH); + JMeterContextService.getContext().getProperties().put(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME, "CONFLUENT"); } private static Stream getSchemaToTest() { - Builder builder = Stream.builder(); + final Builder builder = Stream.builder(); - File testCompleteProtoFile = TEST_COMPLETE_PROTO.getFirst(); - builder.add(Arguments.arguments(Named.of(testCompleteProtoFile.getName(), testCompleteProtoFile), TEST_COMPLETE_PROTO.getSecond())); - File testComplexFile = TEST_COMPLEX.getFirst(); - builder.add(Arguments.arguments(Named.of(testComplexFile.getName(), testComplexFile), TEST_COMPLEX.getSecond())); - File testDateTimeFile = TEST_DATE_TIME.getFirst(); - builder.add(Arguments.arguments(Named.of(testDateTimeFile.getName(), testDateTimeFile), TEST_DATE_TIME.getSecond())); - File testDeveFile = TEST_DEVE.getFirst(); - builder.add(Arguments.arguments(Named.of(testDeveFile.getName(), testDeveFile), TEST_DEVE.getSecond())); - File testEasyFile = TEST_EASY.getFirst(); - builder.add(Arguments.arguments(Named.of(testEasyFile.getName(), testEasyFile), TEST_EASY.getSecond())); - File testEmbeddedTypeFile = TEST_EMBEDDED_TYPE.getFirst(); - builder.add(Arguments.arguments(Named.of(testEmbeddedTypeFile.getName(), testEmbeddedTypeFile), TEST_EMBEDDED_TYPE.getSecond())); - File testEnumFile = TEST_ENUM.getFirst(); - builder.add(Arguments.arguments(Named.of(testEnumFile.getName(), testEnumFile), TEST_ENUM.getSecond())); - File testGoogleTypesFile = TEST_GOOGLE_TYPES.getFirst(); - builder.add(Arguments.arguments(Named.of(testGoogleTypesFile.getName(), testGoogleTypesFile), TEST_GOOGLE_TYPES.getSecond())); - File testIssue311File = TEST_ISSUE_311.getFirst(); - builder.add(Arguments.arguments(Named.of(testIssue311File.getName(), testIssue311File), TEST_ISSUE_311.getSecond())); - File testMapFile = TEST_MAP.getFirst(); - builder.add(Arguments.arguments(Named.of(testMapFile.getName(), testMapFile), TEST_MAP.getSecond())); - File testOneOfFile = TEST_ONE_OF.getFirst(); - builder.add(Arguments.arguments(Named.of(testOneOfFile.getName(), testOneOfFile), TEST_ONE_OF.getSecond())); - File testProvidedFile = TEST_PROVIDED.getFirst(); - builder.add(Arguments.arguments(Named.of(testProvidedFile.getName(), testProvidedFile), TEST_PROVIDED.getSecond())); + final File testCompleteProtoFile = ProtobuffSerializerTestFixture.TEST_COMPLETE_PROTO.getFirst(); + builder.add(Arguments.arguments(Named.of(testCompleteProtoFile.getName(), testCompleteProtoFile), ProtobuffSerializerTestFixture.TEST_COMPLETE_PROTO.getSecond())); + final File testComplexFile = ProtobuffSerializerTestFixture.TEST_COMPLEX.getFirst(); + builder.add(Arguments.arguments(Named.of(testComplexFile.getName(), testComplexFile), ProtobuffSerializerTestFixture.TEST_COMPLEX.getSecond())); + final File testDateTimeFile = ProtobuffSerializerTestFixture.TEST_DATE_TIME.getFirst(); + builder.add(Arguments.arguments(Named.of(testDateTimeFile.getName(), testDateTimeFile), ProtobuffSerializerTestFixture.TEST_DATE_TIME.getSecond())); + final File testDeveFile = ProtobuffSerializerTestFixture.TEST_DEVE.getFirst(); + builder.add(Arguments.arguments(Named.of(testDeveFile.getName(), testDeveFile), ProtobuffSerializerTestFixture.TEST_DEVE.getSecond())); + final File testEasyFile = ProtobuffSerializerTestFixture.TEST_EASY.getFirst(); + builder.add(Arguments.arguments(Named.of(testEasyFile.getName(), testEasyFile), ProtobuffSerializerTestFixture.TEST_EASY.getSecond())); + final File testEmbeddedTypeFile = ProtobuffSerializerTestFixture.TEST_EMBEDDED_TYPE.getFirst(); + builder.add(Arguments.arguments(Named.of(testEmbeddedTypeFile.getName(), testEmbeddedTypeFile), ProtobuffSerializerTestFixture.TEST_EMBEDDED_TYPE.getSecond())); + final File testEnumFile = ProtobuffSerializerTestFixture.TEST_ENUM.getFirst(); + builder.add(Arguments.arguments(Named.of(testEnumFile.getName(), testEnumFile), ProtobuffSerializerTestFixture.TEST_ENUM.getSecond())); + final File testGoogleTypesFile = ProtobuffSerializerTestFixture.TEST_GOOGLE_TYPES.getFirst(); + builder.add(Arguments.arguments(Named.of(testGoogleTypesFile.getName(), testGoogleTypesFile), ProtobuffSerializerTestFixture.TEST_GOOGLE_TYPES.getSecond())); + final File testIssue311File = ProtobuffSerializerTestFixture.TEST_ISSUE_311.getFirst(); + builder.add(Arguments.arguments(Named.of(testIssue311File.getName(), testIssue311File), ProtobuffSerializerTestFixture.TEST_ISSUE_311.getSecond())); + final File testMapFile = ProtobuffSerializerTestFixture.TEST_MAP.getFirst(); + builder.add(Arguments.arguments(Named.of(testMapFile.getName(), testMapFile), ProtobuffSerializerTestFixture.TEST_MAP.getSecond())); + final File testOneOfFile = ProtobuffSerializerTestFixture.TEST_ONE_OF.getFirst(); + builder.add(Arguments.arguments(Named.of(testOneOfFile.getName(), testOneOfFile), ProtobuffSerializerTestFixture.TEST_ONE_OF.getSecond())); + final File testProvidedFile = ProtobuffSerializerTestFixture.TEST_PROVIDED.getFirst(); + builder.add(Arguments.arguments(Named.of(testProvidedFile.getName(), testProvidedFile), ProtobuffSerializerTestFixture.TEST_PROVIDED.getSecond())); return builder.build(); } @ParameterizedTest @MethodSource("getSchemaToTest") - void serialize(File schemaFile, List fieldValueMappings) throws IOException { + void serialize(final File schemaFile, final List fieldValueMappings) throws IOException { final ParsedSchema parsedSchema = SchemaParseUtil.getParsedSchema(schemaFile, "Protobuf"); final SchemaProcessor protobufSchemaProcessor = new SchemaProcessor(); final BaseSchemaMetadata confluentBaseSchemaMetadata = diff --git a/src/test/resources/proto-files/complexTest.proto b/src/test/resources/proto-files/complexTest.proto index dea0058f..4c10d313 100644 --- a/src/test/resources/proto-files/complexTest.proto +++ b/src/test/resources/proto-files/complexTest.proto @@ -8,7 +8,6 @@ option java_outer_classname = "Protos"; import "google/protobuf/timestamp.proto"; import "google/protobuf/descriptor.proto"; -import "google/protobuf/compiler/plugin.proto"; message Test { repeated PhoneTypes phone_types = 1;