Prepare for other compression algorithms in JacksonSerializer, #27066 (#27889)

* change config structure to be able to support other compression
  algorithms, such as lz4 in the future
* enable compression for json (as before) but disable it by default
  for cbor

Co-Authored-By: Ignasi Marimon-Clos <ignasi@lightbend.com>
This commit is contained in:
Patrik Nordwall 2019-10-08 11:23:01 +02:00 committed by GitHub
parent f2de57a057
commit ae70a833fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 109 additions and 34 deletions

View file

@ -110,7 +110,13 @@ class ScalaTestEventMigration extends JacksonMigration {
}
}
class JacksonCborSerializerSpec extends JacksonSerializerSpec("jackson-cbor")
class JacksonCborSerializerSpec extends JacksonSerializerSpec("jackson-cbor") {
"have compression disabled by default" in {
val conf = JacksonObjectMapperProvider.configForBinding("jackson-cbor", system.settings.config)
val compressionAlgo = conf.getString("compression.algorithm")
compressionAlgo should ===("off")
}
}
@silent // this test uses Jackson deprecated APIs
class JacksonJsonSerializerSpec extends JacksonSerializerSpec("jackson-json") {
@ -453,6 +459,24 @@ class JacksonJsonSerializerSpec extends JacksonSerializerSpec("jackson-json") {
deserializeFromJsonString(json, serializer.identifier, serializer.manifest(expected)) should ===(expected)
}
"compress large payload with gzip" in {
val conf = JacksonObjectMapperProvider.configForBinding("jackson-json", system.settings.config)
val compressionAlgo = conf.getString("compression.algorithm")
compressionAlgo should ===("gzip")
val compressLargerThan = conf.getBytes("compression.compress-larger-than")
compressLargerThan should ===(32 * 1024)
val msg = SimpleCommand("0" * (compressLargerThan + 1).toInt)
val bytes = serializeToBinary(msg)
JacksonSerializer.isGZipped(bytes) should ===(true)
bytes.length should be < compressLargerThan.toInt
}
"not compress small payload with gzip" in {
val msg = SimpleCommand("0" * 1000)
val bytes = serializeToBinary(msg)
JacksonSerializer.isGZipped(bytes) should ===(false)
}
}
}