Example #1
0
    def test_start_service(self, sleep_mock, create_cunsumer_mock,
                           _setup_entities_mock):
        # create a basic orchestrator
        orchestrator = Orchestrator(rabbitmq_url="test.rabbitmq.com:8000")

        orchestrator.start_service(run_health_check=False)
        _setup_entities_mock.assert_called()
        create_cunsumer_mock.assert_called()

        self.assertEqual(
            create_cunsumer_mock.call_count, constants.DEFAULT_WORKER_COUNT +
            constants.DEFAULT_RETRY_CONSUMER_COUNT +
            constants.DEFAULT_DLQ_CONSUMER_COUNT)
Example #2
0
    def test_enqueue_job(self, easy_job_mock, enqueue_mock, exchange_mock,
                         connection_mock, sleep_mock):
        # create a basic orchestrator
        orchestrator = Orchestrator(rabbitmq_url="test.rabbitmq.com:8000")
        job_mock = Mock()
        job_mock.tag = "unknown"
        easy_job_mock.create.return_value = job_mock
        body = json.dumps({"body": "work body"})
        api = "http://test.api.com/test_dest"
        api_request_headers = {"title": "Yippi"}

        with self.assertRaises(EasyJobServiceNotStarted) as e:
            orchestrator.enqueue_job(api,
                                     constants.API_REMOTE,
                                     api_request_headers=api_request_headers,
                                     data=body)

        orchestrator.setup_entities()

        orchestrator.enqueue_job(api,
                                 constants.API_REMOTE,
                                 api_request_headers=api_request_headers,
                                 data=body)
        enqueue_mock.assert_called_with(orchestrator._producer, "work",
                                        job_mock, body)
 def setUp(self, kombu_connection_mock):
     drain_events = Mock(side_effect=Exception("Test"))
     drain_events.side_effect = socket.timeout
     connection_mock = Mock(drain_events=drain_events)
     kombu_connection_mock.return_value = connection_mock
     self.orchestrator = Orchestrator(rabbitmq_url="test.rabbitmq.com:8000")
     self.retry_consumer = RetryQueueConsumer(self.orchestrator)
Example #4
0
    def test__setup_entities(self, producer_mock, exchange_mock,
                             connection_mock):
        # create a basic orchestrator
        orchestrator = Orchestrator(rabbitmq_url="test.rabbitmq.com:8000")

        orchestrator.setup_entities()
        exchange_mock.assert_called_with(
            orchestrator.get_config().get_mq_config(constants.EXCHANGE),
            type='topic',
            durable=True)

        connection_mock.assert_called_with(
            "test.rabbitmq.com:8000",
            transport_options={'confirm_publish': True})

        producer_mock.assert_called()
Example #5
0
    def test_constructor(self):
        # create a basic orchestrator
        orchestrator = Orchestrator(rabbitmq_url="test.rabbitmq.com:8000")

        # test is started should be false
        self.assertEqual(orchestrator._service_inited, False)

        # test that service validation should through an exception
        with self.assertRaises(EasyJobServiceNotStarted) as e:
            orchestrator.validate_init()

        # test when config is set while creating then value is reflected in the config
        orchestrator1 = Orchestrator(rabbitmq_url="test.rabbitmq.com:8000",
                                     max_worker_count=34)
        self.assertEqual(orchestrator1.get_config().max_worker_count, 34)
 def setUp(self, connection_mock):
     self.orchestrator = Orchestrator(rabbitmq_url="test.rabbitmq.com:8000")
     self.work_queue_con = work_queue_consumer.WorkQueueConsumer(
         self.orchestrator)
Example #7
0
    def test_create_cunsumer(self, dlq_con_mock, rt_con_mock, wrk_con_mock,
                             create_cunsumer_mock, producer_mock,
                             exchange_mock, connection_mock, sleep_mock):
        # create a basic orchestrator
        orchestrator = Orchestrator(rabbitmq_url="test.rabbitmq.com:8000")

        with self.assertRaises(EasyJobServiceNotStarted) as e:
            orchestrator.create_work_cunsumer()

        with self.assertRaises(EasyJobServiceNotStarted) as e:
            orchestrator.create_retry_queue_consumer()

        with self.assertRaises(EasyJobServiceNotStarted) as e:
            orchestrator.create_dead_letter_queue_consumer()

        orchestrator.start_service(run_health_check=False)

        # test work queue
        orchestrator.create_work_cunsumer()
        wrk_con_mock.assert_called()

        # test retry queue
        orchestrator.create_retry_queue_consumer()
        rt_con_mock.assert_called()

        # test deal letter queue
        orchestrator.create_dead_letter_queue_consumer()
        dlq_con_mock.assert_called()
Example #8
0
 def setUp(self, connection):
     self.orchestrator = Orchestrator(rabbitmq_url="test.rabbitmq.com:8000")
     self.dead_letter_con = DeadLetterQueueConsumer(self.orchestrator)
 def setUp(self):
     self.orchestrator = Orchestrator(rabbitmq_url="test.rabbitmq.com:8000")