Skip to content

Implementation of the ActorAsyncProxy - #58

Closed
JuanJose-Herrera wants to merge 2 commits into
dapr:java_sdk_wipfrom
JuanJose-Herrera:java_sdk_wip
Closed

JuanJose-Herrera wants to merge 2 commits into
dapr:java_sdk_wipfrom
JuanJose-Herrera:java_sdk_wip

Conversation

@JuanJose-Herrera

Copy link
Copy Markdown
Contributor

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:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

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
@msftclas

msftclas commented Dec 24, 2019

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.


post(stateUrl, state.toString()).thenAccept(response -> {
int resCode = response.statusCode() == 200 ? 200 : 500;
int resCode = response.statusCode() == 201 ? 201 : 500;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throws IOException

* @param methodName Method name to invoke.
* @return Asynchronous result with the Actor's response.
*/
public Mono invokeActorMethod(String methodName) ;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mono<Void>

* @param data Object with the data.
* @return Asynchronous result with the Actor's response.
*/
public Mono invokeActorMethod(String methodName, Object data) throws JsonProcessingException;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exception and Mono<Void>

*/
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private ActorId actorId;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class should remain stateless without awareness of actorid and actortype.

/**
* Interface to invoke actor methods.
*/
interface ActorProxyAsyncClient {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one maps to ActorProxy in .net sdk.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change.
Move implementation for ActorProxy to ActorProxyImpl

* Requires Dapr running.
*/
public class DaprHttpAsyncClientIT {
public class DaprHttpAsyncClientTest {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep it untouched and move your tests to a new class.

Also IT means integration tests in Maven.
Test mean unit tests.

@artursouza artursouza left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this and the previous async code.

*/
ActorId getActorId();


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excessive spacing.

import reactor.core.publisher.Mono;

import java.io.IOException;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't throw, just let the Mono response handle the exception async.

*/
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private ActorId actorId;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private ActorId actorId;
private String actorType;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final


private ActorId actorId;
private String actorType;
private ActorProxyHttpAsyncClient abstractDaprClient;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final


@Test()
public void constructorActorProxyTest() {
final ActorProxyHttpAsyncClient actorProxyAsyncClient = (ActorProxyHttpAsyncClient)new ActorProxyClientBuilder().buildAsyncClient();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mock it, not real http communication for unit tests.

public class OrderManager {

static HttpClient httpClient;
static final List<Integer> httpOkStatus = Arrays.asList(200,201);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTTP_OK_STATUSES

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically this is mutable, so it should be wrapped with Collections.unmodifiableList(). It is simpler to just use OR in the if condition.

@artursouza

Copy link
Copy Markdown
Contributor

Took your changes (commits) and put some fixes and refactoring on top: #62

@artursouza artursouza closed this Dec 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants