Skip to content

Commit

Permalink
Merge pull request eclipse-tractusx#411 from catenax-ng/feat/debuggin…
Browse files Browse the repository at this point in the history
…g_testcontainers

feat(tests): Remote-debugging the Testcontainers
  • Loading branch information
nicoprow authored Sep 7, 2023
2 parents bfc4b65 + 6057657 commit f1be278
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package com.catenax.bpdm.bridge.dummy.util
import com.catenax.bpdm.bridge.dummy.util.BpdmPoolContextInitializer.Companion.bpdmPoolContainer
import com.catenax.bpdm.bridge.dummy.util.OpenSearchContextInitializer.Companion.openSearchContainer
import com.catenax.bpdm.bridge.dummy.util.PostgreSQLContextInitializer.Companion.postgreSQLContainer
import mu.KotlinLogging
import org.springframework.boot.test.util.TestPropertyValues
import org.springframework.context.ApplicationContextInitializer
import org.springframework.context.ConfigurableApplicationContext
Expand All @@ -38,18 +39,23 @@ import java.time.Duration

class BpdmGateContextInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> {

private val logger = KotlinLogging.logger { }

companion object {
const val GATE_CONTAINER_STARTUP_TIMEOUT_SEC = 180L
const val GATE_CONTAINER_STARTUP_TIMEOUT_SEC = 300L
const val BPDM_PORT = 8081
const val DEBUG_PORT = 8051
const val IMAGE = "maven-gate"

private val bpdmGateContainer: GenericContainer<*> =
GenericContainer(IMAGE)
.dependsOn(listOf<Startable>(postgreSQLContainer, openSearchContainer, bpdmPoolContainer))
.withNetwork(postgreSQLContainer.getNetwork())
.withExposedPorts(BPDM_PORT)


.withExposedPorts(BPDM_PORT, DEBUG_PORT)
.withEnv(
"JAVA_OPTIONS",
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:$DEBUG_PORT"
)
}


Expand All @@ -73,12 +79,14 @@ class BpdmGateContextInitializer : ApplicationContextInitializer<ConfigurableApp
)
.withEnv(
"spring.datasource.password", postgreSQLContainer.password
).start()
)
.start()


TestPropertyValues.of(
"bpdm.gate.base-url=http://localhost:${bpdmGateContainer.getMappedPort(BPDM_PORT)}",
).applyTo(applicationContext.environment)

logger.info { "[!!!] Gate can be remote-debugged on port ${bpdmGateContainer.getMappedPort(DEBUG_PORT)} " }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package com.catenax.bpdm.bridge.dummy.util

import com.catenax.bpdm.bridge.dummy.util.OpenSearchContextInitializer.Companion.openSearchContainer
import com.catenax.bpdm.bridge.dummy.util.PostgreSQLContextInitializer.Companion.postgreSQLContainer
import mu.KotlinLogging
import org.springframework.boot.test.util.TestPropertyValues
import org.springframework.context.ApplicationContextInitializer
import org.springframework.context.ConfigurableApplicationContext
Expand All @@ -37,18 +38,23 @@ import java.time.Duration

class BpdmPoolContextInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> {

private val logger = KotlinLogging.logger { }

companion object {
const val POOL_CONTAINER_STARTUP_TIMEOUT_SEC = 180L
const val POOL_CONTAINER_STARTUP_TIMEOUT_SEC = 300L
const val BPDM_PORT = 8080
const val DEBUG_PORT = 8050
const val IMAGE = "maven-pool"

val bpdmPoolContainer: GenericContainer<*> =
GenericContainer(IMAGE)
.dependsOn(listOf<Startable>(postgreSQLContainer, openSearchContainer))
.withNetwork(postgreSQLContainer.getNetwork())
.withExposedPorts(BPDM_PORT)
.withStartupTimeout(Duration.ofSeconds(210))

.withExposedPorts(BPDM_PORT, DEBUG_PORT)
.withEnv(
"JAVA_OPTIONS",
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:$DEBUG_PORT"
)
}


Expand Down Expand Up @@ -79,11 +85,13 @@ class BpdmPoolContextInitializer : ApplicationContextInitializer<ConfigurableApp
)
.withEnv(
"spring.datasource.password", postgreSQLContainer.password
).start()
)
.start()

TestPropertyValues.of(
"bpdm.pool.base-url=http://localhost:${bpdmPoolContainer.getMappedPort(8080)}",
"bpdm.pool.base-url=http://localhost:${bpdmPoolContainer.getMappedPort(BPDM_PORT)}",
).applyTo(applicationContext.environment)

logger.info { "[!!!] Pool can be remote-debugged on port ${bpdmPoolContainer.getMappedPort(DEBUG_PORT)} " }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ import java.time.Duration

class OpenSearchContextInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> {
companion object {
const val OPENSEARCH_CONTAINER_STARTUP_TIMEOUT_SEC = 270L
const val OPENSEARCH_PORT = 9200

val openSearchContainer: GenericContainer<*> = GenericContainer("opensearchproject/opensearch:2.1.0")
.withExposedPorts(OPENSEARCH_PORT)
.waitingFor(HttpWaitStrategy()
.forPort(OPENSEARCH_PORT)
.forStatusCodeMatching { response -> response == 200 || response == 401 }
.withStartupTimeout(Duration.ofSeconds(180))
.withStartupTimeout(Duration.ofSeconds(OPENSEARCH_CONTAINER_STARTUP_TIMEOUT_SEC))
)
// based on sample docker-compose for development from https://opensearch.org/docs/latest/opensearch/install/docker
.withEnv("cluster.name", "cdqbridge")
Expand Down
2 changes: 1 addition & 1 deletion bpdm-gate/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ RUN adduser -u $USERID -S $USERNAME $USERNAME
USER $USERNAME
WORKDIR /usr/local/lib/bpdm
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]
ENTRYPOINT java $JAVA_OPTIONS -jar app.jar
2 changes: 1 addition & 1 deletion bpdm-pool/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ RUN adduser -u $USERID -S $USERNAME $USERNAME
USER $USERNAME
WORKDIR /usr/local/lib/bpdm
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]
ENTRYPOINT java $JAVA_OPTIONS -jar app.jar

0 comments on commit f1be278

Please sign in to comment.