Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #853 from rkeytacked/master
Browse files Browse the repository at this point in the history
ensure linear runtime regex pattern matching
  • Loading branch information
lmontrieux authored Mar 6, 2018
2 parents e7c1d2d + 20a6f3c commit 74c3269
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed
- Updated json-schema validation library, now using [RE2/J](https://github.com/google/re2j) for regex pattern matching

## [2.5.8] - 2018-02-22

### Added
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ dependencies {
compile 'org.apache.curator:curator-recipes:2.12.0'

// json
compile 'com.github.everit-org.json-schema:org.everit.json.schema:86c29435e43e3e56924cf6ddf3013b5a381930b6'
compile ('com.github.everit-org.json-schema:org.everit.json.schema:6cb8ae440b0bc34030d7bea85ac609d980d741fb') {
exclude module: "json"
}
compile ('com.fasterxml.jackson.datatype:jackson-datatype-json-org:2.8.8') {
exclude module: "json"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Optional;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.Assert.assertThat;
import static org.zalando.nakadi.utils.IsOptional.isAbsent;
import static org.zalando.nakadi.utils.TestUtils.readFile;
Expand Down Expand Up @@ -104,6 +105,22 @@ public void requireEidToBeFormattedAsUUID() {
"^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"));
}

@Test
public void requirePatternMatchingToBeFast() {
final EventType et = EventTypeTestBuilder.builder().name("some-event-type").schema(patternSchema()).build();
et.setCategory(EventCategory.UNDEFINED);

final long startTime = System.currentTimeMillis();

final JSONObject event = undefinedEvent();
final Optional<ValidationError> error = EventValidation.forType(et).validate(event);

final long duration = System.currentTimeMillis() - startTime;

assertThat(error, isAbsent());
assertThat(duration, lessThan(100L));
}

@Test
public void acceptsDefinitionsOnDataChangeEvents() throws Exception {
final JSONObject schema = new JSONObject(readFile("product-json-schema.json"));
Expand Down Expand Up @@ -131,6 +148,22 @@ private JSONObject basicSchema() {
return schema;
}

private JSONObject patternSchema() {
final JSONObject schema = new JSONObject();
final JSONObject string = new JSONObject();
string.put("type", "string");
string.put("pattern", "a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaaaaaaaaaa");

final JSONObject properties = new JSONObject();
properties.put("foo", string);

schema.put("type", "object");
schema.put("required", Arrays.asList(new String[]{"foo"}));
schema.put("properties", properties);

return schema;
}

private JSONObject businessEvent() {
final JSONObject event = new JSONObject();
event.put("foo", "bar");
Expand All @@ -139,6 +172,13 @@ private JSONObject businessEvent() {
return event;
}

private JSONObject undefinedEvent() {
final JSONObject event = new JSONObject();
event.put("foo", "aaaaaaaaaaaaaaaaaaaaaaaaaaaa");

return event;
}

private JSONObject dataChangeEvent() {
final JSONObject event = new JSONObject();

Expand Down

0 comments on commit 74c3269

Please sign in to comment.