Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,45 @@

package org.creekservice.kafka.test.perf.implementations;

import static org.creekservice.kafka.test.perf.testsuite.SchemaSpec.DRAFT_07;
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;
import dev.harrel.jsonschema.Dialect;
import dev.harrel.jsonschema.Dialects;
import dev.harrel.jsonschema.FormatEvaluatorFactory;
import dev.harrel.jsonschema.JsonNode;
import dev.harrel.jsonschema.SchemaResolver;
import dev.harrel.jsonschema.SpecificationVersion;
import dev.harrel.jsonschema.Validator;
import dev.harrel.jsonschema.ValidatorFactory;
import dev.harrel.jsonschema.providers.JacksonNode;
import java.awt.Color;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
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 {
private static final Map<SchemaSpec, Dialect> SUPPORTED =
Map.of(
DRAFT_07, new Dialects.Draft7Dialect(),
DRAFT_2019_09, new Dialects.Draft2019Dialect(),
DRAFT_2020_12, new Dialects.Draft2020Dialect());

private static final MetaData METADATA =
new MetaData(
"json-schema (dev.harrel)",
"DevHarrel",
Language.Java,
Licence.MIT,
Set.of(DRAFT_2020_12, DRAFT_2019_09),
SUPPORTED.keySet(),
"https://github.com/harrel56/json-schema",
new Color(22, 99, 0),
dev.harrel.jsonschema.ValidatorFactory.class,
Expand Down Expand Up @@ -133,37 +138,21 @@ private Validator validator(
}
return SchemaResolver.Result.empty();
};
switch (spec) {
case DRAFT_2020_12:
final ValidatorFactory validatorFactory2020 =
new ValidatorFactory()
.withDisabledSchemaValidation(true)
.withDialect(new Dialects.Draft2020Dialect())
.withJsonNodeFactory(nodeFactory)
.withSchemaResolver(resolver);
if (enableFormatAssertions) {
validatorFactory2020.withEvaluatorFactory(new FormatEvaluatorFactory());
}
final Validator validator2020 = validatorFactory2020.createValidator();
/* Validate against meta-schema in order to parse it eagerly */
validator2020.validate(URI.create(SpecificationVersion.DRAFT2020_12.getId()), "{}");
return validator2020;
case DRAFT_2019_09:
final ValidatorFactory validatorFactory2019 =
new ValidatorFactory()
.withDisabledSchemaValidation(true)
.withDialect(new Dialects.Draft2019Dialect())
.withJsonNodeFactory(nodeFactory)
.withSchemaResolver(resolver);
if (enableFormatAssertions) {
validatorFactory2019.withEvaluatorFactory(new FormatEvaluatorFactory());
}
final Validator validator2019 = validatorFactory2019.createValidator();
/* Validate against meta-schema in order to parse it eagerly */
validator2019.validate(URI.create(SpecificationVersion.DRAFT2019_09.getId()), "{}");
return validator2019;
default:
throw new RuntimeException("Unsupported Spec:" + spec);
final Dialect dialect = SUPPORTED.get(spec);
if (dialect == null) {
throw new RuntimeException("Unsupported Spec:" + spec);
}
final ValidatorFactory validatorFactory =
new ValidatorFactory()
.withDefaultDialect(dialect)
.withJsonNodeFactory(nodeFactory)
.withSchemaResolver(resolver);
if (enableFormatAssertions) {
validatorFactory.withEvaluatorFactory(new FormatEvaluatorFactory());
}
final Validator validator = validatorFactory.createValidator();
/* Validate against meta-schema in order to parse it eagerly */
validator.validate(spec.uri(), "{}");
return validator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ public DevHarrelState() {
}
}

@Benchmark
public TestModel measureDraft_07_DevHarrel(final DevHarrelState impl, final ModelState model) {
return impl.roundTrip(model, SchemaSpec.DRAFT_07);
}

@Benchmark
public TestModel measureDraft_2020_12_DevHarrel(
final DevHarrelState impl, final ModelState model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ public DevHarrelValidator() {
}
}

@Benchmark
public Result measureDraft_07_DevHarrel(final DevHarrelValidator validator) {
return validator.validate(SchemaSpec.DRAFT_07);
}

@Benchmark
public Result measureDraft_2019_09_DevHarrel(final DevHarrelValidator validator) {
return validator.validate(SchemaSpec.DRAFT_2019_09);
Expand Down
Loading