From 737cd7edbabac97928083f5a478c105cd4d316e8 Mon Sep 17 00:00:00 2001 From: szymonsztuka Date: Thu, 7 Dec 2017 16:26:17 +0000 Subject: [PATCH] Improved SQL test setup for Azure SQL and SQL Server (#152) * Improved SQL scripts for SQL Server and Azure to drop user/permissions on class setup not on test setup * Set Micorsoft JDBC driver as compile time dependency. * Database testing description. * New table node_mutual_exclusion added to SQL test setup scripts. --- .../corda/docs/IntegrationTestingTutorial.kt | 7 +- docs/source/node-database.rst | 2 +- docs/source/testing.rst | 54 ++++++-- node/build.gradle | 10 +- .../net/corda/bank/BankOfCordaCordformTest.kt | 9 +- .../net/corda/testing/IntegrationTest.kt | 7 +- .../azure-sql/db-global-cleanup.sql | 48 +++++++ .../azure-sql/db-global-setup.sql | 4 + .../database-scripts/azure-sql/db-setup.sql | 46 +++++++ .../master-user-setup.sql | 122 ++++++------------ .../sql-server/db-global-cleanup.sql | 49 +++++++ .../sql-server/db-global-setup.sql | 54 ++++++++ .../{sql-azure => sql-server}/db-setup.sql | 1 + ...-azure.conf => integration-azure-sql.conf} | 0 .../net/corda/verifier/VerifierTests.kt | 12 +- .../corda/webserver/WebserverDriverTests.kt | 8 +- 16 files changed, 318 insertions(+), 115 deletions(-) create mode 100644 testing/test-utils/src/main/resources/database-scripts/azure-sql/db-global-cleanup.sql create mode 100644 testing/test-utils/src/main/resources/database-scripts/azure-sql/db-global-setup.sql create mode 100644 testing/test-utils/src/main/resources/database-scripts/azure-sql/db-setup.sql rename testing/test-utils/src/main/resources/database-scripts/{sql-azure => azure-sql}/master-user-setup.sql (58%) create mode 100644 testing/test-utils/src/main/resources/database-scripts/sql-server/db-global-cleanup.sql create mode 100644 testing/test-utils/src/main/resources/database-scripts/sql-server/db-global-setup.sql rename testing/test-utils/src/main/resources/database-scripts/{sql-azure => sql-server}/db-setup.sql (97%) rename testing/test-utils/src/main/resources/{integration-sql-azure.conf => integration-azure-sql.conf} (100%) diff --git a/docs/source/example-code/src/integration-test/kotlin/net/corda/docs/IntegrationTestingTutorial.kt b/docs/source/example-code/src/integration-test/kotlin/net/corda/docs/IntegrationTestingTutorial.kt index d7299a596c..699789bea8 100644 --- a/docs/source/example-code/src/integration-test/kotlin/net/corda/docs/IntegrationTestingTutorial.kt +++ b/docs/source/example-code/src/integration-test/kotlin/net/corda/docs/IntegrationTestingTutorial.kt @@ -16,12 +16,15 @@ import net.corda.node.services.Permissions.Companion.startFlow import net.corda.nodeapi.internal.config.User import net.corda.testing.* import net.corda.testing.driver.driver +import org.junit.ClassRule import org.junit.Test import kotlin.test.assertEquals class IntegrationTestingTutorial : IntegrationTest() { - override val databaseSchemas: MutableList - get() = listOf(ALICE, BOB, DUMMY_NOTARY).map { it.toDatabaseSchemaName() }.toMutableList() + companion object { + @ClassRule @JvmField + val databaseSchemas = IntegrationTestSchemas(*listOf(ALICE, BOB, DUMMY_NOTARY).map { it.toDatabaseSchemaName() }.toTypedArray()) + } @Test fun `alice bob cash exchange example`() { diff --git a/docs/source/node-database.rst b/docs/source/node-database.rst index e407c9db25..d854586397 100644 --- a/docs/source/node-database.rst +++ b/docs/source/node-database.rst @@ -38,7 +38,7 @@ and Hibernate properties in `database` entry - see `:ref:`dataSourceProperties`. SQL Azure and SQL Server ```````````````````````` -Corda supports SQL Server 2017 adn SQL Azure. +Corda supports SQL Server 2017 (14.0.3006.16) and Azure SQL (12.0.2000.8). The minimum transaction isolation level ``database.transactionIsolationLevel`` is 'readCommitted'. The property ``database.schema`` is optional. Corda ships with Microsoft JDBC Driver 6.2 for SQLServer out-of-the-box. diff --git a/docs/source/testing.rst b/docs/source/testing.rst index c4b5c62bfa..d7ed01709d 100644 --- a/docs/source/testing.rst +++ b/docs/source/testing.rst @@ -43,24 +43,50 @@ TODO: Add instructions on manual testing External Database Testing ------------------------- -By default, all tests which need a database, utilize built-in H2 instances. For the purpose of testing other relational -database providers or different database setups (for example, H2 in server mode), we introduce an optional system -property called ``databaseProvider`` which is resolved at run-time to load a configuration file on the classpath with the -name ``$databaseProvider.conf`` containing database configuration properties defined in the general node configuration -file (see ``reference.conf``). These will be used to override the default H2 settings defined in ``reference.conf``. +Integration test can be parameterised to run against any remote database (by default, integration tests use in-memory H2 instances). +For the purpose of testing other relational database providers or different database setups (for example, H2 in server mode), +we introduce an optional system property called ``databaseProvider`` which is resolved at run-time to load a configuration file on the classpath with the +name ``$databaseProvider.conf`` containing database configuration properties that override the default H2 settings +defined in the general node configuration file (see ``reference.conf``). +Integration test runs predefined set of SQL setup scripts selected for a specific database provider by ``test.db.script.dir``. +SQL scripts is a template which contains standard SQL DDL statements with a ${schema} placeholder. An integration test runs the SQL scripts +for all nodes involed in the test and replaces ${schema} with appropriate value derived from node name. +SQL templates files are executed at different stage of an integration test: +``db-global-setup.sql``- before a test class (@BeforeClass), should create database users, schema and permissions +``db-setup.sql`` - before a test (@Before), should clean up/drop tables +``db-cleanup.sql` - after a test (@After), may clean up/drop tables +``db-global-cleanup.sql`` - after a test class (@AfterClass), may drop user and schema +Depends on the database providers not each SQL file is present (e.g. db-setp always deletes tabels so db-cleanp is not needed). -Appropriate changes will then be applied to all tests in a appropriate manner. +The setup ensures that all nodes involved in a single integration test use different database users to achieve database separation. +The data source configuration files (denote by ``databaseProvider``) define user and schema by ${nodeOrganizationName} placeholder. +At a runtime the node resolves the placeholder to its organization name. -- ``dataSourceProperties.dataSource.url`` - JDBC datasource URL. Appropriate drivers must be available in classpath. Also, for - different tests random database name is appended at the end of this string, ie. ``jdbc:h2:tcp://localhost:9092`` will become - full, proper URL - ie.``jdbc:h2:tcp://localhost:9092/34jh543gk243g2`` - mind the last slash missing. -- ``dataSourceProperties.dataSourceClassName`` - JDBC driver classname +To run integration tests against a remote database provide these system properties: -- ``dataSourceProperties.dataSource.user`` - JDBC username +- ``databaseProvider`` - a template dataSource/database configuration for a node, accepted values [“integration-azure-sql”, “integration-sql-server”] + +- ``test.db.script.dir`` - a relative directory path with SQL script templates for a given database, + accepted values [“database-scripts/azure-sql”, “database-scripts/sql-server”] + +- ``test.db.admin.user`` - a database user to run SQL setup scripts, the user need to have permissions + to create other users and grant them permissions +- ``test.db.admin.password`` - a password for the database user to run SQL scripts + +Provided configuration file ``$databaseProvider.conf``file () contains a specific JDBC connection string with a dummy database host, + the following properties can override JDBC connection string and password: + +- ``dataSourceProperties.dataSource.url`` - specify full JDBC connection string use by a node to connect to database + +- ``dataSourceProperties.dataSource.password`` - optional setup, currently SQL scripts creates users with a given hardcoded + password with matches one in node configuration +All defaults are taken from the ``reference.conf`` file. + +Example running Gradle integration tests task against Azure SQL database running at ``mycordadb.database.windows.net``: +``./gradlew integrationTest -DdataSourceProperties.dataSource.url="jdbc:sqlserver://mycordadb.database.windows.net:1433;databaseName=mycordadb;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30" +-DdatabaseProvider=integration-sql-azure -Dtest.db.admin.user=dbuser@mycordadb -Dtest.db.admin.password='paSSword(!' + -Dtest.db.script.dir=database-scripts/sql-azure --info`` -- ``dataSourceProperties.dataSource.password`` - JDBC password -- ``database.transactionIsolationLevel`` - Isolation level pertinent to relevant database provider -All defaults are taken from the ``reference.conf`` file. \ No newline at end of file diff --git a/node/build.gradle b/node/build.gradle index 2b69308580..ed39421af3 100644 --- a/node/build.gradle +++ b/node/build.gradle @@ -116,8 +116,12 @@ dependencies { // For H2 database support in persistence compile "com.h2database:h2:$h2_version" - // For Postgres database support in persistence + //TODO remove once we can put driver jar into a predefined directory + //JDBC driver can be passed to the Node at startup using setting the jarDirs property in the Node configuration file. + //For Postgres database support in persistence compile "org.postgresql:postgresql:$postgresql_version" + //For Azure SQL and SQL Server support in persistence + compile 'com.microsoft.sqlserver:mssql-jdbc:6.2.1.jre8' // SQL connection pooling library compile "com.zaxxer:HikariCP:2.5.1" @@ -162,10 +166,6 @@ dependencies { // Jsh: A SSH implementation for tunneling inbound traffic via a relay compile group: 'com.jcraft', name: 'jsch', version: '0.1.54' - //TODO remove once we can put driver jar into a predefined directory - //JDBC driver can be passed to the Node at startup using setting the jarDirs property in the Node configuration file. - runtime 'com.microsoft.sqlserver:mssql-jdbc:6.2.1.jre8' - // Integration test helpers integrationTestCompile "junit:junit:$junit_version" integrationTestCompile "org.assertj:assertj-core:${assertj_version}" diff --git a/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaCordformTest.kt b/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaCordformTest.kt index 6890793aba..ce33e34030 100644 --- a/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaCordformTest.kt +++ b/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaCordformTest.kt @@ -2,10 +2,17 @@ package net.corda.bank import net.corda.finance.DOLLARS import net.corda.finance.POUNDS +import net.corda.testing.* import net.corda.testing.internal.demorun.deployNodesThen +import org.junit.ClassRule import org.junit.Test -class BankOfCordaCordformTest { +class BankOfCordaCordformTest : IntegrationTest() { + companion object { + @ClassRule @JvmField + val databaseSchemas = IntegrationTestSchemas("NotaryService", "BankOfCorda", BIGCORP_NAME.organisation) + } + @Test fun `run demo`() { BankOfCordaCordform().deployNodesThen { diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/IntegrationTest.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/IntegrationTest.kt index 39b693dd4d..e52cf01f40 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/IntegrationTest.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/IntegrationTest.kt @@ -12,10 +12,7 @@ import org.junit.rules.ExternalResource * Base class for all integration tests that require common setup and/or teardown. * eg. serialization, database schema creation and data population / clean-up */ - abstract class IntegrationTest { - open protected val databaseSchemas = Companion.databaseSchemas - // System properties set in main 'corda-project' build.gradle // Note: the database provider configuration file for integration tests should specify: // dataSource.user = ${nodeOrganizationName} @@ -63,10 +60,10 @@ abstract class IntegrationTest { class IntegrationTestSchemas(vararg var list : String) : ExternalResource() { override fun before() { - IntegrationTest.Companion.databaseSchemas.addAll(list) + IntegrationTest.databaseSchemas.addAll(list) } override fun after() { - IntegrationTest.Companion.databaseSchemas.clear() + IntegrationTest.databaseSchemas.clear() } } diff --git a/testing/test-utils/src/main/resources/database-scripts/azure-sql/db-global-cleanup.sql b/testing/test-utils/src/main/resources/database-scripts/azure-sql/db-global-cleanup.sql new file mode 100644 index 0000000000..c77a50dfb7 --- /dev/null +++ b/testing/test-utils/src/main/resources/database-scripts/azure-sql/db-global-cleanup.sql @@ -0,0 +1,48 @@ +DROP TABLE IF EXISTS ${schema}.node_attachments; +DROP TABLE IF EXISTS ${schema}.node_checkpoints; +DROP TABLE IF EXISTS ${schema}.node_transactions; +DROP TABLE IF EXISTS ${schema}.node_message_retry; +DROP TABLE IF EXISTS ${schema}.node_message_ids; +DROP TABLE IF EXISTS ${schema}.vault_states; +DROP TABLE IF EXISTS ${schema}.node_our_key_pairs; +DROP TABLE IF EXISTS ${schema}.node_scheduled_states; +DROP TABLE IF EXISTS ${schema}.node_network_map_nodes; +DROP TABLE IF EXISTS ${schema}.node_network_map_subscribers; +DROP TABLE IF EXISTS ${schema}.node_notary_commit_log; +DROP TABLE IF EXISTS ${schema}.node_transaction_mappings; +DROP TABLE IF EXISTS ${schema}.vault_fungible_states_parts; +DROP TABLE IF EXISTS ${schema}.vault_linear_states_parts; +DROP TABLE IF EXISTS ${schema}.vault_fungible_states; +DROP TABLE IF EXISTS ${schema}.vault_linear_states; +DROP TABLE IF EXISTS ${schema}.node_bft_committed_states; +DROP TABLE IF EXISTS ${schema}.node_raft_committed_states; +DROP TABLE IF EXISTS ${schema}.vault_transaction_notes; +DROP TABLE IF EXISTS ${schema}.link_nodeinfo_party; +DROP TABLE IF EXISTS ${schema}.node_link_nodeinfo_party; +DROP TABLE IF EXISTS ${schema}.node_info_party_cert; +DROP TABLE IF EXISTS ${schema}.node_info_hosts; +DROP TABLE IF EXISTS ${schema}.node_infos; +DROP TABLE IF EXISTS ${schema}.cp_states; +DROP TABLE IF EXISTS ${schema}.node_contract_upgrades; +DROP TABLE IF EXISTS ${schema}.node_identities; +DROP TABLE IF EXISTS ${schema}.node_named_identities; +DROP TABLE IF EXISTS ${schema}.children; +DROP TABLE IF EXISTS ${schema}.parents; +DROP TABLE IF EXISTS ${schema}.contract_cash_states; +DROP TABLE IF EXISTS ${schema}.messages; +DROP TABLE IF EXISTS ${schema}.DummyDealStateSchemaV1$PersistentDummyDealState_participants; +DROP TABLE IF EXISTS ${schema}.DummyLinearStateSchemaV1$PersistentDummyLinearState_participants; +DROP TABLE IF EXISTS ${schema}.DummyLinearStateSchemaV2$PersistentDummyLinearState_participants; +DROP TABLE IF EXISTS ${schema}.SampleCashSchemaV2$PersistentCashState_participants; +DROP TABLE IF EXISTS ${schema}.SampleCashSchemaV3$PersistentCashState_participants; +DROP TABLE IF EXISTS ${schema}.SampleCommercialPaperSchemaV2$PersistentCommercialPaperState_participants; +DROP TABLE IF EXISTS ${schema}.cash_states_v2; +DROP TABLE IF EXISTS ${schema}.cash_states_v3; +DROP TABLE IF EXISTS ${schema}.cp_states_v2; +DROP TABLE IF EXISTS ${schema}.dummy_deal_states; +DROP TABLE IF EXISTS ${schema}.dummy_linear_states; +DROP TABLE IF EXISTS ${schema}.dummy_linear_states_v2; +DROP TABLE IF EXISTS ${schema}.node_mutual_exclusion; +DROP SEQUENCE IF EXISTS ${schema}.hibernate_sequence; +DROP USER IF EXISTS ${schema}; +DROP SCHEMA IF EXISTS ${schema}; \ No newline at end of file diff --git a/testing/test-utils/src/main/resources/database-scripts/azure-sql/db-global-setup.sql b/testing/test-utils/src/main/resources/database-scripts/azure-sql/db-global-setup.sql new file mode 100644 index 0000000000..d1bc41c273 --- /dev/null +++ b/testing/test-utils/src/main/resources/database-scripts/azure-sql/db-global-setup.sql @@ -0,0 +1,4 @@ +CREATE SCHEMA ${schema}; +CREATE USER ${schema} FOR LOGIN ${schema} WITH DEFAULT_SCHEMA = ${schema}; +GRANT ALTER, DELETE, EXECUTE, INSERT, REFERENCES, SELECT, UPDATE, VIEW DEFINITION ON SCHEMA::${schema} TO ${schema}; +GRANT CREATE TABLE, CREATE PROCEDURE, CREATE FUNCTION, CREATE VIEW TO ${schema}; \ No newline at end of file diff --git a/testing/test-utils/src/main/resources/database-scripts/azure-sql/db-setup.sql b/testing/test-utils/src/main/resources/database-scripts/azure-sql/db-setup.sql new file mode 100644 index 0000000000..fc4542c2fa --- /dev/null +++ b/testing/test-utils/src/main/resources/database-scripts/azure-sql/db-setup.sql @@ -0,0 +1,46 @@ +DROP TABLE IF EXISTS ${schema}.node_attachments; +DROP TABLE IF EXISTS ${schema}.node_checkpoints; +DROP TABLE IF EXISTS ${schema}.node_transactions; +DROP TABLE IF EXISTS ${schema}.node_message_retry; +DROP TABLE IF EXISTS ${schema}.node_message_ids; +DROP TABLE IF EXISTS ${schema}.vault_states; +DROP TABLE IF EXISTS ${schema}.node_our_key_pairs; +DROP TABLE IF EXISTS ${schema}.node_scheduled_states; +DROP TABLE IF EXISTS ${schema}.node_network_map_nodes; +DROP TABLE IF EXISTS ${schema}.node_network_map_subscribers; +DROP TABLE IF EXISTS ${schema}.node_notary_commit_log; +DROP TABLE IF EXISTS ${schema}.node_transaction_mappings; +DROP TABLE IF EXISTS ${schema}.vault_fungible_states_parts; +DROP TABLE IF EXISTS ${schema}.vault_linear_states_parts; +DROP TABLE IF EXISTS ${schema}.vault_fungible_states; +DROP TABLE IF EXISTS ${schema}.vault_linear_states; +DROP TABLE IF EXISTS ${schema}.node_bft_committed_states; +DROP TABLE IF EXISTS ${schema}.node_raft_committed_states; +DROP TABLE IF EXISTS ${schema}.vault_transaction_notes; +DROP TABLE IF EXISTS ${schema}.link_nodeinfo_party; +DROP TABLE IF EXISTS ${schema}.node_link_nodeinfo_party; +DROP TABLE IF EXISTS ${schema}.node_info_party_cert; +DROP TABLE IF EXISTS ${schema}.node_info_hosts; +DROP TABLE IF EXISTS ${schema}.node_infos; +DROP TABLE IF EXISTS ${schema}.cp_states; +DROP TABLE IF EXISTS ${schema}.node_contract_upgrades; +DROP TABLE IF EXISTS ${schema}.node_identities; +DROP TABLE IF EXISTS ${schema}.node_named_identities; +DROP TABLE IF EXISTS ${schema}.children; +DROP TABLE IF EXISTS ${schema}.parents; +DROP TABLE IF EXISTS ${schema}.contract_cash_states; +DROP TABLE IF EXISTS ${schema}.messages; +DROP TABLE IF EXISTS ${schema}.DummyDealStateSchemaV1$PersistentDummyDealState_participants; +DROP TABLE IF EXISTS ${schema}.DummyLinearStateSchemaV1$PersistentDummyLinearState_participants; +DROP TABLE IF EXISTS ${schema}.DummyLinearStateSchemaV2$PersistentDummyLinearState_participants; +DROP TABLE IF EXISTS ${schema}.SampleCashSchemaV2$PersistentCashState_participants; +DROP TABLE IF EXISTS ${schema}.SampleCashSchemaV3$PersistentCashState_participants; +DROP TABLE IF EXISTS ${schema}.SampleCommercialPaperSchemaV2$PersistentCommercialPaperState_participants; +DROP TABLE IF EXISTS ${schema}.cash_states_v2; +DROP TABLE IF EXISTS ${schema}.cash_states_v3; +DROP TABLE IF EXISTS ${schema}.cp_states_v2; +DROP TABLE IF EXISTS ${schema}.dummy_deal_states; +DROP TABLE IF EXISTS ${schema}.dummy_linear_states; +DROP TABLE IF EXISTS ${schema}.dummy_linear_states_v2; +DROP TABLE IF EXISTS ${schema}.node_mutual_exclusion; +DROP SEQUENCE IF EXISTS ${schema}.hibernate_sequence; \ No newline at end of file diff --git a/testing/test-utils/src/main/resources/database-scripts/sql-azure/master-user-setup.sql b/testing/test-utils/src/main/resources/database-scripts/azure-sql/master-user-setup.sql similarity index 58% rename from testing/test-utils/src/main/resources/database-scripts/sql-azure/master-user-setup.sql rename to testing/test-utils/src/main/resources/database-scripts/azure-sql/master-user-setup.sql index a78bee4e1a..fe86225fdd 100644 --- a/testing/test-utils/src/main/resources/database-scripts/sql-azure/master-user-setup.sql +++ b/testing/test-utils/src/main/resources/database-scripts/azure-sql/master-user-setup.sql @@ -1,87 +1,49 @@ --once off script to run against master database (not a user database) CREATE LOGIN AliceCorp WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER AliceCorp FROM LOGIN AliceCorp; CREATE LOGIN AliceCorp_10000 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER AliceCorp_10000 FROM LOGIN AliceCorp_10003; CREATE LOGIN AliceCorp_10003 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER AliceCorp_10003 FROM LOGIN AliceCorp_10003; CREATE LOGIN AliceCorp_10006 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER AliceCorp_10006 FROM LOGIN AliceCorp_10006; -CREATE LOGIN BankA WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER BankA FROM LOGIN BankA; -CREATE LOGIN BankA_10000 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER BankA_10000 FROM LOGIN BankA_10000; -CREATE LOGIN BankA_10003 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER BankA_10003 FROM LOGIN BankA_10003; -CREATE LOGIN BankA_10006 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER BankA_10006 FROM LOGIN BankA_10006; -CREATE LOGIN BankB WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER BankB FROM LOGIN BankB; -CREATE LOGIN BobPlc WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER BobPlc FROM LOGIN BobPlc; -CREATE LOGIN BobPlc_10000 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER BobPlc_10000 FROM LOGIN BobPlc_10000; -CREATE LOGIN BobPlc_10003 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER BobPlc_10003 FROM LOGIN BobPlc_10003; -CREATE LOGIN BobPlc_10006 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER BobPlc_10006 FROM LOGIN BobPlc_10006; -CREATE LOGIN CharlieLtd WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER CharlieLtd FROM LOGIN CharlieLtd; -CREATE LOGIN DistributedService_0 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER DistributedService_0 FROM LOGIN DistributedService_0; -CREATE LOGIN DistributedService_1 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER DistributedService_1 FROM LOGIN DistributedService_1; -CREATE LOGIN NetworkMapService WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER NetworkMapService FROM LOGIN NetworkMapService; -CREATE LOGIN Notary WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER Notary FROM LOGIN Notary; -CREATE LOGIN NotaryService WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER NotaryService FROM LOGIN NotaryService; -CREATE LOGIN NotaryService0 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER NotaryService0 FROM LOGIN NotaryService0; -CREATE LOGIN NotaryService1 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER NotaryService1 FROM LOGIN NotaryService1; -CREATE LOGIN NotaryService2 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER NotaryService2 FROM LOGIN NotaryService2; -CREATE LOGIN NotaryService_0 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER NotaryService_0 FROM LOGIN NotaryService_0; -CREATE LOGIN NotaryService_1 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER NotaryService_1 FROM LOGIN NotaryService_1; -CREATE LOGIN NotaryService_2 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER NotaryService_2 FROM LOGIN NotaryService_2; -CREATE LOGIN MegaCorp WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER MegaCorp FOR LOGIN MegaCorp; -CREATE LOGIN node_0 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER node_0 FOR LOGIN node_0; -CREATE LOGIN node_1 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER node_1 FOR LOGIN node_1; -CREATE LOGIN node_2 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER node_2 FOR LOGIN node_2; -CREATE LOGIN node_3 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER node_3 FOR LOGIN node_3; -CREATE LOGIN node_4 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER node_4 FOR LOGIN node_4; -CREATE LOGIN node_5 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER node_5 FOR LOGIN node_5; -CREATE LOGIN node_6 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER node_6 FOR LOGIN node_6; -CREATE LOGIN node_7 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER node_7 FOR LOGIN node_7; -CREATE LOGIN node_8 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER node_8 FOR LOGIN node_8; -CREATE LOGIN node_9 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER node_9 FOR LOGIN node_9; -CREATE LOGIN RAFTNotaryService_0 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER RAFTNotaryService_0 FROM LOGIN RAFTNotaryService_0; -CREATE LOGIN RAFTNotaryService_1 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER RAFTNotaryService_1 FROM LOGIN RAFTNotaryService_1; -CREATE LOGIN RAFTNotaryService_2 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER RAFTNotaryService_2 FROM LOGIN RAFTNotaryService_2; -CREATE LOGIN RegulatorA WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER RegulatorA FROM LOGIN RegulatorA; CREATE LOGIN AliceCorp_10012 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER AliceCorp_10012 FROM LOGIN AliceCorp_10012; -CREATE LOGIN BobPlc_10012 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER BobPlc_10012 FROM LOGIN BobPlc_10012; +CREATE LOGIN BankA WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN BankA_10000 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN BankA_10003 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN BankA_10006 WITH PASSWORD = 'yourStrong(!)Password'; CREATE LOGIN BankA_10012 WITH PASSWORD = 'yourStrong(!)Password'; -CREATE USER BankA_10012 FROM LOGIN BankA_10012; \ No newline at end of file +CREATE LOGIN BankB WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN BobPlc WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN BobPlc_10000 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN BobPlc_10003 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN BobPlc_10006 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN BobPlc_10012 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN CharlieLtd WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN CharlieLtd_10000 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN CharlieLtd_10003 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN CharlieLtd WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN DistributedService_0 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN DistributedService_1 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN NetworkMapService WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN Notary WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN NotaryService WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN NotaryService_10000 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN NotaryService_10003 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN NotaryService0 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN NotaryService1 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN NotaryService2 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN NotaryService_0 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN NotaryService_1 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN NotaryService_2 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN MegaCorp WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN node_0 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN node_1 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN node_2 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN node_3 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN node_4 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN node_5 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN node_6 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN node_7 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN node_8 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN node_9 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN RAFTNotaryService_0 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN RAFTNotaryService_1 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN RAFTNotaryService_2 WITH PASSWORD = 'yourStrong(!)Password'; +CREATE LOGIN RegulatorA WITH PASSWORD = 'yourStrong(!)Password'; \ No newline at end of file diff --git a/testing/test-utils/src/main/resources/database-scripts/sql-server/db-global-cleanup.sql b/testing/test-utils/src/main/resources/database-scripts/sql-server/db-global-cleanup.sql new file mode 100644 index 0000000000..8a1d6cc4e8 --- /dev/null +++ b/testing/test-utils/src/main/resources/database-scripts/sql-server/db-global-cleanup.sql @@ -0,0 +1,49 @@ +DROP TABLE IF EXISTS ${schema}.node_attachments; +DROP TABLE IF EXISTS ${schema}.node_checkpoints; +DROP TABLE IF EXISTS ${schema}.node_transactions; +DROP TABLE IF EXISTS ${schema}.node_message_retry; +DROP TABLE IF EXISTS ${schema}.node_message_ids; +DROP TABLE IF EXISTS ${schema}.vault_states; +DROP TABLE IF EXISTS ${schema}.node_our_key_pairs; +DROP TABLE IF EXISTS ${schema}.node_scheduled_states; +DROP TABLE IF EXISTS ${schema}.node_network_map_nodes; +DROP TABLE IF EXISTS ${schema}.node_network_map_subscribers; +DROP TABLE IF EXISTS ${schema}.node_notary_commit_log; +DROP TABLE IF EXISTS ${schema}.node_transaction_mappings; +DROP TABLE IF EXISTS ${schema}.vault_fungible_states_parts; +DROP TABLE IF EXISTS ${schema}.vault_linear_states_parts; +DROP TABLE IF EXISTS ${schema}.vault_fungible_states; +DROP TABLE IF EXISTS ${schema}.vault_linear_states; +DROP TABLE IF EXISTS ${schema}.node_bft_committed_states; +DROP TABLE IF EXISTS ${schema}.node_raft_committed_states; +DROP TABLE IF EXISTS ${schema}.vault_transaction_notes; +DROP TABLE IF EXISTS ${schema}.link_nodeinfo_party; +DROP TABLE IF EXISTS ${schema}.node_link_nodeinfo_party; +DROP TABLE IF EXISTS ${schema}.node_info_party_cert; +DROP TABLE IF EXISTS ${schema}.node_info_hosts; +DROP TABLE IF EXISTS ${schema}.node_infos; +DROP TABLE IF EXISTS ${schema}.cp_states; +DROP TABLE IF EXISTS ${schema}.node_contract_upgrades; +DROP TABLE IF EXISTS ${schema}.node_identities; +DROP TABLE IF EXISTS ${schema}.node_named_identities; +DROP TABLE IF EXISTS ${schema}.children; +DROP TABLE IF EXISTS ${schema}.parents; +DROP TABLE IF EXISTS ${schema}.contract_cash_states; +DROP TABLE IF EXISTS ${schema}.messages; +DROP TABLE IF EXISTS ${schema}.DummyDealStateSchemaV1$PersistentDummyDealState_participants; +DROP TABLE IF EXISTS ${schema}.DummyLinearStateSchemaV1$PersistentDummyLinearState_participants; +DROP TABLE IF EXISTS ${schema}.DummyLinearStateSchemaV2$PersistentDummyLinearState_participants; +DROP TABLE IF EXISTS ${schema}.SampleCashSchemaV2$PersistentCashState_participants; +DROP TABLE IF EXISTS ${schema}.SampleCashSchemaV3$PersistentCashState_participants; +DROP TABLE IF EXISTS ${schema}.SampleCommercialPaperSchemaV2$PersistentCommercialPaperState_participants; +DROP TABLE IF EXISTS ${schema}.cash_states_v2; +DROP TABLE IF EXISTS ${schema}.cash_states_v3; +DROP TABLE IF EXISTS ${schema}.cp_states_v2; +DROP TABLE IF EXISTS ${schema}.dummy_deal_states; +DROP TABLE IF EXISTS ${schema}.dummy_linear_states; +DROP TABLE IF EXISTS ${schema}.dummy_linear_states_v2; +DROP TABLE IF EXISTS ${schema}.node_mutual_exclusion; +DROP SEQUENCE IF EXISTS ${schema}.hibernate_sequence; +DROP USER IF EXISTS ${schema}; +DROP LOGIN ${schema}; +DROP SCHEMA IF EXISTS ${schema}; \ No newline at end of file diff --git a/testing/test-utils/src/main/resources/database-scripts/sql-server/db-global-setup.sql b/testing/test-utils/src/main/resources/database-scripts/sql-server/db-global-setup.sql new file mode 100644 index 0000000000..807bd5ad98 --- /dev/null +++ b/testing/test-utils/src/main/resources/database-scripts/sql-server/db-global-setup.sql @@ -0,0 +1,54 @@ +DROP TABLE IF EXISTS ${schema}.node_attachments; +DROP TABLE IF EXISTS ${schema}.node_checkpoints; +DROP TABLE IF EXISTS ${schema}.node_transactions; +DROP TABLE IF EXISTS ${schema}.node_message_retry; +DROP TABLE IF EXISTS ${schema}.node_message_ids; +DROP TABLE IF EXISTS ${schema}.vault_states; +DROP TABLE IF EXISTS ${schema}.node_our_key_pairs; +DROP TABLE IF EXISTS ${schema}.node_scheduled_states; +DROP TABLE IF EXISTS ${schema}.node_network_map_nodes; +DROP TABLE IF EXISTS ${schema}.node_network_map_subscribers; +DROP TABLE IF EXISTS ${schema}.node_notary_commit_log; +DROP TABLE IF EXISTS ${schema}.node_transaction_mappings; +DROP TABLE IF EXISTS ${schema}.vault_fungible_states_parts; +DROP TABLE IF EXISTS ${schema}.vault_linear_states_parts; +DROP TABLE IF EXISTS ${schema}.vault_fungible_states; +DROP TABLE IF EXISTS ${schema}.vault_linear_states; +DROP TABLE IF EXISTS ${schema}.node_bft_committed_states; +DROP TABLE IF EXISTS ${schema}.node_raft_committed_states; +DROP TABLE IF EXISTS ${schema}.vault_transaction_notes; +DROP TABLE IF EXISTS ${schema}.link_nodeinfo_party; +DROP TABLE IF EXISTS ${schema}.node_link_nodeinfo_party; +DROP TABLE IF EXISTS ${schema}.node_info_party_cert; +DROP TABLE IF EXISTS ${schema}.node_info_hosts; +DROP TABLE IF EXISTS ${schema}.node_infos; +DROP TABLE IF EXISTS ${schema}.cp_states; +DROP TABLE IF EXISTS ${schema}.node_contract_upgrades; +DROP TABLE IF EXISTS ${schema}.node_identities; +DROP TABLE IF EXISTS ${schema}.node_named_identities; +DROP TABLE IF EXISTS ${schema}.children; +DROP TABLE IF EXISTS ${schema}.parents; +DROP TABLE IF EXISTS ${schema}.contract_cash_states; +DROP TABLE IF EXISTS ${schema}.messages; +DROP TABLE IF EXISTS ${schema}.DummyDealStateSchemaV1$PersistentDummyDealState_participants; +DROP TABLE IF EXISTS ${schema}.DummyLinearStateSchemaV1$PersistentDummyLinearState_participants; +DROP TABLE IF EXISTS ${schema}.DummyLinearStateSchemaV2$PersistentDummyLinearState_participants; +DROP TABLE IF EXISTS ${schema}.SampleCashSchemaV2$PersistentCashState_participants; +DROP TABLE IF EXISTS ${schema}.SampleCashSchemaV3$PersistentCashState_participants; +DROP TABLE IF EXISTS ${schema}.SampleCommercialPaperSchemaV2$PersistentCommercialPaperState_participants; +DROP TABLE IF EXISTS ${schema}.cash_states_v2; +DROP TABLE IF EXISTS ${schema}.cash_states_v3; +DROP TABLE IF EXISTS ${schema}.cp_states_v2; +DROP TABLE IF EXISTS ${schema}.dummy_deal_states; +DROP TABLE IF EXISTS ${schema}.dummy_linear_states; +DROP TABLE IF EXISTS ${schema}.dummy_linear_states_v2; +DROP TABLE IF EXISTS ${schema}.node_mutual_exclusion; +DROP SEQUENCE IF EXISTS ${schema}.hibernate_sequence; +DROP USER IF EXISTS ${schema}; +DROP LOGIN ${schema}; +DROP SCHEMA IF EXISTS ${schema}; +CREATE LOGIN ${schema} WITH PASSWORD = 'yourStrong(!)Password'; +CREATE SCHEMA ${schema}; +CREATE USER ${schema} FOR LOGIN ${schema} WITH DEFAULT_SCHEMA = ${schema}; +GRANT ALTER, DELETE, EXECUTE, INSERT, REFERENCES, SELECT, UPDATE, VIEW DEFINITION ON SCHEMA::${schema} TO ${schema}; +GRANT CREATE TABLE, CREATE PROCEDURE, CREATE FUNCTION, CREATE VIEW TO ${schema}; \ No newline at end of file diff --git a/testing/test-utils/src/main/resources/database-scripts/sql-azure/db-setup.sql b/testing/test-utils/src/main/resources/database-scripts/sql-server/db-setup.sql similarity index 97% rename from testing/test-utils/src/main/resources/database-scripts/sql-azure/db-setup.sql rename to testing/test-utils/src/main/resources/database-scripts/sql-server/db-setup.sql index d3c0065a79..8658cb9acf 100644 --- a/testing/test-utils/src/main/resources/database-scripts/sql-azure/db-setup.sql +++ b/testing/test-utils/src/main/resources/database-scripts/sql-server/db-setup.sql @@ -42,6 +42,7 @@ DROP TABLE IF EXISTS ${schema}.cp_states_v2; DROP TABLE IF EXISTS ${schema}.dummy_deal_states; DROP TABLE IF EXISTS ${schema}.dummy_linear_states; DROP TABLE IF EXISTS ${schema}.dummy_linear_states_v2; +DROP TABLE IF EXISTS ${schema}.node_mutual_exclusion; DROP SEQUENCE IF EXISTS ${schema}.hibernate_sequence; IF NOT EXISTS (SELECT schema_name FROM information_schema.schemata WHERE schema_name = '${schema}') EXEC('CREATE SCHEMA ${schema}'); IF NOT EXISTS (SELECT * FROM sys.sysusers WHERE name='${schema}') CREATE USER ${schema} FOR LOGIN ${schema} WITH DEFAULT_SCHEMA = ${schema}; diff --git a/testing/test-utils/src/main/resources/integration-sql-azure.conf b/testing/test-utils/src/main/resources/integration-azure-sql.conf similarity index 100% rename from testing/test-utils/src/main/resources/integration-sql-azure.conf rename to testing/test-utils/src/main/resources/integration-azure-sql.conf diff --git a/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierTests.kt b/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierTests.kt index 2ac14a7773..60ad59b5ea 100644 --- a/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierTests.kt +++ b/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierTests.kt @@ -12,11 +12,9 @@ import net.corda.finance.DOLLARS import net.corda.finance.flows.CashIssueFlow import net.corda.finance.flows.CashPaymentFlow import net.corda.node.services.config.VerifierType -import net.corda.testing.ALICE -import net.corda.testing.ALICE_NAME -import net.corda.testing.DUMMY_NOTARY -import net.corda.testing.SerializationEnvironmentRule +import net.corda.testing.* import net.corda.testing.node.NotarySpec +import org.junit.ClassRule import org.junit.Rule import org.junit.Test import java.util.* @@ -24,7 +22,11 @@ import java.util.concurrent.atomic.AtomicInteger import kotlin.test.assertNotNull import kotlin.test.assertTrue -class VerifierTests { +class VerifierTests : IntegrationTest() { + companion object { + @ClassRule @JvmField + val databaseSchemas = IntegrationTestSchemas(ALICE.toDatabaseSchemaName(), DUMMY_NOTARY.toDatabaseSchemaName()) + } @Rule @JvmField val testSerialization = SerializationEnvironmentRule(true) diff --git a/webserver/src/integration-test/kotlin/net/corda/webserver/WebserverDriverTests.kt b/webserver/src/integration-test/kotlin/net/corda/webserver/WebserverDriverTests.kt index ee85cef6fd..c55595d634 100644 --- a/webserver/src/integration-test/kotlin/net/corda/webserver/WebserverDriverTests.kt +++ b/webserver/src/integration-test/kotlin/net/corda/webserver/WebserverDriverTests.kt @@ -2,16 +2,17 @@ package net.corda.webserver import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.getOrThrow -import net.corda.testing.DUMMY_BANK_A +import net.corda.testing.* import net.corda.testing.driver.WebserverHandle import net.corda.testing.driver.addressMustBeBound import net.corda.testing.driver.addressMustNotBeBound import net.corda.testing.driver.driver +import org.junit.ClassRule import org.junit.Test import java.util.concurrent.Executors import java.util.concurrent.ScheduledExecutorService -class WebserverDriverTests { +class WebserverDriverTests : IntegrationTest() { companion object { val executorService: ScheduledExecutorService = Executors.newScheduledThreadPool(2) @@ -22,6 +23,9 @@ class WebserverDriverTests { fun webserverMustBeDown(webserverAddr: NetworkHostAndPort) { addressMustNotBeBound(executorService, webserverAddr) } + + @ClassRule @JvmField + val databaseSchemas = IntegrationTestSchemas(DUMMY_BANK_A.toDatabaseSchemaName()) } @Test