diff --git a/src/main/java/org/creekservice/kafka/test/perf/JsonSerdeBenchmark.java b/src/main/java/org/creekservice/kafka/test/perf/JsonSerdeBenchmark.java index d65cc67..e76e6ea 100644 --- a/src/main/java/org/creekservice/kafka/test/perf/JsonSerdeBenchmark.java +++ b/src/main/java/org/creekservice/kafka/test/perf/JsonSerdeBenchmark.java @@ -20,8 +20,18 @@ import java.nio.file.Path; import java.util.Map; - -import org.creekservice.kafka.test.perf.implementations.*; +import org.creekservice.kafka.test.perf.implementations.ConfluentImplementation; +import org.creekservice.kafka.test.perf.implementations.DevHarrelImplementation; +import org.creekservice.kafka.test.perf.implementations.EveritImplementation; +import org.creekservice.kafka.test.perf.implementations.Implementation; +import org.creekservice.kafka.test.perf.implementations.JacksonImplementation; +import org.creekservice.kafka.test.perf.implementations.JustifyImplementation; +import org.creekservice.kafka.test.perf.implementations.MedeiaImplementation; +import org.creekservice.kafka.test.perf.implementations.NetworkNtImplementation; +import org.creekservice.kafka.test.perf.implementations.SchemaFriendImplementation; +import org.creekservice.kafka.test.perf.implementations.SkemaImplementation; +import org.creekservice.kafka.test.perf.implementations.SnowImplementation; +import org.creekservice.kafka.test.perf.implementations.VertxImplementation; import org.creekservice.kafka.test.perf.model.ModelState; import org.creekservice.kafka.test.perf.model.TestModel; import org.creekservice.kafka.test.perf.testsuite.AdditionalSchemas; diff --git a/src/main/java/org/creekservice/kafka/test/perf/JsonValidateBenchmark.java b/src/main/java/org/creekservice/kafka/test/perf/JsonValidateBenchmark.java index 2a0d253..36b54c1 100644 --- a/src/main/java/org/creekservice/kafka/test/perf/JsonValidateBenchmark.java +++ b/src/main/java/org/creekservice/kafka/test/perf/JsonValidateBenchmark.java @@ -19,7 +19,16 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import org.creekservice.api.test.util.TestPaths; -import org.creekservice.kafka.test.perf.implementations.*; +import org.creekservice.kafka.test.perf.implementations.DevHarrelImplementation; +import org.creekservice.kafka.test.perf.implementations.EveritImplementation; +import org.creekservice.kafka.test.perf.implementations.Implementation; +import org.creekservice.kafka.test.perf.implementations.JustifyImplementation; +import org.creekservice.kafka.test.perf.implementations.MedeiaImplementation; +import org.creekservice.kafka.test.perf.implementations.NetworkNtImplementation; +import org.creekservice.kafka.test.perf.implementations.SchemaFriendImplementation; +import org.creekservice.kafka.test.perf.implementations.SkemaImplementation; +import org.creekservice.kafka.test.perf.implementations.SnowImplementation; +import org.creekservice.kafka.test.perf.implementations.VertxImplementation; import org.creekservice.kafka.test.perf.testsuite.JsonSchemaTestSuite; import org.creekservice.kafka.test.perf.testsuite.JsonSchemaTestSuite.Result; import org.creekservice.kafka.test.perf.testsuite.SchemaSpec; diff --git a/src/main/java/org/creekservice/kafka/test/perf/implementations/DevHarrelImplementation.java b/src/main/java/org/creekservice/kafka/test/perf/implementations/DevHarrelImplementation.java index c5aa43e..124cbe1 100644 --- a/src/main/java/org/creekservice/kafka/test/perf/implementations/DevHarrelImplementation.java +++ b/src/main/java/org/creekservice/kafka/test/perf/implementations/DevHarrelImplementation.java @@ -16,6 +16,9 @@ package org.creekservice.kafka.test.perf.implementations; +import static org.creekservice.kafka.test.perf.testsuite.SchemaSpec.DRAFT_2019_09; +import static org.creekservice.kafka.test.perf.testsuite.SchemaSpec.DRAFT_2020_12; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.json.JsonMapper; @@ -23,18 +26,15 @@ import dev.harrel.jsonschema.SchemaResolver; import dev.harrel.jsonschema.SpecificationVersion; import dev.harrel.jsonschema.Validator; -import org.creekservice.kafka.test.perf.TestSchemas; -import org.creekservice.kafka.test.perf.model.TestModel; -import org.creekservice.kafka.test.perf.testsuite.AdditionalSchemas; -import org.creekservice.kafka.test.perf.testsuite.SchemaSpec; - import java.io.IOException; import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Set; - -import static org.creekservice.kafka.test.perf.testsuite.SchemaSpec.*; +import org.creekservice.kafka.test.perf.TestSchemas; +import org.creekservice.kafka.test.perf.model.TestModel; +import org.creekservice.kafka.test.perf.testsuite.AdditionalSchemas; +import org.creekservice.kafka.test.perf.testsuite.SchemaSpec; @SuppressWarnings("FieldMayBeFinal") // not final to avoid folding. public class DevHarrelImplementation implements Implementation { @@ -54,29 +54,33 @@ public class DevHarrelImplementation implements Implementation { private Map remotes = Map.of(); public DevHarrelImplementation() { - SchemaResolver schemaResolver = uri -> { - String resolved = remotes.get(URI.create(uri)); - if (resolved == null) { - return SchemaResolver.Result.empty(); - } - return SchemaResolver.Result.fromString(resolved); - }; - Validator validator2020 = new dev.harrel.jsonschema.ValidatorFactory() - .withSchemaResolver(schemaResolver) - .createValidator(); - Validator validator2019 = new dev.harrel.jsonschema.ValidatorFactory() - .withDialect(new Dialects.Draft2019Dialect()) - .withSchemaResolver(schemaResolver) - .createValidator(); + final SchemaResolver schemaResolver = + uri -> { + final String resolved = remotes.get(URI.create(uri)); + if (resolved == null) { + return SchemaResolver.Result.empty(); + } + return SchemaResolver.Result.fromString(resolved); + }; + final Validator validator2020 = + new dev.harrel.jsonschema.ValidatorFactory() + .withSchemaResolver(schemaResolver) + .createValidator(); + final Validator validator2019 = + new dev.harrel.jsonschema.ValidatorFactory() + .withDialect(new Dialects.Draft2019Dialect()) + .withSchemaResolver(schemaResolver) + .createValidator(); /* Validate against meta-schemas in order to parse them eagerly */ validator2020.validate(URI.create(SpecificationVersion.DRAFT2020_12.getId()), "{}"); validator2019.validate(URI.create(SpecificationVersion.DRAFT2019_09.getId()), "{}"); validator2020.registerSchema(testSchemaUri, TestSchemas.DRAFT_2020_SCHEMA); - this.validators = Map.of( - DRAFT_2020_12, validator2020, - DRAFT_2019_09, validator2019); + this.validators = + Map.of( + DRAFT_2020_12, validator2020, + DRAFT_2019_09, validator2019); } @Override @@ -88,13 +92,13 @@ public MetaData metadata() { public JsonValidator prepare( final String schema, final SchemaSpec spec, final AdditionalSchemas additionalSchemas) { DevHarrelImplementation.this.remotes = additionalSchemas.remotes(); - Validator validator = validators.get(spec); - URI schemaUri = validator.registerSchema(schema); + final Validator validator = validators.get(spec); + final URI schemaUri = validator.registerSchema(schema); return new JsonValidator() { @Override public void validate(final String json) { - Validator.Result result = validator.validate(schemaUri, json); + final Validator.Result result = validator.validate(schemaUri, json); if (!result.isValid()) { throw new RuntimeException(); } @@ -103,9 +107,13 @@ public void validate(final String json) { @Override public byte[] serialize(final TestModel model, final boolean validate) { try { - String asString = mapper.writeValueAsString(model); - if (validate) { - validators.get(DRAFT_2020_12).validate(testSchemaUri, asString); + final String asString = mapper.writeValueAsString(model); + if (validate + && !validators + .get(DRAFT_2020_12) + .validate(testSchemaUri, asString) + .isValid()) { + throw new RuntimeException(); } return asString.getBytes(StandardCharsets.UTF_8); } catch (JsonProcessingException e) { @@ -116,7 +124,12 @@ public byte[] serialize(final TestModel model, final boolean validate) { @Override public TestModel deserialize(final byte[] data) { try { - validators.get(DRAFT_2020_12).validate(testSchemaUri, new String(data, StandardCharsets.UTF_8)); + if (!validators + .get(DRAFT_2020_12) + .validate(testSchemaUri, new String(data, StandardCharsets.UTF_8)) + .isValid()) { + throw new RuntimeException(); + } return mapper.readValue(data, TestModel.class); } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/main/java/org/creekservice/kafka/test/perf/testsuite/TestSuite.java b/src/main/java/org/creekservice/kafka/test/perf/testsuite/TestSuite.java index 6fc37d0..0ec7f52 100644 --- a/src/main/java/org/creekservice/kafka/test/perf/testsuite/TestSuite.java +++ b/src/main/java/org/creekservice/kafka/test/perf/testsuite/TestSuite.java @@ -22,7 +22,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.JsonNode; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -55,7 +54,10 @@ public TestSuite( this.suiteFilePath = requireNonNull(suiteFilePath, "suiteFilePath"); this.optional = suiteFilePath.getParent() != null - && suiteFilePath.getParent().toString().contains(File.separator + "optional"); + && suiteFilePath + .getParent() + .toString() + .contains(File.separator + "optional"); } catch (final IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/org/creekservice/kafka/test/perf/testsuite/TestSuiteLoader.java b/src/main/java/org/creekservice/kafka/test/perf/testsuite/TestSuiteLoader.java index 17912ec..5973b61 100644 --- a/src/main/java/org/creekservice/kafka/test/perf/testsuite/TestSuiteLoader.java +++ b/src/main/java/org/creekservice/kafka/test/perf/testsuite/TestSuiteLoader.java @@ -94,7 +94,10 @@ public JsonSchemaTestSuite load(final Path rootDir) { private static Map loadRemotes(final Path remotes) { final Function createKey = - path -> URI.create("http://localhost:1234/" + remotes.relativize(path).toString().replace("\\", "/")); + path -> + URI.create( + "http://localhost:1234/" + + remotes.relativize(path).toString().replace("\\", "/")); final Function readContent = path -> { diff --git a/src/test/java/org/creekservice/kafka/test/perf/implementations/DevHarrelImplementationTest.java b/src/test/java/org/creekservice/kafka/test/perf/implementations/DevHarrelImplementationTest.java new file mode 100644 index 0000000..4f6d43a --- /dev/null +++ b/src/test/java/org/creekservice/kafka/test/perf/implementations/DevHarrelImplementationTest.java @@ -0,0 +1,19 @@ +/* + * Copyright 2023 Creek Contributors (https://github.com/creek-service) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.creekservice.kafka.test.perf.implementations; + +class DevHarrelImplementationTest extends ImplementationTest {}