From 8fbb47e633f3ae6a863bfd8131c8de0df10b527d Mon Sep 17 00:00:00 2001 From: Michael Pawliszyn Date: Mon, 16 Oct 2023 11:01:59 -0400 Subject: [PATCH] Move DevelopmentService to test to allow for logging to stdout by default. --- buildSrc/src/main/kotlin/Dependencies.kt | 1 + service-self-backfill/build.gradle.kts | 1 + .../BackfilaSelfBackfillDevelopmentService.kt | 48 +++++++++++++++++++ service/build.gradle.kts | 1 + .../service/BackfilaDevelopmentService.kt | 2 +- 5 files changed, 52 insertions(+), 1 deletion(-) rename service-self-backfill/src/{main => test}/kotlin/app/cash/backfila/service/selfbackfill/BackfilaSelfBackfillDevelopmentService.kt (56%) rename service/src/{main => test}/kotlin/app/cash/backfila/service/BackfilaDevelopmentService.kt (98%) diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 24a8711cc..5124c6ab2 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -40,6 +40,7 @@ object Dependencies { val retrofitWire = "com.squareup.retrofit2:converter-wire:2.9.0" val shadowJarPlugin = "gradle.plugin.com.github.johnrengelman:shadow:7.1.2" val slf4jApi = "org.slf4j:slf4j-api:2.0.3" + val slf4jSimple = "org.slf4j:slf4j-simple:2.0.3" val spotlessPlugin = "com.diffplug.spotless:spotless-plugin-gradle:6.12.0" val tracingJaeger = "io.jaegertracing:jaeger-core:1.1.0" diff --git a/service-self-backfill/build.gradle.kts b/service-self-backfill/build.gradle.kts index 401511225..730312455 100644 --- a/service-self-backfill/build.gradle.kts +++ b/service-self-backfill/build.gradle.kts @@ -70,6 +70,7 @@ dependencies { testImplementation(Dependencies.kotlinxCoroutinesTest) testImplementation(Dependencies.assertj) testImplementation(Dependencies.openTracingMock) + testImplementation(Dependencies.slf4jSimple) testImplementation(project(":backfila-embedded")) } diff --git a/service-self-backfill/src/main/kotlin/app/cash/backfila/service/selfbackfill/BackfilaSelfBackfillDevelopmentService.kt b/service-self-backfill/src/test/kotlin/app/cash/backfila/service/selfbackfill/BackfilaSelfBackfillDevelopmentService.kt similarity index 56% rename from service-self-backfill/src/main/kotlin/app/cash/backfila/service/selfbackfill/BackfilaSelfBackfillDevelopmentService.kt rename to service-self-backfill/src/test/kotlin/app/cash/backfila/service/selfbackfill/BackfilaSelfBackfillDevelopmentService.kt index a456d42ff..7e944eb1b 100644 --- a/service-self-backfill/src/main/kotlin/app/cash/backfila/service/selfbackfill/BackfilaSelfBackfillDevelopmentService.kt +++ b/service-self-backfill/src/test/kotlin/app/cash/backfila/service/selfbackfill/BackfilaSelfBackfillDevelopmentService.kt @@ -1,7 +1,17 @@ package app.cash.backfila.service.selfbackfill +import app.cash.backfila.client.BackfilaClientServiceClient +import app.cash.backfila.client.BackfilaClientServiceClientProvider import app.cash.backfila.client.BackfilaDefaultEndpointConfigModule +import app.cash.backfila.client.ForConnectors import app.cash.backfila.dashboard.ViewLogsUrlProvider +import app.cash.backfila.protos.clientservice.GetNextBatchRangeRequest +import app.cash.backfila.protos.clientservice.GetNextBatchRangeResponse +import app.cash.backfila.protos.clientservice.KeyRange +import app.cash.backfila.protos.clientservice.PrepareBackfillRequest +import app.cash.backfila.protos.clientservice.PrepareBackfillResponse +import app.cash.backfila.protos.clientservice.RunBatchRequest +import app.cash.backfila.protos.clientservice.RunBatchResponse import app.cash.backfila.service.BackfilaConfig import app.cash.backfila.service.BackfilaServiceModule import app.cash.backfila.service.persistence.DbBackfillRun @@ -21,6 +31,7 @@ import misk.security.authz.MiskCallerAuthenticator import misk.web.MiskWebModule import misk.web.WebConfig import misk.web.dashboard.AdminDashboardModule +import okio.ByteString.Companion.encodeUtf8 import wisp.deployment.Deployment internal fun main(args: Array) { @@ -39,6 +50,43 @@ internal fun main(args: Array) { bind().annotatedWith() .toInstance(MiskCaller(user = "testfila")) bind().to() + + newMapBinder(ForConnectors::class) + .permitDuplicates().addBinding("DEV") + .toInstance(object : BackfilaClientServiceClientProvider { + override fun validateExtraData(connectorExtraData: String?) { + } + + override fun clientFor( + serviceName: String, + connectorExtraData: String?, + ): BackfilaClientServiceClient { + return object : BackfilaClientServiceClient { + override fun prepareBackfill(request: PrepareBackfillRequest): PrepareBackfillResponse { + return PrepareBackfillResponse.Builder() + .partitions( + listOf( + PrepareBackfillResponse.Partition( + "-80", KeyRange("0".encodeUtf8(), "1000".encodeUtf8()), null, + ), + PrepareBackfillResponse.Partition( + "80-", KeyRange("0".encodeUtf8(), "1000".encodeUtf8()), null, + ), + ), + ).build() + } + + override suspend fun getNextBatchRange(request: GetNextBatchRangeRequest): GetNextBatchRangeResponse { + TODO("Not yet implemented") + } + + override suspend fun runBatch(request: RunBatchRequest): RunBatchResponse { + TODO("Not yet implemented") + } + } + } + }, + ) } }, DeploymentModule(deployment), diff --git a/service/build.gradle.kts b/service/build.gradle.kts index cb129ab4b..67fcb0459 100644 --- a/service/build.gradle.kts +++ b/service/build.gradle.kts @@ -80,6 +80,7 @@ dependencies { testImplementation(Dependencies.assertj) testImplementation(Dependencies.openTracingMock) testImplementation(Dependencies.okHttpMockWebServer) + testImplementation(Dependencies.slf4jSimple) } val jar by tasks.getting(Jar::class) { diff --git a/service/src/main/kotlin/app/cash/backfila/service/BackfilaDevelopmentService.kt b/service/src/test/kotlin/app/cash/backfila/service/BackfilaDevelopmentService.kt similarity index 98% rename from service/src/main/kotlin/app/cash/backfila/service/BackfilaDevelopmentService.kt rename to service/src/test/kotlin/app/cash/backfila/service/BackfilaDevelopmentService.kt index c105bdc11..29baed09b 100644 --- a/service/src/main/kotlin/app/cash/backfila/service/BackfilaDevelopmentService.kt +++ b/service/src/test/kotlin/app/cash/backfila/service/BackfilaDevelopmentService.kt @@ -118,7 +118,7 @@ fun main(args: Array) { ).run(args) } -class DevelopmentViewLogsUrlProvider : ViewLogsUrlProvider { +internal class DevelopmentViewLogsUrlProvider : ViewLogsUrlProvider { override fun getUrl(session: Session, backfillRun: DbBackfillRun): String { return "/" }