getMessages() {
+ return messagesReceived;
+ }
+
+ @GetMapping(path = "/")
+ public String hello() {
+ return "hello";
+ }
+
+}
diff --git a/sdk/src/test/java/io/dapr/it/services/InputBindingExample.java b/sdk-tests/src/test/java/io/dapr/it/binding/http/InputBindingService.java
similarity index 56%
rename from sdk/src/test/java/io/dapr/it/services/InputBindingExample.java
rename to sdk-tests/src/test/java/io/dapr/it/binding/http/InputBindingService.java
index 8a84e34fc..7ecef637d 100644
--- a/sdk/src/test/java/io/dapr/it/services/InputBindingExample.java
+++ b/sdk-tests/src/test/java/io/dapr/it/binding/http/InputBindingService.java
@@ -3,27 +3,32 @@
* Licensed under the MIT License.
*/
-package io.dapr.it.services;
+package io.dapr.it.binding.http;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-@SpringBootApplication(scanBasePackages = {"io.dapr.it.services"})
-public class InputBindingExample {
+@SpringBootApplication(scanBasePackages = {"io.dapr.it.binding.http"})
+public class InputBindingService {
+
+ public static final String SUCCESS_MESSAGE = "dapr initialized. Status: Running. Init Elapsed";
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]);
+
+ System.out.printf("Service starting on port %d ...\n", port);
// Start Dapr's callback endpoint.
- InputBindingExample.start(port);
+ 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);
+ private static void start(int port) {
+ SpringApplication app = new SpringApplication(InputBindingService.class);
app.run(String.format("--server.port=%d", port));
}
diff --git a/sdk/src/test/java/io/dapr/it/services/EmptyService.java b/sdk-tests/src/test/java/io/dapr/it/services/EmptyService.java
similarity index 68%
rename from sdk/src/test/java/io/dapr/it/services/EmptyService.java
rename to sdk-tests/src/test/java/io/dapr/it/services/EmptyService.java
index b5b262220..1a167e124 100644
--- a/sdk/src/test/java/io/dapr/it/services/EmptyService.java
+++ b/sdk-tests/src/test/java/io/dapr/it/services/EmptyService.java
@@ -7,13 +7,16 @@ package io.dapr.it.services;
/**
* Use this class in order to run DAPR with any needed services, like states.
- *
+ *
* To run manually, from repo root:
* 1. mvn clean install
* 2. dapr run --grpc-port 41707 --port 32851 -- mvn exec:java -Dexec.mainClass=io.dapr.it.services.EmptyService -Dexec.classpathScope="test" -Dexec.args="-p 44511 -grpcPort 41707 -httpPort 32851" -pl=sdk
*/
public class EmptyService {
- public static void main(String[] args) {
- System.out.println("Hello from EmptyService");
- }
+
+ public static final String SUCCESS_MESSAGE = "Hello from " + EmptyService.class.getSimpleName();
+
+ public static void main(String[] args) throws InterruptedException {
+ System.out.println(SUCCESS_MESSAGE);
+ }
}
diff --git a/sdk/src/test/java/io/dapr/it/state/GRPCStateClientIT.java b/sdk-tests/src/test/java/io/dapr/it/state/GRPCStateClientIT.java
similarity index 94%
rename from sdk/src/test/java/io/dapr/it/state/GRPCStateClientIT.java
rename to sdk-tests/src/test/java/io/dapr/it/state/GRPCStateClientIT.java
index 2ca6cf612..ba167d562 100644
--- a/sdk/src/test/java/io/dapr/it/state/GRPCStateClientIT.java
+++ b/sdk-tests/src/test/java/io/dapr/it/state/GRPCStateClientIT.java
@@ -6,11 +6,14 @@
package io.dapr.it.state;
import io.dapr.client.DaprClient;
-import io.dapr.client.DaprClientTestBuilder;
+import io.dapr.client.DaprClientBuilder;
+import io.dapr.client.DaprClientGrpcAdapter;
import io.dapr.client.domain.State;
import io.dapr.client.domain.StateOptions;
import io.dapr.it.BaseIT;
+import io.dapr.it.DaprRun;
import io.dapr.it.services.EmptyService;
+import io.dapr.serializer.DefaultObjectSerializer;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -25,19 +28,23 @@ import static org.junit.Assert.*;
*/
public class GRPCStateClientIT extends BaseIT {
- private static DaprClient daprClient;
+ private static DaprRun daprRun;
+
+ private static DaprClient daprClient;
@BeforeClass
public static void init() throws Exception {
- daprIntegrationTestingRunner =
- createDaprIntegrationTestingRunner(
- "BUILD SUCCESS",
+ daprRun = startDaprApp(
+ GRPCStateClientIT.class.getSimpleName(),
+ EmptyService.SUCCESS_MESSAGE,
EmptyService.class,
false,
- 0
- );
- daprIntegrationTestingRunner.initializeDapr();
- daprClient = DaprClientTestBuilder.buildGrpcClient();
+ 5000
+ );
+ daprRun.switchToGRPC();
+ daprClient = new DaprClientBuilder(new DefaultObjectSerializer(), new DefaultObjectSerializer()).build();
+
+ assertTrue(daprClient instanceof DaprClientGrpcAdapter);
}
@@ -193,7 +200,7 @@ public class GRPCStateClientIT extends BaseIT {
//review that state value changes
assertNotNull(myDataResponse.getEtag());
//review that the etag changes after an update
- assertNotEquals(firstETag,myDataResponse.getEtag());
+ assertNotEquals(firstETag, myDataResponse.getEtag());
assertNotNull(myDataResponse.getKey());
assertNotNull(myDataResponse.getValue());
assertEquals("data in property A2", myDataResponse.getValue().getPropertyA());
@@ -237,7 +244,6 @@ public class GRPCStateClientIT extends BaseIT {
saveResponse.block();
-
response = daprClient.getState(new State(stateKey, null, null), MyData.class);
//retrive the data wihout any etag
myDataResponse = response.block();
@@ -245,7 +251,7 @@ public class GRPCStateClientIT extends BaseIT {
//review that state value changes
assertNotNull(myDataResponse.getEtag());
//review that the etag changes after an update
- assertNotEquals(firstETag,myDataResponse.getEtag());
+ assertNotEquals(firstETag, myDataResponse.getEtag());
assertNotNull(myDataResponse.getKey());
assertNotNull(myDataResponse.getValue());
assertEquals("data in property A2", myDataResponse.getValue().getPropertyA());
@@ -296,7 +302,6 @@ public class GRPCStateClientIT extends BaseIT {
final String stateKey = "myeKeyToBeDeletedWithWrongEtag";
-
//Create dummy data to be store
MyData data = new MyData();
data.setPropertyA("data in property A");
@@ -339,7 +344,6 @@ public class GRPCStateClientIT extends BaseIT {
StateOptions stateOptions = new StateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, null);
-
//create Dummy data
MyData data = new MyData();
data.setPropertyA("data in property A");
@@ -397,7 +401,6 @@ public class GRPCStateClientIT extends BaseIT {
StateOptions stateOptions = new StateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.LAST_WRITE, null);
-
//create Dummy data
MyData data = new MyData();
data.setPropertyA("data in property A");
@@ -447,14 +450,13 @@ public class GRPCStateClientIT extends BaseIT {
assertEquals("data in property B2", myLastDataResponse.getValue().getPropertyB());
}
- @Test(timeout=13000)
+ @Test(timeout = 13000)
public void saveDeleteWithRetry() {
final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry";
- StateOptions.RetryPolicy retryPolicy= new StateOptions.RetryPolicy(Duration.ofSeconds(3),3, StateOptions.RetryPolicy.Pattern.LINEAR);
+ StateOptions.RetryPolicy retryPolicy = new StateOptions.RetryPolicy(Duration.ofSeconds(3), 3, StateOptions.RetryPolicy.Pattern.LINEAR);
StateOptions stateOptions = new StateOptions(null, null, retryPolicy);
-
//Create dummy data to be store
MyData data = new MyData();
data.setPropertyA("data in property A");
@@ -484,25 +486,24 @@ public class GRPCStateClientIT extends BaseIT {
try {
//delete action
deleteResponse.block();
- }catch(RuntimeException ex){
+ } catch (RuntimeException ex) {
assertTrue(ex.getMessage().contains("failed to set value after 3 retries"));
}
long end = System.currentTimeMillis();
System.out.println("DEBUG: Logic A took " + (end - start) + " MilliSeconds");
- long elapsedTime = end -start;
- assertTrue(elapsedTime>9000 && elapsedTime<9200);
+ long elapsedTime = end - start;
+ assertTrue(elapsedTime > 9000 && elapsedTime < 9200);
}
@Ignore("Ignored as an issue on DAPR")
- @Test(timeout=13000)
+ @Test(timeout = 13000)
public void saveUpdateWithRetry() {
final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry";
- StateOptions.RetryPolicy retryPolicy= new StateOptions.RetryPolicy(Duration.ofSeconds(4),3, StateOptions.RetryPolicy.Pattern.LINEAR);
+ StateOptions.RetryPolicy retryPolicy = new StateOptions.RetryPolicy(Duration.ofSeconds(4), 3, StateOptions.RetryPolicy.Pattern.LINEAR);
StateOptions stateOptions = new StateOptions(null, null, retryPolicy);
-
//Create dummy data to be store
MyData data = new MyData();
data.setPropertyA("data in property A");
@@ -533,13 +534,13 @@ public class GRPCStateClientIT extends BaseIT {
try {
saveResponse.block();
- }catch(RuntimeException ex){
+ } catch (RuntimeException ex) {
assertTrue(ex.getMessage().contains("failed to set value after 3 retries"));
}
long end = System.currentTimeMillis();
System.out.println("DEBUG: Logic A took " + (end - start) + " MilliSeconds");
- long elapsedTime = end -start;
- assertTrue(elapsedTime>9000 && elapsedTime<9200);
+ long elapsedTime = end - start;
+ assertTrue(elapsedTime > 9000 && elapsedTime < 9200);
}
diff --git a/sdk/src/test/java/io/dapr/it/state/HelloWorldClientIT.java b/sdk-tests/src/test/java/io/dapr/it/state/HelloWorldClientIT.java
similarity index 66%
rename from sdk/src/test/java/io/dapr/it/state/HelloWorldClientIT.java
rename to sdk-tests/src/test/java/io/dapr/it/state/HelloWorldClientIT.java
index 637e692c4..2bd38c03c 100644
--- a/sdk/src/test/java/io/dapr/it/state/HelloWorldClientIT.java
+++ b/sdk-tests/src/test/java/io/dapr/it/state/HelloWorldClientIT.java
@@ -8,36 +8,25 @@ package io.dapr.it.state;
import io.dapr.DaprGrpc;
import io.dapr.DaprProtos;
import io.dapr.it.BaseIT;
-import io.dapr.it.DaprIntegrationTestingRunner;
-import io.dapr.it.services.HelloWorldGrpcStateService;
+import io.dapr.it.DaprRun;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.junit.Assert;
-import org.junit.BeforeClass;
import org.junit.Test;
-import static io.dapr.it.DaprIntegrationTestingRunner.DAPR_FREEPORTS;
-
public class HelloWorldClientIT extends BaseIT {
- private static DaprIntegrationTestingRunner daprIntegrationTestingRunner;
-
- @BeforeClass
- public static void init() throws Exception {
- daprIntegrationTestingRunner =
- createDaprIntegrationTestingRunner(
- "BUILD SUCCESS",
+ @Test
+ public void testHelloWorldState() throws Exception {
+ DaprRun daprRun = startDaprApp(
+ HelloWorldClientIT.class.getSimpleName(),
+ HelloWorldGrpcStateService.SUCCESS_MESSAGE,
HelloWorldGrpcStateService.class,
false,
2000
- );
- daprIntegrationTestingRunner.initializeDapr();
- }
-
- @Test
- public void testHelloWorldState(){
+ );
ManagedChannel channel =
- ManagedChannelBuilder.forAddress("localhost", DAPR_FREEPORTS.getGrpcPort()).usePlaintext().build();
+ ManagedChannelBuilder.forAddress("localhost", daprRun.getGrpcPort()).usePlaintext().build();
DaprGrpc.DaprBlockingStub client = DaprGrpc.newBlockingStub(channel);
String key = "mykey";
@@ -49,7 +38,7 @@ public class HelloWorldClientIT extends BaseIT {
DaprProtos.GetStateResponseEnvelope response = client.getState(req);
String value = response.getData().getValue().toStringUtf8();
System.out.println("Got: " + value);
- Assert.assertEquals("Hello World",value);
+ Assert.assertEquals("Hello World", value);
}
// Then, delete it.
@@ -70,7 +59,7 @@ public class HelloWorldClientIT extends BaseIT {
DaprProtos.GetStateResponseEnvelope response = client.getState(req);
String value = response.getData().getValue().toStringUtf8();
System.out.println("Got: " + value);
- Assert.assertEquals("",value);
+ Assert.assertEquals("", value);
}
}
}
diff --git a/sdk-tests/src/test/java/io/dapr/it/state/HelloWorldGrpcStateService.java b/sdk-tests/src/test/java/io/dapr/it/state/HelloWorldGrpcStateService.java
new file mode 100644
index 000000000..7c79b9999
--- /dev/null
+++ b/sdk-tests/src/test/java/io/dapr/it/state/HelloWorldGrpcStateService.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) Microsoft Corporation.
+ * Licensed under the MIT License.
+ */
+
+package io.dapr.it.state;
+
+import com.google.protobuf.Any;
+import com.google.protobuf.ByteString;
+import io.dapr.DaprGrpc;
+import io.dapr.DaprGrpc.DaprBlockingStub;
+import io.dapr.DaprProtos.SaveStateEnvelope;
+import io.dapr.DaprProtos.StateRequest;
+import io.grpc.ManagedChannel;
+import io.grpc.ManagedChannelBuilder;
+
+
+/**
+ * Simple example.
+ * To run manually, from repo root:
+ * 1. mvn clean install
+ * 2. dapr run --grpc-port 50001 -- mvn exec:java -Dexec.mainClass=io.dapr.it.state.HelloWorldGrpcStateService -Dexec.classpathScope="test" -pl=sdk
+ */
+public class HelloWorldGrpcStateService {
+
+ public static final String SUCCESS_MESSAGE = "Hello from " + HelloWorldGrpcStateService.class.getSimpleName();
+
+ public static void main(String[] args) {
+ String grpcPort = System.getenv("DAPR_GRPC_PORT");
+
+ // If port string is not valid, it will throw an exception.
+ int grpcPortInt = Integer.parseInt(grpcPort);
+ ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", grpcPortInt).usePlaintext().build();
+ DaprBlockingStub client = DaprGrpc.newBlockingStub(channel);
+
+ String key = "mykey";
+ // First, write key-value pair.
+
+ String value = "Hello World";
+ StateRequest req = StateRequest
+ .newBuilder()
+ .setKey(key)
+ .setValue(Any.newBuilder().setValue(ByteString.copyFromUtf8(value)).build())
+ .build();
+ SaveStateEnvelope state = SaveStateEnvelope.newBuilder()
+ .addRequests(req)
+ .build();
+ client.saveState(state);
+ System.out.println("Saved!");
+ channel.shutdown();
+
+ System.out.println(SUCCESS_MESSAGE);
+ }
+}
diff --git a/sdk/src/test/java/io/dapr/it/state/HttpStateClientIT.java b/sdk-tests/src/test/java/io/dapr/it/state/HttpStateClientIT.java
similarity index 95%
rename from sdk/src/test/java/io/dapr/it/state/HttpStateClientIT.java
rename to sdk-tests/src/test/java/io/dapr/it/state/HttpStateClientIT.java
index 3a6022030..edefd46e2 100644
--- a/sdk/src/test/java/io/dapr/it/state/HttpStateClientIT.java
+++ b/sdk-tests/src/test/java/io/dapr/it/state/HttpStateClientIT.java
@@ -7,11 +7,12 @@ package io.dapr.it.state;
import io.dapr.client.DaprClient;
import io.dapr.client.DaprClientBuilder;
-import io.dapr.serializer.DefaultObjectSerializer;
import io.dapr.client.domain.State;
import io.dapr.client.domain.StateOptions;
import io.dapr.it.BaseIT;
+import io.dapr.it.DaprRun;
import io.dapr.it.services.EmptyService;
+import io.dapr.serializer.DefaultObjectSerializer;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Ignore;
@@ -25,16 +26,17 @@ import java.time.Duration;
*/
public class HttpStateClientIT extends BaseIT {
+ private static DaprRun daprRun;
+
@BeforeClass
public static void init() throws Exception {
- daprIntegrationTestingRunner =
- createDaprIntegrationTestingRunner(
- "BUILD SUCCESS",
+ daprRun = startDaprApp(
+ HttpStateClientIT.class.getSimpleName(),
+ EmptyService.SUCCESS_MESSAGE,
EmptyService.class,
false,
- 0
- );
- daprIntegrationTestingRunner.initializeDapr();
+ 1000
+ );
}
@Test
@@ -192,7 +194,7 @@ public class HttpStateClientIT extends BaseIT {
//review that state value changes
Assert.assertNotNull(myDataResponse.getEtag());
//review that the etag changes after an update
- Assert.assertNotEquals(firstETag,myDataResponse.getEtag());
+ Assert.assertNotEquals(firstETag, myDataResponse.getEtag());
Assert.assertNotNull(myDataResponse.getKey());
Assert.assertNotNull(myDataResponse.getValue());
Assert.assertEquals("data in property A2", myDataResponse.getValue().getPropertyA());
@@ -245,7 +247,7 @@ public class HttpStateClientIT extends BaseIT {
//review that state value changes
Assert.assertNotNull(myDataResponse.getEtag());
//review that the etag changes after an update
- Assert.assertNotEquals(firstETag,myDataResponse.getEtag());
+ Assert.assertNotEquals(firstETag, myDataResponse.getEtag());
Assert.assertNotNull(myDataResponse.getKey());
Assert.assertNotNull(myDataResponse.getValue());
Assert.assertEquals("data in property A2", myDataResponse.getValue().getPropertyA());
@@ -446,10 +448,10 @@ public class HttpStateClientIT extends BaseIT {
Assert.assertEquals("data in property B2", myLastDataResponse.getValue().getPropertyB());
}
- @Test(timeout=13000)
+ @Test(timeout = 13000)
public void saveDeleteWithRetry() {
final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry";
- StateOptions.RetryPolicy retryPolicy= new StateOptions.RetryPolicy(Duration.ofSeconds(3),3, StateOptions.RetryPolicy.Pattern.LINEAR);
+ StateOptions.RetryPolicy retryPolicy = new StateOptions.RetryPolicy(Duration.ofSeconds(3), 3, StateOptions.RetryPolicy.Pattern.LINEAR);
StateOptions stateOptions = new StateOptions(null, null, retryPolicy);
//create DAPR client
@@ -483,21 +485,21 @@ public class HttpStateClientIT extends BaseIT {
try {
//delete action
deleteResponse.block();
- }catch(RuntimeException ex){
+ } catch (RuntimeException ex) {
Assert.assertTrue(ex.getMessage().contains("failed to set value after 3 retries"));
}
long end = System.currentTimeMillis();
System.out.println("DEBUG: Logic A took " + (end - start) + " MilliSeconds");
- long elapsedTime = end -start;
- Assert.assertTrue(elapsedTime>9000 && elapsedTime<9200);
+ long elapsedTime = end - start;
+ Assert.assertTrue(elapsedTime > 9000 && elapsedTime < 9200);
}
@Ignore("Ignored as an issue on DAPR")
- @Test(timeout=13000)
+ @Test(timeout = 13000)
public void saveUpdateWithRetry() {
final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry";
- StateOptions.RetryPolicy retryPolicy= new StateOptions.RetryPolicy(Duration.ofSeconds(4),3, StateOptions.RetryPolicy.Pattern.EXPONENTIAL);
+ StateOptions.RetryPolicy retryPolicy = new StateOptions.RetryPolicy(Duration.ofSeconds(4), 3, StateOptions.RetryPolicy.Pattern.EXPONENTIAL);
StateOptions stateOptions = new StateOptions(null, null, retryPolicy);
//create DAPR client
@@ -532,13 +534,13 @@ public class HttpStateClientIT extends BaseIT {
try {
saveResponse.block();
- }catch(RuntimeException ex){
+ } catch (RuntimeException ex) {
Assert.assertTrue(ex.getMessage().contains("failed to set value after 3 retries"));
}
long end = System.currentTimeMillis();
System.out.println("DEBUG: Logic A took " + (end - start) + " MilliSeconds");
- long elapsedTime = end -start;
- Assert.assertTrue(elapsedTime>9000 && elapsedTime<9200);
+ long elapsedTime = end - start;
+ Assert.assertTrue(elapsedTime > 9000 && elapsedTime < 9200);
}
diff --git a/sdk-tests/src/test/java/io/dapr/it/state/MyData.java b/sdk-tests/src/test/java/io/dapr/it/state/MyData.java
new file mode 100644
index 000000000..e99a2e2eb
--- /dev/null
+++ b/sdk-tests/src/test/java/io/dapr/it/state/MyData.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) Microsoft Corporation.
+ * Licensed under the MIT License.
+ */
+
+package io.dapr.it.state;
+
+public class MyData {
+
+ /// Gets or sets the value for PropertyA.
+ private String propertyA;
+
+ /// Gets or sets the value for PropertyB.
+ private String propertyB;
+
+ private MyData myData;
+
+ public String getPropertyB() {
+ return propertyB;
+ }
+
+ public void setPropertyB(String propertyB) {
+ this.propertyB = propertyB;
+ }
+
+ public String getPropertyA() {
+ return propertyA;
+ }
+
+ public void setPropertyA(String propertyA) {
+ this.propertyA = propertyA;
+ }
+
+ @Override
+ public String toString() {
+ return "MyData{" +
+ "propertyA='" + propertyA + '\'' +
+ ", propertyB='" + propertyB + '\'' +
+ '}';
+ }
+
+ public MyData getMyData() {
+ return myData;
+ }
+
+ public void setMyData(MyData myData) {
+ this.myData = myData;
+ }
+}
diff --git a/sdk/pom.xml b/sdk/pom.xml
index af7a79b2b..d4e59c951 100644
--- a/sdk/pom.xml
+++ b/sdk/pom.xml
@@ -28,7 +28,6 @@
- false
false
@@ -80,12 +79,6 @@
1.3.2
test