Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service manager dependency order poc #3368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions misk-service/src/test/kotlin/misk/ServiceManagerModuleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import misk.inject.keyOf
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import jakarta.inject.Inject
import misk.inject.toKey
import kotlin.test.assertFailsWith

internal class ServiceManagerModuleTest {
Expand Down Expand Up @@ -248,4 +249,54 @@ internal class ServiceManagerModuleTest {
|""".trimMargin()
)
}

@Singleton
class ServiceA : AbstractIdleService() {
override fun startUp() {
System.out.println("ServiceA: starting")
}
override fun shutDown() {
System.out.println("ServiceA: stopping")
}
}

@Singleton
class ServiceB : AbstractIdleService() {
override fun startUp() {
System.out.println("ServiceB: starting")
}
override fun shutDown() {
System.out.println("ServiceB: stopping")
}
}

@Singleton
class ServiceC : AbstractIdleService() {
override fun startUp() {
System.out.println("ServiceC: starting")
}
override fun shutDown() {
System.out.println("ServiceC: stopping")
}
}

@Test fun serviceManagerStartupDependencyOrder() {
val injector = Guice.createInjector(
MiskTestingServiceModule(),
object : KAbstractModule() {
override fun configure() {
install(ServiceModule(key = ServiceA::class.toKey()).dependsOn<ReadyService>())

install(ServiceModule<ServiceB>().enhancedBy<ReadyService>())
install(ServiceModule<ServiceC>().enhancedBy<ReadyService>())
}
}
)
val serviceManager = injector.getInstance<ServiceManager>()
serviceManager.startAsync()
serviceManager.awaitHealthy()
serviceManager.stopAsync()
serviceManager.awaitStopped()
throw RuntimeException()
}
}
Loading