Skip to content

Commit 1cc787f

Browse files
committed
Fix IT for HelloWorldClientIT
Signed-off-by: Artur Souza <[email protected]>
1 parent ecd3f9b commit 1cc787f

File tree

1 file changed

+35
-39
lines changed

1 file changed

+35
-39
lines changed

sdk-tests/src/test/java/io/dapr/it/state/HelloWorldClientIT.java

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@
1313

1414
package io.dapr.it.state;
1515

16-
import io.dapr.config.Properties;
1716
import io.dapr.it.BaseIT;
1817
import io.dapr.it.DaprRun;
1918
import io.dapr.v1.DaprGrpc;
2019
import io.dapr.v1.DaprProtos;
21-
import io.grpc.ManagedChannel;
22-
import io.grpc.ManagedChannelBuilder;
2320
import org.junit.jupiter.api.Assertions;
2421
import org.junit.jupiter.api.Test;
2522

@@ -34,45 +31,44 @@ public void testHelloWorldState() throws Exception {
3431
false,
3532
2000
3633
);
37-
ManagedChannel channel =
38-
ManagedChannelBuilder.forAddress(Properties.SIDECAR_IP.get(), daprRun.getGrpcPort()).usePlaintext().build();
39-
DaprGrpc.DaprBlockingStub client = DaprGrpc.newBlockingStub(channel);
34+
try (var client = daprRun.newDaprClientBuilder().build()) {
35+
var stub = client.newGrpcStub("n/a", DaprGrpc::newBlockingStub);
4036

41-
String key = "mykey";
42-
{
43-
DaprProtos.GetStateRequest req = DaprProtos.GetStateRequest
44-
.newBuilder()
45-
.setStoreName(STATE_STORE_NAME)
46-
.setKey(key)
47-
.build();
48-
DaprProtos.GetStateResponse response = client.getState(req);
49-
String value = response.getData().toStringUtf8();
50-
System.out.println("Got: " + value);
51-
Assertions.assertEquals("Hello World", value);
52-
}
37+
String key = "mykey";
38+
{
39+
DaprProtos.GetStateRequest req = DaprProtos.GetStateRequest
40+
.newBuilder()
41+
.setStoreName(STATE_STORE_NAME)
42+
.setKey(key)
43+
.build();
44+
DaprProtos.GetStateResponse response = stub.getState(req);
45+
String value = response.getData().toStringUtf8();
46+
System.out.println("Got: " + value);
47+
Assertions.assertEquals("Hello World", value);
48+
}
5349

54-
// Then, delete it.
55-
{
56-
DaprProtos.DeleteStateRequest req = DaprProtos.DeleteStateRequest
57-
.newBuilder()
58-
.setStoreName(STATE_STORE_NAME)
59-
.setKey(key)
60-
.build();
61-
client.deleteState(req);
62-
System.out.println("Deleted!");
63-
}
50+
// Then, delete it.
51+
{
52+
DaprProtos.DeleteStateRequest req = DaprProtos.DeleteStateRequest
53+
.newBuilder()
54+
.setStoreName(STATE_STORE_NAME)
55+
.setKey(key)
56+
.build();
57+
stub.deleteState(req);
58+
System.out.println("Deleted!");
59+
}
6460

65-
{
66-
DaprProtos.GetStateRequest req = DaprProtos.GetStateRequest
67-
.newBuilder()
68-
.setStoreName(STATE_STORE_NAME)
69-
.setKey(key)
70-
.build();
71-
DaprProtos.GetStateResponse response = client.getState(req);
72-
String value = response.getData().toStringUtf8();
73-
System.out.println("Got: " + value);
74-
Assertions.assertEquals("", value);
61+
{
62+
DaprProtos.GetStateRequest req = DaprProtos.GetStateRequest
63+
.newBuilder()
64+
.setStoreName(STATE_STORE_NAME)
65+
.setKey(key)
66+
.build();
67+
DaprProtos.GetStateResponse response = stub.getState(req);
68+
String value = response.getData().toStringUtf8();
69+
System.out.println("Got: " + value);
70+
Assertions.assertEquals("", value);
71+
}
7572
}
76-
channel.shutdown();
7773
}
7874
}

0 commit comments

Comments
 (0)