def test_thread_pool_size(self): # Test non default properties server = DataProviderServer( DataProviderTestClass({}), address=RemoteAdapterBase.PROXY_DATA_ADAPTER_ADDRESS, thread_pool_size=2) self.assertEqual(2, server.thread_pool_size) server = DataProviderServer( DataProviderTestClass({}), address=RemoteAdapterBase.PROXY_DATA_ADAPTER_ADDRESS, thread_pool_size=0) self.assertEqual(EXPECTED_CPU_CORES, server.thread_pool_size) server = DataProviderServer( DataProviderTestClass({}), address=RemoteAdapterBase.PROXY_DATA_ADAPTER_ADDRESS, thread_pool_size=-2) self.assertEqual(EXPECTED_CPU_CORES, server.thread_pool_size) server = DataProviderServer( DataProviderTestClass({}), address=RemoteAdapterBase.PROXY_DATA_ADAPTER_ADDRESS, thread_pool_size=None) self.assertEqual(EXPECTED_CPU_CORES, server.thread_pool_size)
def test_thread_pool_size(self): # Test non default properties server = DataProviderServer(DataProviderTestClass({}), address=(RemoteAdapterBase.HOST, RemoteAdapterBase.REQ_REPLY_PORT, RemoteAdapterBase.NOTIFY_PORT), thread_pool_size=2) self.assertEqual(2, server.thread_pool_size) server = DataProviderServer(DataProviderTestClass({}), address=(RemoteAdapterBase.HOST, RemoteAdapterBase.REQ_REPLY_PORT, RemoteAdapterBase.NOTIFY_PORT), thread_pool_size=0) self.assertEqual(4, server.thread_pool_size) server = DataProviderServer(DataProviderTestClass({}), address=(RemoteAdapterBase.HOST, RemoteAdapterBase.REQ_REPLY_PORT, RemoteAdapterBase.NOTIFY_PORT), thread_pool_size=-2) self.assertEqual(4, server.thread_pool_size) server = DataProviderServer(DataProviderTestClass({}), address=(RemoteAdapterBase.HOST, RemoteAdapterBase.REQ_REPLY_PORT, RemoteAdapterBase.NOTIFY_PORT), thread_pool_size=None) self.assertEqual(4, server.thread_pool_size)
def test_keep_alive_value(self): # Test non default properties server = DataProviderServer( DataProviderTestClass({}), address=RemoteAdapterBase.PROXY_DATA_ADAPTER_ADDRESS, keep_alive=2) self.assertEqual(2, server.keep_alive) server = DataProviderServer( DataProviderTestClass({}), address=RemoteAdapterBase.PROXY_DATA_ADAPTER_ADDRESS, keep_alive=0) self.assertEqual(0, server.keep_alive) server = DataProviderServer( DataProviderTestClass({}), address=RemoteAdapterBase.PROXY_DATA_ADAPTER_ADDRESS, keep_alive=-2) self.assertEqual(0, server.keep_alive) server = DataProviderServer( DataProviderTestClass({}), address=RemoteAdapterBase.PROXY_DATA_ADAPTER_ADDRESS, keep_alive=None) self.assertEqual(10, server.keep_alive)
def test_keep_alive_value(self): # Test non default properties server = DataProviderServer(DataProviderTestClass({}), address=(RemoteAdapterBase.HOST, RemoteAdapterBase.REQ_REPLY_PORT, RemoteAdapterBase.NOTIFY_PORT), keep_alive=2) self.assertEqual(2, server.keep_alive) server = DataProviderServer(DataProviderTestClass({}), address=(RemoteAdapterBase.HOST, RemoteAdapterBase.REQ_REPLY_PORT, RemoteAdapterBase.NOTIFY_PORT), keep_alive=0) self.assertEqual(0, server.keep_alive) server = DataProviderServer(DataProviderTestClass({}), address=(RemoteAdapterBase.HOST, RemoteAdapterBase.REQ_REPLY_PORT, RemoteAdapterBase.NOTIFY_PORT), keep_alive=-2) self.assertEqual(0, server.keep_alive) server = DataProviderServer(DataProviderTestClass({}), address=(RemoteAdapterBase.HOST, RemoteAdapterBase.REQ_REPLY_PORT, RemoteAdapterBase.NOTIFY_PORT), keep_alive=None) self.assertEqual(0, server.keep_alive)
def test_remote_credentials(self): server = DataProviderServer( DataProviderTestClass({}), address=RemoteAdapterBase.PROXY_DATA_ADAPTER_ADDRESS) server.remote_user = "******" server.remote_password = "******" self.assertEqual("user", server.remote_user) self.assertEqual("password", server.remote_password)
def main(): '''Module Entry Point''' logging.basicConfig(dateFmt='%m/%d/%Y %I:%M:%S %p', level=logging.DEBUG) parser = argparse.ArgumentParser(description=("Launch the Remote Chat " "Adapter.")) parser.add_argument('--host', type=str, nargs='?', metavar='<host>', default="localhost", help=("the host name or ip " "address of LS server")) parser.add_argument('--metadata_rrport', type=int, metavar='<port>', required=True, help=("the request/reply tcp port " "number where the Proxy Metadata " "Adapter is listening on")) parser.add_argument('--data_rrport', type=int, metavar='<port>', required=True, help=("the request/reply tcp port " "where the Proxy DataAdapter is " "listening on")) parser.add_argument('--data_notifport', type=int, metavar='<port>', required=True, help=("the notify tcp port where the " "Proxy DataAdapter is listening " "on")) args = parser.parse_args() # Creates a new instance of the ChatDataAdapter. data_adapter = ChataDataAdapter() # Creates a new instance of ChatMetadataAdapter and pass data_adapter # to it. metadata_adaper = ChatMetadataAdapter(data_adapter) # Creates and starts the MetadataProviderServer, passing to it # metadata_adaper and the tuple containing the target host information. metadata_provider_server = MetadataProviderServer( metadata_adaper, (args.host, args.metadata_rrport)) metadata_provider_server.start() # Creates and starts the DataProviderServer, passing to it data_adapter # and the tuple containing the target host information. dataprovider_server = DataProviderServer( data_adapter, (args.host, args.data_rrport, args.data_notifport), keep_alive=0) dataprovider_server.start()
def test_start_with_error(self): server = DataProviderServer( DataProviderTestClass({}), RemoteAdapterBase.PROXY_DATA_ADAPTER_ADDRESS) with self.assertRaises(Exception) as err: server.start() the_exception = err.exception self.assertIsInstance(the_exception, DataProviderError) self.assertEqual(str(the_exception), "Caught an error during the initialization phase")
def test_start_with_error(self): server = DataProviderServer(DataProviderTestClass( {}), (RemoteAdapterBase.HOST, RemoteAdapterBase.REQ_REPLY_PORT, RemoteAdapterBase.NOTIFY_PORT)) with self.assertRaises(Exception) as err: server.start() the_exception = err.exception self.assertIsInstance(the_exception, DataProviderError) self.assertEqual(str(the_exception), "Caught an error during the initialization phase")
def test_start_with_error(self): server = DataProviderServer(DataProviderTestClass({}), (RemoteAdapterBase.HOST, RemoteAdapterBase.REQ_REPLY_PORT, RemoteAdapterBase.NOTIFY_PORT)) with self.assertRaises(Exception) as err: server.start() the_exception = err.exception self.assertIsInstance(the_exception, DataProviderError) self.assertEqual(str(the_exception), "Caught an error during the initialization phase")
def main(): '''Module Entry Point''' logging.basicConfig(datefmt='%m/%d/%Y %I:%M:%S %p', format='%(asctime)s %(levelname)-7s %(message)s', level=logging.DEBUG) parser = argparse.ArgumentParser(description=("Launch the Remote Chat " "Adapter.")) parser.add_argument('--host', type=str, nargs='?', metavar='<host>', default="localhost", help=("the host name or ip " "address of LS server")) parser.add_argument('--metadata_rrport', type=int, metavar='<port>', required=True, help=("the request/reply tcp port " "number where the Proxy Metadata " "Adapter is listening on")) parser.add_argument('--data_rrport', type=int, metavar='<port>', required=True, help=("the request/reply tcp port " "where the Proxy DataAdapter is " "listening on")) parser.add_argument('--data_notifport', type=int, metavar='<port>', required=True, help=("the notify tcp port where the " "Proxy DataAdapter is listening " "on")) args = parser.parse_args() # Creates a new instance of the ChatDataAdapter. data_adapter = ChataDataAdapter() # Creates a new instance of ChatMetadataAdapter and pass data_adapter # to it. metadata_adaper = ChatMetadataAdapter(data_adapter) # Creates and starts the MetadataProviderServer, passing to it # metadata_adaper and the tuple containing the target host information. metadata_provider_server = MetadataProviderServer(metadata_adaper, (args.host, args.metadata_rrport)) metadata_provider_server.start() # Creates and starts the DataProviderServer, passing to it data_adapter # and the tuple containing the target host information. dataprovider_server = DataProviderServer(data_adapter, (args.host, args.data_rrport, args.data_notifport), keep_alive=0) dataprovider_server.start()
def on_setup(self): self.collector = {} # Configuring and starting MetadataProviderServer self.adapter = DataProviderTestClass(self.collector) remote_server = DataProviderServer( adapter=self.adapter, address=RemoteAdapterBase.PROXY_DATA_ADAPTER_ADDRESS, name="DataProviderTest") self.launch_remote_server(remote_server)
def test_default_properties(self): # Test default properties server = DataProviderServer(DataProviderTestClass( {}), (RemoteAdapterBase.HOST, RemoteAdapterBase.REQ_REPLY_PORT, RemoteAdapterBase.NOTIFY_PORT)) self.assertEqual('#', server.name[0]) self.assertEqual(1, server.keep_alive) self.assertEqual(4, server.thread_pool_size)
def test_not_right_adapter(self): with self.assertRaises(TypeError) as type_error: DataProviderServer({}, RemoteAdapterBase.PROXY_DATA_ADAPTER_ADDRESS) the_exception = type_error.exception self.assertIsInstance(the_exception, TypeError) self.assertEqual(str(the_exception), "The provided adapter is not a subclass of " "lightstreamer_adapter.interfaces.DataProvider")
def on_setup(self): # Configuring and starting MetadataProviderServer self.adapter = DataProviderTestClass(self.collector) address = (RemoteAdapterBase.HOST, RemoteAdapterBase.REQ_REPLY_PORT, RemoteAdapterBase.NOTIFY_PORT) remote_adapter_server = DataProviderServer(adapter=self.adapter, address=address, keep_alive=1, name="DataProviderTest") return remote_adapter_server
def test_default_properties(self): # Test default properties server = DataProviderServer( DataProviderTestClass({}), RemoteAdapterBase.PROXY_DATA_ADAPTER_ADDRESS) self.assertEqual('#', server.name[0]) self.assertEqual(10, server.keep_alive) self.assertEqual(EXPECTED_CPU_CORES, server.thread_pool_size) self.assertIsNone(server.remote_user) self.assertIsNone(server.remote_password)
def test_not_right_adapter(self): with self.assertRaises(TypeError) as te: DataProviderServer( {}, (RemoteAdapterBase.HOST, RemoteAdapterBase.REQ_REPLY_PORT, RemoteAdapterBase.NOTIFY_PORT)) the_exception = te.exception self.assertIsInstance(the_exception, TypeError) self.assertEqual(str(the_exception), ("The provided adapter is not a subclass of " "lightstreamer_adapter.interfaces.DataProvider"))
def setup_remote_adapter(self, keep_alive=None, config=None, params=None, username=None, password=None): remote_server = DataProviderServer( adapter=self.adapter, address=RemoteAdapterBase.PROXY_DATA_ADAPTER_ADDRESS, keep_alive=keep_alive, name="DataProviderTest") remote_server.adapter_config = config remote_server.adapter_params = params remote_server.remote_user = username remote_server.remote_password = password self.launch_remote_server(remote_server)
def test_unset_remote_credentials(self): server = DataProviderServer( DataProviderTestClass({}), address=RemoteAdapterBase.PROXY_DATA_ADAPTER_ADDRESS) self.assertIsNone(server.remote_user) self.assertIsNone(server.remote_password)