From fa3e3d83e774d423079c74af29cfc90a3af0ce24 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Tue, 14 May 2019 10:14:47 +0000
Subject: [PATCH] SW-699: Fixed some tests after changing MessageBus and
 BusListener interfaces

---
 .../test/t_ingestjobmanagementserver.py             | 10 ++++------
 .../LTAIngestAdminServer/test/t_ingestmomadapter.py | 13 ++++---------
 SAS/MoM/MoMQueryService/test/t_momqueryservice.py   |  3 +--
 SAS/OTDB_Services/TreeService.py                    |  7 +++----
 SAS/OTDB_Services/test/t_TreeService.py             |  3 +--
 SAS/OTDB_Services/test/t_TreeStatusEvents.py        |  1 -
 6 files changed, 13 insertions(+), 24 deletions(-)

diff --git a/LTA/LTAIngest/LTAIngestServer/LTAIngestAdminServer/test/t_ingestjobmanagementserver.py b/LTA/LTAIngest/LTAIngestServer/LTAIngestAdminServer/test/t_ingestjobmanagementserver.py
index dd6e551164c..f095fd39b5f 100755
--- a/LTA/LTAIngest/LTAIngestServer/LTAIngestAdminServer/test/t_ingestjobmanagementserver.py
+++ b/LTA/LTAIngest/LTAIngestServer/LTAIngestAdminServer/test/t_ingestjobmanagementserver.py
@@ -15,19 +15,17 @@ from lofar.messaging.messages import CommandMessage, EventMessage
 
 testname = 't_ingestjobmanagementserver_%s' % uuid.uuid1()
 
-with TemporaryQueue(testname+"_ingest_notification_bus") as tmp_queue1, \
-     TemporaryQueue(testname+"_ingest_bus") as tmp_queue2, \
-     TemporaryQueue(testname + "_jobman_notification_bus") as tmp_queue3, \
+with TemporaryQueue(testname+"_bus") as tmp_bus, \
      TemporaryQueue(testname + "_jobs_queue") as tmp_queue4, \
      TemporaryQueue(testname + "_jobs_for_transfer_queue") as tmp_queue5:
 
     #overwrite some defaults in the config to run this as an isolated test
     import lofar.lta.ingest.common.config as cconfig
-    cconfig.DEFAULT_INGEST_NOTIFICATION_BUSNAME = tmp_queue1.address
+    cconfig.DEFAULT_INGEST_NOTIFICATION_BUSNAME = tmp_bus.address
 
     import lofar.lta.ingest.server.config as config
-    config.DEFAULT_INGEST_BUSNAME = tmp_queue2.address
-    config.DEFAULT_JOBMANAGER_NOTIFICATION_QUEUENAME = tmp_queue3.address
+    config.DEFAULT_INGEST_BUSNAME = tmp_bus.address
+    config.DEFAULT_JOBMANAGER_NOTIFICATION_QUEUENAME = tmp_bus.address
     config.DEFAULT_INGEST_JOBS_QUEUENAME = tmp_queue4.address
     config.DEFAULT_INGEST_JOBS_FOR_TRANSER_QUEUENAME = tmp_queue5.address
 
diff --git a/LTA/LTAIngest/LTAIngestServer/LTAIngestAdminServer/test/t_ingestmomadapter.py b/LTA/LTAIngest/LTAIngestServer/LTAIngestAdminServer/test/t_ingestmomadapter.py
index d33ce2d5c44..8896d970cde 100755
--- a/LTA/LTAIngest/LTAIngestServer/LTAIngestAdminServer/test/t_ingestmomadapter.py
+++ b/LTA/LTAIngest/LTAIngestServer/LTAIngestAdminServer/test/t_ingestmomadapter.py
@@ -20,21 +20,16 @@ class TestIngestMoMAdapter(unittest.TestCase):
         self.tmp_queue1.open()
         self.addCleanup(self.tmp_queue1.close)
 
-        self.tmp_queue2 = TemporaryQueue("t_ingestmomadapter_lofar.lta.ingest.notification")
-        self.tmp_queue2.open()
-        self.addCleanup(self.tmp_queue2.close)
-
-        self.tmp_queue3 = TemporaryQueue("t_ingestmomadapter_lofar.lta.ingest.notification.momingestadapter")
-        self.tmp_queue3.open()
-        self.addCleanup(self.tmp_queue3.close)
+        self.tmp_bus = TemporaryQueue("t_ingestmomadapter_lofar")
+        self.tmp_bus.open()
+        self.addCleanup(self.tmp_bus.close)
 
         momclient_patcher = mock.patch('lofar.lta.ingest.server.momclient.MoMClient')
         self.addCleanup(momclient_patcher.stop)
         self.momclient_mock = momclient_patcher.start()
 
         self.adapter = IngestMomAdapter(job_queue_name=self.tmp_queue1.address,
-                                        notification_publish_busname=self.tmp_queue2.address,
-                                        notification_queue_name=self.tmp_queue3.address,
+                                        busname=self.tmp_bus.address,
                                         mom_xmlrpc_host='localhost',
                                         mom_xmlrpc_port=randint(2345, 4567), # pick random port to reduce chance of clashes
                                         momClient = self.momclient_mock)
