mirror of https://github.com/dapr/java-sdk.git
Adding @ServiceConnection spring boot support with Testcontainers (#1118)
* adding service connection plumbing Signed-off-by: salaboy <Salaboy@gmail.com> * fixing style Signed-off-by: salaboy <Salaboy@gmail.com> * updating sdk-tests Signed-off-by: salaboy <Salaboy@gmail.com> * Update dapr-spring/dapr-spring-boot-autoconfigure/src/main/java/io/dapr/spring/boot/autoconfigure/client/DaprClientAutoConfiguration.java Co-authored-by: Eddú Meléndez Gonzales <eddu.melendez@gmail.com> Signed-off-by: salaboy <Salaboy@gmail.com> * Update dapr-spring/dapr-spring-boot-autoconfigure/src/main/java/io/dapr/spring/boot/autoconfigure/client/PropertiesDaprConnectionDetails.java Co-authored-by: Eddú Meléndez Gonzales <eddu.melendez@gmail.com> Signed-off-by: salaboy <Salaboy@gmail.com> * fixing details Signed-off-by: salaboy <Salaboy@gmail.com> * adding @ServiceConnection to Dapr Signed-off-by: salaboy <Salaboy@gmail.com> * fixing tests and style Signed-off-by: salaboy <Salaboy@gmail.com> * removing test that is not needed anymore Signed-off-by: salaboy <Salaboy@gmail.com> * updating starter dependencies Signed-off-by: salaboy <Salaboy@gmail.com> * adding juniper testcontainers support Signed-off-by: salaboy <Salaboy@gmail.com> * adding new testing module Signed-off-by: salaboy <Salaboy@gmail.com> * cleaning sdk-tests deps Signed-off-by: salaboy <Salaboy@gmail.com> * removing dead code Signed-off-by: salaboy <Salaboy@gmail.com> * removing core that is not needed Signed-off-by: salaboy <Salaboy@gmail.com> * adding setters Signed-off-by: salaboy <Salaboy@gmail.com> * default constructor Signed-off-by: salaboy <Salaboy@gmail.com> --------- Signed-off-by: salaboy <Salaboy@gmail.com> Co-authored-by: Eddú Meléndez Gonzales <eddu.melendez@gmail.com>
This commit is contained in:
parent
9b927c84c2
commit
4b83da6327
|
|
@ -15,12 +15,6 @@
|
|||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-core</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-data</artifactId>
|
||||
|
|
|
|||
|
|
@ -15,34 +15,33 @@ package io.dapr.spring.boot.autoconfigure.client;
|
|||
|
||||
import io.dapr.client.DaprClient;
|
||||
import io.dapr.client.DaprClientBuilder;
|
||||
import io.dapr.spring.core.client.DaprClientCustomizer;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import io.dapr.config.Properties;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AutoConfiguration
|
||||
@ConditionalOnClass(DaprClient.class)
|
||||
@EnableConfigurationProperties(DaprClientProperties.class)
|
||||
public class DaprClientAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
DaprClientBuilderConfigurer daprClientBuilderConfigurer(ObjectProvider<DaprClientCustomizer> customizerProvider) {
|
||||
DaprClientBuilderConfigurer configurer = new DaprClientBuilderConfigurer();
|
||||
configurer.setDaprClientCustomizer(customizerProvider.orderedStream().collect(Collectors.toList()));
|
||||
|
||||
return configurer;
|
||||
@ConditionalOnMissingBean(DaprConnectionDetails.class)
|
||||
DaprConnectionDetails daprConnectionDetails(DaprClientProperties properties) {
|
||||
return new PropertiesDaprConnectionDetails(properties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
DaprClientBuilder daprClientBuilder(DaprClientBuilderConfigurer daprClientBuilderConfigurer) {
|
||||
DaprClientBuilder daprClientBuilder(DaprConnectionDetails daprConnectionDetails) {
|
||||
DaprClientBuilder builder = new DaprClientBuilder();
|
||||
|
||||
return daprClientBuilderConfigurer.configure(builder);
|
||||
builder.withPropertyOverride(Properties.HTTP_ENDPOINT, daprConnectionDetails.httpEndpoint());
|
||||
builder.withPropertyOverride(Properties.GRPC_ENDPOINT, daprConnectionDetails.grpcEndpoint());
|
||||
builder.withPropertyOverride(Properties.HTTP_PORT, String.valueOf(daprConnectionDetails.httpPort()));
|
||||
builder.withPropertyOverride(Properties.GRPC_PORT, String.valueOf(daprConnectionDetails.grpcPort()));
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Copyright 2024 The Dapr Authors
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package io.dapr.spring.boot.autoconfigure.client;
|
||||
|
||||
import io.dapr.client.DaprClientBuilder;
|
||||
import io.dapr.spring.core.client.DaprClientCustomizer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Builder for configuring a {@link DaprClientBuilder}.
|
||||
*/
|
||||
public class DaprClientBuilderConfigurer {
|
||||
|
||||
private List<DaprClientCustomizer> customizers;
|
||||
|
||||
void setDaprClientCustomizer(List<DaprClientCustomizer> customizers) {
|
||||
this.customizers = List.copyOf(customizers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the specified {@link DaprClientBuilder}. The builder can be further
|
||||
* tuned and default settings can be overridden.
|
||||
*
|
||||
* @param builder the {@link DaprClientBuilder} instance to configure
|
||||
* @return the configured builder
|
||||
*/
|
||||
public DaprClientBuilder configure(DaprClientBuilder builder) {
|
||||
applyCustomizers(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
private void applyCustomizers(DaprClientBuilder builder) {
|
||||
if (this.customizers != null) {
|
||||
for (DaprClientCustomizer customizer : this.customizers) {
|
||||
customizer.customize(builder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright 2024 The Dapr Authors
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package io.dapr.spring.boot.autoconfigure.client;
|
||||
|
||||
import io.dapr.spring.data.DaprKeyValueAdapterResolver;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "dapr.client")
|
||||
public class DaprClientProperties {
|
||||
private String httpEndpoint;
|
||||
private String grpcEndpoint;
|
||||
private Integer httpPort;
|
||||
private Integer grpcPort;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a {@link DaprClientProperties}.
|
||||
*/
|
||||
public DaprClientProperties() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@link DaprClientProperties}.
|
||||
* @param httpEndpoint http endpoint to interact with the Dapr Sidecar
|
||||
* @param grpcEndpoint grpc endpoint to interact with the Dapr Sidecar
|
||||
* @param httpPort http port to interact with the Dapr Sidecar
|
||||
* @param grpcPort grpc port to interact with the Dapr Sidecar
|
||||
*/
|
||||
public DaprClientProperties(String httpEndpoint, String grpcEndpoint, Integer httpPort, Integer grpcPort) {
|
||||
this.httpEndpoint = httpEndpoint;
|
||||
this.grpcEndpoint = grpcEndpoint;
|
||||
this.httpPort = httpPort;
|
||||
this.grpcPort = grpcPort;
|
||||
}
|
||||
|
||||
public String getHttpEndpoint() {
|
||||
return httpEndpoint;
|
||||
}
|
||||
|
||||
public String getGrpcEndpoint() {
|
||||
return grpcEndpoint;
|
||||
}
|
||||
|
||||
public Integer getHttpPort() {
|
||||
return httpPort;
|
||||
}
|
||||
|
||||
public Integer getGrpcPort() {
|
||||
return grpcPort;
|
||||
}
|
||||
|
||||
public void setHttpEndpoint(String httpEndpoint) {
|
||||
this.httpEndpoint = httpEndpoint;
|
||||
}
|
||||
|
||||
public void setGrpcEndpoint(String grpcEndpoint) {
|
||||
this.grpcEndpoint = grpcEndpoint;
|
||||
}
|
||||
|
||||
public void setHttpPort(Integer httpPort) {
|
||||
this.httpPort = httpPort;
|
||||
}
|
||||
|
||||
public void setGrpcPort(Integer grpcPort) {
|
||||
this.grpcPort = grpcPort;
|
||||
}
|
||||
}
|
||||
|
|
@ -11,21 +11,16 @@
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package io.dapr.spring.core.client;
|
||||
package io.dapr.spring.boot.autoconfigure.client;
|
||||
|
||||
import io.dapr.client.DaprClientBuilder;
|
||||
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
|
||||
|
||||
/**
|
||||
* Callback interface that can be used to customize a {@link DaprClientBuilder}.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface DaprClientCustomizer {
|
||||
public interface DaprConnectionDetails extends ConnectionDetails {
|
||||
String httpEndpoint();
|
||||
|
||||
/**
|
||||
* Callback to customize a {@link DaprClientBuilder} instance.
|
||||
*
|
||||
* @param daprClientBuilder the client builder to customize
|
||||
*/
|
||||
void customize(DaprClientBuilder daprClientBuilder);
|
||||
String grpcEndpoint();
|
||||
|
||||
Integer httpPort();
|
||||
|
||||
Integer grpcPort();
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright 2024 The Dapr Authors
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package io.dapr.spring.boot.autoconfigure.client;
|
||||
|
||||
class PropertiesDaprConnectionDetails implements DaprConnectionDetails {
|
||||
|
||||
private final DaprClientProperties daprClientProperties;
|
||||
|
||||
public PropertiesDaprConnectionDetails(DaprClientProperties daprClientProperties) {
|
||||
this.daprClientProperties = daprClientProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String httpEndpoint() {
|
||||
return this.daprClientProperties.getHttpEndpoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String grpcEndpoint() {
|
||||
return this.daprClientProperties.getGrpcEndpoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer httpPort() {
|
||||
return this.daprClientProperties.getHttpPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer grpcPort() {
|
||||
return this.daprClientProperties.getGrpcPort();
|
||||
}
|
||||
}
|
||||
|
|
@ -29,11 +29,6 @@ class DaprClientAutoConfigurationTests {
|
|||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(DaprClientAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
void daprClientBuilderConfigurer() {
|
||||
contextRunner.run(context -> assertThat(context).hasSingleBean(DaprClientBuilderConfigurer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void daprClientBuilder() {
|
||||
contextRunner.run(context -> assertThat(context).hasSingleBean(DaprClientBuilder.class));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-parent</artifactId>
|
||||
<version>0.13.0-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>dapr-spring-boot-starter-test</artifactId>
|
||||
<name>dapr-spring-boot-starter-test</name>
|
||||
<description>Dapr Spring Boot Starter Tests (with Testcontainers Support)</description>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-boot-tests</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr</groupId>
|
||||
<artifactId>testcontainers-dapr</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-testcontainers</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
<artifactId>dapr-spring-boot-starter</artifactId>
|
||||
<name>dapr-spring-boot-starter</name>
|
||||
<description>Dapr Client Spring Boot Starter</description>
|
||||
<description>Dapr Spring Boot Starter</description>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
|
@ -21,15 +21,25 @@
|
|||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-core</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<groupId>io.dapr</groupId>
|
||||
<artifactId>dapr-sdk-springboot</artifactId>
|
||||
<version>${dapr.sdk.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-boot-autoconfigure</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-data</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-messaging</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-parent</artifactId>
|
||||
<version>0.13.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dapr-spring-boot-tests</artifactId>
|
||||
<name>dapr-spring-boot-tests</name>
|
||||
<description>Dapr Spring Boot Tests</description>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-testcontainers</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-boot-autoconfigure</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.vaadin.external.google</groupId>
|
||||
<artifactId>android-json</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr</groupId>
|
||||
<artifactId>testcontainers-dapr</artifactId>
|
||||
<version>${dapr.sdk.alpha.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package io.dapr.spring.boot.testcontainers.service.connection;
|
||||
|
||||
import io.dapr.spring.boot.autoconfigure.client.DaprConnectionDetails;
|
||||
import io.dapr.testcontainers.DaprContainer;
|
||||
import org.springframework.boot.testcontainers.service.connection.ContainerConnectionDetailsFactory;
|
||||
import org.springframework.boot.testcontainers.service.connection.ContainerConnectionSource;
|
||||
|
||||
public class DaprContainerConnectionDetailsFactory
|
||||
extends ContainerConnectionDetailsFactory<DaprContainer, DaprConnectionDetails> {
|
||||
|
||||
DaprContainerConnectionDetailsFactory() {
|
||||
}
|
||||
|
||||
protected DaprConnectionDetails getContainerConnectionDetails(ContainerConnectionSource<DaprContainer> source) {
|
||||
return new DaprContainerConnectionDetails(source);
|
||||
}
|
||||
|
||||
private static final class DaprContainerConnectionDetails
|
||||
extends ContainerConnectionDetailsFactory.ContainerConnectionDetails<DaprContainer>
|
||||
implements DaprConnectionDetails {
|
||||
private DaprContainerConnectionDetails(ContainerConnectionSource<DaprContainer> source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String httpEndpoint() {
|
||||
return getContainer().getHttpEndpoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String grpcEndpoint() {
|
||||
return getContainer().getGrpcEndpoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer httpPort() {
|
||||
return getContainer().getHttpPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer grpcPort() {
|
||||
return getContainer().getGrpcPort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
org.springframework.boot.autoconfigure.service.connection.ConnectionDetailsFactory=\
|
||||
io.dapr.spring.boot.testcontainers.service.connection.DaprContainerConnectionDetailsFactory
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-parent</artifactId>
|
||||
<version>0.13.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dapr-spring-core</artifactId>
|
||||
<name>dapr-spring-core</name>
|
||||
<description>Dapr Spring Core</description>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
</project>
|
||||
|
|
@ -18,11 +18,12 @@
|
|||
<description>SDK extension for Spring and Spring Boot</description>
|
||||
|
||||
<modules>
|
||||
<module>dapr-spring-core</module>
|
||||
<module>dapr-spring-data</module>
|
||||
<module>dapr-spring-messaging</module>
|
||||
<module>dapr-spring-boot-autoconfigure</module>
|
||||
<module>dapr-spring-boot-tests</module>
|
||||
<module>dapr-spring-boot-starters/dapr-spring-boot-starter</module>
|
||||
<module>dapr-spring-boot-starters/dapr-spring-boot-starter-test</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
|
|
|||
|
|
@ -147,34 +147,19 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr</groupId>
|
||||
<artifactId>dapr-sdk-springboot</artifactId>
|
||||
<version>${dapr.sdk.version}</version>
|
||||
<scope>test</scope>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-boot-starter</artifactId>
|
||||
<version>${dapr.sdk.alpha.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-core</artifactId>
|
||||
<artifactId>dapr-spring-boot-starter-test</artifactId>
|
||||
<version>${dapr.sdk.alpha.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-data</artifactId>
|
||||
<version>${dapr.sdk.alpha.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-messaging</artifactId>
|
||||
<version>${dapr.sdk.alpha.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-boot-autoconfigure</artifactId>
|
||||
<version>${dapr.sdk.alpha.version}</version>
|
||||
<scope>test</scope>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
|
|
@ -185,11 +170,6 @@
|
|||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-testcontainers</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wiremock</groupId>
|
||||
<artifactId>wiremock-standalone</artifactId>
|
||||
|
|
@ -219,17 +199,6 @@
|
|||
<version>3.9</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr</groupId>
|
||||
<artifactId>testcontainers-dapr</artifactId>
|
||||
<version>${dapr.sdk.alpha.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${testcontainers-test.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
|
|
|
|||
|
|
@ -21,9 +21,8 @@ import org.junit.jupiter.api.Tag;
|
|||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||
import org.springframework.test.context.DynamicPropertySource;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.containers.PostgreSQLContainer;
|
||||
|
|
@ -65,6 +64,7 @@ public class DaprKeyValueRepositoryIT {
|
|||
.withNetwork(DAPR_NETWORK);
|
||||
|
||||
@Container
|
||||
@ServiceConnection
|
||||
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.13.2")
|
||||
.withAppName("postgresql-repository-dapr-app")
|
||||
.withNetwork(DAPR_NETWORK)
|
||||
|
|
@ -74,12 +74,6 @@ public class DaprKeyValueRepositoryIT {
|
|||
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
|
||||
.dependsOn(POSTGRE_SQL_CONTAINER);
|
||||
|
||||
@DynamicPropertySource
|
||||
static void daprProperties(DynamicPropertyRegistry registry) {
|
||||
registry.add("dapr.http.endpoint", DAPR_CONTAINER::getHttpEndpoint);
|
||||
registry.add("dapr.grpc.endpoint", DAPR_CONTAINER::getGrpcEndpoint);
|
||||
}
|
||||
|
||||
private static Map<String, String> createStateStoreProperties() {
|
||||
Map<String, String> result = new HashMap<>();
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.junit.jupiter.api.Tag;
|
|||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||
|
|
@ -80,6 +81,7 @@ public class MySQLDaprKeyValueTemplateIT {
|
|||
.waitingFor(MYSQL_WAIT_STRATEGY);
|
||||
|
||||
@Container
|
||||
@ServiceConnection
|
||||
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.13.2")
|
||||
.withAppName("mysql-dapr-app")
|
||||
.withNetwork(DAPR_NETWORK)
|
||||
|
|
@ -88,12 +90,7 @@ public class MySQLDaprKeyValueTemplateIT {
|
|||
.withDaprLogLevel(DaprLogLevel.DEBUG)
|
||||
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
|
||||
.dependsOn(MY_SQL_CONTAINER);
|
||||
|
||||
@DynamicPropertySource
|
||||
static void daprProperties(DynamicPropertyRegistry registry) {
|
||||
registry.add("dapr.http.endpoint", DAPR_CONTAINER::getHttpEndpoint);
|
||||
registry.add("dapr.grpc.endpoint", DAPR_CONTAINER::getGrpcEndpoint);
|
||||
}
|
||||
|
||||
|
||||
private static Map<String, String> createStateStoreProperties() {
|
||||
Map<String, String> result = new HashMap<>();
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.junit.jupiter.api.Tag;
|
|||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||
|
|
@ -66,6 +67,7 @@ public class PostgreSQLDaprKeyValueTemplateIT {
|
|||
.withNetwork(DAPR_NETWORK);
|
||||
|
||||
@Container
|
||||
@ServiceConnection
|
||||
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.13.2")
|
||||
.withAppName("postgresql-dapr-app")
|
||||
.withNetwork(DAPR_NETWORK)
|
||||
|
|
@ -75,11 +77,6 @@ public class PostgreSQLDaprKeyValueTemplateIT {
|
|||
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
|
||||
.dependsOn(POSTGRE_SQL_CONTAINER);
|
||||
|
||||
@DynamicPropertySource
|
||||
static void daprProperties(DynamicPropertyRegistry registry) {
|
||||
registry.add("dapr.http.endpoint", DAPR_CONTAINER::getHttpEndpoint);
|
||||
registry.add("dapr.grpc.endpoint", DAPR_CONTAINER::getGrpcEndpoint);
|
||||
}
|
||||
|
||||
private static Map<String, String> createStateStoreProperties() {
|
||||
Map<String, String> result = new HashMap<>();
|
||||
|
|
|
|||
|
|
@ -3,13 +3,10 @@ package io.dapr.it.spring.data;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.dapr.client.DaprClient;
|
||||
import io.dapr.spring.boot.autoconfigure.client.DaprClientAutoConfiguration;
|
||||
import io.dapr.spring.core.client.DaprClientCustomizer;
|
||||
import io.dapr.spring.data.DaprKeyValueAdapterResolver;
|
||||
import io.dapr.spring.data.DaprKeyValueTemplate;
|
||||
import io.dapr.spring.data.KeyValueAdapterResolver;
|
||||
import io.dapr.spring.data.repository.config.EnableDaprRepositories;
|
||||
import io.dapr.testcontainers.TestcontainersDaprClientCustomizer;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
|
@ -23,13 +20,6 @@ public class TestDaprSpringDataConfiguration {
|
|||
return new ObjectMapper();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DaprClientCustomizer daprClientCustomizer(
|
||||
@Value("${dapr.http.endpoint}") String daprHttpEndpoint,
|
||||
@Value("${dapr.grpc.endpoint}") String daprGrpcEndpoint
|
||||
){
|
||||
return new TestcontainersDaprClientCustomizer(daprHttpEndpoint, daprGrpcEndpoint);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KeyValueAdapterResolver keyValueAdapterResolver(DaprClient daprClient, ObjectMapper mapper) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import io.dapr.spring.messaging.DaprMessagingTemplate;
|
|||
import io.dapr.testcontainers.Component;
|
||||
import io.dapr.testcontainers.DaprContainer;
|
||||
import io.dapr.testcontainers.DaprLogLevel;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -26,6 +28,7 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||
import org.springframework.test.context.DynamicPropertySource;
|
||||
import org.testcontainers.containers.Network;
|
||||
|
|
@ -56,6 +59,7 @@ public class DaprSpringMessagingIT {
|
|||
private static final Network DAPR_NETWORK = Network.newNetwork();
|
||||
|
||||
@Container
|
||||
@ServiceConnection
|
||||
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.13.2")
|
||||
.withAppName("messaging-dapr-app")
|
||||
.withNetwork(DAPR_NETWORK)
|
||||
|
|
@ -65,22 +69,17 @@ public class DaprSpringMessagingIT {
|
|||
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
|
||||
.withAppChannelAddress("host.testcontainers.internal");
|
||||
|
||||
@DynamicPropertySource
|
||||
static void daprProperties(DynamicPropertyRegistry registry) {
|
||||
org.testcontainers.Testcontainers.exposeHostPorts(8080);
|
||||
|
||||
registry.add("dapr.http.endpoint", DAPR_CONTAINER::getHttpEndpoint);
|
||||
registry.add("dapr.grpc.endpoint", DAPR_CONTAINER::getGrpcEndpoint);
|
||||
registry.add("dapr.grpc.port", DAPR_CONTAINER::getGrpcPort);
|
||||
registry.add("dapr.http.port", DAPR_CONTAINER::getHttpPort);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private DaprMessagingTemplate<String> messagingTemplate;
|
||||
|
||||
@Autowired
|
||||
private TestRestController testRestController;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup(){
|
||||
org.testcontainers.Testcontainers.exposeHostPorts(8080);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDaprMessagingTemplate() throws InterruptedException {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
|
|
|||
|
|
@ -15,10 +15,7 @@ package io.dapr.it.spring.messaging;
|
|||
|
||||
import io.dapr.client.DaprClient;
|
||||
import io.dapr.spring.boot.autoconfigure.pubsub.DaprPubSubProperties;
|
||||
import io.dapr.spring.core.client.DaprClientCustomizer;
|
||||
import io.dapr.spring.messaging.DaprMessagingTemplate;
|
||||
import io.dapr.testcontainers.TestcontainersDaprClientCustomizer;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
|
|
@ -35,14 +32,6 @@ public class TestApplication {
|
|||
@EnableConfigurationProperties(DaprPubSubProperties.class)
|
||||
static class DaprSpringMessagingConfiguration {
|
||||
|
||||
@Bean
|
||||
public DaprClientCustomizer daprClientCustomizer(
|
||||
@Value("${dapr.http.endpoint}") String daprHttpEndpoint,
|
||||
@Value("${dapr.grpc.endpoint}") String daprGrpcEndpoint
|
||||
){
|
||||
return new TestcontainersDaprClientCustomizer(daprHttpEndpoint, daprGrpcEndpoint);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DaprMessagingTemplate<String> messagingTemplate(DaprClient daprClient,
|
||||
DaprPubSubProperties daprPubSubProperties) {
|
||||
|
|
|
|||
|
|
@ -41,12 +41,6 @@
|
|||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dapr.spring</groupId>
|
||||
<artifactId>dapr-spring-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
package io.dapr.testcontainers;
|
||||
|
||||
import io.dapr.client.DaprClientBuilder;
|
||||
import io.dapr.config.Properties;
|
||||
import io.dapr.spring.core.client.DaprClientCustomizer;
|
||||
|
||||
public class TestcontainersDaprClientCustomizer implements DaprClientCustomizer {
|
||||
|
||||
private String httpEndpoint;
|
||||
private String grpcEndpoint;
|
||||
private Integer daprHttpPort;
|
||||
private Integer daprGrpcPort;
|
||||
|
||||
/**
|
||||
* Constructor for TestcontainersDaprClientCustomizer.
|
||||
* @param httpEndpoint HTTP endpoint.
|
||||
* @param grpcEndpoint GRPC endpoint.
|
||||
*/
|
||||
public TestcontainersDaprClientCustomizer(String httpEndpoint, String grpcEndpoint) {
|
||||
this.httpEndpoint = httpEndpoint;
|
||||
this.grpcEndpoint = grpcEndpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for TestcontainersDaprClientCustomizer.
|
||||
* @param daprHttpPort Dapr HTTP port.
|
||||
* @param daprGrpcPort Dapr GRPC port.
|
||||
*/
|
||||
public TestcontainersDaprClientCustomizer(int daprHttpPort, int daprGrpcPort) {
|
||||
this.daprHttpPort = daprHttpPort;
|
||||
this.daprGrpcPort = daprGrpcPort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(DaprClientBuilder daprClientBuilder) {
|
||||
if (httpEndpoint != null) {
|
||||
daprClientBuilder.withPropertyOverride(Properties.HTTP_ENDPOINT, httpEndpoint);
|
||||
}
|
||||
|
||||
if (grpcEndpoint != null) {
|
||||
daprClientBuilder.withPropertyOverride(Properties.GRPC_ENDPOINT, grpcEndpoint);
|
||||
}
|
||||
|
||||
if (daprHttpPort != null) {
|
||||
daprClientBuilder.withPropertyOverride(Properties.HTTP_PORT, String.valueOf(daprHttpPort));
|
||||
}
|
||||
|
||||
if (daprGrpcPort != null) {
|
||||
daprClientBuilder.withPropertyOverride(Properties.GRPC_PORT, String.valueOf(daprGrpcPort));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
package io.dapr.testcontainers;
|
||||
|
||||
import io.dapr.client.DaprClientBuilder;
|
||||
import io.dapr.config.Properties;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
class TestcontainersDaprClientCustomizerTest {
|
||||
private static final int HTTP_PORT = 3500;
|
||||
private static final int GRPC_PORT = 50001;
|
||||
private static final String HTTP_ENDPOINT = "http://localhost:" + HTTP_PORT;
|
||||
private static final String GRPC_ENDPOINT = "localhost:" + GRPC_PORT;
|
||||
|
||||
private DaprClientBuilder daprClientBuilder;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
daprClientBuilder = mock(DaprClientBuilder.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomizeWithEndpointOverrides() {
|
||||
TestcontainersDaprClientCustomizer customizer = new TestcontainersDaprClientCustomizer(HTTP_ENDPOINT, GRPC_ENDPOINT);
|
||||
customizer.customize(daprClientBuilder);
|
||||
|
||||
verify(daprClientBuilder).withPropertyOverride(Properties.HTTP_ENDPOINT, HTTP_ENDPOINT);
|
||||
verify(daprClientBuilder).withPropertyOverride(Properties.GRPC_ENDPOINT, GRPC_ENDPOINT);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomizeWithPortOverrides() {
|
||||
TestcontainersDaprClientCustomizer customizer = new TestcontainersDaprClientCustomizer(HTTP_PORT, GRPC_PORT);
|
||||
customizer.customize(daprClientBuilder);
|
||||
|
||||
verify(daprClientBuilder).withPropertyOverride(Properties.HTTP_PORT, String.valueOf(HTTP_PORT));
|
||||
verify(daprClientBuilder).withPropertyOverride(Properties.GRPC_PORT, String.valueOf(GRPC_PORT));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue