-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5293 from entur/limit_search_window
Add a configurable limit for the search window
- Loading branch information
Showing
8 changed files
with
189 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
53 changes: 53 additions & 0 deletions
53
src/test/java/org/opentripplanner/standalone/config/RouterConfigDocTest.java
This file contains 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,53 @@ | ||
package org.opentripplanner.standalone.config; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
import static org.opentripplanner.standalone.config.framework.json.JsonSupport.jsonNodeForTest; | ||
import static org.opentripplanner.standalone.config.framework.json.JsonSupport.jsonNodeFromResource; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.opentripplanner.framework.application.OtpAppException; | ||
import org.opentripplanner.standalone.config.framework.json.NodeAdapter; | ||
|
||
class RouterConfigDocTest { | ||
|
||
private static final String SOURCE = "RouterConfigTest"; | ||
|
||
/** | ||
* Test that the router-config.json example used in documentation is valid. | ||
*/ | ||
@Test | ||
void validateExample() { | ||
var node = jsonNodeFromResource("standalone/config/router-config.json"); | ||
|
||
// Setup so we get access to the NodeAdapter | ||
var a = new NodeAdapter(node, SOURCE); | ||
var c = new RouterConfig(a, false); | ||
|
||
// Test for unused parameters | ||
var buf = new StringBuilder(); | ||
a.logAllWarnings(m -> buf.append("\n").append(m)); | ||
if (!buf.isEmpty()) { | ||
fail(buf.toString()); | ||
} | ||
} | ||
|
||
@Test | ||
void testSemanticValidation() { | ||
// apiProcessingTimeout must be greater then streetRoutingTimeout | ||
var root = createNodeAdaptor( | ||
""" | ||
{ | ||
server: { apiProcessingTimeout : "1s" }, | ||
routingDefaults: { streetRoutingTimeout: "17s" } | ||
} | ||
""" | ||
); | ||
// | ||
assertThrows(OtpAppException.class, () -> new RouterConfig(root, false)); | ||
} | ||
|
||
private static NodeAdapter createNodeAdaptor(String jsonText) { | ||
return new NodeAdapter(jsonNodeForTest(jsonText), "Test"); | ||
} | ||
} |
49 changes: 15 additions & 34 deletions
49
src/test/java/org/opentripplanner/standalone/config/RouterConfigTest.java
This file contains 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 |
---|---|---|
@@ -1,53 +1,34 @@ | ||
package org.opentripplanner.standalone.config; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
import static org.opentripplanner.standalone.config.framework.json.JsonSupport.jsonNodeForTest; | ||
import static org.opentripplanner.standalone.config.framework.json.JsonSupport.jsonNodeFromResource; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.opentripplanner.standalone.config.framework.json.JsonSupport.newNodeAdapterForTest; | ||
|
||
import java.time.Duration; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentripplanner.framework.application.OtpAppException; | ||
import org.opentripplanner.standalone.config.framework.json.NodeAdapter; | ||
|
||
class RouterConfigTest { | ||
|
||
private static final String SOURCE = "RouterConfigTest"; | ||
|
||
/** | ||
* Test that the router-config.json example used in documentation is valid. | ||
*/ | ||
@Test | ||
void validateExample() { | ||
var node = jsonNodeFromResource("standalone/config/router-config.json"); | ||
|
||
// Setup so we get access to the NodeAdapter | ||
var a = new NodeAdapter(node, SOURCE); | ||
var c = new RouterConfig(a, false); | ||
|
||
// Test for unused parameters | ||
var buf = new StringBuilder(); | ||
a.logAllWarnings(m -> buf.append("\n").append(m)); | ||
if (!buf.isEmpty()) { | ||
fail(buf.toString()); | ||
} | ||
void defaultMaxSearchWindowIs24Hours() { | ||
validateMaxSearchWindow("", Duration.ofHours(24)); | ||
} | ||
|
||
@Test | ||
void testSemanticValidation() { | ||
// apiProcessingTimeout must be greater then streetRoutingTimeout | ||
var root = createNodeAdaptor( | ||
void maxSearchWindowIsOverriddenInRouterConfig() { | ||
validateMaxSearchWindow( | ||
""" | ||
{ | ||
server: { apiProcessingTimeout : "1s" }, | ||
routingDefaults: { streetRoutingTimeout: "17s" } | ||
"transit": { | ||
"maxSearchWindow": "48h" | ||
} | ||
} | ||
""" | ||
""", | ||
Duration.ofHours(48) | ||
); | ||
// | ||
assertThrows(OtpAppException.class, () -> new RouterConfig(root, false)); | ||
} | ||
|
||
private static NodeAdapter createNodeAdaptor(String jsonText) { | ||
return new NodeAdapter(jsonNodeForTest(jsonText), "Test"); | ||
private void validateMaxSearchWindow(String configuration, Duration expectedDuration) { | ||
RouterConfig routerConfig = new RouterConfig(newNodeAdapterForTest(configuration), false); | ||
assertEquals(expectedDuration, routerConfig.routingRequestDefaults().maxSearchWindow()); | ||
} | ||
} |