Implementation of the ActorAsyncProxy - #58
JuanJose-Herrera wants to merge 2 commits into
Conversation
Change the implement the calls to DAPR using the class AbstractDaprClient because before the change the class always return Mono.Empty Implementation of the ActorAsyncProxy Change the name of the Actor Dapr Http Async Client
|
|
||
| post(stateUrl, state.toString()).thenAccept(response -> { | ||
| int resCode = response.statusCode() == 200 ? 200 : 500; | ||
| int resCode = response.statusCode() == 201 ? 201 : 500; |
There was a problem hiding this comment.
Please, support both 200 and 201.
| * @return Asynchronous result with the Actor's response. | ||
| */ | ||
| Mono<String> invokeActorMethod(String actorType, String actorId, String methodName, String jsonPayload); | ||
| <T> Mono<T> invokeActorMethod(String methodName, Object data, Class<T> clazz) throws JsonProcessingException; |
| * @param methodName Method name to invoke. | ||
| * @return Asynchronous result with the Actor's response. | ||
| */ | ||
| public Mono invokeActorMethod(String methodName) ; |
| * @param data Object with the data. | ||
| * @return Asynchronous result with the Actor's response. | ||
| */ | ||
| public Mono invokeActorMethod(String methodName, Object data) throws JsonProcessingException; |
There was a problem hiding this comment.
Exception and Mono<Void>
| */ | ||
| private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); | ||
|
|
||
| private ActorId actorId; |
There was a problem hiding this comment.
This class should remain stateless without awareness of actorid and actortype.
| /** | ||
| * Interface to invoke actor methods. | ||
| */ | ||
| interface ActorProxyAsyncClient { |
There was a problem hiding this comment.
This one maps to ActorProxy in .net sdk.
There was a problem hiding this comment.
Move implementation to a new ActorProxy interface. Leave this file unchanged.
| * Http client to call actors methods. | ||
| */ | ||
| class ActorProxyHttpAsyncClient extends AbstractDaprClient implements ActorProxyAsyncClient { | ||
| public class ActorProxyHttpAsyncClient extends AbstractDaprClient implements ActorProxyAsyncClient { |
There was a problem hiding this comment.
Revert this change.
Move implementation for ActorProxy to ActorProxyImpl
| * Requires Dapr running. | ||
| */ | ||
| public class DaprHttpAsyncClientIT { | ||
| public class DaprHttpAsyncClientTest { |
There was a problem hiding this comment.
Keep it untouched and move your tests to a new class.
Also IT means integration tests in Maven.
Test mean unit tests.
artursouza
left a comment
There was a problem hiding this comment.
Thanks for this PR. This first one will have more comments as you onboard into the code style and learn about previous decisions in the code (like the async call in the http client - we want to keep that).
| String respBodyString = responseBody.string(); | ||
| cb.onSuccess(respBodyString); | ||
| response.close(); | ||
| try (Response response = this.httpClient.newCall(request).execute()) { |
There was a problem hiding this comment.
Revert this change to the previous solution. This one is a blocking operation while the previous one was async.
| */ | ||
| public final Mono<String> invokeAPI(String method, String urlString, String json) throws RuntimeException { | ||
|
|
||
| DaprHttpCallback cb = new DaprHttpCallback() { |
There was a problem hiding this comment.
Keep this and the previous async code.
| */ | ||
| ActorId getActorId(); | ||
|
|
||
|
|
| import reactor.core.publisher.Mono; | ||
|
|
||
| import java.io.IOException; | ||
|
|
There was a problem hiding this comment.
Javadoc this interface, specially because it is client facing.
| * @param clazz The type of the return class. | ||
| * @return Asynchronous result with the Actor's response. | ||
| */ | ||
| <T> Mono<T> invokeActorMethod(String methodName, Object data, Class<T> clazz) throws IOException; |
There was a problem hiding this comment.
Don't throw, just let the Mono response handle the exception async.
| */ | ||
| private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); | ||
|
|
||
| private ActorId actorId; |
| private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); | ||
|
|
||
| private ActorId actorId; | ||
| private String actorType; |
|
|
||
| private ActorId actorId; | ||
| private String actorType; | ||
| private ActorProxyHttpAsyncClient abstractDaprClient; |
|
|
||
| @Test() | ||
| public void constructorActorProxyTest() { | ||
| final ActorProxyHttpAsyncClient actorProxyAsyncClient = (ActorProxyHttpAsyncClient)new ActorProxyClientBuilder().buildAsyncClient(); |
There was a problem hiding this comment.
Mock it, not real http communication for unit tests.
| public class OrderManager { | ||
|
|
||
| static HttpClient httpClient; | ||
| static final List<Integer> httpOkStatus = Arrays.asList(200,201); |
There was a problem hiding this comment.
Theoretically this is mutable, so it should be wrapped with Collections.unmodifiableList(). It is simpler to just use OR in the if condition.
|
Took your changes (commits) and put some fixes and refactoring on top: #62 |
Change the implement the calls to DAPR using the class AbstractDaprClient because before the change the class always return Mono.Empty
Implementation of the ActorAsyncProxy
Change the name of the Actor Dapr Http Async Client
Description
Please explain the changes you've made
Issue reference
We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.
Please reference the issue this PR will close: #[issue number]
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: