Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions sdk-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,75 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${maven-antrun-plugin.version}</version>
<executions>
<execution>
<id>clear-it-runtime</id>
<phase>pre-integration-test</phase>
<goals><goal>run</goal></goals>
<configuration>
<target>
<delete dir="${project.build.directory}/it-runtime"/>
<!-- Remove pre-migration classes left by incremental builds before Failsafe discovery. -->
<delete>
<fileset dir="${project.build.testOutputDirectory}" erroronmissingdir="false">
<include name="io/dapr/it/methodinvoke/http/MethodInvokeIT*.class"/>
<include name="io/dapr/it/methodinvoke/http/MethodInvokeService*.class"/>
<include name="io/dapr/it/methodinvoke/http/MethodInvokeController*.class"/>
<include name="io/dapr/it/methodinvoke/http/Person*.class"/>
</fileset>
</delete>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
<executions>
<execution>
<id>stage-it-classes</id>
<phase>pre-integration-test</phase>
<goals><goal>copy-resources</goal></goals>
<configuration>
<outputDirectory>${project.build.directory}/it-runtime/classes</outputDirectory>
<resources><resource><directory>${project.build.outputDirectory}</directory></resource></resources>
</configuration>
</execution>
<execution>
<id>stage-it-test-classes</id>
<phase>pre-integration-test</phase>
<goals><goal>copy-resources</goal></goals>
<configuration>
<outputDirectory>${project.build.directory}/it-runtime/test-classes</outputDirectory>
<resources><resource><directory>${project.build.testOutputDirectory}</directory></resource></resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version>
<executions>
<execution>
<id>stage-it-dependencies</id>
<phase>pre-integration-test</phase>
<goals><goal>copy-dependencies</goal></goals>
<configuration>
<includeScope>test</includeScope>
<includeTypes>jar</includeTypes>
<useRepositoryLayout>true</useRepositoryLayout>
<outputDirectory>${project.build.directory}/it-runtime/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@
limitations under the License.
*/

package io.dapr.it.methodinvoke.http;
package io.dapr.it.testcontainers.methodinvoke.http;

import com.fasterxml.jackson.databind.JsonNode;
import io.dapr.client.DaprClient;
import io.dapr.client.DaprHttp;
import io.dapr.client.domain.HttpExtension;
import io.dapr.exceptions.DaprException;
import io.dapr.it.AppRun;
import io.dapr.it.MethodInvokeServiceProtos;
import io.dapr.it.containers.BaseContainerIT;
import io.dapr.testcontainers.DaprContainer;
import org.junit.jupiter.api.BeforeAll;
import io.dapr.it.testcontainers.methodinvoke.http.app.MethodInvokeService;
import io.dapr.it.testcontainers.methodinvoke.http.model.Person;
import io.dapr.it.testcontainers.support.DaprTestEnvironment;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.Arrays;
import java.util.Calendar;
Expand All @@ -38,33 +43,27 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

@SuppressWarnings("deprecation")
public class MethodInvokeIT extends BaseContainerIT {
@Testcontainers
@Tag("testcontainers")
public class MethodInvokeIT {

private static final String APP_NAME = "methodinvoke-http-it";
private static final int NUM_MESSAGES = 10;

private static DaprContainer dapr;
private static AppRun app;

@BeforeAll
public static void init() throws Exception {
var pair = startAppAndAttach(
APP_NAME,
MethodInvokeService.class,
AppRun.AppProtocol.HTTP,
appPort -> {
DaprContainer d = daprBuilder(APP_NAME)
.withAppPort(appPort)
.withAppChannelAddress("host.testcontainers.internal");
return d;
});
dapr = pair.dapr();
app = pair.app();
@Container
private static final DaprTestEnvironment ENVIRONMENT = new DaprTestEnvironment(APP_NAME, MethodInvokeService.class);

@BeforeEach
public void reset() throws Exception {
HttpRequest request = HttpRequest.newBuilder(ENVIRONMENT.appEndpoint().resolve("/reset"))
.timeout(Duration.ofSeconds(10)).POST(HttpRequest.BodyPublishers.noBody()).build();
HttpResponse<Void> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.discarding());
assertEquals(200, response.statusCode());
}

@Test
public void testInvoke() throws Exception {
try (DaprClient client = newDaprClient(dapr)) {
try (DaprClient client = ENVIRONMENT.clientBuilder().build()) {
client.waitForSidecar(10000).block();
for (int i = 0; i < NUM_MESSAGES; i++) {
String message = String.format("This is message #%d", i);
Expand All @@ -89,7 +88,7 @@ public void testInvoke() throws Exception {

@Test
public void testInvokeWithObjects() throws Exception {
try (DaprClient client = newDaprClient(dapr)) {
try (DaprClient client = ENVIRONMENT.clientBuilder().build()) {
client.waitForSidecar(10000).block();
for (int i = 0; i < NUM_MESSAGES; i++) {
Person person = new Person();
Expand All @@ -100,12 +99,14 @@ public void testInvokeWithObjects() throws Exception {
System.out.println("Invoke method persons with parameter : " + person);
}

List<Person> persons = Arrays.asList(client.invokeMethod(APP_NAME, "persons", null, HttpExtension.GET, Person[].class).block());
List<Person> persons = Arrays.asList(client.invokeMethod(APP_NAME, "persons", null,
HttpExtension.GET, Person[].class).block());
assertEquals(10, persons.size());

client.invokeMethod(APP_NAME, "persons/1", null, HttpExtension.DELETE).block();

persons = Arrays.asList(client.invokeMethod(APP_NAME, "persons", null, HttpExtension.GET, Person[].class).block());
persons = Arrays.asList(client.invokeMethod(APP_NAME, "persons", null,
HttpExtension.GET, Person[].class).block());
assertEquals(9, persons.size());

Person person = new Person();
Expand All @@ -115,7 +116,8 @@ public void testInvokeWithObjects() throws Exception {

client.invokeMethod(APP_NAME, "persons/2", person, HttpExtension.PUT).block();

persons = Arrays.asList(client.invokeMethod(APP_NAME, "persons", null, HttpExtension.GET, Person[].class).block());
persons = Arrays.asList(client.invokeMethod(APP_NAME, "persons", null,
HttpExtension.GET, Person[].class).block());
Person resultPerson = persons.get(1);
assertEquals("John", resultPerson.getName());
assertEquals("Smith", resultPerson.getLastName());
Expand All @@ -124,7 +126,7 @@ public void testInvokeWithObjects() throws Exception {

@Test
public void testInvokeTimeout() throws Exception {
try (DaprClient client = newDaprClient(dapr)) {
try (DaprClient client = ENVIRONMENT.clientBuilder().build()) {
client.waitForSidecar(10000).block();
long started = System.currentTimeMillis();
String message = assertThrows(IllegalStateException.class, () -> {
Expand All @@ -141,9 +143,8 @@ public void testInvokeTimeout() throws Exception {

@Test
public void testInvokeException() throws Exception {
try (DaprClient client = newDaprClient(dapr)) {
try (DaprClient client = ENVIRONMENT.clientBuilder().build()) {
client.waitForSidecar(10000).block();
MethodInvokeServiceProtos.SleepRequest req = MethodInvokeServiceProtos.SleepRequest.newBuilder().setSeconds(-9).build();
DaprException exception = assertThrows(DaprException.class, () ->
client.invokeMethod(APP_NAME, "sleep", -9, HttpExtension.POST).block());

Expand All @@ -157,7 +158,7 @@ public void testInvokeException() throws Exception {

@Test
public void testInvokeQueryParamEncoding() throws Exception {
try (DaprClient client = newDaprClient(dapr)) {
try (DaprClient client = ENVIRONMENT.clientBuilder().build()) {
client.waitForSidecar(10000).block();

String uri = "abc/pqr";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
package io.dapr.it.methodinvoke.http;
/*
* Copyright 2026 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.it.testcontainers.methodinvoke.http.app;

import io.dapr.it.testcontainers.methodinvoke.http.model.Person;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -24,6 +37,12 @@ public class MethodInvokeController {
private static final Map<Integer,String> messagesReceived = new HashMap<>();
private static final List<Person> persons= new ArrayList<>();

@PostMapping("/reset")
public void reset() {
messagesReceived.clear();
persons.clear();
}

@PostMapping("/messages")
public void postMessages(@RequestBody String message){
System.out.println("Controller got message: " + message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*/

package io.dapr.it.methodinvoke.http;
package io.dapr.it.testcontainers.methodinvoke.http.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down Expand Up @@ -49,4 +49,4 @@ private static void start(int port) {
app.run(String.format("--server.port=%d", port));
}

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
package io.dapr.it.methodinvoke.http;
/*
* Copyright 2026 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.it.testcontainers.methodinvoke.http.model;

import java.util.Date;

/** Serializable person used by the method-invocation fixture. */
public class Person {

private int id;
Expand Down
Loading
Loading