Skip to content

Commit

Permalink
Adding @Serviceconnection spring boot support with Testcontainers (#1118
Browse files Browse the repository at this point in the history
)

* 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>
  • Loading branch information
salaboy and eddumelendez authored Sep 6, 2024
1 parent 9b927c8 commit 4b83da6
Show file tree
Hide file tree
Showing 24 changed files with 312 additions and 294 deletions.
6 changes: 0 additions & 6 deletions dapr-spring/dapr-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,33 @@

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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,32 @@

<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>io.dapr</groupId>
<artifactId>dapr-sdk-springboot</artifactId>
<version>${dapr.sdk.version}</version>
</dependency>
<dependency>
<groupId>io.dapr.spring</groupId>
<artifactId>dapr-spring-core</artifactId>
<artifactId>dapr-spring-boot-autoconfigure</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>io.dapr.spring</groupId>
<artifactId>dapr-spring-boot-autoconfigure</artifactId>
<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>
Expand Down
Loading

0 comments on commit 4b83da6

Please sign in to comment.