mkporwit
10/16/2017, 8:24 AMraniejade
10/16/2017, 8:26 AMgiven
, describe
, etc ..)raniejade
10/16/2017, 8:27 AMbeforeTest { init container here }
describe("a profile handler") {
val userProfileRedis by memoized { ... }
}
mkporwit
10/16/2017, 8:32 AMuserProfileRedisContainer.start()
is done in the beforeGroup
-- that sets up the container. All I'm doing afterwards is to just take a couple of properties from the running container to initialize a local redis handler...raniejade
10/16/2017, 8:57 AMuserProfileRedis
inside a group.mkporwit
10/16/2017, 8:57 AMclass ProfileHandlerSpec: Spek({
val userProfileRedisContainer = KGenericContainer("redis:latest").withExposedPorts(6379)!!
var ph : ProfileHandler? = null
beforeGroup {
userProfileRedisContainer.start()
val userProfileRedis : RedisHandler = makeRedisHandler(userProfileRedisContainer.containerIpAddress, userProfileRedisContainer.getMappedPort(6379))
ph = ProfileHandler(userProfileRedis)
}
describe("a profile handler") {
val uuid = UUID.randomUUID().toString()
val cTime = Date.from(Instant.now()).time
on("new profile creation") {
val profile = ph!!.createNewUserProfile(UserProfile(uuid, "Hoylu", "User", "<mailto:testuser@hoylu.com|testuser@hoylu.com>"))
it("should create a profile with the proper uuid, creationTime, and default lastLoginTime") {
assertEquals(uuid, profile.uuid)
assertTrue(profile.creationTime >= cTime)
assertEquals(0L, profile.lastLoginInfo.lastLoginTime)
}
}
}
afterGroup {
userProfileRedisContainer.stop()
}
})
mkporwit
10/16/2017, 8:58 AMby memoized
to make this any more idiomatic, @raniejaderaniejade
10/16/2017, 9:00 AMraniejade
10/16/2017, 9:02 AMclass ProfileHandlerSpec: Spek({
val userProfileRedisContainer by memoized { KGenericContainer("redis:latest").withExposedPorts(6379)!! }
var ph by memoized {
userProfileRedisContainer.start()
val userProfileRedis : RedisHandler = makeRedisHandler(userProfileRedisContainer.containerIpAddress, userProfileRedisContainer.getMappedPort(6379))
ProfileHandler(userProfileRedis)
}
beforeEachTest {
userProfileRedisContainer.start()
}
describe("a profile handler") {
on("new profile creation") {
val uuid = UUID.randomUUID().toString()
val cTime = Date.from(Instant.now()).time
val profile = ph!!.createNewUserProfile(UserProfile(uuid, "Hoylu", "User", "<mailto:testuser@hoylu.com|testuser@hoylu.com>"))
it("should create a profile with the proper uuid, creationTime, and default lastLoginTime") {
assertEquals(uuid, profile.uuid)
assertTrue(profile.creationTime >= cTime)
assertEquals(0L, profile.lastLoginInfo.lastLoginTime)
}
}
}
afterEachTest {
userProfileRedisContainer.stop()
}
})
raniejade
10/16/2017, 9:02 AMon
is not a group, but considered a test that’s why it’s okay to have initialization login inside of itraniejade
10/16/2017, 9:03 AM!!
mkporwit
10/16/2017, 9:07 AMvar ph by memoized
block: Error:(15, 15) Kotlin: Missing 'setValue(Nothing?, KProperty<*>, ProfileHandler)' method on delegate of type 'LifecycleAware<ProfileHandler>'
raniejade
10/16/2017, 9:07 AMval
mkporwit
10/16/2017, 9:41 AMclass ProfileHandlerSpec: Spek({
val userProfileRedisContainer by memoized { KGenericContainer("redis:latest").withExposedPorts(6379) }
val ph by memoized {
val userProfileRedis= makeRedisHandler(userProfileRedisContainer.containerIpAddress, userProfileRedisContainer.getMappedPort(6379))
ProfileHandler(userProfileRedis)
}
given("a profile handler") {
beforeGroup {
userProfileRedisContainer.start()
}
on("new profile creation") {
val uuid = UUID.randomUUID().toString()
val cTime = Date.from(Instant.now()).time
val profile = ph.createNewUserProfile(UserProfile(uuid, "Hoylu", "User", "<mailto:testuser@hoylu.com|testuser@hoylu.com>"))
it("should create a profile with the proper uuid, creationTime, and default lastLoginTime") {
assertEquals(uuid, profile.uuid)
assertTrue(profile.creationTime >= cTime)
assertEquals(0L, profile.lastLoginInfo.lastLoginTime)
}
val gotProfile = ph.getUserProfile(profile.uuid)
it("should return the profile for the uuid") {
assertEquals(profile, gotProfile)
}
}
afterGroup {
userProfileRedisContainer.stop()
}
}
})
I can see in the debugger that the afterGroup block is being executed, which stops the container. I can step all the way through the test termination sequence, see it return a tests successful, and finally step out of execute
in DefaultLauncher.java
. And then it seems to still wait for something...mkporwit
10/16/2017, 9:42 AMraniejade
10/16/2017, 9:43 AMmkporwit
10/16/2017, 9:44 AMpackage lu.hoy.eng.userprofile
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.given
import <http://org.jetbrains.spek.api.dsl.it|org.jetbrains.spek.api.dsl.it>
import org.jetbrains.spek.api.dsl.on
import java.time.Instant
import java.util.*
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class ProfileHandlerSpec: Spek({
val userProfileRedisContainer by memoized { KGenericContainer("redis:latest").withExposedPorts(6379) }
val ph by memoized {
val userProfileRedis= makeRedisHandler(userProfileRedisContainer.containerIpAddress, userProfileRedisContainer.getMappedPort(6379))
ProfileHandler(userProfileRedis)
}
given("a profile handler") {
beforeGroup {
userProfileRedisContainer.start()
}
on("new profile creation") {
val uuid = UUID.randomUUID().toString()
val cTime = Date.from(Instant.now()).time
val profile = ph.createNewUserProfile(UserProfile(uuid, "Hoylu", "User", "<mailto:testuser@hoylu.com|testuser@hoylu.com>"))
it("should create a profile with the proper uuid, creationTime, and default lastLoginTime") {
assertEquals(uuid, profile.uuid)
assertTrue(profile.creationTime >= cTime)
assertEquals(0L, profile.lastLoginInfo.lastLoginTime)
}
val gotProfile = ph.getUserProfile(profile.uuid)
it("should return the profile for the uuid") {
assertEquals(profile, gotProfile)
}
}
afterGroup {
userProfileRedisContainer.stop()
}
}
})
raniejade
10/16/2017, 9:45 AMbeforeEachTest
and afterEachTest
?mkporwit
10/16/2017, 9:47 AMraniejade
10/16/2017, 9:47 AMraniejade
10/16/2017, 9:48 AMmkporwit
10/16/2017, 9:49 AMstart()
?mkporwit
10/16/2017, 9:49 AMraniejade
10/16/2017, 9:49 AMraniejade
10/16/2017, 9:50 AMmkporwit
10/16/2017, 9:50 AMraniejade
10/16/2017, 9:50 AMKGenericContainer(...)
mkporwit
10/16/2017, 9:51 AMmkporwit
10/16/2017, 9:52 AMraniejade
10/16/2017, 9:52 AMmkporwit
10/16/2017, 9:57 AMraniejade
10/16/2017, 9:57 AMmkporwit
10/16/2017, 9:59 AMmkporwit
10/16/2017, 9:59 AMraniejade
10/16/2017, 9:59 AMmkporwit
10/16/2017, 10:00 AMmkporwit
10/16/2017, 10:01 AMraniejade
10/16/2017, 10:02 AM"pool-1-thread-1@3028" prio=5 tid=0xe nid=NA waiting
java.lang.Thread.State: WAITING
at sun.misc.Unsafe.park(Unsafe.java:-1)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:460)
at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362)
at java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:941)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1066)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
"dockerjava-netty-1-16@4317" prio=5 tid=0x21 nid=NA runnable
java.lang.Thread.State: RUNNABLE
at org.testcontainers.shaded.io.netty.channel.kqueue.Native.keventWait(Native.java:-1)
at org.testcontainers.shaded.io.netty.channel.kqueue.Native.keventWait(Native.java:76)
at org.testcontainers.shaded.io.netty.channel.kqueue.KQueueEventLoop.kqueueWait(KQueueEventLoop.java:158)
at org.testcontainers.shaded.io.netty.channel.kqueue.KQueueEventLoop.kqueueWait(KQueueEventLoop.java:149)
at org.testcontainers.shaded.io.netty.channel.kqueue.KQueueEventLoop.run(KQueueEventLoop.java:219)
at org.testcontainers.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
at org.testcontainers.shaded.io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
at java.lang.Thread.run(Thread.java:748)
raniejade
10/16/2017, 10:02 AMdockerjava-netty
non daemon threadsraniejade
10/16/2017, 10:03 AMpool-1-thread-xxxx
raniejade
10/16/2017, 10:03 AMmkporwit
10/16/2017, 10:04 AMmkporwit
10/16/2017, 10:05 AMclass ProfileTests {
companion object {
val userProfileRedisContainer = KGenericContainer("redis:latest").withExposedPorts(6379)!!
@BeforeClass
@JvmStatic
fun classSetup() {
userProfileRedisContainer.start()
}
@AfterClass
@JvmStatic
fun classShutdown() {
userProfileRedisContainer.stop()
}
}
private val userProfileRedis = makeRedisHandler(userProfileRedisContainer.containerIpAddress, userProfileRedisContainer.getMappedPort(6379))
<bunch of tests here>
raniejade
10/16/2017, 10:05 AMraniejade
10/16/2017, 10:07 AMraniejade
10/16/2017, 10:07 AMmkporwit
10/16/2017, 10:08 AMmkporwit
10/16/2017, 10:09 AMraniejade
10/16/2017, 10:09 AMdockerjava-netty-1-16@4317
non daemonraniejade
10/16/2017, 10:10 AMmkporwit
10/16/2017, 10:10 AMraniejade
10/16/2017, 10:10 AMmkporwit
10/16/2017, 10:10 AMmkporwit
10/16/2017, 10:11 AMmkporwit
10/16/2017, 10:11 AMraniejade
10/16/2017, 10:11 AMraniejade
10/16/2017, 10:11 AMmkporwit
10/16/2017, 10:11 AMmkporwit
10/16/2017, 10:12 AMraniejade
10/16/2017, 10:12 AM