From f177ad34d30225888f903ccceacca5f3a696cfd4 Mon Sep 17 00:00:00 2001 From: Javier Aliaga Date: Tue, 13 Jan 2026 16:21:47 +0100 Subject: [PATCH 1/2] chore: Update dapr version Signed-off-by: Javier Aliaga --- .github/workflows/build.yml | 2 +- .github/workflows/validate.yml | 2 +- pom.xml | 3 +- sdk-autogen/pom.xml | 192 +++++++++++++++++- spring-boot-examples/kubernetes/README.md | 2 +- .../DaprContainerConstants.java | 2 +- 6 files changed, 191 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5613ce1685..dfe9980410 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -116,7 +116,7 @@ jobs: GOPROXY: https://proxy.golang.org JDK_VER: ${{ matrix.java }} DAPR_CLI_VER: 1.15.0 - DAPR_RUNTIME_VER: 1.16.0-rc.5 + DAPR_RUNTIME_VER: 1.17.0-rc.1 DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v1.15.0/install/install.sh DAPR_CLI_REF: DAPR_REF: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 43d19bcd37..34db9d800a 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -38,7 +38,7 @@ jobs: GOPROXY: https://proxy.golang.org JDK_VER: ${{ matrix.java }} DAPR_CLI_VER: 1.15.0 - DAPR_RUNTIME_VER: 1.16.0-rc.5 + DAPR_RUNTIME_VER: 1.17.0-rc.1 DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v1.15.0/install/install.sh DAPR_CLI_REF: DAPR_REF: diff --git a/pom.xml b/pom.xml index 37c6ecea7d..faa95322a2 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,8 @@ UTF-8 1.69.0 3.25.5 - https://raw.githubusercontent.com/dapr/dapr/v1.16.0-rc.5/dapr/proto + https://raw.githubusercontent.com/javier-aliaga/dapr/fix-dapr-proto-java-class/dapr/proto + https://raw.githubusercontent.com/dapr/durabletask-protobuf/main/protos/orchestrator_service.proto 1.17.0-SNAPSHOT 1.7.1 diff --git a/sdk-autogen/pom.xml b/sdk-autogen/pom.xml index b64287d811..d6339abaf9 100644 --- a/sdk-autogen/pom.xml +++ b/sdk-autogen/pom.xml @@ -59,6 +59,97 @@ download-maven-plugin ${download-maven-plugin.version} + + getCommonProto + initialize + + wget + + + true + ${dapr.proto.baseurl}/common/v1/common.proto + common.proto + ${protobuf.input.directory}/dapr/proto/common/v1 + + + + getActorsProto + initialize + + wget + + + true + ${dapr.proto.baseurl}/runtime/v1/actors.proto + actors.proto + ${protobuf.input.directory}/dapr/proto/runtime/v1 + + + + getAiProto + initialize + + wget + + + true + ${dapr.proto.baseurl}/runtime/v1/ai.proto + ai.proto + ${protobuf.input.directory}/dapr/proto/runtime/v1 + + + + getAppcallbackProto + initialize + + wget + + + true + ${dapr.proto.baseurl}/runtime/v1/appcallback.proto + appcallback.proto + ${protobuf.input.directory}/dapr/proto/runtime/v1 + + + + getBindingProto + initialize + + wget + + + true + ${dapr.proto.baseurl}/runtime/v1/binding.proto + binding.proto + ${protobuf.input.directory}/dapr/proto/runtime/v1 + + + + getConfigurationProto + initialize + + wget + + + true + ${dapr.proto.baseurl}/runtime/v1/configuration.proto + configuration.proto + ${protobuf.input.directory}/dapr/proto/runtime/v1 + + + + getCryptoProto + initialize + + wget + + + true + ${dapr.proto.baseurl}/runtime/v1/crypto.proto + crypto.proto + ${protobuf.input.directory}/dapr/proto/runtime/v1 + + getDaprProto initialize @@ -73,33 +164,113 @@ - getCommonProto + getInvokeProto initialize wget true - ${dapr.proto.baseurl}/common/v1/common.proto - common.proto - ${protobuf.input.directory}/dapr/proto/common/v1 + ${dapr.proto.baseurl}/runtime/v1/invoke.proto + invoke.proto + ${protobuf.input.directory}/dapr/proto/runtime/v1 - getDaprClientProto + getJobsProto initialize wget true - ${dapr.proto.baseurl}/runtime/v1/appcallback.proto - appcallback.proto + ${dapr.proto.baseurl}/runtime/v1/jobs.proto + jobs.proto + ${protobuf.input.directory}/dapr/proto/runtime/v1 + + + + getLockProto + initialize + + wget + + + true + ${dapr.proto.baseurl}/runtime/v1/lock.proto + lock.proto + ${protobuf.input.directory}/dapr/proto/runtime/v1 + + + + getMetadataProto + initialize + + wget + + + true + ${dapr.proto.baseurl}/runtime/v1/metadata.proto + metadata.proto + ${protobuf.input.directory}/dapr/proto/runtime/v1 + + + + getPubsubProto + initialize + + wget + + + true + ${dapr.proto.baseurl}/runtime/v1/pubsub.proto + pubsub.proto + ${protobuf.input.directory}/dapr/proto/runtime/v1 + + + + getSecretProto + initialize + + wget + + + true + ${dapr.proto.baseurl}/runtime/v1/secret.proto + secret.proto + ${protobuf.input.directory}/dapr/proto/runtime/v1 + + + + getStateProto + initialize + + wget + + + true + ${dapr.proto.baseurl}/runtime/v1/state.proto + state.proto + ${protobuf.input.directory}/dapr/proto/runtime/v1 + + + + getWorkflowProto + initialize + + wget + + + true + ${dapr.proto.baseurl}/runtime/v1/workflow.proto + workflow.proto ${protobuf.input.directory}/dapr/proto/runtime/v1 + + org.xolstice.maven.plugins protobuf-maven-plugin @@ -116,6 +287,13 @@ compile compile-custom + + + dapr/proto/common/v1/common.proto + dapr/proto/runtime/v1/*.proto + + + diff --git a/spring-boot-examples/kubernetes/README.md b/spring-boot-examples/kubernetes/README.md index d780c2eb82..9ededae68f 100644 --- a/spring-boot-examples/kubernetes/README.md +++ b/spring-boot-examples/kubernetes/README.md @@ -30,7 +30,7 @@ Once you have the cluster up and running you can install Dapr: helm repo add dapr https://dapr.github.io/helm-charts/ helm repo update helm upgrade --install dapr dapr/dapr \ ---version=1.16.0-rc.5 \ +--version=1.17.0-rc.1 \ --namespace dapr-system \ --create-namespace \ --wait diff --git a/testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprContainerConstants.java b/testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprContainerConstants.java index f326073366..418e79b798 100644 --- a/testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprContainerConstants.java +++ b/testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprContainerConstants.java @@ -14,7 +14,7 @@ package io.dapr.testcontainers; public interface DaprContainerConstants { - String DAPR_VERSION = "1.16.0-rc.5"; + String DAPR_VERSION = "1.17.0-rc.1"; String DAPR_RUNTIME_IMAGE_TAG = "daprio/daprd:" + DAPR_VERSION; String DAPR_PLACEMENT_IMAGE_TAG = "daprio/placement:" + DAPR_VERSION; String DAPR_SCHEDULER_IMAGE_TAG = "daprio/scheduler:" + DAPR_VERSION; From 9798647d146e83b3d319f96a2f82d574bd1b7a88 Mon Sep 17 00:00:00 2001 From: Javier Aliaga Date: Tue, 13 Jan 2026 18:32:20 +0100 Subject: [PATCH 2/2] chore: Refator Proto classes Signed-off-by: Javier Aliaga --- pom.xml | 3 +- .../io/dapr/actors/client/DaprClientImpl.java | 17 +- .../dapr/actors/runtime/DaprClientImpl.java | 34 +- .../actors/client/DaprGrpcClientTest.java | 10 +- .../actors/runtime/DaprGrpcClientTest.java | 153 ++- .../io/dapr/it/state/HelloWorldClientIT.java | 12 +- .../it/state/HelloWorldGrpcStateService.java | 2 +- .../java/io/dapr/client/DaprClientImpl.java | 466 +++---- .../java/io/dapr/client/Subscription.java | 24 +- .../EventSubscriberStreamObserver.java | 143 +-- .../client/DaprClientGrpcTelemetryTest.java | 10 +- .../io/dapr/client/DaprClientGrpcTest.java | 1104 ++++++++--------- .../io/dapr/client/DaprExceptionTest.java | 7 +- .../client/DaprPreviewClientGrpcTest.java | 423 ++++--- .../EventSubscriberStreamObserverTest.java | 76 +- 15 files changed, 1246 insertions(+), 1238 deletions(-) diff --git a/pom.xml b/pom.xml index faa95322a2..3cf40985ef 100644 --- a/pom.xml +++ b/pom.xml @@ -16,8 +16,7 @@ UTF-8 1.69.0 3.25.5 - https://raw.githubusercontent.com/javier-aliaga/dapr/fix-dapr-proto-java-class/dapr/proto - + https://raw.githubusercontent.com/dapr/dapr/release-1.17/dapr/proto https://raw.githubusercontent.com/dapr/durabletask-protobuf/main/protos/orchestrator_service.proto 1.17.0-SNAPSHOT 1.7.1 diff --git a/sdk-actors/src/main/java/io/dapr/actors/client/DaprClientImpl.java b/sdk-actors/src/main/java/io/dapr/actors/client/DaprClientImpl.java index 30ea4616c9..4e0fdfac4d 100644 --- a/sdk-actors/src/main/java/io/dapr/actors/client/DaprClientImpl.java +++ b/sdk-actors/src/main/java/io/dapr/actors/client/DaprClientImpl.java @@ -15,24 +15,15 @@ import com.google.protobuf.ByteString; import io.dapr.client.resiliency.ResiliencyOptions; -import io.dapr.config.Properties; import io.dapr.exceptions.DaprException; import io.dapr.internal.grpc.DaprClientGrpcInterceptors; import io.dapr.internal.resiliency.RetryPolicy; import io.dapr.internal.resiliency.TimeoutPolicy; +import io.dapr.v1.DaprActorsProtos; import io.dapr.v1.DaprGrpc; -import io.dapr.v1.DaprProtos; -import io.grpc.CallOptions; -import io.grpc.Channel; -import io.grpc.ClientCall; -import io.grpc.ClientInterceptor; -import io.grpc.ForwardingClientCall; -import io.grpc.Metadata; -import io.grpc.MethodDescriptor; import io.grpc.stub.StreamObserver; import reactor.core.publisher.Mono; import reactor.core.publisher.MonoSink; -import reactor.util.context.ContextView; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -89,8 +80,8 @@ class DaprClientImpl implements DaprClient { */ @Override public Mono invoke(String actorType, String actorId, String methodName, byte[] jsonPayload) { - DaprProtos.InvokeActorRequest req = - DaprProtos.InvokeActorRequest.newBuilder() + DaprActorsProtos.InvokeActorRequest req = + DaprActorsProtos.InvokeActorRequest.newBuilder() .setActorType(actorType) .setActorId(actorId) .setMethod(methodName) @@ -98,7 +89,7 @@ public Mono invoke(String actorType, String actorId, String methodName, .setData(jsonPayload == null ? ByteString.EMPTY : ByteString.copyFrom(jsonPayload)) .build(); return Mono.deferContextual( - context -> this.createMono( + context -> this.createMono( it -> this.grpcInterceptors.intercept(client, context).invokeActor(req, it) ) ).map(r -> r.getData().toByteArray()); diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/DaprClientImpl.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/DaprClientImpl.java index a14d7e257a..6dfef68585 100644 --- a/sdk-actors/src/main/java/io/dapr/actors/runtime/DaprClientImpl.java +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/DaprClientImpl.java @@ -20,8 +20,8 @@ import io.dapr.config.Properties; import io.dapr.exceptions.DaprException; import io.dapr.utils.DurationUtils; +import io.dapr.v1.DaprActorsProtos; import io.dapr.v1.DaprGrpc; -import io.dapr.v1.DaprProtos; import io.grpc.ManagedChannel; import io.grpc.stub.StreamObserver; import reactor.core.publisher.Mono; @@ -78,14 +78,14 @@ class DaprClientImpl implements DaprClient { */ @Override public Mono getState(String actorType, String actorId, String keyName) { - DaprProtos.GetActorStateRequest req = - DaprProtos.GetActorStateRequest.newBuilder() + DaprActorsProtos.GetActorStateRequest req = + DaprActorsProtos.GetActorStateRequest.newBuilder() .setActorType(actorType) .setActorId(actorId) .setKey(keyName) .build(); - return Mono.create(it -> + return Mono.create(it -> client.getActorState(req, createStreamObserver(it))).map(r -> r.getData().toByteArray()); } @@ -97,13 +97,13 @@ public Mono saveStateTransactionally( String actorType, String actorId, List operations) { - List grpcOps = new ArrayList<>(); + List grpcOps = new ArrayList<>(); for (ActorStateOperation op : operations) { String operationType = op.getOperationType(); String key = op.getKey(); Object value = op.getValue(); - DaprProtos.TransactionalActorStateOperation.Builder opBuilder = - DaprProtos.TransactionalActorStateOperation.newBuilder() + DaprActorsProtos.TransactionalActorStateOperation.Builder opBuilder = + DaprActorsProtos.TransactionalActorStateOperation.newBuilder() .setOperationType(operationType) .setKey(key); if (value != null) { @@ -126,8 +126,8 @@ public Mono saveStateTransactionally( grpcOps.add(opBuilder.build()); } - DaprProtos.ExecuteActorStateTransactionRequest req = - DaprProtos.ExecuteActorStateTransactionRequest.newBuilder() + DaprActorsProtos.ExecuteActorStateTransactionRequest req = + DaprActorsProtos.ExecuteActorStateTransactionRequest.newBuilder() .setActorType(actorType) .setActorId(actorId) .addAllOperations(grpcOps) @@ -145,8 +145,8 @@ public Mono registerReminder( String actorId, String reminderName, ActorReminderParams reminderParams) { - DaprProtos.RegisterActorReminderRequest req = - DaprProtos.RegisterActorReminderRequest.newBuilder() + DaprActorsProtos.RegisterActorReminderRequest req = + DaprActorsProtos.RegisterActorReminderRequest.newBuilder() .setActorType(actorType) .setActorId(actorId) .setName(reminderName) @@ -162,8 +162,8 @@ public Mono registerReminder( */ @Override public Mono unregisterReminder(String actorType, String actorId, String reminderName) { - DaprProtos.UnregisterActorReminderRequest req = - DaprProtos.UnregisterActorReminderRequest.newBuilder() + DaprActorsProtos.UnregisterActorReminderRequest req = + DaprActorsProtos.UnregisterActorReminderRequest.newBuilder() .setActorType(actorType) .setActorId(actorId) .setName(reminderName) @@ -181,8 +181,8 @@ public Mono registerTimer( String actorId, String timerName, ActorTimerParams timerParams) { - DaprProtos.RegisterActorTimerRequest req = - DaprProtos.RegisterActorTimerRequest.newBuilder() + DaprActorsProtos.RegisterActorTimerRequest req = + DaprActorsProtos.RegisterActorTimerRequest.newBuilder() .setActorType(actorType) .setActorId(actorId) .setName(timerName) @@ -200,8 +200,8 @@ public Mono registerTimer( */ @Override public Mono unregisterTimer(String actorType, String actorId, String timerName) { - DaprProtos.UnregisterActorTimerRequest req = - DaprProtos.UnregisterActorTimerRequest.newBuilder() + DaprActorsProtos.UnregisterActorTimerRequest req = + DaprActorsProtos.UnregisterActorTimerRequest.newBuilder() .setActorType(actorType) .setActorId(actorId) .setName(timerName) diff --git a/sdk-actors/src/test/java/io/dapr/actors/client/DaprGrpcClientTest.java b/sdk-actors/src/test/java/io/dapr/actors/client/DaprGrpcClientTest.java index 1f05e7ac6c..e2f75a2b41 100644 --- a/sdk-actors/src/test/java/io/dapr/actors/client/DaprGrpcClientTest.java +++ b/sdk-actors/src/test/java/io/dapr/actors/client/DaprGrpcClientTest.java @@ -14,8 +14,8 @@ package io.dapr.actors.client; import com.google.protobuf.ByteString; +import io.dapr.v1.DaprActorsProtos; import io.dapr.v1.DaprGrpc; -import io.dapr.v1.DaprProtos; import io.grpc.ManagedChannel; import io.grpc.Status; import io.grpc.StatusException; @@ -60,22 +60,22 @@ public class DaprGrpcClientTest { mock(DaprGrpc.DaprImplBase.class, delegatesTo( new DaprGrpc.DaprImplBase() { @Override - public void invokeActor(DaprProtos.InvokeActorRequest request, - StreamObserver responseObserver) { + public void invokeActor(DaprActorsProtos.InvokeActorRequest request, + StreamObserver responseObserver) { assertEquals(ACTOR_TYPE, request.getActorType()); assertEquals(METHOD_NAME, request.getMethod()); switch (request.getActorId()) { case ACTOR_ID_OK: assertArrayEquals(REQUEST_PAYLOAD, request.getData().toByteArray()); responseObserver.onNext( - DaprProtos.InvokeActorResponse.newBuilder().setData(ByteString.copyFrom(RESPONSE_PAYLOAD)) + DaprActorsProtos.InvokeActorResponse.newBuilder().setData(ByteString.copyFrom(RESPONSE_PAYLOAD)) .build()); responseObserver.onCompleted(); return; case ACTOR_ID_NULL_INPUT: assertArrayEquals(new byte[0], request.getData().toByteArray()); responseObserver.onNext( - DaprProtos.InvokeActorResponse.newBuilder().setData(ByteString.copyFrom(RESPONSE_PAYLOAD)) + DaprActorsProtos.InvokeActorResponse.newBuilder().setData(ByteString.copyFrom(RESPONSE_PAYLOAD)) .build()); responseObserver.onCompleted(); return; diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/DaprGrpcClientTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/DaprGrpcClientTest.java index 7f006df1ec..425ba64589 100644 --- a/sdk-actors/src/test/java/io/dapr/actors/runtime/DaprGrpcClientTest.java +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/DaprGrpcClientTest.java @@ -17,9 +17,8 @@ import com.google.protobuf.Any; import com.google.protobuf.ByteString; import com.google.protobuf.Empty; -import com.google.protobuf.GeneratedMessageV3; +import io.dapr.v1.DaprActorsProtos; import io.dapr.v1.DaprGrpc; -import io.dapr.v1.DaprProtos; import io.grpc.ManagedChannel; import io.grpc.Status; import io.grpc.StatusException; @@ -178,17 +177,83 @@ public void unregisterActorTimer() { } - private class CustomDaprClient extends DaprGrpc.DaprImplBase { + private static class OperationsMatcher { + + private final List operations; + + OperationsMatcher(List operations) { + this.operations = operations; + } + + private static boolean nullableEquals(Object one, Any another) { + if (one == null) { + return another.getValue().isEmpty(); + } + + if ((one == null) ^ (another == null)) { + return false; + } + + try { + Any oneAny = getAny(one); + return oneAny.getValue().equals(another.getValue()); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } + + private static Any getAny(Object value) throws IOException { + if (value instanceof byte[]) { + String base64 = OBJECT_MAPPER.writeValueAsString(value); + return Any.newBuilder().setValue(ByteString.copyFrom(base64.getBytes())).build(); + } else if (value instanceof String) { + return Any.newBuilder().setValue(ByteString.copyFrom(((String) value).getBytes())).build(); + } + + throw new IllegalArgumentException("Must be byte[] or String"); + } + + public boolean matches(DaprActorsProtos.ExecuteActorStateTransactionRequest argument) { + if (argument == null) { + return false; + } + + if (operations.size() != argument.getOperationsCount()) { + return false; + } + + for (ActorStateOperation operation : operations) { + boolean found = false; + for (DaprActorsProtos.TransactionalActorStateOperation grpcOperation : argument.getOperationsList()) { + if (operation.getKey().equals(grpcOperation.getKey()) + && operation.getOperationType().equals(grpcOperation.getOperationType()) + && nullableEquals(operation.getValue(), grpcOperation.getValue())) { + found = true; + break; + } + } + + if (!found) { + return false; + } + } + + return true; + } + } + + private class CustomDaprClient extends DaprGrpc.DaprImplBase { @Override - public void getActorState(DaprProtos.GetActorStateRequest request, - StreamObserver responseObserver) { + public void getActorState(DaprActorsProtos.GetActorStateRequest request, + StreamObserver responseObserver) { assertEquals(ACTOR_TYPE, request.getActorType()); assertEquals(KEY, request.getKey()); assertEquals(ACTOR_ID, request.getActorId()); switch (request.getActorId()) { case ACTOR_ID: - populateObserver(responseObserver, DaprProtos.GetActorStateResponse.newBuilder().setData(ByteString.copyFrom(RESPONSE_PAYLOAD)) + populateObserver(responseObserver, DaprActorsProtos.GetActorStateResponse.newBuilder().setData(ByteString.copyFrom(RESPONSE_PAYLOAD)) .build()); return; @@ -199,7 +264,7 @@ public void getActorState(DaprProtos.GetActorStateRequest request, super.getActorState(request, responseObserver); } - public void executeActorStateTransaction(io.dapr.v1.DaprProtos.ExecuteActorStateTransactionRequest request, + public void executeActorStateTransaction(DaprActorsProtos.ExecuteActorStateTransactionRequest request, io.grpc.stub.StreamObserver responseObserver) { assertEquals(ACTOR_TYPE, request.getActorType()); assertEquals(ACTOR_ID, request.getActorId()); @@ -217,7 +282,7 @@ public void executeActorStateTransaction(io.dapr.v1.DaprProtos.ExecuteActorState } @Override - public void registerActorReminder(io.dapr.v1.DaprProtos.RegisterActorReminderRequest request, + public void registerActorReminder(DaprActorsProtos.RegisterActorReminderRequest request, io.grpc.stub.StreamObserver responseObserver) { assertEquals(REMINDER_NAME, request.getName()); assertEquals("0h0m1s0ms", request.getDueTime()); @@ -236,7 +301,7 @@ public void registerActorReminder(io.dapr.v1.DaprProtos.RegisterActorReminderReq super.registerActorReminder(request, responseObserver); } - public void registerActorTimer(io.dapr.v1.DaprProtos.RegisterActorTimerRequest request, + public void registerActorTimer(DaprActorsProtos.RegisterActorTimerRequest request, io.grpc.stub.StreamObserver responseObserver) { assertEquals(ACTOR_TYPE, request.getActorType()); assertEquals(ACTOR_ID, request.getActorId()); @@ -261,7 +326,7 @@ public void registerActorTimer(io.dapr.v1.DaprProtos.RegisterActorTimerRequest r * Unregister an actor timer. * */ - public void unregisterActorTimer(io.dapr.v1.DaprProtos.UnregisterActorTimerRequest request, + public void unregisterActorTimer(DaprActorsProtos.UnregisterActorTimerRequest request, io.grpc.stub.StreamObserver responseObserver) { assertEquals(ACTOR_TYPE, request.getActorType()); assertEquals(ACTOR_ID, request.getActorId()); @@ -278,7 +343,7 @@ public void unregisterActorTimer(io.dapr.v1.DaprProtos.UnregisterActorTimerReque super.unregisterActorTimer(request, responseObserver); } - public void unregisterActorReminder(io.dapr.v1.DaprProtos.UnregisterActorReminderRequest request, + public void unregisterActorReminder(DaprActorsProtos.UnregisterActorReminderRequest request, io.grpc.stub.StreamObserver responseObserver) { assertEquals(ACTOR_TYPE, request.getActorType()); assertEquals(ACTOR_ID, request.getActorId()); @@ -306,70 +371,4 @@ private void populateObserver(StreamObse responseObserver.onCompleted(); } } - - private static class OperationsMatcher { - - private final List operations; - - OperationsMatcher(List operations) { - this.operations = operations; - } - - public boolean matches(DaprProtos.ExecuteActorStateTransactionRequest argument) { - if (argument == null) { - return false; - } - - if (operations.size() != argument.getOperationsCount()) { - return false; - } - - for (ActorStateOperation operation : operations) { - boolean found = false; - for (DaprProtos.TransactionalActorStateOperation grpcOperation : argument.getOperationsList()) { - if (operation.getKey().equals(grpcOperation.getKey()) - && operation.getOperationType().equals(grpcOperation.getOperationType()) - && nullableEquals(operation.getValue(), grpcOperation.getValue())) { - found = true; - break; - } - } - - if (!found) { - return false; - } - } - - return true; - } - - private static boolean nullableEquals(Object one, Any another) { - if (one == null) { - return another.getValue().isEmpty(); - } - - if ((one == null) ^ (another == null)) { - return false; - } - - try { - Any oneAny = getAny(one); - return oneAny.getValue().equals(another.getValue()); - } catch (IOException e) { - e.printStackTrace(); - return false; - } - } - - private static Any getAny(Object value) throws IOException { - if (value instanceof byte[]) { - String base64 = OBJECT_MAPPER.writeValueAsString(value); - return Any.newBuilder().setValue(ByteString.copyFrom(base64.getBytes())).build(); - } else if (value instanceof String) { - return Any.newBuilder().setValue(ByteString.copyFrom(((String)value).getBytes())).build(); - } - - throw new IllegalArgumentException("Must be byte[] or String"); - } - } } diff --git a/sdk-tests/src/test/java/io/dapr/it/state/HelloWorldClientIT.java b/sdk-tests/src/test/java/io/dapr/it/state/HelloWorldClientIT.java index 713f152f15..bdd25ae780 100644 --- a/sdk-tests/src/test/java/io/dapr/it/state/HelloWorldClientIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/state/HelloWorldClientIT.java @@ -16,7 +16,7 @@ import io.dapr.it.BaseIT; import io.dapr.it.DaprRun; import io.dapr.v1.DaprGrpc; -import io.dapr.v1.DaprProtos; +import io.dapr.v1.DaprStateProtos; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -36,12 +36,12 @@ public void testHelloWorldState() throws Exception { String key = "mykey"; { - DaprProtos.GetStateRequest req = DaprProtos.GetStateRequest + DaprStateProtos.GetStateRequest req = DaprStateProtos.GetStateRequest .newBuilder() .setStoreName(STATE_STORE_NAME) .setKey(key) .build(); - DaprProtos.GetStateResponse response = stub.getState(req); + DaprStateProtos.GetStateResponse response = stub.getState(req); String value = response.getData().toStringUtf8(); System.out.println("Got: " + value); Assertions.assertEquals("Hello World", value); @@ -49,7 +49,7 @@ public void testHelloWorldState() throws Exception { // Then, delete it. { - DaprProtos.DeleteStateRequest req = DaprProtos.DeleteStateRequest + DaprStateProtos.DeleteStateRequest req = DaprStateProtos.DeleteStateRequest .newBuilder() .setStoreName(STATE_STORE_NAME) .setKey(key) @@ -59,12 +59,12 @@ public void testHelloWorldState() throws Exception { } { - DaprProtos.GetStateRequest req = DaprProtos.GetStateRequest + DaprStateProtos.GetStateRequest req = DaprStateProtos.GetStateRequest .newBuilder() .setStoreName(STATE_STORE_NAME) .setKey(key) .build(); - DaprProtos.GetStateResponse response = stub.getState(req); + DaprStateProtos.GetStateResponse response = stub.getState(req); String value = response.getData().toStringUtf8(); System.out.println("Got: " + value); Assertions.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 index be493b4697..abab918be7 100644 --- a/sdk-tests/src/test/java/io/dapr/it/state/HelloWorldGrpcStateService.java +++ b/sdk-tests/src/test/java/io/dapr/it/state/HelloWorldGrpcStateService.java @@ -20,7 +20,7 @@ import io.dapr.v1.CommonProtos.StateItem; import io.dapr.v1.DaprGrpc; import io.dapr.v1.DaprGrpc.DaprBlockingStub; -import io.dapr.v1.DaprProtos.SaveStateRequest; +import io.dapr.v1.DaprStateProtos.SaveStateRequest; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; diff --git a/sdk/src/main/java/io/dapr/client/DaprClientImpl.java b/sdk/src/main/java/io/dapr/client/DaprClientImpl.java index 05b555b5e9..c32f8789ea 100644 --- a/sdk/src/main/java/io/dapr/client/DaprClientImpl.java +++ b/sdk/src/main/java/io/dapr/client/DaprClientImpl.java @@ -99,16 +99,18 @@ import io.dapr.utils.DefaultContentTypeConverter; import io.dapr.utils.TypeRef; import io.dapr.v1.CommonProtos; +import io.dapr.v1.DaprAiProtos; +import io.dapr.v1.DaprBindingsProtos; +import io.dapr.v1.DaprConfigurationProtos; +import io.dapr.v1.DaprCryptoProtos; import io.dapr.v1.DaprGrpc; +import io.dapr.v1.DaprJobsProtos; +import io.dapr.v1.DaprLockProtos; +import io.dapr.v1.DaprMetadataProtos; import io.dapr.v1.DaprProtos; -import io.dapr.v1.DaprProtos.ActiveActorsCount; -import io.dapr.v1.DaprProtos.ActorRuntime; -import io.dapr.v1.DaprProtos.AppConnectionHealthProperties; -import io.dapr.v1.DaprProtos.AppConnectionProperties; -import io.dapr.v1.DaprProtos.MetadataHTTPEndpoint; -import io.dapr.v1.DaprProtos.PubsubSubscription; -import io.dapr.v1.DaprProtos.PubsubSubscriptionRule; -import io.dapr.v1.DaprProtos.RegisteredComponents; +import io.dapr.v1.DaprPubsubProtos; +import io.dapr.v1.DaprSecretProtos; +import io.dapr.v1.DaprStateProtos; import io.grpc.Channel; import io.grpc.Metadata; import io.grpc.stub.AbstractStub; @@ -313,7 +315,7 @@ public > T newGrpcStub(String appId, Function waitForSidecar(int timeoutInMilliseconds) { - String[] pathSegments = new String[] { DaprHttp.API_VERSION, "healthz", "outbound"}; + String[] pathSegments = new String[]{DaprHttp.API_VERSION, "healthz", "outbound"}; // Do the Dapr Http endpoint check to have parity with Dotnet Mono responseMono = this.httpClient.invokeApi(DaprHttp.HttpMethods.GET.name(), pathSegments, @@ -345,7 +347,7 @@ public Mono publishEvent(PublishEventRequest request) { String pubsubName = request.getPubsubName(); String topic = request.getTopic(); Object data = request.getData(); - DaprProtos.PublishEventRequest.Builder envelopeBuilder = DaprProtos.PublishEventRequest.newBuilder() + DaprPubsubProtos.PublishEventRequest.Builder envelopeBuilder = DaprPubsubProtos.PublishEventRequest.newBuilder() .setTopic(topic) .setPubsubName(pubsubName) .setData(ByteString.copyFrom(objectSerializer.serialize(data))); @@ -382,7 +384,7 @@ public Mono> publishEvents(BulkPublishRequest requ try { String pubsubName = request.getPubsubName(); String topic = request.getTopic(); - DaprProtos.BulkPublishRequest.Builder envelopeBuilder = DaprProtos.BulkPublishRequest.newBuilder(); + DaprPubsubProtos.BulkPublishRequest.Builder envelopeBuilder = DaprPubsubProtos.BulkPublishRequest.newBuilder(); envelopeBuilder.setTopic(topic); envelopeBuilder.setPubsubName(pubsubName); @@ -414,10 +416,11 @@ public Mono> publishEvents(BulkPublishRequest requ throw DaprException.propagate(ex); } - DaprProtos.BulkPublishRequestEntry.Builder reqEntryBuilder = DaprProtos.BulkPublishRequestEntry.newBuilder() - .setEntryId(entry.getEntryId()) - .setEvent(ByteString.copyFrom(data)) - .setContentType(contentType); + DaprPubsubProtos.BulkPublishRequestEntry.Builder reqEntryBuilder = + DaprPubsubProtos.BulkPublishRequestEntry.newBuilder() + .setEntryId(entry.getEntryId()) + .setEvent(ByteString.copyFrom(data)) + .setContentType(contentType); Map metadata = entry.getMetadata(); if (metadata != null) { reqEntryBuilder.putAllMetadata(metadata); @@ -437,13 +440,14 @@ public Mono> publishEvents(BulkPublishRequest requ } return Mono.deferContextual( context -> - this.createMono( - it -> intercept(context, asyncStub).bulkPublishEventAlpha1(envelopeBuilder.build(), it) + this.createMono( + it -> + intercept(context, asyncStub).bulkPublishEventAlpha1(envelopeBuilder.build(), it) ) ).map( it -> { List> entries = new ArrayList<>(); - for (DaprProtos.BulkPublishResponseFailedEntry entry : it.getFailedEntriesList()) { + for (DaprPubsubProtos.BulkPublishResponseFailedEntry entry : it.getFailedEntriesList()) { BulkPublishResponseFailedEntry domainEntry = new BulkPublishResponseFailedEntry( entryMap.get(entry.getEntryId()), entry.getError()); @@ -466,13 +470,13 @@ public Mono> publishEvents(BulkPublishRequest requ @Override public Subscription subscribeToEvents( String pubsubName, String topic, SubscriptionListener listener, TypeRef type) { - DaprProtos.SubscribeTopicEventsRequestInitialAlpha1 initialRequest = - DaprProtos.SubscribeTopicEventsRequestInitialAlpha1.newBuilder() + DaprPubsubProtos.SubscribeTopicEventsRequestInitialAlpha1 initialRequest = + DaprPubsubProtos.SubscribeTopicEventsRequestInitialAlpha1.newBuilder() .setTopic(topic) .setPubsubName(pubsubName) .build(); - DaprProtos.SubscribeTopicEventsRequestAlpha1 request = - DaprProtos.SubscribeTopicEventsRequestAlpha1.newBuilder() + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 request = + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1.newBuilder() .setInitialRequest(initialRequest) .build(); return buildSubscription(listener, type, request); @@ -483,13 +487,13 @@ public Subscription subscribeToEvents( */ @Override public Flux> subscribeToEvents(String pubsubName, String topic, TypeRef type) { - DaprProtos.SubscribeTopicEventsRequestInitialAlpha1 initialRequest = - DaprProtos.SubscribeTopicEventsRequestInitialAlpha1.newBuilder() + DaprPubsubProtos.SubscribeTopicEventsRequestInitialAlpha1 initialRequest = + DaprPubsubProtos.SubscribeTopicEventsRequestInitialAlpha1.newBuilder() .setTopic(topic) .setPubsubName(pubsubName) .build(); - DaprProtos.SubscribeTopicEventsRequestAlpha1 request = - DaprProtos.SubscribeTopicEventsRequestAlpha1.newBuilder() + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 request = + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1.newBuilder() .setInitialRequest(initialRequest) .build(); @@ -501,7 +505,7 @@ public Flux> subscribeToEvents(String pubsubName, String topic type, this.objectSerializer ); - StreamObserver requestStream = eventSubscriber.start(request); + StreamObserver requestStream = eventSubscriber.start(request); // Cleanup when Flux is cancelled or completed sink.onDispose(() -> { @@ -518,36 +522,37 @@ public Flux> subscribeToEvents(String pubsubName, String topic private Subscription buildSubscription( SubscriptionListener listener, TypeRef type, - DaprProtos.SubscribeTopicEventsRequestAlpha1 request) { + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 request) { var interceptedStub = this.grpcInterceptors.intercept(this.asyncStub); - Subscription subscription = new Subscription<>(interceptedStub, request, listener, response -> { - if (response.getEventMessage() == null) { - return null; - } + Subscription subscription = + new Subscription<>(interceptedStub, request, listener, response -> { + if (response.getEventMessage() == null) { + return null; + } - var message = response.getEventMessage(); - if ((message.getPubsubName() == null) || message.getPubsubName().isEmpty()) { - return null; - } + var message = response.getEventMessage(); + if ((message.getPubsubName() == null) || message.getPubsubName().isEmpty()) { + return null; + } - try { - CloudEvent cloudEvent = new CloudEvent<>(); - T object = null; - if (type != null) { - object = DaprClientImpl.this.objectSerializer.deserialize(message.getData().toByteArray(), type); - } - cloudEvent.setData(object); - cloudEvent.setDatacontenttype(message.getDataContentType()); - cloudEvent.setId(message.getId()); - cloudEvent.setTopic(message.getTopic()); - cloudEvent.setSpecversion(message.getSpecVersion()); - cloudEvent.setType(message.getType()); - cloudEvent.setPubsubName(message.getPubsubName()); - return cloudEvent; - } catch (IOException e) { - throw new RuntimeException(e); - } - }); + try { + CloudEvent cloudEvent = new CloudEvent<>(); + T object = null; + if (type != null) { + object = DaprClientImpl.this.objectSerializer.deserialize(message.getData().toByteArray(), type); + } + cloudEvent.setData(object); + cloudEvent.setDatacontenttype(message.getDataContentType()); + cloudEvent.setId(message.getId()); + cloudEvent.setTopic(message.getTopic()); + cloudEvent.setSpecversion(message.getSpecVersion()); + cloudEvent.setType(message.getType()); + cloudEvent.setPubsubName(message.getPubsubName()); + return cloudEvent; + } catch (IOException e) { + throw new RuntimeException(e); + } + }); subscription.start(); return subscription; } @@ -637,7 +642,7 @@ public Mono invokeBinding(InvokeBindingRequest request, TypeRef type) } byte[] byteData = objectSerializer.serialize(data); - DaprProtos.InvokeBindingRequest.Builder builder = DaprProtos.InvokeBindingRequest.newBuilder() + DaprBindingsProtos.InvokeBindingRequest.Builder builder = DaprBindingsProtos.InvokeBindingRequest.newBuilder() .setName(name).setOperation(operation); if (byteData != null) { builder.setData(ByteString.copyFrom(byteData)); @@ -645,13 +650,14 @@ public Mono invokeBinding(InvokeBindingRequest request, TypeRef type) if (metadata != null) { builder.putAllMetadata(metadata); } - DaprProtos.InvokeBindingRequest envelope = builder.build(); + DaprBindingsProtos.InvokeBindingRequest envelope = builder.build(); Metadata responseMetadata = new Metadata(); return Mono.deferContextual( - context -> this.createMono( + context -> this.createMono( responseMetadata, - it -> intercept(context, asyncStub, m -> responseMetadata.merge(m)).invokeBinding(envelope, it) + it -> + intercept(context, asyncStub, m -> responseMetadata.merge(m)).invokeBinding(envelope, it) ) ).flatMap( it -> { @@ -695,7 +701,7 @@ public Mono> getState(GetStateRequest request, TypeRef type) { if ((key == null) || (key.trim().isEmpty())) { throw new IllegalArgumentException("Key cannot be null or empty."); } - DaprProtos.GetStateRequest.Builder builder = DaprProtos.GetStateRequest.newBuilder() + DaprStateProtos.GetStateRequest.Builder builder = DaprStateProtos.GetStateRequest.newBuilder() .setStoreName(stateStoreName) .setKey(key); if (metadata != null) { @@ -705,11 +711,11 @@ public Mono> getState(GetStateRequest request, TypeRef type) { builder.setConsistency(getGrpcStateConsistency(options)); } - DaprProtos.GetStateRequest envelope = builder.build(); + DaprStateProtos.GetStateRequest envelope = builder.build(); return Mono.deferContextual( context -> - this.createMono( + this.createMono( it -> intercept(context, asyncStub).getState(envelope, it) ) ).map( @@ -746,7 +752,7 @@ public Mono>> getBulkState(GetBulkStateRequest request, TypeRe if (parallelism < 0) { throw new IllegalArgumentException("Parallelism cannot be negative."); } - DaprProtos.GetBulkStateRequest.Builder builder = DaprProtos.GetBulkStateRequest.newBuilder() + DaprStateProtos.GetBulkStateRequest.Builder builder = DaprStateProtos.GetBulkStateRequest.newBuilder() .setStoreName(stateStoreName) .addAllKeys(keys) .setParallelism(parallelism); @@ -754,10 +760,10 @@ public Mono>> getBulkState(GetBulkStateRequest request, TypeRe builder.putAllMetadata(metadata); } - DaprProtos.GetBulkStateRequest envelope = builder.build(); + DaprStateProtos.GetBulkStateRequest envelope = builder.build(); return Mono.deferContextual( - context -> this.createMono(it -> intercept(context, asyncStub) + context -> this.createMono(it -> intercept(context, asyncStub) .getBulkState(envelope, it) ) ).map( @@ -780,7 +786,7 @@ public Mono>> getBulkState(GetBulkStateRequest request, TypeRe } private State buildStateKeyValue( - DaprProtos.BulkStateItem item, + DaprStateProtos.BulkStateItem item, TypeRef type) throws IOException { String key = item.getKey(); String error = item.getError(); @@ -804,7 +810,7 @@ private State buildStateKeyValue( } private State buildStateKeyValue( - DaprProtos.GetStateResponse response, + DaprStateProtos.GetStateResponse response, String requestedKey, StateOptions stateOptions, TypeRef type) throws IOException { @@ -834,20 +840,20 @@ public Mono executeStateTransaction(ExecuteStateTransactionRequest request if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) { throw new IllegalArgumentException("State store name cannot be null or empty."); } - DaprProtos.ExecuteStateTransactionRequest.Builder builder = DaprProtos.ExecuteStateTransactionRequest + DaprStateProtos.ExecuteStateTransactionRequest.Builder builder = DaprStateProtos.ExecuteStateTransactionRequest .newBuilder(); builder.setStoreName(stateStoreName); if (metadata != null) { builder.putAllMetadata(metadata); } for (TransactionalStateOperation operation : operations) { - DaprProtos.TransactionalStateOperation.Builder operationBuilder = DaprProtos.TransactionalStateOperation - .newBuilder(); + DaprStateProtos.TransactionalStateOperation.Builder operationBuilder = + DaprStateProtos.TransactionalStateOperation.newBuilder(); operationBuilder.setOperationType(operation.getOperation().toString().toLowerCase()); operationBuilder.setRequest(buildStateRequest(operation.getRequest()).build()); builder.addOperations(operationBuilder.build()); } - DaprProtos.ExecuteStateTransactionRequest req = builder.build(); + DaprStateProtos.ExecuteStateTransactionRequest req = builder.build(); return Mono.deferContextual( context -> this.createMono(it -> intercept(context, asyncStub).executeStateTransaction(req, it)) @@ -868,12 +874,12 @@ public Mono saveBulkState(SaveStateRequest request) { if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) { throw new IllegalArgumentException("State store name cannot be null or empty."); } - DaprProtos.SaveStateRequest.Builder builder = DaprProtos.SaveStateRequest.newBuilder(); + DaprStateProtos.SaveStateRequest.Builder builder = DaprStateProtos.SaveStateRequest.newBuilder(); builder.setStoreName(stateStoreName); for (State state : states) { builder.addStates(buildStateRequest(state).build()); } - DaprProtos.SaveStateRequest req = builder.build(); + DaprStateProtos.SaveStateRequest req = builder.build(); return Mono.deferContextual( context -> this.createMono(it -> intercept(context, asyncStub).saveState(req, it)) @@ -943,7 +949,7 @@ public Mono deleteState(DeleteStateRequest request) { optionBuilder.setConsistency(getGrpcStateConsistency(options)); } } - DaprProtos.DeleteStateRequest.Builder builder = DaprProtos.DeleteStateRequest.newBuilder() + DaprStateProtos.DeleteStateRequest.Builder builder = DaprStateProtos.DeleteStateRequest.newBuilder() .setStoreName(stateStoreName) .setKey(key); if (metadata != null) { @@ -957,7 +963,7 @@ public Mono deleteState(DeleteStateRequest request) { builder.setOptions(optionBuilder.build()); } - DaprProtos.DeleteStateRequest req = builder.build(); + DaprStateProtos.DeleteStateRequest req = builder.build(); return Mono.deferContextual( context -> this.createMono(it -> intercept(context, asyncStub).deleteState(req, it)) @@ -986,18 +992,20 @@ public Mono> getSecret(GetSecretRequest request) { return DaprException.wrapMono(e); } - DaprProtos.GetSecretRequest.Builder requestBuilder = DaprProtos.GetSecretRequest.newBuilder() + DaprSecretProtos.GetSecretRequest.Builder requestBuilder = DaprSecretProtos.GetSecretRequest.newBuilder() .setStoreName(secretStoreName) .setKey(key); if (metadata != null) { requestBuilder.putAllMetadata(metadata); } - DaprProtos.GetSecretRequest req = requestBuilder.build(); + DaprSecretProtos.GetSecretRequest req = requestBuilder.build(); return Mono.deferContextual( - context -> this.createMono(it -> intercept(context, asyncStub).getSecret(req, it)) - ).map(DaprProtos.GetSecretResponse::getDataMap); + context -> + this.createMono( + it -> intercept(context, asyncStub).getSecret(req, it)) + ).map(DaprSecretProtos.GetSecretResponse::getDataMap); } /** @@ -1012,21 +1020,21 @@ public Mono>> getBulkSecret(GetBulkSecretRequest throw new IllegalArgumentException("Secret store name cannot be null or empty."); } - DaprProtos.GetBulkSecretRequest.Builder builder = DaprProtos.GetBulkSecretRequest.newBuilder() + DaprSecretProtos.GetBulkSecretRequest.Builder builder = DaprSecretProtos.GetBulkSecretRequest.newBuilder() .setStoreName(storeName); if (metadata != null) { builder.putAllMetadata(metadata); } - DaprProtos.GetBulkSecretRequest envelope = builder.build(); + DaprSecretProtos.GetBulkSecretRequest envelope = builder.build(); return Mono.deferContextual( context -> - this.createMono( + this.createMono( it -> intercept(context, asyncStub).getBulkSecret(envelope, it) ) ).map(it -> { - Map secretsMap = it.getDataMap(); + Map secretsMap = it.getDataMap(); if (secretsMap == null) { return Collections.emptyMap(); } @@ -1064,18 +1072,18 @@ public Mono tryLock(LockRequest request) { throw new IllegalArgumentException("ExpiryInSeconds cannot be negative."); } - DaprProtos.TryLockRequest.Builder builder = DaprProtos.TryLockRequest.newBuilder() - .setStoreName(stateStoreName) - .setResourceId(resourceId) - .setLockOwner(lockOwner) - .setExpiryInSeconds(expiryInSeconds); + DaprLockProtos.TryLockRequest.Builder builder = DaprLockProtos.TryLockRequest.newBuilder() + .setStoreName(stateStoreName) + .setResourceId(resourceId) + .setLockOwner(lockOwner) + .setExpiryInSeconds(expiryInSeconds); - DaprProtos.TryLockRequest tryLockRequest = builder.build(); + DaprLockProtos.TryLockRequest tryLockRequest = builder.build(); return Mono.deferContextual( - context -> this.createMono( - it -> intercept(context, asyncStub).tryLockAlpha1(tryLockRequest, it) - ) + context -> this.createMono( + it -> intercept(context, asyncStub).tryLockAlpha1(tryLockRequest, it) + ) ).flatMap(response -> { try { return Mono.just(response.getSuccess()); @@ -1108,17 +1116,17 @@ public Mono unlock(UnlockRequest request) { throw new IllegalArgumentException("LockOwner cannot be null or empty."); } - DaprProtos.UnlockRequest.Builder builder = DaprProtos.UnlockRequest.newBuilder() - .setStoreName(stateStoreName) - .setResourceId(resourceId) - .setLockOwner(lockOwner); + DaprLockProtos.UnlockRequest.Builder builder = DaprLockProtos.UnlockRequest.newBuilder() + .setStoreName(stateStoreName) + .setResourceId(resourceId) + .setLockOwner(lockOwner); - DaprProtos.UnlockRequest unlockRequest = builder.build(); + DaprLockProtos.UnlockRequest unlockRequest = builder.build(); return Mono.deferContextual( - context -> this.createMono( - it -> intercept(context, asyncStub).unlockAlpha1(unlockRequest, it) - ) + context -> this.createMono( + it -> intercept(context, asyncStub).unlockAlpha1(unlockRequest, it) + ) ).flatMap(response -> { try { return Mono.just(UnlockResponseStatus.valueOf(response.getStatus().getNumber())); @@ -1155,17 +1163,17 @@ public Mono> queryState(QueryStateRequest request, Typ throw new IllegalArgumentException("Both query and queryString fields are not set."); } - DaprProtos.QueryStateRequest.Builder builder = DaprProtos.QueryStateRequest.newBuilder() + DaprStateProtos.QueryStateRequest.Builder builder = DaprStateProtos.QueryStateRequest.newBuilder() .setStoreName(storeName) .setQuery(queryString); if (metadata != null) { builder.putAllMetadata(metadata); } - DaprProtos.QueryStateRequest envelope = builder.build(); + DaprStateProtos.QueryStateRequest envelope = builder.build(); return Mono.deferContextual( - context -> this.createMono( + context -> this.createMono( it -> intercept(context, asyncStub).queryStateAlpha1(envelope, it) ) ).map( @@ -1190,7 +1198,7 @@ public Mono> queryState(QueryStateRequest request, Typ } private QueryStateItem buildQueryStateKeyValue( - DaprProtos.QueryStateItem item, + DaprStateProtos.QueryStateItem item, TypeRef type) throws IOException { String key = item.getKey(); String error = item.getError(); @@ -1255,13 +1263,14 @@ public Mono> getConfiguration(GetConfigurationReq throw new IllegalArgumentException("Configuration Store Name cannot be null or empty."); } - DaprProtos.GetConfigurationRequest.Builder builder = DaprProtos.GetConfigurationRequest.newBuilder() + DaprConfigurationProtos.GetConfigurationRequest.Builder builder = + DaprConfigurationProtos.GetConfigurationRequest.newBuilder() .setStoreName(configurationStoreName).addAllKeys(keys); if (metadata != null) { builder.putAllMetadata(metadata); } - DaprProtos.GetConfigurationRequest envelope = builder.build(); + DaprConfigurationProtos.GetConfigurationRequest envelope = builder.build(); return this.getConfiguration(envelope); } catch (Exception ex) { @@ -1269,10 +1278,11 @@ public Mono> getConfiguration(GetConfigurationReq } } - private Mono> getConfiguration(DaprProtos.GetConfigurationRequest envelope) { + private Mono> getConfiguration( + DaprConfigurationProtos.GetConfigurationRequest envelope) { return Mono.deferContextual( context -> - this.createMono( + this.createMono( it -> intercept(context, asyncStub).getConfiguration(envelope, it) ) ).map( @@ -1303,7 +1313,8 @@ public Flux subscribeConfiguration(SubscribeConf } // keys can and empty list for subscribe all scenario, so we do not need check for empty keys. - DaprProtos.SubscribeConfigurationRequest.Builder builder = DaprProtos.SubscribeConfigurationRequest.newBuilder() + DaprConfigurationProtos.SubscribeConfigurationRequest.Builder builder = + DaprConfigurationProtos.SubscribeConfigurationRequest.newBuilder() .setStoreName(configurationStoreName) .addAllKeys(keys); @@ -1311,9 +1322,10 @@ public Flux subscribeConfiguration(SubscribeConf builder.putAllMetadata(metadata); } - DaprProtos.SubscribeConfigurationRequest envelope = builder.build(); - return this.createFlux( - it -> intercept(null, asyncStub).subscribeConfiguration(envelope, it) + DaprConfigurationProtos.SubscribeConfigurationRequest envelope = builder.build(); + return this.createFlux( + it -> + intercept(null, asyncStub).subscribeConfiguration(envelope, it) ).map( it -> { Map configMap = new HashMap<>(); @@ -1345,14 +1357,14 @@ public Mono unsubscribeConfiguration(Unsubscri if (id.isEmpty()) { throw new IllegalArgumentException("Subscription id can not be null or empty."); } - DaprProtos.UnsubscribeConfigurationRequest.Builder builder = - DaprProtos.UnsubscribeConfigurationRequest.newBuilder() + DaprConfigurationProtos.UnsubscribeConfigurationRequest.Builder builder = + DaprConfigurationProtos.UnsubscribeConfigurationRequest.newBuilder() .setId(id) .setStoreName(configurationStoreName); - DaprProtos.UnsubscribeConfigurationRequest envelope = builder.build(); + DaprConfigurationProtos.UnsubscribeConfigurationRequest envelope = builder.build(); - return this.createMono( + return this.createMono( it -> intercept(null, asyncStub).unsubscribeConfiguration(envelope, it) ).map( it -> new UnsubscribeConfigurationResponse(it.getOk(), it.getMessage()) @@ -1369,11 +1381,11 @@ public Mono scheduleJob(ScheduleJobRequest scheduleJobRequest) { try { validateScheduleJobRequest(scheduleJobRequest); - DaprProtos.Job.Builder jobBuilder = DaprProtos.Job.newBuilder(); + DaprJobsProtos.Job.Builder jobBuilder = DaprJobsProtos.Job.newBuilder(); jobBuilder.setName(scheduleJobRequest.getName()); DateTimeFormatter iso8601Formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - .withZone(ZoneOffset.UTC); + .withZone(ZoneOffset.UTC); if (scheduleJobRequest.getData() != null) { jobBuilder.setData(Any.newBuilder() @@ -1401,12 +1413,12 @@ public Mono scheduleJob(ScheduleJobRequest scheduleJobRequest) { } - Mono scheduleJobResponseMono = + Mono scheduleJobResponseMono = Mono.deferContextual(context -> this.createMono( it -> intercept(context, asyncStub) - .scheduleJobAlpha1(DaprProtos.ScheduleJobRequest.newBuilder() - .setOverwrite(scheduleJobRequest.getOverwrite()) - .setJob(jobBuilder.build()).build(), it) + .scheduleJobAlpha1(DaprJobsProtos.ScheduleJobRequest.newBuilder() + .setOverwrite(scheduleJobRequest.getOverwrite()) + .setJob(jobBuilder.build()).build(), it) ) ); @@ -1423,16 +1435,16 @@ public Mono getJob(GetJobRequest getJobRequest) { try { validateGetJobRequest(getJobRequest); - Mono getJobResponseMono = + Mono getJobResponseMono = Mono.deferContextual(context -> this.createMono( it -> intercept(context, asyncStub) - .getJobAlpha1(DaprProtos.GetJobRequest.newBuilder() + .getJobAlpha1(DaprJobsProtos.GetJobRequest.newBuilder() .setName(getJobRequest.getName()).build(), it) ) ); return getJobResponseMono.map(response -> { - DaprProtos.Job job = response.getJob(); + DaprJobsProtos.Job job = response.getJob(); GetJobResponse getJobResponse = null; if (job.hasSchedule() && job.hasDueTime()) { @@ -1466,8 +1478,8 @@ private FailurePolicy getJobFailurePolicy(CommonProtos.JobFailurePolicy jobFailu CommonProtos.JobFailurePolicyConstant jobFailurePolicyConstant = jobFailurePolicy.getConstant(); if (jobFailurePolicyConstant.hasInterval() && jobFailurePolicyConstant.hasMaxRetries()) { return new ConstantFailurePolicy(jobFailurePolicyConstant.getMaxRetries()) - .setDurationBetweenRetries(Duration.of(jobFailurePolicyConstant.getInterval().getNanos(), - ChronoUnit.NANOS)); + .setDurationBetweenRetries(Duration.of(jobFailurePolicyConstant.getInterval().getNanos(), + ChronoUnit.NANOS)); } if (jobFailurePolicyConstant.hasMaxRetries()) { @@ -1489,7 +1501,7 @@ private CommonProtos.JobFailurePolicy getJobFailurePolicy(FailurePolicy failureP CommonProtos.JobFailurePolicyConstant.Builder constantPolicyBuilder = CommonProtos.JobFailurePolicyConstant.newBuilder(); - ConstantFailurePolicy jobConstantFailurePolicy = (ConstantFailurePolicy)failurePolicy; + ConstantFailurePolicy jobConstantFailurePolicy = (ConstantFailurePolicy) failurePolicy; if (jobConstantFailurePolicy.getMaxRetries() != null) { constantPolicyBuilder.setMaxRetries(jobConstantFailurePolicy.getMaxRetries()); @@ -1512,10 +1524,10 @@ public Mono deleteJob(DeleteJobRequest deleteJobRequest) { try { validateDeleteJobRequest(deleteJobRequest); - Mono deleteJobResponseMono = + Mono deleteJobResponseMono = Mono.deferContextual(context -> this.createMono( it -> intercept(context, asyncStub) - .deleteJobAlpha1(DaprProtos.DeleteJobRequest.newBuilder() + .deleteJobAlpha1(DaprJobsProtos.DeleteJobRequest.newBuilder() .setName(deleteJobRequest.getName()).build(), it) ) ); @@ -1658,10 +1670,10 @@ public void onCompleted() { @Override public Mono getMetadata() { - DaprProtos.GetMetadataRequest metadataRequest = DaprProtos.GetMetadataRequest.newBuilder().build(); + DaprMetadataProtos.GetMetadataRequest metadataRequest = DaprMetadataProtos.GetMetadataRequest.newBuilder().build(); return Mono.deferContextual( - context -> this.createMono( - it -> intercept(context, asyncStub).getMetadata(metadataRequest, it))) + context -> this.createMono( + it -> intercept(context, asyncStub).getMetadata(metadataRequest, it))) .map( it -> { try { @@ -1682,7 +1694,7 @@ public Mono converse(ConversationRequest conversationReque try { validateConversationRequest(conversationRequest); - DaprProtos.ConversationRequest.Builder protosConversationRequestBuilder = DaprProtos.ConversationRequest + DaprAiProtos.ConversationRequest.Builder protosConversationRequestBuilder = DaprAiProtos.ConversationRequest .newBuilder().setTemperature(conversationRequest.getTemperature()) .setScrubPII(conversationRequest.isScrubPii()) .setName(conversationRequest.getName()); @@ -1696,7 +1708,7 @@ public Mono converse(ConversationRequest conversationReque throw new IllegalArgumentException("Conversation input content cannot be null or empty."); } - DaprProtos.ConversationInput.Builder conversationInputOrBuilder = DaprProtos.ConversationInput.newBuilder() + DaprAiProtos.ConversationInput.Builder conversationInputOrBuilder = DaprAiProtos.ConversationInput.newBuilder() .setContent(input.getContent()) .setScrubPII(input.isScrubPii()); @@ -1707,7 +1719,7 @@ public Mono converse(ConversationRequest conversationReque protosConversationRequestBuilder.addInputs(conversationInputOrBuilder.build()); } - Mono conversationResponseMono = Mono.deferContextual( + Mono conversationResponseMono = Mono.deferContextual( context -> this.createMono( it -> intercept(context, asyncStub) .converseAlpha1(protosConversationRequestBuilder.build(), it) @@ -1717,7 +1729,7 @@ public Mono converse(ConversationRequest conversationReque return conversationResponseMono.map(conversationResponse -> { List conversationOutputs = new ArrayList<>(); - for (DaprProtos.ConversationResult conversationResult : conversationResponse.getOutputsList()) { + for (DaprAiProtos.ConversationResult conversationResult : conversationResponse.getOutputsList()) { Map parameters = new HashMap<>(); for (Map.Entry entrySet : conversationResult.getParametersMap().entrySet()) { parameters.put(entrySet.getKey(), entrySet.getValue().toByteArray()); @@ -1760,15 +1772,15 @@ public Mono converseAlpha2(ConversationRequestAlpha2 throw new IllegalArgumentException("Conversation Inputs cannot be null or empty."); } - DaprProtos.ConversationRequestAlpha2 protoRequest = buildConversationRequestProto(conversationRequestAlpha2); - - Mono conversationResponseMono = Mono.deferContextual( + DaprAiProtos.ConversationRequestAlpha2 protoRequest = buildConversationRequestProto(conversationRequestAlpha2); + + Mono conversationResponseMono = Mono.deferContextual( context -> this.createMono( it -> intercept(context, asyncStub).converseAlpha2(protoRequest, it) ) ); - - DaprProtos.ConversationResponseAlpha2 conversationResponse = conversationResponseMono.block(); + + DaprAiProtos.ConversationResponseAlpha2 conversationResponse = conversationResponseMono.block(); assert conversationResponse != null; List results = buildConversationResults(conversationResponse.getOutputsList()); @@ -1778,8 +1790,8 @@ public Mono converseAlpha2(ConversationRequestAlpha2 } } - private DaprProtos.ConversationRequestAlpha2 buildConversationRequestProto(ConversationRequestAlpha2 request) { - DaprProtos.ConversationRequestAlpha2.Builder builder = DaprProtos.ConversationRequestAlpha2 + private DaprAiProtos.ConversationRequestAlpha2 buildConversationRequestProto(ConversationRequestAlpha2 request) { + DaprAiProtos.ConversationRequestAlpha2.Builder builder = DaprAiProtos.ConversationRequestAlpha2 .newBuilder() .setTemperature(request.getTemperature()) .setScrubPii(request.isScrubPii()) @@ -1822,27 +1834,27 @@ private DaprProtos.ConversationRequestAlpha2 buildConversationRequestProto(Conve } for (ConversationInputAlpha2 input : request.getInputs()) { - DaprProtos.ConversationInputAlpha2.Builder inputBuilder = DaprProtos.ConversationInputAlpha2 - .newBuilder() - .setScrubPii(input.isScrubPii()); + DaprAiProtos.ConversationInputAlpha2.Builder inputBuilder = DaprAiProtos.ConversationInputAlpha2 + .newBuilder() + .setScrubPii(input.isScrubPii()); if (input.getMessages() != null) { for (ConversationMessage message : input.getMessages()) { - DaprProtos.ConversationMessage protoMessage = buildConversationMessage(message); + DaprAiProtos.ConversationMessage protoMessage = buildConversationMessage(message); inputBuilder.addMessages(protoMessage); } } builder.addInputs(inputBuilder.build()); } - + return builder.build(); } - private DaprProtos.ConversationTools buildConversationTools(ConversationTools tool) { + private DaprAiProtos.ConversationTools buildConversationTools(ConversationTools tool) { ConversationToolsFunction function = tool.getFunction(); - DaprProtos.ConversationToolsFunction.Builder protoFunction = DaprProtos.ConversationToolsFunction.newBuilder() + DaprAiProtos.ConversationToolsFunction.Builder protoFunction = DaprAiProtos.ConversationToolsFunction.newBuilder() .setName(function.getName()); if (function.getDescription() != null) { @@ -1866,30 +1878,30 @@ private DaprProtos.ConversationTools buildConversationTools(ConversationTools to protoFunction.setParameters(Struct.newBuilder().putAllFields(functionParams).build()); } - return DaprProtos.ConversationTools.newBuilder().setFunction(protoFunction).build(); + return DaprAiProtos.ConversationTools.newBuilder().setFunction(protoFunction).build(); } - private DaprProtos.ConversationMessage buildConversationMessage(ConversationMessage message) { - DaprProtos.ConversationMessage.Builder messageBuilder = DaprProtos.ConversationMessage.newBuilder(); + private DaprAiProtos.ConversationMessage buildConversationMessage(ConversationMessage message) { + DaprAiProtos.ConversationMessage.Builder messageBuilder = DaprAiProtos.ConversationMessage.newBuilder(); switch (message.getRole()) { case TOOL: - DaprProtos.ConversationMessageOfTool.Builder toolMessage = - DaprProtos.ConversationMessageOfTool.newBuilder(); + DaprAiProtos.ConversationMessageOfTool.Builder toolMessage = + DaprAiProtos.ConversationMessageOfTool.newBuilder(); if (message.getName() != null) { toolMessage.setName(message.getName()); } if (message.getContent() != null) { toolMessage.addAllContent(getConversationMessageContent(message)); } - if (((ToolMessage)message).getToolId() != null) { - toolMessage.setToolId(((ToolMessage)message).getToolId()); + if (((ToolMessage) message).getToolId() != null) { + toolMessage.setToolId(((ToolMessage) message).getToolId()); } messageBuilder.setOfTool(toolMessage); break; case USER: - DaprProtos.ConversationMessageOfUser.Builder userMessage = - DaprProtos.ConversationMessageOfUser.newBuilder(); + DaprAiProtos.ConversationMessageOfUser.Builder userMessage = + DaprAiProtos.ConversationMessageOfUser.newBuilder(); if (message.getName() != null) { userMessage.setName(message.getName()); } @@ -1899,8 +1911,8 @@ private DaprProtos.ConversationMessage buildConversationMessage(ConversationMess messageBuilder.setOfUser(userMessage); break; case ASSISTANT: - DaprProtos.ConversationMessageOfAssistant.Builder assistantMessage = - DaprProtos.ConversationMessageOfAssistant.newBuilder(); + DaprAiProtos.ConversationMessageOfAssistant.Builder assistantMessage = + DaprAiProtos.ConversationMessageOfAssistant.newBuilder(); if (message.getName() != null) { assistantMessage.setName(message.getName()); @@ -1908,14 +1920,14 @@ private DaprProtos.ConversationMessage buildConversationMessage(ConversationMess if (message.getContent() != null) { assistantMessage.addAllContent(getConversationMessageContent(message)); } - if (((AssistantMessage)message).getToolCalls() != null) { - assistantMessage.addAllToolCalls(getConversationToolCalls((AssistantMessage)message)); + if (((AssistantMessage) message).getToolCalls() != null) { + assistantMessage.addAllToolCalls(getConversationToolCalls((AssistantMessage) message)); } messageBuilder.setOfAssistant(assistantMessage); break; case DEVELOPER: - DaprProtos.ConversationMessageOfDeveloper.Builder developerMessage = - DaprProtos.ConversationMessageOfDeveloper.newBuilder(); + DaprAiProtos.ConversationMessageOfDeveloper.Builder developerMessage = + DaprAiProtos.ConversationMessageOfDeveloper.newBuilder(); if (message.getName() != null) { developerMessage.setName(message.getName()); } @@ -1925,8 +1937,8 @@ private DaprProtos.ConversationMessage buildConversationMessage(ConversationMess messageBuilder.setOfDeveloper(developerMessage); break; case SYSTEM: - DaprProtos.ConversationMessageOfSystem.Builder systemMessage = - DaprProtos.ConversationMessageOfSystem.newBuilder(); + DaprAiProtos.ConversationMessageOfSystem.Builder systemMessage = + DaprAiProtos.ConversationMessageOfSystem.newBuilder(); if (message.getName() != null) { systemMessage.setName(message.getName()); } @@ -1943,31 +1955,31 @@ private DaprProtos.ConversationMessage buildConversationMessage(ConversationMess } private List buildConversationResults( - List protoResults) { + List protoResults) { List results = new ArrayList<>(); - - for (DaprProtos.ConversationResultAlpha2 protoResult : protoResults) { + + for (DaprAiProtos.ConversationResultAlpha2 protoResult : protoResults) { List choices = new ArrayList<>(); - - for (DaprProtos.ConversationResultChoices protoChoice : protoResult.getChoicesList()) { + + for (DaprAiProtos.ConversationResultChoices protoChoice : protoResult.getChoicesList()) { ConversationResultMessage message = buildConversationResultMessage(protoChoice); choices.add(new ConversationResultChoices(protoChoice.getFinishReason(), protoChoice.getIndex(), message)); - } + } results.add(new ConversationResultAlpha2(choices)); } - + return results; } - private ConversationResultMessage buildConversationResultMessage(DaprProtos.ConversationResultChoices protoChoice) { + private ConversationResultMessage buildConversationResultMessage(DaprAiProtos.ConversationResultChoices protoChoice) { if (!protoChoice.hasMessage()) { return null; } List toolCalls = new ArrayList<>(); - for (DaprProtos.ConversationToolCalls protoToolCall : protoChoice.getMessage().getToolCallsList()) { + for (DaprAiProtos.ConversationToolCalls protoToolCall : protoChoice.getMessage().getToolCallsList()) { ConversationToolCallsOfFunction function = null; if (protoToolCall.hasFunction()) { function = new ConversationToolCallsOfFunction( @@ -1981,17 +1993,17 @@ private ConversationResultMessage buildConversationResultMessage(DaprProtos.Conv toolCalls.add(conversationToolCalls); } - + return new ConversationResultMessage(protoChoice.getMessage().getContent(), toolCalls ); } - private List getConversationMessageContent( + private List getConversationMessageContent( ConversationMessage conversationMessage) { - List conversationMessageContents = new ArrayList<>(); - for (ConversationMessageContent conversationMessageContent: conversationMessage.getContent()) { - conversationMessageContents.add(DaprProtos.ConversationMessageContent.newBuilder() + List conversationMessageContents = new ArrayList<>(); + for (ConversationMessageContent conversationMessageContent : conversationMessage.getContent()) { + conversationMessageContents.add(DaprAiProtos.ConversationMessageContent.newBuilder() .setText(conversationMessageContent.getText()) .build()); } @@ -1999,15 +2011,15 @@ private List getConversationMessageConten return conversationMessageContents; } - private List getConversationToolCalls( + private List getConversationToolCalls( AssistantMessage assistantMessage) { - List conversationToolCalls = new ArrayList<>(); - for (ConversationToolCalls conversationToolCall: assistantMessage.getToolCalls()) { - DaprProtos.ConversationToolCalls.Builder toolCallsBuilder = DaprProtos.ConversationToolCalls.newBuilder() - .setFunction(DaprProtos.ConversationToolCallsOfFunction.newBuilder() - .setName(conversationToolCall.getFunction().getName()) - .setArguments(conversationToolCall.getFunction().getArguments()) - .build()); + List conversationToolCalls = new ArrayList<>(); + for (ConversationToolCalls conversationToolCall : assistantMessage.getToolCalls()) { + DaprAiProtos.ConversationToolCalls.Builder toolCallsBuilder = DaprAiProtos.ConversationToolCalls.newBuilder() + .setFunction(DaprAiProtos.ConversationToolCallsOfFunction.newBuilder() + .setName(conversationToolCall.getFunction().getName()) + .setArguments(conversationToolCall.getFunction().getArguments()) + .build()); if (conversationToolCall.getId() != null) { toolCallsBuilder.setId(conversationToolCall.getId()); } @@ -2018,7 +2030,7 @@ private List getConversationToolCalls( return conversationToolCalls; } - private DaprMetadata buildDaprMetadata(DaprProtos.GetMetadataResponse response) throws IOException { + private DaprMetadata buildDaprMetadata(DaprMetadataProtos.GetMetadataResponse response) throws IOException { String id = response.getId(); String runtimeVersion = response.getRuntimeVersion(); List enabledFeatures = response.getEnabledFeaturesList(); @@ -2030,40 +2042,40 @@ private DaprMetadata buildDaprMetadata(DaprProtos.GetMetadataResponse response) AppConnectionPropertiesMetadata appConnectionProperties = getAppConnectionProperties(response); return new DaprMetadata(id, runtimeVersion, enabledFeatures, actors, attributes, components, httpEndpoints, - subscriptions, appConnectionProperties); + subscriptions, appConnectionProperties); } - private List getActors(DaprProtos.GetMetadataResponse response) { - ActorRuntime actorRuntime = response.getActorRuntime(); - List activeActorsList = actorRuntime.getActiveActorsList(); + private List getActors(DaprMetadataProtos.GetMetadataResponse response) { + DaprMetadataProtos.ActorRuntime actorRuntime = response.getActorRuntime(); + List activeActorsList = actorRuntime.getActiveActorsList(); List actors = new ArrayList<>(); - for (ActiveActorsCount aac : activeActorsList) { + for (DaprMetadataProtos.ActiveActorsCount aac : activeActorsList) { actors.add(new ActorMetadata(aac.getType(), aac.getCount())); } return actors; } - private List getComponents(DaprProtos.GetMetadataResponse response) { - List registeredComponentsList = response.getRegisteredComponentsList(); + private List getComponents(DaprMetadataProtos.GetMetadataResponse response) { + List registeredComponentsList = response.getRegisteredComponentsList(); List components = new ArrayList<>(); - for (RegisteredComponents rc : registeredComponentsList) { + for (DaprMetadataProtos.RegisteredComponents rc : registeredComponentsList) { components.add(new ComponentMetadata(rc.getName(), rc.getType(), rc.getVersion(), rc.getCapabilitiesList())); } return components; } - private List getSubscriptions(DaprProtos.GetMetadataResponse response) { - List subscriptionsList = response.getSubscriptionsList(); + private List getSubscriptions(DaprMetadataProtos.GetMetadataResponse response) { + List subscriptionsList = response.getSubscriptionsList(); List subscriptions = new ArrayList<>(); - for (PubsubSubscription s : subscriptionsList) { - List rulesList = s.getRules().getRulesList(); + for (DaprMetadataProtos.PubsubSubscription s : subscriptionsList) { + List rulesList = s.getRules().getRulesList(); List rules = new ArrayList<>(); - for (PubsubSubscriptionRule r : rulesList) { + for (DaprMetadataProtos.PubsubSubscriptionRule r : rulesList) { rules.add(new RuleMetadata(r.getMatch(), r.getPath())); } subscriptions.add(new SubscriptionMetadata(s.getPubsubName(), s.getTopic(), s.getMetadataMap(), rules, @@ -2073,19 +2085,19 @@ private List getSubscriptions(DaprProtos.GetMetadataRespon return subscriptions; } - private List getHttpEndpoints(DaprProtos.GetMetadataResponse response) { - List httpEndpointsList = response.getHttpEndpointsList(); + private List getHttpEndpoints(DaprMetadataProtos.GetMetadataResponse response) { + List httpEndpointsList = response.getHttpEndpointsList(); List httpEndpoints = new ArrayList<>(); - for (MetadataHTTPEndpoint m : httpEndpointsList) { + for (DaprMetadataProtos.MetadataHTTPEndpoint m : httpEndpointsList) { httpEndpoints.add(new HttpEndpointMetadata(m.getName())); } return httpEndpoints; } - private AppConnectionPropertiesMetadata getAppConnectionProperties(DaprProtos.GetMetadataResponse response) { - AppConnectionProperties appConnectionProperties = response.getAppConnectionProperties(); + private AppConnectionPropertiesMetadata getAppConnectionProperties(DaprMetadataProtos.GetMetadataResponse response) { + DaprMetadataProtos.AppConnectionProperties appConnectionProperties = response.getAppConnectionProperties(); int port = appConnectionProperties.getPort(); String protocol = appConnectionProperties.getProtocol(); String channelAddress = appConnectionProperties.getChannelAddress(); @@ -2096,12 +2108,12 @@ private AppConnectionPropertiesMetadata getAppConnectionProperties(DaprProtos.Ge } private AppConnectionPropertiesHealthMetadata getAppConnectionPropertiesHealth( - AppConnectionProperties appConnectionProperties) { + DaprMetadataProtos.AppConnectionProperties appConnectionProperties) { if (!appConnectionProperties.hasHealth()) { return null; } - AppConnectionHealthProperties health = appConnectionProperties.getHealth(); + DaprMetadataProtos.AppConnectionHealthProperties health = appConnectionProperties.getHealth(); String healthCheckPath = health.getHealthCheckPath(); String healthProbeInterval = health.getHealthProbeInterval(); String healthProbeTimeout = health.getHealthProbeTimeout(); @@ -2135,10 +2147,10 @@ public Flux encrypt(EncryptRequestAlpha1 request) { return Flux.create(sink -> { // Create response observer to receive encrypted data - final StreamObserver responseObserver = - new StreamObserver() { + final StreamObserver responseObserver = + new StreamObserver() { @Override - public void onNext(DaprProtos.EncryptResponse response) { + public void onNext(DaprCryptoProtos.EncryptResponse response) { if (response.hasPayload()) { byte[] data = response.getPayload().getData().toByteArray(); if (data.length > 0) { @@ -2160,7 +2172,8 @@ public void onCompleted() { }; // Build options for the first message - DaprProtos.EncryptRequestOptions.Builder optionsBuilder = DaprProtos.EncryptRequestOptions.newBuilder() + DaprCryptoProtos.EncryptRequestOptions.Builder optionsBuilder = + DaprCryptoProtos.EncryptRequestOptions.newBuilder() .setComponentName(request.getComponentName()) .setKeyName(request.getKeyName()) .setKeyWrapAlgorithm(request.getKeyWrapAlgorithm()); @@ -2173,18 +2186,18 @@ public void onCompleted() { optionsBuilder.setDecryptionKeyName(request.getDecryptionKeyName()); } - final DaprProtos.EncryptRequestOptions options = optionsBuilder.build(); + final DaprCryptoProtos.EncryptRequestOptions options = optionsBuilder.build(); final long[] sequenceNumber = {0}; final boolean[] firstMessage = {true}; // Get the request stream observer from gRPC - final StreamObserver requestObserver = + final StreamObserver requestObserver = intercept(null, asyncStub).encryptAlpha1(responseObserver); // Subscribe to the plaintext stream and send chunks request.getPlainTextStream() .doOnNext(chunk -> { - DaprProtos.EncryptRequest.Builder reqBuilder = DaprProtos.EncryptRequest.newBuilder() + DaprCryptoProtos.EncryptRequest.Builder reqBuilder = DaprCryptoProtos.EncryptRequest.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(chunk)) .setSeq(sequenceNumber[0]++) @@ -2200,7 +2213,7 @@ public void onCompleted() { }) .doOnError(error -> { requestObserver.onError(error); - sink.error(DaprException.propagate(new DaprException("ENCRYPT_ERROR", + sink.error(DaprException.propagate(new DaprException("ENCRYPT_ERROR", "Error reading plaintext stream: " + error.getMessage(), error))); }) .doOnComplete(() -> { @@ -2231,10 +2244,10 @@ public Flux decrypt(DecryptRequestAlpha1 request) { return Flux.create(sink -> { // Create response observer to receive decrypted data - final StreamObserver responseObserver = - new StreamObserver() { + final StreamObserver responseObserver = + new StreamObserver() { @Override - public void onNext(DaprProtos.DecryptResponse response) { + public void onNext(DaprCryptoProtos.DecryptResponse response) { if (response.hasPayload()) { byte[] data = response.getPayload().getData().toByteArray(); if (data.length > 0) { @@ -2256,25 +2269,26 @@ public void onCompleted() { }; // Build options for the first message - DaprProtos.DecryptRequestOptions.Builder optionsBuilder = DaprProtos.DecryptRequestOptions.newBuilder() + DaprCryptoProtos.DecryptRequestOptions.Builder optionsBuilder = DaprCryptoProtos.DecryptRequestOptions + .newBuilder() .setComponentName(request.getComponentName()); if (request.getKeyName() != null && !request.getKeyName().isEmpty()) { optionsBuilder.setKeyName(request.getKeyName()); } - final DaprProtos.DecryptRequestOptions options = optionsBuilder.build(); + final DaprCryptoProtos.DecryptRequestOptions options = optionsBuilder.build(); final long[] sequenceNumber = {0}; final boolean[] firstMessage = {true}; // Get the request stream observer from gRPC - final StreamObserver requestObserver = + final StreamObserver requestObserver = intercept(null, asyncStub).decryptAlpha1(responseObserver); // Subscribe to the ciphertext stream and send chunks request.getCipherTextStream() .doOnNext(chunk -> { - DaprProtos.DecryptRequest.Builder reqBuilder = DaprProtos.DecryptRequest.newBuilder() + DaprCryptoProtos.DecryptRequest.Builder reqBuilder = DaprCryptoProtos.DecryptRequest.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(chunk)) .setSeq(sequenceNumber[0]++) @@ -2290,7 +2304,7 @@ public void onCompleted() { }) .doOnError(error -> { requestObserver.onError(error); - sink.error(DaprException.propagate(new DaprException("DECRYPT_ERROR", + sink.error(DaprException.propagate(new DaprException("DECRYPT_ERROR", "Error reading ciphertext stream: " + error.getMessage(), error))); }) .doOnComplete(() -> { diff --git a/sdk/src/main/java/io/dapr/client/Subscription.java b/sdk/src/main/java/io/dapr/client/Subscription.java index 2cbd1e9b30..2f85128474 100644 --- a/sdk/src/main/java/io/dapr/client/Subscription.java +++ b/sdk/src/main/java/io/dapr/client/Subscription.java @@ -17,12 +17,11 @@ import io.dapr.exceptions.DaprException; import io.dapr.v1.DaprAppCallbackProtos; import io.dapr.v1.DaprGrpc; -import io.dapr.v1.DaprProtos; +import io.dapr.v1.DaprPubsubProtos; import io.grpc.stub.StreamObserver; import reactor.core.publisher.Mono; import javax.annotation.Nonnull; - import java.io.Closeable; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -38,7 +37,8 @@ @Deprecated public class Subscription implements Closeable { - private final BlockingQueue ackQueue = new LinkedBlockingQueue<>(50); + private final BlockingQueue ackQueue = + new LinkedBlockingQueue<>(50); private final AtomicBoolean running = new AtomicBoolean(true); @@ -49,10 +49,10 @@ public class Subscription implements Closeable { private Thread receiver; Subscription(DaprGrpc.DaprStub asyncStub, - DaprProtos.SubscribeTopicEventsRequestAlpha1 request, + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 request, SubscriptionListener listener, - Function> cloudEventConverter) { - final AtomicReference> streamRef = + Function> cloudEventConverter) { + final AtomicReference> streamRef = new AtomicReference<>(); this.acker = new Thread(() -> { @@ -91,7 +91,7 @@ public class Subscription implements Closeable { while (running.get()) { var stream = asyncStub.subscribeTopicEventsAlpha1(new StreamObserver<>() { @Override - public void onNext(DaprProtos.SubscribeTopicEventsResponseAlpha1 topicEventRequest) { + public void onNext(DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1 topicEventRequest) { try { var stream = streamRef.get(); if (stream == null) { @@ -156,10 +156,10 @@ private static Mono onEvent( } @Nonnull - private static DaprProtos.SubscribeTopicEventsRequestAlpha1 buildAckRequest( + private static DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 buildAckRequest( String id, SubscriptionListener.Status status) { - DaprProtos.SubscribeTopicEventsRequestProcessedAlpha1 eventProcessed = - DaprProtos.SubscribeTopicEventsRequestProcessedAlpha1.newBuilder() + DaprPubsubProtos.SubscribeTopicEventsRequestProcessedAlpha1 eventProcessed = + DaprPubsubProtos.SubscribeTopicEventsRequestProcessedAlpha1.newBuilder() .setId(id) .setStatus( DaprAppCallbackProtos.TopicEventResponse.newBuilder() @@ -167,8 +167,8 @@ private static DaprProtos.SubscribeTopicEventsRequestAlpha1 buildAckRequest( status.name())) .build()) .build(); - DaprProtos.SubscribeTopicEventsRequestAlpha1 ack = - DaprProtos.SubscribeTopicEventsRequestAlpha1.newBuilder() + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 ack = + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1.newBuilder() .setEventProcessed(eventProcessed) .build(); return ack; diff --git a/sdk/src/main/java/io/dapr/internal/subscription/EventSubscriberStreamObserver.java b/sdk/src/main/java/io/dapr/internal/subscription/EventSubscriberStreamObserver.java index 56131882b8..5b4eb79cec 100644 --- a/sdk/src/main/java/io/dapr/internal/subscription/EventSubscriberStreamObserver.java +++ b/sdk/src/main/java/io/dapr/internal/subscription/EventSubscriberStreamObserver.java @@ -19,7 +19,7 @@ import io.dapr.utils.TypeRef; import io.dapr.v1.DaprAppCallbackProtos; import io.dapr.v1.DaprGrpc; -import io.dapr.v1.DaprProtos; +import io.dapr.v1.DaprPubsubProtos; import io.grpc.stub.StreamObserver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,7 +35,8 @@ * * @param The type of the event payload */ -public class EventSubscriberStreamObserver implements StreamObserver { +public class EventSubscriberStreamObserver implements + StreamObserver { private static final Logger logger = LoggerFactory.getLogger(EventSubscriberStreamObserver.class); @@ -44,7 +45,7 @@ public class EventSubscriberStreamObserver implements StreamObserver type; private final DaprObjectSerializer objectSerializer; - private StreamObserver requestStream; + private StreamObserver requestStream; /** * Creates a new EventSubscriberStreamObserver. @@ -65,41 +66,12 @@ public EventSubscriberStreamObserver( this.objectSerializer = objectSerializer; } - /** Starts the subscription by sending the initial request. - * - * @param request The subscription request - * @return The StreamObserver to send further requests (acknowledgments) - */ - public StreamObserver start( - DaprProtos.SubscribeTopicEventsRequestAlpha1 request - ) { - requestStream = stub.subscribeTopicEventsAlpha1(this); - - requestStream.onNext(request); - - return requestStream; + private static DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 buildSuccessAck(String eventId) { + return buildAckRequest(eventId, DaprAppCallbackProtos.TopicEventResponse.TopicEventResponseStatus.SUCCESS); } - @Override - public void onNext(DaprProtos.SubscribeTopicEventsResponseAlpha1 response) { - if (!isValidEventMessage(response)) { - return; - } - - DaprAppCallbackProtos.TopicEventRequest message = response.getEventMessage(); - String eventId = message.getId(); - - try { - T data = deserializeEventData(message); - CloudEvent cloudEvent = buildCloudEvent(message, data); - emitEventAndAcknowledge(cloudEvent, eventId); - } catch (IOException e) { - // Deserialization failure - send DROP ack - handleDeserializationError(eventId, e); - } catch (Exception e) { - // Processing failure - send RETRY ack - handleProcessingError(eventId, e); - } + private static DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 buildRetryAck(String eventId) { + return buildAckRequest(eventId, DaprAppCallbackProtos.TopicEventResponse.TopicEventResponseStatus.RETRY); } @Override @@ -112,25 +84,8 @@ public void onCompleted() { sink.complete(); } - private boolean isValidEventMessage(DaprProtos.SubscribeTopicEventsResponseAlpha1 response) { - if (response.getEventMessage() == null) { - logger.debug("Received response with null event message, skipping"); - return false; - } - - DaprAppCallbackProtos.TopicEventRequest message = response.getEventMessage(); - - if (message.getPubsubName() == null || message.getPubsubName().isEmpty()) { - logger.debug("Received event with empty pubsub name, skipping"); - return false; - } - - if (message.getId() == null || message.getId().isEmpty()) { - logger.debug("Received event with empty ID, skipping"); - return false; - } - - return true; + private static DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 buildDropAck(String eventId) { + return buildAckRequest(eventId, DaprAppCallbackProtos.TopicEventResponse.TopicEventResponseStatus.DROP); } private T deserializeEventData(DaprAppCallbackProtos.TopicEventRequest message) throws IOException { @@ -192,23 +147,11 @@ private void handleProcessingError(String eventId, Exception cause) { sink.error(DaprException.propagate(cause)); } - private static DaprProtos.SubscribeTopicEventsRequestAlpha1 buildSuccessAck(String eventId) { - return buildAckRequest(eventId, DaprAppCallbackProtos.TopicEventResponse.TopicEventResponseStatus.SUCCESS); - } - - private static DaprProtos.SubscribeTopicEventsRequestAlpha1 buildRetryAck(String eventId) { - return buildAckRequest(eventId, DaprAppCallbackProtos.TopicEventResponse.TopicEventResponseStatus.RETRY); - } - - private static DaprProtos.SubscribeTopicEventsRequestAlpha1 buildDropAck(String eventId) { - return buildAckRequest(eventId, DaprAppCallbackProtos.TopicEventResponse.TopicEventResponseStatus.DROP); - } - - private static DaprProtos.SubscribeTopicEventsRequestAlpha1 buildAckRequest( + private static DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 buildAckRequest( String eventId, DaprAppCallbackProtos.TopicEventResponse.TopicEventResponseStatus status) { - DaprProtos.SubscribeTopicEventsRequestProcessedAlpha1 eventProcessed = - DaprProtos.SubscribeTopicEventsRequestProcessedAlpha1.newBuilder() + DaprPubsubProtos.SubscribeTopicEventsRequestProcessedAlpha1 eventProcessed = + DaprPubsubProtos.SubscribeTopicEventsRequestProcessedAlpha1.newBuilder() .setId(eventId) .setStatus( DaprAppCallbackProtos.TopicEventResponse.newBuilder() @@ -216,8 +159,66 @@ private static DaprProtos.SubscribeTopicEventsRequestAlpha1 buildAckRequest( .build()) .build(); - return DaprProtos.SubscribeTopicEventsRequestAlpha1.newBuilder() + return DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1.newBuilder() .setEventProcessed(eventProcessed) .build(); } + + /** Starts the subscription by sending the initial request. + * + * @param request The subscription request + * @return The StreamObserver to send further requests (acknowledgments) + */ + public StreamObserver start( + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 request + ) { + requestStream = stub.subscribeTopicEventsAlpha1(this); + + requestStream.onNext(request); + + return requestStream; + } + + @Override + public void onNext(DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1 response) { + if (!isValidEventMessage(response)) { + return; + } + + DaprAppCallbackProtos.TopicEventRequest message = response.getEventMessage(); + String eventId = message.getId(); + + try { + T data = deserializeEventData(message); + CloudEvent cloudEvent = buildCloudEvent(message, data); + emitEventAndAcknowledge(cloudEvent, eventId); + } catch (IOException e) { + // Deserialization failure - send DROP ack + handleDeserializationError(eventId, e); + } catch (Exception e) { + // Processing failure - send RETRY ack + handleProcessingError(eventId, e); + } + } + + private boolean isValidEventMessage(DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1 response) { + if (response.getEventMessage() == null) { + logger.debug("Received response with null event message, skipping"); + return false; + } + + DaprAppCallbackProtos.TopicEventRequest message = response.getEventMessage(); + + if (message.getPubsubName() == null || message.getPubsubName().isEmpty()) { + logger.debug("Received event with empty pubsub name, skipping"); + return false; + } + + if (message.getId() == null || message.getId().isEmpty()) { + logger.debug("Received event with empty ID, skipping"); + return false; + } + + return true; + } } diff --git a/sdk/src/test/java/io/dapr/client/DaprClientGrpcTelemetryTest.java b/sdk/src/test/java/io/dapr/client/DaprClientGrpcTelemetryTest.java index dc7ed58edd..889b7d19e2 100644 --- a/sdk/src/test/java/io/dapr/client/DaprClientGrpcTelemetryTest.java +++ b/sdk/src/test/java/io/dapr/client/DaprClientGrpcTelemetryTest.java @@ -18,7 +18,7 @@ import io.dapr.internal.grpc.DaprClientGrpcInterceptors; import io.dapr.v1.CommonProtos; import io.dapr.v1.DaprGrpc; -import io.dapr.v1.DaprProtos; +import io.dapr.v1.DaprInvokeProtos; import io.grpc.ManagedChannel; import io.grpc.Metadata; import io.grpc.ServerCall; @@ -118,7 +118,7 @@ public static Stream data() { public void setup(String traceparent, String tracestate, boolean expectGrpcTraceBin) throws IOException { DaprGrpc.DaprImplBase daprImplBase = new DaprGrpc.DaprImplBase() { - public void invokeService(io.dapr.v1.DaprProtos.InvokeServiceRequest request, + public void invokeService(DaprInvokeProtos.InvokeServiceRequest request, io.grpc.stub.StreamObserver responseObserver) { responseObserver.onNext(CommonProtos.InvokeResponse.getDefaultInstance()); responseObserver.onCompleted(); @@ -154,7 +154,7 @@ public ServerCall.Listener interceptCall(ServerCall responseObserver) { responseObserver.onNext(CommonProtos.InvokeResponse.getDefaultInstance()); responseObserver.onCompleted(); @@ -233,8 +233,8 @@ public void invokeServiceVoidWithTracingTestAndEmptyContext() throws IOException } private Mono invoke() { - DaprProtos.InvokeServiceRequest req = - DaprProtos.InvokeServiceRequest.newBuilder() + DaprInvokeProtos.InvokeServiceRequest req = + DaprInvokeProtos.InvokeServiceRequest.newBuilder() .build(); return Mono.deferContextual( context -> this.createMono( diff --git a/sdk/src/test/java/io/dapr/client/DaprClientGrpcTest.java b/sdk/src/test/java/io/dapr/client/DaprClientGrpcTest.java index 642c3b4f28..e57509deb0 100644 --- a/sdk/src/test/java/io/dapr/client/DaprClientGrpcTest.java +++ b/sdk/src/test/java/io/dapr/client/DaprClientGrpcTest.java @@ -46,16 +46,15 @@ import io.dapr.serializer.DefaultObjectSerializer; import io.dapr.utils.TypeRef; import io.dapr.v1.CommonProtos; +import io.dapr.v1.DaprBindingsProtos; +import io.dapr.v1.DaprConfigurationProtos; import io.dapr.v1.DaprGrpc; +import io.dapr.v1.DaprJobsProtos; +import io.dapr.v1.DaprMetadataProtos; import io.dapr.v1.DaprProtos; -import io.dapr.v1.DaprProtos.ActiveActorsCount; -import io.dapr.v1.DaprProtos.ActorRuntime; -import io.dapr.v1.DaprProtos.AppConnectionHealthProperties; -import io.dapr.v1.DaprProtos.AppConnectionProperties; -import io.dapr.v1.DaprProtos.MetadataHTTPEndpoint; -import io.dapr.v1.DaprProtos.PubsubSubscription; -import io.dapr.v1.DaprProtos.PubsubSubscriptionRules; -import io.dapr.v1.DaprProtos.RegisteredComponents; +import io.dapr.v1.DaprPubsubProtos; +import io.dapr.v1.DaprSecretProtos; +import io.dapr.v1.DaprStateProtos; import io.grpc.Status; import io.grpc.StatusRuntimeException; import io.grpc.protobuf.StatusProto; @@ -142,11 +141,25 @@ public void tearDown() throws Exception { verify(channel).close(); } + public static StatusRuntimeException newStatusRuntimeException(String statusCode, String message) { + return new StatusRuntimeException(Status.fromCode(Status.Code.valueOf(statusCode)).withDescription(message)); + } + + public static StatusRuntimeException newStatusRuntimeException(String statusCode, String message, com.google.rpc.Status statusDetails) { + com.google.rpc.Status status = com.google.rpc.Status.newBuilder() + .setCode(Status.Code.valueOf(statusCode).value()) + .setMessage(message) + .addAllDetails(statusDetails.getDetailsList()) + .build(); + + return StatusProto.toStatusRuntimeException(status); + } + @Test public void publishEventExceptionThrownTest() { doAnswer((Answer) invocation -> { throw newStatusRuntimeException("INVALID_ARGUMENT", "bad bad argument"); - }).when(daprStub).publishEvent(any(DaprProtos.PublishEventRequest.class), any()); + }).when(daprStub).publishEvent(any(DaprPubsubProtos.PublishEventRequest.class), any()); assertThrowsDaprException( StatusRuntimeException.class, @@ -161,7 +174,7 @@ public void publishEventCallbackExceptionThrownTest() { StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onError(newStatusRuntimeException("INVALID_ARGUMENT", "bad bad argument")); return null; - }).when(daprStub).publishEvent(any(DaprProtos.PublishEventRequest.class), any()); + }).when(daprStub).publishEvent(any(DaprPubsubProtos.PublishEventRequest.class), any()); Mono result = client.publishEvent("pubsubname","topic", "object"); @@ -181,7 +194,7 @@ public void publishEventSerializeException() throws IOException { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).publishEvent(any(DaprProtos.PublishEventRequest.class), any()); + }).when(daprStub).publishEvent(any(DaprPubsubProtos.PublishEventRequest.class), any()); when(mockSerializer.serialize(any())).thenThrow(IOException.class); Mono result = client.publishEvent("pubsubname","topic", "{invalid-json"); @@ -193,34 +206,6 @@ public void publishEventSerializeException() throws IOException { () -> result.block()); } - @Test - public void publishEventTest() { - doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; - observer.onNext(Empty.getDefaultInstance()); - observer.onCompleted(); - return null; - }).when(daprStub).publishEvent(any(DaprProtos.PublishEventRequest.class), any()); - - Mono result = client.publishEvent("pubsubname","topic", "object"); - result.block(); - } - - @Test - public void publishEventNoHotMono() { - AtomicBoolean called = new AtomicBoolean(false); - doAnswer((Answer) invocation -> { - called.set(true); - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; - observer.onNext(Empty.getDefaultInstance()); - observer.onCompleted(); - return null; - }).when(daprStub).publishEvent(any(DaprProtos.PublishEventRequest.class), any()); - client.publishEvent("pubsubname", "topic", "object"); - // Do not call block() on the mono above, so nothing should happen. - assertFalse(called.get()); - } - @Test public void publishEventObjectTest() { doAnswer((Answer) invocation -> { @@ -290,6 +275,34 @@ public void invokeBindingIllegalArgumentExceptionTest() { }); } + @Test + public void publishEventTest() { + doAnswer((Answer) invocation -> { + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + observer.onNext(Empty.getDefaultInstance()); + observer.onCompleted(); + return null; + }).when(daprStub).publishEvent(any(DaprPubsubProtos.PublishEventRequest.class), any()); + + Mono result = client.publishEvent("pubsubname", "topic", "object"); + result.block(); + } + + @Test + public void publishEventNoHotMono() { + AtomicBoolean called = new AtomicBoolean(false); + doAnswer((Answer) invocation -> { + called.set(true); + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + observer.onNext(Empty.getDefaultInstance()); + observer.onCompleted(); + return null; + }).when(daprStub).publishEvent(any(DaprPubsubProtos.PublishEventRequest.class), any()); + client.publishEvent("pubsubname", "topic", "object"); + // Do not call block() on the mono above, so nothing should happen. + assertFalse(called.get()); + } + @Test public void invokeBindingSerializeException() throws IOException { DaprObjectSerializer mockSerializer = mock(DaprObjectSerializer.class); @@ -299,7 +312,7 @@ public void invokeBindingSerializeException() throws IOException { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).invokeBinding(any(DaprProtos.InvokeBindingRequest.class), any()); + }).when(daprStub).invokeBinding(any(DaprBindingsProtos.InvokeBindingRequest.class), any()); when(mockSerializer.serialize(any())).thenThrow(IOException.class); Mono result = client.invokeBinding("BindingName", "MyOperation", "request".getBytes(), Collections.EMPTY_MAP); @@ -315,7 +328,7 @@ public void invokeBindingSerializeException() throws IOException { public void invokeBindingExceptionThrownTest() { doAnswer((Answer) invocation -> { throw new RuntimeException(); - }).when(daprStub).invokeBinding(any(DaprProtos.InvokeBindingRequest.class), any()); + }).when(daprStub).invokeBinding(any(DaprBindingsProtos.InvokeBindingRequest.class), any()); Mono result = client.invokeBinding("BindingName", "MyOperation", "request"); @@ -330,10 +343,10 @@ public void invokeBindingExceptionThrownTest() { public void invokeBindingCallbackExceptionThrownTest() { RuntimeException ex = new RuntimeException("An Exception"); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onError(ex); return null; - }).when(daprStub).invokeBinding(any(DaprProtos.InvokeBindingRequest.class), any()); + }).when(daprStub).invokeBinding(any(DaprBindingsProtos.InvokeBindingRequest.class), any()); Mono result = client.invokeBinding("BindingName", "MyOperation", "request"); @@ -346,14 +359,14 @@ public void invokeBindingCallbackExceptionThrownTest() { @Test public void invokeBindingTest() throws IOException { - DaprProtos.InvokeBindingResponse.Builder responseBuilder = - DaprProtos.InvokeBindingResponse.newBuilder().setData(serialize("OK")); + DaprBindingsProtos.InvokeBindingResponse.Builder responseBuilder = + DaprBindingsProtos.InvokeBindingResponse.newBuilder().setData(serialize("OK")); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseBuilder.build()); observer.onCompleted(); return null; - }).when(daprStub).invokeBinding(any(DaprProtos.InvokeBindingRequest.class), any()); + }).when(daprStub).invokeBinding(any(DaprBindingsProtos.InvokeBindingRequest.class), any()); Mono result = client.invokeBinding("BindingName", "MyOperation", "request"); result.block(); @@ -361,14 +374,14 @@ public void invokeBindingTest() throws IOException { @Test public void invokeBindingVoidReturnTest() throws IOException { - DaprProtos.InvokeBindingResponse.Builder responseBuilder = - DaprProtos.InvokeBindingResponse.newBuilder().setData(serialize("OK")); + DaprBindingsProtos.InvokeBindingResponse.Builder responseBuilder = + DaprBindingsProtos.InvokeBindingResponse.newBuilder().setData(serialize("OK")); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseBuilder.build()); observer.onCompleted(); return null; - }).when(daprStub).invokeBinding(any(DaprProtos.InvokeBindingRequest.class), any()); + }).when(daprStub).invokeBinding(any(DaprBindingsProtos.InvokeBindingRequest.class), any()); var request = new InvokeBindingRequest("BindingName", "MyOperation"); request.setData("request"); @@ -378,14 +391,14 @@ public void invokeBindingVoidReturnTest() throws IOException { @Test public void invokeBindingByteArrayTest() { - DaprProtos.InvokeBindingResponse.Builder responseBuilder = - DaprProtos.InvokeBindingResponse.newBuilder().setData(ByteString.copyFrom("OK".getBytes())); + DaprBindingsProtos.InvokeBindingResponse.Builder responseBuilder = + DaprBindingsProtos.InvokeBindingResponse.newBuilder().setData(ByteString.copyFrom("OK".getBytes())); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseBuilder.build()); observer.onCompleted(); return null; - }).when(daprStub).invokeBinding(any(DaprProtos.InvokeBindingRequest.class), any()); + }).when(daprStub).invokeBinding(any(DaprBindingsProtos.InvokeBindingRequest.class), any()); Mono result = client.invokeBinding("BindingName", "MyOperation", "request".getBytes(), Collections.EMPTY_MAP); @@ -394,14 +407,14 @@ public void invokeBindingByteArrayTest() { @Test public void invokeBindingObjectTest() throws IOException { - DaprProtos.InvokeBindingResponse.Builder responseBuilder = - DaprProtos.InvokeBindingResponse.newBuilder().setData(serialize("OK")); + DaprBindingsProtos.InvokeBindingResponse.Builder responseBuilder = + DaprBindingsProtos.InvokeBindingResponse.newBuilder().setData(serialize("OK")); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseBuilder.build()); observer.onCompleted(); return null; - }).when(daprStub).invokeBinding(any(DaprProtos.InvokeBindingRequest.class), any()); + }).when(daprStub).invokeBinding(any(DaprBindingsProtos.InvokeBindingRequest.class), any()); MyObject event = new MyObject(1, "Event"); Mono result = client.invokeBinding("BindingName", "MyOperation", event); @@ -411,14 +424,14 @@ public void invokeBindingObjectTest() throws IOException { @Test public void invokeBindingResponseObjectTest() throws IOException { - DaprProtos.InvokeBindingResponse.Builder responseBuilder = - DaprProtos.InvokeBindingResponse.newBuilder().setData(serialize("OK")); + DaprBindingsProtos.InvokeBindingResponse.Builder responseBuilder = + DaprBindingsProtos.InvokeBindingResponse.newBuilder().setData(serialize("OK")); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseBuilder.build()); observer.onCompleted(); return null; - }).when(daprStub).invokeBinding(any(DaprProtos.InvokeBindingRequest.class), any()); + }).when(daprStub).invokeBinding(any(DaprBindingsProtos.InvokeBindingRequest.class), any()); MyObject event = new MyObject(1, "Event"); Mono result = client.invokeBinding("BindingName", "MyOperation", event, String.class); @@ -426,16 +439,37 @@ public void invokeBindingResponseObjectTest() throws IOException { assertEquals("OK", result.block()); } + @Test + public void getStateIllegalArgumentExceptionTest() { + State key = buildStateKey(null, "Key1", "ETag1", null); + assertThrows(IllegalArgumentException.class, () -> { + // empty state store name + client.getState("", key, String.class).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + // null state store name + client.getState(null, key, String.class).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + // null key + client.getState(STATE_STORE_NAME, (String) null, String.class).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + // empty key + client.getState(STATE_STORE_NAME, "", String.class).block(); + }); + } + @Test public void invokeBindingResponseObjectTypeRefTest() throws IOException { - DaprProtos.InvokeBindingResponse.Builder responseBuilder = - DaprProtos.InvokeBindingResponse.newBuilder().setData(serialize("OK")); + DaprBindingsProtos.InvokeBindingResponse.Builder responseBuilder = + DaprBindingsProtos.InvokeBindingResponse.newBuilder().setData(serialize("OK")); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseBuilder.build()); observer.onCompleted(); return null; - }).when(daprStub).invokeBinding(any(DaprProtos.InvokeBindingRequest.class), any()); + }).when(daprStub).invokeBinding(any(DaprBindingsProtos.InvokeBindingRequest.class), any()); MyObject event = new MyObject(1, "Event"); Mono result = client.invokeBinding("BindingName", "MyOperation", event, TypeRef.get(String.class)); @@ -446,47 +480,26 @@ public void invokeBindingResponseObjectTypeRefTest() throws IOException { @Test public void invokeBindingObjectNoHotMono() throws IOException { AtomicBoolean called = new AtomicBoolean(false); - DaprProtos.InvokeBindingResponse.Builder responseBuilder = - DaprProtos.InvokeBindingResponse.newBuilder().setData(serialize("OK")); + DaprBindingsProtos.InvokeBindingResponse.Builder responseBuilder = + DaprBindingsProtos.InvokeBindingResponse.newBuilder().setData(serialize("OK")); doAnswer((Answer) invocation -> { called.set(true); - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseBuilder.build()); observer.onCompleted(); return null; - }).when(daprStub).invokeBinding(any(DaprProtos.InvokeBindingRequest.class), any()); + }).when(daprStub).invokeBinding(any(DaprBindingsProtos.InvokeBindingRequest.class), any()); MyObject event = new MyObject(1, "Event"); client.invokeBinding("BindingName", "MyOperation", event); // Do not call block() on mono above, so nothing should happen. assertFalse(called.get()); } - @Test - public void getStateIllegalArgumentExceptionTest() { - State key = buildStateKey(null, "Key1", "ETag1", null); - assertThrows(IllegalArgumentException.class, () -> { - // empty state store name - client.getState("", key, String.class).block(); - }); - assertThrows(IllegalArgumentException.class, () -> { - // null state store name - client.getState(null, key, String.class).block(); - }); - assertThrows(IllegalArgumentException.class, () -> { - // null key - client.getState(STATE_STORE_NAME, (String)null, String.class).block(); - }); - assertThrows(IllegalArgumentException.class, () -> { - // empty key - client.getState(STATE_STORE_NAME, "", String.class).block(); - }); - } - @Test public void getStateExceptionThrownTest() { doAnswer((Answer) invocation -> { throw new RuntimeException(); - }).when(daprStub).getState(any(DaprProtos.GetStateRequest.class), any()); + }).when(daprStub).getState(any(DaprStateProtos.GetStateRequest.class), any()); State key = buildStateKey(null, "Key1", "ETag1", null); Mono> result = client.getState(STATE_STORE_NAME, key, String.class); @@ -502,10 +515,10 @@ public void getStateExceptionThrownTest() { public void getStateCallbackExceptionThrownTest() { RuntimeException ex = new RuntimeException("An Exception"); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onError(ex); return null; - }).when(daprStub).getState(any(DaprProtos.GetStateRequest.class), any()); + }).when(daprStub).getState(any(DaprStateProtos.GetStateRequest.class), any()); State key = buildStateKey(null, "Key1", "ETag1", null); Mono> result = client.getState(STATE_STORE_NAME, key, String.class); @@ -523,13 +536,13 @@ public void getStateStringValueNoOptionsTest() throws IOException { String key = "key1"; String expectedValue = "Expected state"; State expectedState = buildStateKey(expectedValue, key, etag, new HashMap<>(), null); - DaprProtos.GetStateResponse responseEnvelope = buildGetStateResponse(expectedValue, etag); + DaprStateProtos.GetStateResponse responseEnvelope = buildGetStateResponse(expectedValue, etag); doAnswer(invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getState(any(DaprProtos.GetStateRequest.class), any()); + }).when(daprStub).getState(any(DaprStateProtos.GetStateRequest.class), any()); State keyRequest = buildStateKey(null, key, etag, null); Mono> result = client.getState(STATE_STORE_NAME, keyRequest, String.class); @@ -545,14 +558,14 @@ public void getStateStringValueNoHotMono() throws IOException { String etag = "ETag1"; String key = "key1"; String expectedValue = "Expected state"; - DaprProtos.GetStateResponse responseEnvelope = buildGetStateResponse(expectedValue, etag); + DaprStateProtos.GetStateResponse responseEnvelope = buildGetStateResponse(expectedValue, etag); doAnswer((Answer) invocation -> { called.set(true); - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getState(any(DaprProtos.GetStateRequest.class), any()); + }).when(daprStub).getState(any(DaprStateProtos.GetStateRequest.class), any()); State keyRequest = buildStateKey(null, key, etag, null); client.getState(STATE_STORE_NAME, keyRequest, String.class); @@ -567,17 +580,17 @@ public void getStateObjectValueWithOptionsTest() throws IOException { MyObject expectedValue = new MyObject(1, "The Value"); StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE); State expectedState = buildStateKey(expectedValue, key, etag, new HashMap<>(), options); - DaprProtos.GetStateResponse responseEnvelope = DaprProtos.GetStateResponse.newBuilder() + DaprStateProtos.GetStateResponse responseEnvelope = DaprStateProtos.GetStateResponse.newBuilder() .setData(serialize(expectedValue)) .setEtag(etag) .build(); State keyRequest = buildStateKey(null, key, etag, new HashMap<>(), options); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getState(any(DaprProtos.GetStateRequest.class), any()); + }).when(daprStub).getState(any(DaprStateProtos.GetStateRequest.class), any()); Mono> result = client.getState(STATE_STORE_NAME, keyRequest, MyObject.class); State res = result.block(); @@ -586,6 +599,33 @@ public void getStateObjectValueWithOptionsTest() throws IOException { assertEquals(expectedState, res); } + @Test + public void getStatesIllegalArgumentExceptionTest() { + State key = buildStateKey(null, "Key1", "ETag1", null); + assertThrows(IllegalArgumentException.class, () -> { + // empty state store name + client.getBulkState("", Collections.singletonList("100"), String.class).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + // null state store name + client.getBulkState(null, Collections.singletonList("100"), String.class).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + // null key + // null pointer exception due to keys being converted to an unmodifiable list + client.getBulkState(STATE_STORE_NAME, null, String.class).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + // empty key list + client.getBulkState(STATE_STORE_NAME, Collections.emptyList(), String.class).block(); + }); + // negative parallelism + GetBulkStateRequest req = new GetBulkStateRequest(STATE_STORE_NAME, Collections.singletonList("100")) + .setMetadata(new HashMap<>()) + .setParallelism(-1); + assertThrows(IllegalArgumentException.class, () -> client.getBulkState(req, TypeRef.BOOLEAN).block()); + } + @Test public void getStateObjectValueWithMetadataTest() throws IOException { String etag = "ETag1"; @@ -595,7 +635,7 @@ public void getStateObjectValueWithMetadataTest() throws IOException { Map metadata = new HashMap<>(); metadata.put("key_1", "val_1"); State expectedState = buildStateKey(expectedValue, key, etag, new HashMap<>(), options); - DaprProtos.GetStateResponse responseEnvelope = DaprProtos.GetStateResponse.newBuilder() + DaprStateProtos.GetStateResponse responseEnvelope = DaprStateProtos.GetStateResponse.newBuilder() .setData(serialize(expectedValue)) .setEtag(etag) .build(); @@ -603,11 +643,11 @@ public void getStateObjectValueWithMetadataTest() throws IOException { .setMetadata(metadata) .setStateOptions(options); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getState(any(DaprProtos.GetStateRequest.class), any()); + }).when(daprStub).getState(any(DaprStateProtos.GetStateRequest.class), any()); Mono> result = client.getState(request, TypeRef.get(MyObject.class)); State res = result.block(); @@ -622,73 +662,46 @@ public void getStateObjectValueWithOptionsNoConcurrencyTest() throws IOException MyObject expectedValue = new MyObject(1, "The Value"); StateOptions options = new StateOptions(null, StateOptions.Concurrency.FIRST_WRITE); State expectedState = buildStateKey(expectedValue, key, etag, new HashMap<>(), options); - DaprProtos.GetStateResponse responseEnvelope = DaprProtos.GetStateResponse.newBuilder() + DaprStateProtos.GetStateResponse responseEnvelope = DaprStateProtos.GetStateResponse.newBuilder() .setData(serialize(expectedValue)) .setEtag(etag) .build(); State keyRequest = buildStateKey(null, key, etag, new HashMap<>(), options); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getState(any(DaprProtos.GetStateRequest.class), any()); + }).when(daprStub).getState(any(DaprStateProtos.GetStateRequest.class), any()); Mono> result = client.getState(STATE_STORE_NAME, keyRequest, MyObject.class); assertEquals(expectedState, result.block()); } - @Test - public void getStatesIllegalArgumentExceptionTest() { - State key = buildStateKey(null, "Key1", "ETag1", null); - assertThrows(IllegalArgumentException.class, () -> { - // empty state store name - client.getBulkState("", Collections.singletonList("100"), String.class).block(); - }); - assertThrows(IllegalArgumentException.class, () -> { - // null state store name - client.getBulkState(null, Collections.singletonList("100"), String.class).block(); - }); - assertThrows(IllegalArgumentException.class, () -> { - // null key - // null pointer exception due to keys being converted to an unmodifiable list - client.getBulkState(STATE_STORE_NAME, null, String.class).block(); - }); - assertThrows(IllegalArgumentException.class, () -> { - // empty key list - client.getBulkState(STATE_STORE_NAME, Collections.emptyList(), String.class).block(); - }); - // negative parallelism - GetBulkStateRequest req = new GetBulkStateRequest(STATE_STORE_NAME, Collections.singletonList("100")) - .setMetadata(new HashMap<>()) - .setParallelism(-1); - assertThrows(IllegalArgumentException.class, () -> client.getBulkState(req, TypeRef.BOOLEAN).block()); - } - @Test public void getStatesString() throws IOException { Map metadata = new HashMap<>(); metadata.put("meta1", "value1"); metadata.put("meta2", "value2"); - DaprProtos.GetBulkStateResponse responseEnvelope = DaprProtos.GetBulkStateResponse.newBuilder() - .addItems(DaprProtos.BulkStateItem.newBuilder() + DaprStateProtos.GetBulkStateResponse responseEnvelope = DaprStateProtos.GetBulkStateResponse.newBuilder() + .addItems(DaprStateProtos.BulkStateItem.newBuilder() .setData(serialize("hello world")) .setKey("100") .putAllMetadata(metadata) .setEtag("1") .build()) - .addItems(DaprProtos.BulkStateItem.newBuilder() + .addItems(DaprStateProtos.BulkStateItem.newBuilder() .setKey("200") .setError("not found") .build()) .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getBulkState(any(DaprProtos.GetBulkStateRequest.class), any()); + }).when(daprStub).getBulkState(any(DaprStateProtos.GetBulkStateRequest.class), any()); List> result = client.getBulkState(STATE_STORE_NAME, Arrays.asList("100", "200"), String.class).block(); @@ -708,24 +721,24 @@ public void getStatesString() throws IOException { public void getStatesInteger() throws IOException { Map metadata = new HashMap<>(); metadata.put("meta1", "value1"); - DaprProtos.GetBulkStateResponse responseEnvelope = DaprProtos.GetBulkStateResponse.newBuilder() - .addItems(DaprProtos.BulkStateItem.newBuilder() + DaprStateProtos.GetBulkStateResponse responseEnvelope = DaprStateProtos.GetBulkStateResponse.newBuilder() + .addItems(DaprStateProtos.BulkStateItem.newBuilder() .setData(serialize(1234)) .setKey("100") .putAllMetadata(metadata) .setEtag("1") .build()) - .addItems(DaprProtos.BulkStateItem.newBuilder() + .addItems(DaprStateProtos.BulkStateItem.newBuilder() .setKey("200") .setError("not found") .build()) .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getBulkState(any(DaprProtos.GetBulkStateRequest.class), any()); + }).when(daprStub).getBulkState(any(DaprStateProtos.GetBulkStateRequest.class), any()); List> result = client.getBulkState(STATE_STORE_NAME, Arrays.asList("100", "200"), int.class).block(); assertEquals(2, result.size()); @@ -744,24 +757,24 @@ public void getStatesInteger() throws IOException { public void getStatesBoolean() throws IOException { Map metadata = new HashMap<>(); metadata.put("meta1", "value1"); - DaprProtos.GetBulkStateResponse responseEnvelope = DaprProtos.GetBulkStateResponse.newBuilder() - .addItems(DaprProtos.BulkStateItem.newBuilder() + DaprStateProtos.GetBulkStateResponse responseEnvelope = DaprStateProtos.GetBulkStateResponse.newBuilder() + .addItems(DaprStateProtos.BulkStateItem.newBuilder() .setData(serialize(true)) .setKey("100") .putAllMetadata(metadata) .setEtag("1") .build()) - .addItems(DaprProtos.BulkStateItem.newBuilder() + .addItems(DaprStateProtos.BulkStateItem.newBuilder() .setKey("200") .setError("not found") .build()) .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getBulkState(any(DaprProtos.GetBulkStateRequest.class), any()); + }).when(daprStub).getBulkState(any(DaprStateProtos.GetBulkStateRequest.class), any()); List> result = client.getBulkState(STATE_STORE_NAME, Arrays.asList("100", "200"), boolean.class).block(); @@ -780,24 +793,24 @@ public void getStatesBoolean() throws IOException { @Test public void getStatesByteArray() throws IOException { Map metadata = new HashMap<>(); - DaprProtos.GetBulkStateResponse responseEnvelope = DaprProtos.GetBulkStateResponse.newBuilder() - .addItems(DaprProtos.BulkStateItem.newBuilder() + DaprStateProtos.GetBulkStateResponse responseEnvelope = DaprStateProtos.GetBulkStateResponse.newBuilder() + .addItems(DaprStateProtos.BulkStateItem.newBuilder() .setData(serialize(new byte[]{1, 2, 3})) .setKey("100") .putAllMetadata(metadata) .setEtag("1") .build()) - .addItems(DaprProtos.BulkStateItem.newBuilder() + .addItems(DaprStateProtos.BulkStateItem.newBuilder() .setKey("200") .setError("not found") .build()) .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getBulkState(any(DaprProtos.GetBulkStateRequest.class), any()); + }).when(daprStub).getBulkState(any(DaprStateProtos.GetBulkStateRequest.class), any()); List> result = client.getBulkState(STATE_STORE_NAME, Arrays.asList("100", "200"), byte[].class).block(); @@ -813,26 +826,47 @@ public void getStatesByteArray() throws IOException { assertEquals("not found", result.stream().skip(1).findFirst().get().getError()); } + @Test + public void deleteStateIllegalArgumentExceptionTest() { + State key = buildStateKey(null, "Key1", "ETag1", null); + assertThrows(IllegalArgumentException.class, () -> { + // empty state store name + client.deleteState("", key.getKey(), "etag", null).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + // null state store name + client.deleteState(null, key.getKey(), "etag", null).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + // null state store name + client.deleteState(STATE_STORE_NAME, null, "etag", null).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + // null state store name + client.deleteState(STATE_STORE_NAME, "", "etag", null).block(); + }); + } + @Test public void getStatesObject() throws IOException { MyObject object = new MyObject(1, "Event"); - DaprProtos.GetBulkStateResponse responseEnvelope = DaprProtos.GetBulkStateResponse.newBuilder() - .addItems(DaprProtos.BulkStateItem.newBuilder() + DaprStateProtos.GetBulkStateResponse responseEnvelope = DaprStateProtos.GetBulkStateResponse.newBuilder() + .addItems(DaprStateProtos.BulkStateItem.newBuilder() .setData(serialize(object)) .setKey("100") .setEtag("1") .build()) - .addItems(DaprProtos.BulkStateItem.newBuilder() + .addItems(DaprStateProtos.BulkStateItem.newBuilder() .setKey("200") .setError("not found") .build()) .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getBulkState(any(DaprProtos.GetBulkStateRequest.class), any()); + }).when(daprStub).getBulkState(any(DaprStateProtos.GetBulkStateRequest.class), any()); List> result = client.getBulkState(STATE_STORE_NAME, Arrays.asList("100", "200"), MyObject.class).block(); @@ -852,7 +886,7 @@ public void getStatesObject() throws IOException { public void deleteStateExceptionThrowTest() { doAnswer((Answer) invocation -> { throw new RuntimeException(); - }).when(daprStub).deleteState(any(DaprProtos.DeleteStateRequest.class), any()); + }).when(daprStub).deleteState(any(DaprStateProtos.DeleteStateRequest.class), any()); State key = buildStateKey(null, "Key1", "ETag1", null); Mono result = client.deleteState(STATE_STORE_NAME, key.getKey(), key.getEtag(), key.getOptions()); @@ -864,27 +898,6 @@ public void deleteStateExceptionThrowTest() { () -> result.block()); } - @Test - public void deleteStateIllegalArgumentExceptionTest() { - State key = buildStateKey(null, "Key1", "ETag1", null); - assertThrows(IllegalArgumentException.class, () -> { - // empty state store name - client.deleteState("", key.getKey(), "etag", null).block(); - }); - assertThrows(IllegalArgumentException.class, () -> { - // null state store name - client.deleteState(null, key.getKey(), "etag", null).block(); - }); - assertThrows(IllegalArgumentException.class, () -> { - // null state store name - client.deleteState(STATE_STORE_NAME, null, "etag", null).block(); - }); - assertThrows(IllegalArgumentException.class, () -> { - // null state store name - client.deleteState(STATE_STORE_NAME, "", "etag", null).block(); - }); - } - @Test public void deleteStateCallbackExcpetionThrownTest() { RuntimeException ex = new RuntimeException("An Exception"); @@ -892,7 +905,7 @@ public void deleteStateCallbackExcpetionThrownTest() { StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onError(ex); return null; - }).when(daprStub).deleteState(any(DaprProtos.DeleteStateRequest.class), any()); + }).when(daprStub).deleteState(any(DaprStateProtos.DeleteStateRequest.class), any()); State key = buildStateKey(null, "Key1", "ETag1", null); Mono result = client.deleteState(STATE_STORE_NAME, key.getKey(), key.getEtag(), key.getOptions()); @@ -913,7 +926,7 @@ public void deleteStateNoOptionsTest() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).deleteState(any(DaprProtos.DeleteStateRequest.class), any()); + }).when(daprStub).deleteState(any(DaprStateProtos.DeleteStateRequest.class), any()); State stateKey = buildStateKey(null, key, etag, null); Mono result = client.deleteState(STATE_STORE_NAME, stateKey.getKey(), stateKey.getEtag(), @@ -931,7 +944,7 @@ public void deleteStateTest() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).deleteState(any(DaprProtos.DeleteStateRequest.class), any()); + }).when(daprStub).deleteState(any(DaprStateProtos.DeleteStateRequest.class), any()); State stateKey = buildStateKey(null, key, etag, options); Mono result = client.deleteState(STATE_STORE_NAME, stateKey.getKey(), stateKey.getEtag(), @@ -951,7 +964,7 @@ public void deleteStateWithMetadata() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).deleteState(any(DaprProtos.DeleteStateRequest.class), any()); + }).when(daprStub).deleteState(any(DaprStateProtos.DeleteStateRequest.class), any()); DeleteStateRequest request = new DeleteStateRequest(STATE_STORE_NAME, key); request.setEtag(etag) @@ -973,7 +986,7 @@ public void deleteStateTestNoHotMono() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).deleteState(any(DaprProtos.DeleteStateRequest.class), any()); + }).when(daprStub).deleteState(any(DaprStateProtos.DeleteStateRequest.class), any()); State stateKey = buildStateKey(null, key, etag, options); client.deleteState(STATE_STORE_NAME, stateKey.getKey(), stateKey.getEtag(), @@ -982,6 +995,22 @@ public void deleteStateTestNoHotMono() { assertFalse(called.get()); } + @Test + public void executeTransactionIllegalArgumentExceptionTest() { + State key = buildStateKey(null, "Key1", "ETag1", null); + TransactionalStateOperation upsertOperation = new TransactionalStateOperation<>( + TransactionalStateOperation.OperationType.UPSERT, + key); + assertThrows(IllegalArgumentException.class, () -> { + // empty state store name + client.executeStateTransaction("", Collections.singletonList(upsertOperation)).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + // null state store name + client.executeStateTransaction(null, Collections.singletonList(upsertOperation)).block(); + }); + } + @Test public void deleteStateNoConsistencyTest() { String etag = "ETag1"; @@ -992,7 +1021,7 @@ public void deleteStateNoConsistencyTest() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).deleteState(any(DaprProtos.DeleteStateRequest.class), any()); + }).when(daprStub).deleteState(any(DaprStateProtos.DeleteStateRequest.class), any()); State stateKey = buildStateKey(null, key, etag, options); Mono result = client.deleteState(STATE_STORE_NAME, stateKey.getKey(), stateKey.getEtag(), @@ -1010,7 +1039,7 @@ public void deleteStateNoConcurrencyTest() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).deleteState(any(DaprProtos.DeleteStateRequest.class), any()); + }).when(daprStub).deleteState(any(DaprStateProtos.DeleteStateRequest.class), any()); State stateKey = buildStateKey(null, key, etag, options); Mono result = client.deleteState(STATE_STORE_NAME, stateKey.getKey(), stateKey.getEtag(), @@ -1018,22 +1047,6 @@ public void deleteStateNoConcurrencyTest() { result.block(); } - @Test - public void executeTransactionIllegalArgumentExceptionTest() { - State key = buildStateKey(null, "Key1", "ETag1", null); - TransactionalStateOperation upsertOperation = new TransactionalStateOperation<>( - TransactionalStateOperation.OperationType.UPSERT, - key); - assertThrows(IllegalArgumentException.class, () -> { - // empty state store name - client.executeStateTransaction("", Collections.singletonList(upsertOperation)).block(); - }); - assertThrows(IllegalArgumentException.class, () -> { - // null state store name - client.executeStateTransaction(null, Collections.singletonList(upsertOperation)).block(); - }); - } - @Test public void executeTransactionSerializerExceptionTest() throws IOException { DaprObjectSerializer mockSerializer = mock(DaprObjectSerializer.class); @@ -1047,7 +1060,7 @@ public void executeTransactionSerializerExceptionTest() throws IOException { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).executeStateTransaction(any(DaprProtos.ExecuteStateTransactionRequest.class), any()); + }).when(daprStub).executeStateTransaction(any(DaprStateProtos.ExecuteStateTransactionRequest.class), any()); when(mockSerializer.serialize(any())).thenThrow(IOException.class); @@ -1077,7 +1090,7 @@ public void executeTransactionWithMetadataTest() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).executeStateTransaction(any(DaprProtos.ExecuteStateTransactionRequest.class), any()); + }).when(daprStub).executeStateTransaction(any(DaprStateProtos.ExecuteStateTransactionRequest.class), any()); State stateKey = buildStateKey(data, key, etag, options); TransactionalStateOperation upsertOperation = new TransactionalStateOperation<>( @@ -1106,7 +1119,7 @@ public void executeTransactionTest() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).executeStateTransaction(any(DaprProtos.ExecuteStateTransactionRequest.class), any()); + }).when(daprStub).executeStateTransaction(any(DaprStateProtos.ExecuteStateTransactionRequest.class), any()); State stateKey = buildStateKey(data, key, etag, options); TransactionalStateOperation upsertOperation = new TransactionalStateOperation<>( @@ -1120,6 +1133,18 @@ public void executeTransactionTest() { result.block(); } + @Test + public void saveStatesIllegalArgumentExceptionTest() { + assertThrows(IllegalArgumentException.class, () -> { + // empty state store name + client.saveBulkState("", Collections.emptyList()).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + // empty state store name + client.saveBulkState(null, Collections.emptyList()).block(); + }); + } + @Test public void executeTransactionExceptionThrownTest() { String etag = "ETag1"; @@ -1128,7 +1153,7 @@ public void executeTransactionExceptionThrownTest() { StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, null); doAnswer((Answer) invocation -> { throw new RuntimeException(); - }).when(daprStub).executeStateTransaction(any(DaprProtos.ExecuteStateTransactionRequest.class), any()); + }).when(daprStub).executeStateTransaction(any(DaprStateProtos.ExecuteStateTransactionRequest.class), any()); State stateKey = buildStateKey(data, key, etag, options); TransactionalStateOperation operation = new TransactionalStateOperation<>( @@ -1154,7 +1179,7 @@ public void executeTransactionCallbackExceptionTest() { StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onError(ex); return null; - }).when(daprStub).executeStateTransaction(any(DaprProtos.ExecuteStateTransactionRequest.class), any()); + }).when(daprStub).executeStateTransaction(any(DaprStateProtos.ExecuteStateTransactionRequest.class), any()); State stateKey = buildStateKey(data, key, etag, options); TransactionalStateOperation operation = new TransactionalStateOperation<>( @@ -1169,25 +1194,13 @@ public void executeTransactionCallbackExceptionTest() { () -> result.block()); } - @Test - public void saveStatesIllegalArgumentExceptionTest() { - assertThrows(IllegalArgumentException.class, () -> { - // empty state store name - client.saveBulkState("", Collections.emptyList()).block(); - }); - assertThrows(IllegalArgumentException.class, () -> { - // empty state store name - client.saveBulkState(null, Collections.emptyList()).block(); - }); - } - @Test public void saveBulkStateTestNullEtag() { List> states = new ArrayList>(); states.add(new State("null_etag_key", "null_etag_value", null, (StateOptions)null)); states.add(new State("empty_etag_key", "empty_etag_value", "", (StateOptions)null)); - ArgumentCaptor argument = ArgumentCaptor.forClass(DaprProtos.SaveStateRequest.class); + ArgumentCaptor argument = ArgumentCaptor.forClass(DaprStateProtos.SaveStateRequest.class); doAnswer((Answer) invocation -> { StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(Empty.getDefaultInstance()); @@ -1211,7 +1224,7 @@ public void saveStateExceptionThrownTest() { String value = "State value"; doAnswer((Answer) invocation -> { throw new RuntimeException(); - }).when(daprStub).saveState(any(DaprProtos.SaveStateRequest.class), any()); + }).when(daprStub).saveState(any(DaprStateProtos.SaveStateRequest.class), any()); Mono result = client.saveState(STATE_STORE_NAME, key, etag, value, null); @@ -1232,7 +1245,7 @@ public void saveStateCallbackExceptionThrownTest() { StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onError(ex); return null; - }).when(daprStub).saveState(any(DaprProtos.SaveStateRequest.class), any()); + }).when(daprStub).saveState(any(DaprStateProtos.SaveStateRequest.class), any()); Mono result = client.saveState(STATE_STORE_NAME, key, etag, value, null); @@ -1253,7 +1266,7 @@ public void saveStateNoOptionsTest() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).saveState(any(DaprProtos.SaveStateRequest.class), any()); + }).when(daprStub).saveState(any(DaprStateProtos.SaveStateRequest.class), any()); Mono result = client.saveState(STATE_STORE_NAME, key, etag, value, null); @@ -1267,7 +1280,7 @@ public void saveStateWithMetaTest() { String value = "State value"; Map metadata = new HashMap<>(); metadata.put("custom", "customValue"); - ArgumentCaptor argument = ArgumentCaptor.forClass(DaprProtos.SaveStateRequest.class); + ArgumentCaptor argument = ArgumentCaptor.forClass(DaprStateProtos.SaveStateRequest.class); doAnswer((Answer) invocation -> { StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(Empty.getDefaultInstance()); @@ -1287,7 +1300,7 @@ public void saveStateWithMetaContentTypeTest() { String etag = "ETag1"; String value = "State value"; Map metadata = new HashMap<>(); - ArgumentCaptor argument = ArgumentCaptor.forClass(DaprProtos.SaveStateRequest.class); + ArgumentCaptor argument = ArgumentCaptor.forClass(DaprStateProtos.SaveStateRequest.class); doAnswer((Answer) invocation -> { StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(Empty.getDefaultInstance()); @@ -1305,7 +1318,7 @@ public void saveStateWithMetaContentTypeTest() { public void saveStateWithMetaEmptyTest() { String key = "key1"; String etag = "ETag1"; - ArgumentCaptor argument = ArgumentCaptor.forClass(DaprProtos.SaveStateRequest.class); + ArgumentCaptor argument = ArgumentCaptor.forClass(DaprStateProtos.SaveStateRequest.class); doAnswer((Answer) invocation -> { StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(Empty.getDefaultInstance()); @@ -1328,7 +1341,7 @@ public void saveStateTest() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).saveState(any(DaprProtos.SaveStateRequest.class), any()); + }).when(daprStub).saveState(any(DaprStateProtos.SaveStateRequest.class), any()); StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE); Mono result = client.saveState(STATE_STORE_NAME, key, etag, value, options); @@ -1340,7 +1353,7 @@ public void saveStateTestNullEtag() { String key = "key1"; String etag = null; String value = "State value"; - ArgumentCaptor argument = ArgumentCaptor.forClass(DaprProtos.SaveStateRequest.class); + ArgumentCaptor argument = ArgumentCaptor.forClass(DaprStateProtos.SaveStateRequest.class); doAnswer((Answer) invocation -> { StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(Empty.getDefaultInstance()); @@ -1367,7 +1380,7 @@ public void saveStateTestNoHotMono() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).saveState(any(DaprProtos.SaveStateRequest.class), any()); + }).when(daprStub).saveState(any(DaprStateProtos.SaveStateRequest.class), any()); StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE); client.saveState(STATE_STORE_NAME, key, etag, value, options); @@ -1385,13 +1398,21 @@ public void saveStateNoConsistencyTest() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).saveState(any(DaprProtos.SaveStateRequest.class), any()); + }).when(daprStub).saveState(any(DaprStateProtos.SaveStateRequest.class), any()); StateOptions options = buildStateOptions(null, StateOptions.Concurrency.FIRST_WRITE); Mono result = client.saveState(STATE_STORE_NAME, key, etag, value, options); result.block(); } + private State buildStateKey(T value, String key, String etag, StateOptions options) { + return new State<>(key, value, etag, options); + } + + private State buildStateKey(T value, String key, String etag, Map metadata, StateOptions options) { + return new State<>(key, value, etag, metadata, options); + } + @Test public void saveStateNoConcurrencyTest() { String key = "key1"; @@ -1402,7 +1423,7 @@ public void saveStateNoConcurrencyTest() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).saveState(any(DaprProtos.SaveStateRequest.class), any()); + }).when(daprStub).saveState(any(DaprStateProtos.SaveStateRequest.class), any()); StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, null); Mono result = client.saveState(STATE_STORE_NAME, key, etag, value, options); @@ -1419,21 +1440,13 @@ public void saveStateNoRetryPolicyTest() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).saveState(any(DaprProtos.SaveStateRequest.class), any()); + }).when(daprStub).saveState(any(DaprStateProtos.SaveStateRequest.class), any()); StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE); Mono result = client.saveState(STATE_STORE_NAME, key, etag, value, options); result.block(); } - private State buildStateKey(T value, String key, String etag, StateOptions options) { - return new State<>(key, value, etag, options); - } - - private State buildStateKey(T value, String key, String etag, Map metadata, StateOptions options) { - return new State<>(key, value, etag, metadata, options); - } - /** * The purpose of this test is to show that it doesn't matter when the client is called, the actual coll to DAPR * will be done when the output Mono response call the Mono.block method. @@ -1463,18 +1476,18 @@ public void getStateThenDelete() throws Exception { String expectedValue2 = "Expected state 2"; State expectedState1 = buildStateKey(expectedValue1, key1, etag, new HashMap<>(), null); State expectedState2 = buildStateKey(expectedValue2, key2, etag, new HashMap<>(), null); - Map futuresMap = new HashMap<>(); + Map futuresMap = new HashMap<>(); futuresMap.put(key1, buildFutureGetStateEnvelop(expectedValue1, etag)); futuresMap.put(key2, buildFutureGetStateEnvelop(expectedValue2, etag)); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(futuresMap.get(key1)); observer.onCompleted(); return null; }).when(daprStub).getState(argThat(new GetStateRequestKeyMatcher(key1)), any()); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(futuresMap.get(key2)); observer.onCompleted(); return null; @@ -1492,7 +1505,7 @@ public void getStateThenDelete() throws Exception { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).deleteState(any(io.dapr.v1.DaprProtos.DeleteStateRequest.class), any()); + }).when(daprStub).deleteState(any(io.dapr.v1.DaprStateProtos.DeleteStateRequest.class), any()); Mono resultDelete = client.deleteState(STATE_STORE_NAME, keyRequest2.getKey(), keyRequest2.getEtag(), keyRequest2.getOptions()); @@ -1503,7 +1516,7 @@ public void getStateThenDelete() throws Exception { public void deleteStateNullEtag() { String key = "key1"; String etag = null; - ArgumentCaptor argument = ArgumentCaptor.forClass(DaprProtos.DeleteStateRequest.class); + ArgumentCaptor argument = ArgumentCaptor.forClass(DaprStateProtos.DeleteStateRequest.class); doAnswer((Answer) invocation -> { StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(Empty.getDefaultInstance()); @@ -1524,13 +1537,13 @@ public void getStateNullEtag() throws Exception { String key1 = "key1"; String expectedValue1 = "Expected state 1"; State expectedState1 = buildStateKey(expectedValue1, key1, etag, new HashMap<>(), null); - Map futuresMap = new HashMap<>(); - DaprProtos.GetStateResponse envelope = DaprProtos.GetStateResponse.newBuilder() + Map futuresMap = new HashMap<>(); + DaprStateProtos.GetStateResponse envelope = DaprStateProtos.GetStateResponse.newBuilder() .setData(serialize(expectedValue1)) .build(); futuresMap.put(key1, envelope); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(futuresMap.get(key1)); observer.onCompleted(); return null; @@ -1543,23 +1556,23 @@ public void getStateNullEtag() throws Exception { @Test public void getBulkStateNullEtag() throws Exception { - DaprProtos.GetBulkStateResponse responseEnvelope = DaprProtos.GetBulkStateResponse.newBuilder() - .addItems(DaprProtos.BulkStateItem.newBuilder() + DaprStateProtos.GetBulkStateResponse responseEnvelope = DaprStateProtos.GetBulkStateResponse.newBuilder() + .addItems(DaprStateProtos.BulkStateItem.newBuilder() .setData(serialize("hello world")) .setKey("100") .build()) - .addItems(DaprProtos.BulkStateItem.newBuilder() + .addItems(DaprStateProtos.BulkStateItem.newBuilder() .setKey("200") .setEtag("") .setError("not found") .build()) .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getBulkState(any(DaprProtos.GetBulkStateRequest.class), any()); + }).when(daprStub).getBulkState(any(DaprStateProtos.GetBulkStateRequest.class), any()); List> result = client.getBulkState(STATE_STORE_NAME, Arrays.asList("100", "200"), String.class).block(); @@ -1578,19 +1591,19 @@ public void getBulkStateNullEtag() throws Exception { public void getSecrets() { String expectedKey = "attributeKey"; String expectedValue = "Expected secret value"; - DaprProtos.GetSecretResponse responseEnvelope = buildGetSecretResponse(expectedKey, expectedValue); + DaprSecretProtos.GetSecretResponse responseEnvelope = buildGetSecretResponse(expectedKey, expectedValue); doAnswer((Answer) invocation -> { - DaprProtos.GetSecretRequest req = invocation.getArgument(0); + DaprSecretProtos.GetSecretRequest req = invocation.getArgument(0); assertEquals("key", req.getKey()); assertEquals(SECRET_STORE_NAME, req.getStoreName()); assertEquals(0, req.getMetadataCount()); - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getSecret(any(DaprProtos.GetSecretRequest.class), any()); + }).when(daprStub).getSecret(any(DaprSecretProtos.GetSecretRequest.class), any()); Map result = client.getSecret(SECRET_STORE_NAME, "key").block(); @@ -1598,21 +1611,41 @@ public void getSecrets() { assertEquals(expectedValue, result.get(expectedKey)); } + @Test + public void getSecretsIllegalArgumentException() { + assertThrows(IllegalArgumentException.class, () -> { + // empty secret store name + client.getSecret("", "key").block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + // null secret store name + client.getSecret(null, "key").block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + // empty key + client.getSecret(SECRET_STORE_NAME, "").block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + // null key + client.getSecret(SECRET_STORE_NAME, null).block(); + }); + } + @Test public void getSecretsEmptyResponse() { - DaprProtos.GetSecretResponse responseEnvelope = buildGetSecretResponse(); + DaprSecretProtos.GetSecretResponse responseEnvelope = buildGetSecretResponse(); doAnswer((Answer) invocation -> { - DaprProtos.GetSecretRequest req = invocation.getArgument(0); + DaprSecretProtos.GetSecretRequest req = invocation.getArgument(0); assertEquals("key", req.getKey()); assertEquals(SECRET_STORE_NAME, req.getStoreName()); assertEquals(0, req.getMetadataCount()); - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getSecret(any(DaprProtos.GetSecretRequest.class), any()); + }).when(daprStub).getSecret(any(DaprSecretProtos.GetSecretRequest.class), any()); Map result = client.getSecret(SECRET_STORE_NAME, "key").block(); @@ -1622,55 +1655,35 @@ public void getSecretsEmptyResponse() { @Test public void getSecretsException() { doAnswer((Answer) invocation -> { - DaprProtos.GetSecretRequest req = invocation.getArgument(0); + DaprSecretProtos.GetSecretRequest req = invocation.getArgument(0); assertEquals("key", req.getKey()); assertEquals(SECRET_STORE_NAME, req.getStoreName()); assertEquals(0, req.getMetadataCount()); - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onError(new RuntimeException()); return null; - }).when(daprStub).getSecret(any(DaprProtos.GetSecretRequest.class), any()); + }).when(daprStub).getSecret(any(DaprSecretProtos.GetSecretRequest.class), any()); assertThrowsDaprException(ExecutionException.class, () -> client.getSecret(SECRET_STORE_NAME, "key").block()); } - @Test - public void getSecretsIllegalArgumentException() { - assertThrows(IllegalArgumentException.class, () -> { - // empty secret store name - client.getSecret("", "key").block(); - }); - assertThrows(IllegalArgumentException.class, () -> { - // null secret store name - client.getSecret(null, "key").block(); - }); - assertThrows(IllegalArgumentException.class, () -> { - // empty key - client.getSecret(SECRET_STORE_NAME, "").block(); - }); - assertThrows(IllegalArgumentException.class, () -> { - // null key - client.getSecret(SECRET_STORE_NAME, null).block(); - }); - } - @Test public void getSecretsWithMetadata() { String expectedKey = "attributeKey"; String expectedValue = "Expected secret value"; - DaprProtos.GetSecretResponse responseEnvelope = buildGetSecretResponse(expectedKey, expectedValue); + DaprSecretProtos.GetSecretResponse responseEnvelope = buildGetSecretResponse(expectedKey, expectedValue); doAnswer((Answer) invocation -> { - DaprProtos.GetSecretRequest req = invocation.getArgument(0); + DaprSecretProtos.GetSecretRequest req = invocation.getArgument(0); assertEquals("key", req.getKey()); assertEquals(SECRET_STORE_NAME, req.getStoreName()); assertEquals("metavalue", req.getMetadataMap().get("metakey")); - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getSecret(any(DaprProtos.GetSecretRequest.class), any()); + }).when(daprStub).getSecret(any(DaprSecretProtos.GetSecretRequest.class), any()); Map result = client.getSecret( SECRET_STORE_NAME, @@ -1681,9 +1694,16 @@ public void getSecretsWithMetadata() { assertEquals(expectedValue, result.get(expectedKey)); } + @Test + public void getConfigurationTestErrorScenario() { + assertThrows(IllegalArgumentException.class, () -> { + client.getConfiguration("", "key").block(); + }); + } + @Test public void getBulkSecrets() { - DaprProtos.GetBulkSecretResponse responseEnvelope = buildGetBulkSecretResponse( + DaprSecretProtos.GetBulkSecretResponse responseEnvelope = buildGetBulkSecretResponse( new HashMap>() {{ put("one", Collections.singletonMap("mysecretkey", "mysecretvalue")); put("two", new HashMap() {{ @@ -1693,16 +1713,16 @@ public void getBulkSecrets() { }}); doAnswer((Answer) invocation -> { - DaprProtos.GetBulkSecretRequest req = invocation.getArgument(0); + DaprSecretProtos.GetBulkSecretRequest req = invocation.getArgument(0); assertEquals(SECRET_STORE_NAME, req.getStoreName()); assertEquals(0, req.getMetadataCount()); - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getBulkSecret(any(DaprProtos.GetBulkSecretRequest.class), any()); + }).when(daprStub).getBulkSecret(any(DaprSecretProtos.GetBulkSecretRequest.class), any()); Map> secrets = client.getBulkSecret(SECRET_STORE_NAME).block(); @@ -1716,7 +1736,7 @@ public void getBulkSecrets() { @Test public void getBulkSecretsWithMetadata() { - DaprProtos.GetBulkSecretResponse responseEnvelope = buildGetBulkSecretResponse( + DaprSecretProtos.GetBulkSecretResponse responseEnvelope = buildGetBulkSecretResponse( new HashMap>() {{ put("one", Collections.singletonMap("mysecretkey", "mysecretvalue")); put("two", new HashMap() {{ @@ -1726,17 +1746,17 @@ public void getBulkSecretsWithMetadata() { }}); doAnswer((Answer) invocation -> { - DaprProtos.GetBulkSecretRequest req = invocation.getArgument(0); + DaprSecretProtos.GetBulkSecretRequest req = invocation.getArgument(0); assertEquals(SECRET_STORE_NAME, req.getStoreName()); assertEquals(1, req.getMetadataCount()); assertEquals("metavalue", req.getMetadataOrThrow("metakey")); - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getBulkSecret(any(DaprProtos.GetBulkSecretRequest.class), any()); + }).when(daprStub).getBulkSecret(any(DaprSecretProtos.GetBulkSecretRequest.class), any()); Map> secrets = client.getBulkSecret( SECRET_STORE_NAME, Collections.singletonMap("metakey", "metavalue")).block(); @@ -1749,22 +1769,15 @@ public void getBulkSecretsWithMetadata() { assertEquals("2", secrets.get("two").get("b")); } - @Test - public void getConfigurationTestErrorScenario() { - assertThrows(IllegalArgumentException.class, () -> { - client.getConfiguration("", "key").block(); - }); - } - @Test public void getSingleConfigurationTest() { doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(getSingleMockResponse()); observer.onCompleted(); return null; - }).when(daprStub).getConfiguration(any(DaprProtos.GetConfigurationRequest.class), any()); + }).when(daprStub).getConfiguration(any(DaprConfigurationProtos.GetConfigurationRequest.class), any()); ConfigurationItem ci = client.getConfiguration(CONFIG_STORE_NAME, "configkey1").block(); assertEquals("configvalue1", ci.getValue()); @@ -1774,12 +1787,12 @@ public void getSingleConfigurationTest() { @Test public void getSingleConfigurationWithMetadataTest() { doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(getSingleMockResponse()); observer.onCompleted(); return null; - }).when(daprStub).getConfiguration(any(DaprProtos.GetConfigurationRequest.class), any()); + }).when(daprStub).getConfiguration(any(DaprConfigurationProtos.GetConfigurationRequest.class), any()); Map reqMetadata = new HashMap<>(); reqMetadata.put("meta1", "value1"); @@ -1791,12 +1804,12 @@ public void getSingleConfigurationWithMetadataTest() { @Test public void getMultipleConfigurationTest() { doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(getMultipleMockResponse()); observer.onCompleted(); return null; - }).when(daprStub).getConfiguration(any(DaprProtos.GetConfigurationRequest.class), any()); + }).when(daprStub).getConfiguration(any(DaprConfigurationProtos.GetConfigurationRequest.class), any()); Map cis = client.getConfiguration(CONFIG_STORE_NAME, "configkey1","configkey2").block(); assertEquals(2, cis.size()); @@ -1811,12 +1824,12 @@ public void getMultipleConfigurationTest() { @Test public void getMultipleConfigurationWithMetadataTest() { doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(getMultipleMockResponse()); observer.onCompleted(); return null; - }).when(daprStub).getConfiguration(any(DaprProtos.GetConfigurationRequest.class), any()); + }).when(daprStub).getConfiguration(any(DaprConfigurationProtos.GetConfigurationRequest.class), any()); Map reqMetadata = new HashMap<>(); reqMetadata.put("meta1", "value1"); @@ -1837,18 +1850,18 @@ public void subscribeConfigurationTest() { .setVersion("1") .putAllMetadata(metadata) .build()); - DaprProtos.SubscribeConfigurationResponse responseEnvelope = DaprProtos.SubscribeConfigurationResponse.newBuilder() + DaprConfigurationProtos.SubscribeConfigurationResponse responseEnvelope = DaprConfigurationProtos.SubscribeConfigurationResponse.newBuilder() .putAllItems(configs) .setId("subscription_id") .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).subscribeConfiguration(any(DaprProtos.SubscribeConfigurationRequest.class), any()); + }).when(daprStub).subscribeConfiguration(any(DaprConfigurationProtos.SubscribeConfigurationRequest.class), any()); Iterator itr = client.subscribeConfiguration(CONFIG_STORE_NAME, "configkey1").toIterable().iterator(); assertTrue(itr.hasNext()); @@ -1868,18 +1881,18 @@ public void subscribeConfigurationTestWithMetadata() { .setVersion("1") .putAllMetadata(metadata) .build()); - DaprProtos.SubscribeConfigurationResponse responseEnvelope = DaprProtos.SubscribeConfigurationResponse.newBuilder() + DaprConfigurationProtos.SubscribeConfigurationResponse responseEnvelope = DaprConfigurationProtos.SubscribeConfigurationResponse.newBuilder() .putAllItems(configs) .setId("subscription_id") .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).subscribeConfiguration(any(DaprProtos.SubscribeConfigurationRequest.class), any()); + }).when(daprStub).subscribeConfiguration(any(DaprConfigurationProtos.SubscribeConfigurationRequest.class), any()); Map reqMetadata = new HashMap<>(); List keys = Arrays.asList("configkey1"); @@ -1895,12 +1908,12 @@ public void subscribeConfigurationTestWithMetadata() { @Test public void subscribeConfigurationWithErrorTest() { doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onError(new RuntimeException()); observer.onCompleted(); return null; - }).when(daprStub).subscribeConfiguration(any(DaprProtos.SubscribeConfigurationRequest.class), any()); + }).when(daprStub).subscribeConfiguration(any(DaprConfigurationProtos.SubscribeConfigurationRequest.class), any()); assertThrowsDaprException(ExecutionException.class, () -> { client.subscribeConfiguration(CONFIG_STORE_NAME, "key").blockFirst(); @@ -1913,18 +1926,18 @@ public void subscribeConfigurationWithErrorTest() { @Test public void unsubscribeConfigurationTest() { - DaprProtos.UnsubscribeConfigurationResponse responseEnvelope = DaprProtos.UnsubscribeConfigurationResponse.newBuilder() + DaprConfigurationProtos.UnsubscribeConfigurationResponse responseEnvelope = DaprConfigurationProtos.UnsubscribeConfigurationResponse.newBuilder() .setOk(true) .setMessage("unsubscribed_message") .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).unsubscribeConfiguration(any(DaprProtos.UnsubscribeConfigurationRequest.class), any()); + }).when(daprStub).unsubscribeConfiguration(any(DaprConfigurationProtos.UnsubscribeConfigurationRequest.class), any()); UnsubscribeConfigurationResponse response = client.unsubscribeConfiguration("subscription_id", CONFIG_STORE_NAME).block(); @@ -1935,12 +1948,12 @@ public void unsubscribeConfigurationTest() { @Test public void unsubscribeConfigurationTestWithError() { doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onError(new RuntimeException()); observer.onCompleted(); return null; - }).when(daprStub).unsubscribeConfiguration(any(DaprProtos.UnsubscribeConfigurationRequest.class), any()); + }).when(daprStub).unsubscribeConfiguration(any(DaprConfigurationProtos.UnsubscribeConfigurationRequest.class), any()); assertThrowsDaprException(ExecutionException.class, () -> { client.unsubscribeConfiguration("subscription_id", CONFIG_STORE_NAME).block(); @@ -1956,7 +1969,7 @@ public void unsubscribeConfigurationTestWithError() { }); } - private DaprProtos.GetConfigurationResponse getSingleMockResponse() { + private DaprConfigurationProtos.GetConfigurationResponse getSingleMockResponse() { Map metadata = new HashMap<>(); metadata.put("meta1", "value1"); Map configs = new HashMap<>(); @@ -1965,13 +1978,13 @@ private DaprProtos.GetConfigurationResponse getSingleMockResponse() { .setVersion("1") .putAllMetadata(metadata) .build()); - DaprProtos.GetConfigurationResponse responseEnvelope = DaprProtos.GetConfigurationResponse.newBuilder() + DaprConfigurationProtos.GetConfigurationResponse responseEnvelope = DaprConfigurationProtos.GetConfigurationResponse.newBuilder() .putAllItems(configs) .build(); return responseEnvelope; } - private DaprProtos.GetConfigurationResponse getMultipleMockResponse() { + private DaprConfigurationProtos.GetConfigurationResponse getMultipleMockResponse() { Map metadata = new HashMap<>(); metadata.put("meta1", "value1"); Map configs = new HashMap<>(); @@ -1985,12 +1998,25 @@ private DaprProtos.GetConfigurationResponse getMultipleMockResponse() { .setVersion("1") .putAllMetadata(metadata) .build()); - DaprProtos.GetConfigurationResponse responseEnvelope = DaprProtos.GetConfigurationResponse.newBuilder() + DaprConfigurationProtos.GetConfigurationResponse responseEnvelope = DaprConfigurationProtos.GetConfigurationResponse.newBuilder() .putAllItems(configs) .build(); return responseEnvelope; } + @Test + public void shutdownTest() { + doAnswer((Answer) invocation -> { + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; + observer.onNext(DaprProtos.ShutdownRequest.getDefaultInstance()); + observer.onCompleted(); + return null; + }).when(daprStub).shutdown(any(DaprProtos.ShutdownRequest.class), any()); + + Mono result = client.shutdown(); + result.block(); + } + /* If this test is failing, it means that a new value was added to StateOptions.Consistency * enum, without creating a mapping to one of the proto defined gRPC enums */ @@ -2004,7 +2030,7 @@ public void stateOptionsConsistencyValuesHaveValidGrpcEnumMappings() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).saveState(any(DaprProtos.SaveStateRequest.class), any()); + }).when(daprStub).saveState(any(DaprStateProtos.SaveStateRequest.class), any()); for (StateOptions.Consistency consistency : StateOptions.Consistency.values()) { StateOptions options = buildStateOptions(consistency, StateOptions.Concurrency.FIRST_WRITE); @@ -2026,7 +2052,7 @@ public void stateOptionsConcurrencyValuesHaveValidGrpcEnumMappings() { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).saveState(any(DaprProtos.SaveStateRequest.class), any()); + }).when(daprStub).saveState(any(DaprStateProtos.SaveStateRequest.class), any()); for (StateOptions.Concurrency concurrency : StateOptions.Concurrency.values()) { StateOptions options = buildStateOptions(StateOptions.Consistency.EVENTUAL, concurrency); @@ -2035,51 +2061,23 @@ public void stateOptionsConcurrencyValuesHaveValidGrpcEnumMappings() { } } - @Test - public void shutdownTest() { - doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; - observer.onNext(DaprProtos.ShutdownRequest.getDefaultInstance()); - observer.onCompleted(); - return null; - }).when(daprStub).shutdown(any(DaprProtos.ShutdownRequest.class), any()); - - Mono result = client.shutdown(); - result.block(); - } - - - private DaprProtos.GetStateResponse buildFutureGetStateEnvelop(T value, String etag) throws IOException { + private DaprStateProtos.GetStateResponse buildFutureGetStateEnvelop(T value, String etag) throws IOException { return buildGetStateResponse(value, etag); } - private DaprProtos.GetStateResponse buildGetStateResponse(T value, String etag) throws IOException { - return DaprProtos.GetStateResponse.newBuilder() + private DaprStateProtos.GetStateResponse buildGetStateResponse(T value, String etag) throws IOException { + return DaprStateProtos.GetStateResponse.newBuilder() .setData(serialize(value)) .setEtag(etag) .build(); } - private DaprProtos.GetSecretResponse buildGetSecretResponse(String key, String value) { - return DaprProtos.GetSecretResponse.newBuilder() + private DaprSecretProtos.GetSecretResponse buildGetSecretResponse(String key, String value) { + return DaprSecretProtos.GetSecretResponse.newBuilder() .putAllData(Collections.singletonMap(key, value)) .build(); } - private DaprProtos.GetSecretResponse buildGetSecretResponse() { - return DaprProtos.GetSecretResponse.newBuilder().build(); - } - - private DaprProtos.GetBulkSecretResponse buildGetBulkSecretResponse(Map> res) { - Map map = res.entrySet().stream().collect( - Collectors.toMap( - e -> e.getKey(), - e -> DaprProtos.SecretResponse.newBuilder().putAllSecrets(e.getValue()).build())); - return DaprProtos.GetBulkSecretResponse.newBuilder() - .putAllData(map) - .build(); - } - private StateOptions buildStateOptions(StateOptions.Consistency consistency, StateOptions.Concurrency concurrency) { StateOptions options = null; if (consistency != null || concurrency != null) { @@ -2146,88 +2144,60 @@ public int hashCode() { } } - private static class GetStateRequestKeyMatcher implements ArgumentMatcher { - - private final String propValue; - - GetStateRequestKeyMatcher(String propValue) { - this.propValue = propValue; - } - - @Override - public boolean matches(DaprProtos.GetStateRequest argument) { - if (argument == null) { - return false; - } - if (propValue == null && argument.getKey() != null) { - return false; - } - if (propValue == null && argument.getKey() == null) { - return true; - } - return propValue.equals(argument.getKey()); - } - - @Override - public String toString() { - return ""; - } - } - - public static StatusRuntimeException newStatusRuntimeException(String statusCode, String message) { - return new StatusRuntimeException(Status.fromCode(Status.Code.valueOf(statusCode)).withDescription(message)); + private DaprSecretProtos.GetSecretResponse buildGetSecretResponse() { + return DaprSecretProtos.GetSecretResponse.newBuilder().build(); } - public static StatusRuntimeException newStatusRuntimeException(String statusCode, String message, com.google.rpc.Status statusDetails) { - com.google.rpc.Status status = com.google.rpc.Status.newBuilder() - .setCode(Status.Code.valueOf(statusCode).value()) - .setMessage(message) - .addAllDetails(statusDetails.getDetailsList()) - .build(); - - return StatusProto.toStatusRuntimeException(status); + private DaprSecretProtos.GetBulkSecretResponse buildGetBulkSecretResponse(Map> res) { + Map map = res.entrySet().stream().collect( + Collectors.toMap( + e -> e.getKey(), + e -> DaprSecretProtos.SecretResponse.newBuilder().putAllSecrets(e.getValue()).build())); + return DaprSecretProtos.GetBulkSecretResponse.newBuilder() + .putAllData(map) + .build(); } @Test public void getMetadataTest() { - ActiveActorsCount activeActorsCount = DaprProtos.ActiveActorsCount.newBuilder() + DaprMetadataProtos.ActiveActorsCount activeActorsCount = DaprMetadataProtos.ActiveActorsCount.newBuilder() .setType("actor") .setCount(1) .build(); - ActorRuntime actorRuntime = DaprProtos.ActorRuntime.newBuilder() + DaprMetadataProtos.ActorRuntime actorRuntime = DaprMetadataProtos.ActorRuntime.newBuilder() .addActiveActors(activeActorsCount) .build(); - RegisteredComponents registeredComponents = DaprProtos.RegisteredComponents.newBuilder() + DaprMetadataProtos.RegisteredComponents registeredComponents = DaprMetadataProtos.RegisteredComponents.newBuilder() .setName("statestore") .setType("state.redis") .setVersion("v1") .build(); - DaprProtos.MetadataHTTPEndpoint httpEndpoint = DaprProtos.MetadataHTTPEndpoint.newBuilder() + DaprMetadataProtos.MetadataHTTPEndpoint httpEndpoint = DaprMetadataProtos.MetadataHTTPEndpoint.newBuilder() .setName("httpEndpoint") .build(); - PubsubSubscriptionRules pubsubSubscriptionRules = DaprProtos.PubsubSubscriptionRules.newBuilder() - .addRules(DaprProtos.PubsubSubscriptionRule.newBuilder().setPath("/events").build()) + DaprMetadataProtos.PubsubSubscriptionRules pubsubSubscriptionRules = DaprMetadataProtos.PubsubSubscriptionRules.newBuilder() + .addRules(DaprMetadataProtos.PubsubSubscriptionRule.newBuilder().setPath("/events").build()) .build(); - PubsubSubscription pubsubSubscription = DaprProtos.PubsubSubscription.newBuilder() + DaprMetadataProtos.PubsubSubscription pubsubSubscription = DaprMetadataProtos.PubsubSubscription.newBuilder() .setDeadLetterTopic("") .setPubsubName("pubsub") .setTopic("topic") .setRules(pubsubSubscriptionRules) .build(); - AppConnectionHealthProperties healthProperties = DaprProtos.AppConnectionHealthProperties.newBuilder() + DaprMetadataProtos.AppConnectionHealthProperties healthProperties = DaprMetadataProtos.AppConnectionHealthProperties.newBuilder() .setHealthCheckPath("/health") .setHealthProbeInterval("10s") .setHealthProbeTimeout("5s") .setHealthThreshold(1) .build(); - AppConnectionProperties appConnectionProperties = DaprProtos.AppConnectionProperties.newBuilder() + DaprMetadataProtos.AppConnectionProperties appConnectionProperties = DaprMetadataProtos.AppConnectionProperties.newBuilder() .setPort(8080) .setProtocol("http") .setChannelAddress("localhost") @@ -2235,7 +2205,7 @@ public void getMetadataTest() { .setHealth(healthProperties) .build(); - DaprProtos.GetMetadataResponse responseEnvelope = DaprProtos.GetMetadataResponse.newBuilder() + DaprMetadataProtos.GetMetadataResponse responseEnvelope = DaprMetadataProtos.GetMetadataResponse.newBuilder() .setId("app") .setRuntimeVersion("1.1x.x") .addAllEnabledFeatures(Collections.emptyList()) @@ -2248,12 +2218,12 @@ public void getMetadataTest() { .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = (StreamObserver) invocation + StreamObserver observer = (StreamObserver) invocation .getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).getMetadata(any(DaprProtos.GetMetadataRequest.class), any()); + }).when(daprStub).getMetadata(any(DaprMetadataProtos.GetMetadataRequest.class), any()); Mono result = client.getMetadata(); DaprMetadata metadata = result.block(); @@ -2330,18 +2300,18 @@ public void scheduleJobShouldSucceedWhenAllFieldsArePresentInRequest() { .setDueTime(Instant.now().plus(10, ChronoUnit.MINUTES)); doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); + StreamObserver observer = invocation.getArgument(1); observer.onCompleted(); // Simulate successful response return null; - }).when(daprStub).scheduleJobAlpha1(any(DaprProtos.ScheduleJobRequest.class), any()); + }).when(daprStub).scheduleJobAlpha1(any(DaprJobsProtos.ScheduleJobRequest.class), any()); assertDoesNotThrow(() -> client.scheduleJob(expectedScheduleJobRequest).block()); - ArgumentCaptor captor = - ArgumentCaptor.forClass(DaprProtos.ScheduleJobRequest.class); + ArgumentCaptor captor = + ArgumentCaptor.forClass(DaprJobsProtos.ScheduleJobRequest.class); verify(daprStub, times(1)).scheduleJobAlpha1(captor.capture(), Mockito.any()); - DaprProtos.ScheduleJobRequest actualScheduleJobReq = captor.getValue(); + DaprJobsProtos.ScheduleJobRequest actualScheduleJobReq = captor.getValue(); assertEquals("testJob", actualScheduleJobReq.getJob().getName()); assertEquals("testData", @@ -2358,21 +2328,21 @@ public void scheduleJobShouldSucceedWhenRequiredFieldsNameAndDueTimeArePresentIn .withZone(ZoneOffset.UTC); doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); + StreamObserver observer = invocation.getArgument(1); observer.onCompleted(); // Simulate successful response return null; - }).when(daprStub).scheduleJobAlpha1(any(DaprProtos.ScheduleJobRequest.class), any()); + }).when(daprStub).scheduleJobAlpha1(any(DaprJobsProtos.ScheduleJobRequest.class), any()); ScheduleJobRequest expectedScheduleJobRequest = new ScheduleJobRequest("testJob", Instant.now().plus(10, ChronoUnit.MINUTES)); assertDoesNotThrow(() -> client.scheduleJob(expectedScheduleJobRequest).block()); - ArgumentCaptor captor = - ArgumentCaptor.forClass(DaprProtos.ScheduleJobRequest.class); + ArgumentCaptor captor = + ArgumentCaptor.forClass(DaprJobsProtos.ScheduleJobRequest.class); verify(daprStub, times(1)).scheduleJobAlpha1(captor.capture(), Mockito.any()); - DaprProtos.ScheduleJobRequest actualScheduleJobRequest = captor.getValue(); - DaprProtos.Job job = actualScheduleJobRequest.getJob(); + DaprJobsProtos.ScheduleJobRequest actualScheduleJobRequest = captor.getValue(); + DaprJobsProtos.Job job = actualScheduleJobRequest.getJob(); assertEquals("testJob", job.getName()); assertFalse(job.hasData()); assertFalse(job.hasSchedule()); @@ -2388,26 +2358,54 @@ public void scheduleJobShouldSucceedWhenRequiredFieldsNameAndScheduleArePresentI .withZone(ZoneOffset.UTC); doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); + StreamObserver observer = invocation.getArgument(1); observer.onCompleted(); // Simulate successful response return null; - }).when(daprStub).scheduleJobAlpha1(any(DaprProtos.ScheduleJobRequest.class), any()); + }).when(daprStub).scheduleJobAlpha1(any(DaprJobsProtos.ScheduleJobRequest.class), any()); ScheduleJobRequest expectedScheduleJobRequest = new ScheduleJobRequest("testJob", JobSchedule.fromString("* * * * * *")); assertDoesNotThrow(() -> client.scheduleJob(expectedScheduleJobRequest).block()); - ArgumentCaptor captor = - ArgumentCaptor.forClass(DaprProtos.ScheduleJobRequest.class); + ArgumentCaptor captor = + ArgumentCaptor.forClass(DaprJobsProtos.ScheduleJobRequest.class); verify(daprStub, times(1)).scheduleJobAlpha1(captor.capture(), Mockito.any()); - DaprProtos.ScheduleJobRequest actualScheduleJobRequest = captor.getValue(); - DaprProtos.Job job = actualScheduleJobRequest.getJob(); + DaprJobsProtos.ScheduleJobRequest actualScheduleJobRequest = captor.getValue(); + DaprJobsProtos.Job job = actualScheduleJobRequest.getJob(); + assertEquals("testJob", job.getName()); + assertFalse(job.hasData()); + assertEquals("* * * * * *", job.getSchedule()); + assertEquals(0, job.getRepeats()); + assertFalse(job.hasTtl()); + } + + @Test + public void scheduleJobShouldHavePolicyWhenPolicyIsSet() { + doAnswer(invocation -> { + StreamObserver observer = invocation.getArgument(1); + observer.onCompleted(); // Simulate successful response + return null; + }).when(daprStub).scheduleJobAlpha1(any(DaprJobsProtos.ScheduleJobRequest.class), any()); + + ScheduleJobRequest expectedScheduleJobRequest = new ScheduleJobRequest("testJob", + JobSchedule.fromString("* * * * * *")) + .setFailurePolicy(new DropFailurePolicy()); + + client.scheduleJob(expectedScheduleJobRequest).block(); + + ArgumentCaptor captor = + ArgumentCaptor.forClass(DaprJobsProtos.ScheduleJobRequest.class); + + verify(daprStub, times(1)).scheduleJobAlpha1(captor.capture(), Mockito.any()); + DaprJobsProtos.ScheduleJobRequest actualScheduleJobRequest = captor.getValue(); + DaprJobsProtos.Job job = actualScheduleJobRequest.getJob(); assertEquals("testJob", job.getName()); assertFalse(job.hasData()); assertEquals( "* * * * * *", job.getSchedule()); assertEquals(0, job.getRepeats()); assertFalse(job.hasTtl()); + Assertions.assertTrue(job.hasFailurePolicy()); } @Test @@ -2437,41 +2435,13 @@ public void scheduleJobShouldThrowWhenNameInRequestIsEmpty() { assertEquals("Name in the request cannot be null or empty", exception.getMessage()); } - @Test - public void scheduleJobShouldHavePolicyWhenPolicyIsSet() { - doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); - observer.onCompleted(); // Simulate successful response - return null; - }).when(daprStub).scheduleJobAlpha1(any(DaprProtos.ScheduleJobRequest.class), any()); - - ScheduleJobRequest expectedScheduleJobRequest = new ScheduleJobRequest("testJob", - JobSchedule.fromString("* * * * * *")) - .setFailurePolicy(new DropFailurePolicy()); - - client.scheduleJob(expectedScheduleJobRequest).block(); - - ArgumentCaptor captor = - ArgumentCaptor.forClass(DaprProtos.ScheduleJobRequest.class); - - verify(daprStub, times(1)).scheduleJobAlpha1(captor.capture(), Mockito.any()); - DaprProtos.ScheduleJobRequest actualScheduleJobRequest = captor.getValue(); - DaprProtos.Job job = actualScheduleJobRequest.getJob(); - assertEquals("testJob", job.getName()); - assertFalse(job.hasData()); - assertEquals( "* * * * * *", job.getSchedule()); - assertEquals(0, job.getRepeats()); - assertFalse(job.hasTtl()); - Assertions.assertTrue(job.hasFailurePolicy()); - } - @Test public void scheduleJobShouldHaveConstantPolicyWithMaxRetriesWhenConstantPolicyIsSetWithMaxRetries() { doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); + StreamObserver observer = invocation.getArgument(1); observer.onCompleted(); // Simulate successful response return null; - }).when(daprStub).scheduleJobAlpha1(any(DaprProtos.ScheduleJobRequest.class), any()); + }).when(daprStub).scheduleJobAlpha1(any(DaprJobsProtos.ScheduleJobRequest.class), any()); ScheduleJobRequest expectedScheduleJobRequest = new ScheduleJobRequest("testJob", JobSchedule.fromString("* * * * * *")) @@ -2479,12 +2449,12 @@ public void scheduleJobShouldHaveConstantPolicyWithMaxRetriesWhenConstantPolicyI client.scheduleJob(expectedScheduleJobRequest).block(); - ArgumentCaptor captor = - ArgumentCaptor.forClass(DaprProtos.ScheduleJobRequest.class); + ArgumentCaptor captor = + ArgumentCaptor.forClass(DaprJobsProtos.ScheduleJobRequest.class); verify(daprStub, times(1)).scheduleJobAlpha1(captor.capture(), Mockito.any()); - DaprProtos.ScheduleJobRequest actualScheduleJobRequest = captor.getValue(); - DaprProtos.Job job = actualScheduleJobRequest.getJob(); + DaprJobsProtos.ScheduleJobRequest actualScheduleJobRequest = captor.getValue(); + DaprJobsProtos.Job job = actualScheduleJobRequest.getJob(); assertEquals("testJob", job.getName()); assertFalse(job.hasData()); assertEquals( "* * * * * *", job.getSchedule()); @@ -2497,10 +2467,10 @@ public void scheduleJobShouldHaveConstantPolicyWithMaxRetriesWhenConstantPolicyI @Test public void scheduleJobShouldHaveConstantPolicyWithIntervalWhenConstantPolicyIsSetWithInterval() { doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); + StreamObserver observer = invocation.getArgument(1); observer.onCompleted(); // Simulate successful response return null; - }).when(daprStub).scheduleJobAlpha1(any(DaprProtos.ScheduleJobRequest.class), any()); + }).when(daprStub).scheduleJobAlpha1(any(DaprJobsProtos.ScheduleJobRequest.class), any()); ScheduleJobRequest expectedScheduleJobRequest = new ScheduleJobRequest("testJob", JobSchedule.fromString("* * * * * *")) @@ -2508,12 +2478,12 @@ public void scheduleJobShouldHaveConstantPolicyWithIntervalWhenConstantPolicyIsS client.scheduleJob(expectedScheduleJobRequest).block(); - ArgumentCaptor captor = - ArgumentCaptor.forClass(DaprProtos.ScheduleJobRequest.class); + ArgumentCaptor captor = + ArgumentCaptor.forClass(DaprJobsProtos.ScheduleJobRequest.class); verify(daprStub, times(1)).scheduleJobAlpha1(captor.capture(), Mockito.any()); - DaprProtos.ScheduleJobRequest actualScheduleJobRequest = captor.getValue(); - DaprProtos.Job job = actualScheduleJobRequest.getJob(); + DaprJobsProtos.ScheduleJobRequest actualScheduleJobRequest = captor.getValue(); + DaprJobsProtos.Job job = actualScheduleJobRequest.getJob(); assertEquals("testJob", job.getName()); assertFalse(job.hasData()); assertEquals( "* * * * * *", job.getSchedule()); @@ -2527,10 +2497,10 @@ public void scheduleJobShouldHaveConstantPolicyWithIntervalWhenConstantPolicyIsS @Test public void scheduleJobShouldHaveBothRetiresAndIntervalWhenConstantPolicyIsSetWithRetriesAndInterval() { doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); + StreamObserver observer = invocation.getArgument(1); observer.onCompleted(); // Simulate successful response return null; - }).when(daprStub).scheduleJobAlpha1(any(DaprProtos.ScheduleJobRequest.class), any()); + }).when(daprStub).scheduleJobAlpha1(any(DaprJobsProtos.ScheduleJobRequest.class), any()); ScheduleJobRequest expectedScheduleJobRequest = new ScheduleJobRequest("testJob", JobSchedule.fromString("* * * * * *")) @@ -2539,12 +2509,12 @@ public void scheduleJobShouldHaveBothRetiresAndIntervalWhenConstantPolicyIsSetWi client.scheduleJob(expectedScheduleJobRequest).block(); - ArgumentCaptor captor = - ArgumentCaptor.forClass(DaprProtos.ScheduleJobRequest.class); + ArgumentCaptor captor = + ArgumentCaptor.forClass(DaprJobsProtos.ScheduleJobRequest.class); verify(daprStub, times(1)).scheduleJobAlpha1(captor.capture(), Mockito.any()); - DaprProtos.ScheduleJobRequest actualScheduleJobRequest = captor.getValue(); - DaprProtos.Job job = actualScheduleJobRequest.getJob(); + DaprJobsProtos.ScheduleJobRequest actualScheduleJobRequest = captor.getValue(); + DaprJobsProtos.Job job = actualScheduleJobRequest.getJob(); assertEquals("testJob", job.getName()); assertFalse(job.hasData()); assertEquals( "* * * * * *", job.getSchedule()); @@ -2561,7 +2531,7 @@ public void scheduleJobShouldThrowWhenNameAlreadyExists() { AtomicInteger callCount = new AtomicInteger(0); doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); + StreamObserver observer = invocation.getArgument(1); if (callCount.incrementAndGet() == 1) { // First call succeeds observer.onCompleted(); @@ -2570,18 +2540,18 @@ public void scheduleJobShouldThrowWhenNameAlreadyExists() { observer.onError(newStatusRuntimeException("ALREADY_EXISTS", "Job with name 'testJob' already exists")); } return null; - }).when(daprStub).scheduleJobAlpha1(any(DaprProtos.ScheduleJobRequest.class), any()); + }).when(daprStub).scheduleJobAlpha1(any(DaprJobsProtos.ScheduleJobRequest.class), any()); // First call should succeed ScheduleJobRequest firstRequest = new ScheduleJobRequest("testJob", Instant.now()); assertDoesNotThrow(() -> client.scheduleJob(firstRequest).block()); - ArgumentCaptor captor = - ArgumentCaptor.forClass(DaprProtos.ScheduleJobRequest.class); + ArgumentCaptor captor = + ArgumentCaptor.forClass(DaprJobsProtos.ScheduleJobRequest.class); verify(daprStub, times(1)).scheduleJobAlpha1(captor.capture(), Mockito.any()); - DaprProtos.ScheduleJobRequest actualScheduleJobRequest = captor.getValue(); - DaprProtos.Job job = actualScheduleJobRequest.getJob(); + DaprJobsProtos.ScheduleJobRequest actualScheduleJobRequest = captor.getValue(); + DaprJobsProtos.Job job = actualScheduleJobRequest.getJob(); assertEquals("testJob", job.getName()); assertFalse(job.hasData()); assertEquals(0, job.getRepeats()); @@ -2600,10 +2570,10 @@ public void scheduleJobShouldThrowWhenNameAlreadyExists() { @Test public void scheduleJobShouldSucceedWhenNameAlreadyExistsWithOverwrite() { doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); + StreamObserver observer = invocation.getArgument(1); observer.onCompleted(); // Simulate successful response for both calls return null; - }).when(daprStub).scheduleJobAlpha1(any(DaprProtos.ScheduleJobRequest.class), any()); + }).when(daprStub).scheduleJobAlpha1(any(DaprJobsProtos.ScheduleJobRequest.class), any()); // First call should succeed ScheduleJobRequest firstRequest = new ScheduleJobRequest("testJob", Instant.now()); @@ -2615,17 +2585,17 @@ public void scheduleJobShouldSucceedWhenNameAlreadyExistsWithOverwrite() { assertDoesNotThrow(() -> client.scheduleJob(secondRequest).block()); // Verify that both calls were made successfully - ArgumentCaptor captor = - ArgumentCaptor.forClass(DaprProtos.ScheduleJobRequest.class); + ArgumentCaptor captor = + ArgumentCaptor.forClass(DaprJobsProtos.ScheduleJobRequest.class); verify(daprStub, times(2)).scheduleJobAlpha1(captor.capture(), any()); // Verify the first call doesn't have overwrite set - DaprProtos.ScheduleJobRequest firstActualRequest = captor.getAllValues().get(0); + DaprJobsProtos.ScheduleJobRequest firstActualRequest = captor.getAllValues().get(0); assertFalse(firstActualRequest.getOverwrite()); assertEquals("testJob", firstActualRequest.getJob().getName()); // Verify the second call has overwrite set to true - DaprProtos.ScheduleJobRequest secondActualRequest = captor.getAllValues().get(1); + DaprJobsProtos.ScheduleJobRequest secondActualRequest = captor.getAllValues().get(1); Assert.assertTrue(secondActualRequest.getOverwrite()); assertEquals("testJob", secondActualRequest.getJob().getName()); } @@ -2637,7 +2607,7 @@ public void getJobShouldReturnResponseWhenAllFieldsArePresentInRequest() { GetJobRequest getJobRequest = new GetJobRequest("testJob"); - DaprProtos.Job job = DaprProtos.Job.newBuilder() + DaprJobsProtos.Job job = DaprJobsProtos.Job.newBuilder() .setName("testJob") .setTtl(OffsetDateTime.now().format(iso8601Formatter)) .setData(Any.newBuilder().setValue(ByteString.copyFrom("testData".getBytes())).build()) @@ -2647,13 +2617,13 @@ public void getJobShouldReturnResponseWhenAllFieldsArePresentInRequest() { .build(); doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); - observer.onNext(DaprProtos.GetJobResponse.newBuilder() + StreamObserver observer = invocation.getArgument(1); + observer.onNext(DaprJobsProtos.GetJobResponse.newBuilder() .setJob(job) .build()); observer.onCompleted(); return null; - }).when(daprStub).getJobAlpha1(any(DaprProtos.GetJobRequest.class), any()); + }).when(daprStub).getJobAlpha1(any(DaprJobsProtos.GetJobRequest.class), any()); Mono resultMono = client.getJob(getJobRequest); @@ -2671,19 +2641,19 @@ public void getJobShouldReturnResponseWhenAllFieldsArePresentInRequest() { public void getJobShouldReturnResponseWithScheduleSetWhenResponseHasSchedule() { GetJobRequest getJobRequest = new GetJobRequest("testJob"); - DaprProtos.Job job = DaprProtos.Job.newBuilder() + DaprJobsProtos.Job job = DaprJobsProtos.Job.newBuilder() .setName("testJob") .setSchedule("0 0 0 1 1 *") .build(); doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); - observer.onNext(DaprProtos.GetJobResponse.newBuilder() + StreamObserver observer = invocation.getArgument(1); + observer.onNext(DaprJobsProtos.GetJobResponse.newBuilder() .setJob(job) .build()); observer.onCompleted(); return null; - }).when(daprStub).getJobAlpha1(any(DaprProtos.GetJobRequest.class), any()); + }).when(daprStub).getJobAlpha1(any(DaprJobsProtos.GetJobRequest.class), any()); Mono resultMono = client.getJob(getJobRequest); @@ -2702,19 +2672,19 @@ public void getJobShouldReturnResponseWithDueTimeSetWhenResponseHasDueTime() { GetJobRequest getJobRequest = new GetJobRequest("testJob"); String datetime = OffsetDateTime.now().toString(); - DaprProtos.Job job = DaprProtos.Job.newBuilder() + DaprJobsProtos.Job job = DaprJobsProtos.Job.newBuilder() .setName("testJob") .setDueTime(datetime) .build(); doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); - observer.onNext(DaprProtos.GetJobResponse.newBuilder() + StreamObserver observer = invocation.getArgument(1); + observer.onNext(DaprJobsProtos.GetJobResponse.newBuilder() .setJob(job) .build()); observer.onCompleted(); return null; - }).when(daprStub).getJobAlpha1(any(DaprProtos.GetJobRequest.class), any()); + }).when(daprStub).getJobAlpha1(any(DaprJobsProtos.GetJobRequest.class), any()); Mono resultMono = client.getJob(getJobRequest); @@ -2733,7 +2703,7 @@ public void getJobShouldReturnResponseWithDropFailurePolicySet() { GetJobRequest getJobRequest = new GetJobRequest("testJob"); String datetime = OffsetDateTime.now().toString(); - DaprProtos.Job job = DaprProtos.Job.newBuilder() + DaprJobsProtos.Job job = DaprJobsProtos.Job.newBuilder() .setName("testJob") .setDueTime(datetime) .setFailurePolicy(CommonProtos.JobFailurePolicy.newBuilder() @@ -2741,13 +2711,13 @@ public void getJobShouldReturnResponseWithDropFailurePolicySet() { .build(); doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); - observer.onNext(DaprProtos.GetJobResponse.newBuilder() + StreamObserver observer = invocation.getArgument(1); + observer.onNext(DaprJobsProtos.GetJobResponse.newBuilder() .setJob(job) .build()); observer.onCompleted(); return null; - }).when(daprStub).getJobAlpha1(any(DaprProtos.GetJobRequest.class), any()); + }).when(daprStub).getJobAlpha1(any(DaprJobsProtos.GetJobRequest.class), any()); Mono resultMono = client.getJob(getJobRequest); @@ -2768,7 +2738,7 @@ public void getJobShouldReturnResponseWithConstantFailurePolicyAndMaxRetriesSet( GetJobRequest getJobRequest = new GetJobRequest("testJob"); String datetime = OffsetDateTime.now().toString(); - DaprProtos.Job job = DaprProtos.Job.newBuilder() + DaprJobsProtos.Job job = DaprJobsProtos.Job.newBuilder() .setName("testJob") .setDueTime(datetime) .setFailurePolicy(CommonProtos.JobFailurePolicy.newBuilder() @@ -2776,13 +2746,13 @@ public void getJobShouldReturnResponseWithConstantFailurePolicyAndMaxRetriesSet( .build(); doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); - observer.onNext(DaprProtos.GetJobResponse.newBuilder() + StreamObserver observer = invocation.getArgument(1); + observer.onNext(DaprJobsProtos.GetJobResponse.newBuilder() .setJob(job) .build()); observer.onCompleted(); return null; - }).when(daprStub).getJobAlpha1(any(DaprProtos.GetJobRequest.class), any()); + }).when(daprStub).getJobAlpha1(any(DaprJobsProtos.GetJobRequest.class), any()); Mono resultMono = client.getJob(getJobRequest); @@ -2804,7 +2774,7 @@ public void getJobShouldReturnResponseWithConstantFailurePolicyAndIntervalSet() GetJobRequest getJobRequest = new GetJobRequest("testJob"); String datetime = OffsetDateTime.now().toString(); - DaprProtos.Job job = DaprProtos.Job.newBuilder() + DaprJobsProtos.Job job = DaprJobsProtos.Job.newBuilder() .setName("testJob") .setDueTime(datetime) .setFailurePolicy(CommonProtos.JobFailurePolicy.newBuilder() @@ -2813,13 +2783,13 @@ public void getJobShouldReturnResponseWithConstantFailurePolicyAndIntervalSet() .build(); doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); - observer.onNext(DaprProtos.GetJobResponse.newBuilder() + StreamObserver observer = invocation.getArgument(1); + observer.onNext(DaprJobsProtos.GetJobResponse.newBuilder() .setJob(job) .build()); observer.onCompleted(); return null; - }).when(daprStub).getJobAlpha1(any(DaprProtos.GetJobRequest.class), any()); + }).when(daprStub).getJobAlpha1(any(DaprJobsProtos.GetJobRequest.class), any()); Mono resultMono = client.getJob(getJobRequest); @@ -2841,7 +2811,7 @@ public void getJobShouldReturnResponseWithConstantFailurePolicyIntervalAndMaxRet GetJobRequest getJobRequest = new GetJobRequest("testJob"); String datetime = OffsetDateTime.now().toString(); - DaprProtos.Job job = DaprProtos.Job.newBuilder() + DaprJobsProtos.Job job = DaprJobsProtos.Job.newBuilder() .setName("testJob") .setDueTime(datetime) .setFailurePolicy(CommonProtos.JobFailurePolicy.newBuilder() @@ -2851,13 +2821,13 @@ public void getJobShouldReturnResponseWithConstantFailurePolicyIntervalAndMaxRet .build(); doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); - observer.onNext(DaprProtos.GetJobResponse.newBuilder() + StreamObserver observer = invocation.getArgument(1); + observer.onNext(DaprJobsProtos.GetJobResponse.newBuilder() .setJob(job) .build()); observer.onCompleted(); return null; - }).when(daprStub).getJobAlpha1(any(DaprProtos.GetJobRequest.class), any()); + }).when(daprStub).getJobAlpha1(any(DaprJobsProtos.GetJobRequest.class), any()); Mono resultMono = client.getJob(getJobRequest); @@ -2875,6 +2845,21 @@ public void getJobShouldReturnResponseWithConstantFailurePolicyIntervalAndMaxRet assertEquals(5, job.getFailurePolicy().getConstant().getInterval().getNanos()); } + @Test + public void deleteJobShouldSucceedWhenValidRequest() { + DeleteJobRequest deleteJobRequest = new DeleteJobRequest("testJob"); + + doAnswer(invocation -> { + StreamObserver observer = invocation.getArgument(1); + observer.onCompleted(); // Simulate successful response + return null; + }).when(daprStub).deleteJobAlpha1(any(DaprJobsProtos.DeleteJobRequest.class), any()); + + Mono resultMono = client.deleteJob(deleteJobRequest); + + assertDoesNotThrow(() -> resultMono.block()); + } + @Test public void getJobShouldThrowWhenRequestIsNull() { @@ -2905,18 +2890,18 @@ public void getJobShouldThrowWhenNameIsEmptyRequest() { } @Test - public void deleteJobShouldSucceedWhenValidRequest() { - DeleteJobRequest deleteJobRequest = new DeleteJobRequest("testJob"); - - doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); - observer.onCompleted(); // Simulate successful response - return null; - }).when(daprStub).deleteJobAlpha1(any(DaprProtos.DeleteJobRequest.class), any()); + public void getMetadataExceptionTest() { + doAnswer((Answer) invocation -> { + throw new RuntimeException(); + }).when(daprStub).getMetadata(any(DaprMetadataProtos.GetMetadataRequest.class), any()); - Mono resultMono = client.deleteJob(deleteJobRequest); + Mono result = client.getMetadata(); - assertDoesNotThrow(() -> resultMono.block()); + assertThrowsDaprException( + RuntimeException.class, + "UNKNOWN", + "UNKNOWN: ", + () -> result.block()); } @Test @@ -2945,18 +2930,31 @@ public void deleteJobShouldThrowWhenNameIsEmptyRequest() { assertEquals("Name in the request cannot be null or empty", exception.getMessage()); } - @Test - public void getMetadataExceptionTest() { - doAnswer((Answer) invocation -> { - throw new RuntimeException(); - }).when(daprStub).getMetadata(any(DaprProtos.GetMetadataRequest.class), any()); + private static class GetStateRequestKeyMatcher implements ArgumentMatcher { - Mono result = client.getMetadata(); + private final String propValue; - assertThrowsDaprException( - RuntimeException.class, - "UNKNOWN", - "UNKNOWN: ", - () -> result.block()); + GetStateRequestKeyMatcher(String propValue) { + this.propValue = propValue; + } + + @Override + public boolean matches(DaprStateProtos.GetStateRequest argument) { + if (argument == null) { + return false; + } + if (propValue == null && argument.getKey() != null) { + return false; + } + if (propValue == null && argument.getKey() == null) { + return true; + } + return propValue.equals(argument.getKey()); + } + + @Override + public String toString() { + return ""; + } } } diff --git a/sdk/src/test/java/io/dapr/client/DaprExceptionTest.java b/sdk/src/test/java/io/dapr/client/DaprExceptionTest.java index 4abb10186e..b656639875 100644 --- a/sdk/src/test/java/io/dapr/client/DaprExceptionTest.java +++ b/sdk/src/test/java/io/dapr/client/DaprExceptionTest.java @@ -19,7 +19,8 @@ import io.dapr.exceptions.DaprErrorDetails; import io.dapr.serializer.DefaultObjectSerializer; import io.dapr.v1.DaprGrpc; -import io.dapr.v1.DaprProtos; +import io.dapr.v1.DaprPubsubProtos; +import io.dapr.v1.DaprStateProtos; import io.grpc.StatusRuntimeException; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -82,7 +83,7 @@ public void daprExceptionWithMultipleDetailsThrownTest() { doAnswer((Answer) invocation -> { throw newStatusRuntimeException("INVALID_ARGUMENT", "bad bad argument", status); - }).when(daprStub).publishEvent(any(DaprProtos.PublishEventRequest.class), any()); + }).when(daprStub).publishEvent(any(DaprPubsubProtos.PublishEventRequest.class), any()); DaprErrorDetails expectedStatusDetails = new DaprErrorDetails(status); @@ -109,7 +110,7 @@ public void daprExceptionWithOneDetailThrownTest() { doAnswer((Answer) invocation -> { throw newStatusRuntimeException("INVALID_ARGUMENT", "bad bad argument", status); - }).when(daprStub).getState(any(DaprProtos.GetStateRequest.class), any()); + }).when(daprStub).getState(any(DaprStateProtos.GetStateRequest.class), any()); DaprErrorDetails expectedStatusDetails = new DaprErrorDetails(status); diff --git a/sdk/src/test/java/io/dapr/client/DaprPreviewClientGrpcTest.java b/sdk/src/test/java/io/dapr/client/DaprPreviewClientGrpcTest.java index af54b64904..6e77839147 100644 --- a/sdk/src/test/java/io/dapr/client/DaprPreviewClientGrpcTest.java +++ b/sdk/src/test/java/io/dapr/client/DaprPreviewClientGrpcTest.java @@ -22,29 +22,23 @@ import io.dapr.client.domain.BulkPublishRequest; import io.dapr.client.domain.BulkPublishResponse; import io.dapr.client.domain.CloudEvent; -import io.dapr.client.domain.ConversationToolCallsOfFunction; -import io.dapr.client.domain.ConversationToolsFunction; +import io.dapr.client.domain.ConversationInput; import io.dapr.client.domain.ConversationInputAlpha2; import io.dapr.client.domain.ConversationMessage; import io.dapr.client.domain.ConversationMessageContent; +import io.dapr.client.domain.ConversationRequest; import io.dapr.client.domain.ConversationRequestAlpha2; +import io.dapr.client.domain.ConversationResponse; import io.dapr.client.domain.ConversationResponseAlpha2; import io.dapr.client.domain.ConversationResultAlpha2; import io.dapr.client.domain.ConversationResultChoices; import io.dapr.client.domain.ConversationToolCalls; +import io.dapr.client.domain.ConversationToolCallsOfFunction; import io.dapr.client.domain.ConversationTools; +import io.dapr.client.domain.ConversationToolsFunction; import io.dapr.client.domain.DecryptRequestAlpha1; -import io.dapr.client.domain.DeleteJobRequest; import io.dapr.client.domain.DeveloperMessage; -import io.dapr.client.domain.ConversationInput; -import io.dapr.client.domain.ConversationRequest; -import io.dapr.client.domain.ConversationResponse; -import io.dapr.client.domain.DeleteJobRequest; -import io.dapr.client.domain.DropFailurePolicy; import io.dapr.client.domain.EncryptRequestAlpha1; -import io.dapr.client.domain.GetJobRequest; -import io.dapr.client.domain.GetJobResponse; -import io.dapr.client.domain.JobSchedule; import io.dapr.client.domain.QueryStateItem; import io.dapr.client.domain.QueryStateRequest; import io.dapr.client.domain.QueryStateResponse; @@ -57,9 +51,13 @@ import io.dapr.serializer.DefaultObjectSerializer; import io.dapr.utils.TypeRef; import io.dapr.v1.CommonProtos; +import io.dapr.v1.DaprAiProtos; import io.dapr.v1.DaprAppCallbackProtos; +import io.dapr.v1.DaprCryptoProtos; import io.dapr.v1.DaprGrpc; -import io.dapr.v1.DaprProtos; +import io.dapr.v1.DaprLockProtos; +import io.dapr.v1.DaprPubsubProtos; +import io.dapr.v1.DaprStateProtos; import io.grpc.Status; import io.grpc.StatusRuntimeException; import io.grpc.stub.StreamObserver; @@ -92,7 +90,6 @@ import static io.dapr.utils.TestUtils.assertThrowsDaprException; import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -145,7 +142,7 @@ public void tearDown() throws Exception { public void publishEventsExceptionThrownTest() { doAnswer((Answer) invocation -> { throw newStatusRuntimeException("INVALID_ARGUMENT", "bad bad argument"); - }).when(daprStub).bulkPublishEventAlpha1(any(DaprProtos.BulkPublishRequest.class), any()); + }).when(daprStub).bulkPublishEventAlpha1(any(DaprPubsubProtos.BulkPublishRequest.class), any()); assertThrowsDaprException( StatusRuntimeException.class, @@ -158,11 +155,11 @@ public void publishEventsExceptionThrownTest() { @Test public void publishEventsCallbackExceptionThrownTest() { doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onError(newStatusRuntimeException("INVALID_ARGUMENT", "bad bad argument")); return null; - }).when(daprStub).bulkPublishEventAlpha1(any(DaprProtos.BulkPublishRequest.class), any()); + }).when(daprStub).bulkPublishEventAlpha1(any(DaprPubsubProtos.BulkPublishRequest.class), any()); assertThrowsDaprException( ExecutionException.class, @@ -176,12 +173,12 @@ public void publishEventsCallbackExceptionThrownTest() { public void publishEventsContentTypeMismatchException() throws IOException { DaprObjectSerializer mockSerializer = mock(DaprObjectSerializer.class); doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; - observer.onNext(DaprProtos.BulkPublishResponse.getDefaultInstance()); + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; + observer.onNext(DaprPubsubProtos.BulkPublishResponse.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).bulkPublishEventAlpha1(any(DaprProtos.BulkPublishRequest.class), any()); + }).when(daprStub).bulkPublishEventAlpha1(any(DaprPubsubProtos.BulkPublishRequest.class), any()); BulkPublishEntry entry = new BulkPublishEntry<>("1", "testEntry" @@ -197,12 +194,12 @@ public void publishEventsSerializeException() throws IOException { DaprObjectSerializer mockSerializer = mock(DaprObjectSerializer.class); previewClient = new DaprClientImpl(channel, daprStub, daprHttp, mockSerializer, new DefaultObjectSerializer()); doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; - observer.onNext(DaprProtos.BulkPublishResponse.getDefaultInstance()); + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; + observer.onNext(DaprPubsubProtos.BulkPublishResponse.getDefaultInstance()); observer.onCompleted(); return null; - }).when(daprStub).publishEvent(any(DaprProtos.PublishEventRequest.class), any()); + }).when(daprStub).publishEvent(any(DaprPubsubProtos.PublishEventRequest.class), any()); BulkPublishEntry> entry = new BulkPublishEntry<>("1", new HashMap<>(), "application/json", null); BulkPublishRequest> req = new BulkPublishRequest<>(PUBSUB_NAME, TOPIC_NAME, @@ -220,13 +217,13 @@ public void publishEventsSerializeException() throws IOException { @Test public void publishEventsTest() { doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; - DaprProtos.BulkPublishResponse.Builder builder = DaprProtos.BulkPublishResponse.newBuilder(); + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; + DaprPubsubProtos.BulkPublishResponse.Builder builder = DaprPubsubProtos.BulkPublishResponse.newBuilder(); observer.onNext(builder.build()); observer.onCompleted(); return null; - }).when(daprStub).bulkPublishEventAlpha1(any(DaprProtos.BulkPublishRequest.class), any()); + }).when(daprStub).bulkPublishEventAlpha1(any(DaprPubsubProtos.BulkPublishRequest.class), any()); BulkPublishEntry entry = new BulkPublishEntry<>("1", "test", "text/plain", null); @@ -241,13 +238,13 @@ public void publishEventsTest() { @Test public void publishEventsWithoutMetaTest() { doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; - DaprProtos.BulkPublishResponse.Builder builder = DaprProtos.BulkPublishResponse.newBuilder(); + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; + DaprPubsubProtos.BulkPublishResponse.Builder builder = DaprPubsubProtos.BulkPublishResponse.newBuilder(); observer.onNext(builder.build()); observer.onCompleted(); return null; - }).when(daprStub).bulkPublishEventAlpha1(any(DaprProtos.BulkPublishRequest.class), any()); + }).when(daprStub).bulkPublishEventAlpha1(any(DaprPubsubProtos.BulkPublishRequest.class), any()); Mono> result = previewClient.publishEvents(PUBSUB_NAME, TOPIC_NAME, "text/plain", Collections.singletonList("test")); @@ -259,13 +256,13 @@ public void publishEventsWithoutMetaTest() { @Test public void publishEventsWithRequestMetaTest() { doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; - DaprProtos.BulkPublishResponse.Builder builder = DaprProtos.BulkPublishResponse.newBuilder(); + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; + DaprPubsubProtos.BulkPublishResponse.Builder builder = DaprPubsubProtos.BulkPublishResponse.newBuilder(); observer.onNext(builder.build()); observer.onCompleted(); return null; - }).when(daprStub).bulkPublishEventAlpha1(any(DaprProtos.BulkPublishRequest.class), any()); + }).when(daprStub).bulkPublishEventAlpha1(any(DaprPubsubProtos.BulkPublishRequest.class), any()); Mono> result = previewClient.publishEvents(PUBSUB_NAME, TOPIC_NAME, "text/plain", new HashMap(){{ @@ -279,13 +276,13 @@ public void publishEventsWithRequestMetaTest() { @Test public void publishEventsObjectTest() { doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; - observer.onNext(DaprProtos.BulkPublishResponse.getDefaultInstance()); + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; + observer.onNext(DaprPubsubProtos.BulkPublishResponse.getDefaultInstance()); observer.onCompleted(); return null; }).when(daprStub).bulkPublishEventAlpha1(ArgumentMatchers.argThat(bulkPublishRequest -> { - DaprProtos.BulkPublishRequestEntry entry = bulkPublishRequest.getEntries(0); + DaprPubsubProtos.BulkPublishRequestEntry entry = bulkPublishRequest.getEntries(0); if (!"application/json".equals(bulkPublishRequest.getEntries(0).getContentType())) { return false; } @@ -311,13 +308,13 @@ public void publishEventsObjectTest() { @Test public void publishEventsContentTypeOverrideTest() { doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; - observer.onNext(DaprProtos.BulkPublishResponse.getDefaultInstance()); + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; + observer.onNext(DaprPubsubProtos.BulkPublishResponse.getDefaultInstance()); observer.onCompleted(); return null; }).when(daprStub).bulkPublishEventAlpha1(ArgumentMatchers.argThat(bulkPublishRequest -> { - DaprProtos.BulkPublishRequestEntry entry = bulkPublishRequest.getEntries(0); + DaprPubsubProtos.BulkPublishRequestEntry entry = bulkPublishRequest.getEntries(0); if (!"application/json".equals(entry.getContentType())) { return false; } @@ -363,19 +360,19 @@ public void queryStateExceptionsTest() { public void queryState() throws JsonProcessingException { List> resp = new ArrayList<>(); resp.add(new QueryStateItem("1", (Object)"testData", "6f54ad94-dfb9-46f0-a371-e42d550adb7d")); - DaprProtos.QueryStateResponse responseEnvelope = buildQueryStateResponse(resp, ""); + DaprStateProtos.QueryStateResponse responseEnvelope = buildQueryStateResponse(resp, ""); doAnswer(invocation -> { - DaprProtos.QueryStateRequest req = (DaprProtos.QueryStateRequest) invocation.getArgument(0); + DaprStateProtos.QueryStateRequest req = (DaprStateProtos.QueryStateRequest) invocation.getArgument(0); assertEquals(QUERY_STORE_NAME, req.getStoreName()); assertEquals("query", req.getQuery()); assertEquals(0, req.getMetadataCount()); - StreamObserver observer = (StreamObserver) + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).queryStateAlpha1(any(DaprProtos.QueryStateRequest.class), any()); + }).when(daprStub).queryStateAlpha1(any(DaprStateProtos.QueryStateRequest.class), any()); QueryStateResponse response = previewClient.queryState(QUERY_STORE_NAME, "query", String.class).block(); assertNotNull(response); @@ -389,20 +386,20 @@ public void queryState() throws JsonProcessingException { public void queryStateMetadataError() throws JsonProcessingException { List> resp = new ArrayList<>(); resp.add(new QueryStateItem("1", null, "error data")); - DaprProtos.QueryStateResponse responseEnvelope = buildQueryStateResponse(resp, ""); + DaprStateProtos.QueryStateResponse responseEnvelope = buildQueryStateResponse(resp, ""); doAnswer(invocation -> { - DaprProtos.QueryStateRequest req = (DaprProtos.QueryStateRequest) invocation.getArgument(0); + DaprStateProtos.QueryStateRequest req = (DaprStateProtos.QueryStateRequest) invocation.getArgument(0); assertEquals(QUERY_STORE_NAME, req.getStoreName()); assertEquals("query", req.getQuery()); assertEquals(1, req.getMetadataCount()); assertEquals(1, req.getMetadataCount()); - StreamObserver observer = (StreamObserver) + StreamObserver observer = (StreamObserver) invocation.getArguments()[1]; observer.onNext(responseEnvelope); observer.onCompleted(); return null; - }).when(daprStub).queryStateAlpha1(any(DaprProtos.QueryStateRequest.class), any()); + }).when(daprStub).queryStateAlpha1(any(DaprStateProtos.QueryStateRequest.class), any()); QueryStateResponse response = previewClient.queryState(QUERY_STORE_NAME, "query", new HashMap(){{ put("key", "error"); }}, String.class).block(); @@ -415,24 +412,24 @@ public void queryStateMetadataError() throws JsonProcessingException { @Test public void tryLock() { - DaprProtos.TryLockResponse.Builder builder = DaprProtos.TryLockResponse.newBuilder() + DaprLockProtos.TryLockResponse.Builder builder = DaprLockProtos.TryLockResponse.newBuilder() .setSuccess(true); - DaprProtos.TryLockResponse response = builder.build(); + DaprLockProtos.TryLockResponse response = builder.build(); doAnswer((Answer) invocation -> { - DaprProtos.TryLockRequest req = invocation.getArgument(0); + DaprLockProtos.TryLockRequest req = invocation.getArgument(0); assertEquals(LOCK_STORE_NAME, req.getStoreName()); assertEquals("1", req.getResourceId()); assertEquals("owner", req.getLockOwner()); assertEquals(10, req.getExpiryInSeconds()); - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(response); observer.onCompleted(); return null; - }).when(daprStub).tryLockAlpha1(any(DaprProtos.TryLockRequest.class), any()); + }).when(daprStub).tryLockAlpha1(any(DaprLockProtos.TryLockRequest.class), any()); Boolean result = previewClient.tryLock("MyLockStore", "1", "owner", 10).block(); assertEquals(Boolean.TRUE, result); @@ -441,23 +438,23 @@ public void tryLock() { @Test public void unLock() { - DaprProtos.UnlockResponse.Builder builder = DaprProtos.UnlockResponse.newBuilder() - .setStatus(DaprProtos.UnlockResponse.Status.SUCCESS); + DaprLockProtos.UnlockResponse.Builder builder = DaprLockProtos.UnlockResponse.newBuilder() + .setStatus(DaprLockProtos.UnlockResponse.Status.SUCCESS); - DaprProtos.UnlockResponse response = builder.build(); + DaprLockProtos.UnlockResponse response = builder.build(); doAnswer((Answer) invocation -> { - DaprProtos.UnlockRequest req = invocation.getArgument(0); + DaprLockProtos.UnlockRequest req = invocation.getArgument(0); assertEquals(LOCK_STORE_NAME, req.getStoreName()); assertEquals("1", req.getResourceId()); assertEquals("owner", req.getLockOwner()); - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(response); observer.onCompleted(); return null; - }).when(daprStub).unlockAlpha1(any(DaprProtos.UnlockRequest.class), any()); + }).when(daprStub).unlockAlpha1(any(DaprLockProtos.UnlockRequest.class), any()); UnlockResponseStatus result = previewClient.unlock("MyLockStore", "1", "owner").block(); assertEquals(UnlockResponseStatus.SUCCESS, result); @@ -475,18 +472,18 @@ public void subscribeEventTest() throws Exception { var started = new Semaphore(0); - doAnswer((Answer>) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[0]; + doAnswer((Answer>) invocation -> { + StreamObserver observer = + (StreamObserver) invocation.getArguments()[0]; var emitterThread = new Thread(() -> { try { started.acquire(); } catch (InterruptedException e) { throw new RuntimeException(e); } - observer.onNext(DaprProtos.SubscribeTopicEventsResponseAlpha1.getDefaultInstance()); + observer.onNext(DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1.getDefaultInstance()); for (int i = 0; i < numEvents; i++) { - observer.onNext(DaprProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() + observer.onNext(DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() .setEventMessage(DaprAppCallbackProtos.TopicEventRequest.newBuilder() .setId(Integer.toString(i)) .setPubsubName(pubsubName) @@ -499,7 +496,7 @@ public void subscribeEventTest() throws Exception { for (int i = 0; i < numDrops; i++) { // Bad messages - observer.onNext(DaprProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() + observer.onNext(DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() .setEventMessage(DaprAppCallbackProtos.TopicEventRequest.newBuilder() .setId(UUID.randomUUID().toString()) .setPubsubName("bad pubsub") @@ -515,7 +512,7 @@ public void subscribeEventTest() throws Exception { return new StreamObserver<>() { @Override - public void onNext(DaprProtos.SubscribeTopicEventsRequestAlpha1 subscribeTopicEventsRequestAlpha1) { + public void onNext(DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 subscribeTopicEventsRequestAlpha1) { started.release(); } @@ -586,9 +583,9 @@ public void subscribeEventFluxTest() throws Exception { var data = "my message"; var started = new Semaphore(0); - doAnswer((Answer>) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[0]; + doAnswer((Answer>) invocation -> { + StreamObserver observer = + (StreamObserver) invocation.getArguments()[0]; var emitterThread = new Thread(() -> { try { @@ -597,11 +594,11 @@ public void subscribeEventFluxTest() throws Exception { throw new RuntimeException(e); } - observer.onNext(DaprProtos.SubscribeTopicEventsResponseAlpha1.getDefaultInstance()); + observer.onNext(DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1.getDefaultInstance()); for (int i = 0; i < numEvents; i++) { - DaprProtos.SubscribeTopicEventsResponseAlpha1 reponse = - DaprProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() + DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1 reponse = + DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() .setEventMessage(DaprAppCallbackProtos.TopicEventRequest.newBuilder() .setId(Integer.toString(i)) .setPubsubName(pubsubName) @@ -620,7 +617,7 @@ public void subscribeEventFluxTest() throws Exception { return new StreamObserver<>() { @Override - public void onNext(DaprProtos.SubscribeTopicEventsRequestAlpha1 subscribeTopicEventsRequestAlpha1) { + public void onNext(DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 subscribeTopicEventsRequestAlpha1) { started.release(); } @@ -723,26 +720,26 @@ public void converseShouldThrowIllegalArgumentExceptionWhenInputContentIsEmpty() @Test public void converseShouldReturnConversationResponseWhenRequiredInputsAreValid() throws Exception { - DaprProtos.ConversationResponse conversationResponse = DaprProtos.ConversationResponse.newBuilder() - .addOutputs(DaprProtos.ConversationResult.newBuilder().setResult("Hello How are you").build()).build(); + DaprAiProtos.ConversationResponse conversationResponse = DaprAiProtos.ConversationResponse.newBuilder() + .addOutputs(DaprAiProtos.ConversationResult.newBuilder().setResult("Hello How are you").build()).build(); doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); + StreamObserver observer = invocation.getArgument(1); observer.onNext(conversationResponse); observer.onCompleted(); return null; - }).when(daprStub).converseAlpha1(any(DaprProtos.ConversationRequest.class), any()); + }).when(daprStub).converseAlpha1(any(DaprAiProtos.ConversationRequest.class), any()); List inputs = new ArrayList<>(); inputs.add(new ConversationInput("Hello there")); ConversationResponse response = previewClient.converse(new ConversationRequest("openai", inputs)).block(); - ArgumentCaptor captor = - ArgumentCaptor.forClass(DaprProtos.ConversationRequest.class); + ArgumentCaptor captor = + ArgumentCaptor.forClass(DaprAiProtos.ConversationRequest.class); verify(daprStub, times(1)).converseAlpha1(captor.capture(), Mockito.any()); - DaprProtos.ConversationRequest conversationRequest = captor.getValue(); + DaprAiProtos.ConversationRequest conversationRequest = captor.getValue(); assertEquals("openai", conversationRequest.getName()); assertEquals("Hello there", conversationRequest.getInputs(0).getContent()); @@ -752,16 +749,16 @@ public void converseShouldReturnConversationResponseWhenRequiredInputsAreValid() @Test public void converseShouldReturnConversationResponseWhenRequiredAndOptionalInputsAreValid() throws Exception { - DaprProtos.ConversationResponse conversationResponse = DaprProtos.ConversationResponse.newBuilder() + DaprAiProtos.ConversationResponse conversationResponse = DaprAiProtos.ConversationResponse.newBuilder() .setContextID("contextId") - .addOutputs(DaprProtos.ConversationResult.newBuilder().setResult("Hello How are you").build()).build(); + .addOutputs(DaprAiProtos.ConversationResult.newBuilder().setResult("Hello How are you").build()).build(); doAnswer(invocation -> { - StreamObserver observer = invocation.getArgument(1); + StreamObserver observer = invocation.getArgument(1); observer.onNext(conversationResponse); observer.onCompleted(); return null; - }).when(daprStub).converseAlpha1(any(DaprProtos.ConversationRequest.class), any()); + }).when(daprStub).converseAlpha1(any(DaprAiProtos.ConversationRequest.class), any()); ConversationInput daprConversationInput = new ConversationInput("Hello there") .setRole("Assistant") @@ -776,11 +773,11 @@ public void converseShouldReturnConversationResponseWhenRequiredAndOptionalInput .setScrubPii(true) .setTemperature(1.1d)).block(); - ArgumentCaptor captor = - ArgumentCaptor.forClass(DaprProtos.ConversationRequest.class); + ArgumentCaptor captor = + ArgumentCaptor.forClass(DaprAiProtos.ConversationRequest.class); verify(daprStub, times(1)).converseAlpha1(captor.capture(), Mockito.any()); - DaprProtos.ConversationRequest conversationRequest = captor.getValue(); + DaprAiProtos.ConversationRequest conversationRequest = captor.getValue(); assertEquals("openai", conversationRequest.getName()); assertEquals("contextId", conversationRequest.getContextID()); @@ -864,7 +861,7 @@ public void converseAlpha2ShouldThrowIllegalArgumentExceptionWhenInputIsEmpty() public void converseAlpha2ExceptionThrownTest() { doAnswer((Answer) invocation -> { throw newStatusRuntimeException("INVALID_ARGUMENT", "bad argument"); - }).when(daprStub).converseAlpha2(any(DaprProtos.ConversationRequestAlpha2.class), any()); + }).when(daprStub).converseAlpha2(any(DaprAiProtos.ConversationRequestAlpha2.class), any()); ConversationRequestAlpha2 request = new ConversationRequestAlpha2("openai", null); @@ -874,11 +871,11 @@ public void converseAlpha2ExceptionThrownTest() { @Test public void converseAlpha2CallbackExceptionThrownTest() { doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onError(newStatusRuntimeException("INVALID_ARGUMENT", "bad argument")); return null; - }).when(daprStub).converseAlpha2(any(DaprProtos.ConversationRequestAlpha2.class), any()); + }).when(daprStub).converseAlpha2(any(DaprAiProtos.ConversationRequestAlpha2.class), any()); List messages = new ArrayList<>(); SystemMessage systemMsg = new SystemMessage(List.of(new ConversationMessageContent("System info"))); @@ -899,13 +896,13 @@ public void converseAlpha2CallbackExceptionThrownTest() { @Test public void converseAlpha2MinimalRequestTest() { - DaprProtos.ConversationResponseAlpha2 grpcResponse = DaprProtos.ConversationResponseAlpha2.newBuilder() + DaprAiProtos.ConversationResponseAlpha2 grpcResponse = DaprAiProtos.ConversationResponseAlpha2.newBuilder() .setContextId("test-context") - .addOutputs(DaprProtos.ConversationResultAlpha2.newBuilder() - .addChoices(DaprProtos.ConversationResultChoices.newBuilder() + .addOutputs(DaprAiProtos.ConversationResultAlpha2.newBuilder() + .addChoices(DaprAiProtos.ConversationResultChoices.newBuilder() .setFinishReason("stop") .setIndex(0) - .setMessage(DaprProtos.ConversationResultMessage.newBuilder() + .setMessage(DaprAiProtos.ConversationResultMessage.newBuilder() .setContent("Hello! How can I help you today?") .build()) .build()) @@ -913,12 +910,12 @@ public void converseAlpha2MinimalRequestTest() { .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(grpcResponse); observer.onCompleted(); return null; - }).when(daprStub).converseAlpha2(any(DaprProtos.ConversationRequestAlpha2.class), any()); + }).when(daprStub).converseAlpha2(any(DaprAiProtos.ConversationRequestAlpha2.class), any()); List messages = new ArrayList<>(); DeveloperMessage devMsg = new DeveloperMessage(List.of(new ConversationMessageContent("Debug info"))); @@ -981,17 +978,17 @@ public void converseAlpha2ComplexRequestTest() { request.setParameters(parameters); // Mock response with tool calls - DaprProtos.ConversationResponseAlpha2 grpcResponse = DaprProtos.ConversationResponseAlpha2.newBuilder() + DaprAiProtos.ConversationResponseAlpha2 grpcResponse = DaprAiProtos.ConversationResponseAlpha2.newBuilder() .setContextId("test-context") - .addOutputs(DaprProtos.ConversationResultAlpha2.newBuilder() - .addChoices(DaprProtos.ConversationResultChoices.newBuilder() + .addOutputs(DaprAiProtos.ConversationResultAlpha2.newBuilder() + .addChoices(DaprAiProtos.ConversationResultChoices.newBuilder() .setFinishReason("tool_calls") .setIndex(0) - .setMessage(DaprProtos.ConversationResultMessage.newBuilder() + .setMessage(DaprAiProtos.ConversationResultMessage.newBuilder() .setContent("I'll help you get the weather information.") - .addToolCalls(DaprProtos.ConversationToolCalls.newBuilder() + .addToolCalls(DaprAiProtos.ConversationToolCalls.newBuilder() .setId("call_123") - .setFunction(DaprProtos.ConversationToolCallsOfFunction.newBuilder() + .setFunction(DaprAiProtos.ConversationToolCallsOfFunction.newBuilder() .setName("get_weather") .setArguments("{\"location\": \"New York\"}") .build()) @@ -1002,12 +999,12 @@ public void converseAlpha2ComplexRequestTest() { .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(grpcResponse); observer.onCompleted(); return null; - }).when(daprStub).converseAlpha2(any(DaprProtos.ConversationRequestAlpha2.class), any()); + }).when(daprStub).converseAlpha2(any(DaprAiProtos.ConversationRequestAlpha2.class), any()); ConversationResponseAlpha2 response = previewClient.converseAlpha2(request).block(); @@ -1025,11 +1022,11 @@ public void converseAlpha2ComplexRequestTest() { assertEquals("{\"location\": \"New York\"}", toolCall.getFunction().getArguments()); // Verify the request was built correctly - ArgumentCaptor captor = - ArgumentCaptor.forClass(DaprProtos.ConversationRequestAlpha2.class); + ArgumentCaptor captor = + ArgumentCaptor.forClass(DaprAiProtos.ConversationRequestAlpha2.class); verify(daprStub).converseAlpha2(captor.capture(), any()); - DaprProtos.ConversationRequestAlpha2 capturedRequest = captor.getValue(); + DaprAiProtos.ConversationRequestAlpha2 capturedRequest = captor.getValue(); assertEquals("openai", capturedRequest.getName()); assertEquals("test-context", capturedRequest.getContextId()); assertEquals(0.7, capturedRequest.getTemperature(), 0.001); @@ -1073,12 +1070,12 @@ public void converseAlpha2AllMessageTypesTest() { ConversationInputAlpha2 input = new ConversationInputAlpha2(messages); ConversationRequestAlpha2 request = new ConversationRequestAlpha2("openai", List.of(input)); - DaprProtos.ConversationResponseAlpha2 grpcResponse = DaprProtos.ConversationResponseAlpha2.newBuilder() - .addOutputs(DaprProtos.ConversationResultAlpha2.newBuilder() - .addChoices(DaprProtos.ConversationResultChoices.newBuilder() + DaprAiProtos.ConversationResponseAlpha2 grpcResponse = DaprAiProtos.ConversationResponseAlpha2.newBuilder() + .addOutputs(DaprAiProtos.ConversationResultAlpha2.newBuilder() + .addChoices(DaprAiProtos.ConversationResultChoices.newBuilder() .setFinishReason("stop") .setIndex(0) - .setMessage(DaprProtos.ConversationResultMessage.newBuilder() + .setMessage(DaprAiProtos.ConversationResultMessage.newBuilder() .setContent("Processed all message types") .build()) .build()) @@ -1086,12 +1083,12 @@ public void converseAlpha2AllMessageTypesTest() { .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(grpcResponse); observer.onCompleted(); return null; - }).when(daprStub).converseAlpha2(any(DaprProtos.ConversationRequestAlpha2.class), any()); + }).when(daprStub).converseAlpha2(any(DaprAiProtos.ConversationRequestAlpha2.class), any()); ConversationResponseAlpha2 response = previewClient.converseAlpha2(request).block(); @@ -1099,16 +1096,16 @@ public void converseAlpha2AllMessageTypesTest() { assertEquals("Processed all message types", response.getOutputs().get(0).getChoices().get(0).getMessage().getContent()); // Verify all message types were processed - ArgumentCaptor captor = - ArgumentCaptor.forClass(DaprProtos.ConversationRequestAlpha2.class); + ArgumentCaptor captor = + ArgumentCaptor.forClass(DaprAiProtos.ConversationRequestAlpha2.class); verify(daprStub).converseAlpha2(captor.capture(), any()); - DaprProtos.ConversationRequestAlpha2 capturedRequest = captor.getValue(); + DaprAiProtos.ConversationRequestAlpha2 capturedRequest = captor.getValue(); assertEquals(1, capturedRequest.getInputsCount()); assertEquals(5, capturedRequest.getInputs(0).getMessagesCount()); // Verify each message type was converted correctly - List capturedMessages = capturedRequest.getInputs(0).getMessagesList(); + List capturedMessages = capturedRequest.getInputs(0).getMessagesList(); assertTrue(capturedMessages.get(0).hasOfSystem()); assertTrue(capturedMessages.get(1).hasOfUser()); assertTrue(capturedMessages.get(2).hasOfAssistant()); @@ -1127,9 +1124,9 @@ public void converseAlpha2ResponseWithoutMessageTest() { ConversationRequestAlpha2 request = new ConversationRequestAlpha2("openai", List.of(input)); - DaprProtos.ConversationResponseAlpha2 grpcResponse = DaprProtos.ConversationResponseAlpha2.newBuilder() - .addOutputs(DaprProtos.ConversationResultAlpha2.newBuilder() - .addChoices(DaprProtos.ConversationResultChoices.newBuilder() + DaprAiProtos.ConversationResponseAlpha2 grpcResponse = DaprAiProtos.ConversationResponseAlpha2.newBuilder() + .addOutputs(DaprAiProtos.ConversationResultAlpha2.newBuilder() + .addChoices(DaprAiProtos.ConversationResultChoices.newBuilder() .setFinishReason("stop") .setIndex(0) // No message set @@ -1138,12 +1135,12 @@ public void converseAlpha2ResponseWithoutMessageTest() { .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(grpcResponse); observer.onCompleted(); return null; - }).when(daprStub).converseAlpha2(any(DaprProtos.ConversationRequestAlpha2.class), any()); + }).when(daprStub).converseAlpha2(any(DaprAiProtos.ConversationRequestAlpha2.class), any()); ConversationResponseAlpha2 response = previewClient.converseAlpha2(request).block(); @@ -1165,28 +1162,28 @@ public void converseAlpha2MultipleResultsTest() { ConversationRequestAlpha2 request = new ConversationRequestAlpha2("openai", List.of(input)); - DaprProtos.ConversationResponseAlpha2 grpcResponse = DaprProtos.ConversationResponseAlpha2.newBuilder() - .addOutputs(DaprProtos.ConversationResultAlpha2.newBuilder() - .addChoices(DaprProtos.ConversationResultChoices.newBuilder() + DaprAiProtos.ConversationResponseAlpha2 grpcResponse = DaprAiProtos.ConversationResponseAlpha2.newBuilder() + .addOutputs(DaprAiProtos.ConversationResultAlpha2.newBuilder() + .addChoices(DaprAiProtos.ConversationResultChoices.newBuilder() .setFinishReason("stop") .setIndex(0) - .setMessage(DaprProtos.ConversationResultMessage.newBuilder() + .setMessage(DaprAiProtos.ConversationResultMessage.newBuilder() .setContent("First choice") .build()) .build()) - .addChoices(DaprProtos.ConversationResultChoices.newBuilder() + .addChoices(DaprAiProtos.ConversationResultChoices.newBuilder() .setFinishReason("stop") .setIndex(1) - .setMessage(DaprProtos.ConversationResultMessage.newBuilder() + .setMessage(DaprAiProtos.ConversationResultMessage.newBuilder() .setContent("Second choice") .build()) .build()) .build()) - .addOutputs(DaprProtos.ConversationResultAlpha2.newBuilder() - .addChoices(DaprProtos.ConversationResultChoices.newBuilder() + .addOutputs(DaprAiProtos.ConversationResultAlpha2.newBuilder() + .addChoices(DaprAiProtos.ConversationResultChoices.newBuilder() .setFinishReason("length") .setIndex(0) - .setMessage(DaprProtos.ConversationResultMessage.newBuilder() + .setMessage(DaprAiProtos.ConversationResultMessage.newBuilder() .setContent("Third result") .build()) .build()) @@ -1194,12 +1191,12 @@ public void converseAlpha2MultipleResultsTest() { .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(grpcResponse); observer.onCompleted(); return null; - }).when(daprStub).converseAlpha2(any(DaprProtos.ConversationRequestAlpha2.class), any()); + }).when(daprStub).converseAlpha2(any(DaprAiProtos.ConversationRequestAlpha2.class), any()); ConversationResponseAlpha2 response = previewClient.converseAlpha2(request).block(); @@ -1228,14 +1225,14 @@ public void converseAlpha2ToolCallWithoutFunctionTest() { ConversationInputAlpha2 input = new ConversationInputAlpha2(messages); ConversationRequestAlpha2 request = new ConversationRequestAlpha2("openai", List.of(input)); - DaprProtos.ConversationResponseAlpha2 grpcResponse = DaprProtos.ConversationResponseAlpha2.newBuilder() - .addOutputs(DaprProtos.ConversationResultAlpha2.newBuilder() - .addChoices(DaprProtos.ConversationResultChoices.newBuilder() + DaprAiProtos.ConversationResponseAlpha2 grpcResponse = DaprAiProtos.ConversationResponseAlpha2.newBuilder() + .addOutputs(DaprAiProtos.ConversationResultAlpha2.newBuilder() + .addChoices(DaprAiProtos.ConversationResultChoices.newBuilder() .setFinishReason("tool_calls") .setIndex(0) - .setMessage(DaprProtos.ConversationResultMessage.newBuilder() + .setMessage(DaprAiProtos.ConversationResultMessage.newBuilder() .setContent("Test content") - .addToolCalls(DaprProtos.ConversationToolCalls.newBuilder() + .addToolCalls(DaprAiProtos.ConversationToolCalls.newBuilder() .setId("call_123") // No function set .build()) @@ -1245,12 +1242,12 @@ public void converseAlpha2ToolCallWithoutFunctionTest() { .build(); doAnswer((Answer) invocation -> { - StreamObserver observer = - (StreamObserver) invocation.getArguments()[1]; + StreamObserver observer = + (StreamObserver) invocation.getArguments()[1]; observer.onNext(grpcResponse); observer.onCompleted(); return null; - }).when(daprStub).converseAlpha2(any(DaprProtos.ConversationRequestAlpha2.class), any()); + }).when(daprStub).converseAlpha2(any(DaprAiProtos.ConversationRequestAlpha2.class), any()); ConversationResponseAlpha2 response = previewClient.converseAlpha2(request).block(); @@ -1261,20 +1258,20 @@ public void converseAlpha2ToolCallWithoutFunctionTest() { assertNull(toolCall.getFunction()); } - private DaprProtos.QueryStateResponse buildQueryStateResponse(List> resp,String token) + private DaprStateProtos.QueryStateResponse buildQueryStateResponse(List> resp, String token) throws JsonProcessingException { - List items = new ArrayList<>(); + List items = new ArrayList<>(); for (QueryStateItem item: resp) { items.add(buildQueryStateItem(item)); } - return DaprProtos.QueryStateResponse.newBuilder() + return DaprStateProtos.QueryStateResponse.newBuilder() .addAllResults(items) .setToken(token) .build(); } - private DaprProtos.QueryStateItem buildQueryStateItem(QueryStateItem item) throws JsonProcessingException { - DaprProtos.QueryStateItem.Builder it = DaprProtos.QueryStateItem.newBuilder().setKey(item.getKey()); + private DaprStateProtos.QueryStateItem buildQueryStateItem(QueryStateItem item) throws JsonProcessingException { + DaprStateProtos.QueryStateItem.Builder it = DaprStateProtos.QueryStateItem.newBuilder().setKey(item.getKey()); if (item.getValue() != null) { it.setData(ByteString.copyFrom(MAPPER.writeValueAsBytes(item.getValue()))); } @@ -1434,12 +1431,12 @@ public void encryptSuccessTest() { byte[] plaintext = "Hello, World!".getBytes(StandardCharsets.UTF_8); byte[] encryptedData = "encrypted-data".getBytes(StandardCharsets.UTF_8); - doAnswer((Answer>) invocation -> { - StreamObserver responseObserver = - (StreamObserver) invocation.getArguments()[0]; + doAnswer((Answer>) invocation -> { + StreamObserver responseObserver = + (StreamObserver) invocation.getArguments()[0]; // Simulate returning encrypted data - DaprProtos.EncryptResponse response = DaprProtos.EncryptResponse.newBuilder() + DaprCryptoProtos.EncryptResponse response = DaprCryptoProtos.EncryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(encryptedData)) .setSeq(0) @@ -1474,24 +1471,24 @@ public void encryptMultipleChunksResponseTest() { byte[] chunk2 = "chunk2".getBytes(StandardCharsets.UTF_8); byte[] chunk3 = "chunk3".getBytes(StandardCharsets.UTF_8); - doAnswer((Answer>) invocation -> { - StreamObserver responseObserver = - (StreamObserver) invocation.getArguments()[0]; + doAnswer((Answer>) invocation -> { + StreamObserver responseObserver = + (StreamObserver) invocation.getArguments()[0]; // Simulate returning multiple chunks - responseObserver.onNext(DaprProtos.EncryptResponse.newBuilder() + responseObserver.onNext(DaprCryptoProtos.EncryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(chunk1)) .setSeq(0) .build()) .build()); - responseObserver.onNext(DaprProtos.EncryptResponse.newBuilder() + responseObserver.onNext(DaprCryptoProtos.EncryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(chunk2)) .setSeq(1) .build()) .build()); - responseObserver.onNext(DaprProtos.EncryptResponse.newBuilder() + responseObserver.onNext(DaprCryptoProtos.EncryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(chunk3)) .setSeq(2) @@ -1525,11 +1522,11 @@ public void encryptWithDataEncryptionCipherTest() { byte[] plaintext = "Hello, World!".getBytes(StandardCharsets.UTF_8); byte[] encryptedData = "encrypted-data".getBytes(StandardCharsets.UTF_8); - doAnswer((Answer>) invocation -> { - StreamObserver responseObserver = - (StreamObserver) invocation.getArguments()[0]; + doAnswer((Answer>) invocation -> { + StreamObserver responseObserver = + (StreamObserver) invocation.getArguments()[0]; - DaprProtos.EncryptResponse response = DaprProtos.EncryptResponse.newBuilder() + DaprCryptoProtos.EncryptResponse response = DaprCryptoProtos.EncryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(encryptedData)) .setSeq(0) @@ -1561,11 +1558,11 @@ public void encryptWithOmitDecryptionKeyNameTest() { byte[] plaintext = "Hello, World!".getBytes(StandardCharsets.UTF_8); byte[] encryptedData = "encrypted-data".getBytes(StandardCharsets.UTF_8); - doAnswer((Answer>) invocation -> { - StreamObserver responseObserver = - (StreamObserver) invocation.getArguments()[0]; + doAnswer((Answer>) invocation -> { + StreamObserver responseObserver = + (StreamObserver) invocation.getArguments()[0]; - DaprProtos.EncryptResponse response = DaprProtos.EncryptResponse.newBuilder() + DaprCryptoProtos.EncryptResponse response = DaprCryptoProtos.EncryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(encryptedData)) .setSeq(0) @@ -1597,11 +1594,11 @@ public void encryptWithDecryptionKeyNameTest() { byte[] plaintext = "Hello, World!".getBytes(StandardCharsets.UTF_8); byte[] encryptedData = "encrypted-data".getBytes(StandardCharsets.UTF_8); - doAnswer((Answer>) invocation -> { - StreamObserver responseObserver = - (StreamObserver) invocation.getArguments()[0]; + doAnswer((Answer>) invocation -> { + StreamObserver responseObserver = + (StreamObserver) invocation.getArguments()[0]; - DaprProtos.EncryptResponse response = DaprProtos.EncryptResponse.newBuilder() + DaprCryptoProtos.EncryptResponse response = DaprCryptoProtos.EncryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(encryptedData)) .setSeq(0) @@ -1633,11 +1630,11 @@ public void encryptWithAllOptionalFieldsTest() { byte[] plaintext = "Hello, World!".getBytes(StandardCharsets.UTF_8); byte[] encryptedData = "encrypted-data".getBytes(StandardCharsets.UTF_8); - doAnswer((Answer>) invocation -> { - StreamObserver responseObserver = - (StreamObserver) invocation.getArguments()[0]; + doAnswer((Answer>) invocation -> { + StreamObserver responseObserver = + (StreamObserver) invocation.getArguments()[0]; - DaprProtos.EncryptResponse response = DaprProtos.EncryptResponse.newBuilder() + DaprCryptoProtos.EncryptResponse response = DaprCryptoProtos.EncryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(encryptedData)) .setSeq(0) @@ -1672,12 +1669,12 @@ public void encryptFilterEmptyDataTest() { byte[] plaintext = "Hello, World!".getBytes(StandardCharsets.UTF_8); byte[] validData = "valid-data".getBytes(StandardCharsets.UTF_8); - doAnswer((Answer>) invocation -> { - StreamObserver responseObserver = - (StreamObserver) invocation.getArguments()[0]; + doAnswer((Answer>) invocation -> { + StreamObserver responseObserver = + (StreamObserver) invocation.getArguments()[0]; // Send empty data - should be filtered - responseObserver.onNext(DaprProtos.EncryptResponse.newBuilder() + responseObserver.onNext(DaprCryptoProtos.EncryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.EMPTY) .setSeq(0) @@ -1685,7 +1682,7 @@ public void encryptFilterEmptyDataTest() { .build()); // Send valid data - responseObserver.onNext(DaprProtos.EncryptResponse.newBuilder() + responseObserver.onNext(DaprCryptoProtos.EncryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(validData)) .setSeq(1) @@ -1771,11 +1768,11 @@ public void decryptSuccessTest() { byte[] ciphertext = "encrypted-data".getBytes(StandardCharsets.UTF_8); byte[] decryptedData = "Hello, World!".getBytes(StandardCharsets.UTF_8); - doAnswer((Answer>) invocation -> { - StreamObserver responseObserver = - (StreamObserver) invocation.getArguments()[0]; + doAnswer((Answer>) invocation -> { + StreamObserver responseObserver = + (StreamObserver) invocation.getArguments()[0]; - DaprProtos.DecryptResponse response = DaprProtos.DecryptResponse.newBuilder() + DaprCryptoProtos.DecryptResponse response = DaprCryptoProtos.DecryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(decryptedData)) .setSeq(0) @@ -1805,23 +1802,23 @@ public void decryptMultipleChunksResponseTest() { byte[] chunk2 = "chunk2".getBytes(StandardCharsets.UTF_8); byte[] chunk3 = "chunk3".getBytes(StandardCharsets.UTF_8); - doAnswer((Answer>) invocation -> { - StreamObserver responseObserver = - (StreamObserver) invocation.getArguments()[0]; + doAnswer((Answer>) invocation -> { + StreamObserver responseObserver = + (StreamObserver) invocation.getArguments()[0]; - responseObserver.onNext(DaprProtos.DecryptResponse.newBuilder() + responseObserver.onNext(DaprCryptoProtos.DecryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(chunk1)) .setSeq(0) .build()) .build()); - responseObserver.onNext(DaprProtos.DecryptResponse.newBuilder() + responseObserver.onNext(DaprCryptoProtos.DecryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(chunk2)) .setSeq(1) .build()) .build()); - responseObserver.onNext(DaprProtos.DecryptResponse.newBuilder() + responseObserver.onNext(DaprCryptoProtos.DecryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(chunk3)) .setSeq(2) @@ -1850,11 +1847,11 @@ public void decryptWithKeyNameTest() { byte[] ciphertext = "encrypted-data".getBytes(StandardCharsets.UTF_8); byte[] decryptedData = "Hello, World!".getBytes(StandardCharsets.UTF_8); - doAnswer((Answer>) invocation -> { - StreamObserver responseObserver = - (StreamObserver) invocation.getArguments()[0]; + doAnswer((Answer>) invocation -> { + StreamObserver responseObserver = + (StreamObserver) invocation.getArguments()[0]; - DaprProtos.DecryptResponse response = DaprProtos.DecryptResponse.newBuilder() + DaprCryptoProtos.DecryptResponse response = DaprCryptoProtos.DecryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(decryptedData)) .setSeq(0) @@ -1883,12 +1880,12 @@ public void decryptFilterEmptyDataTest() { byte[] ciphertext = "encrypted-data".getBytes(StandardCharsets.UTF_8); byte[] validData = "valid-data".getBytes(StandardCharsets.UTF_8); - doAnswer((Answer>) invocation -> { - StreamObserver responseObserver = - (StreamObserver) invocation.getArguments()[0]; + doAnswer((Answer>) invocation -> { + StreamObserver responseObserver = + (StreamObserver) invocation.getArguments()[0]; // Send empty data - should be filtered - responseObserver.onNext(DaprProtos.DecryptResponse.newBuilder() + responseObserver.onNext(DaprCryptoProtos.DecryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.EMPTY) .setSeq(0) @@ -1896,7 +1893,7 @@ public void decryptFilterEmptyDataTest() { .build()); // Send valid data - responseObserver.onNext(DaprProtos.DecryptResponse.newBuilder() + responseObserver.onNext(DaprCryptoProtos.DecryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(validData)) .setSeq(1) @@ -1924,11 +1921,11 @@ public void decryptWithKeyNameVersionTest() { byte[] ciphertext = "encrypted-data".getBytes(StandardCharsets.UTF_8); byte[] decryptedData = "Hello, World!".getBytes(StandardCharsets.UTF_8); - doAnswer((Answer>) invocation -> { - StreamObserver responseObserver = - (StreamObserver) invocation.getArguments()[0]; + doAnswer((Answer>) invocation -> { + StreamObserver responseObserver = + (StreamObserver) invocation.getArguments()[0]; - DaprProtos.DecryptResponse response = DaprProtos.DecryptResponse.newBuilder() + DaprCryptoProtos.DecryptResponse response = DaprCryptoProtos.DecryptResponse.newBuilder() .setPayload(CommonProtos.StreamPayload.newBuilder() .setData(ByteString.copyFrom(decryptedData)) .setSeq(0) diff --git a/sdk/src/test/java/io/dapr/internal/subscription/EventSubscriberStreamObserverTest.java b/sdk/src/test/java/io/dapr/internal/subscription/EventSubscriberStreamObserverTest.java index 7328f79e51..f9551287b2 100644 --- a/sdk/src/test/java/io/dapr/internal/subscription/EventSubscriberStreamObserverTest.java +++ b/sdk/src/test/java/io/dapr/internal/subscription/EventSubscriberStreamObserverTest.java @@ -21,7 +21,7 @@ import io.dapr.utils.TypeRef; import io.dapr.v1.DaprAppCallbackProtos; import io.dapr.v1.DaprGrpc; -import io.dapr.v1.DaprProtos; +import io.dapr.v1.DaprPubsubProtos; import io.grpc.stub.StreamObserver; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -34,9 +34,17 @@ import java.util.List; import java.util.stream.Collectors; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.argThat; +import static org.mockito.Mockito.atLeast; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; /** * Unit tests for EventSubscriberStreamObserver. @@ -47,7 +55,7 @@ class EventSubscriberStreamObserverTest { public static final String TOPIC_NAME = "topic"; private DaprGrpc.DaprStub mockStub; private DaprObjectSerializer objectSerializer; - private StreamObserver mockRequestStream; + private StreamObserver mockRequestStream; @BeforeEach @SuppressWarnings("unchecked") @@ -71,12 +79,12 @@ void testSuccessfulEventProcessing() { ); // Start the subscription - DaprProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( ); observer.start(initialRequest); // Simulate receiving an event - DaprProtos.SubscribeTopicEventsResponseAlpha1 response = buildEventResponse( + DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1 response = buildEventResponse( "event-1", "Hello World" ); @@ -95,12 +103,12 @@ void testSuccessfulEventProcessing() { }) .verifyComplete(); - ArgumentCaptor requestCaptor = - ArgumentCaptor.forClass(DaprProtos.SubscribeTopicEventsRequestAlpha1.class); + ArgumentCaptor requestCaptor = + ArgumentCaptor.forClass(DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1.class); verify(mockRequestStream, times(2)).onNext(requestCaptor.capture()); - List requests = requestCaptor.getAllValues(); + List requests = requestCaptor.getAllValues(); assertEquals(2, requests.size()); assertTrue(requests.get(0).hasInitialRequest()); @@ -123,7 +131,7 @@ void testMultipleEvents() { objectSerializer ); - DaprProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( ); observer.start(initialRequest); @@ -163,12 +171,12 @@ void testDeserializationError() { objectSerializer ); - DaprProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( ); observer.start(initialRequest); // Send an event with invalid data (can't deserialize to String) - DaprProtos.SubscribeTopicEventsResponseAlpha1 response = DaprProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() + DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1 response = DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() .setEventMessage( DaprAppCallbackProtos.TopicEventRequest.newBuilder() .setId("event-1") @@ -189,13 +197,13 @@ void testDeserializationError() { && error.getMessage().contains("event-1")) .verify(); - ArgumentCaptor requestCaptor = - ArgumentCaptor.forClass(DaprProtos.SubscribeTopicEventsRequestAlpha1.class); + ArgumentCaptor requestCaptor = + ArgumentCaptor.forClass(DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1.class); verify(mockRequestStream, atLeast(2)).onNext(requestCaptor.capture()); - List ackRequests = requestCaptor.getAllValues().stream() - .filter(DaprProtos.SubscribeTopicEventsRequestAlpha1::hasEventProcessed) + List ackRequests = requestCaptor.getAllValues().stream() + .filter(DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1::hasEventProcessed) .collect(Collectors.toList()); assertEquals(1, ackRequests.size()); @@ -217,7 +225,7 @@ void testProcessingError() { objectSerializer ); - DaprProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest(); + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest(); observer.start(initialRequest); // Simulate a processing error by throwing during sink.next() @@ -248,7 +256,7 @@ void testGrpcError() { objectSerializer ); - DaprProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest(); + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest(); observer.start(initialRequest); // Simulate gRPC error @@ -271,11 +279,11 @@ void testNullEventMessage() { objectSerializer ); - DaprProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( ); observer.start(initialRequest); - DaprProtos.SubscribeTopicEventsResponseAlpha1 response = DaprProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() + DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1 response = DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() .build(); observer.onNext(response); @@ -299,11 +307,11 @@ void testEmptyPubsubName() { objectSerializer ); - DaprProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( ); observer.start(initialRequest); - DaprProtos.SubscribeTopicEventsResponseAlpha1 response = DaprProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() + DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1 response = DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() .setEventMessage( DaprAppCallbackProtos.TopicEventRequest.newBuilder() .setId("event-1") @@ -335,11 +343,11 @@ void testEmptyEventId() { objectSerializer ); - DaprProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( ); observer.start(initialRequest); - DaprProtos.SubscribeTopicEventsResponseAlpha1 response = DaprProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() + DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1 response = DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() .setEventMessage( DaprAppCallbackProtos.TopicEventRequest.newBuilder() .setId("") @@ -371,7 +379,7 @@ void testNullData() { objectSerializer ); - DaprProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( ); observer.start(initialRequest); @@ -405,11 +413,11 @@ void testComplexObjectSerialization() throws IOException { objectSerializer ); - DaprProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest( ); observer.start(initialRequest); - DaprProtos.SubscribeTopicEventsResponseAlpha1 response = DaprProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() + DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1 response = DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() .setEventMessage( DaprAppCallbackProtos.TopicEventRequest.newBuilder() .setId("event-1") @@ -439,7 +447,7 @@ void testComplexObjectSerialization() throws IOException { void testErrorDuringSendingAck() { doThrow(new RuntimeException("Failed to send ack")) .when(mockRequestStream) - .onNext(argThat(DaprProtos.SubscribeTopicEventsRequestAlpha1::hasEventProcessed)); + .onNext(argThat(DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1::hasEventProcessed)); Flux> flux = Flux.create(sink -> { EventSubscriberStreamObserver observer = new EventSubscriberStreamObserver<>( @@ -449,7 +457,7 @@ void testErrorDuringSendingAck() { objectSerializer ); - DaprProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest(); + DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 initialRequest = buildInitialRequest(); observer.start(initialRequest); observer.onNext(buildEventResponse("event-1", "Hello")); @@ -461,10 +469,10 @@ void testErrorDuringSendingAck() { .verify(); } - private DaprProtos.SubscribeTopicEventsRequestAlpha1 buildInitialRequest() { - return DaprProtos.SubscribeTopicEventsRequestAlpha1.newBuilder() + private DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1 buildInitialRequest() { + return DaprPubsubProtos.SubscribeTopicEventsRequestAlpha1.newBuilder() .setInitialRequest( - DaprProtos.SubscribeTopicEventsRequestInitialAlpha1.newBuilder() + DaprPubsubProtos.SubscribeTopicEventsRequestInitialAlpha1.newBuilder() .setPubsubName(PUBSUB_NAME) .setTopic(TOPIC_NAME) .build() @@ -472,11 +480,11 @@ private DaprProtos.SubscribeTopicEventsRequestAlpha1 buildInitialRequest() { .build(); } - private DaprProtos.SubscribeTopicEventsResponseAlpha1 buildEventResponse(String eventId, String data) { + private DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1 buildEventResponse(String eventId, String data) { try { byte[] serializedData = objectSerializer.serialize(data); - return DaprProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() + return DaprPubsubProtos.SubscribeTopicEventsResponseAlpha1.newBuilder() .setEventMessage( DaprAppCallbackProtos.TopicEventRequest.newBuilder() .setId(eventId)