-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added support and tests for defining static ports * Changed GitHub Actions configuration to run the checks sequentially, because parallel runs are no longer possible due to usage of static port values in tests
- Loading branch information
1 parent
ea7ce72
commit b49d21a
Showing
29 changed files
with
553 additions
and
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ jobs: | |
build: | ||
|
||
runs-on: ubuntu-latest | ||
concurrency: sequential | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
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,3 +1,7 @@ | ||
### 3.3.0 | ||
General: | ||
* Added support for starting containers on a predefined port | ||
|
||
### 3.2.0 | ||
|
||
#### ClickHouse: | ||
|
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
43 changes: 43 additions & 0 deletions
43
...ip/testcontainers/spring/clickhouse/ClickhouseContainerInitializerWithStaticPortTest.java
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,43 @@ | ||
package com.infobip.testcontainers.spring.clickhouse; | ||
|
||
import static com.infobip.testcontainers.spring.clickhouse.DataSourceConfig.CLICKHOUSE_URL_PROPERTY_NAME; | ||
import static org.assertj.core.api.BDDAssertions.then; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.TestConstructor; | ||
|
||
@AllArgsConstructor | ||
@ActiveProfiles("static-port") | ||
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) | ||
@SpringBootTest(classes = Main.class) | ||
class ClickhouseContainerInitializerWithStaticPortTest { | ||
|
||
Environment environment; | ||
DataSource dataSource; | ||
|
||
@Test | ||
void shouldCreateContainerWithStaticPort() { | ||
//given | ||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); | ||
|
||
//when | ||
String result = jdbcTemplate.queryForObject("SELECT 1", String.class); | ||
|
||
//then | ||
then(result).isEqualTo("1"); | ||
} | ||
|
||
@Test | ||
void shouldResolveHostInUrl() { | ||
// then | ||
then(environment.getProperty(CLICKHOUSE_URL_PROPERTY_NAME)).isEqualTo("jdbc:clickhouse://localhost:5001"); | ||
} | ||
|
||
} |
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
8 changes: 8 additions & 0 deletions
8
...khouse-testcontainers-spring-boot-starter/src/test/resources/application-static-port.yaml
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,8 @@ | ||
spring: | ||
datasource: | ||
clickhouse: | ||
jdbc-url: jdbc:clickhouse://<host>:5001 | ||
|
||
testcontainers: | ||
clickhouse: | ||
custom-path: "spring.datasource.clickhouse" |
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
36 changes: 14 additions & 22 deletions
36
.../src/test/java/com/infobip/testcontainers/spring/kafka/KafkaContainerInitializerTest.java
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,53 +1,45 @@ | ||
package com.infobip.testcontainers.spring.kafka; | ||
|
||
import static com.infobip.testcontainers.spring.kafka.Listener.TOPIC; | ||
import static org.assertj.core.api.BDDAssertions.then; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.awaitility.Awaitility; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.kafka.core.KafkaTemplate; | ||
import org.springframework.kafka.support.SendResult; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.TestConstructor; | ||
|
||
import java.time.Duration; | ||
import java.util.Objects; | ||
import java.util.concurrent.*; | ||
|
||
import static org.assertj.core.api.BDDAssertions.then; | ||
|
||
@AllArgsConstructor | ||
@ActiveProfiles("test") | ||
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) | ||
@SpringBootTest(classes = Main.class) | ||
class KafkaContainerInitializerTest { | ||
|
||
final static String TOPIC_NAME = "test-topic"; | ||
|
||
private final KafkaTemplate<String, String> kafkaTemplate; | ||
private final Listener listener; | ||
|
||
@Test | ||
void shouldCreateContainer() throws InterruptedException, ExecutionException, TimeoutException { | ||
|
||
// given | ||
String givenData = "givenData"; | ||
String givenValue = this.getClass().getName(); | ||
|
||
// when | ||
SendResult<?, ?> actual = kafkaTemplate.send(TOPIC_NAME, "key", givenData) | ||
SendResult<?, ?> actual = kafkaTemplate.send(TOPIC, "key", givenValue) | ||
.completable() | ||
.get(10, TimeUnit.SECONDS); | ||
|
||
// then | ||
then(actual).isNotNull(); | ||
Awaitility.await().atMost(Duration.ofSeconds(10)).until(() -> { | ||
String value = listener.getValue(); | ||
|
||
if(Objects.isNull(value)) { | ||
return false; | ||
} | ||
|
||
then(value).isEqualTo(givenData); | ||
return true; | ||
}); | ||
await().atMost(Duration.ofSeconds(10)) | ||
.untilAsserted(() -> then(listener.getValue()).isEqualTo(givenValue)); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
.../com/infobip/testcontainers/spring/kafka/KafkaContainerInitializerWithStaticPortTest.java
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,53 @@ | ||
package com.infobip.testcontainers.spring.kafka; | ||
|
||
import static com.infobip.testcontainers.spring.kafka.Listener.TOPIC; | ||
import static org.assertj.core.api.BDDAssertions.then; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.autoconfigure.kafka.KafkaProperties; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.kafka.core.KafkaTemplate; | ||
import org.springframework.kafka.support.SendResult; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.TestConstructor; | ||
|
||
@AllArgsConstructor | ||
@ActiveProfiles("static-port") | ||
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) | ||
@SpringBootTest(classes = Main.class) | ||
class KafkaContainerInitializerWithStaticPortTest { | ||
|
||
private final KafkaTemplate<String, String> kafkaTemplate; | ||
private final Listener listener; | ||
private final KafkaProperties kafkaProperties; | ||
|
||
@Test | ||
void shouldCreateContainer() throws InterruptedException, ExecutionException, TimeoutException { | ||
// given | ||
String givenValue = this.getClass().getName(); | ||
|
||
// when | ||
SendResult<?, ?> actual = kafkaTemplate.send(TOPIC, "key", givenValue) | ||
.completable() | ||
.get(10, TimeUnit.SECONDS); | ||
|
||
// then | ||
then(actual).isNotNull(); | ||
await().atMost(Duration.ofSeconds(10)) | ||
.untilAsserted(() -> then(listener.getValue()).isEqualTo(givenValue)); | ||
} | ||
|
||
@Test | ||
void shouldResolveHostInUrl() { | ||
// then | ||
then(kafkaProperties.getBootstrapServers()).containsExactly("localhost:5002"); | ||
} | ||
|
||
} |
11 changes: 6 additions & 5 deletions
11
...s-spring-boot-starter/src/test/java/com/infobip/testcontainers/spring/kafka/Listener.java
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,26 +1,27 @@ | ||
package com.infobip.testcontainers.spring.kafka; | ||
|
||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.springframework.kafka.annotation.KafkaListener; | ||
import org.springframework.messaging.handler.annotation.Payload; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.concurrent.ArrayBlockingQueue; | ||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
@AllArgsConstructor | ||
@Component | ||
class Listener { | ||
|
||
public static final String TOPIC = "test-topic"; | ||
|
||
private final AtomicReference<String> value = new AtomicReference<>(); | ||
|
||
@KafkaListener(topics = KafkaContainerInitializerTest.TOPIC_NAME) | ||
@KafkaListener(topics = TOPIC) | ||
public void handle(@Payload String value) { | ||
this.value.set(value); | ||
} | ||
|
||
String getValue() { | ||
return value.get(); | ||
} | ||
|
||
} |
Oops, something went wrong.