diff --git a/build/repositories.bzl b/build/repositories.bzl index 4969b7f551b..5e53078dd12 100644 --- a/build/repositories.bzl +++ b/build/repositories.bzl @@ -27,8 +27,8 @@ def wfa_measurement_system_repositories(): wfa_repo_archive( name = "wfa_common_jvm", repo = "common-jvm", - sha256 = "71e2051b40c384d5d7f506cc985c5f7aa74292a9a7fddb1f34f5d352f2953032", - version = "0.62.0", + sha256 = "328f4707c79ff1b309784463309f4c5918c6a2fab8c0187efda014f8b3bc79eb", + version = "0.63.0", ) wfa_repo_archive( diff --git a/src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/testing/BUILD.bazel b/src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/testing/BUILD.bazel index d3fc119e0ec..acb5de3d929 100644 --- a/src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/testing/BUILD.bazel +++ b/src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/testing/BUILD.bazel @@ -4,7 +4,7 @@ package( default_testonly = True, default_visibility = [ "//src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres:__subpackages__", - "//src/test/kotlin/org/wfanet/measurement/integration/common/duchy:__pkg__", + "//src/test/kotlin/org/wfanet/measurement/integration:__subpackages__", ], ) diff --git a/src/main/kotlin/org/wfanet/measurement/eventdataprovider/privacybudgetmanagement/deploy/postgres/PostgresBackingStore.kt b/src/main/kotlin/org/wfanet/measurement/eventdataprovider/privacybudgetmanagement/deploy/postgres/PostgresBackingStore.kt index 0f69e21d858..58c9b7f1435 100644 --- a/src/main/kotlin/org/wfanet/measurement/eventdataprovider/privacybudgetmanagement/deploy/postgres/PostgresBackingStore.kt +++ b/src/main/kotlin/org/wfanet/measurement/eventdataprovider/privacybudgetmanagement/deploy/postgres/PostgresBackingStore.kt @@ -35,10 +35,11 @@ private const val MAX_BATCH_INSERT = 1000 * * @param createConnection is a function that creates a postgres JDBC connection that will be owned * by the backing store and should not be used outside this backing store. + * + * TODO(@uakyol): Use R2DBC-based + * [org.wfanet.measurement.common.db.r2dbc.postgres.PostgresDatabaseClient] instead of JDBC. */ class PostgresBackingStore(createConnection: () -> Connection) : PrivacyBudgetLedgerBackingStore { - // TODO(@duliomatos1) : redesign this to reduce connection lifetime, e.g. using a Connection for - // a single transaction/operation and then closing it. private val connection = createConnection() init { connection.autoCommit = false @@ -58,7 +59,6 @@ class PostgresBackingStore(createConnection: () -> Connection) : PrivacyBudgetLe ) } connection.createStatement().use { statement: Statement -> - // TODO(@duliomatos) Make the blocking IO run within a dispatcher using coroutines statement.executeUpdate("begin transaction") return PostgresBackingStoreTransactionContext(connection) } diff --git a/src/main/kotlin/org/wfanet/measurement/integration/common/InProcessCmmsComponents.kt b/src/main/kotlin/org/wfanet/measurement/integration/common/InProcessCmmsComponents.kt index 98ba13e494a..29a5669129d 100644 --- a/src/main/kotlin/org/wfanet/measurement/integration/common/InProcessCmmsComponents.kt +++ b/src/main/kotlin/org/wfanet/measurement/integration/common/InProcessCmmsComponents.kt @@ -40,14 +40,12 @@ import org.wfanet.measurement.loadtest.measurementconsumer.MeasurementConsumerDa import org.wfanet.measurement.loadtest.resourcesetup.DuchyCert import org.wfanet.measurement.loadtest.resourcesetup.EntityContent import org.wfanet.measurement.loadtest.resourcesetup.ResourceSetup -import org.wfanet.measurement.storage.StorageClient import org.wfanet.measurement.system.v1alpha.ComputationLogEntriesGrpcKt.ComputationLogEntriesCoroutineStub class InProcessCmmsComponents( private val kingdomDataServicesRule: ProviderRule, private val duchyDependenciesRule: ProviderRule<(String, ComputationLogEntriesCoroutineStub) -> InProcessDuchy.DuchyDependencies>, - private val storageClient: StorageClient, ) : TestRule { private val kingdomDataServices: DataServices get() = kingdomDataServicesRule.value diff --git a/src/main/kotlin/org/wfanet/measurement/integration/common/InProcessLifeOfAMeasurementIntegrationTest.kt b/src/main/kotlin/org/wfanet/measurement/integration/common/InProcessLifeOfAMeasurementIntegrationTest.kt index b9da8755e08..8b2532e292d 100644 --- a/src/main/kotlin/org/wfanet/measurement/integration/common/InProcessLifeOfAMeasurementIntegrationTest.kt +++ b/src/main/kotlin/org/wfanet/measurement/integration/common/InProcessLifeOfAMeasurementIntegrationTest.kt @@ -33,7 +33,6 @@ import org.wfanet.measurement.kingdom.deploy.common.service.DataServices import org.wfanet.measurement.loadtest.measurementconsumer.MeasurementConsumerData import org.wfanet.measurement.loadtest.measurementconsumer.MeasurementConsumerSimulator import org.wfanet.measurement.loadtest.measurementconsumer.MetadataSyntheticGeneratorEventQuery -import org.wfanet.measurement.storage.StorageClient import org.wfanet.measurement.system.v1alpha.ComputationLogEntriesGrpcKt.ComputationLogEntriesCoroutineStub /** @@ -42,19 +41,15 @@ import org.wfanet.measurement.system.v1alpha.ComputationLogEntriesGrpcKt.Computa * This is abstract so that different implementations of dependencies can all run the same tests * easily. */ -abstract class InProcessLifeOfAMeasurementIntegrationTest { - abstract val kingdomDataServicesRule: ProviderRule - - /** Provides a function from Duchy to the dependencies needed to start the Duchy to the test. */ - abstract val duchyDependenciesRule: +abstract class InProcessLifeOfAMeasurementIntegrationTest( + kingdomDataServicesRule: ProviderRule, + duchyDependenciesRule: ProviderRule<(String, ComputationLogEntriesCoroutineStub) -> InProcessDuchy.DuchyDependencies> - - abstract val storageClient: StorageClient +) { @get:Rule - val inProcessCmmsComponents: InProcessCmmsComponents by lazy { - InProcessCmmsComponents(kingdomDataServicesRule, duchyDependenciesRule, storageClient) - } + val inProcessCmmsComponents = + InProcessCmmsComponents(kingdomDataServicesRule, duchyDependenciesRule) private lateinit var mcSimulator: MeasurementConsumerSimulator diff --git a/src/main/kotlin/org/wfanet/measurement/integration/common/reporting/v2/InProcessLifeOfAReportIntegrationTest.kt b/src/main/kotlin/org/wfanet/measurement/integration/common/reporting/v2/InProcessLifeOfAReportIntegrationTest.kt index c6561a9f3aa..f99ec0e4962 100644 --- a/src/main/kotlin/org/wfanet/measurement/integration/common/reporting/v2/InProcessLifeOfAReportIntegrationTest.kt +++ b/src/main/kotlin/org/wfanet/measurement/integration/common/reporting/v2/InProcessLifeOfAReportIntegrationTest.kt @@ -101,7 +101,6 @@ import org.wfanet.measurement.reporting.v2alpha.periodicTimeInterval import org.wfanet.measurement.reporting.v2alpha.report import org.wfanet.measurement.reporting.v2alpha.reportingSet import org.wfanet.measurement.reporting.v2alpha.timeIntervals -import org.wfanet.measurement.storage.StorageClient import org.wfanet.measurement.system.v1alpha.ComputationLogEntriesGrpcKt /** @@ -110,30 +109,23 @@ import org.wfanet.measurement.system.v1alpha.ComputationLogEntriesGrpcKt * This is abstract so that different implementations of dependencies can all run the same tests * easily. */ -abstract class InProcessLifeOfAReportIntegrationTest { - abstract val kingdomDataServicesRule: ProviderRule - - /** Provides a function from Duchy to the dependencies needed to start the Duchy to the test. */ - abstract val duchyDependenciesRule: +abstract class InProcessLifeOfAReportIntegrationTest( + kingdomDataServicesRule: ProviderRule, + duchyDependenciesRule: ProviderRule< ( String, ComputationLogEntriesGrpcKt.ComputationLogEntriesCoroutineStub ) -> InProcessDuchy.DuchyDependencies > - - abstract val storageClient: StorageClient - - private val inProcessCmmsComponents: InProcessCmmsComponents by lazy { - InProcessCmmsComponents(kingdomDataServicesRule, duchyDependenciesRule, storageClient) - } - - private val inProcessCmmsComponentsStartup: TestRule by lazy { - TestRule { statement, _ -> - object : Statement() { - override fun evaluate() { - inProcessCmmsComponents.startDaemons() - statement.evaluate() - } +) { + private val inProcessCmmsComponents: InProcessCmmsComponents = + InProcessCmmsComponents(kingdomDataServicesRule, duchyDependenciesRule) + + private val inProcessCmmsComponentsStartup = TestRule { base, _ -> + object : Statement() { + override fun evaluate() { + inProcessCmmsComponents.startDaemons() + base.evaluate() } } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/testing/BUILD.bazel b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/testing/BUILD.bazel deleted file mode 100644 index a313c09df11..00000000000 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/testing/BUILD.bazel +++ /dev/null @@ -1,23 +0,0 @@ -load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") - -package(default_visibility = ["//visibility:public"]) - -kt_jvm_library( - name = "schemata", - srcs = [ - "Schemata.kt", - ], - deps = [ - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common", - ], -) - -genrule( - name = "concat_kingdom", - srcs = [ - "exchange.sql", - ], - outs = ["kingdom.sql"], - cmd = "cat $(SRCS) > $@", - visibility = ["//visibility:public"], -) diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/testing/Schemata.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/testing/Schemata.kt deleted file mode 100644 index ce211c6cc30..00000000000 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/testing/Schemata.kt +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2020 The Cross-Media Measurement Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.wfanet.measurement.kingdom.deploy.aws.postgres - -import java.io.File -import java.nio.file.Paths -import org.wfanet.measurement.common.getRuntimePath - -private val SCHEMA_DIR = - Paths.get( - "wfa_measurement_system", - "src", - "main", - "kotlin", - "org", - "wfanet", - "measurement", - "kingdom", - "deploy", - "aws", - "postgres", - "testing", - ) - -val AWS_KINGDOM_SCHEMA_FILE: File = - checkNotNull(getRuntimePath(SCHEMA_DIR.resolve("kingdom.sql"))).toFile() diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/testing/exchange.sql b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/testing/exchange.sql deleted file mode 100644 index 42029ec9a50..00000000000 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/testing/exchange.sql +++ /dev/null @@ -1,27 +0,0 @@ --- Copyright 2020 The Cross-Media Measurement Authors --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. - - --- minimal port of a table from `src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/exchange.sdl` --- for use in testing - -CREATE TABLE ModelProviders ( - PRIMARY KEY (ModelProviderId), - ModelProviderId BIGINT NOT NULL, - - ExternalModelProviderId BIGINT NOT NULL -); - -CREATE UNIQUE INDEX ModelProvidersByExternalId - ON ModelProviders(ExternalModelProviderId); diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2/ReportingSetsServiceTest.kt b/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2/ReportingSetsServiceTest.kt index 8fd34dffde9..f664f4d9b47 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2/ReportingSetsServiceTest.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2/ReportingSetsServiceTest.kt @@ -1611,67 +1611,59 @@ abstract class ReportingSetsServiceTest { measurementConsumersService.createMeasurementConsumer( measurementConsumer { cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID } ) - - val reportingSet = reportingSet { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID - displayName = "displayName" - filter = "filter" - - primitive = - ReportingSetKt.primitive { - eventGroupKeys += - ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsDataProviderId = "1235" - cmmsEventGroupId = "1236" - } - - eventGroupKeys += - ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsDataProviderId = "2235" - cmmsEventGroupId = "2236" - } - } - } - - val reportingSet2 = reportingSet { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID - displayName = "displayName" - filter = "filter" - - primitive = - ReportingSetKt.primitive { - eventGroupKeys += - ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsDataProviderId = "1235" - cmmsEventGroupId = "1236" - } - - eventGroupKeys += - ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsDataProviderId = "2235" - cmmsEventGroupId = "2236" - } - } - } - - val createdReportingSet = + val reportingSet1 = service.createReportingSet( createReportingSetRequest { - this.reportingSet = reportingSet - externalReportingSetId = "reporting-set-id" + externalReportingSetId = "reporting-set-id-1" + reportingSet = reportingSet { + cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID + displayName = "displayName" + filter = "filter" + + primitive = + ReportingSetKt.primitive { + eventGroupKeys += + ReportingSetKt.PrimitiveKt.eventGroupKey { + cmmsDataProviderId = "1235" + cmmsEventGroupId = "1236" + } + + eventGroupKeys += + ReportingSetKt.PrimitiveKt.eventGroupKey { + cmmsDataProviderId = "2235" + cmmsEventGroupId = "2236" + } + } + } } ) - val createdReportingSet2 = + val reportingSet2 = service.createReportingSet( createReportingSetRequest { - this.reportingSet = reportingSet2 - externalReportingSetId = "reportingSet2" + externalReportingSetId = "reporting-set-id-2" + reportingSet = reportingSet { + cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID + displayName = "displayName" + filter = "filter" + + primitive = + ReportingSetKt.primitive { + eventGroupKeys += + ReportingSetKt.PrimitiveKt.eventGroupKey { + cmmsDataProviderId = "1235" + cmmsEventGroupId = "1236" + } + + eventGroupKeys += + ReportingSetKt.PrimitiveKt.eventGroupKey { + cmmsDataProviderId = "2235" + cmmsEventGroupId = "2236" + } + } + } } ) - val afterId = - minOf(createdReportingSet.externalReportingSetId, createdReportingSet2.externalReportingSetId) - val retrievedReportingSets = service .streamReportingSets( @@ -1679,47 +1671,13 @@ abstract class ReportingSetsServiceTest { filter = StreamReportingSetsRequestKt.filter { cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID - externalReportingSetIdAfter = afterId + externalReportingSetIdAfter = reportingSet1.externalReportingSetId } } ) .toList() - if (createdReportingSet.externalReportingSetId == afterId) { - assertThat(retrievedReportingSets) - .ignoringRepeatedFieldOrder() - .containsExactly( - reportingSet.copy { - externalReportingSetId = createdReportingSet2.externalReportingSetId - weightedSubsetUnions += - ReportingSetKt.weightedSubsetUnion { - weight = 1 - primitiveReportingSetBases += - ReportingSetKt.primitiveReportingSetBasis { - this.externalReportingSetId = createdReportingSet2.externalReportingSetId - filters += reportingSet.filter - } - } - } - ) - } else { - assertThat(retrievedReportingSets) - .ignoringRepeatedFieldOrder() - .containsExactly( - reportingSet2.copy { - externalReportingSetId = createdReportingSet.externalReportingSetId - weightedSubsetUnions += - ReportingSetKt.weightedSubsetUnion { - weight = 1 - primitiveReportingSetBases += - ReportingSetKt.primitiveReportingSetBasis { - this.externalReportingSetId = createdReportingSet.externalReportingSetId - filters += reportingSet.filter - } - } - } - ) - } + assertThat(retrievedReportingSets).containsExactly(reportingSet2) } @Test @@ -1727,63 +1685,57 @@ abstract class ReportingSetsServiceTest { measurementConsumersService.createMeasurementConsumer( measurementConsumer { cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID } ) - - val reportingSet = reportingSet { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID - displayName = "displayName" - filter = "filter" - - primitive = - ReportingSetKt.primitive { - eventGroupKeys += - ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsDataProviderId = "1235" - cmmsEventGroupId = "1236" - } - - eventGroupKeys += - ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsDataProviderId = "2235" - cmmsEventGroupId = "2236" - } - } - } - - val reportingSet2 = reportingSet { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID - displayName = "displayName" - filter = "filter" - - primitive = - ReportingSetKt.primitive { - eventGroupKeys += - ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsDataProviderId = "1235" - cmmsEventGroupId = "1236" - } - - eventGroupKeys += - ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsDataProviderId = "2235" - cmmsEventGroupId = "2236" - } - } - } - - val createdReportingSet = + val reportingSet1 = service.createReportingSet( createReportingSetRequest { - this.reportingSet = reportingSet - externalReportingSetId = "reporting-set-id" + externalReportingSetId = "reporting-set-id-1" + reportingSet = reportingSet { + cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID + displayName = "displayName" + filter = "filter" + + primitive = + ReportingSetKt.primitive { + eventGroupKeys += + ReportingSetKt.PrimitiveKt.eventGroupKey { + cmmsDataProviderId = "1235" + cmmsEventGroupId = "1236" + } + + eventGroupKeys += + ReportingSetKt.PrimitiveKt.eventGroupKey { + cmmsDataProviderId = "2235" + cmmsEventGroupId = "2236" + } + } + } } ) - val createdReportingSet2 = - service.createReportingSet( - createReportingSetRequest { - this.reportingSet = reportingSet2 - externalReportingSetId = "reportingSet2" + service.createReportingSet( + createReportingSetRequest { + externalReportingSetId = "reporting-set-id-2" + reportingSet = reportingSet { + cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID + displayName = "displayName" + filter = "filter" + + primitive = + ReportingSetKt.primitive { + eventGroupKeys += + ReportingSetKt.PrimitiveKt.eventGroupKey { + cmmsDataProviderId = "1235" + cmmsEventGroupId = "1236" + } + + eventGroupKeys += + ReportingSetKt.PrimitiveKt.eventGroupKey { + cmmsDataProviderId = "2235" + cmmsEventGroupId = "2236" + } + } } - ) + } + ) val retrievedReportingSets = service @@ -1798,41 +1750,7 @@ abstract class ReportingSetsServiceTest { ) .toList() - if (createdReportingSet.externalReportingSetId < createdReportingSet2.externalReportingSetId) { - assertThat(retrievedReportingSets) - .ignoringRepeatedFieldOrder() - .containsExactly( - reportingSet.copy { - externalReportingSetId = createdReportingSet.externalReportingSetId - weightedSubsetUnions += - ReportingSetKt.weightedSubsetUnion { - weight = 1 - primitiveReportingSetBases += - ReportingSetKt.primitiveReportingSetBasis { - this.externalReportingSetId = createdReportingSet.externalReportingSetId - filters += reportingSet.filter - } - } - } - ) - } else { - assertThat(retrievedReportingSets) - .ignoringRepeatedFieldOrder() - .containsExactly( - reportingSet2.copy { - externalReportingSetId = createdReportingSet2.externalReportingSetId - weightedSubsetUnions += - ReportingSetKt.weightedSubsetUnion { - weight = 1 - primitiveReportingSetBases += - ReportingSetKt.primitiveReportingSetBasis { - this.externalReportingSetId = createdReportingSet2.externalReportingSetId - filters += reportingSet.filter - } - } - } - ) - } + assertThat(retrievedReportingSets).containsExactly(reportingSet1) } @Test diff --git a/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/BUILD.bazel b/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/BUILD.bazel index 20222ec0d1d..d9171215e57 100644 --- a/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/BUILD.bazel +++ b/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/BUILD.bazel @@ -7,9 +7,8 @@ kt_jvm_test( deps = [ "//src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/testing", "@wfa_common_jvm//imports/java/com/google/common/truth", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", "@wfa_common_jvm//imports/java/org/junit", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:embedded_postgres", + "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:database_provider", ], ) @@ -22,9 +21,8 @@ kt_jvm_test( "//src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/testing", "//src/main/kotlin/org/wfanet/measurement/duchy/service/internal/testing", "@wfa_common_jvm//imports/java/com/google/common/truth", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", "@wfa_common_jvm//imports/java/org/junit", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:embedded_postgres", + "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:database_provider", ], ) @@ -39,9 +37,8 @@ kt_jvm_test( "//src/main/kotlin/org/wfanet/measurement/duchy/service/internal/computations", "//src/main/kotlin/org/wfanet/measurement/duchy/service/internal/testing", "@wfa_common_jvm//imports/java/com/google/common/truth", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", "@wfa_common_jvm//imports/java/org/junit", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:embedded_postgres", + "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:database_provider", "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/storage/filesystem:client", ], ) @@ -57,9 +54,8 @@ kt_jvm_test( "//src/main/kotlin/org/wfanet/measurement/duchy/service/internal/computations", "//src/main/kotlin/org/wfanet/measurement/duchy/service/internal/testing", "@wfa_common_jvm//imports/java/com/google/common/truth", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", "@wfa_common_jvm//imports/java/org/junit", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:embedded_postgres", + "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:database_provider", "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/storage/filesystem:client", ], ) diff --git a/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/DuchySchemaTest.kt b/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/DuchySchemaTest.kt index 526c6365b86..2c66a32f268 100644 --- a/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/DuchySchemaTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/DuchySchemaTest.kt @@ -17,17 +17,19 @@ package org.wfanet.measurement.duchy.deploy.common.postgres import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.flow.toList import kotlinx.coroutines.runBlocking +import org.junit.ClassRule import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 import org.wfanet.measurement.common.db.r2dbc.ResultRow import org.wfanet.measurement.common.db.r2dbc.boundStatement -import org.wfanet.measurement.common.db.r2dbc.postgres.testing.EmbeddedPostgresDatabaseProvider -import org.wfanet.measurement.duchy.deploy.common.postgres.testing.Schemata.DUCHY_CHANGELOG_PATH +import org.wfanet.measurement.common.db.r2dbc.postgres.PostgresDatabaseClient +import org.wfanet.measurement.common.db.r2dbc.postgres.testing.PostgresDatabaseProviderRule +import org.wfanet.measurement.duchy.deploy.common.postgres.testing.Schemata @RunWith(JUnit4::class) class DuchySchemaTest { - val databaseClient = EmbeddedPostgresDatabaseProvider(DUCHY_CHANGELOG_PATH).createNewDatabase() + val databaseClient: PostgresDatabaseClient = databaseProvider.createDatabase() private fun translate(row: ResultRow): String = row["table_name"] @@ -54,4 +56,10 @@ class DuchySchemaTest { assertThat(resList).containsAtLeastElementsIn(duchyTableNames) } + + companion object { + @get:ClassRule + @JvmStatic + val databaseProvider = PostgresDatabaseProviderRule(Schemata.DUCHY_CHANGELOG_PATH) + } } diff --git a/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/PostgresComputationStatsServiceTest.kt b/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/PostgresComputationStatsServiceTest.kt index 3c15218f797..9ef6838c114 100644 --- a/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/PostgresComputationStatsServiceTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/PostgresComputationStatsServiceTest.kt @@ -16,11 +16,13 @@ package org.wfanet.measurement.duchy.deploy.common.postgres import java.time.Clock import kotlin.random.Random +import org.junit.ClassRule import org.junit.Rule import org.junit.rules.TemporaryFolder import org.junit.runner.RunWith import org.junit.runners.JUnit4 -import org.wfanet.measurement.common.db.r2dbc.postgres.testing.EmbeddedPostgresDatabaseProvider +import org.wfanet.measurement.common.db.r2dbc.postgres.PostgresDatabaseClient +import org.wfanet.measurement.common.db.r2dbc.postgres.testing.PostgresDatabaseProviderRule import org.wfanet.measurement.common.grpc.testing.GrpcTestServerRule import org.wfanet.measurement.common.grpc.testing.mockService import org.wfanet.measurement.common.identity.RandomIdGenerator @@ -28,7 +30,7 @@ import org.wfanet.measurement.common.testing.chainRulesSequentially import org.wfanet.measurement.duchy.db.computation.ComputationProtocolStageDetails import org.wfanet.measurement.duchy.db.computation.ComputationProtocolStages import org.wfanet.measurement.duchy.db.computation.ComputationTypes -import org.wfanet.measurement.duchy.deploy.common.postgres.testing.Schemata.DUCHY_CHANGELOG_PATH +import org.wfanet.measurement.duchy.deploy.common.postgres.testing.Schemata import org.wfanet.measurement.duchy.service.internal.testing.ComputationStatsServiceTest import org.wfanet.measurement.duchy.storage.ComputationStore import org.wfanet.measurement.duchy.storage.RequisitionStore @@ -50,7 +52,7 @@ class PostgresComputationStatsServiceTest : private val mockComputationLogEntriesService: ComputationLogEntriesCoroutineImplBase = mockService() - private val client = EmbeddedPostgresDatabaseProvider(DUCHY_CHANGELOG_PATH).createNewDatabase() + private val client: PostgresDatabaseClient = databaseProvider.createDatabase() private val idGenerator = RandomIdGenerator(Clock.systemUTC(), Random(1)) private val grpcTestServerRule = GrpcTestServerRule { @@ -80,4 +82,10 @@ class PostgresComputationStatsServiceTest : computationLogEntriesClient = systemComputationLogEntriesClient, ) } + + companion object { + @get:ClassRule + @JvmStatic + val databaseProvider = PostgresDatabaseProviderRule(Schemata.DUCHY_CHANGELOG_PATH) + } } diff --git a/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/PostgresComputationsServiceTest.kt b/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/PostgresComputationsServiceTest.kt index 7939b4f4807..330eb63c6b0 100644 --- a/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/PostgresComputationsServiceTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/PostgresComputationsServiceTest.kt @@ -16,11 +16,13 @@ package org.wfanet.measurement.duchy.deploy.common.postgres import java.time.Clock import kotlin.random.Random +import org.junit.ClassRule import org.junit.Rule import org.junit.rules.TemporaryFolder import org.junit.runner.RunWith import org.junit.runners.JUnit4 -import org.wfanet.measurement.common.db.r2dbc.postgres.testing.EmbeddedPostgresDatabaseProvider +import org.wfanet.measurement.common.db.r2dbc.postgres.PostgresDatabaseClient +import org.wfanet.measurement.common.db.r2dbc.postgres.testing.PostgresDatabaseProviderRule import org.wfanet.measurement.common.grpc.testing.GrpcTestServerRule import org.wfanet.measurement.common.grpc.testing.mockService import org.wfanet.measurement.common.identity.RandomIdGenerator @@ -28,7 +30,7 @@ import org.wfanet.measurement.common.testing.chainRulesSequentially import org.wfanet.measurement.duchy.db.computation.ComputationProtocolStageDetails import org.wfanet.measurement.duchy.db.computation.ComputationProtocolStages import org.wfanet.measurement.duchy.db.computation.ComputationTypes -import org.wfanet.measurement.duchy.deploy.common.postgres.testing.Schemata.DUCHY_CHANGELOG_PATH +import org.wfanet.measurement.duchy.deploy.common.postgres.testing.Schemata import org.wfanet.measurement.duchy.service.internal.testing.ComputationsServiceTest import org.wfanet.measurement.duchy.storage.ComputationStore import org.wfanet.measurement.duchy.storage.RequisitionStore @@ -48,7 +50,7 @@ class PostgresComputationsServiceTest : ComputationsServiceTest() { + override fun newService(): PostgresContinuationTokensService { - val client = EmbeddedPostgresDatabaseProvider(DUCHY_CHANGELOG_PATH).createNewDatabase() + val client: PostgresDatabaseClient = databaseProvider.createDatabase() val idGenerator = RandomIdGenerator(Clock.systemUTC(), Random(1)) return PostgresContinuationTokensService(client, idGenerator) } + + companion object { + @get:ClassRule + @JvmStatic + val databaseProvider = PostgresDatabaseProviderRule(Schemata.DUCHY_CHANGELOG_PATH) + } } diff --git a/src/test/kotlin/org/wfanet/measurement/eventdataprovider/privacybudgetmanagement/deploy/postgres/BUILD.bazel b/src/test/kotlin/org/wfanet/measurement/eventdataprovider/privacybudgetmanagement/deploy/postgres/BUILD.bazel index 800c1c5e8f9..0193da9e1fd 100644 --- a/src/test/kotlin/org/wfanet/measurement/eventdataprovider/privacybudgetmanagement/deploy/postgres/BUILD.bazel +++ b/src/test/kotlin/org/wfanet/measurement/eventdataprovider/privacybudgetmanagement/deploy/postgres/BUILD.bazel @@ -8,6 +8,7 @@ kt_jvm_test( ], test_class = "org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.deploy.postgres.PostgresBackingStoreTest", runtime_deps = [ + "@wfa_common_jvm//imports/java/org/postgresql:j2dbc", # Workaround for `NoClassDefFoundError: kotlin/jdk7/AutoCloseableKt`. # See https://github.com/bazelbuild/rules_kotlin/issues/333 "@wfa_common_jvm//imports/kotlin/kotlin:stdlib_jdk7", @@ -16,6 +17,6 @@ kt_jvm_test( "//src/main/kotlin/org/wfanet/measurement/eventdataprovider/privacybudgetmanagement/deploy/postgres", "//src/main/kotlin/org/wfanet/measurement/eventdataprovider/privacybudgetmanagement/testing", "//src/main/kotlin/org/wfanet/measurement/integration/deploy/postgres:schemata", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", + "@wfa_common_jvm//imports/java/org/testcontainers/containers:postgresql", ], ) diff --git a/src/test/kotlin/org/wfanet/measurement/eventdataprovider/privacybudgetmanagement/deploy/postgres/PostgresBackingStoreTest.kt b/src/test/kotlin/org/wfanet/measurement/eventdataprovider/privacybudgetmanagement/deploy/postgres/PostgresBackingStoreTest.kt index 6353550c98a..6fdcb084a9c 100644 --- a/src/test/kotlin/org/wfanet/measurement/eventdataprovider/privacybudgetmanagement/deploy/postgres/PostgresBackingStoreTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/eventdataprovider/privacybudgetmanagement/deploy/postgres/PostgresBackingStoreTest.kt @@ -13,46 +13,19 @@ */ package org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.deploy.postgres -import com.opentable.db.postgres.embedded.EmbeddedPostgres import java.sql.Connection import java.sql.Statement -import org.junit.AfterClass -import org.junit.BeforeClass +import org.junit.ClassRule import org.junit.runner.RunWith import org.junit.runners.JUnit4 +import org.testcontainers.containers.PostgreSQLContainer import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.PrivacyBudgetLedgerBackingStore import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.testing.AbstractPrivacyBudgetLedgerStoreTest import src.main.kotlin.org.wfanet.measurement.integration.deploy.postgres.POSTGRES_LEDGER_SCHEMA_FILE @RunWith(JUnit4::class) class PostgresBackingStoreTest : AbstractPrivacyBudgetLedgerStoreTest() { - companion object { - private const val TEST_DB = "junit_testing" - private const val PG_USER_NAME = "postgres" - - @JvmStatic private val schema = POSTGRES_LEDGER_SCHEMA_FILE.readText() - @JvmStatic private lateinit var embeddedPostgres: EmbeddedPostgres - - @JvmStatic - @BeforeClass - fun initDatabase() { - embeddedPostgres = EmbeddedPostgres.start() - embeddedPostgres.postgresDatabase.connection.use { connection -> - connection.createStatement().use { statement: Statement -> - statement.executeUpdate("CREATE DATABASE $TEST_DB") - } - } - } - - @JvmStatic - @AfterClass - fun closeDataBase() { - embeddedPostgres.close() - } - } - - private fun createConnection(): Connection = - embeddedPostgres.getDatabase(PG_USER_NAME, TEST_DB).connection + private fun createConnection(): Connection = postgresContainer.createConnection("") override fun recreateSchema() { createConnection().use { connection -> @@ -68,7 +41,7 @@ class PostgresBackingStoreTest : AbstractPrivacyBudgetLedgerStoreTest() { """ .trimIndent() ) - statement.executeUpdate(schema) + statement.executeUpdate(SCHEMA) } } } @@ -76,4 +49,20 @@ class PostgresBackingStoreTest : AbstractPrivacyBudgetLedgerStoreTest() { override fun createBackingStore(): PrivacyBudgetLedgerBackingStore { return PostgresBackingStore(::createConnection) } + + companion object { + private const val POSTGRES_IMAGE_NAME = "postgres:15" + + private val SCHEMA by lazy { POSTGRES_LEDGER_SCHEMA_FILE.readText() } + + /** + * PostgreSQL test container. + * + * TODO(@uakyol): Use [org.wfanet.measurement.common.db.r2dbc.postgres.testing.PostgresDatabaseProviderRule] + * instead of referencing TestContainers directly. + */ + @get:ClassRule + @JvmStatic + val postgresContainer = PostgreSQLContainer(POSTGRES_IMAGE_NAME) + } } diff --git a/src/test/kotlin/org/wfanet/measurement/integration/common/duchy/BUILD.bazel b/src/test/kotlin/org/wfanet/measurement/integration/common/duchy/BUILD.bazel index f3a701593c9..e5bc5284861 100644 --- a/src/test/kotlin/org/wfanet/measurement/integration/common/duchy/BUILD.bazel +++ b/src/test/kotlin/org/wfanet/measurement/integration/common/duchy/BUILD.bazel @@ -33,11 +33,10 @@ kt_jvm_library( "//src/test/kotlin/org/wfanet/measurement/integration:__subpackages__", ], deps = [ - "//src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/testing", "//src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/service:postgres_duchy_data_services", "//src/main/kotlin/org/wfanet/measurement/integration/common:in_process_duchy", "@wfa_common_jvm//imports/java/com/google/cloud/storage/contrib/nio", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:embedded_postgres", + "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:database_provider", "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/testing", "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/gcloud/common", "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/gcloud/gcs", diff --git a/src/test/kotlin/org/wfanet/measurement/integration/common/duchy/PostgresDuchyDependencyProviderRule.kt b/src/test/kotlin/org/wfanet/measurement/integration/common/duchy/PostgresDuchyDependencyProviderRule.kt index dbdc3568309..867ebfcb4a2 100644 --- a/src/test/kotlin/org/wfanet/measurement/integration/common/duchy/PostgresDuchyDependencyProviderRule.kt +++ b/src/test/kotlin/org/wfanet/measurement/integration/common/duchy/PostgresDuchyDependencyProviderRule.kt @@ -19,21 +19,20 @@ import java.time.Clock import org.junit.runner.Description import org.junit.runners.model.Statement import org.wfanet.measurement.common.db.r2dbc.postgres.PostgresDatabaseClient -import org.wfanet.measurement.common.db.r2dbc.postgres.testing.EmbeddedPostgresDatabaseProvider +import org.wfanet.measurement.common.db.r2dbc.postgres.testing.PostgresDatabaseProvider import org.wfanet.measurement.common.identity.RandomIdGenerator import org.wfanet.measurement.common.testing.ProviderRule -import org.wfanet.measurement.duchy.deploy.common.postgres.testing.Schemata import org.wfanet.measurement.duchy.deploy.common.service.PostgresDuchyDataServices import org.wfanet.measurement.gcloud.gcs.GcsStorageClient import org.wfanet.measurement.integration.common.InProcessDuchy import org.wfanet.measurement.system.v1alpha.ComputationLogEntriesGrpcKt.ComputationLogEntriesCoroutineStub -class PostgresDuchyDependencyProviderRule(duchies: Iterable) : - ProviderRule<(String, ComputationLogEntriesCoroutineStub) -> InProcessDuchy.DuchyDependencies> { - private val computationsDatabases: Map = - duchies.associateWith { - EmbeddedPostgresDatabaseProvider(Schemata.DUCHY_CHANGELOG_PATH).createNewDatabase() - } +class PostgresDuchyDependencyProviderRule( + private val databaseProvider: PostgresDatabaseProvider, + private val duchies: Iterable +) : ProviderRule<(String, ComputationLogEntriesCoroutineStub) -> InProcessDuchy.DuchyDependencies> { + + private lateinit var computationsDatabases: Map private fun buildDuchyDependencies( duchyId: String, @@ -60,6 +59,11 @@ class PostgresDuchyDependencyProviderRule(duchies: Iterable) : get() = ::buildDuchyDependencies override fun apply(base: Statement, description: Description): Statement { - return base + return object : Statement() { + override fun evaluate() { + computationsDatabases = duchies.associateWith { databaseProvider.createDatabase() } + base.evaluate() + } + } } } diff --git a/src/test/kotlin/org/wfanet/measurement/integration/gcloud/BUILD.bazel b/src/test/kotlin/org/wfanet/measurement/integration/gcloud/BUILD.bazel index 7de3cc4948c..fc3536c4bf5 100644 --- a/src/test/kotlin/org/wfanet/measurement/integration/gcloud/BUILD.bazel +++ b/src/test/kotlin/org/wfanet/measurement/integration/gcloud/BUILD.bazel @@ -53,6 +53,7 @@ spanner_emulator_test( test_class = "org.wfanet.measurement.integration.gcloud.GCloudPostgresInProcessLifeOfAMeasurementIntegrationTest", deps = [ ":kingdom_provider_rule", + "//src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/testing", "//src/main/kotlin/org/wfanet/measurement/integration/common:in_process_life_of_a_measurement_integration_test", "//src/test/kotlin/org/wfanet/measurement/integration/common/duchy:postgres_duchy_dependency_provider_rule", "@wfa_common_jvm//imports/kotlin/kotlinx/coroutines/debug", diff --git a/src/test/kotlin/org/wfanet/measurement/integration/gcloud/GCloudPostgresInProcessLifeOfAMeasurementIntegrationTest.kt b/src/test/kotlin/org/wfanet/measurement/integration/gcloud/GCloudPostgresInProcessLifeOfAMeasurementIntegrationTest.kt index a793bac5bcf..61af3532469 100644 --- a/src/test/kotlin/org/wfanet/measurement/integration/gcloud/GCloudPostgresInProcessLifeOfAMeasurementIntegrationTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/integration/gcloud/GCloudPostgresInProcessLifeOfAMeasurementIntegrationTest.kt @@ -16,29 +16,30 @@ package org.wfanet.measurement.integration.gcloud -import com.google.cloud.storage.contrib.nio.testing.LocalStorageHelper import kotlinx.coroutines.debug.junit4.CoroutinesTimeout +import org.junit.ClassRule import org.junit.Rule -import org.wfanet.measurement.gcloud.gcs.GcsStorageClient +import org.wfanet.measurement.common.db.r2dbc.postgres.testing.PostgresDatabaseProviderRule +import org.wfanet.measurement.duchy.deploy.common.postgres.testing.Schemata import org.wfanet.measurement.integration.common.ALL_DUCHY_NAMES import org.wfanet.measurement.integration.common.InProcessLifeOfAMeasurementIntegrationTest import org.wfanet.measurement.integration.common.duchy.PostgresDuchyDependencyProviderRule -import org.wfanet.measurement.storage.StorageClient /** * Implementation of [InProcessLifeOfAMeasurementIntegrationTest] for GCloud backends with Postgres * database. */ class GCloudPostgresInProcessLifeOfAMeasurementIntegrationTest : - InProcessLifeOfAMeasurementIntegrationTest() { + InProcessLifeOfAMeasurementIntegrationTest( + KingdomDataServicesProviderRule(), + PostgresDuchyDependencyProviderRule(databaseProvider, ALL_DUCHY_NAMES) + ) { @get:Rule val timeout = CoroutinesTimeout.seconds(90) - override val kingdomDataServicesRule by lazy { KingdomDataServicesProviderRule() } - override val duchyDependenciesRule by lazy { - PostgresDuchyDependencyProviderRule(ALL_DUCHY_NAMES) - } - override val storageClient: StorageClient by lazy { - GcsStorageClient(LocalStorageHelper.getOptions().service, "bucket-simulator") + companion object { + @JvmStatic + @get:ClassRule + val databaseProvider = PostgresDatabaseProviderRule(Schemata.DUCHY_CHANGELOG_PATH) } } diff --git a/src/test/kotlin/org/wfanet/measurement/integration/gcloud/GCloudSpannerInProcessLifeOfAMeasurementIntegrationTest.kt b/src/test/kotlin/org/wfanet/measurement/integration/gcloud/GCloudSpannerInProcessLifeOfAMeasurementIntegrationTest.kt index 67193696f17..dd4869066cb 100644 --- a/src/test/kotlin/org/wfanet/measurement/integration/gcloud/GCloudSpannerInProcessLifeOfAMeasurementIntegrationTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/integration/gcloud/GCloudSpannerInProcessLifeOfAMeasurementIntegrationTest.kt @@ -14,27 +14,21 @@ package org.wfanet.measurement.integration.gcloud -import com.google.cloud.storage.contrib.nio.testing.LocalStorageHelper import kotlinx.coroutines.debug.junit4.CoroutinesTimeout import org.junit.Rule -import org.wfanet.measurement.gcloud.gcs.GcsStorageClient import org.wfanet.measurement.integration.common.ALL_DUCHY_NAMES import org.wfanet.measurement.integration.common.InProcessLifeOfAMeasurementIntegrationTest import org.wfanet.measurement.integration.common.duchy.SpannerDuchyDependencyProviderRule -import org.wfanet.measurement.storage.StorageClient /** * Implementation of [InProcessLifeOfAMeasurementIntegrationTest] for GCloud backends with Spanner * database. */ class GCloudSpannerInProcessLifeOfAMeasurementIntegrationTest : - InProcessLifeOfAMeasurementIntegrationTest() { + InProcessLifeOfAMeasurementIntegrationTest( + KingdomDataServicesProviderRule(), + SpannerDuchyDependencyProviderRule(ALL_DUCHY_NAMES) + ) { @get:Rule val timeout = CoroutinesTimeout.seconds(90) - - override val kingdomDataServicesRule by lazy { KingdomDataServicesProviderRule() } - override val duchyDependenciesRule by lazy { SpannerDuchyDependencyProviderRule(ALL_DUCHY_NAMES) } - override val storageClient: StorageClient by lazy { - GcsStorageClient(LocalStorageHelper.getOptions().service, "bucket-simulator") - } } diff --git a/src/test/kotlin/org/wfanet/measurement/integration/postgres/BUILD.bazel b/src/test/kotlin/org/wfanet/measurement/integration/postgres/BUILD.bazel index b9491ae62a8..f16ae30e266 100644 --- a/src/test/kotlin/org/wfanet/measurement/integration/postgres/BUILD.bazel +++ b/src/test/kotlin/org/wfanet/measurement/integration/postgres/BUILD.bazel @@ -4,7 +4,7 @@ load("@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/gcloud/spanner/tes kt_jvm_test( name = "PostgresInProcessLifeOfAReportIntegrationTest", srcs = ["PostgresInProcessLifeOfAReportIntegrationTest.kt"], - flaky = True, + tags = ["cpu:2"], test_class = "org.wfanet.measurement.integration.postgres.PostgresInProcessLifeOfAReportIntegrationTest", runtime_deps = [ "@wfa_common_jvm//imports/java/org/yaml:snakeyaml", @@ -13,8 +13,7 @@ kt_jvm_test( "//src/main/kotlin/org/wfanet/measurement/integration/common/reporting:in_process_life_of_a_report_integration_test", "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/common/server/postgres:services", "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/testing", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:embedded_postgres", + "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:database_provider", "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/identity", ], ) @@ -23,21 +22,20 @@ spanner_emulator_test( name = "V2PostgresInProcessLifeOfAReportIntegrationTest", size = "large", srcs = ["V2PostgresInProcessLifeOfAReportIntegrationTest.kt"], - flaky = True, tags = ["cpu:2"], test_class = "org.wfanet.measurement.integration.postgres.V2PostgresInProcessLifeOfAReportIntegrationTest", runtime_deps = [ "@wfa_common_jvm//imports/java/org/yaml:snakeyaml", ], deps = [ + "//src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/testing", "//src/main/kotlin/org/wfanet/measurement/integration/common:in_process_duchy", "//src/main/kotlin/org/wfanet/measurement/integration/common/reporting/v2:in_process_life_of_a_report_integration_test", "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/common/server/postgres:services", "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/testing", - "//src/test/kotlin/org/wfanet/measurement/integration/common/duchy:spanner_duchy_dependency_provider_rule", + "//src/test/kotlin/org/wfanet/measurement/integration/common/duchy:postgres_duchy_dependency_provider_rule", "//src/test/kotlin/org/wfanet/measurement/integration/gcloud:kingdom_provider_rule", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:embedded_postgres", + "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:database_provider", "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/identity", ], ) @@ -51,10 +49,11 @@ kt_jvm_test( "//src/main/kotlin/org/wfanet/measurement/integration/deploy/postgres:ledger.sql", ], test_class = "org.wfanet.measurement.integration.postgres.PrivacyBudgetPostgresSchemaTest", + runtime_deps = ["@wfa_common_jvm//imports/java/org/postgresql:j2dbc"], deps = [ "//src/main/kotlin/org/wfanet/measurement/integration/deploy/postgres:schemata", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", "@wfa_common_jvm//imports/java/org/junit", + "@wfa_common_jvm//imports/java/org/testcontainers/containers:postgresql", "@wfa_common_jvm//imports/kotlin/kotlin/test", "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common", ], diff --git a/src/test/kotlin/org/wfanet/measurement/integration/postgres/PostgresInProcessLifeOfAReportIntegrationTest.kt b/src/test/kotlin/org/wfanet/measurement/integration/postgres/PostgresInProcessLifeOfAReportIntegrationTest.kt index 17f070b2e61..87a1d86fe93 100644 --- a/src/test/kotlin/org/wfanet/measurement/integration/postgres/PostgresInProcessLifeOfAReportIntegrationTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/integration/postgres/PostgresInProcessLifeOfAReportIntegrationTest.kt @@ -15,7 +15,8 @@ package org.wfanet.measurement.integration.postgres import java.time.Clock -import org.wfanet.measurement.common.db.r2dbc.postgres.testing.EmbeddedPostgresDatabaseProvider +import org.junit.ClassRule +import org.wfanet.measurement.common.db.r2dbc.postgres.testing.PostgresDatabaseProviderRule import org.wfanet.measurement.common.identity.RandomIdGenerator import org.wfanet.measurement.integration.common.reporting.InProcessLifeOfAReportIntegrationTest import org.wfanet.measurement.reporting.deploy.common.server.postgres.PostgresServices @@ -24,9 +25,12 @@ import org.wfanet.measurement.reporting.deploy.postgres.testing.Schemata /** Implementation of [InProcessLifeOfAReportIntegrationTest] for Postgres. */ class PostgresInProcessLifeOfAReportIntegrationTest : InProcessLifeOfAReportIntegrationTest() { override val reportingServerDataServices by lazy { - PostgresServices.create( - RandomIdGenerator(Clock.systemUTC()), - EmbeddedPostgresDatabaseProvider(Schemata.REPORTING_CHANGELOG_PATH).createNewDatabase() - ) + PostgresServices.create(RandomIdGenerator(Clock.systemUTC()), databaseProvider.createDatabase()) + } + + companion object { + @get:ClassRule + @JvmStatic + val databaseProvider = PostgresDatabaseProviderRule(Schemata.REPORTING_CHANGELOG_PATH) } } diff --git a/src/test/kotlin/org/wfanet/measurement/integration/postgres/PrivacyBudgetPostgresSchemaTest.kt b/src/test/kotlin/org/wfanet/measurement/integration/postgres/PrivacyBudgetPostgresSchemaTest.kt index c11ee113557..2867bd0a78a 100644 --- a/src/test/kotlin/org/wfanet/measurement/integration/postgres/PrivacyBudgetPostgresSchemaTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/integration/postgres/PrivacyBudgetPostgresSchemaTest.kt @@ -14,37 +14,42 @@ package org.wfanet.measurement.integration.postgres -import com.opentable.db.postgres.junit.EmbeddedPostgresRules -import com.opentable.db.postgres.junit.SingleInstancePostgresRule -import java.sql.Connection import java.sql.ResultSet import java.sql.Statement import kotlin.test.assertEquals -import org.junit.Rule +import org.junit.Before +import org.junit.ClassRule import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 +import org.testcontainers.containers.PostgreSQLContainer import src.main.kotlin.org.wfanet.measurement.integration.deploy.postgres.POSTGRES_LEDGER_SCHEMA_FILE @RunWith(JUnit4::class) class PrivacyBudgetPostgresSchemaTest { - val schema = POSTGRES_LEDGER_SCHEMA_FILE.readText() - - @get:Rule val pg: SingleInstancePostgresRule = EmbeddedPostgresRules.singleInstance() + @Before + fun resetDatabase() { + createConnection().use { connection -> + connection.createStatement().use { + it.execute("DROP SCHEMA public CASCADE; CREATE SCHEMA public;") + } + } + } @Test fun `privacy budget ledger sql file is valid for postgres`() { - val connection: Connection = pg.embeddedPostgres.postgresDatabase.connection - val statement: Statement = connection.createStatement() - statement.execute(schema) + createConnection().use { connection -> + val statement: Statement = connection.createStatement() + statement.execute(SCHEMA) + } } @Test fun `privacy budget balance can be written and read`() { - val connection: Connection = pg.embeddedPostgres.postgresDatabase.connection - val statement = connection.createStatement() - val insertSql = - """ + createConnection().use { connection -> + val statement = connection.createStatement() + val insertSql = + """ INSERT INTO PrivacyBucketCharges ( MeasurementConsumerId, Date, @@ -65,23 +70,24 @@ class PrivacyBudgetPostgresSchemaTest { 10 ); """ - val selectSql = """ + val selectSql = """ SELECT Gender, Delta from PrivacyBucketCharges """ - statement.execute(schema) - statement.execute(insertSql) - val result: ResultSet = statement.executeQuery(selectSql) - result.next() - assertEquals("F", result.getString("gender")) - assertEquals(0.1f, result.getFloat("delta")) + statement.execute(SCHEMA) + statement.execute(insertSql) + val result: ResultSet = statement.executeQuery(selectSql) + result.next() + assertEquals("F", result.getString("gender")) + assertEquals(0.1f, result.getFloat("delta")) + } } @Test fun `privacy budget ledger can be written and read`() { - val connection: Connection = pg.embeddedPostgres.postgresDatabase.connection - val statement = connection.createStatement() - val insertSql = - """ + createConnection().use { connection -> + val statement = connection.createStatement() + val insertSql = + """ INSERT INTO LedgerEntries ( MeasurementConsumerId, ReferenceId, @@ -94,16 +100,35 @@ class PrivacyBudgetPostgresSchemaTest { NOW() ); """ - val selectSql = - """ + val selectSql = + """ SELECT MeasurementConsumerId, ReferenceId, IsRefund from LedgerEntries """ - statement.execute(schema) - statement.execute(insertSql) - val result: ResultSet = statement.executeQuery(selectSql) - result.next() - assertEquals("MC1", result.getString("measurementConsumerId")) - assertEquals("Ref1", result.getString("referenceId")) - assertEquals(false, result.getBoolean("isRefund")) + statement.execute(SCHEMA) + statement.execute(insertSql) + val result: ResultSet = statement.executeQuery(selectSql) + result.next() + assertEquals("MC1", result.getString("measurementConsumerId")) + assertEquals("Ref1", result.getString("referenceId")) + assertEquals(false, result.getBoolean("isRefund")) + } + } + + companion object { + private const val POSTGRES_IMAGE_NAME = "postgres:15" + + private val SCHEMA by lazy { POSTGRES_LEDGER_SCHEMA_FILE.readText() } + + /** + * PostgreSQL test container. + * + * TODO(@uakyol): Use [org.wfanet.measurement.common.db.r2dbc.postgres.testing.PostgresDatabaseProviderRule] + * instead of referencing TestContainers directly. + */ + @get:ClassRule + @JvmStatic + val postgresContainer = PostgreSQLContainer(POSTGRES_IMAGE_NAME) + + private fun createConnection() = postgresContainer.createConnection("") } } diff --git a/src/test/kotlin/org/wfanet/measurement/integration/postgres/V2PostgresInProcessLifeOfAReportIntegrationTest.kt b/src/test/kotlin/org/wfanet/measurement/integration/postgres/V2PostgresInProcessLifeOfAReportIntegrationTest.kt index f21292e70b2..fe2d9482ee7 100644 --- a/src/test/kotlin/org/wfanet/measurement/integration/postgres/V2PostgresInProcessLifeOfAReportIntegrationTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/integration/postgres/V2PostgresInProcessLifeOfAReportIntegrationTest.kt @@ -16,43 +16,38 @@ package org.wfanet.measurement.integration.postgres -import com.google.cloud.storage.contrib.nio.testing.LocalStorageHelper import java.time.Clock -import org.wfanet.measurement.common.db.r2dbc.postgres.testing.EmbeddedPostgresDatabaseProvider +import org.junit.ClassRule +import org.wfanet.measurement.common.db.r2dbc.postgres.testing.PostgresDatabaseProviderRule import org.wfanet.measurement.common.identity.RandomIdGenerator -import org.wfanet.measurement.common.testing.ProviderRule -import org.wfanet.measurement.gcloud.gcs.GcsStorageClient +import org.wfanet.measurement.duchy.deploy.common.postgres.testing.Schemata.DUCHY_CHANGELOG_PATH import org.wfanet.measurement.integration.common.ALL_DUCHY_NAMES -import org.wfanet.measurement.integration.common.InProcessDuchy -import org.wfanet.measurement.integration.common.duchy.SpannerDuchyDependencyProviderRule +import org.wfanet.measurement.integration.common.duchy.PostgresDuchyDependencyProviderRule import org.wfanet.measurement.integration.common.reporting.v2.InProcessLifeOfAReportIntegrationTest import org.wfanet.measurement.integration.gcloud.KingdomDataServicesProviderRule -import org.wfanet.measurement.kingdom.deploy.common.service.DataServices import org.wfanet.measurement.reporting.deploy.v2.common.server.postgres.PostgresServices -import org.wfanet.measurement.reporting.deploy.v2.postgres.testing.Schemata -import org.wfanet.measurement.storage.StorageClient -import org.wfanet.measurement.system.v1alpha.ComputationLogEntriesGrpcKt.ComputationLogEntriesCoroutineStub +import org.wfanet.measurement.reporting.deploy.v2.postgres.testing.Schemata.REPORTING_CHANGELOG_PATH /** Implementation of [InProcessLifeOfAReportIntegrationTest] for Postgres. */ -class V2PostgresInProcessLifeOfAReportIntegrationTest : InProcessLifeOfAReportIntegrationTest() { - override val kingdomDataServicesRule: ProviderRule by lazy { - KingdomDataServicesProviderRule() - } - - /** Provides a function from Duchy to the dependencies needed to start the Duchy to the test. */ - override val duchyDependenciesRule: - ProviderRule< - (String, ComputationLogEntriesCoroutineStub) -> InProcessDuchy.DuchyDependencies - > by lazy { SpannerDuchyDependencyProviderRule(ALL_DUCHY_NAMES) } - - override val storageClient: StorageClient by lazy { - GcsStorageClient(LocalStorageHelper.getOptions().service, "bucket-simulator") - } - +class V2PostgresInProcessLifeOfAReportIntegrationTest : + InProcessLifeOfAReportIntegrationTest( + KingdomDataServicesProviderRule(), + PostgresDuchyDependencyProviderRule(duchyDatabaseProvider, ALL_DUCHY_NAMES) + ) { override val internalReportingServerServices by lazy { PostgresServices.create( RandomIdGenerator(Clock.systemUTC()), - EmbeddedPostgresDatabaseProvider(Schemata.REPORTING_CHANGELOG_PATH).createNewDatabase() + reportingDatabaseProvider.createDatabase() ) } + + companion object { + @get:ClassRule + @JvmStatic + val reportingDatabaseProvider = PostgresDatabaseProviderRule(REPORTING_CHANGELOG_PATH) + + @get:ClassRule + @JvmStatic + val duchyDatabaseProvider = PostgresDatabaseProviderRule(DUCHY_CHANGELOG_PATH) + } } diff --git a/src/test/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/AwsKingdomSchemaTest.kt b/src/test/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/AwsKingdomSchemaTest.kt deleted file mode 100644 index a529054ed2b..00000000000 --- a/src/test/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/AwsKingdomSchemaTest.kt +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2020 The Cross-Media Measurement Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.wfanet.measurement.kingdom.deploy.aws.postgres - -import com.opentable.db.postgres.junit.EmbeddedPostgresRules -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 - -@RunWith(JUnit4::class) -class AwsKingdomSchemaTest { - val schema = AWS_KINGDOM_SCHEMA_FILE.readText() - - @get:Rule val pg = EmbeddedPostgresRules.singleInstance() - - @Test - fun `kingdom schema is valid sql for postgres`() { - val conn = pg.embeddedPostgres.postgresDatabase.connection - val statement = conn.createStatement() - statement.execute(schema) - } -} diff --git a/src/test/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/BUILD.bazel b/src/test/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/BUILD.bazel deleted file mode 100644 index d094ce8cc3a..00000000000 --- a/src/test/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/BUILD.bazel +++ /dev/null @@ -1,19 +0,0 @@ -load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_test") - -kt_jvm_test( - name = "AwsKingdomSchemaTest", - srcs = [ - "AwsKingdomSchemaTest.kt", - ], - data = [ - "//src/main/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/testing:kingdom.sql", - ], - test_class = "org.wfanet.measurement.kingdom.deploy.aws.postgres.AwsKingdomSchemaTest", - deps = [ - "//src/main/kotlin/org/wfanet/measurement/kingdom/deploy/aws/postgres/testing:schemata", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", - "@wfa_common_jvm//imports/java/org/junit", - "@wfa_common_jvm//imports/kotlin/kotlin/test", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common", - ], -) diff --git a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/postgres/BUILD.bazel b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/postgres/BUILD.bazel index 23efebaf10e..e4e780fe203 100644 --- a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/postgres/BUILD.bazel +++ b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/postgres/BUILD.bazel @@ -3,7 +3,7 @@ load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_test") kt_jvm_test( name = "PostgresMeasurementsServiceTest", srcs = ["PostgresMeasurementsServiceTest.kt"], - flaky = True, + tags = ["cpu:2"], test_class = "org.wfanet.measurement.reporting.deploy.postgres.PostgresMeasurementsServiceTest", runtime_deps = [ "@wfa_common_jvm//imports/java/org/yaml:snakeyaml", @@ -12,15 +12,14 @@ kt_jvm_test( "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres:services", "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/testing", "//src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:embedded_postgres", + "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:database_provider", ], ) kt_jvm_test( name = "PostgresReportingSetsServiceTest", srcs = ["PostgresReportingSetsServiceTest.kt"], - flaky = True, + tags = ["cpu:2"], test_class = "org.wfanet.measurement.reporting.deploy.postgres.PostgresReportingSetsServiceTest", runtime_deps = [ "@wfa_common_jvm//imports/java/org/yaml:snakeyaml", @@ -29,15 +28,14 @@ kt_jvm_test( "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres:services", "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/testing", "//src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:embedded_postgres", + "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:database_provider", ], ) kt_jvm_test( name = "PostgresReportsServiceTest", srcs = ["PostgresReportsServiceTest.kt"], - flaky = True, + tags = ["cpu:2"], test_class = "org.wfanet.measurement.reporting.deploy.postgres.PostgresReportsServiceTest", runtime_deps = [ "@wfa_common_jvm//imports/java/org/yaml:snakeyaml", @@ -46,7 +44,6 @@ kt_jvm_test( "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres:services", "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/testing", "//src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:embedded_postgres", + "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:database_provider", ], ) diff --git a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresMeasurementsServiceTest.kt b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresMeasurementsServiceTest.kt index c37c330c92a..2774fc2588e 100644 --- a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresMeasurementsServiceTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresMeasurementsServiceTest.kt @@ -14,20 +14,29 @@ package org.wfanet.measurement.reporting.deploy.postgres +import org.junit.ClassRule import org.junit.runner.RunWith import org.junit.runners.JUnit4 -import org.wfanet.measurement.common.db.r2dbc.postgres.testing.EmbeddedPostgresDatabaseProvider +import org.wfanet.measurement.common.db.r2dbc.postgres.PostgresDatabaseClient +import org.wfanet.measurement.common.db.r2dbc.postgres.testing.PostgresDatabaseProviderRule import org.wfanet.measurement.common.identity.IdGenerator -import org.wfanet.measurement.reporting.deploy.postgres.testing.Schemata.REPORTING_CHANGELOG_PATH +import org.wfanet.measurement.reporting.deploy.postgres.testing.Schemata import org.wfanet.measurement.reporting.service.internal.testing.MeasurementsServiceTest @RunWith(JUnit4::class) class PostgresMeasurementsServiceTest : MeasurementsServiceTest() { + override fun newServices(idGenerator: IdGenerator): Services { - val client = EmbeddedPostgresDatabaseProvider(REPORTING_CHANGELOG_PATH).createNewDatabase() + val client: PostgresDatabaseClient = databaseProvider.createDatabase() return Services( PostgresMeasurementsService(idGenerator, client), PostgresReportsService(idGenerator, client) ) } + + companion object { + @get:ClassRule + @JvmStatic + val databaseProvider = PostgresDatabaseProviderRule(Schemata.REPORTING_CHANGELOG_PATH) + } } diff --git a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresReportingSetsServiceTest.kt b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresReportingSetsServiceTest.kt index 6085c9a80ec..87c86f34857 100644 --- a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresReportingSetsServiceTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresReportingSetsServiceTest.kt @@ -14,11 +14,13 @@ package org.wfanet.measurement.reporting.deploy.postgres +import org.junit.ClassRule import org.junit.runner.RunWith import org.junit.runners.JUnit4 -import org.wfanet.measurement.common.db.r2dbc.postgres.testing.EmbeddedPostgresDatabaseProvider +import org.wfanet.measurement.common.db.r2dbc.postgres.PostgresDatabaseClient +import org.wfanet.measurement.common.db.r2dbc.postgres.testing.PostgresDatabaseProviderRule import org.wfanet.measurement.common.identity.IdGenerator -import org.wfanet.measurement.reporting.deploy.postgres.testing.Schemata.REPORTING_CHANGELOG_PATH +import org.wfanet.measurement.reporting.deploy.postgres.testing.Schemata import org.wfanet.measurement.reporting.service.internal.testing.ReportingSetsServiceTest @RunWith(JUnit4::class) @@ -26,9 +28,13 @@ class PostgresReportingSetsServiceTest : ReportingSetsServiceTest() override fun newServices( idGenerator: IdGenerator, ): Services { - val client = EmbeddedPostgresDatabaseProvider(REPORTING_CHANGELOG_PATH).createNewDatabase() + val client: PostgresDatabaseClient = databaseProvider.createDatabase() return Services( PostgresReportsService(idGenerator, client), PostgresMeasurementsService(idGenerator, client), PostgresReportingSetsService(idGenerator, client), ) } + + companion object { + @get:ClassRule + @JvmStatic + val databaseProvider = PostgresDatabaseProviderRule(Schemata.REPORTING_CHANGELOG_PATH) + } } diff --git a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/BUILD.bazel b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/BUILD.bazel index 225400dfc52..ebb9a48e299 100644 --- a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/BUILD.bazel +++ b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/BUILD.bazel @@ -3,7 +3,7 @@ load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_test") kt_jvm_test( name = "PostgresMeasurementConsumersServiceTest", srcs = ["PostgresMeasurementConsumersServiceTest.kt"], - flaky = True, + tags = ["cpu:2"], test_class = "org.wfanet.measurement.reporting.deploy.v2.postgres.PostgresMeasurementConsumersServiceTest", runtime_deps = [ "@wfa_common_jvm//imports/java/org/yaml:snakeyaml", @@ -12,15 +12,14 @@ kt_jvm_test( "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres:services", "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/testing", "//src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2:testing", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:embedded_postgres", + "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:database_provider", ], ) kt_jvm_test( name = "PostgresMeasurementsServiceTest", srcs = ["PostgresMeasurementsServiceTest.kt"], - flaky = True, + tags = ["cpu:2"], test_class = "org.wfanet.measurement.reporting.deploy.v2.postgres.PostgresMeasurementsServiceTest", runtime_deps = [ "@wfa_common_jvm//imports/java/org/yaml:snakeyaml", @@ -29,15 +28,14 @@ kt_jvm_test( "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres:services", "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/testing", "//src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2:testing", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:embedded_postgres", + "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:database_provider", ], ) kt_jvm_test( name = "PostgresMetricsServiceTest", srcs = ["PostgresMetricsServiceTest.kt"], - flaky = True, + tags = ["cpu:2"], test_class = "org.wfanet.measurement.reporting.deploy.v2.postgres.PostgresMetricsServiceTest", runtime_deps = [ "@wfa_common_jvm//imports/java/org/yaml:snakeyaml", @@ -46,15 +44,14 @@ kt_jvm_test( "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres:services", "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/testing", "//src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2:testing", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:embedded_postgres", + "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:database_provider", ], ) kt_jvm_test( name = "PostgresReportingSetsServiceTest", srcs = ["PostgresReportingSetsServiceTest.kt"], - flaky = True, + tags = ["cpu:2"], test_class = "org.wfanet.measurement.reporting.deploy.v2.postgres.PostgresReportingSetsServiceTest", runtime_deps = [ "@wfa_common_jvm//imports/java/org/yaml:snakeyaml", @@ -63,15 +60,14 @@ kt_jvm_test( "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres:services", "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/testing", "//src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2:testing", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:embedded_postgres", + "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:database_provider", ], ) kt_jvm_test( name = "PostgresReportsServiceTest", srcs = ["PostgresReportsServiceTest.kt"], - flaky = True, + tags = ["cpu:2"], test_class = "org.wfanet.measurement.reporting.deploy.v2.postgres.PostgresReportsServiceTest", runtime_deps = [ "@wfa_common_jvm//imports/java/org/yaml:snakeyaml", @@ -80,7 +76,6 @@ kt_jvm_test( "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres:services", "//src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/testing", "//src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2:testing", - "@wfa_common_jvm//imports/java/com/opentable/db/postgres:pg_embedded", - "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:embedded_postgres", + "@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc/postgres/testing:database_provider", ], ) diff --git a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMeasurementConsumersServiceTest.kt b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMeasurementConsumersServiceTest.kt index 407b82f9d3f..fad7a9b0ced 100644 --- a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMeasurementConsumersServiceTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMeasurementConsumersServiceTest.kt @@ -16,20 +16,29 @@ package org.wfanet.measurement.reporting.deploy.v2.postgres +import org.junit.ClassRule import org.junit.runner.RunWith import org.junit.runners.JUnit4 -import org.wfanet.measurement.common.db.r2dbc.postgres.testing.EmbeddedPostgresDatabaseProvider +import org.wfanet.measurement.common.db.r2dbc.postgres.PostgresDatabaseClient +import org.wfanet.measurement.common.db.r2dbc.postgres.testing.PostgresDatabaseProviderRule import org.wfanet.measurement.common.identity.IdGenerator -import org.wfanet.measurement.reporting.deploy.v2.postgres.testing.Schemata.REPORTING_CHANGELOG_PATH +import org.wfanet.measurement.reporting.deploy.v2.postgres.testing.Schemata import org.wfanet.measurement.reporting.service.internal.testing.v2.MeasurementConsumersServiceTest @RunWith(JUnit4::class) class PostgresMeasurementConsumersServiceTest : MeasurementConsumersServiceTest() { + override fun newService( idGenerator: IdGenerator, ): PostgresMeasurementConsumersService { - val client = EmbeddedPostgresDatabaseProvider(REPORTING_CHANGELOG_PATH).createNewDatabase() + val client: PostgresDatabaseClient = databaseProvider.createDatabase() return PostgresMeasurementConsumersService(idGenerator, client) } + + companion object { + @get:ClassRule + @JvmStatic + val databaseProvider = PostgresDatabaseProviderRule(Schemata.REPORTING_CHANGELOG_PATH) + } } diff --git a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMeasurementsServiceTest.kt b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMeasurementsServiceTest.kt index d5b13612e22..5a6dc5d1199 100644 --- a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMeasurementsServiceTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMeasurementsServiceTest.kt @@ -16,11 +16,13 @@ package org.wfanet.measurement.reporting.deploy.v2.postgres +import org.junit.ClassRule import org.junit.runner.RunWith import org.junit.runners.JUnit4 -import org.wfanet.measurement.common.db.r2dbc.postgres.testing.EmbeddedPostgresDatabaseProvider +import org.wfanet.measurement.common.db.r2dbc.postgres.PostgresDatabaseClient +import org.wfanet.measurement.common.db.r2dbc.postgres.testing.PostgresDatabaseProviderRule import org.wfanet.measurement.common.identity.IdGenerator -import org.wfanet.measurement.reporting.deploy.v2.postgres.testing.Schemata.REPORTING_CHANGELOG_PATH +import org.wfanet.measurement.reporting.deploy.v2.postgres.testing.Schemata import org.wfanet.measurement.reporting.service.internal.testing.v2.MeasurementsServiceTest @RunWith(JUnit4::class) @@ -28,7 +30,7 @@ class PostgresMeasurementsServiceTest : MeasurementsServiceTest { - val client = EmbeddedPostgresDatabaseProvider(REPORTING_CHANGELOG_PATH).createNewDatabase() + val client: PostgresDatabaseClient = databaseProvider.createDatabase() return Services( PostgresMeasurementsService(idGenerator, client), PostgresMetricsService(idGenerator, client), @@ -36,4 +38,10 @@ class PostgresMeasurementsServiceTest : MeasurementsServiceTest() override fun newServices( idGenerator: IdGenerator, ): Services { - val client = EmbeddedPostgresDatabaseProvider(REPORTING_CHANGELOG_PATH).createNewDatabase() + val client: PostgresDatabaseClient = databaseProvider.createDatabase() return Services( PostgresMetricsService(idGenerator, client), PostgresReportingSetsService(idGenerator, client), PostgresMeasurementConsumersService(idGenerator, client) ) } + + companion object { + @get:ClassRule + @JvmStatic + val databaseProvider = PostgresDatabaseProviderRule(Schemata.REPORTING_CHANGELOG_PATH) + } } diff --git a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresReportingSetsServiceTest.kt b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresReportingSetsServiceTest.kt index 069b09964a7..a1c1981e810 100644 --- a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresReportingSetsServiceTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresReportingSetsServiceTest.kt @@ -16,11 +16,13 @@ package org.wfanet.measurement.reporting.deploy.v2.postgres +import org.junit.ClassRule import org.junit.runner.RunWith import org.junit.runners.JUnit4 -import org.wfanet.measurement.common.db.r2dbc.postgres.testing.EmbeddedPostgresDatabaseProvider +import org.wfanet.measurement.common.db.r2dbc.postgres.PostgresDatabaseClient +import org.wfanet.measurement.common.db.r2dbc.postgres.testing.PostgresDatabaseProviderRule import org.wfanet.measurement.common.identity.IdGenerator -import org.wfanet.measurement.reporting.deploy.v2.postgres.testing.Schemata.REPORTING_CHANGELOG_PATH +import org.wfanet.measurement.reporting.deploy.v2.postgres.testing.Schemata import org.wfanet.measurement.reporting.service.internal.testing.v2.ReportingSetsServiceTest @RunWith(JUnit4::class) @@ -28,10 +30,16 @@ class PostgresReportingSetsServiceTest : ReportingSetsServiceTest { - val client = EmbeddedPostgresDatabaseProvider(REPORTING_CHANGELOG_PATH).createNewDatabase() + val client: PostgresDatabaseClient = databaseProvider.createDatabase() return Services( PostgresReportingSetsService(idGenerator, client), PostgresMeasurementConsumersService(idGenerator, client) ) } + + companion object { + @get:ClassRule + @JvmStatic + val databaseProvider = PostgresDatabaseProviderRule(Schemata.REPORTING_CHANGELOG_PATH) + } } diff --git a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresReportsServiceTest.kt b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresReportsServiceTest.kt index af6c498a173..38ae5e2a865 100644 --- a/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresReportsServiceTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresReportsServiceTest.kt @@ -16,11 +16,13 @@ package org.wfanet.measurement.reporting.deploy.v2.postgres +import org.junit.ClassRule import org.junit.runner.RunWith import org.junit.runners.JUnit4 -import org.wfanet.measurement.common.db.r2dbc.postgres.testing.EmbeddedPostgresDatabaseProvider +import org.wfanet.measurement.common.db.r2dbc.postgres.PostgresDatabaseClient +import org.wfanet.measurement.common.db.r2dbc.postgres.testing.PostgresDatabaseProviderRule import org.wfanet.measurement.common.identity.IdGenerator -import org.wfanet.measurement.reporting.deploy.v2.postgres.testing.Schemata.REPORTING_CHANGELOG_PATH +import org.wfanet.measurement.reporting.deploy.v2.postgres.testing.Schemata import org.wfanet.measurement.reporting.service.internal.testing.v2.ReportsServiceTest @RunWith(JUnit4::class) @@ -28,7 +30,7 @@ class PostgresReportsServiceTest : ReportsServiceTest() override fun newServices( idGenerator: IdGenerator, ): Services { - val client = EmbeddedPostgresDatabaseProvider(REPORTING_CHANGELOG_PATH).createNewDatabase() + val client: PostgresDatabaseClient = databaseProvider.createDatabase() return Services( PostgresReportsService(idGenerator, client), PostgresMetricsService(idGenerator, client), @@ -36,4 +38,10 @@ class PostgresReportsServiceTest : ReportsServiceTest() PostgresMeasurementConsumersService(idGenerator, client) ) } + + companion object { + @get:ClassRule + @JvmStatic + val databaseProvider = PostgresDatabaseProviderRule(Schemata.REPORTING_CHANGELOG_PATH) + } }