-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TileFeature Serialization and I/O Tests
- Loading branch information
James McClain
committed
Apr 6, 2016
1 parent
b6e8c18
commit 0ec6d21
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
spark/src/test/scala/geotrellis/spark/io/TileFeatureIOSpec.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,69 @@ | ||
package geotrellis.spark.io | ||
|
||
import geotrellis.raster._ | ||
import geotrellis.raster.io.geotiff.SinglebandGeoTiff | ||
import geotrellis.spark._ | ||
import geotrellis.spark.io._ | ||
import geotrellis.spark.io.file._ | ||
import geotrellis.spark.io.index._ | ||
import geotrellis.vector.Extent | ||
|
||
import org.scalatest.FunSpec | ||
|
||
|
||
class TileFeatureIOSpec | ||
extends FunSpec | ||
with TestEnvironment { | ||
|
||
describe("TileFeature AvroRecordCodec") { | ||
val path = "raster-test/data/aspect.tif" | ||
val gt = SinglebandGeoTiff(path) | ||
val originalRaster = gt.raster.resample(500, 500) | ||
val (_, rdd) = createTileLayerRDD(originalRaster, 5, 5, gt.crs) | ||
val outRdd = rdd.withContext { | ||
_.map({ case (key,tile) => key -> TileFeature(tile,tile) }) | ||
} | ||
|
||
val toDisk = outRdd | ||
.collect | ||
.sortWith((a,b) => a.toString.compareTo(b.toString) < 0) | ||
|
||
val writer = FileLayerWriter(outputLocalPath) | ||
val reader = FileLayerReader(outputLocalPath) | ||
val deleter = FileLayerDeleter(outputLocalPath) | ||
|
||
it("should allow proper writing and reading") { | ||
import java.security.MessageDigest | ||
val md = MessageDigest.getInstance("SHA-256"); | ||
val layerId = LayerId("TileFeatureLayer", 0) | ||
|
||
try { | ||
writer.write[SpatialKey, TileFeature[Tile, Tile], TileLayerMetadata[SpatialKey]](layerId, outRdd, ZCurveKeyIndexMethod) | ||
|
||
val fromDisk = reader.read[SpatialKey, TileFeature[Tile, Tile], TileLayerMetadata[SpatialKey]](layerId) | ||
.collect | ||
.sortWith((a,b) => a.toString.compareTo(b.toString) < 0) | ||
|
||
toDisk.zip(fromDisk).map({ case (a,b) => | ||
md.reset | ||
md.update(a._1.toString.getBytes) | ||
md.update(a._2.tile.toBytes) | ||
md.update(a._2.data.toBytes) | ||
val digestA = md.digest | ||
|
||
md.reset | ||
md.update(b._1.toString.getBytes) | ||
md.update(b._2.tile.toBytes) | ||
md.update(b._2.data.toBytes) | ||
val digestB = md.digest | ||
|
||
MessageDigest.isEqual(digestA, digestB) should be (true) | ||
}) | ||
} | ||
finally { | ||
deleter.delete(layerId) | ||
} | ||
} | ||
|
||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
spark/src/test/scala/geotrellis/spark/io/avro/TileFeatureCodecSpec.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,21 @@ | ||
package geotrellis.spark.io.avro | ||
|
||
import geotrellis.raster._ | ||
import geotrellis.spark.io._ | ||
import org.scalatest._ | ||
|
||
|
||
class TileFeatureCodecSpec extends FunSpec with Matchers with AvroTools { | ||
describe("TileFeatureCodec") { | ||
val tile = IntArrayTile.fill(0, 10, 10) | ||
|
||
it("should encode/decode a TileFeature of a Tile and a Tile"){ | ||
roundTrip(TileFeature(tile,tile)) | ||
} | ||
|
||
it("should encode/decode a TileFeature of a Tile and a non-Tile"){ | ||
roundTrip(TileFeature(tile,TileFeature(tile,tile))) | ||
} | ||
|
||
} | ||
} |