Skip to content

Commit

Permalink
Add review comments
Browse files Browse the repository at this point in the history
Make naming consistent between java and python for uuid/uri serializers/deserializers.
  • Loading branch information
matthewd0123 committed Apr 16, 2024
1 parent 9c071b0 commit 530a135
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 44 deletions.
59 changes: 23 additions & 36 deletions test_agent/java/src/main/java/org/eclipse/uprotocol/TestAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public class TestAgent {
actionHandlers.put(Constant.REGISTER_LISTENER_COMMAND, TestAgent::handleRegisterListenerCommand);
actionHandlers.put(Constant.UNREGISTER_LISTENER_COMMAND, TestAgent::handleUnregisterListenerCommand);
actionHandlers.put(Constant.INVOKE_METHOD_COMMAND, TestAgent::handleInvokeMethodCommand);
actionHandlers.put(Constant.SERIALIZE_URI, TestAgent::handleSerializeUriCommand);
actionHandlers.put(Constant.DESERIALIZE_URI, TestAgent::handleDeserializeUriCommand);
actionHandlers.put(Constant.SERIALIZE_URI, TestAgent::handleLongSerializeUriCommand);
actionHandlers.put(Constant.DESERIALIZE_URI, TestAgent::handleLongDeserializeUriCommand);
actionHandlers.put(Constant.VALIDATE_URI, TestAgent::handleValidateUriCommand);
actionHandlers.put(Constant.SERIALIZE_UUID, TestAgent::handleSerializeUuidCommand);
actionHandlers.put(Constant.DESERIALIZE_UUID, TestAgent::handleDeserializeUuidCommand);
actionHandlers.put(Constant.SERIALIZE_UUID, TestAgent::handleLongSerializeUuidCommand);
actionHandlers.put(Constant.DESERIALIZE_UUID, TestAgent::handleLongDeserializeUuidCommand);

}

Expand All @@ -92,28 +92,35 @@ public static void processMessage(Map<String, Object> jsonData) throws IOExcepti
}
}

private static void sendToTestManager(Object json, String action) {
sendToTestManager(json, action, null);
}

private static void sendToTestManager(Message proto, String action) {
// Create a new dictionary
sendToTestManager(proto, action, null);
}

private static void sendToTestManager(Object json, String action, String received_test_id) {
JSONObject responseDict = new JSONObject();

responseDict.put("data", ProtoConverter.convertMessageToMap(proto));
responseDict.put("data", json);
if (received_test_id != null) {
responseDict.put("test_id", received_test_id);
}
writeDataToTMSocket(responseDict, action);
}

private static void sendToTestManager(Message proto, String action, String received_test_id) {
// Create a new dictionary
JSONObject responseDict = new JSONObject();
responseDict.put("data", ProtoConverter.convertMessageToMap(proto));
responseDict.put("test_id", received_test_id);

if (received_test_id != null) {
responseDict.put("test_id", received_test_id);
}
writeDataToTMSocket(responseDict, action);
}

private static void writeDataToTMSocket(JSONObject responseDict, String action) {
responseDict.put("action", action);
responseDict.put("ue", "java");


try {
OutputStream outputStream = clientSocket.getOutputStream();
outputStream.write(responseDict.toString().getBytes(StandardCharsets.UTF_8));
Expand All @@ -125,25 +132,6 @@ private static void writeDataToTMSocket(JSONObject responseDict, String action)

}
}

private static void sendToTestManager(Object json, String action) {
// Object json should be str or dict
// Create a new dictionary
JSONObject responseDict = new JSONObject();
responseDict.put("data", json);
writeDataToTMSocket(responseDict, action);

}

private static void sendToTestManager(Object json, String action, String received_test_id) {
// Create a new dictionary
JSONObject responseDict = new JSONObject();
responseDict.put("data", json);
responseDict.put("test_id", received_test_id);

writeDataToTMSocket(responseDict, action);

}

