Skip to content

Commit

Permalink
HttpServiceTestFixture provides a sandbox-classic ledger used for per…
Browse files Browse the repository at this point in the history
…formance tests (#11128)

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
akshayshirahatti-da authored Oct 5, 2021
1 parent 63ab3f3 commit 55af7ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 32 deletions.
2 changes: 1 addition & 1 deletion ledger-service/http-json-testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ hj_scalacopts = lf_scalacopts + [
"//ledger/participant-integration-api",
"//ledger/sandbox",
"//ledger/sandbox:sandbox-scala-tests-lib",
"//ledger/sandbox-classic",
"//ledger/sandbox-common",
"//ledger/sandbox-common:sandbox-common-scala-tests-lib",
"//libs-scala/contextualized-logging",
"//libs-scala/db-utils",
"//libs-scala/ports",
"//libs-scala/resources",
"@maven//:io_dropwizard_metrics_metrics_core",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ import com.daml.ledger.client.configuration.{
LedgerIdRequirement,
}
import com.daml.ledger.client.withoutledgerid.{LedgerClient => DamlLedgerClient}
import com.daml.ledger.resources.ResourceContext
import com.daml.logging.LoggingContextOf
import com.daml.metrics.Metrics
import com.daml.platform.apiserver.SeedService.Seeding
import com.daml.platform.common.LedgerIdMode
import com.daml.platform.sandbox.SandboxBackend
import com.daml.platform.sandbox
import com.daml.platform.sandbox.SandboxServer
import com.daml.platform.sandbox.config.SandboxConfig
import com.daml.platform.sandboxnext.Runner
import com.daml.platform.services.time.TimeProviderType
import com.daml.ports.Port
import com.typesafe.scalalogging.LazyLogging
Expand Down Expand Up @@ -151,35 +150,19 @@ object HttpServiceTestFixture extends LazyLogging with Assertions with Inside {
useTls: UseTls = UseTls.NoTls,
authService: Option[AuthService] = None,
)(testFn: (Port, DamlLedgerClient, LedgerId) => Future[A])(implicit
mat: Materializer,
aesf: ExecutionSequencerFactory,
ec: ExecutionContext,
): Future[A] = {

val ledgerId = LedgerId(testName)
val applicationId = ApplicationId(testName)
implicit val resourceContext: ResourceContext = ResourceContext(ec)

val ledgerF = for {
urlResource <- Future(
SandboxBackend.H2Database.owner
.map(info => Some(info.jdbcUrl))
.acquire()
)
jdbcUrl <- urlResource.asFuture
ledger <- Future(
new Runner(
ledgerConfig(
Port.Dynamic,
dars,
ledgerId,
useTls = useTls,
authService = authService,
jdbcUrl = jdbcUrl,
)
)
.acquire()
new SandboxServer(ledgerConfig(Port.Dynamic, dars, ledgerId, authService, useTls), mat)
)
port <- ledger.asFuture
port <- ledger.portF
} yield (ledger, port)

val clientF: Future[DamlLedgerClient] = for {
Expand All @@ -196,12 +179,11 @@ object HttpServiceTestFixture extends LazyLogging with Assertions with Inside {
a <- testFn(ledgerPort, client, ledgerId)
} yield a

fa.transformWith { ta =>
ledgerF
.flatMap(_._1.release())
.fallbackTo(Future.unit)
.transform(_ => ta)
fa.onComplete { _ =>
ledgerF.foreach(_._1.close())
}

fa
}

private def ledgerConfig(
Expand All @@ -210,15 +192,12 @@ object HttpServiceTestFixture extends LazyLogging with Assertions with Inside {
ledgerId: LedgerId,
authService: Option[AuthService],
useTls: UseTls,
jdbcUrl: Option[String],
): SandboxConfig =
SandboxConfig.defaultConfig.copy(
sandbox.DefaultConfig.copy(
port = ledgerPort,
damlPackages = dars,
jdbcUrl = jdbcUrl,
timeProviderType = Some(TimeProviderType.WallClock),
tlsConfig = if (useTls) Some(serverTlsConfig) else None,
engineMode = SandboxConfig.EngineMode.Dev,
ledgerIdMode = LedgerIdMode.Static(ledgerId),
authService = authService,
seeding = Some(Seeding.Weak),
Expand Down

0 comments on commit 55af7ad

Please sign in to comment.