daml/ledger/sandbox/BUILD.bazel
Samir Talwar 51f596daa7
Sandbox Next: Implicit party allocation. (#4894)
* ledger-api-test-tool: Fix warnings flagged by IntelliJ IDEA.

* ledger-api-test-tool: Open-world mode.

In open-world mode, parties aren't allocated; their names are just
reserved for the test case, so that no other test will accidentally use
the same party name.

This is so we can test ledgers which dynamically allocate parties, such
as Sandbox.

* sandbox: Run conformance tests in "open-world" mode.

This means that the tests don't explicitly allocate parties (except for
a few), instead relying on Sandbox's implicit party allocation feature.

This is not enabled for Sandbox Next yet.

* sandbox-next: Implicit party allocation.

This is added to the command submission service.

CHANGELOG_BEGIN
CHANGELOG_END

* sandbox-next: Don't implicitly allocate pre-existing parties.

* ledger-api-test-tool: Move pre-allocation into ParticipantTestContext.

* ledger-api-test-tool: We can reserve parties or wait for them. Not both.

Make illegal states unrepresentable as early as possible.

* sandbox: Name ApiSubmissionService's private methods a little better.

* sandbox: Move ApiSubmissionService's conditional logic into methods.

* sandbox: Document why we set `implicitPartyAllocation` to `false`.

* sandbox: Document why `implicitPartyAllocation` is dangerous.
2020-03-09 15:49:11 +00:00

491 lines
15 KiB
Python

