Skip to content

Commit

Permalink
CORE-19108 Sandbox stress tests (single thread) (#5478)
Browse files Browse the repository at this point in the history
* [CORE-19108]-stress tests for flow and entity sandboxes

* [CORE-19108]-stress tests for flow and entity sandboxes

* [CORE-19108]-stress tests for flow and entity sandboxes

* [CORE-19108]-stress tests for flow and entity sandboxes

* [CORE-19108]-clean-up

* [CORE-19108]-clean-up

* [CORE-19108]-clean-up
  • Loading branch information
bpaunescu authored Jan 24, 2024
1 parent d86f3dc commit ff7b3a0
Show file tree
Hide file tree
Showing 14 changed files with 819 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import picocli.CommandLine
import kotlin.concurrent.thread
import kotlin.system.exitProcess

@Suppress("SpreadOperator")
fun main(args: Array<String>) {
val exitCode = CommandLine(MetricsReaderApp()).execute(*args)
exitProcess(exitCode)
Expand Down
1 change: 0 additions & 1 deletion components/flow/flow-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ plugins {
}

description "Flow service"

dependencies {
compileOnly 'org.osgi:org.osgi.service.component.annotations'
compileOnly "org.osgi:org.osgi.service.component:$osgiServiceComponentVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ configurations {
transitive = false
}
}

dependencies {
compileOnly 'org.osgi:org.osgi.service.component.annotations'
compileOnly "org.osgi:org.osgi.service.component:$osgiServiceComponentVersion"
Expand Down
39 changes: 0 additions & 39 deletions libs/sandbox-internal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,6 @@ configurations {
transitive = false
}
}

sourceSets {
stressTest {
kotlin {
srcDirs += [ 'src/stressTest/kotlin' ]
}
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}

kotlin {
target {
java
compilations.stressTest {
associateWith compilations.main
associateWith compilations.test
}

configurations {
stressTestApi.extendsFrom testApi
stressTestImplementation.extendsFrom testImplementation
stressTestRuntimeOnly.extendsFrom testRuntimeOnly
}
}
}

dependencies {
compileOnly 'org.osgi:org.osgi.service.component.annotations'
compileOnly "org.osgi:osgi.annotation"
Expand Down Expand Up @@ -75,8 +48,6 @@ dependencies {
integrationTestRuntimeOnly project(':libs:lifecycle:lifecycle-impl')
integrationTestRuntimeOnly project(':libs:messaging:messaging-impl')
integrationTestRuntimeOnly project(':libs:messaging:db-message-bus-impl')

stressTestImplementation project(':testing:sandboxes')
}

def integrationTestResources = tasks.named('processIntegrationTestResources', ProcessResources) {
Expand All @@ -88,14 +59,4 @@ def integrationTestResources = tasks.named('processIntegrationTestResources', Pr

tasks.named('testingBundle', Bundle) {
dependsOn integrationTestResources
}

tasks.register('stressTest', Test) {
description = "Runs smoke tests."
group = "verification"

testClassesDirs = project.sourceSets["stressTest"].output.classesDirs
classpath = project.sourceSets["stressTest"].runtimeClasspath

println "Running sandbox stress tests"
}

This file was deleted.

1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ include 'testing:packaging-test-utilities'
include 'testing:persistence-testkit'
include 'testing:sandboxes'
include 'testing:sandboxes:test-api'
include 'testing:sandbox-stresstests'
include 'testing:sandboxes-testkit'
include 'testing:security-manager-utilities'
include 'testing:test-serialization'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import net.corda.orm.EntityManagerFactoryFactory
import net.corda.orm.JpaEntitiesSet
import net.corda.orm.impl.EntityManagerFactoryFactoryImpl
import org.slf4j.LoggerFactory
import java.sql.SQLException
import java.time.Duration
import java.util.UUID
import javax.persistence.EntityManager
Expand All @@ -25,7 +26,7 @@ import javax.sql.DataSource
//@Component(service = [DbConnectionManager::class, FakeDbConnectionManager::class])
@Suppress("TooManyFunctions")
class FakeDbConnectionManager(
connections: List<Pair<UUID, String>>,
private val connections: List<Pair<UUID, String>>,
private val schemaName: String,
private val emff: EntityManagerFactoryFactory = EntityManagerFactoryFactoryImpl()
): DbConnectionManager, DbConnectionOps, DataSourceFactory {
Expand All @@ -45,7 +46,25 @@ class FakeDbConnectionManager(

override fun createEntityManagerFactory(connectionId: UUID, entitiesSet: JpaEntitiesSet):
EntityManagerFactory {
val source = dbSources.single { it.id == connectionId }
var source = dbSources.single { it.id == connectionId }
try {
// This will throw if the datasource is actually closed. This means we need to re-create it
// Ideally we'd re-place it in the dbSources list
println(source.dataSource.connection.isClosed)
} catch (e: SQLException) {
if (e.message!!.contains("has been closed")) {
val conn = connections.single { it.first == connectionId }
source = DbUtils.getEntityManagerConfiguration(
"fake-db-manager-db-$schemaName",
schemaName = "$schemaName${conn.second.replace("-","")}",
createSchema = true).dataSource.let {

NamedDataSources(conn.first, conn.second, it)
}
} else {
throw e
}
}
return emff.create(
source.name,
entitiesSet.classes.toList(),
Expand Down
126 changes: 126 additions & 0 deletions testing/sandbox-stresstests/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import aQute.bnd.gradle.Bundle

plugins {
id 'corda.osgi-test-conventions'
id 'corda.common-library'
}

description "Sandbox stress tests"

configurations {
cpis {
canBeConsumed = false
transitive = false
}
}

// TODO: START CLEANING UP THE ONES WE DON"T NEED.
dependencies {
compileOnly 'org.osgi:org.osgi.service.component.annotations'
compileOnly "org.osgi:org.osgi.service.component:$osgiServiceComponentVersion"

implementation platform("net.corda:corda-api:$cordaApiVersion")

implementation project(':components:configuration:configuration-read-service')
implementation project(':components:db:db-connection-manager')

// implementation project(':components:flow:flow-service')
implementation project(':components:membership:group-policy')
implementation project(':components:persistence:entity-processor-service')
implementation project(':components:persistence:persistence-service-common')
implementation project(':components:virtual-node:cpi-info-read-service')
implementation project(":components:virtual-node:cpk-read-service")
implementation project(':components:virtual-node:sandbox-group-context-service')
implementation project(':components:virtual-node:virtual-node-info-read-service')

implementation project(':libs:flows:external-event-responses')
implementation project(':libs:flows:flow-utils')
implementation project(':libs:flows:flow-api')
implementation project(":libs:messaging:messaging")
implementation project(':libs:metrics')
implementation project(':libs:serialization:serialization-checkpoint-api')
implementation project(":libs:tracing")
implementation project(":libs:utilities")
implementation project(':libs:virtual-node:sandbox-group-context')
implementation project(":libs:virtual-node:virtual-node-datamodel")
implementation project(":libs:serialization:serialization-avro")

implementation 'net.corda:corda-application'
implementation 'net.corda:corda-avro-schema'
implementation 'net.corda:corda-config-schema'
implementation 'net.corda:corda-db-schema'
implementation 'net.corda:corda-topic-schema'
implementation 'org.jetbrains.kotlin:kotlin-osgi-bundle'
implementation 'org.slf4j:slf4j-api'
implementation "io.micrometer:micrometer-registry-prometheus:$micrometerVersion"

testImplementation project(':testing:db-testkit')
testImplementation project(':testing:persistence-testkit')
testImplementation project(':testing:sandboxes-testkit')

testImplementation project(':libs:flows:session-manager-impl')
testImplementation project(':libs:lifecycle:lifecycle-test-impl')
testImplementation project(':libs:lifecycle:lifecycle-impl')
testImplementation project(':libs:lifecycle:registry')
testImplementation project(':testing:flow:flow-utilities')
testImplementation project(':testing:test-utilities')

testRuntimeOnly "org.ops4j.pax.jdbc:pax-jdbc-hsqldb:$paxJdbcVersion"
testRuntimeOnly "org.postgresql:postgresql:$postgresDriverVersion"

// Integration test resources using cpis configuration
cpis project(path: ':testing:cpbs:extendable-cpb', configuration: 'cordaCPB')
cpis project(path: ':testing:bundles:testing-fish', configuration: 'cordaCPB')

// IMPORTANT: do NOT include cpbs (or cpks) as dependencies of the integration test.
// This would cause OSGi to load the bundle twice (once as part of the test) and again
// as part of the CPB loading. This introduces *two* unique instances of classes in the CPKs (remember
// the class is unique by name **and** classloader).

// IMPORTANT: do NOT attempt to use mockito-kotlin in the integration tests.
// It's not an OSGi bundle, so you will get errors (despite Intellij appearing to allow you to use it).

integrationTestImplementation libs.mockito.core

integrationTestImplementation project(':components:flow:flow-service')
integrationTestImplementation project(":testing:db-message-bus-testkit")
integrationTestImplementation project(':libs:db:db-admin-impl')
integrationTestImplementation project(':testing:sandboxes')
integrationTestImplementation project(':testing:test-utilities')
integrationTestImplementation project(':testing:virtual-node-info-read-service-fake')
integrationTestImplementation project(':testing:cpi-info-read-service-fake')
integrationTestImplementation project(':testing:group-policy-test-common')

// needed to import serialization libs
integrationTestRuntimeOnly "org.apache.aries.spifly:org.apache.aries.spifly.dynamic.framework.extension:$ariesDynamicFrameworkExtensionVersion"

integrationTestRuntimeOnly project(':libs:flows:external-event-responses-impl')
integrationTestRuntimeOnly project(':libs:lifecycle:lifecycle-impl')
integrationTestRuntimeOnly project(':libs:messaging:db-message-bus-impl')
integrationTestRuntimeOnly project(':libs:messaging:messaging-impl')
integrationTestRuntimeOnly project(':libs:state-manager:state-manager-db-impl')
integrationTestRuntimeOnly project(':libs:serialization:serialization-checkpoint-api')
integrationTestRuntimeOnly project(':components:db:db-connection-manager-impl')
integrationTestRuntimeOnly project(':components:membership:membership-group-read-impl')
integrationTestRuntimeOnly project(':components:virtual-node:cpk-read-service-impl')

integrationTestRuntimeOnly project(':libs:application:application-impl')
integrationTestRuntimeOnly project(':libs:flows:session-manager-impl')
integrationTestRuntimeOnly project(':libs:serialization:serialization-kryo')

integrationTestRuntimeOnly "com.sun.activation:javax.activation:$activationVersion"
integrationTestRuntimeOnly "org.hsqldb:hsqldb:$hsqldbVersion"
integrationTestRuntimeOnly "org.postgresql:postgresql:$postgresDriverVersion"
}

// Copy the cpi builds declared in the cpis configuration into our resources so we find and load them
def integrationTestResources = tasks.named('processIntegrationTestResources', ProcessResources) {
from(configurations.cpis) {
into 'META-INF'
rename "(.*)-\\Q${version}\\E-package.cpb", "\$1.cpb"
}
}

tasks.named('testingBundle', Bundle) {
dependsOn integrationTestResources
}
Loading

0 comments on commit ff7b3a0

Please sign in to comment.