-
Notifications
You must be signed in to change notification settings - Fork 2
117 fix test container setup #118
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9d9befe
fix test container config by injecting the config instead of exchangi…
DivineThreepwood 743b0ca
fix test container framework integration, made sure mqtt docker conta…
DivineThreepwood 66adfc9
bump version to 3.7.3
DivineThreepwood d1ab6ea
introduce broker manager and shutdown hook for test container
DivineThreepwood b5b7d12
cleanup code
DivineThreepwood cb61f55
handle strange client behaviour that throws an not connected exceptio…
DivineThreepwood 5331478
fix FileSynchronizer null handling in java class.
DivineThreepwood fae838b
Code improvements as requested.
DivineThreepwood 3e8136f
Update outdated actions in workflows to latest versions
LukBelter 87c83cb
Merge pull request #119 from openbase/update_workflow_versions
DivineThreepwood 6e3840a
switch detekt version back to v1.15.0
LukBelter 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,3 +1,3 @@ | ||
| version=3.7.2 | ||
| version=3.7.3 | ||
| org.gradle.caching=true | ||
| org.gradle.parallel=true |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
65 changes: 65 additions & 0 deletions
65
...on/mqtttest/src/main/kotlin/org/openbase/jul/communication/mqtt/test/MqttBrokerManager.kt
This file contains hidden or 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,65 @@ | ||
| package org.openbase.jul.communication.mqtt.test | ||
|
|
||
| import org.openbase.jps.core.JPService | ||
| import org.openbase.jps.exception.JPServiceException | ||
| import org.openbase.jul.communication.jp.JPComHost | ||
| import org.openbase.jul.communication.jp.JPComPort | ||
| import org.openbase.jul.communication.mqtt.SharedMqttClient | ||
| import org.testcontainers.containers.GenericContainer | ||
| import org.testcontainers.utility.DockerImageName | ||
| import org.testcontainers.utility.MountableFile | ||
| import java.nio.file.Files | ||
| import java.nio.file.Path | ||
| import java.time.Duration | ||
| import kotlin.concurrent.Volatile | ||
| import kotlin.io.path.deleteIfExists | ||
|
|
||
| object MqttBrokerManager { | ||
|
|
||
| val STARTUP_TIMEOUT: Duration = Duration.ofSeconds(30) | ||
|
|
||
| var broker: GenericContainer<*>? = null | ||
| val lock = Any() | ||
|
|
||
| fun setupMqtt(testClassName: String, port: Int = 1883) { | ||
| synchronized(lock) { | ||
| if (broker == null) { | ||
| val mosquittoConfig: Path = Files.createTempFile("${testClassName}_mosquitto_", ".conf") | ||
| Files.write( | ||
| mosquittoConfig, listOf( | ||
| "allow_anonymous true", | ||
| "listener $port" | ||
| ) | ||
| ) | ||
| MqttBrokerContainer() | ||
| .withExposedPorts(port) | ||
| .withCopyFileToContainer( | ||
| MountableFile.forHostPath(mosquittoConfig.toString()), | ||
| "/mosquitto/config/mosquitto.conf" | ||
| ) | ||
| .apply { withStartupTimeout(STARTUP_TIMEOUT).start() } | ||
| .also { broker = it } | ||
| .also { setupProperties() } | ||
| .also { | ||
| // Add shutdown hook to stop broker at JVM exit | ||
| Runtime.getRuntime().addShutdownHook(Thread { | ||
| synchronized(lock) { | ||
| broker?.stop() | ||
| } | ||
| }) | ||
| } | ||
| mosquittoConfig.deleteIfExists() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Throws(JPServiceException::class) | ||
| private fun setupProperties() { | ||
| JPService.reset() | ||
| JPService.registerProperty(JPComPort::class.java, broker!!.firstMappedPort) | ||
| JPService.registerProperty(JPComHost::class.java, broker!!.host) | ||
| JPService.setupJUnitTestMode() | ||
| } | ||
|
|
||
| class MqttBrokerContainer : GenericContainer<MqttBrokerContainer>(DockerImageName.parse("eclipse-mosquitto")) | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.