Skip to content

Commit

Permalink
GEOMESA-2934 Fix kryo serialization errors expanding large buffers (#…
Browse files Browse the repository at this point in the history
…2636)

Signed-off-by: Emilio Lahr-Vivaz <[email protected]>
  • Loading branch information
elahrvivaz authored and jnh5y committed Oct 20, 2020
1 parent d153ea4 commit b444b29
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ trait KryoFeatureSerialization extends SimpleFeatureSerializer {
output.setBuffer(expanded)
} else {
val buffer = output.getBuffer
var i = end
// end is the position of the next byte to write, so we want to copy from the previous byte
var i = end - 1
while (i > offset) {
buffer(i + shift) = buffer(i)
i -= 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class KryoFeatureSerializerTest extends Specification with LazyLogging {

sequential

val options = Seq(
val options: Seq[Set[SerializationOption]] = Seq(
Set.empty[SerializationOption],
Set(Immutable),
Set(WithUserData),
Expand Down Expand Up @@ -412,6 +412,20 @@ class KryoFeatureSerializerTest extends Specification with LazyLogging {
}
}

"correctly expand the buffer for large serialized objects" in {
val spec = "age:Int,name:String,dtg:Date,*geom:Point:srid=4326"
val sft = SimpleFeatureTypes.createType("test", spec)
val sf = ScalaSimpleFeature.create(sft, "fid-0", "10", null, "2013-01-02T00:00:00.000Z", "POINT(45.0 49.0)")
val name = new String(Array.fill(131011)('a'.toByte), StandardCharsets.UTF_8)
sf.setAttribute("name", name)
val serializer = KryoFeatureSerializer(sft, SerializationOptions.withoutId)
val serialized = serializer.serialize(sf)
val deserialized = serializer.deserialize(serialized)
deserialized.getAttribute("name") mustEqual name
deserialized.getAttributes mustEqual sf.getAttributes
deserialized.getUserData.asScala must beEmpty
}

"be backwards compatible" in {
val spec = "dtg:Date,*geom:Point:srid=4326"
val sft = SimpleFeatureTypes.createType("testType", spec)
Expand Down

0 comments on commit b444b29

Please sign in to comment.