def test_collate_worker_error(self): def get_object_data(*a, **kw): raise Exception() orig_get_object_data = log_processor.LogProcessor.get_object_data try: log_processor.LogProcessor.get_object_data = get_object_data proxy_config = self.proxy_config.copy() proxy_config.update({ 'log-processor-access': { 'source_filename_format': '%Y%m%d%H*', 'class_path': 'slogging.access_processor.AccessLogProcessor' }}) processor_args = (proxy_config, DumbLogger()) q_in = Queue.Queue() q_in.close = lambda: None q_out = Queue.Queue() q_out.close = lambda: None work_request = ('access', 'a', 'c', 'o') q_in.put(work_request) q_in.put(None) processor_klass = log_processor.LogProcessor log_common.collate_worker(processor_klass, processor_args, 'process_one_file', q_in, q_out, DumbLogger()) item, ret = q_out.get() self.assertEquals(item, work_request) # these only work for Py2.7+ #self.assertIsInstance(ret, log_common.BadFileDownload) self.assertTrue(isinstance(ret, Exception)) finally: log_processor.LogProcessor.get_object_data = orig_get_object_data
def test_collate_worker_error(self): def get_object_data(*a, **kw): raise Exception() orig_get_object_data = log_processor.LogProcessor.get_object_data try: log_processor.LogProcessor.get_object_data = get_object_data proxy_config = self.proxy_config.copy() proxy_config.update({ 'log-processor-access': { 'source_filename_format': '%Y%m%d%H*', 'class_path': 'slogging.access_processor.AccessLogProcessor' } }) processor_args = (proxy_config, DumbLogger()) q_in = Queue.Queue() q_in.close = lambda: None q_out = Queue.Queue() q_out.close = lambda: None work_request = ('access', 'a', 'c', 'o') q_in.put(work_request) q_in.put(None) processor_klass = log_processor.LogProcessor log_common.collate_worker(processor_klass, processor_args, 'process_one_file', q_in, q_out, DumbLogger()) item, ret = q_out.get() self.assertEquals(item, work_request) # these only work for Py2.7+ #self.assertIsInstance(ret, log_common.BadFileDownload) self.assertTrue(isinstance(ret, Exception)) finally: log_processor.LogProcessor.get_object_data = orig_get_object_data
def test_collate_worker(self): try: log_processor.LogProcessor._internal_proxy = DumbInternalProxy() def get_object_data(*a, **kw): return [self.access_test_line] orig_get_object_data = log_processor.LogProcessor.get_object_data log_processor.LogProcessor.get_object_data = get_object_data proxy_config = self.proxy_config.copy() proxy_config.update({ 'log-processor-access': { 'source_filename_format': '%Y%m%d%H*', 'class_path': 'slogging.access_processor.AccessLogProcessor' } }) processor_args = (proxy_config, DumbLogger()) q_in = Queue.Queue() q_in.close = lambda: None q_out = Queue.Queue() q_out.close = lambda: None work_request = ('access', 'a', 'c', 'o') q_in.put(work_request) q_in.put(None) processor_klass = log_processor.LogProcessor log_common.collate_worker(processor_klass, processor_args, 'process_one_file', q_in, q_out, DumbLogger()) item, ret = q_out.get() self.assertEquals(item, work_request) expected = { ('acct', '2010', '07', '09', '04'): { ('public', 'object', 'GET', '2xx'): 1, ('public', 'bytes_out'): 95, 'marker_query': 0, 'format_query': 1, 'delimiter_query': 0, 'path_query': 0, ('public', 'bytes_in'): 6, 'prefix_query': 0 } } self.assertEquals(ret, expected) finally: log_processor.LogProcessor._internal_proxy = None log_processor.LogProcessor.get_object_data = orig_get_object_data
def test_collate_worker(self): try: log_processor.LogProcessor._internal_proxy = DumbInternalProxy() def get_object_data(*a, **kw): return [self.access_test_line] orig_get_object_data = log_processor.LogProcessor.get_object_data log_processor.LogProcessor.get_object_data = get_object_data proxy_config = self.proxy_config.copy() proxy_config.update({ 'log-processor-access': { 'source_filename_format': '%Y%m%d%H*', 'class_path': 'slogging.access_processor.AccessLogProcessor' }}) processor_args = (proxy_config, DumbLogger()) q_in = Queue.Queue() q_in.close = lambda: None q_out = Queue.Queue() q_out.close = lambda: None work_request = ('access', 'a', 'c', 'o') q_in.put(work_request) q_in.put(None) processor_klass = log_processor.LogProcessor log_common.collate_worker(processor_klass, processor_args, 'process_one_file', q_in, q_out, DumbLogger()) item, ret = q_out.get() self.assertEquals(item, work_request) expected = {('acct', '2010', '07', '09', '04'): {('public', 'object', 'GET', '2xx'): 1, ('public', 'bytes_out'): 95, 'marker_query': 0, 'format_query': 1, 'delimiter_query': 0, 'path_query': 0, ('public', 'bytes_in'): 6, 'prefix_query': 0}} self.assertEquals(ret, expected) finally: log_processor.LogProcessor._internal_proxy = None log_processor.LogProcessor.get_object_data = orig_get_object_data