Created
July 9, 2020 04:06
-
-
Save yoshiyoshifujii/5fc29487252631c42342e4e0a114ae0a to your computer and use it in GitHub Desktop.
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
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