def test_load_queues_from_file(self): self.maxDiff = None flexmock(file_io).should_receive("mkdir").and_return(None) app_id = 'myapp' # Test queue sample. flexmock(TaskQueueConfig).should_receive("get_queue_file_location").\ and_return("/path/to/file") flexmock(file_io).should_receive("read").and_return(sample_queue_yaml) expected_info = [{ 'name': 'default', 'rate': '5/s' }, { 'name': 'foo', 'rate': '10/m' }] expected_queues = { info['name']: PushQueue(info, app_id) for info in expected_info } flexmock(TaskQueueConfig).should_receive('load_queues_from_file').\ and_return(expected_queues) tqc = TaskQueueConfig(app_id) self.assertEquals(tqc.queues, expected_queues) # Test queue sample 2. flexmock(TaskQueueConfig).should_receive("get_queue_file_location").\ and_return("/path/to/file") flexmock(file_io).should_receive("read").and_return(sample_queue_yaml2) expected_info = [{ 'name': 'foo', 'rate': '10/m' }, { 'name': 'default', 'rate': '5/s' }] expected_queues = { info['name']: PushQueue(info, app_id) for info in expected_info } flexmock(TaskQueueConfig).should_receive('load_queues_from_file').\ and_return(expected_queues) tqc = TaskQueueConfig(app_id) self.assertEquals(tqc.queues, expected_queues) # Test without queues. flexmock(TaskQueueConfig).should_receive("get_queue_file_location").\ and_return("") flexmock(file_io).should_receive("read").and_raise(IOError) expected_info = [{'name': 'default', 'rate': '5/s'}] expected_queues = { info['name']: PushQueue(info, app_id) for info in expected_info } flexmock(TaskQueueConfig).should_receive('load_queues_from_file').\ and_return(expected_queues) tqc = TaskQueueConfig(app_id) self.assertEquals(tqc.queues, expected_queues)
def test_load_queues_from_xml_file(self): flexmock(file_io).should_receive("mkdir").and_return(None) app_id = 'myapp' flexmock(TaskQueueConfig).should_receive("get_queue_file_location").\ and_return("/path/to/file") flexmock(file_io).should_receive("read").and_return(sample_queue_xml) expected_info = [{ 'max_concurrent_requests': '300', 'rate': '100/s', 'bucket_size': '100', 'name': 'default', 'retry_parameters': { 'task_age_limit': '3d' } }, { 'max_concurrent_requests': '100', 'rate': '100/s', 'bucket_size': '100', 'name': 'mapreduce-workers', 'retry_parameters': { 'task_age_limit': '3d' } }] expected_queues = { info['name']: PushQueue(info, app_id) for info in expected_info } flexmock(TaskQueueConfig).should_receive('load_queues_from_file').\ and_return(expected_queues) tqc = TaskQueueConfig(app_id) self.assertEquals(tqc.queues, expected_queues)
def test_load_queues_from_xml_file(self): flexmock(file_io).should_receive("read").and_return(sample_queue_xml) flexmock(file_io).should_receive("exists").and_return(False)\ .and_return(True) flexmock(file_io).should_receive("write").and_return(None) flexmock(file_io).should_receive("mkdir").and_return(None) app_id = 'myapp' tqc = TaskQueueConfig(app_id) expected_info = [{ 'max_concurrent_requests': '300', 'rate': '100/s', 'bucket_size': '100', 'name': 'default', 'retry_parameters': { 'task_age_limit': '3d' } }, { 'max_concurrent_requests': '100', 'rate': '100/s', 'bucket_size': '100', 'name': 'mapreduce-workers', 'retry_parameters': { 'task_age_limit': '3d' } }] expected_queues = { info['name']: PushQueue(info, app_id) for info in expected_info } self.assertEquals(tqc.queues, expected_queues)
def test_load_queues_from_file(self): flexmock(file_io).should_receive("read").and_return(sample_queue_yaml) flexmock(file_io).should_receive("exists").and_return(True) flexmock(file_io).should_receive("write").and_return(None) flexmock(file_io).should_receive("mkdir").and_return(None) app_id = 'myapp' tqc = TaskQueueConfig(app_id) expected_info = [{ 'name': 'default', 'rate': '5/s' }, { 'name': 'foo', 'rate': '10/m' }] expected_queues = { info['name']: PushQueue(info, app_id) for info in expected_info } self.assertEquals(tqc.queues, expected_queues) flexmock(file_io).should_receive("read").and_raise(IOError) tqc = TaskQueueConfig(app_id) expected_info = [{'name': 'default', 'rate': '5/s'}] expected_queues = { info['name']: PushQueue(info, app_id) for info in expected_info } self.assertEquals(tqc.queues, expected_queues) flexmock(file_io).should_receive("read").and_return(sample_queue_yaml2) flexmock(file_io).should_receive("write").and_return(None) tqc = TaskQueueConfig(app_id) expected_info = [{ 'name': 'foo', 'rate': '10/m' }, { 'name': 'default', 'rate': '5/s' }] expected_queues = { info['name']: PushQueue(info, app_id) for info in expected_info } self.assertEquals(tqc.queues, expected_queues)
def test_queue_name_validation(self): app_id = 'guestbook' valid_names = ['hello', 'hello-hello', 'HELLO-world-1'] invalid_names = ['hello_hello5354', 'hello$hello', 'hello@hello', 'hello&hello', 'hello*hello', 'a'*101] for name in valid_names: PushQueue({'name': name}, app_id) for name in invalid_names: self.assertRaises( InvalidQueueConfiguration, PushQueue, {'name': name}, app_id)