diff --git a/.gitattributes b/.gitattributes index 304c4b2666e711418acbb9e908bdb7c923c8daf0..9f2726c09f75333b7fc38e6ecbaeb9b6929a48dc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1631,9 +1631,6 @@ LCS/Messaging/python/messaging/test/t_messagebus.sh -text LCS/Messaging/python/messaging/test/t_messages.py -text LCS/Messaging/python/messaging/test/t_messages.run -text LCS/Messaging/python/messaging/test/t_messages.sh -text -LCS/Messaging/python/messaging/test/t_service_message_handler.py -text -LCS/Messaging/python/messaging/test/t_service_message_handler.run -text svneol=unset#application/x-shellscript -LCS/Messaging/python/messaging/test/t_service_message_handler.sh -text svneol=unset#application/x-shellscript LCS/Messaging/src/CMakeLists.txt -text LCS/Messaging/src/DefaultSettings.cc -text LCS/Messaging/src/EventMessage.cc -text diff --git a/LCS/Messaging/python/messaging/test/CMakeLists.txt b/LCS/Messaging/python/messaging/test/CMakeLists.txt index 6b503a29c317ea140f6c3c13263ae8db82e67cba..d99e64ffa445afcba569e7a842e8ee6f16f2e5dc 100644 --- a/LCS/Messaging/python/messaging/test/CMakeLists.txt +++ b/LCS/Messaging/python/messaging/test/CMakeLists.txt @@ -4,6 +4,5 @@ include(LofarCTest) lofar_add_test(t_messages) lofar_add_test(t_messagebus) -lofar_add_test(t_service_message_handler) lofar_add_test(t_RPC) diff --git a/LCS/Messaging/python/messaging/test/t_service_message_handler.py b/LCS/Messaging/python/messaging/test/t_service_message_handler.py deleted file mode 100644 index 6aa1d15eb6297eba0bd1ff55fc203799a411a1f5..0000000000000000000000000000000000000000 --- a/LCS/Messaging/python/messaging/test/t_service_message_handler.py +++ /dev/null @@ -1,225 +0,0 @@ -#!/usr/bin/env python3 -""" -Program to test the RPCClient and RPCService class of the Messaging package. -It defines 5 functions and first calls those functions directly to check -that the functions are OK. Next the same tests are done with the RPCClient and -RPCService classes in between. This should give the same results. -""" -import sys -import time -from lofar.messaging.messagebus import TemporaryExchange, BusListenerJanitor -from lofar.messaging.Service import ServiceMessageHandler, Service -from lofar.messaging.RPCClient import RPCClient - -import logging -logger = logging.getLogger(__name__) - -class UserException(Exception): - "Always thrown in one of the functions" - pass - -class InvalidArgType(Exception): - "Thrown when the input is wrong for one of the functions" - pass - -# create several function: -def ErrorFunc(input_value): - " Always thrown a predefined exception" - raise UserException("Intentional exception for testing") - -def ExceptionFunc(input_value): - "Generate a exception not caught by the function" - a = "aap" - b = a[23] - -def StringFunc(input_value): - "Convert the string to uppercase." - if not isinstance(input_value, str) and not isinstance(input_value, str): - raise InvalidArgType("Input value must be of the type 'string'") - return input_value.upper() - -class OnlyMessageHandling(ServiceMessageHandler): - def __init__(self, **kwargs): - ServiceMessageHandler.__init__(self) - logger.info("Creation of OnlyMessageHandling class: %s" % kwargs) - self.handle_message = kwargs.pop("function") - self.args = kwargs - -class FullMessageHandling(ServiceMessageHandler): - def __init__(self, **kwargs): - ServiceMessageHandler.__init__(self) - logger.info("Creation of FullMessageHandling class: %s" % kwargs) - self.handle_message = kwargs.pop("function") - self.args = kwargs - def prepare_loop(self): - logger.info("FullMessageHandling prepare_loop: %s" % self.args) - def prepare_receive(self): - logger.info("FullMessageHandling prepare_receive: %s" % self.args) - def finalize_handling(self, successful): - logger.info("FullMessageHandling finalize_handling: %s" % self.args) - def finalize_loop(self): - logger.info("FullMessageHandling finalize_loop: %s" % self.args) - -class FailingMessageHandling(ServiceMessageHandler): - def __init__(self, **kwargs): - ServiceMessageHandler.__init__(self) - logger.info("Creation of FailingMessageHandling class: %s" % kwargs) - self.handle_message = kwargs.pop("function") - self.args = kwargs - self.counter = 0 - def prepare_loop(self): - logger.info("FailingMessageHandling prepare_loop: %s" % self.args) - #raise UserException("oops in prepare_loop()") # todo: this is freezing the test. Why is this necessary? - def prepare_receive(self): - # allow one succesfull call otherwise the main loop never accepts the message :-) - logger.info("FailingMessageHandling prepare_receive: %s" % self.args) - if self.counter: - time.sleep(1) # Prevent running around too fast - raise UserException("FailingMessageHandling: intentional oops in prepare_receive counter=%d" % self.counter) - else: - self.counter = self.counter + 1 - def finalize_handling(self, successful): - logger.info("FailingMessageHandling finalize_handling: %s, %s" % (self.args, successful)) - raise UserException("oops in finalize_handling()") - def finalize_loop(self): - logger.info("FailingMessageHandling finalize_loop: %s" % self.args) - raise UserException("oops in finalize_loop()") - -def main(): - with TemporaryExchange("TEST") as tmp_exchange: - busname = tmp_exchange.address - - # Register StringFunc functions as a service handler listening at busname and ServiceName - serv1_plain = Service("String1Service", StringFunc, busname=busname) - serv1_minimal_class = Service("String2Service", OnlyMessageHandling, busname=busname, - handler_args={"function" : StringFunc}) - serv1_full_class = Service("String3Service", FullMessageHandling, busname=busname, - handler_args={"function" : StringFunc}) - serv1_failing_class = Service("String4Service", FailingMessageHandling, busname=busname, - handler_args={"function" : StringFunc}) - - # 'with' sets up the connection context and defines the scope of the service. - # also use each service inside a BusListenerJanitor context to auto-cleanup auto-generated listener queues - with BusListenerJanitor(serv1_plain), BusListenerJanitor(serv1_minimal_class), \ - BusListenerJanitor(serv1_full_class), BusListenerJanitor(serv1_failing_class): - - # Redo string tests via RPCClient - with RPCClient("String1Service", busname=busname) as rpc: - result = rpc("aap noot mies") - if result[0] != "AAP NOOT MIES": - raise Exception("String function failed of String1Service:{}".format(result)) - logger.info("string1Service is OK") - - with RPCClient("String2Service", busname=busname) as rpc: - result = rpc("aap noot mies") - if result[0] != "AAP NOOT MIES": - raise Exception("String function failed of String2Service:{}".format(result)) - logger.info("string2Service is OK") - - with RPCClient("String3Service", busname=busname) as rpc: - result = rpc("aap noot mies") - if result[0] != "AAP NOOT MIES": - raise Exception("String function failed of String3Service:{}".format(result)) - logger.info("string3Service is OK") - - with RPCClient("String4Service", busname=busname) as rpc: - result = rpc("aap noot mies") - if result[0] != "AAP NOOT MIES": - raise Exception("String function failed of String4Service:{}".format(result)) - logger.info("string4Service is OK") - - logger.info("******************************************************************************") - - # Register ErrorFunc function as a service handler listening at busname and ServiceName - serv2_plain = Service("Error1Service", ErrorFunc, busname=busname) - serv2_minimal_class = Service("Error2Service", OnlyMessageHandling, busname=busname, - handler_args={"function" : ErrorFunc}) - serv2_full_class = Service("Error3Service", FullMessageHandling, busname=busname, - handler_args={"function" : ErrorFunc}) - serv2_failing_class = Service("Error4Service", FailingMessageHandling, busname=busname, - handler_args={"function" : ErrorFunc}) - - # 'with' sets up the connection context and defines the scope of the service. - # also use each service inside a BusListenerJanitor context to auto-cleanup auto-generated listener queues - with BusListenerJanitor(serv2_plain), BusListenerJanitor(serv2_minimal_class), \ - BusListenerJanitor(serv2_full_class), BusListenerJanitor(serv2_failing_class): - - # do Error tests via RPCClient - with RPCClient("Error1Service", busname=busname) as rpc: - try: - result = rpc("aap noot mies") - except RPCException as e: - logger.info("Error1Service is OK") - - with RPCClient("Error2Service", busname=busname) as rpc: - try: - result = rpc("aap noot mies") - except RPCException as e: - logger.info("Error2Service is OK") - - with RPCClient("Error3Service", busname=busname) as rpc: - try: - result = rpc("aap noot mies") - except RPCException as e: - logger.info("Error3Service is OK") - - with RPCClient("Error4Service", busname=busname) as rpc: - try: - result = rpc("aap noot mies") - except Exception as e: - logger.info("Error4Service is OK") - - logger.info("******************************************************************************") - - # Register ExceptionFunc functions as a service handler listening at busname and ServiceName - serv3_plain = Service("Except1Service", ExceptionFunc, busname=busname) - serv3_minimal_class = Service("Except2Service", OnlyMessageHandling, busname=busname, - handler_args={"function" : ExceptionFunc}) - serv3_full_class = Service("Except3Service", FullMessageHandling, busname=busname, - handler_args={"function" : ExceptionFunc}) - serv3_failing_class = Service("Except4Service", FailingMessageHandling, busname=busname, - handler_args={"function" : ExceptionFunc}) - - # 'with' sets up the connection context and defines the scope of the service. - # also use each service inside a BusListenerJanitor context to auto-cleanup auto-generated listener queues - with BusListenerJanitor(serv3_plain), BusListenerJanitor(serv3_minimal_class), \ - BusListenerJanitor(serv3_full_class), BusListenerJanitor(serv3_failing_class): - - # do exception tests via RPCClient - with RPCClient("Except1Service", busname=busname) as rpc: - try: - result = rpc("aap noot mies") - except RPCException as e: - if 'IndexError' not in str(e): - raise - logger.info("Except1Service is OK") - - with RPCClient("Except2Service", busname=busname) as rpc: - try: - result = rpc("aap noot mies") - except RPCException as e: - if 'IndexError' not in str(e): - raise - logger.info("Except2Service is OK") - - with RPCClient("Except3Service", busname=busname) as rpc: - try: - result = rpc("aap noot mies") - except RPCException as e: - if 'IndexError' not in str(e): - raise - logger.info("Except3Service is OK") - - with RPCClient("Except4Service", busname=busname) as rpc: - try: - result = rpc("aap noot mies") - except RPCException as e: - if 'IndexError' not in str(e): - raise - logger.info("Except4Service is OK") - - logger.info("Functions tested with RPCClient: All OK") - -if __name__ == '__main__': - logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO) - main() \ No newline at end of file diff --git a/LCS/Messaging/python/messaging/test/t_service_message_handler.run b/LCS/Messaging/python/messaging/test/t_service_message_handler.run deleted file mode 100755 index cc3a1790084b52256ed6134c427af48d2073b350..0000000000000000000000000000000000000000 --- a/LCS/Messaging/python/messaging/test/t_service_message_handler.run +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -e - -# Run the unit test -source python-coverage.sh -python_coverage_test "Messaging/python" t_service_message_handler.py diff --git a/LCS/Messaging/python/messaging/test/t_service_message_handler.sh b/LCS/Messaging/python/messaging/test/t_service_message_handler.sh deleted file mode 100755 index ef9fd1a7376f292a74ae2168e7861c05dd8fcf97..0000000000000000000000000000000000000000 --- a/LCS/Messaging/python/messaging/test/t_service_message_handler.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -./runctest.sh t_service_message_handler - -