forked from osmlab/atlas-checks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ExternalData: Use ResourceCache to get data (osmlab#398)
* Gradle: Add JUnit5 JUnit5 has better support for exceptions (assertThrows, assertDoesNotThrow, etc.). Signed-off-by: Taylor Smock <[email protected]> * ExternalData: Allow checks to obtain and use arbitrary external data WaterWayChecks: Add note in documentation about resolution and NASA SRTM ElevationUtilities: External data: Add tests to ensure that data is fetched. ExternalData: * Use ResourceCache to get data * Use check constructors to fetch necessary data or to store the file fetcher to be used later. Each check can decide how it fetches data. * See docs/externalData.md for implementation notes. CheckResourceLoader: Fix all code smells Signed-off-by: Taylor Smock <[email protected]>
- Loading branch information
Showing
15 changed files
with
509 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# External Data | ||
## Common information | ||
External data is defined as any data that is not an atlas file. External data | ||
_MUST_ be placed in the same directory as the atlas files, with the name | ||
`extra`. | ||
|
||
In some cases, if the external data file is _very large_, the data transfer | ||
may be interrupted, and the process will fail, absent error handling. | ||
|
||
## Using external data in a check | ||
There must be a constructor for the check that follows this definition: | ||
`public Check(Configuration configuration, ExternalDataFetcher fetcher)` | ||
|
||
At this point, the `ExternalDataFetcher` can be used to prefetch data, or | ||
stored later to be used to dynamically get data as the check progresses. | ||
The latter is generally recommended, since the data is cached as it is needed. | ||
This means that the data will not be transferred if the check is cancelled or | ||
has an error prior to needing the data. | ||
|
||
### Example code | ||
```java | ||
public Check(Configuration configuration, ExternalDataFetcher fetcher) { | ||
super(configuration); | ||
Optional<Resource> optionalResource = fetcher.apply("filename"); | ||
if (optionalResource.isPresent()) { | ||
// Congratulations, you have the data | ||
Resource resource = optionalResource.get(); | ||
// At this point, you can get an InputStream. | ||
InputStream inputStream = resource.read(); | ||
/* Currently, there is no good way to get the actual file on the local | ||
* filesystem. This should be implemented as soon as that functionality | ||
* is required. | ||
* | ||
* Implementation note: The returned resource will most likely be a | ||
* InputStreamResource. This, however, can change. | ||
*/ | ||
} else { | ||
// You don't have the data. Either error out or log, depending upon | ||
// how critical the data is. | ||
} | ||
} | ||
``` |
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 |
---|---|---|
|
@@ -24,6 +24,7 @@ sourceSets | |
|
||
test | ||
{ | ||
useJUnitPlatform() | ||
testLogging | ||
{ | ||
events "failed" | ||
|
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
Oops, something went wrong.