Skip to content

Commit

Permalink
DAT-19460. Moved Stress test from the GenerateChangelogTest to the se…
Browse files Browse the repository at this point in the history
…parate class. (#981)

* DAT-12908 adding "verify that the 'stored objects' directories are created" check

* refactoring GenerateChangelogTest, wip

* fixed path

* DAT-19460. Moved Stress test from the GenerateChangelogTest to the separate class.

* DAT-19460. returned a line deleted by error

* DAT-19460. commented stress test

* DAT-19460. changes according to PR review

* DAT-19460. using @ignore instead of commenting

---------

Co-authored-by: Tamelianovych <[email protected]>
Co-authored-by: KushnirykOleh <[email protected]>
Co-authored-by: Taras Amelianovych <[email protected]>
  • Loading branch information
4 people authored Jan 24, 2025
1 parent e64baa2 commit 01f4700
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
package liquibase.harness.generateChangelog

import com.datical.liquibase.ext.config.LiquibaseProConfiguration
import liquibase.Scope
import liquibase.database.jvm.JdbcConnection
import liquibase.exception.CommandExecutionException
import liquibase.harness.config.DatabaseUnderTest
import liquibase.harness.config.TestConfig
import liquibase.harness.util.rollback.RollbackStrategy
import liquibase.ui.UIService
import org.junit.jupiter.api.Assumptions
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll

import java.nio.file.Paths

import static GenerateChangelogTestHelper.*
import static liquibase.harness.util.TestUtils.*
import static liquibase.harness.util.FileUtils.*
import static liquibase.harness.generateChangelog.GenerateChangelogTestHelper.*
import static liquibase.harness.util.FileUtils.getResourceContent
import static liquibase.harness.util.FileUtils.readFile
import static liquibase.harness.util.TestUtils.chooseRollbackStrategy
import static liquibase.harness.util.TestUtils.executeCommandScope

class GenerateChangelogTest extends Specification {
@Shared
RollbackStrategy strategy
@Shared
List<DatabaseUnderTest> databases
@Shared
UIService uiService = Scope.getCurrentScope().getUI()
String resourcesDirPath = "src/test/resources/"
long timeMillisBeforeTest
long timeMillisAfterTest

def setupSpec() {
databases = TestConfig.instance.getFilteredDatabasesUnderTest()
Expand Down Expand Up @@ -126,47 +123,6 @@ class GenerateChangelogTest extends Specification {
testInput << buildTestInput()
}



// @Unroll
// def "apply stress test against #testInput.databaseName #testInput.version"() {
// given: "read input data for stress testing"
// Map<String, Object> argsMap = new HashMap()
// argsMap.put("url", testInput.url)
// argsMap.put("username", testInput.username)
// argsMap.put("password", testInput.password)
// boolean shouldRunChangeSet
//
// and: "check database under test is online"
// def connection = testInput.database.getConnection()
// shouldRunChangeSet = connection instanceof JdbcConnection
// assert shouldRunChangeSet: "Database ${testInput.databaseName} ${testInput.version} is offline!"
//
// and: "executing stress test with queries for 10000 rows"
// def map = new LinkedHashMap<String, String>()
// map.put("setup", testInput.setupChangelogPath)
// map.put("insert", testInput.insertChangelogPath)
// map.put("update", testInput.updateChangelogPath)
// map.put("select", testInput.selectChangelogPath)
// for (Map.Entry<String, String> entry : map.entrySet()) {
// timeMillisBeforeTest = System.currentTimeMillis()
// uiService.sendMessage("Executing $entry.key query: 10000 rows!")
// argsMap.put("changeLogFile", entry.value)
// executeCommandScope("update", argsMap)
// timeMillisAfterTest = System.currentTimeMillis()
// uiService.sendMessage("Execution time for $entry.key query: " + (timeMillisAfterTest - timeMillisBeforeTest) / 1000 + "s")
// }
//
// cleanup: "rollback changes if we ran changeSet"
// if (shouldRunChangeSet) {
// argsMap.put("changeLogFile", testInput.setupChangelogPath)
// strategy.performRollback(argsMap)
// }
//
// where: "test input in next data table"
// testInput << buildTestInput()
// }

def cleanupSpec() {
strategy.cleanupDatabase(databases)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,9 @@ class GenerateChangelogTestHelper {
inputList.add(TestInput.builder()
.databaseName(databaseUnderTest.name)
.url(databaseUnderTest.url)
.dbSchema(databaseUnderTest.dbSchema)
.username(databaseUnderTest.username)
.password(databaseUnderTest.password)
.version(databaseUnderTest.version)
.setupChangelogPath(changeLogEntry.value)
.insertChangelogPath(FileUtils.resolveInputFilePaths(databaseUnderTest, baseChangelogPath +
"stress/insert", "xml").get(changeLogEntry.key))
.updateChangelogPath(FileUtils.resolveInputFilePaths(databaseUnderTest, baseChangelogPath +
"stress/update", "xml").get(changeLogEntry.key))
.selectChangelogPath(FileUtils.resolveInputFilePaths(databaseUnderTest, baseChangelogPath +
"stress/select", "xml").get(changeLogEntry.key))
.inputChangelogFile(FileUtils.resolveInputFilePaths(databaseUnderTest, baseChangelogPath +
"expectedChangeLog", "xml").get(changeLogEntry.key))
.expectedSqlPath(FileUtils.resolveInputFilePaths(databaseUnderTest, baseChangelogPath +
Expand Down Expand Up @@ -109,13 +101,8 @@ class GenerateChangelogTestHelper {
String username
String password
String url
String setupChangelogPath
String insertChangelogPath
String updateChangelogPath
String selectChangelogPath
String inputChangelogFile
String expectedSqlPath
String dbSchema
String change
Database database
}
Expand Down
77 changes: 77 additions & 0 deletions src/main/groovy/liquibase/harness/stress/StressTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package liquibase.harness.stress

import liquibase.Scope
import liquibase.database.jvm.JdbcConnection
import liquibase.harness.config.DatabaseUnderTest
import liquibase.harness.config.TestConfig
import liquibase.harness.util.rollback.RollbackStrategy
import liquibase.ui.UIService
import spock.lang.Ignore
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll

import static liquibase.harness.util.TestUtils.chooseRollbackStrategy
import static liquibase.harness.util.TestUtils.executeCommandScope

@Ignore("ignored until discussion regarding it's necessity")
class StressTest extends Specification {
@Shared
RollbackStrategy strategy
@Shared
List<DatabaseUnderTest> databases
@Shared
UIService uiService = Scope.getCurrentScope().getUI()

long timeMillisBeforeTest
long timeMillisAfterTest

def setupSpec() {
databases = TestConfig.instance.getFilteredDatabasesUnderTest()
strategy = chooseRollbackStrategy()
strategy.prepareForRollback(databases)
}

@Unroll
def "apply stress test against #testInput.databaseName #testInput.version"() {
given: "read input data for stress testing"
Map<String, Object> argsMap = new HashMap()
argsMap.put("url", testInput.url)
argsMap.put("username", testInput.username)
argsMap.put("password", testInput.password)
boolean shouldRunChangeSet

and: "check database under test is online"
def connection = testInput.database.getConnection()
shouldRunChangeSet = connection instanceof JdbcConnection
assert shouldRunChangeSet: "Database ${testInput.databaseName} ${testInput.version} is offline!"

and: "executing stress test with queries for 10000 rows"
def map = new LinkedHashMap<String, String>()
map.put("setup", testInput.setupChangelogPath)
map.put("insert", testInput.insertChangelogPath)
map.put("update", testInput.updateChangelogPath)
map.put("select", testInput.selectChangelogPath)
for (Map.Entry<String, String> entry : map.entrySet()) {
timeMillisBeforeTest = System.currentTimeMillis()
uiService.sendMessage("Executing $entry.key query: 10000 rows!")
argsMap.put("changeLogFile", entry.value)
executeCommandScope("update", argsMap)
timeMillisAfterTest = System.currentTimeMillis()
uiService.sendMessage("Execution time for $entry.key query: " + (timeMillisAfterTest - timeMillisBeforeTest) / 1000 + "s")
}

cleanup: "rollback changes if we ran changeSet"
if (shouldRunChangeSet) {
argsMap.put("changeLogFile", testInput.setupChangelogPath)
strategy.performRollback(argsMap)
}

where: "test input in next data table"
testInput << StressTestHelper.buildTestInput()
}

def cleanupSpec() {
strategy.cleanupDatabase(databases)
}
}
77 changes: 77 additions & 0 deletions src/main/groovy/liquibase/harness/stress/StressTestHelper.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package liquibase.harness.stress

import groovy.transform.ToString
import groovy.transform.builder.Builder
import liquibase.Scope
import liquibase.database.Database
import liquibase.harness.config.DatabaseUnderTest
import liquibase.harness.config.TestConfig
import liquibase.harness.util.DatabaseConnectionUtil
import liquibase.harness.util.FileUtils
import liquibase.ui.UIService

import java.nio.file.Path
import java.nio.file.Paths

class StressTestHelper {
final static String baseChangelogPath = "liquibase/harness/generateChangelog/"

static List<TestInput> buildTestInput() {
String commandLineChanges = System.getProperty("change")
List commandLineChangesList = Collections.emptyList()
if (commandLineChanges) {
commandLineChangesList = Arrays.asList(commandLineChanges.contains(",")
? commandLineChanges.split(",")
: commandLineChanges)
}

List<TestInput> inputList = new ArrayList<>()
DatabaseConnectionUtil databaseConnectionUtil = new DatabaseConnectionUtil()
for (DatabaseUnderTest databaseUnderTest : databaseConnectionUtil
.initializeDatabasesConnection(TestConfig.instance.getFilteredDatabasesUnderTest())) {
for (def changeLogEntry : FileUtils.resolveInputFilePaths(databaseUnderTest, baseChangelogPath +
"expectedChangeLog", "xml").entrySet()) {
if (!commandLineChangesList || commandLineChangesList.contains(changeLogEntry.key)) {
inputList.add(TestInput.builder()
.databaseName(databaseUnderTest.name)
.url(databaseUnderTest.url)
.dbSchema(databaseUnderTest.dbSchema)
.username(databaseUnderTest.username)
.password(databaseUnderTest.password)
.version(databaseUnderTest.version)
.setupChangelogPath(changeLogEntry.value)
.insertChangelogPath(FileUtils.resolveInputFilePaths(databaseUnderTest, baseChangelogPath +
"stress/insert", "xml").get(changeLogEntry.key))
.updateChangelogPath(FileUtils.resolveInputFilePaths(databaseUnderTest, baseChangelogPath +
"stress/update", "xml").get(changeLogEntry.key))
.selectChangelogPath(FileUtils.resolveInputFilePaths(databaseUnderTest, baseChangelogPath +
"stress/select", "xml").get(changeLogEntry.key))
.inputChangelogFile(FileUtils.resolveInputFilePaths(databaseUnderTest, baseChangelogPath +
"expectedChangeLog", "xml").get(changeLogEntry.key))
.change(changeLogEntry.key)
.database(databaseUnderTest.database)
.build())
}
}
}
return inputList
}

@Builder
@ToString(includeNames = true, includeFields = true, includePackage = false, excludes = 'database,password')
static class TestInput {
String databaseName
String version
String username
String password
String url
String setupChangelogPath
String insertChangelogPath
String updateChangelogPath
String selectChangelogPath
String inputChangelogFile
String dbSchema
String change
Database database
}
}

0 comments on commit 01f4700

Please sign in to comment.