-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Gate-Pool): Add Bpdm pool and gate containers to test env
- Loading branch information
1 parent
a0effc1
commit 0985f0a
Showing
6 changed files
with
264 additions
and
2 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
74 changes: 74 additions & 0 deletions
74
...ge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/util/BpdmGateContextInitializer.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,74 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
******************************************************************************/ | ||
|
||
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 org.springframework.boot.test.util.TestPropertyValues | ||
import org.springframework.context.ApplicationContextInitializer | ||
import org.springframework.context.ConfigurableApplicationContext | ||
import org.testcontainers.containers.GenericContainer | ||
import org.testcontainers.lifecycle.Startable | ||
|
||
/** | ||
* When used on a spring boot test, starts a singleton postgres db container that is shared between all integration tests. | ||
*/ | ||
|
||
|
||
class BpdmGateContextInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> { | ||
|
||
companion object { | ||
const val BPDM_PORT = 8081 | ||
|
||
private val bpdmGateContainer: GenericContainer<*> = | ||
GenericContainer("ghcr.io/catenax-ng/tx-bpdm/gate:4.0.0-alpha.4") | ||
.dependsOn(listOf<Startable>(postgreSQLContainer, openSearchContainer, bpdmPoolContainer)) | ||
.withNetwork(postgreSQLContainer.getNetwork()) | ||
.withExposedPorts(BPDM_PORT) | ||
|
||
|
||
} | ||
|
||
|
||
override fun initialize(applicationContext: ConfigurableApplicationContext) { | ||
val postgresNetworkAlias = applicationContext.environment.getProperty("bpdm.datasource.alias") | ||
val bpdmPoolAlias = applicationContext.environment.getProperty("bpdm.pool.alias") | ||
val dataBase = postgreSQLContainer.getDatabaseName() | ||
bpdmGateContainer.withEnv( | ||
"spring.datasource.url", "jdbc:postgresql://${postgresNetworkAlias}:5432/${dataBase}?loggerLevel=OFF" | ||
) | ||
.withEnv("bpdm.pool.base-url", "http://$bpdmPoolAlias:8080/api/catena") | ||
|
||
.withEnv( | ||
"spring.datasource.username", postgreSQLContainer.username | ||
) | ||
.withEnv( | ||
"spring.datasource.password", postgreSQLContainer.password | ||
).start() | ||
|
||
|
||
TestPropertyValues.of( | ||
"bpdm.gate.base-url=http://localhost:${bpdmGateContainer.getMappedPort(BPDM_PORT)}", | ||
).applyTo(applicationContext.environment) | ||
|
||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...ge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/util/BpdmPoolContextInitializer.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,79 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
******************************************************************************/ | ||
|
||
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 org.springframework.boot.test.util.TestPropertyValues | ||
import org.springframework.context.ApplicationContextInitializer | ||
import org.springframework.context.ConfigurableApplicationContext | ||
import org.testcontainers.containers.GenericContainer | ||
import org.testcontainers.lifecycle.Startable | ||
|
||
/** | ||
* When used on a spring boot test, starts a singleton postgres db container that is shared between all integration tests. | ||
*/ | ||
|
||
|
||
class BpdmPoolContextInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> { | ||
|
||
companion object { | ||
const val BPDM_PORT = 8080 | ||
|
||
val bpdmPoolContainer: GenericContainer<*> = | ||
GenericContainer("ghcr.io/catenax-ng/tx-bpdm/pool:4.0.0-alpha.4") | ||
.dependsOn(listOf<Startable>(postgreSQLContainer, openSearchContainer)) | ||
.withNetwork(postgreSQLContainer.getNetwork()) | ||
.withExposedPorts(BPDM_PORT) | ||
|
||
|
||
} | ||
|
||
|
||
override fun initialize(applicationContext: ConfigurableApplicationContext) { | ||
val postgresNetworkAlias = applicationContext.environment.getProperty("bpdm.datasource.alias") | ||
val openSearchNetworkAlias = applicationContext.environment.getProperty("bpdm.opensearch.alias") | ||
val dataBase = postgreSQLContainer.getDatabaseName() | ||
val bpdmAlias = applicationContext.environment.getProperty("bpdm.pool.alias") | ||
bpdmPoolContainer.withNetworkAliases(bpdmAlias) | ||
|
||
bpdmPoolContainer.withEnv( | ||
"spring.datasource.url", "jdbc:postgresql://${postgresNetworkAlias}:5432/${dataBase}?loggerLevel=OFF" | ||
) | ||
.withEnv("bpdm.opensearch.host", openSearchNetworkAlias) | ||
.withEnv( | ||
"pdm.opensearch.port", | ||
OpenSearchContextInitializer.OPENSEARCH_PORT.toString() | ||
) | ||
.withEnv("bpdm.opensearch.scheme", "http") | ||
.withEnv( | ||
"spring.datasource.username", postgreSQLContainer.username | ||
) | ||
.withEnv( | ||
"spring.datasource.password", postgreSQLContainer.password | ||
).start() | ||
|
||
TestPropertyValues.of( | ||
"bpdm.pool.base-url=http://localhost:${bpdmPoolContainer.getMappedPort(8080)}", | ||
).applyTo(applicationContext.environment) | ||
|
||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/util/OpenSearchContextInitializer.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,71 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
******************************************************************************/ | ||
|
||
package com.catenax.bpdm.bridge.dummy.util | ||
|
||
|
||
import com.catenax.bpdm.bridge.dummy.util.PostgreSQLContextInitializer.Companion.postgreSQLContainer | ||
import com.github.dockerjava.api.model.Ulimit | ||
import org.springframework.boot.test.util.TestPropertyValues | ||
import org.springframework.context.ApplicationContextInitializer | ||
import org.springframework.context.ConfigurableApplicationContext | ||
import org.testcontainers.containers.GenericContainer | ||
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy | ||
import org.testcontainers.lifecycle.Startable | ||
|
||
/** | ||
* When used on a spring boot test, starts a singleton opensearch container that is shared between all integration tests. | ||
*/ | ||
|
||
class OpenSearchContextInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> { | ||
companion object { | ||
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 } | ||
) | ||
// based on sample docker-compose for development from https://opensearch.org/docs/latest/opensearch/install/docker | ||
.withEnv("cluster.name", "cdqbridge") | ||
.withEnv("node.name", "bpdm-opensearch") | ||
.withEnv("bootstrap.memory_lock", "true") | ||
.withEnv("OPENSEARCH_JAVA_OPTS", "-Xms512m -Xmx512m") | ||
.withEnv("DISABLE_INSTALL_DEMO_CONFIG", "true") | ||
.withEnv("DISABLE_SECURITY_PLUGIN", "true") | ||
.withEnv("discovery.type", "single-node") | ||
.withCreateContainerCmdModifier { cmd -> | ||
cmd.hostConfig!!.withUlimits(arrayOf(Ulimit("nofile", 65536L, 65536L), Ulimit("memlock", -1L, -1L))) | ||
} | ||
.withNetwork(postgreSQLContainer.getNetwork()) | ||
.dependsOn(listOf<Startable>(postgreSQLContainer)) | ||
} | ||
|
||
override fun initialize(applicationContext: ConfigurableApplicationContext) { | ||
val openSearchAlias = applicationContext.environment.getProperty("bpdm.opensearch.alias") | ||
openSearchContainer.withNetworkAliases(openSearchAlias) | ||
openSearchContainer.start() | ||
TestPropertyValues.of( | ||
"bpdm.opensearch.host=${openSearchContainer.host}", | ||
"bpdm.opensearch.port=${openSearchContainer.getMappedPort(OPENSEARCH_PORT)}", | ||
"bpdm.opensearch.scheme=http", | ||
"bpdm.opensearch.enabled=true", | ||
).applyTo(applicationContext.environment) | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
bpdm-bridge-dummy/src/test/resources/application-test.properties
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,25 @@ | ||
################################################################################ | ||
# Copyright (c) 2021,2023 Contributors to the Eclipse Foundation | ||
# | ||
# See the NOTICE file(s) distributed with this work for additional | ||
# information regarding copyright ownership. | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Apache License, Version 2.0 which is available at | ||
# https://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
################################################################################ | ||
bpdm.opensearch.enabled=false | ||
bpdm.opensearch.refresh-on-write=true | ||
bpdm.opensearch.alias=bpdm-opensearch | ||
bpdm.datasource.alias=bpdm-postgres | ||
bpdm.pool.alias=bpdm-pool | ||
logging.level.root=INFO | ||
spring.datasource.hikari.maximum-pool-size=2 |