private static UStatus handleSendCommand(Map<String, Object> jsonData) {
UMessage uMessage = (UMessage) ProtoConverter.dictToProto((Map<String, Object>) jsonData.get("data"),
Expand Down Expand Up @@ -177,7 +165,7 @@ private static Object handleInvokeMethodCommand(Map<String, Object> jsonData) {
return null;
}

private static Object handleSerializeUriCommand(Map<String, Object> jsonData) {
private static Object handleLongSerializeUriCommand(Map<String, Object> jsonData) {
Map<String, Object> data = (Map<String, Object>) jsonData.get("data");
UUri uri = (UUri) ProtoConverter.dictToProto(data, UUri.newBuilder());
String serializedUuri = LongUriSerializer.instance().serialize(uri);
Expand All @@ -186,7 +174,7 @@ private static Object handleSerializeUriCommand(Map<String, Object> jsonData) {
return null;
}

private static Object handleDeserializeUriCommand(Map<String, Object> jsonData) {
private static Object handleLongDeserializeUriCommand(Map<String, Object> jsonData) {
UUri uri = LongUriSerializer.instance().deserialize(jsonData.get("data").toString());
String testID = (String) jsonData.get("test_id");
sendToTestManager(uri, Constant.DESERIALIZE_URI, testID);
Expand Down Expand Up @@ -246,7 +234,7 @@ private static Object handleValidateUriCommand(Map<String, Object> jsonData) {
return null;
}

private static Object handleSerializeUuidCommand(Map<String, Object> jsonData) {
private static Object handleLongSerializeUuidCommand(Map<String, Object> jsonData) {
Map<String, Object> data = (Map<String, Object>) jsonData.get("data");
UUID uuid = (UUID) ProtoConverter.dictToProto(data, UUID.newBuilder());
String serializedUUid = LongUuidSerializer.instance().serialize(uuid);
Expand All @@ -255,8 +243,7 @@ private static Object handleSerializeUuidCommand(Map<String, Object> jsonData) {
return null;
}

private static Object handleDeserializeUuidCommand(Map<String, Object> jsonData) {

private static Object handleLongDeserializeUuidCommand(Map<String, Object> jsonData) {
UUID uuid = LongUuidSerializer.instance().deserialize(jsonData.get("data").toString());
String testID = (String) jsonData.get("test_id");
sendToTestManager(uuid, Constant.DESERIALIZE_UUID, testID);
Expand Down
16 changes: 8 additions & 8 deletions test_agent/python/testagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def handle_response(message):
res_future.add_done_callback(handle_response)


def send_longserialize_uuri(json_msg: Dict[str, Any]):
def handle_long_serialize_uuri(json_msg: Dict[str, Any]):
uri: UUri = dict_to_proto(json_msg["data"], UUri())
serialized_uuri: str = LongUriSerializer().serialize(uri)
send_to_test_manager(
Expand All @@ -220,21 +220,21 @@ def send_longserialize_uuri(json_msg: Dict[str, Any]):
)


def send_longdeserialize_uri(json_msg: Dict[str, Any]):
def handle_long_deserialize_uri(json_msg: Dict[str, Any]):
uuri: UUri = LongUriSerializer().deserialize(json_msg["data"])
send_to_test_manager(
uuri, CONSTANTS.DESERIALIZE_URI, received_test_id=json_msg["test_id"]
)


def send_longdeserialize_uuid(json_msg: Dict[str, Any]):
def handle_long_deserialize_uuid(json_msg: Dict[str, Any]):
uuid: UUID = LongUuidSerializer().deserialize(json_msg["data"])
send_to_test_manager(
uuid, CONSTANTS.DESERIALIZE_UUID, received_test_id=json_msg["test_id"]
)


def send_longserialize_uuid(json_msg: Dict[str, Any]):
def handle_long_serialize_uuid(json_msg: Dict[str, Any]):
uuid: UUID = dict_to_proto(json_msg["data"], UUID())
serialized_uuid: str = LongUuidSerializer().serialize(uuid)
send_to_test_manager(
Expand Down Expand Up @@ -280,10 +280,10 @@ def handle_uri_validate_command(json_msg):
CONSTANTS.REGISTER_LISTENER_COMMAND: handle_register_listener_command,
CONSTANTS.UNREGISTER_LISTENER_COMMAND: handle_unregister_listener_command,
CONSTANTS.INVOKE_METHOD_COMMAND: handle_invoke_method_command,
CONSTANTS.SERIALIZE_URI: send_longserialize_uuri,
CONSTANTS.DESERIALIZE_URI: send_longdeserialize_uri,
CONSTANTS.SERIALIZE_UUID: send_longserialize_uuid,
CONSTANTS.DESERIALIZE_UUID: send_longdeserialize_uuid,
CONSTANTS.SERIALIZE_URI: handle_long_serialize_uuri,
CONSTANTS.DESERIALIZE_URI: handle_long_deserialize_uri,
CONSTANTS.SERIALIZE_UUID: handle_long_serialize_uuid,
CONSTANTS.DESERIALIZE_UUID: handle_long_deserialize_uuid,
CONSTANTS.VALIDATE_URI: handle_uri_validate_command,
}

Expand Down

0 comments on commit 530a135

Please sign in to comment.