From 530a13560e7272fe0ba6c83bb3801e33b9d51f46 Mon Sep 17 00:00:00 2001 From: Matthew D'Alonzo Date: Tue, 16 Apr 2024 15:21:43 -0400 Subject: [PATCH] Add review comments Make naming consistent between java and python for uuid/uri serializers/deserializers. --- .../java/org/eclipse/uprotocol/TestAgent.java | 59 ++++++++----------- test_agent/python/testagent.py | 16 ++--- 2 files changed, 31 insertions(+), 44 deletions(-) diff --git a/test_agent/java/src/main/java/org/eclipse/uprotocol/TestAgent.java b/test_agent/java/src/main/java/org/eclipse/uprotocol/TestAgent.java index aae49120..80881c0d 100644 --- a/test_agent/java/src/main/java/org/eclipse/uprotocol/TestAgent.java +++ b/test_agent/java/src/main/java/org/eclipse/uprotocol/TestAgent.java @@ -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); } @@ -92,28 +92,35 @@ public static void processMessage(Map 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)); @@ -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 jsonData) { UMessage uMessage = (UMessage) ProtoConverter.dictToProto((Map) jsonData.get("data"), @@ -177,7 +165,7 @@ private static Object handleInvokeMethodCommand(Map jsonData) { return null; } - private static Object handleSerializeUriCommand(Map jsonData) { + private static Object handleLongSerializeUriCommand(Map jsonData) { Map data = (Map) jsonData.get("data"); UUri uri = (UUri) ProtoConverter.dictToProto(data, UUri.newBuilder()); String serializedUuri = LongUriSerializer.instance().serialize(uri); @@ -186,7 +174,7 @@ private static Object handleSerializeUriCommand(Map jsonData) { return null; } - private static Object handleDeserializeUriCommand(Map jsonData) { + private static Object handleLongDeserializeUriCommand(Map jsonData) { UUri uri = LongUriSerializer.instance().deserialize(jsonData.get("data").toString()); String testID = (String) jsonData.get("test_id"); sendToTestManager(uri, Constant.DESERIALIZE_URI, testID); @@ -246,7 +234,7 @@ private static Object handleValidateUriCommand(Map jsonData) { return null; } - private static Object handleSerializeUuidCommand(Map jsonData) { + private static Object handleLongSerializeUuidCommand(Map jsonData) { Map data = (Map) jsonData.get("data"); UUID uuid = (UUID) ProtoConverter.dictToProto(data, UUID.newBuilder()); String serializedUUid = LongUuidSerializer.instance().serialize(uuid); @@ -255,8 +243,7 @@ private static Object handleSerializeUuidCommand(Map jsonData) { return null; } - private static Object handleDeserializeUuidCommand(Map jsonData) { - + private static Object handleLongDeserializeUuidCommand(Map jsonData) { UUID uuid = LongUuidSerializer.instance().deserialize(jsonData.get("data").toString()); String testID = (String) jsonData.get("test_id"); sendToTestManager(uuid, Constant.DESERIALIZE_UUID, testID); diff --git a/test_agent/python/testagent.py b/test_agent/python/testagent.py index 7a16323e..1811a56e 100644 --- a/test_agent/python/testagent.py +++ b/test_agent/python/testagent.py @@ -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( @@ -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( @@ -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, }