-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(deps): update dependency org.springframework.boot:spring-boot-sta…
…rter-parent to v3.4.0-rc1 (#575) * fix(deps): update dependency org.springframework.boot:spring-boot-starter-parent to v3.4.0-rc1 * fix : issues with Integration Tests * fix : rest * fix : issue with connecting to kafka * minor code refactor --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Raja Kolli <[email protected]>
- Loading branch information
1 parent
2e48886
commit b0f4cca
Showing
29 changed files
with
273 additions
and
189 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
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
...sl-integration/src/test/java/com/example/integration/kafkadsl/ContainerConfiguration.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,25 @@ | ||
package com.example.integration.kafkadsl; | ||
|
||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.test.context.DynamicPropertyRegistrar; | ||
import org.testcontainers.kafka.KafkaContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
@TestConfiguration(proxyBeanMethods = false) | ||
class ContainerConfiguration { | ||
|
||
@ServiceConnection | ||
@Bean | ||
KafkaContainer kafkaContainer() { | ||
return new KafkaContainer(DockerImageName.parse("apache/kafka-native").withTag("3.8.1")); | ||
} | ||
|
||
@Bean | ||
DynamicPropertyRegistrar kafkaProperties(KafkaContainer kafkaContainer) { | ||
return (properties) -> { | ||
properties.add("spring.kafka.bootstrapServers", kafkaContainer::getBootstrapServers); | ||
}; | ||
} | ||
} |
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
19 changes: 1 addition & 18 deletions
19
...l-integration/src/test/java/com/example/integration/kafkadsl/TestKafkaDslApplication.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,29 +1,12 @@ | ||
package com.example.integration.kafkadsl; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.testcontainers.kafka.KafkaContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
@TestConfiguration(proxyBeanMethods = false) | ||
public class TestKafkaDslApplication { | ||
|
||
@Bean | ||
@ServiceConnection | ||
KafkaContainer kafkaContainer(DynamicPropertyRegistry dynamicPropertyRegistry) { | ||
KafkaContainer kafkaContainer = | ||
new KafkaContainer(DockerImageName.parse("apache/kafka").withTag("3.8.0")); | ||
// Connect our Spring application to our Testcontainers Kafka instance | ||
dynamicPropertyRegistry.add("spring.kafka.bootstrap-servers", kafkaContainer::getBootstrapServers); | ||
return kafkaContainer; | ||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.from(KafkaDslApplication::main) | ||
.with(TestKafkaDslApplication.class) | ||
.with(ContainerConfiguration.class) | ||
.run(args); | ||
} | ||
} |
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
43 changes: 3 additions & 40 deletions
43
...src/test/java/com/example/boot/kafka/reactor/TestBootKafkaReactorConsumerApplication.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,51 +1,14 @@ | ||
package com.example.boot.kafka.reactor; | ||
|
||
import com.example.boot.kafka.reactor.entity.MessageDTO; | ||
import java.util.Map; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import com.example.boot.kafka.reactor.common.ContainerConfiguration; | ||
import com.example.boot.kafka.reactor.common.TestKafkaProducer; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.kafka.KafkaProperties; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.kafka.KafkaContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
import reactor.kafka.sender.KafkaSender; | ||
import reactor.kafka.sender.SenderOptions; | ||
|
||
@TestConfiguration(proxyBeanMethods = false) | ||
class TestBootKafkaReactorConsumerApplication { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(TestBootKafkaReactorConsumerApplication.class); | ||
|
||
@Bean | ||
@ServiceConnection | ||
PostgreSQLContainer<?> postgresContainer() { | ||
return new PostgreSQLContainer<>(DockerImageName.parse("postgres:17.0-alpine")); | ||
} | ||
|
||
@Bean | ||
@ServiceConnection | ||
KafkaContainer kafkaContainer(DynamicPropertyRegistry dynamicPropertyRegistry) { | ||
KafkaContainer kafkaContainer = | ||
new KafkaContainer(DockerImageName.parse("apache/kafka").withTag("3.8.0")); | ||
dynamicPropertyRegistry.add("spring.kafka.bootstrapServers", kafkaContainer::getBootstrapServers); | ||
return kafkaContainer; | ||
} | ||
|
||
@Bean | ||
KafkaSender<Integer, MessageDTO> reactiveKafkaSender(KafkaProperties properties) { | ||
log.info("Creating Sender"); | ||
Map<String, Object> props = properties.buildProducerProperties(null); | ||
return KafkaSender.create(SenderOptions.create(props)); | ||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.from(BootKafkaReactorConsumerApplication::main) | ||
.with(TestBootKafkaReactorConsumerApplication.class) | ||
.with(ContainerConfiguration.class, TestKafkaProducer.class) | ||
.run(args); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...-consumer/src/test/java/com/example/boot/kafka/reactor/common/ContainerConfiguration.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,32 @@ | ||
package com.example.boot.kafka.reactor.common; | ||
|
||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.test.context.DynamicPropertyRegistrar; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.kafka.KafkaContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
@TestConfiguration(proxyBeanMethods = false) | ||
public class ContainerConfiguration { | ||
|
||
@Bean | ||
@ServiceConnection | ||
PostgreSQLContainer<?> postgresContainer() { | ||
return new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("17.0-alpine")); | ||
} | ||
|
||
@ServiceConnection | ||
@Bean | ||
KafkaContainer kafkaContainer() { | ||
return new KafkaContainer(DockerImageName.parse("apache/kafka-native").withTag("3.8.1")); | ||
} | ||
|
||
@Bean | ||
DynamicPropertyRegistrar kafkaProperties(KafkaContainer kafkaContainer) { | ||
return (properties) -> { | ||
properties.add("spring.kafka.bootstrapServers", kafkaContainer::getBootstrapServers); | ||
}; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...actor-consumer/src/test/java/com/example/boot/kafka/reactor/common/TestKafkaProducer.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,41 @@ | ||
package com.example.boot.kafka.reactor.common; | ||
|
||
import com.example.boot.kafka.reactor.entity.MessageDTO; | ||
import java.util.Map; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.autoconfigure.kafka.KafkaProperties; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import reactor.kafka.sender.KafkaSender; | ||
import reactor.kafka.sender.SenderOptions; | ||
|
||
/** | ||
* Test configuration class that provides a reactive Kafka producer for integration testing. | ||
* This configuration creates a KafkaSender bean that can be used to send messages | ||
* in a reactive manner during tests. | ||
*/ | ||
@TestConfiguration(proxyBeanMethods = false) | ||
public class TestKafkaProducer { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(TestKafkaProducer.class); | ||
|
||
@Bean | ||
KafkaSender<Integer, MessageDTO> reactiveKafkaSender(KafkaProperties properties) { | ||
log.info("Creating reactive Kafka sender with properties: {}", properties.getProducer()); | ||
Map<String, Object> props = properties.buildProducerProperties(null); | ||
SenderOptions<Integer, MessageDTO> senderOptions = SenderOptions.create(props); | ||
senderOptions.maxInFlight(1024); | ||
senderOptions.stopOnError(false); | ||
|
||
KafkaSender<Integer, MessageDTO> sender = KafkaSender.create(senderOptions); | ||
|
||
// Register shutdown hook | ||
Runtime.getRuntime().addShutdownHook(new Thread(() -> { | ||
log.info("Closing Kafka sender"); | ||
sender.close(); | ||
})); | ||
|
||
return sender; | ||
} | ||
} |
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
42 changes: 2 additions & 40 deletions
42
...src/test/java/com/example/boot/kafka/reactor/TestBootKafkaReactorProducerApplication.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,51 +1,13 @@ | ||
package com.example.boot.kafka.reactor; | ||
|
||
import static com.example.boot.kafka.reactor.util.AppConstants.HELLO_TOPIC; | ||
|
||
import com.example.boot.kafka.reactor.entity.MessageDTO; | ||
import java.util.Collections; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import com.example.boot.kafka.reactor.common.ContainerConfiguration; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.kafka.KafkaProperties; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.testcontainers.kafka.KafkaContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
import reactor.kafka.receiver.KafkaReceiver; | ||
import reactor.kafka.receiver.ReceiverOptions; | ||
|
||
@TestConfiguration(proxyBeanMethods = false) | ||
class TestBootKafkaReactorProducerApplication { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(TestBootKafkaReactorProducerApplication.class); | ||
|
||
@Bean | ||
@ServiceConnection | ||
KafkaContainer kafkaContainer(DynamicPropertyRegistry dynamicPropertyRegistry) { | ||
KafkaContainer kafkaContainer = | ||
new KafkaContainer(DockerImageName.parse("apache/kafka-native").withTag("3.8.0")); | ||
dynamicPropertyRegistry.add("spring.kafka.bootstrapServers", kafkaContainer::getBootstrapServers); | ||
return kafkaContainer; | ||
} | ||
|
||
@Bean | ||
KafkaReceiver<Integer, MessageDTO> receiver(KafkaProperties properties) { | ||
LOGGER.info("Creating receiver"); | ||
ReceiverOptions<Integer, MessageDTO> receiverOptions = ReceiverOptions.<Integer, MessageDTO>create( | ||
properties.buildConsumerProperties(null)) | ||
.subscription(Collections.singleton(HELLO_TOPIC)) | ||
.addAssignListener(partitions -> LOGGER.debug("onPartitionsAssigned {}", partitions)) | ||
.addRevokeListener(partitions -> LOGGER.debug("onPartitionsRevoked {}", partitions)); | ||
|
||
return KafkaReceiver.create(receiverOptions); | ||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.from(BootKafkaReactorProducerApplication::main) | ||
.with(TestBootKafkaReactorProducerApplication.class) | ||
.with(ContainerConfiguration.class) | ||
.run(args); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...-producer/src/test/java/com/example/boot/kafka/reactor/common/ContainerConfiguration.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,25 @@ | ||
package com.example.boot.kafka.reactor.common; | ||
|
||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.test.context.DynamicPropertyRegistrar; | ||
import org.testcontainers.kafka.KafkaContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
@TestConfiguration(proxyBeanMethods = false) | ||
public class ContainerConfiguration { | ||
|
||
@ServiceConnection | ||
@Bean | ||
KafkaContainer kafkaContainer() { | ||
return new KafkaContainer(DockerImageName.parse("apache/kafka-native").withTag("3.8.1")); | ||
} | ||
|
||
@Bean | ||
DynamicPropertyRegistrar kafkaProperties(KafkaContainer kafkaContainer) { | ||
return (properties) -> { | ||
properties.add("spring.kafka.bootstrap-servers", kafkaContainer::getBootstrapServers); | ||
}; | ||
} | ||
} |
Oops, something went wrong.