Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding @ServiceConnection spring boot support with Testcontainers #1118

Merged
merged 17 commits into from
Sep 6, 2024

Conversation

salaboy
Copy link
Contributor

@salaboy salaboy commented Sep 3, 2024

Description

This PR implements the Testcontainers @Serviceconnection to simplify how applications can connect to DaprContainers.
This PR also aligns Spring Boot dependencies to reduce the amount of dependencies that users need to add to their projects.

Issue reference

Fixes: #1117

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

@salaboy salaboy requested review from a team as code owners September 3, 2024 09:20
@salaboy salaboy marked this pull request as draft September 3, 2024 09:22
@salaboy salaboy force-pushed the service-conn branch 2 times, most recently from 1850c5b to b6bd2ee Compare September 3, 2024 10:50
Copy link
Contributor

@eddumelendez eddumelendez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just leaving some suggestions and improvements

@salaboy salaboy force-pushed the service-conn branch 2 times, most recently from 1307148 to cbced54 Compare September 4, 2024 14:23
@artur-ciocanu
Copy link
Contributor

@salaboy could you please rebase your PR. Thank you!

@salaboy salaboy force-pushed the service-conn branch 3 times, most recently from 7867cc6 to 2e1eb11 Compare September 5, 2024 08:24
@salaboy salaboy marked this pull request as ready for review September 5, 2024 08:51
@salaboy salaboy changed the title [WIP] Adding @ServiceConnection spring boot support with Testcontainers Adding @ServiceConnection spring boot support with Testcontainers Sep 5, 2024
@salaboy salaboy force-pushed the service-conn branch 4 times, most recently from a3cf5ec to c85cd22 Compare September 5, 2024 09:46
@salaboy
Copy link
Contributor Author

salaboy commented Sep 5, 2024

@artursouza @cicoyle this is the last PR to get the Documentation working with an example. Please review and I am happy to have a call if you want to make the review faster.

Copy link
Contributor

@artur-ciocanu artur-ciocanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@salaboy awesome job! I have left a few tiny comments, mostly for renaming and cleanup.

package io.dapr.spring.boot.autoconfigure.client;

import org.springframework.boot.context.properties.ConfigurationProperties;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small question, should we use the old Java style Java Beans or should we recommend users to go with Java records?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both should be fine right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, I would go with java beans in order to add javadoc and could generate the metadata, the configuration processor is already in the classpath. See https://docs.spring.io/spring-boot/specification/configuration-metadata/annotation-processor.html


public class DaprContainerConnectionDetailsFactory
extends ContainerConnectionDetailsFactory<DaprContainer, DaprConnectionDetails> {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this constructor provides any value

import io.dapr.testcontainers.DaprContainer;
import org.springframework.boot.testcontainers.service.connection.ContainerConnectionDetailsFactory;
import org.springframework.boot.testcontainers.service.connection.ContainerConnectionSource;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could rename this to DaprConnectionDetailsFactory so it is similar to other connection details factory like Redis, Mongo, Kafka, etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@artur-ciocanu I am following testcontainers conventions as the connectiondetails for this will be extracted from the DaprContainer

protected DaprConnectionDetails getContainerConnectionDetails(ContainerConnectionSource<DaprContainer> source) {
return new DaprContainerConnectionDetails(source);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we rename this to DefaultDaprConnectionDetails, DaprContainer seems redundant. We want to connect to Dapr, irrespective where it is running, container or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming convention comes from this: DaprContainer paramter

@@ -93,6 +95,8 @@ public class MySQLDaprKeyValueTemplateIT {
static void daprProperties(DynamicPropertyRegistry registry) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove the daprProperties method, we are using @ServiceConnection

package io.dapr.spring.boot.autoconfigure.client;

import org.springframework.boot.context.properties.ConfigurationProperties;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, I would go with java beans in order to add javadoc and could generate the metadata, the configuration processor is already in the classpath. See https://docs.spring.io/spring-boot/specification/configuration-metadata/annotation-processor.html

@salaboy salaboy force-pushed the service-conn branch 2 times, most recently from 9f130eb to 73a1f55 Compare September 6, 2024 10:35
@artur-ciocanu
Copy link
Contributor

@salaboy I have added a small comment, the issue with the build that you have faced is related to DaprClientProperties. You have two options:

  • Remove the constructor and leave the setters
  • Remove the setters and ensure that we preserve parameter names by leveraging the -parameter compiler flag. In order to preserver the parameter name you should add the <parameters>true</parameters> to Maven Compiler Plugin in the Parent POM. Something like this:
          <configuration>
            <source>${maven.compiler.source}</source>
            <target>${maven.compiler.target}</target>
            <release>${maven.compiler.release}</release>
            <parameters>true</parameters>
          </configuration>

Let me know your thoughts.

salaboy and others added 17 commits September 6, 2024 14:16
Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
…pr/spring/boot/autoconfigure/client/DaprClientAutoConfiguration.java

Co-authored-by: Eddú Meléndez Gonzales <eddu.melendez@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
…pr/spring/boot/autoconfigure/client/PropertiesDaprConnectionDetails.java

Co-authored-by: Eddú Meléndez Gonzales <eddu.melendez@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>
@salaboy
Copy link
Contributor Author

salaboy commented Sep 6, 2024

@salaboy I have added a small comment, the issue with the build that you have faced is related to DaprClientProperties. You have two options:

  • Remove the constructor and leave the setters
  • Remove the setters and ensure that we preserve parameter names by leveraging the -parameter compiler flag. In order to preserver the parameter name you should add the <parameters>true</parameters> to Maven Compiler Plugin in the Parent POM. Something like this:
          <configuration>
            <source>${maven.compiler.source}</source>
            <target>${maven.compiler.target}</target>
            <release>${maven.compiler.release}</release>
            <parameters>true</parameters>
          </configuration>

Let me know your thoughts.

This is solved now

@artursouza artursouza merged commit 4b83da6 into dapr:master Sep 6, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support @ServiceConnection for DaprContainer using Testcontainers
4 participants