-
Notifications
You must be signed in to change notification settings - Fork 155
TestKit backend: add full support for temporal types #1257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
injectives
merged 12 commits into
neo4j:5.0
from
robsdedude:testkit-backend-serialize-temporal-types
Jul 6, 2022
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2ea05ca
TestKit backend: add full support for temporal types
robsdedude f975a36
Remove debug print
robsdedude a1786cf
Code style: Mono.just
injectives b377941
Code style: use Optional for `createSkipResponse`
robsdedude 1bb3294
Invert logic and throw sooner on parsing temporal TestKit types
robsdedude c76699e
Be more strict when parsing temporal TestKit types
robsdedude b57efc9
Move inner classes to bottom of their parent class' body
robsdedude 1ce7a0b
Make backend handle (de-)serialization Exceptions gracefully
robsdedude ce83ef5
Move `createErrorResponse` to the right handler in the pipeline
robsdedude 424449b
Remove leftover debug print
robsdedude fa96cf3
Merge branch '5.0' into testkit-backend-serialize-temporal-types
injectives 650e266
Merge branch '5.0' into testkit-backend-serialize-temporal-types
injectives File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
203 changes: 203 additions & 0 deletions
203
testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/StartSubTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* 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 neo4j.org.testkit.backend.messages.requests; | ||
|
||
import java.time.DateTimeException; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionStage; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import neo4j.org.testkit.backend.TestkitState; | ||
import neo4j.org.testkit.backend.messages.responses.RunTest; | ||
import neo4j.org.testkit.backend.messages.responses.SkipTest; | ||
import neo4j.org.testkit.backend.messages.responses.TestkitResponse; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Setter | ||
@Getter | ||
public class StartSubTest implements TestkitRequest { | ||
interface SkipDeciderInterface { | ||
SkipDecision check(Map<String, Object> params); | ||
} | ||
|
||
public static class SkipDecision { | ||
private final boolean skipped; | ||
private final String reason; | ||
|
||
public SkipDecision(boolean skipped, String reason) { | ||
this.skipped = skipped; | ||
this.reason = reason; | ||
} | ||
|
||
public boolean isSkipped() { | ||
return skipped; | ||
} | ||
|
||
public String getReason() { | ||
return reason; | ||
} | ||
|
||
static SkipDecision ofNonSkipped() { | ||
return new SkipDecision(false, null); | ||
} | ||
|
||
static SkipDecision ofSkipped(String reason) { | ||
return new SkipDecision(true, reason); | ||
} | ||
} | ||
|
||
private static final Map<String, SkipDeciderInterface> COMMON_SKIP_PATTERN_TO_CHECK = new HashMap<>(); | ||
private static final Map<String, SkipDeciderInterface> ASYNC_SKIP_PATTERN_TO_CHECK = new HashMap<>(); | ||
private static final Map<String, SkipDeciderInterface> REACTIVE_LEGACY_SKIP_PATTERN_TO_CHECK = new HashMap<>(); | ||
private static final Map<String, SkipDeciderInterface> REACTIVE_SKIP_PATTERN_TO_CHECK = new HashMap<>(); | ||
|
||
private static SkipDecision checkTzIdSupported(Map<String, Object> params) { | ||
String tzId = (String) params.get("tz_id"); | ||
try { | ||
ZoneId.of(tzId); | ||
return SkipDecision.ofNonSkipped(); | ||
} catch (DateTimeException e) { | ||
return SkipDecision.ofSkipped("Timezone not supported: " + tzId); | ||
} | ||
} | ||
|
||
private static SkipDecision checkDateTimeSupported(Map<String, Object> params) { | ||
@SuppressWarnings("unchecked") | ||
HashMap<String, Object> dt_param = (HashMap<String, Object>) params.get("dt"); | ||
if (dt_param == null) { | ||
throw new RuntimeException("params expected to contain 'dt'"); | ||
} | ||
@SuppressWarnings("unchecked") | ||
HashMap<String, Object> data = (HashMap<String, Object>) dt_param.get("data"); | ||
if (data == null) { | ||
throw new RuntimeException("param 'dt' expected to contain 'data'"); | ||
} | ||
Integer year = (Integer) data.get("year"); | ||
Integer month = (Integer) data.get("month"); | ||
Integer day = (Integer) data.get("day"); | ||
Integer hour = (Integer) data.get("hour"); | ||
Integer minute = (Integer) data.get("minute"); | ||
Integer second = (Integer) data.get("second"); | ||
Integer nano = (Integer) data.get("nanosecond"); | ||
Integer utcOffset = (Integer) data.get("utc_offset_s"); | ||
String tzId = (String) data.get("timezone_id"); | ||
try { | ||
ZonedDateTime dt = ZonedDateTime.of(year, month, day, hour, minute, second, nano, ZoneId.of(tzId)); | ||
if (dt.getOffset().getTotalSeconds() != utcOffset) { | ||
throw new DateTimeException(String.format( | ||
"Unmatched UTC offset. TestKit expected %d, local zone db yielded %d", | ||
utcOffset, dt.getOffset().getTotalSeconds())); | ||
} | ||
return SkipDecision.ofNonSkipped(); | ||
} catch (DateTimeException e) { | ||
return SkipDecision.ofSkipped("DateTime not supported: " + e.getMessage()); | ||
} | ||
} | ||
|
||
static { | ||
COMMON_SKIP_PATTERN_TO_CHECK.put( | ||
"neo4j\\.datatypes\\.test_temporal_types\\.TestDataTypes\\.test_should_echo_all_timezone_ids", | ||
StartSubTest::checkDateTimeSupported); | ||
COMMON_SKIP_PATTERN_TO_CHECK.put( | ||
"neo4j\\.datatypes\\.test_temporal_types\\.TestDataTypes\\.test_date_time_cypher_created_tz_id", | ||
StartSubTest::checkTzIdSupported); | ||
|
||
ASYNC_SKIP_PATTERN_TO_CHECK.putAll(COMMON_SKIP_PATTERN_TO_CHECK); | ||
|
||
REACTIVE_LEGACY_SKIP_PATTERN_TO_CHECK.putAll(COMMON_SKIP_PATTERN_TO_CHECK); | ||
|
||
REACTIVE_SKIP_PATTERN_TO_CHECK.putAll(COMMON_SKIP_PATTERN_TO_CHECK); | ||
} | ||
|
||
private StartSubTestBody data; | ||
|
||
public static boolean decidePerSubTest(String testName) { | ||
return skipPatternMatches(testName, COMMON_SKIP_PATTERN_TO_CHECK); | ||
} | ||
|
||
public static boolean decidePerSubTestAsync(String testName) { | ||
return skipPatternMatches(testName, ASYNC_SKIP_PATTERN_TO_CHECK); | ||
} | ||
|
||
public static boolean decidePerSubTestReactiveLegacy(String testName) { | ||
return skipPatternMatches(testName, REACTIVE_LEGACY_SKIP_PATTERN_TO_CHECK); | ||
} | ||
|
||
public static boolean decidePerSubTestReactive(String testName) { | ||
return skipPatternMatches(testName, REACTIVE_SKIP_PATTERN_TO_CHECK); | ||
} | ||
|
||
private static boolean skipPatternMatches( | ||
String testName, Map<String, SkipDeciderInterface> skipPatternToFunction) { | ||
return skipPatternToFunction.entrySet().stream().anyMatch(entry -> testName.matches(entry.getKey())); | ||
} | ||
|
||
@Override | ||
public TestkitResponse process(TestkitState testkitState) { | ||
return createResponse(COMMON_SKIP_PATTERN_TO_CHECK); | ||
} | ||
|
||
@Override | ||
public CompletionStage<TestkitResponse> processAsync(TestkitState testkitState) { | ||
TestkitResponse testkitResponse = createResponse(ASYNC_SKIP_PATTERN_TO_CHECK); | ||
return CompletableFuture.completedFuture(testkitResponse); | ||
} | ||
|
||
@Override | ||
public Mono<TestkitResponse> processRx(TestkitState testkitState) { | ||
TestkitResponse testkitResponse = createResponse(REACTIVE_LEGACY_SKIP_PATTERN_TO_CHECK); | ||
return Mono.fromCompletionStage(CompletableFuture.completedFuture(testkitResponse)); | ||
} | ||
|
||
@Override | ||
public Mono<TestkitResponse> processReactive(TestkitState testkitState) { | ||
TestkitResponse testkitResponse = createResponse(REACTIVE_SKIP_PATTERN_TO_CHECK); | ||
return Mono.fromCompletionStage(CompletableFuture.completedFuture(testkitResponse)); | ||
robsdedude marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
private TestkitResponse createResponse(Map<String, SkipDeciderInterface> skipPatternToCheck) { | ||
System.out.println(data.getTestName()); | ||
robsdedude marked this conversation as resolved.
Show resolved
Hide resolved
robsdedude marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return (TestkitResponse) skipPatternToCheck.entrySet().stream() | ||
.filter(entry -> data.getTestName().matches(entry.getKey())) | ||
.findFirst() | ||
.map(entry -> { | ||
SkipDecision decision = entry.getValue().check(data.getSubtestArguments()); | ||
if (decision.isSkipped()) { | ||
return SkipTest.builder() | ||
.data(SkipTest.SkipTestBody.builder() | ||
.reason(decision.getReason()) | ||
.build()) | ||
.build(); | ||
} | ||
return RunTest.builder().build(); | ||
}) | ||
.orElse(RunTest.builder().build()); | ||
} | ||
|
||
@Setter | ||
@Getter | ||
public static class StartSubTestBody { | ||
private String testName; | ||
private Map<String, Object> subtestArguments; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.