Skip to content
Permalink
Browse files

Require configs to be explicitly bound and enable requireExplicitInje…

…ct() (#816)

* Requires configs to be explicitly bound.

Fixes #794. This removes the code in `ConfigModule` that walks the
app's `Config` object and binds its child `Config` classes automatically.

* Rename and un-deprecate WebActionModule's factory methods

* Enable requireAtInjectOnConstructors()

* skipSources() on WebActionModule provider check

Makes the error message for WebAction injector errors refer to the
module that installs WebActionModule instead of WebActionModule.
  • Loading branch information...
mightyguava committed Mar 6, 2019
1 parent 0508802 commit e82b920a605f5739c77a8e28d5e1e99241fb67b6
Showing with 552 additions and 573 deletions.
  1. +3 −1 misk-aws/src/main/kotlin/misk/jobqueue/sqs/AwsSqsJobQueueConfig.kt
  2. +4 −1 misk-aws/src/main/kotlin/misk/jobqueue/sqs/AwsSqsJobQueueModule.kt
  3. +1 −1 misk-aws/src/test/kotlin/misk/jobqueue/sqs/SqsJobQueueTest.kt
  4. +2 −1 misk-eventrouter/src/main/kotlin/misk/eventrouter/ConsistentHashing.kt
  5. +1 −1 misk-eventrouter/src/main/kotlin/misk/eventrouter/EventRouterConnectionAction.kt
  6. +1 −1 misk-eventrouter/src/main/kotlin/misk/eventrouter/EventRouterTester.kt
  7. +1 −1 misk-eventrouter/src/main/kotlin/misk/eventrouter/EventRouterTestingModule.kt
  8. +2 −1 misk-eventrouter/src/main/kotlin/misk/eventrouter/FakeClusterConnector.kt
  9. +2 −1 misk-eventrouter/src/main/kotlin/misk/eventrouter/FakeClusterMapper.kt
  10. +1 −1 misk-eventrouter/src/main/kotlin/misk/eventrouter/KubernetesClusterConnector.kt
  11. +1 −1 misk-eventrouter/src/main/kotlin/misk/eventrouter/KubernetesHealthCheck.kt
  12. +1 −1 misk-eventrouter/src/main/kotlin/misk/eventrouter/LocalClusterConnector.kt
  13. +2 −1 misk-eventrouter/src/main/kotlin/misk/eventrouter/QueueingExecutorService.kt
  14. +1 −1 misk-eventrouter/src/main/kotlin/misk/eventrouter/RealEventRouter.kt
  15. +2 −5 misk-eventrouter/src/main/kotlin/misk/eventrouter/RealEventRouterModule.kt
  16. +1 −1 misk-eventrouter/src/test/kotlin/misk/eventrouter/EventRouterTest.kt
  17. +6 −1 misk-gcp/src/main/kotlin/misk/cloud/gcp/GoogleCloudModule.kt
  18. +2 −1 misk-gcp/src/main/kotlin/misk/cloud/gcp/security/keys/GcpKeyManagementModule.kt
  19. +2 −1 misk-grpc-tests/src/main/kotlin/misk/grpc/miskserver/GetFeatureGrpcAction.kt
  20. +2 −2 misk-grpc-tests/src/main/kotlin/misk/grpc/miskserver/RouteGuideMiskServiceModule.kt
  21. +1 −3 misk-grpc-tests/src/main/kotlin/misk/grpc/protocclient/GrpcChannelFactory.kt
  22. +1 −2 misk-grpc-tests/src/main/kotlin/misk/grpc/protocclient/ProtocGrpcClientModule.kt
  23. +4 −3 misk-grpc-tests/src/main/kotlin/misk/grpc/protocserver/ProtocGrpcService.kt
  24. +2 −1 misk-grpc-tests/src/main/kotlin/misk/grpc/protocserver/RouteGuideProtocService.kt
  25. +2 −3 misk-hibernate-testing/src/main/kotlin/misk/hibernate/HibernateTestingModule.kt
  26. +1 −1 misk-hibernate/src/main/kotlin/misk/hibernate/HibernateHealthCheckModule.kt
  27. +1 −1 misk-hibernate/src/main/kotlin/misk/hibernate/HibernateInjectorAccess.kt
  28. +2 −1 misk-hibernate/src/main/kotlin/misk/hibernate/QueryTracingListener.kt
  29. +1 −1 misk-hibernate/src/main/kotlin/misk/hibernate/TimestampListener.kt
  30. +1 −0 misk-hibernate/src/test/kotlin/misk/hibernate/EventListenersTest.kt
  31. +2 −1 misk-hibernate/src/test/kotlin/misk/hibernate/FakeEventListener.kt
  32. +1 −1 misk-hibernate/src/test/kotlin/misk/hibernate/MoviesTestModule.kt
  33. +1 −3 misk-hibernate/src/test/kotlin/misk/hibernate/QueryTracingTest.kt
  34. +1 −1 misk-hibernate/src/test/kotlin/misk/hibernate/SchemaMigratorTest.kt
  35. +2 −1 misk-prometheus/src/main/kotlin/misk/metrics/backends/prometheus/PrometheusMetricsModule.kt
  36. +10 −6 misk-redis/src/main/kotlin/misk/redis/RedisModule.kt
  37. +0 −1 misk-testing/src/main/kotlin/misk/concurrent/FakeSleeperModule.kt
  38. +2 −1 misk-testing/src/main/kotlin/misk/logging/RealLogCollector.kt
  39. +2 −2 misk-testing/src/main/kotlin/misk/random/FakeRandom.kt
  40. +0 −1 misk-testing/src/main/kotlin/misk/random/FakeRandomModule.kt
  41. +9 −11 misk-testing/src/main/kotlin/misk/testing/MiskTestExtension.kt
  42. +1 −1 misk-testing/src/main/kotlin/misk/testing/MockTracingBackendModule.kt
  43. +3 −4 misk-testing/src/main/kotlin/misk/testing/TemporaryFolder.kt
  44. +1 −1 misk-testing/src/main/kotlin/misk/time/FakeClockModule.kt
  45. +1 −1 misk-testing/src/main/kotlin/misk/time/FakeTickerModule.kt
  46. +1 −7 misk-testing/src/main/kotlin/misk/web/WebTestingModule.kt
  47. +2 −1 misk-zookeeper/src/main/kotlin/misk/clustering/zookeeper/ZookeeperModule.kt
  48. +8 −7 misk-zookeeper/src/test/kotlin/misk/clustering/zookeeper/ZkTestModule.kt
  49. +1 −0 misk/src/main/kotlin/misk/MiskApplication.kt
  50. +0 −2 misk/src/main/kotlin/misk/MiskServiceModule.kt
  51. +1 −1 misk/src/main/kotlin/misk/client/HttpClientConfigUrlProvider.kt
  52. +4 −3 misk/src/main/kotlin/misk/client/HttpClientFactory.kt
  53. +9 −0 misk/src/main/kotlin/misk/client/HttpClientsConfigModule.kt
  54. +2 −1 misk/src/main/kotlin/misk/clustering/fake/FakeCluster.kt
  55. +2 −1 misk/src/main/kotlin/misk/clustering/fake/lease/FakeLeaseManager.kt
  56. +2 −1 misk/src/main/kotlin/misk/clustering/kubernetes/KubernetesClusterModule.kt
  57. +0 −55 misk/src/main/kotlin/misk/config/ConfigModule.kt
  58. +2 −1 misk/src/main/kotlin/misk/flags/memory/InMemoryFlagStore.kt
  59. +1 −2 misk/src/main/kotlin/misk/flags/memory/InMemoryFlagStoreModule.kt
  60. +4 −0 misk/src/main/kotlin/misk/inject/KAbstractModule.kt
  61. +1 −1 misk/src/main/kotlin/misk/metrics/MetricsModule.kt
  62. +2 −1 misk/src/main/kotlin/misk/moshi/wire/WireMessageAdapter.kt
  63. +1 −1 misk/src/main/kotlin/misk/prometheus/PrometheusHistogramRegistry.kt
  64. +0 −11 misk/src/main/kotlin/misk/random/RandomModule.kt
  65. +2 −1 misk/src/main/kotlin/misk/resources/MemoryResourceLoaderBackend.kt
  66. +2 −2 misk/src/main/kotlin/misk/security/authz/AccessAnnotation.kt
  67. +7 −15 misk/src/main/kotlin/misk/security/authz/FakeCallerAuthenticator.kt
  68. +3 −3 misk/src/main/kotlin/misk/security/ssl/CertificatesModule.kt
  69. +1 −3 misk/src/main/kotlin/misk/security/ssl/SslContextFactory.kt
  70. +2 −1 misk/src/main/kotlin/misk/tokens/FakeTokenGenerator.kt
  71. +2 −1 misk/src/main/kotlin/misk/tokens/RealTokenGenerator.kt
  72. +14 −11 misk/src/main/kotlin/misk/web/MiskWebModule.kt
  73. +38 −10 misk/src/main/kotlin/misk/web/WebActionModule.kt
  74. +3 −1 misk/src/main/kotlin/misk/web/WebConfig.kt
  75. +1 −1 misk/src/main/kotlin/misk/web/actions/AdminDashboardTabAction.kt
  76. +2 −1 misk/src/main/kotlin/misk/web/actions/InternalErrorAction.kt
  77. +2 −1 misk/src/main/kotlin/misk/web/actions/NotFoundAction.kt
  78. +3 −9 misk/src/main/kotlin/misk/web/actions/WebActionEntry.kt
  79. +8 −12 misk/src/main/kotlin/misk/web/actions/WebActionFactory.kt
  80. +1 −1 misk/src/main/kotlin/misk/web/actions/WebActionMetadataAction.kt
  81. +1 −1 misk/src/main/kotlin/misk/web/exceptions/ActionExceptionMapper.kt
  82. +2 −1 misk/src/main/kotlin/misk/web/interceptors/InternalErrorInterceptorFactory.kt
  83. +1 −1 misk/src/main/kotlin/misk/web/interceptors/TracingInterceptor.kt
  84. +2 −2 misk/src/main/kotlin/misk/web/interceptors/WideOpenDevelopmentInterceptor.kt
  85. +3 −2 misk/src/main/kotlin/misk/web/marshal/Grpc.kt
  86. +3 −2 misk/src/main/kotlin/misk/web/marshal/PlainText.kt
  87. +3 −2 misk/src/main/kotlin/misk/web/marshal/Protobuf.kt
  88. +5 −5 misk/src/main/kotlin/misk/web/metadata/AdminDashboardModule.kt
  89. +4 −5 misk/src/main/kotlin/misk/web/metadata/WebTabResourceModule.kt
  90. +1 −1 misk/src/main/kotlin/misk/web/proxy/WebProxyAction.kt
  91. +4 −0 misk/src/test/java/misk/web/extractors/JavaPathParamDispatchTest.java
  92. +3 −3 misk/src/test/kotlin/misk/client/ClientMetricsInterceptorTest.kt
  93. +3 −4 misk/src/test/kotlin/misk/client/HttpClientEventListenerTest.kt
  94. +3 −3 misk/src/test/kotlin/misk/client/ProtoMessageHttpClientTest.kt
  95. +2 −1 misk/src/test/kotlin/misk/client/TestDino.kt
  96. +3 −3 misk/src/test/kotlin/misk/client/TypedHttpClientInterceptorTest.kt
  97. +5 −5 misk/src/test/kotlin/misk/client/TypedHttpClientTest.kt
  98. +2 −3 misk/src/test/kotlin/misk/clustering/kubernetes/KubernetesClusterTest.kt
  99. +0 −28 misk/src/test/kotlin/misk/config/MiskConfigTest.kt
  100. +0 −21 misk/src/test/kotlin/misk/config/SecretConfigTest.kt
  101. +0 −2 misk/src/test/kotlin/misk/config/SecretTestConfigs.kt
  102. +3 −3 misk/src/test/kotlin/misk/grpc/GrpcConnectivityTest.kt
  103. +2 −1 misk/src/test/kotlin/misk/healthchecks/FakeHealthCheck.kt
  104. +42 −0 misk/src/test/kotlin/misk/inject/MultiBinderTest.kt
  105. +2 −1 misk/src/test/kotlin/misk/security/ssl/SslLoaderTest.kt
  106. +2 −1 misk/src/test/kotlin/misk/services/FakeService.kt
  107. +8 −13 misk/src/test/kotlin/misk/tracing/ClientServerTraceTest.kt
  108. +1 −2 misk/src/test/kotlin/misk/web/ActionScopedWebDispatchTest.kt
  109. +16 −17 misk/src/test/kotlin/misk/web/ContentBasedDispatchTest.kt
  110. +6 −7 misk/src/test/kotlin/misk/web/DeterministicRoutingTest.kt
  111. +4 −5 misk/src/test/kotlin/misk/web/JettyServiceMetricsTest.kt
  112. +11 −11 misk/src/test/kotlin/misk/web/WebDispatchTest.kt
  113. +2 −3 misk/src/test/kotlin/misk/web/WebSocketsTest.kt
  114. +2 −1 misk/src/test/kotlin/misk/web/actions/DefaultActionsWithWithAccessControlModuleTest.kt
  115. +3 −1 misk/src/test/kotlin/misk/web/actions/LivenessCheckActionTest.kt
  116. +2 −1 misk/src/test/kotlin/misk/web/actions/NotFoundActionTest.kt
  117. +3 −1 misk/src/test/kotlin/misk/web/actions/ReadinessCheckActionTest.kt
  118. +3 −1 misk/src/test/kotlin/misk/web/actions/StatusActionTest.kt
  119. +5 −4 misk/src/test/kotlin/misk/web/actions/TestWebActionModule.kt
  120. +5 −5 misk/src/test/kotlin/misk/web/exceptions/ExceptionMapperTest.kt
  121. +11 −11 misk/src/test/kotlin/misk/web/extractors/FormValueParameterTest.kt
  122. +5 −5 misk/src/test/kotlin/misk/web/extractors/PathParamDispatchTest.kt
  123. +9 −9 misk/src/test/kotlin/misk/web/extractors/QueryStringRequestTest.kt
  124. +5 −3 misk/src/test/kotlin/misk/web/interceptors/MetricsInterceptorTest.kt
  125. +3 −3 misk/src/test/kotlin/misk/web/interceptors/RequestLogContextInterceptorTest.kt
  126. +11 −11 misk/src/test/kotlin/misk/web/interceptors/RequestLoggingInterceptorTest.kt
  127. +9 −6 misk/src/test/kotlin/misk/web/interceptors/TracingInterceptorTest.kt
  128. +3 −3 misk/src/test/kotlin/misk/web/interceptors/UserInterceptorTest.kt
  129. +7 −7 misk/src/test/kotlin/misk/web/marshal/JsonRequestTest.kt
  130. +17 −17 misk/src/test/kotlin/misk/web/marshal/JsonResponseTest.kt
  131. +5 −5 misk/src/test/kotlin/misk/web/marshal/PlainTextRequestTest.kt
  132. +17 −17 misk/src/test/kotlin/misk/web/marshal/PlainTextResponseTest.kt
  133. +3 −2 misk/src/test/kotlin/misk/web/proxy/WebProxyActionTest.kt
  134. +12 −19 misk/src/test/kotlin/misk/web/resource/StaticResourceActionTest.kt
  135. +3 −3 misk/src/test/kotlin/misk/web/ssl/Http2ConnectivityTest.kt
  136. +5 −5 misk/src/test/kotlin/misk/web/ssl/JceksSslClientServerTest.kt
  137. +3 −3 misk/src/test/kotlin/misk/web/ssl/PemSslClientServerTest.kt
  138. +0 −2 misk/src/test/resources/secret_config_app-common.yaml
  139. +1 −1 samples/exemplar/src/main/java/com/squareup/exemplar/ExemplarJavaApp.java
  140. +4 −4 samples/exemplar/src/main/kotlin/com/squareup/exemplar/ExemplarModule.kt
  141. +2 −2 samples/exemplar/src/main/kotlin/com/squareup/exemplar/ExemplarService.kt
  142. +2 −1 samples/exemplar/src/main/kotlin/com/squareup/exemplar/actions/EchoFormAction.kt
  143. +2 −1 samples/exemplar/src/main/kotlin/com/squareup/exemplar/actions/HelloWebAction.kt
  144. +2 −1 samples/exemplar/src/main/kotlin/com/squareup/exemplar/actions/HelloWebPostAction.kt
  145. +1 −3 samples/exemplar/src/test/kotlin/com/squareup/exemplar/HelloWebActionTest.kt
  146. +4 −4 samples/exemplarchat/src/main/kotlin/com/squareup/chat/ChatModule.kt
  147. +2 −2 samples/exemplarchat/src/main/kotlin/com/squareup/chat/ChatService.kt
  148. +1 −2 samples/exemplarchat/src/main/kotlin/com/squareup/chat/actions/ChatWebSocketAction.kt
  149. +1 −1 samples/exemplarchat/src/main/kotlin/com/squareup/chat/actions/ToggleManualHealthCheckAction.kt
  150. +6 −1 samples/exemplarchat/src/test/kotlin/com/squareup/chat/ChatWebSocketActionTest.kt
@@ -1,5 +1,7 @@
package misk.jobqueue.sqs

import misk.config.Config

/**
* [AwsSqsJobQueueConfig] is the configuration for job queueing backed by Amazon's
* Simple Queuing Service
@@ -10,4 +12,4 @@ class AwsSqsJobQueueConfig(
* at a time, so this parameter controls how many fetches of 10 are outstanding at any one time.
*/
val concurrent_receivers_per_queue: Int = 1
)
): Config
@@ -16,10 +16,13 @@ import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors

