Skip to content

Instantly share code, notes, and snippets.

@yoshiyoshifujii
Created July 9, 2020 04:06
Show Gist options
  • Save yoshiyoshifujii/5fc29487252631c42342e4e0a114ae0a to your computer and use it in GitHub Desktop.
Save yoshiyoshifujii/5fc29487252631c42342e4e0a114ae0a to your computer and use it in GitHub Desktop.
package sample.domain.model
import java.io.{ ByteArrayOutputStream, ObjectOutputStream }
import java.util.concurrent.TimeUnit
import sample.infrastructure.ulid.ULID
import com.google.common.cache.{ CacheBuilder, RemovalListener, RemovalNotification }
import org.scalatest.freespec.AnyFreeSpec
class MessageMetasSpec extends AnyFreeSpec {
"MessageMetas" - {
"cache serialization" in {
val removalListener = new RemovalListener[MessageId, MessageMeta] {
override def onRemoval(notification: RemovalNotification[MessageId, MessageMeta]): Unit = {
println(s"removalListener = $notification")
}
}
val cache = CacheBuilder
.newBuilder()
.maximumSize(Long.MaxValue)
.removalListener(removalListener)
.expireAfterWrite(30, TimeUnit.MINUTES)
.build[MessageId, MessageMeta]()
val arrayOutputStream = new ByteArrayOutputStream()
val objectOutputStream = new ObjectOutputStream(arrayOutputStream)
objectOutputStream.writeObject(cache)
objectOutputStream.flush()
objectOutputStream.close()
arrayOutputStream.close()
}
"serialization" in {
val metas = MessageMetas.Empty.add(MessageMeta(MessageId(ULID()), AccountId(ULID())))
val arrayOutputStream = new ByteArrayOutputStream()
val objectOutputStream = new ObjectOutputStream(arrayOutputStream)
objectOutputStream.writeObject(metas)
objectOutputStream.flush()
objectOutputStream.close()
arrayOutputStream.close()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment