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
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<maven.compiler.target>8</maven.compiler.target>
<maven.deploy.skip>true</maven.deploy.skip>
<gpg.skip>true</gpg.skip>
<skipITs>true</skipITs>

</properties>

<distributionManagement>
Expand Down Expand Up @@ -112,15 +112,15 @@
<groupId>org.codehaus.mojo</groupId>
<artifactId>failsafe-maven-plugin</artifactId>
<version>2.4.3-alpha-1</version>
<configuration>
<skip>${skipITs}</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<skip>${skipITs}</skip>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
12 changes: 12 additions & 0 deletions sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.2.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.2.2.RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
16 changes: 13 additions & 3 deletions sdk/src/test/java/io/dapr/it/DaprIntegrationTestingRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public DaprFreePorts initializeDapr() throws Exception {
private static final String DAPR_COMMAND = " -- mvn exec:java -Dexec.mainClass=%s -Dexec.classpathScope=test -Dexec.args=\"%d\"";

private String buildDaprCommand(){
StringBuilder stringBuilder= new StringBuilder(String.format(DAPR_RUN, this.appName))
StringBuilder stringBuilder= new StringBuilder(String.format(DAPR_RUN, this.getAppName()))
.append(this.useAppPort ? "--app-port " + this.DAPR_FREEPORTS.appPort : "")
.append(" --grpc-port ")
.append(this.DAPR_FREEPORTS.grpcPort)
Expand All @@ -110,12 +110,22 @@ private static Integer findRandomOpenPortOnAllLocalInterfaces() throws Exception
public void destroyDapr() {
Optional.ofNullable(rt).ifPresent( runtime -> {
try {
runtime.exec("dapr stop --app-id " + this.appName);
System.out.println("Start dapr Stop");
runtime.exec("dapr stop --app-id " + this.getAppName());
System.out.println("End Dapr Stop");
} catch (IOException e) {
throw new RuntimeException(e);
}
});
Optional.ofNullable(proc).ifPresent(process -> process.destroy());
Optional.ofNullable(proc).ifPresent(process -> {
System.out.println("Start process Stop");
process.destroyForcibly();
System.out.println("End process Stop");
});
}

public String getAppName() {
return appName;
}

public static class DaprFreePorts
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*/

package io.dapr.it.binding.http;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.dapr.client.DaprClient;
import io.dapr.client.DaprClientBuilder;
import io.dapr.client.domain.Verb;
import io.dapr.it.BaseIT;
import io.dapr.it.services.InputBindingExample;
import io.dapr.serializer.DefaultObjectSerializer;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.Base64;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

/**
* Service for output binding example.
*/
public class OutputBindingExample extends BaseIT {

private static DaprClient client;

@BeforeClass
public static void init() throws Exception {
daprIntegrationTestingRunner =
createDaprIntegrationTestingRunner(
"dapr initialized. Status: Running. Init Elapsed",
InputBindingExample.class,
true,
19000
);
daprIntegrationTestingRunner.initializeDapr();
client = new DaprClientBuilder(new DefaultObjectSerializer(), new DefaultObjectSerializer()).build();
}

public static class MyClass {
public MyClass(){}
public String message;
}

@Test
public void BindingTest() {


final String BINDING_NAME = "sample123";

// This is an example of sending data in a user-defined object. The input binding will receive:
// {"message":"hello"}
MyClass myClass = new MyClass();
myClass.message = "hello";

System.out.println("sending first message");
client.invokeBinding(BINDING_NAME, myClass).block();

// This is an example of sending a plain string. The input binding will receive
// cat
final String m = "cat";
System.out.println("sending " + m);
client.invokeBinding(BINDING_NAME, m).block();

try {
Thread.sleep(8000);
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
return;
}

final List<String> messages = client.invokeService(Verb.GET, daprIntegrationTestingRunner.getAppName(), "messages", null, List.class).block();
assertEquals(2,messages.size());
MyClass resultClass = null;
try {
resultClass = new ObjectMapper().readValue(new String(Base64.getDecoder().decode(messages.get(0))), MyClass.class);
}catch (Exception ex)
{
ex.printStackTrace();
fail("Error on decode message 1");
}

try {
assertEquals("cat", new ObjectMapper().readValue(new String(Base64.getDecoder().decode(messages.get(1))), String.class));
}catch (Exception ex){
ex.printStackTrace();
fail("Error on decode message 2");
}
assertEquals("hello",resultClass.message);
}
}
41 changes: 41 additions & 0 deletions sdk/src/test/java/io/dapr/it/services/InputBindingController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*/

package io.dapr.it.services;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.util.ArrayList;
import java.util.List;

/**
* SpringBoot Controller to handle input binding.
*/
@RestController
public class InputBindingController {

private static final List<byte[]> messagesReceived = new ArrayList();

@PostMapping(path = "/sample123")
public Mono<Void> handleInputBinding(@RequestBody(required = false) byte[] body) {

return Mono.fromRunnable(() -> {
messagesReceived.add(body);
System.out.println("Received message through binding: " + (body == null ? "" : new String(body)));
});
}

@GetMapping(path = "/messages")
public Mono<List<byte[]>> getMessages(){
return Mono.just( messagesReceived);
}



}
30 changes: 30 additions & 0 deletions sdk/src/test/java/io/dapr/it/services/InputBindingExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*/

package io.dapr.it.services;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages = {"io.dapr.it.services"})
public class InputBindingExample {

public static void main(String[] args) throws Exception {
// If port string is not valid, it will throw an exception.
int port = Integer.parseInt(args[0]);
// Start Dapr's callback endpoint.
InputBindingExample.start(port);
}

/**
* Starts Dapr's callback in a given port.
* @param port Port to listen to.
*/
public static void start(int port) {
SpringApplication app = new SpringApplication(InputBindingExample.class);
app.run(String.format("--server.port=%d", port));
}

}