From: David ‘Bombe’ Roden Date: Fri, 26 Jul 2019 20:58:15 +0000 (+0200) Subject: ✨ Configure metric registry for injection X-Git-Tag: v81^2~181 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=a8050b466202bb6ddec8430129f728749cdfec1a;p=Sone.git ✨ Configure metric registry for injection --- diff --git a/build.gradle b/build.gradle index dc7878c..877169f 100644 --- a/build.gradle +++ b/build.gradle @@ -51,6 +51,7 @@ dependencies { compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.9.1' compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2' compile group: 'org.jsoup', name: 'jsoup', version: '1.10.2' + compile group: 'io.dropwizard.metrics', name: 'metrics-core', version: '4.1.0' testCompile group: 'org.jetbrains.kotlin', name: 'kotlin-test-junit' testCompile group: 'junit', name: 'junit', version: '4.11' diff --git a/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt b/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt index 31cc54a..8f018f5 100644 --- a/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt +++ b/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt @@ -1,5 +1,6 @@ package net.pterodactylus.sone.main +import com.codahale.metrics.* import com.google.common.base.* import com.google.common.eventbus.* import com.google.inject.* @@ -52,6 +53,7 @@ open class SoneModule(private val sonePlugin: SonePlugin, private val eventBus: bind(Database::class.java).to(MemoryDatabase::class.java).`in`(Singleton::class.java) bind(BaseL10n::class.java).toInstance(sonePlugin.l10n().base) loaders?.let { bind(Loaders::class.java).toInstance(it) } + bind(MetricRegistry::class.java).`in`(Singleton::class.java) bindListener(Matchers.any(), object : TypeListener { override fun hear(typeLiteral: TypeLiteral, typeEncounter: TypeEncounter) { diff --git a/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt b/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt index 6cac0a8..93a041c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt @@ -1,5 +1,6 @@ package net.pterodactylus.sone.main +import com.codahale.metrics.* import com.google.common.base.* import com.google.common.eventbus.* import com.google.inject.Guice.* @@ -210,4 +211,16 @@ class SoneModuleTest { verify(eventBus).register(core) } + @Test + fun `metrics registry can be created`() { + assertThat(injector.getInstance(), notNullValue()) + } + + @Test + fun `metrics registry is created as singleton`() { + val firstMetricRegistry = injector.getInstance() + val secondMetricRegistry = injector.getInstance() + assertThat(firstMetricRegistry, sameInstance(secondMetricRegistry)) + } + }