def test_setup_connection(self, mock_sub_ar, mock_connect, mock_client):
        """
        Test: Connection to ActiveMQ setup, along with subscription to queues
        When: setup_connection is called with a consumer name
        """
        queue_listener.main()

        mock_client.assert_called_once()
        mock_connect.assert_called_once()
        mock_sub_ar.assert_called_once()

        (args, _) = mock_sub_ar.call_args
        self.assertEqual(args[0], "queue_processor")
        self.assertIsInstance(args[1], QueueListener)
        self.assertIsInstance(args[1].client, QueueClient)
Beispiel #2
0
    def setUp(self):
        """ Start all external services """
        # Get all clients
        self.database_client = DatabaseClient()
        self.database_client.connect()
        try:
            self.queue_client, self.listener = main()
        except ConnectionException as err:
            raise RuntimeError(
                "Could not connect to ActiveMQ - check you credentials. If running locally check that "
                "ActiveMQ is running and started by `python setup.py start`"
            ) from err

        # Add placeholder variables:
        # these are used to ensure runs are deleted even if test fails before completion
        self.instrument = 'ARMI'
        self.rb_number = 1234567
        self.run_number = 101

        # Create test archive and add data
        self.data_archive = DataArchive([self.instrument], 19, 19)
        self.data_archive.create()

        # Create and send json message to ActiveMQ
        self.data_ready_message = Message(rb_number=self.rb_number,
                                          instrument=self.instrument,
                                          run_number=self.run_number,
                                          description="This is a system test",
                                          facility="ISIS",
                                          started_by=0)
 def run(self):
     """ Run queue processor. """
     self.logger.info("Starting Queue Processor")
     self.client, self.listener = queue_listener.main()
     # keeps the daemon alive as the main call above does not block
     # but simply runs the connections in async. If this sleep isn't
     # here the deamon will just exit after connecting
     while not self._shutting_down:
         time.sleep(0.5)
    def setUpClass(cls):
        """ Start all external services """
        super().setUpClass()
        cls.database_client = DatabaseClient()
        cls.database_client.connect()
        try:
            cls.queue_client, cls.listener = main()
        except ConnectionException as err:
            raise RuntimeError(
                "Could not connect to ActiveMQ - check you credentials. If running locally check that "
                "ActiveMQ is running and started by `python setup.py start`"
            ) from err

        cls.instrument_name = "TestInstrument"
        cls.rb_number = 1234567
        cls.run_number = 99999

        cls.data_archive = DataArchive([cls.instrument_name], 21, 21)
        cls.data_archive.create()
        cls.data_archive.add_reduce_vars_script(
            cls.instrument_name,
            """standard_vars={"variable1":"test_variable_value_123"}""")
Beispiel #5
0
    def setUpClass(cls):
        super().setUpClass()
        cls.instrument_name = "TestInstrument"
        cls.data_archive = DataArchive([cls.instrument_name], 21, 21)
        cls.data_archive.create()
        cls.data_archive.add_reduction_script(cls.instrument_name,
                                              """print('some text')""")
        cls.data_archive.add_reduce_vars_script(
            cls.instrument_name,
            f"""standard_vars={{"variable1":"{REDUCE_VARS_DEFAULT_VALUE}"}}""")
        cls.database_client = DatabaseClient()
        cls.database_client.connect()
        try:
            cls.queue_client, cls.listener = main()
        except ConnectionException as err:
            raise RuntimeError(
                "Could not connect to ActiveMQ - check you credentials. If running locally check that "
                "ActiveMQ is running and started by `python setup.py start`"
            ) from err

        cls.instrument_name = "TestInstrument"
        cls.rb_number = 1234567
        cls.run_number = 99999
Beispiel #6
0
 def run(self):
     """ Run queue processor. """
     self._client_handle = queue_listener.main()
     self._stop_timer = threading.Timer(self.stop_interval, self.stop)
     self._stop_timer.start()