-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DPP-468 StorageBackend tests #10529
Merged
Merged
DPP-468 StorageBackend tests #10529
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4edc9c6
Add StorageBackend tests
rautenrieth-da 3bb92e2
Fix Oracle tests
rautenrieth-da 813be9d
Do not use empty byte arrays
rautenrieth-da 946655c
Format
rautenrieth-da 13682f3
Fix after rebase
rautenrieth-da 39820a1
Substitute type params with type bounded ingest method
nmarton-da cda4a6f
Remove empty line
rautenrieth-da 9c0eac6
Assert on configuration contents
rautenrieth-da 4c84c68
Fix Oracle build
rautenrieth-da db51c6f
Add tests for ingestion initialization
rautenrieth-da 01189e3
fmt
rautenrieth-da f86c11e
Add test for leftover data after reset
rautenrieth-da d5bc040
Add resetAll
rautenrieth-da e69e7e7
Use resetAll between tests
rautenrieth-da File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 0 additions & 73 deletions
73
...ntegration-api/src/test/lib/scala/platform/store/backend/StorageBackendPostgresSpec.scala
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
...nt-integration-api/src/test/lib/scala/platform/store/backend/StorageBackendProvider.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.platform.store.backend | ||
|
||
import java.sql.Connection | ||
|
||
import com.daml.platform.store.backend.h2.H2StorageBackend | ||
import com.daml.platform.store.backend.oracle.OracleStorageBackend | ||
import com.daml.platform.store.backend.postgresql.PostgresStorageBackend | ||
import com.daml.testing.oracle.OracleAroundAll | ||
import com.daml.testing.postgresql.PostgresAroundAll | ||
import org.scalatest.Suite | ||
|
||
/** Creates a database and a [[StorageBackend]]. | ||
* Used by [[StorageBackendSpec]] to run all StorageBackend tests on different databases. | ||
*/ | ||
private[backend] trait StorageBackendProvider { | ||
protected def jdbcUrl: String | ||
protected def backend: StorageBackend[_] | ||
protected final def ingest(dbDtos: Vector[DbDto], connection: Connection): Unit = { | ||
def typeBoundIngest[T](backend: StorageBackend[T]): Unit = | ||
backend.insertBatch(connection, backend.batch(dbDtos)) | ||
typeBoundIngest(backend) | ||
} | ||
} | ||
|
||
private[backend] trait StorageBackendProviderPostgres | ||
extends StorageBackendProvider | ||
with PostgresAroundAll { this: Suite => | ||
override protected def jdbcUrl: String = postgresDatabase.url | ||
override protected val backend: StorageBackend[_] = PostgresStorageBackend | ||
} | ||
|
||
private[backend] trait StorageBackendProviderH2 extends StorageBackendProvider { this: Suite => | ||
override protected def jdbcUrl: String = "jdbc:h2:mem:storage_backend_provider;db_close_delay=-1" | ||
override protected val backend: StorageBackend[_] = H2StorageBackend | ||
} | ||
|
||
private[backend] trait StorageBackendProviderOracle | ||
extends StorageBackendProvider | ||
with OracleAroundAll { this: Suite => | ||
override protected def jdbcUrl: String = | ||
s"jdbc:oracle:thin:$oracleUser/$oraclePwd@localhost:$oraclePort/ORCLPDB1" | ||
override protected val backend: StorageBackend[_] = OracleStorageBackend | ||
} |
95 changes: 95 additions & 0 deletions
95
...cipant-integration-api/src/test/lib/scala/platform/store/backend/StorageBackendSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.platform.store.backend | ||
|
||
import java.sql.Connection | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
import com.codahale.metrics.MetricRegistry | ||
import com.daml.ledger.api.testing.utils.AkkaBeforeAndAfterAll | ||
import com.daml.ledger.resources.{Resource, ResourceContext} | ||
import com.daml.logging.{ContextualizedLogger, LoggingContext} | ||
import com.daml.metrics.Metrics | ||
import com.daml.platform.configuration.ServerRole | ||
import com.daml.platform.store.appendonlydao.DbDispatcher | ||
import com.daml.platform.store.FlywayMigrations | ||
import org.scalatest.{AsyncTestSuite, BeforeAndAfterEach} | ||
|
||
import scala.concurrent.{Await, Future} | ||
import scala.concurrent.duration.{DurationInt, FiniteDuration} | ||
|
||
private[backend] trait StorageBackendSpec | ||
extends AkkaBeforeAndAfterAll | ||
with BeforeAndAfterEach | ||
with StorageBackendProvider { this: AsyncTestSuite => | ||
|
||
protected val logger: ContextualizedLogger = ContextualizedLogger.get(getClass) | ||
implicit protected val loggingContext: LoggingContext = LoggingContext.ForTesting | ||
|
||
private val connectionPoolSize: Int = 16 | ||
private val metrics = new Metrics(new MetricRegistry) | ||
|
||
// Initialized in beforeAll() | ||
private var dbDispatcherResource: Resource[DbDispatcher] = _ | ||
private var dbDispatcher: DbDispatcher = _ | ||
|
||
protected def executeSql[T](sql: Connection => T): Future[T] = { | ||
dbDispatcher.executeSql(metrics.test.db)(sql) | ||
} | ||
|
||
override protected def beforeAll(): Unit = { | ||
super.beforeAll() | ||
|
||
implicit val resourceContext: ResourceContext = ResourceContext(system.dispatcher) | ||
implicit val loggingContext: LoggingContext = LoggingContext.ForTesting | ||
dbDispatcherResource = for { | ||
_ <- Resource.fromFuture( | ||
new FlywayMigrations(jdbcUrl).migrate(enableAppendOnlySchema = true) | ||
) | ||
dispatcher <- DbDispatcher | ||
.owner( | ||
dataSource = backend.createDataSource(jdbcUrl), | ||
serverRole = ServerRole.Testing(this.getClass), | ||
connectionPoolSize = connectionPoolSize, | ||
connectionTimeout = FiniteDuration(250, "millis"), | ||
metrics = metrics, | ||
) | ||
.acquire() | ||
} yield dispatcher | ||
|
||
dbDispatcher = Await.result(dbDispatcherResource.asFuture, 30.seconds) | ||
logger.info( | ||
s"Finished setting up database $jdbcUrl for tests. You can now connect to this database to debug failed tests. Note that tables are truncated between each test." | ||
) | ||
} | ||
|
||
override protected def afterAll(): Unit = { | ||
Await.result(dbDispatcherResource.release(), 30.seconds) | ||
super.afterAll() | ||
} | ||
|
||
private val runningTests = new AtomicInteger(0) | ||
|
||
// Each test should start with an empty database to allow testing low-level behavior | ||
// However, creating a fresh database for each test would be too expensive. | ||
// Instead, we truncate all tables using the reset() call before each test. | ||
override protected def beforeEach(): Unit = { | ||
super.beforeEach() | ||
|
||
assert( | ||
runningTests.incrementAndGet() == 1, | ||
"StorageBackendSpec tests must not run in parallel, as they all run against the same database.", | ||
) | ||
Await.result(executeSql(backend.resetAll), 10.seconds) | ||
} | ||
|
||
override protected def afterEach(): Unit = { | ||
assert( | ||
runningTests.decrementAndGet() == 0, | ||
"StorageBackendSpec tests must not run in parallel, as they all run against the same database.", | ||
) | ||
|
||
super.afterEach() | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ipant-integration-api/src/test/lib/scala/platform/store/backend/StorageBackendSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.platform.store.backend | ||
|
||
import org.scalatest.flatspec.AsyncFlatSpec | ||
|
||
trait StorageBackendSuite | ||
extends StorageBackendSpec | ||
with StorageBackendTestsInitialization | ||
with StorageBackendTestsInitializeIngestion | ||
with StorageBackendTestsIngestion | ||
with StorageBackendTestsReset | ||
with StorageBackendTestsPruning { | ||
this: AsyncFlatSpec => | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add reuse here?
how about unifying the truncation in common? the one-by-one style seems compatible with all. and the referential integrity treatment with H2 seems to be doable with some set to false;super.reset;set true sequence.