From 7eeb0470fcbc4bc62c78bd74910b101579cc8014 Mon Sep 17 00:00:00 2001 From: Harrel Date: Sat, 18 Nov 2023 14:22:31 +0100 Subject: [PATCH 1/3] bump dev.harrel version, optimize serde a bit --- build.gradle.kts | 2 +- .../implementations/DevHarrelImplementation.java | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 1be83a2..dec0161 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -73,7 +73,7 @@ dependencies { implementation("org.leadpony.justify:justify:3.1.0") - implementation("dev.harrel:json-schema:1.4.1") + implementation("dev.harrel:json-schema:1.4.3") implementation("org.apache.logging.log4j:log4j-core:$log4jVersion") runtimeOnly("org.apache.logging.log4j:log4j-slf4j2-impl:$log4jVersion") 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 36e0344..c5fb819 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 @@ -31,7 +31,6 @@ import java.awt.Color; import java.io.IOException; import java.net.URI; -import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -81,12 +80,12 @@ public void validate(final String json) { @Override public byte[] serialize(final TestModel model, final boolean validate) { try { - final String asString = mapper.writeValueAsString(model); - final Validator.Result result = validator.validate(schemaUri, asString); + com.fasterxml.jackson.databind.JsonNode node = mapper.convertValue(model, com.fasterxml.jackson.databind.JsonNode.class); + final Validator.Result result = validator.validate(schemaUri, node); if (validate && !result.isValid()) { throw new RuntimeException(result.getErrors().get(0).getError()); } - return asString.getBytes(StandardCharsets.UTF_8); + return mapper.writeValueAsBytes(node); } catch (JsonProcessingException e) { throw new RuntimeException(e); } @@ -95,12 +94,12 @@ public byte[] serialize(final TestModel model, final boolean validate) { @Override public TestModel deserialize(final byte[] data) { try { - final String json = new String(data, StandardCharsets.UTF_8); - final Validator.Result result = validator.validate(schemaUri, json); + com.fasterxml.jackson.databind.JsonNode node = mapper.readTree(data); + final Validator.Result result = validator.validate(schemaUri, node); if (!result.isValid()) { throw new RuntimeException(result.getErrors().get(0).getError()); } - return mapper.readValue(data, TestModel.class); + return mapper.convertValue(node, TestModel.class); } catch (IOException e) { throw new RuntimeException(e); } @@ -128,6 +127,7 @@ private Validator validator(final SchemaSpec spec, final AdditionalSchemas addit case DRAFT_2020_12: final Validator validator2020 = new dev.harrel.jsonschema.ValidatorFactory() + .withDisabledSchemaValidation(true) .withDialect(new Dialects.Draft2020Dialect()) .withJsonNodeFactory(nodeFactory) .withSchemaResolver(resolver) @@ -138,6 +138,7 @@ private Validator validator(final SchemaSpec spec, final AdditionalSchemas addit case DRAFT_2019_09: final Validator validator2019 = new dev.harrel.jsonschema.ValidatorFactory() + .withDisabledSchemaValidation(true) .withDialect(new Dialects.Draft2019Dialect()) .withJsonNodeFactory(nodeFactory) .withSchemaResolver(resolver) From ba8fe59b2fa4b66b8863d515ea8f7c5a9f2f1073 Mon Sep 17 00:00:00 2001 From: Harrel Date: Sat, 18 Nov 2023 14:25:06 +0100 Subject: [PATCH 2/3] lint fix --- .../test/perf/implementations/DevHarrelImplementation.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 c5fb819..2e901f5 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 @@ -80,7 +80,9 @@ public void validate(final String json) { @Override public byte[] serialize(final TestModel model, final boolean validate) { try { - com.fasterxml.jackson.databind.JsonNode node = mapper.convertValue(model, com.fasterxml.jackson.databind.JsonNode.class); + final com.fasterxml.jackson.databind.JsonNode node = + mapper.convertValue( + model, com.fasterxml.jackson.databind.JsonNode.class); final Validator.Result result = validator.validate(schemaUri, node); if (validate && !result.isValid()) { throw new RuntimeException(result.getErrors().get(0).getError()); @@ -94,7 +96,7 @@ public byte[] serialize(final TestModel model, final boolean validate) { @Override public TestModel deserialize(final byte[] data) { try { - com.fasterxml.jackson.databind.JsonNode node = mapper.readTree(data); + final com.fasterxml.jackson.databind.JsonNode node = mapper.readTree(data); final Validator.Result result = validator.validate(schemaUri, node); if (!result.isValid()) { throw new RuntimeException(result.getErrors().get(0).getError()); From 5e8ad77b1e4f53c517d8df7b9ca9e4cc344d3456 Mon Sep 17 00:00:00 2001 From: Harrel Date: Sat, 18 Nov 2023 14:34:31 +0100 Subject: [PATCH 3/3] support also windows line breaks --- .../util/JsonToMarkdownConvertorTest.java | 18 ++++++++++++------ .../util/PerformanceDataValidatorTest.java | 18 ++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/test/java/org/creekservice/kafka/test/perf/performance/util/JsonToMarkdownConvertorTest.java b/src/test/java/org/creekservice/kafka/test/perf/performance/util/JsonToMarkdownConvertorTest.java index 4f5be70..ee35031 100644 --- a/src/test/java/org/creekservice/kafka/test/perf/performance/util/JsonToMarkdownConvertorTest.java +++ b/src/test/java/org/creekservice/kafka/test/perf/performance/util/JsonToMarkdownConvertorTest.java @@ -36,8 +36,10 @@ class JsonToMarkdownConvertorTest { private static final String EXPECTED_HEADINGS = - "| Benchmark | Mode | Score | Score Error (99.9%) | Unit |\n" - + "|-----------|------|-------|---------------------|------|\n"; + "| Benchmark | Mode | Score | Score Error (99.9%) | Unit |" + + System.lineSeparator() + + "|-----------|------|-------|---------------------|------|" + + System.lineSeparator(); private static final Path SOME_PATH = Paths.get("some/path"); @@ -89,13 +91,16 @@ void shouldConvertJsonToMarkdown() { "JsonValidateBenchmark", EXPECTED_HEADINGS + "| measureDraft_4_Medeia | avgt | 0.34276 | 0.0038394 |" - + " ms/op |\n" + + " ms/op |" + + System.lineSeparator() + "| measureDraft_7_Medeia | avgt | 0.89360 | 0.0035984 |" - + " ms/op |\n", + + " ms/op |" + + System.lineSeparator(), "JsonSerdeBenchmark", EXPECTED_HEADINGS + "| measureEveritRoundTrip | diff | 2135454 | 0.0035367 |" - + " us/op |\n"))); + + " us/op |" + + System.lineSeparator()))); } @Test @@ -121,6 +126,7 @@ void shouldHandleNaN() { "JsonValidateBenchmark", EXPECTED_HEADINGS + "| measureDraft_7_Medeia | avgt | 0.89360 | | ms/op" - + " |\n"))); + + " |" + + System.lineSeparator()))); } } diff --git a/src/test/java/org/creekservice/kafka/test/perf/performance/util/PerformanceDataValidatorTest.java b/src/test/java/org/creekservice/kafka/test/perf/performance/util/PerformanceDataValidatorTest.java index 35fa150..4274d54 100644 --- a/src/test/java/org/creekservice/kafka/test/perf/performance/util/PerformanceDataValidatorTest.java +++ b/src/test/java/org/creekservice/kafka/test/perf/performance/util/PerformanceDataValidatorTest.java @@ -64,7 +64,8 @@ void shouldThrowIfBenchmarkMethodDoesNotMatchPattern() { is( "The JSON benchmark results contain a benchmark method with a name that" + " does not match the expected pattern. Expected pattern:" - + " measure(?Draft[_0-9]+)_(?[A-Za-z0-9]+)\n" + + " measure(?Draft[_0-9]+)_(?[A-Za-z0-9]+)" + + System.lineSeparator() + "Method name: JsonTestBenchmark.invalidPattern")); } @@ -82,10 +83,13 @@ void shouldThrowOnUnknownDraftVersion() { e.getMessage(), is( "The JSON benchmark results contain a benchmark method with a name that" - + " does not contain a valid schema specification draft.\n" + + " does not contain a valid schema specification draft." + + System.lineSeparator() + "Available versions: [Draft_03, Draft_04, Draft_06, Draft_07," - + " Draft_2019_09, Draft_2020_12]\n" - + "Detected version: Draft_11\n" + + " Draft_2019_09, Draft_2020_12]" + + System.lineSeparator() + + "Detected version: Draft_11" + + System.lineSeparator() + "Method name: JsonTestBenchmark.measureDraft_11_Snow")); } @@ -103,8 +107,10 @@ void shouldThrowOnUnknownImplementation() { e.getMessage(), is( "The JSON benchmark results contain a benchmark method with a name that not" - + " end with a known implementation's short name.\n" - + "Detected short name: InvalidImpl\n" + + " end with a known implementation's short name." + + System.lineSeparator() + + "Detected short name: InvalidImpl" + + System.lineSeparator() + "Method name: JsonTestBenchmark.measureDraft_07_InvalidImpl")); }