# Copyright (c) 2020 The DAML Authors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
load("//rules_daml:daml.bzl", "daml_compile")
load("//bazel_tools:scala.bzl", "da_scala_binary", "da_scala_library", "da_scala_test_suite")
load("//bazel_tools:pom_file.bzl", "pom_file")
load("//ledger/ledger-api-test-tool:conformance.bzl", "server_conformance_test")
load("@io_bazel_rules_docker//container:container.bzl", "container_image")
load("@io_bazel_rules_docker//java:image.bzl", "java_image")
load("@os_info//:os_info.bzl", "is_windows")
load("@build_environment//:configuration.bzl", "mvn_version")
compile_deps = [
"//daml-lf/archive:daml_lf_archive_reader",
"//daml-lf/archive:daml_lf_dev_archive_java_proto",
"//daml-lf/data",
"//daml-lf/engine",
"//daml-lf/interpreter",
"//daml-lf/language",
"//daml-lf/scenario-interpreter",
"//daml-lf/transaction",
"//daml-lf/transaction:transaction_java_proto",
"//daml-lf/transaction:value_java_proto",
"//language-support/scala/bindings",
"//ledger-api/rs-grpc-akka",
"//ledger-api/rs-grpc-bridge",
"//ledger-service/jwt",
"//ledger/ledger-api-akka",
"//ledger/ledger-api-auth",
"//ledger/ledger-api-client",
"//ledger/ledger-api-common",
"//ledger/ledger-api-domain",
"//ledger/ledger-api-health",
"//ledger/ledger-on-sql",
"//ledger/participant-state",
"//ledger/participant-state-index",
"//ledger/participant-state/kvutils",
"//libs-scala/contextualized-logging",
"//libs-scala/direct-execution-context",
"//libs-scala/ports",
"//libs-scala/resources",
"//libs-scala/resources-akka",
"@maven//:ch_qos_logback_logback_classic",
"@maven//:ch_qos_logback_logback_core",
"@maven//:com_auth0_java_jwt",
"@maven//:com_github_scopt_scopt_2_12",
"@maven//:com_google_guava_guava",
"@maven//:com_typesafe_akka_akka_actor_2_12",
"@maven//:com_typesafe_akka_akka_stream_2_12",
"@maven//:com_typesafe_config",
"@maven//:com_typesafe_play_anorm_2_12",
"@maven//:com_typesafe_play_anorm_tokenizer_2_12",
"@maven//:com_typesafe_scala_logging_scala_logging_2_12",
"@maven//:com_zaxxer_HikariCP",
"@maven//:io_dropwizard_metrics_metrics_core",
"@maven//:io_dropwizard_metrics_metrics_jmx",
"@maven//:io_grpc_grpc_netty",
"@maven//:io_grpc_grpc_services",
"@maven//:io_netty_netty_common",
"@maven//:io_netty_netty_handler",
"@maven//:io_netty_netty_transport",
"@maven//:net_logstash_logback_logstash_logback_encoder",
"@maven//:org_flywaydb_flyway_core",
"@maven//:org_scala_lang_modules_scala_java8_compat_2_12",
"@maven//:org_scalaz_scalaz_core_2_12",
"@maven//:org_slf4j_slf4j_api",
]
runtime_deps = [
"@maven//:ch_qos_logback_logback_classic",
"@maven//:ch_qos_logback_logback_core",
"@maven//:com_h2database_h2",
"@maven//:org_postgresql_postgresql",
"@maven//:org_xerial_sqlite_jdbc",
]
da_scala_library(
name = "sandbox",
srcs = glob(["src/main/scala/**/*.scala"]),
resources =
glob(
["src/main/resources/**/*"],
# Do not include logback.xml into the library: let the user
# of the sandbox-as-a-library decide how to log.
exclude = ["src/main/resources/logback.xml"],
) + [
"//:MVN_VERSION",
],
tags = ["maven_coordinates=com.digitalasset.platform:sandbox:__VERSION__"],
visibility = [
"//visibility:public",
],
runtime_deps = runtime_deps,
deps = compile_deps,
)
da_scala_library(
name = "ledger-api-server",
srcs = glob(["src/main/scala/**/*.scala"]),
resources =
glob(
["src/main/resources/**/*"],
# Do not include logback.xml into the library: let the user
# of the sandbox-as-a-library decide how to log.
exclude = ["src/main/resources/logback.xml"],
) + [
"//:MVN_VERSION",
],
tags = ["maven_coordinates=com.daml.ledger:ledger-api-server:__VERSION__"],
visibility = [
"//visibility:public",
],
runtime_deps = runtime_deps,
deps = compile_deps,
)
da_scala_binary(
name = "sandbox-binary",
main_class = "com.digitalasset.platform.sandbox.SandboxMain",
resources = ["src/main/resources/logback.xml"],
visibility = ["//visibility:public"],
deps = [
":sandbox",
],
)
da_scala_binary(
name = "sandbox-next-binary",
main_class = "com.digitalasset.platform.sandboxnext.Main",
resources = ["src/main/resources/logback.xml"],
visibility = ["//visibility:public"],
deps = [
":sandbox",
],
)
da_scala_binary(
name = "sandbox-ephemeral-postgresql",
main_class = "com.digitalasset.platform.sandbox.persistence.MainWithEphemeralPostgresql",
resources = ["src/main/resources/logback.xml"],
visibility = ["//visibility:public"],
deps = [
":sandbox",
":sandbox-scala-tests-lib",
],
)
da_scala_binary(
name = "sandbox-next-ephemeral-postgresql",
main_class = "com.digitalasset.platform.sandboxnext.persistence.MainWithEphemeralPostgresql",
resources = ["src/main/resources/logback.xml"],
visibility = ["//visibility:public"],
deps = [
":sandbox",
":sandbox-scala-tests-lib",
],
)
genrule(
name = "sandbox-tarball",
srcs = [
":sandbox-binary_deploy.jar",
],
outs = ["sandbox-tarball.tar.gz"],
cmd = """
mkdir -p sandbox-tarball/sandbox
cp -L $(location :sandbox-binary_deploy.jar) sandbox-tarball/sandbox/sandbox-{mvn}.jar
out=$$(realpath $@)
cd sandbox-tarball
tar zcf $$out sandbox
""".format(mvn = mvn_version),
visibility = ["//visibility:public"],
)
container_image(
name = "sandbox-image-base",
base = "@openjdk_base//image",
cmd = None,
directory = "/usr/bin",
files = [
"@com_github_grpc_ecosystem_grpc_health_probe_binary//file",
],
) if not is_windows else None
java_image(
name = "sandbox-image",
base = ":sandbox-image-base",
main_class = "com.digitalasset.platform.sandbox.SandboxMain",
resources = ["src/main/resources/logback.xml"],
visibility = ["//visibility:public"],
runtime_deps = [":sandbox"],
) if not is_windows else None
alias(
name = "Test-1.5.dar",
actual = ":historical-dars/Test-1.5.dar",
visibility = ["//visibility:public"],
)
#TODO: generate dynamic BuildInfo.scala
da_scala_library(
name = "sandbox-scala-tests-lib",
srcs = glob(["src/test/lib/**/*.scala"]),
visibility = ["//visibility:public"],
runtime_deps = [
"@maven//:com_h2database_h2",
"@maven//:com_typesafe_akka_akka_slf4j_2_12",
"@maven//:org_postgresql_postgresql",
],
deps = [
":sandbox",
"//bazel_tools/runfiles:scala_runfiles",
"//daml-lf/archive:daml_lf_archive_reader",
"//daml-lf/archive:daml_lf_dev_archive_java_proto",
"//daml-lf/data",
"//language-support/scala/bindings",
"//ledger-api/rs-grpc-akka",
"//ledger-api/rs-grpc-bridge",
"//ledger-api/testing-utils",
"//ledger-service/jwt",
"//ledger/ledger-api-auth",
"//ledger/ledger-api-auth-client",
"//ledger/ledger-api-client",
"//ledger/ledger-api-common",
"//ledger/ledger-api-domain",
"//ledger/ledger-api-health",
"//ledger/participant-state",
"//ledger/test-common",
"//libs-scala/contextualized-logging",
"//libs-scala/direct-execution-context",
"//libs-scala/grpc-utils",
"//libs-scala/ports",
"//libs-scala/postgresql-testing",
"//libs-scala/resources",
"//libs-scala/timer-utils",
"@maven//:ch_qos_logback_logback_classic",
"@maven//:com_auth0_java_jwt",
"@maven//:com_google_guava_guava",
"@maven//:com_typesafe_akka_akka_actor_2_12",
"@maven//:com_typesafe_akka_akka_stream_2_12",
"@maven//:com_typesafe_config",
"@maven//:com_typesafe_scala_logging_scala_logging_2_12",
"@maven//:io_dropwizard_metrics_metrics_core",
"@maven//:io_grpc_grpc_netty",
"@maven//:io_netty_netty_common",
"@maven//:io_netty_netty_transport",
"@maven//:org_scalactic_scalactic_2_12",
"@maven//:org_scalatest_scalatest_2_12",
"@maven//:org_scalaz_scalaz_core_2_12",
"@maven//:org_slf4j_slf4j_api",
],
)
da_scala_test_suite(
name = "sandbox-scala-tests",
srcs = glob(
["src/test/suite/**/*.scala"],
),
data = [
"//ledger/test-common:Test-stable.dar",
],
resources = glob(["src/test/resources/**/*"]),
deps = [
":sandbox",
":sandbox-scala-tests-lib",
"//bazel_tools/runfiles:scala_runfiles",
"//daml-lf/archive:daml_lf_archive_reader",
"//daml-lf/archive:daml_lf_dev_archive_java_proto",
"//daml-lf/data",
"//daml-lf/interpreter",
"//daml-lf/language",
"//daml-lf/transaction",
"//language-support/scala/bindings",
"//ledger-api/rs-grpc-akka",
"//ledger-api/rs-grpc-bridge",
"//ledger-api/testing-utils",
"//ledger/ledger-api-auth",
"//ledger/ledger-api-client",
"//ledger/ledger-api-common",
"//ledger/ledger-api-common:ledger-api-common-scala-tests-lib",
"//ledger/ledger-api-domain",
"//ledger/ledger-api-health",
"//ledger/participant-state",
"//ledger/participant-state-index",
"//ledger/test-common",
"//libs-scala/contextualized-logging",
"//libs-scala/direct-execution-context",
"//libs-scala/grpc-utils",
"//libs-scala/ports",
"//libs-scala/postgresql-testing",
"//libs-scala/resources",
"//libs-scala/timer-utils",
"@maven//:ch_qos_logback_logback_classic",
"@maven//:ch_qos_logback_logback_core",
"@maven//:com_typesafe_akka_akka_actor_2_12",
"@maven//:com_typesafe_akka_akka_stream_2_12",
"@maven//:com_typesafe_akka_akka_stream_testkit_2_12",
"@maven//:com_typesafe_akka_akka_testkit_2_12",
"@maven//:com_typesafe_config",
"@maven//:commons_io_commons_io",
"@maven//:io_dropwizard_metrics_metrics_core",
"@maven//:io_grpc_grpc_services",
"@maven//:io_netty_netty_handler",
"@maven//:org_awaitility_awaitility",
"@maven//:org_flywaydb_flyway_core",
"@maven//:org_mockito_mockito_core",
"@maven//:org_mockito_mockito_scala_2_12",
"@maven//:org_reactivestreams_reactive_streams",
"@maven//:org_scalactic_scalactic_2_12",
"@maven//:org_scalatest_scalatest_2_12",
"@maven//:org_scalaz_scalaz_core_2_12",
"@maven//:org_slf4j_slf4j_api",
],
)
SERVERS = {
"memory": {
"binary": ":sandbox-binary",
"server_args": [
"--port=6865",
"--eager-package-loading",
],
},
"h2database": {
"binary": ":sandbox-binary",
"server_args": [
"--port=6865",
"--eager-package-loading",
# "db_close_delay=-1" is needed so that the in-memory database is not closed
# (and therefore lost) after the flyway migration
"--sql-backend-jdbcurl=jdbc:h2:mem:static_time;db_close_delay=-1",
],
},
"postgresql": {
"binary": ":sandbox-ephemeral-postgresql",
"server_args": [
"--port=6865",
"--eager-package-loading",
],
},
}
server_conformance_test(
name = "conformance-test-static-time",
server_args = [
"--static-time",
],
servers = SERVERS,
test_tool_args = [
"--verbose",
"--open-world",
"--all-tests",
"--exclude=LotsOfPartiesIT",
"--exclude=ConfigManagementServiceIT",
"--exclude=ClosedWorldIT",
],
)
server_conformance_test(
name = "conformance-test-lots-of-parties",
flaky = True,
server_args = [
"--static-time",
],
servers = SERVERS,
test_tool_args = [
"--verbose",
"--open-world",
"--include=LotsOfPartiesIT",
],
)
server_conformance_test(
name = "conformance-test-wall-clock",
server_args = [
"--wall-clock-time",
],
servers = SERVERS,
test_tool_args = [
"--verbose",
"--open-world",
"--all-tests",
"--exclude=LotsOfPartiesIT",
"--exclude=ConfigManagementServiceIT",
"--exclude=ClosedWorldIT",
],
)
server_conformance_test(
name = "conformance-test-config-management",
servers = SERVERS,
test_tool_args = [
"--verbose",
"--open-world",
"--include=ConfigManagementServiceIT",
],
)
server_conformance_test(
name = "conformance-test-command-deduplication",
servers = SERVERS,
test_tool_args = [
"--verbose",
"--open-world",
"--include=CommandDeduplicationIT",
],
)
server_conformance_test(
name = "conformance-test-contract-id-seeding",
server_args = [
"--contract-id-seeding=weak",
],
servers = SERVERS,
test_tool_args = [
"--verbose",
"--open-world",
"--all-tests",
"--exclude=ConfigManagementServiceIT",
"--exclude=ClosedWorldIT",
"--exclude=CommandDeduplicationIT",
],
)
NEXT_SERVERS = {
"memory": {
"binary": ":sandbox-next-binary",
"server_args": [
"--contract-id-seeding=weak",
"--port=6865",
"--eager-package-loading",
],
},
"postgresql": {
"binary": ":sandbox-next-ephemeral-postgresql",
"server_args": [
"--contract-id-seeding=weak",
"--port=6865",
"--eager-package-loading",
],
},
}
server_conformance_test(
name = "next-conformance-test-static-time",
server_args = [
"--static-time",
],
servers = NEXT_SERVERS,
test_tool_args = [
"--verbose",
"--open-world",
"--all-tests",
"--exclude=ClosedWorldIT",
"--exclude=CommandDeduplicationIT",
"--exclude=ConfigManagementServiceIT",
],
)
server_conformance_test(
name = "next-conformance-test-wall-clock-time",
server_args = [
"--wall-clock-time",
],
servers = NEXT_SERVERS,
test_tool_args = [
"--verbose",
"--open-world",
"--all-tests",
"--exclude=ClosedWorldIT",
"--exclude=CommandDeduplicationIT",
"--exclude=ConfigManagementServiceIT",
],
)
server_conformance_test(
name = "next-conformance-test-config-management",
server_args = [
"--wall-clock-time",
],
servers = NEXT_SERVERS,
test_tool_args = [
"--verbose",
"--open-world",
"--include=ConfigManagementServiceIT",
],
)
exports_files(["src/main/resources/logback.xml"])