-
Notifications
You must be signed in to change notification settings - Fork 11
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 #206 from jbouffard/fix/rs-threadsafety
GeoTiffRasterSource Thread Safety
- Loading branch information
Showing
5 changed files
with
106 additions
and
24 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
70 changes: 70 additions & 0 deletions
70
...src/test/scala/geotrellis/contrib/vlm/geotiff/GeoTiffRasterSourceMultiThreadingSpec.scala
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,70 @@ | ||
/* | ||
* Copyright 2019 Azavea | ||
* | ||
* 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 geotrellis.contrib.vlm.geotiff | ||
|
||
import geotrellis.contrib.vlm.{RasterSource, Resource} | ||
import geotrellis.proj4.CRS | ||
import geotrellis.raster.resample._ | ||
|
||
import cats.instances.future._ | ||
import cats.instances.list._ | ||
import cats.syntax.traverse._ | ||
import org.scalatest.{AsyncFunSpec, Matchers} | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class GeoTiffRasterSourceMultiThreadingSpec extends AsyncFunSpec with Matchers { | ||
val url = Resource.path("img/aspect-tiled.tif") | ||
val source = GeoTiffRasterSource(url) | ||
|
||
implicit val ec = ExecutionContext.global | ||
|
||
val iterations = (0 to 100).toList | ||
|
||
/** | ||
* readBounds and readExtends are not covered by these tests since these methods return an [[Iterator]]. | ||
* Due to the [[Iterator]] lazy nature, the lock in these cases should be done on the user side. | ||
* */ | ||
def testMultithreading(rs: RasterSource): Unit = { | ||
it("read") { | ||
val res = iterations.map { _ => Future { rs.read() } }.sequence.map(_.flatten) | ||
res.map { rasters => rasters.length shouldBe iterations.length } | ||
} | ||
|
||
it("readBounds - Option") { | ||
val res = | ||
iterations | ||
.map { _ => Future { rs.read(rs.gridBounds, 0 until rs.bandCount) } } | ||
.sequence | ||
.map(_.flatten) | ||
|
||
res.map { rasters => rasters.length shouldBe iterations.length } | ||
} | ||
} | ||
|
||
describe("GeoTiffRasterSource should be threadsafe") { | ||
testMultithreading(source) | ||
} | ||
|
||
describe("GeoTiffRasterReprojectSource should be threadsafe") { | ||
testMultithreading(source.reproject(CRS.fromEpsgCode(4326))) | ||
} | ||
|
||
describe("GeoTiffRasterResampleSource should be threadsafe") { | ||
testMultithreading(source.resample((source.cols * 0.95).toInt , (source.rows * 0.95).toInt, NearestNeighbor)) | ||
} | ||
} |