-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DAT-19460. Moved Stress test from the GenerateChangelogTest to the se…
…parate class.
- Loading branch information
1 parent
e39c0f8
commit 6c2b5e3
Showing
4 changed files
with
157 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/groovy/liquibase/harness/stress/StressTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
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.Shared | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
import static liquibase.harness.util.TestUtils.chooseRollbackStrategy | ||
import static liquibase.harness.util.TestUtils.executeCommandScope | ||
|
||
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
77
src/main/groovy/liquibase/harness/stress/StressTestHelper.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |