-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pivotal ID # 181937926: Avoid restarting ITests containers #560
Merged
Juan-EBI
merged 4 commits into
master
from
chore/pivotal-181937926-avoid-restarting-itests-containers
May 16, 2022
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
org.gradle.parallel=false | ||
org.gradle.jvmargs=-Xmx2g | ||
org.gradle.jvmargs=-Xmx4g |
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
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
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
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
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
6 changes: 3 additions & 3 deletions
6
...ubmission-webapp/src/itest/kotlin/ac/uk/ebi/biostd/itest/factory/AllInOneSubmissionXml.kt
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
119 changes: 119 additions & 0 deletions
119
submission/submission-webapp/src/itest/kotlin/ac/uk/ebi/biostd/itest/itest/ITestListener.kt
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,119 @@ | ||
package ac.uk.ebi.biostd.itest.itest | ||
|
||
import ac.uk.ebi.biostd.itest.common.CHARACTER_SET | ||
import ac.uk.ebi.biostd.itest.common.COLLATION | ||
import ac.uk.ebi.biostd.itest.common.FIRE_PASSWORD | ||
import ac.uk.ebi.biostd.itest.common.FIRE_USERNAME | ||
import ac.uk.ebi.biostd.itest.common.SpecificMySQLContainer | ||
import ac.uk.ebi.biostd.itest.wiremock.TestWireMockTransformer | ||
import ac.uk.ebi.biostd.itest.wiremock.TestWireMockTransformer.Companion.newTransformer | ||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import com.github.tomakehurst.wiremock.client.WireMock | ||
import com.github.tomakehurst.wiremock.client.WireMock.post | ||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration | ||
import ebi.ac.uk.db.MINIMUM_RUNNING_TIME | ||
import ebi.ac.uk.db.MONGO_VERSION | ||
import ebi.ac.uk.db.MYSQL_VERSION | ||
import org.junit.platform.launcher.TestExecutionListener | ||
import org.junit.platform.launcher.TestPlan | ||
import org.testcontainers.containers.MongoDBContainer | ||
import org.testcontainers.containers.startupcheck.MinimumDurationRunningStartupCheckStrategy | ||
import org.testcontainers.utility.DockerImageName.parse | ||
import uk.ac.ebi.fire.client.api.FIRE_OBJECTS_URL | ||
import java.io.File | ||
import java.nio.file.Files | ||
import java.time.Duration.ofSeconds | ||
|
||
class ITestListener : TestExecutionListener { | ||
|
||
override fun testPlanExecutionStarted(testPlan: TestPlan) { | ||
mongoSetup() | ||
mySqlSetup() | ||
fireSetup() | ||
appPropertiesSetup() | ||
} | ||
|
||
override fun testPlanExecutionFinished(testPlan: TestPlan) { | ||
mongoContainer.stop() | ||
mysqlContainer.stop() | ||
fireApiMock.stop() | ||
} | ||
|
||
private fun mongoSetup() { | ||
mongoContainer.start() | ||
System.setProperty("spring.data.mongodb.uri", mongoContainer.getReplicaSetUrl("biostudies-test")) | ||
System.setProperty("spring.data.mongodb.database", "biostudies-test") | ||
} | ||
|
||
private fun mySqlSetup() { | ||
mysqlContainer.start() | ||
System.setProperty("spring.datasource.url", mysqlContainer.jdbcUrl) | ||
System.setProperty("spring.datasource.username", mysqlContainer.username) | ||
System.setProperty("spring.datasource.password", mysqlContainer.password) | ||
} | ||
|
||
private fun fireSetup() { | ||
fireApiMock.stubFor( | ||
post(WireMock.urlMatching(FIRE_OBJECTS_URL)) | ||
.withBasicAuth(FIRE_USERNAME, FIRE_PASSWORD) | ||
.willReturn(WireMock.aResponse().withTransformers(TestWireMockTransformer.name)) | ||
) | ||
fireApiMock.start() | ||
|
||
System.setProperty("app.fire.host", fireApiMock.baseUrl()) | ||
System.setProperty("app.fire.username", FIRE_USERNAME) | ||
System.setProperty("app.fire.password", FIRE_PASSWORD) | ||
} | ||
|
||
private fun appPropertiesSetup() { | ||
System.setProperty("app.submissionPath", submissionPath.absolutePath) | ||
System.setProperty("app.ftpPath", ftpPath.absolutePath) | ||
System.setProperty("app.fireTempDirPath", fireTempFolder.absolutePath) | ||
System.setProperty("app.tempDirPath", tempDirPath.absolutePath) | ||
System.setProperty("app.requestFilesPath", requestFilesPath.absolutePath) | ||
System.setProperty("app.security.filesDirPath", dropboxPath.absolutePath) | ||
System.setProperty("app.security.magicDirPath", magicDirPath.absolutePath) | ||
System.setProperty("app.persistence.enableFire", "${System.getProperty("enableFire").toBoolean()}") | ||
} | ||
|
||
companion object { | ||
private val testAppFolder = Files.createTempDirectory("test-app-folder").toFile() | ||
|
||
internal val submissionPath = testAppFolder.createDirectory("submission") | ||
internal val firePath = testAppFolder.createDirectory("fire-db") | ||
internal val fireTempFolder = testAppFolder.createDirectory("fire-temp") | ||
internal val ftpPath = testAppFolder.createDirectory("ftpPath") | ||
internal val tempDirPath = testAppFolder.createDirectory("tempDirPath") | ||
internal val tempFolder = testAppFolder.createDirectory("testTempDir") | ||
internal val requestFilesPath = testAppFolder.createDirectory("requestFilesPath") | ||
internal val magicDirPath = testAppFolder.createDirectory("magic") | ||
internal val dropboxPath = testAppFolder.createDirectory("dropbox") | ||
|
||
private val mongoContainer = createMongoContainer(MONGO_VERSION) | ||
private val mysqlContainer = createMysqlContainer(MYSQL_VERSION, "Schema.sql") | ||
private val fireApiMock = createFireApiMock(submissionPath, ftpPath, firePath) | ||
|
||
val enableFire get() = System.getProperty("enableFire").toBoolean() | ||
|
||
private fun createMongoContainer(version: String): MongoDBContainer = | ||
MongoDBContainer(parse(version)) | ||
.withStartupCheckStrategy(MinimumDurationRunningStartupCheckStrategy(ofSeconds(MINIMUM_RUNNING_TIME))) | ||
|
||
private fun createMysqlContainer(version: String, schema: String): SpecificMySQLContainer = | ||
SpecificMySQLContainer(version) | ||
.withCommand("mysqld --character-set-server=$CHARACTER_SET --collation-server=$COLLATION") | ||
.withInitScript(schema) | ||
.withStartupCheckStrategy(MinimumDurationRunningStartupCheckStrategy(ofSeconds(MINIMUM_RUNNING_TIME))) | ||
|
||
private fun createFireApiMock(submissionDir: File, ftpDir: File, fireDir: File): WireMockServer { | ||
val wireMockTransformer = newTransformer(submissionDir.toPath(), ftpDir.toPath(), fireDir.toPath()) | ||
return WireMockServer(WireMockConfiguration().dynamicPort().extensions(wireMockTransformer)) | ||
} | ||
|
||
private fun File.createDirectory(path: String): File { | ||
val file = resolve(path) | ||
file.mkdir() | ||
return file | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
submission/submission-webapp/src/itest/kotlin/ac/uk/ebi/biostd/itest/itest/TestFunctions.kt
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,10 @@ | ||
package ac.uk.ebi.biostd.itest.itest | ||
|
||
import ac.uk.ebi.biostd.client.integration.web.BioWebClient | ||
import ac.uk.ebi.biostd.client.integration.web.SecurityWebClient | ||
import ac.uk.ebi.biostd.itest.entities.TestUser | ||
|
||
fun getWebClient(serverPort: Int, user: TestUser): BioWebClient { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one-liner
|
||
val securityClient = SecurityWebClient.create("http://localhost:$serverPort") | ||
return securityClient.getAuthenticatedClient(user.email, user.password) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest
ensureUserRegistration