diff --git a/SAS/MoM/MoMQueryService/test/t_momqueryservice.py b/SAS/MoM/MoMQueryService/test/t_momqueryservice.py
index 76fde85d6ea..2b360816811 100755
--- a/SAS/MoM/MoMQueryService/test/t_momqueryservice.py
+++ b/SAS/MoM/MoMQueryService/test/t_momqueryservice.py
@@ -41,7 +41,6 @@ except ImportError as e:
 
 from lofar.common.dbcredentials import Credentials
 from lofar.mom.momqueryservice.momqueryrpc import MoMQueryRPC
-from lofar.mom.momqueryservice.config import DEFAULT_MOMQUERY_SERVICENAME
 from lofar.mom.momqueryservice.momqueryservice import MoMDatabaseWrapper, ProjectDetailsQueryHandler
 from proton import Message
 
@@ -864,7 +863,7 @@ class TestMomQueryRPC(unittest.TestCase):
         # the mock library had difficulty to mock ToBus and FromBus probably to some weir naming issue.
         # so mocking is done on QPID messaging level.
 
-        self.momrpc = MoMQueryRPC('busname', DEFAULT_MOMQUERY_SERVICENAME)
+        self.momrpc = MoMQueryRPC('busname')
         self.sender_mock = mock.MagicMock()
 
         self.receiver_mock = mock.MagicMock()
diff --git a/SAS/OTDB_Services/TreeService.py b/SAS/OTDB_Services/TreeService.py
index 9d31b1dcf66..64b0d5a59e3 100755
--- a/SAS/OTDB_Services/TreeService.py
+++ b/SAS/OTDB_Services/TreeService.py
@@ -657,8 +657,8 @@ class PostgressMessageHandler(MessageHandlerInterface):
         logger.info("_SetProject({0})".format(kwargs))
         return SetProject(kwargs, self.connection)
 
-def create_service(service_name, busname, dbcreds, broker=None):
-    return Service(service_name,
+def create_service(busname, dbcreds, broker=None):
+    return Service(DEFAULT_OTDB_SERVICENAME,
                    PostgressMessageHandler,
                    busname=busname,
                    use_service_methods=True,
@@ -692,8 +692,7 @@ def main():
     dbcreds = dbcredentials.parse_options(options)
     print("###dbcreds:", dbcreds)
 
-    with create_service(service_name=DEFAULT_OTDB_SERVICENAME,
-                        busname=options.busname,
+    with create_service(busname=options.busname,
                         dbcreds=dbcreds,
                         broker=options.broker):
         waitForInterrupt()
diff --git a/SAS/OTDB_Services/test/t_TreeService.py b/SAS/OTDB_Services/test/t_TreeService.py
index 6080285faf5..b5a1800f317 100644
--- a/SAS/OTDB_Services/test/t_TreeService.py
+++ b/SAS/OTDB_Services/test/t_TreeService.py
@@ -34,7 +34,6 @@ import psycopg2
 import subprocess
 from lofar.messaging.messagebus import *
 from lofar.messaging.RPC import *
-from lofar.sas.otdb.config import DEFAULT_OTDB_SERVICENAME
 from lofar.sas.otdb.TreeService import create_service
 from lofar.common.dbcredentials import Credentials
 
@@ -98,7 +97,7 @@ try:
     with TemporaryQueue(__name__) as tmp_queue:
         busname = tmp_queue.address
 
-        with create_service(DEFAULT_OTDB_SERVICENAME, busname, database_credentials):
+        with create_service(busname, database_credentials):
             with RPC("OTDBService.TaskGetIDs", ForwardExceptions=True, busname=busname, timeout=10) as otdbRPC:
                 # Existing: otdb_id:1099268, mom_id:353713
                 do_rpc                    (otdbRPC, {'OtdbID': 1099268, 'MomID': 353713 })
diff --git a/SAS/OTDB_Services/test/t_TreeStatusEvents.py b/SAS/OTDB_Services/test/t_TreeStatusEvents.py
index 01e98d9fc8f..bfe9a61ed30 100644
--- a/SAS/OTDB_Services/test/t_TreeStatusEvents.py
+++ b/SAS/OTDB_Services/test/t_TreeStatusEvents.py
@@ -34,7 +34,6 @@ import testing.postgresql
 import psycopg2
 import subprocess
 from lofar.messaging.messagebus import *
-from lofar.sas.otdb.config import DEFAULT_OTDB_SERVICENAME
 from lofar.sas.otdb.TreeStatusEvents import create_service
 from lofar.common.dbcredentials import Credentials
 import threading
-- 
GitLab