/** [AwsSqsJobQueueModule] installs job queue support provided by SQS */
class AwsSqsJobQueueModule : KAbstractModule() {
class AwsSqsJobQueueModule(private val config: AwsSqsJobQueueConfig) : KAbstractModule() {
override fun configure() {
requireBinding(AWSCredentialsProvider::class.java)
requireBinding(AwsRegion::class.java)

bind<AwsSqsJobQueueConfig>().toInstance(config)

bind<JobConsumer>().to<SqsJobConsumer>()
bind<JobQueue>().to<SqsJobQueue>()
bind<TransactionalJobQueue>().to<SqsTransactionalJobQueue>()
@@ -236,7 +236,7 @@ internal class SqsJobQueueTest {
multibind<Service>().to<DockerSqs.Service>()
install(MiskTestingServiceModule())
install(MockTracingBackendModule())
install(Modules.override(AwsSqsJobQueueModule()).with(SQSTestModule()))
install(Modules.override(AwsSqsJobQueueModule(AwsSqsJobQueueConfig())).with(SQSTestModule()))
}
}

@@ -2,10 +2,11 @@ package misk.eventrouter

import com.google.common.hash.HashFunction
import com.google.common.hash.Hashing
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class ConsistentHashing(
class ConsistentHashing @Inject constructor(
private val hashFunction: HashFunction = Hashing.murmur3_32(),
private val mod: Long = 65536L,
private val virtualPoints: Int = 16
@@ -8,7 +8,7 @@ import javax.inject.Inject
import javax.inject.Singleton

@Singleton
internal class EventRouterConnectionAction : WebAction {
internal class EventRouterConnectionAction @Inject constructor() : WebAction {
@Inject lateinit var realEventRouter: RealEventRouter

@ConnectWebSocket("/eventrouter")
@@ -2,7 +2,7 @@ package misk.eventrouter

import javax.inject.Inject

class EventRouterTester {
class EventRouterTester @Inject constructor() {
@Inject private lateinit var fakeClusterConnector: FakeClusterConnector

@Inject
@@ -23,7 +23,7 @@ class EventRouterTestingModule internal constructor(val distributed: Boolean) :
private val subscriberExecutor = QueueingExecutorService()

@Singleton
private class TestingService : AbstractIdleService() {
private class TestingService @Inject constructor() : AbstractIdleService() {
@Inject private lateinit var eventRouter: RealEventRouter
@Inject private lateinit var eventRouterTester: EventRouterTester
@Inject private lateinit var clusterMapper: FakeClusterMapper
@@ -5,10 +5,11 @@ import misk.web.actions.WebSocketListener
import okio.ByteString
import java.io.IOException
import java.util.concurrent.LinkedBlockingQueue
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
internal class FakeClusterConnector : ClusterConnector {
internal class FakeClusterConnector @Inject constructor() : ClusterConnector {
val queue = LinkedBlockingQueue<Action>()
private var nextHostId = 1
private val peers = mutableMapOf<String, TopicPeer>()
@@ -1,9 +1,10 @@
package misk.eventrouter

import javax.inject.Inject
import javax.inject.Singleton

@Singleton
internal class FakeClusterMapper : ClusterMapper {
internal class FakeClusterMapper @Inject constructor() : ClusterMapper {
private val mapping = mutableMapOf<List<String>, String>()

fun setOwnerForHostList(hosts: List<String>, host: String) {
@@ -26,7 +26,7 @@ import javax.inject.Singleton
private val logger = getLogger<KubernetesClusterConnector>()

@Singleton
internal class KubernetesClusterConnector : ClusterConnector {
internal class KubernetesClusterConnector @Inject constructor() : ClusterConnector {
@Inject @ForKubernetesWatching lateinit var executor: ExecutorService
@Inject lateinit var config: KubernetesConfig
@Inject lateinit var webConfig: WebConfig
@@ -6,7 +6,7 @@ import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class KubernetesHealthCheck : HealthCheck {
class KubernetesHealthCheck @Inject constructor() : HealthCheck {
@Inject private lateinit var kubernetesClusterConnector: KubernetesClusterConnector

override fun status(): HealthStatus {
@@ -7,7 +7,7 @@ import javax.inject.Inject
import javax.inject.Singleton

@Singleton
internal class LocalClusterConnector : ClusterConnector {
internal class LocalClusterConnector @Inject constructor() : ClusterConnector {
@Inject lateinit var kubernetesConfig: KubernetesConfig

override fun joinCluster(topicPeer: TopicPeer) {
@@ -3,12 +3,13 @@ package misk.eventrouter
import java.util.concurrent.AbstractExecutorService
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.TimeUnit
import javax.inject.Inject

/**
* An executor service that holds enqueued work until explicitly executed. Useful for making tests
* deterministic.
*/
internal class QueueingExecutorService : AbstractExecutorService() {
internal class QueueingExecutorService: AbstractExecutorService() {
private val queue = LinkedBlockingQueue<Runnable>()
private var processing = false

@@ -12,7 +12,7 @@ import javax.inject.Inject

private val logger = getLogger<RealEventRouter>()

internal class RealEventRouter : EventRouter {
internal class RealEventRouter @Inject constructor() : EventRouter {
@Inject lateinit var clusterConnector: ClusterConnector
@Inject lateinit var eventJsonAdapter: JsonAdapter<SocketEvent>
@Inject lateinit var clusterMapper: ClusterMapper
@@ -9,7 +9,7 @@ import misk.inject.KAbstractModule
import misk.inject.asSingleton
import misk.moshi.MoshiAdapterModule
import misk.moshi.adapter
import misk.web.actions.WebActionEntry
import misk.web.WebActionModule
import java.util.concurrent.ExecutorService
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
@@ -30,7 +30,7 @@ class RealEventRouterModule(val environment: Environment) : KAbstractModule() {
}
bind<ClusterMapper>().to<ConsistentHashing>()
install(MoshiAdapterModule(SocketEventJsonAdapter))
multibind<WebActionEntry>().toInstance(WebActionEntry<EventRouterConnectionAction>())
install(WebActionModule.create<EventRouterConnectionAction>())
}

@Provides @Singleton @ForEventRouterActions
@@ -56,7 +56,6 @@ class RealEventRouterModule(val environment: Environment) : KAbstractModule() {
* not run multiple enqueued tasks concurrently! Instead it should have exactly 1 thread always.
*/
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FIELD, AnnotationTarget.FUNCTION)
internal annotation class ForEventRouterActions

@@ -65,11 +64,9 @@ internal annotation class ForEventRouterActions
* onClose).
*/
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FIELD, AnnotationTarget.FUNCTION)
internal annotation class ForEventRouterSubscribers

@Qualifier
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FIELD, AnnotationTarget.FUNCTION)
internal annotation class ForKubernetesWatching
@@ -19,7 +19,7 @@ internal class EventRouterTest {
@Inject lateinit var machineC: RealEventRouter
@Inject lateinit var clusterMapper: FakeClusterMapper
@Inject lateinit var fakeEventRouterProcessor: EventRouterTester
@Inject @ForEventRouterActions
@Inject @field:ForEventRouterActions
lateinit var actionExecutor: QueueingExecutorService

@Test fun helloWorld() {
@@ -22,8 +22,13 @@ import java.nio.file.Paths
import javax.inject.Inject

/** Installs support for talking to real GCP services, either direct or via emulator */
class GoogleCloudModule : KAbstractModule() {
class GoogleCloudModule(
private val datastoreConfig: DatastoreConfig,
private val storageConfig: StorageConfig
) : KAbstractModule() {
override fun configure() {
bind<DatastoreConfig>().toInstance(datastoreConfig)
bind<StorageConfig>().toInstance(storageConfig)
multibind<Service>().to<GoogleCloud>()
}

@@ -10,8 +10,9 @@ import misk.inject.asSingleton
import misk.security.keys.KeyService
import javax.inject.Singleton

class GcpKeyManagementModule : KAbstractModule() {
class GcpKeyManagementModule(private val config: GcpKmsConfig) : KAbstractModule() {
override fun configure() {
bind<GcpKmsConfig>().toInstance(config)
bind<KeyService>().to<GcpKeyService>().asSingleton()
}

@@ -5,8 +5,9 @@ import misk.web.RequestBody
import misk.web.actions.WebAction
import routeguide.Feature
import routeguide.Point
import javax.inject.Inject

class GetFeatureGrpcAction : WebAction {
class GetFeatureGrpcAction @Inject constructor() : WebAction {
@Grpc("/routeguide.RouteGuide/GetFeature")
fun sayHello(@RequestBody point: Point): Feature {
return Feature.Builder()
@@ -2,16 +2,16 @@ package misk.grpc.miskserver

import com.google.inject.Provides
import misk.inject.KAbstractModule
import misk.web.WebActionModule
import misk.web.WebTestingModule
import misk.web.actions.WebActionEntry
import misk.web.jetty.JettyService
import javax.inject.Named

/** A module that runs a Misk gRPC server: Wire protos and a Jetty backend. */
class RouteGuideMiskServiceModule : KAbstractModule() {
override fun configure() {
install(WebTestingModule())
multibind<WebActionEntry>().toInstance(WebActionEntry<GetFeatureGrpcAction>())
install(WebActionModule.create<GetFeatureGrpcAction>())
}

@Provides
@@ -11,9 +11,7 @@ import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class GrpcChannelFactory {
@Inject lateinit var resourceLoader: ResourceLoader

class GrpcChannelFactory @Inject constructor(val resourceLoader: ResourceLoader) {
fun createClientChannel(
serverAddress: SocketAddress,
serverCertResource: String = "classpath:/ssl/server_cert.pem"
@@ -8,8 +8,7 @@ import javax.inject.Named
import javax.inject.Singleton

class ProtocGrpcClientModule : KAbstractModule() {
override fun configure() {
}
override fun configure() {}

@Provides
@Singleton
@@ -14,9 +14,10 @@ import javax.inject.Singleton
* does gRPC, but it should be useful to confirm interoperability.
*/
@Singleton
class ProtocGrpcService : AbstractIdleService() {
@Inject lateinit var services: List<BindableService>
@Inject lateinit var resourceLoader: ResourceLoader
class ProtocGrpcService @Inject constructor(
private val services: List<BindableService>,
private val resourceLoader: ResourceLoader
): AbstractIdleService() {

lateinit var server: Server

@@ -4,10 +4,11 @@ import io.grpc.stub.StreamObserver
import routeguide.RouteGuideGrpc.RouteGuideImplBase
import routeguide.RouteGuideProto.Feature
import routeguide.RouteGuideProto.Point
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
internal class RouteGuideProtocService : RouteGuideImplBase() {
internal class RouteGuideProtocService @Inject constructor() : RouteGuideImplBase() {
override fun getFeature(point: Point, responseObserver: StreamObserver<Feature>) {
responseObserver.onNext(Feature.newBuilder()
.setName("pine tree")
@@ -7,9 +7,9 @@ import misk.inject.asSingleton
import misk.inject.toKey
import misk.jdbc.DataSourceConfig
import misk.jdbc.DataSourceDecorator
import misk.vitess.StartVitessService
import misk.jdbc.TruncateTablesService
import misk.jdbc.VitessScaleSafetyChecks
import misk.vitess.StartVitessService
import okhttp3.OkHttpClient
import javax.inject.Provider
import kotlin.reflect.KClass
@@ -41,12 +41,11 @@ class HibernateTestingModule(
val transacterProvider = getProvider(transacterKey)

val moshiProvider = getProvider(Moshi::class.java)
val okHttpClientProvider = getProvider(OkHttpClient::class.java)
bind(crossShardQueryDetectorKey).toProvider(Provider<VitessScaleSafetyChecks> {
VitessScaleSafetyChecks(
config = configProvider.get(),
moshi = moshiProvider.get(),
okHttpClient = okHttpClientProvider.get(),
okHttpClient = OkHttpClient(),
startVitessService = startVitessServiceProvider.get()
)
}).asSingleton()
@@ -1,9 +1,9 @@
package misk.hibernate

import misk.jdbc.DataSourceConfig
import misk.healthchecks.HealthCheck
import misk.inject.KAbstractModule
import misk.inject.asSingleton
import misk.jdbc.DataSourceConfig
import org.hibernate.SessionFactory
import java.time.Clock
import javax.inject.Inject
@@ -16,7 +16,7 @@ import javax.inject.Singleton
* ```
*/
@Singleton
internal class HibernateInjectorAccess : org.hibernate.service.Service,
internal class HibernateInjectorAccess @Inject constructor() : org.hibernate.service.Service,
StandardServiceInitiator<HibernateInjectorAccess> {
@Inject lateinit var injector: Injector

@@ -19,6 +19,7 @@ import org.hibernate.event.spi.PreInsertEventListener
import org.hibernate.event.spi.PreUpdateEvent
import org.hibernate.event.spi.PreUpdateEventListener
import org.hibernate.persister.entity.EntityPersister
import javax.inject.Inject
import javax.inject.Singleton

private val logger = getLogger<QueryTracingListener>()
@@ -32,7 +33,7 @@ private val logger = getLogger<QueryTracingListener>()
* {@see misk.hibernate.ReflectionQuery}.
*/
@Singleton
internal class QueryTracingListener
internal class QueryTracingListener @Inject constructor()
: PreInsertEventListener,
PostInsertEventListener,
PreUpdateEventListener,
@@ -9,7 +9,7 @@ import javax.inject.Inject
import javax.inject.Singleton

@Singleton
internal class TimestampListener : PreInsertEventListener, PreUpdateEventListener {
internal class TimestampListener @Inject constructor() : PreInsertEventListener, PreUpdateEventListener {
@Inject lateinit var clock: Clock

override fun onPreInsert(event: PreInsertEvent): Boolean {
@@ -1,6 +1,7 @@
package misk.hibernate

import com.google.inject.util.Modules
import misk.inject.asSingleton
import misk.testing.MiskTest
import misk.testing.MiskTestModule
import org.assertj.core.api.Assertions.assertThat
@@ -8,10 +8,11 @@ import org.hibernate.event.spi.PreLoadEvent
import org.hibernate.event.spi.PreLoadEventListener
import org.hibernate.event.spi.PreUpdateEvent
import org.hibernate.event.spi.PreUpdateEventListener
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class FakeEventListener
class FakeEventListener @Inject constructor()
: PreLoadEventListener, PreInsertEventListener, PreUpdateEventListener, PreDeleteEventListener {
private val eventLog = mutableListOf<String>()

Oops, something went wrong.

0 comments on commit e82b920

Please sign in to comment.
You can’t perform that action at this time.