def test_bundling(self): # pylint: disable=abstract-method, too-few-public-methods class BundlingRequest(object): def __init__(self, elements=None): self.elements = elements fake_grpc_func_descriptor = BundleDescriptor('elements', []) bundler = bundling.Executor(BundleOptions(element_count_threshold=8)) def my_func(request, dummy_timeout): return len(request.elements) settings = _CallSettings(bundler=bundler, bundle_descriptor=fake_grpc_func_descriptor, timeout=0) my_callable = api_callable.create_api_call(my_func, settings) first = my_callable(BundlingRequest([0] * 3)) self.assertIsInstance(first, bundling.Event) self.assertIsNone(first.result) # pylint: disable=no-member second = my_callable(BundlingRequest([0] * 5)) self.assertEqual(second.result, 8) # pylint: disable=no-member
test_task = _make_a_test_task() an_event = test_task.extend([an_elt]) another_event = test_task.extend([another_msg]) self.assertEquals(test_task.element_count, 2) self.assertTrue(an_event.cancel()) self.assertEquals(test_task.element_count, 1) self.assertFalse(an_event.cancel()) self.assertEquals(test_task.element_count, 1) test_task.run() self.assertEquals(test_task.element_count, 0) self.assertEquals(_Simple([another_msg]), another_event.result) self.assertFalse(an_event.is_set()) self.assertIsNone(an_event.result) SIMPLE_DESCRIPTOR = BundleDescriptor('field1', []) DEMUX_DESCRIPTOR = BundleDescriptor('field1', [], subresponse_field='field1') class TestExecutor(unittest2.TestCase): def test_api_calls_are_grouped_by_bundle_id(self): an_elt = 'dummy message' api_call = _return_request bundle_ids = ['id1', 'id2'] threshold = 5 # arbitrary options = BundleOptions(element_count_threshold=threshold) bundler = bundling.Executor(options) for an_id in bundle_ids: for i in range(threshold - 1): got_event = bundler.schedule(
'retry_codes_name': 'bar_retry', 'retry_params_name': 'default', 'timeout_millis': 12000 } } } } } _PAGE_DESCRIPTORS = { 'page_streaming_method': PageDescriptor('page_token', 'next_page_token', 'page_streams') } _BUNDLE_DESCRIPTORS = { 'bundling_method': BundleDescriptor('bundled_field', []) } _RETRY_DICT = {'code_a': Exception, 'code_b': Exception, 'code_c': Exception} _FAKE_STATUS_CODE_1 = object() class CustomException(Exception): def __init__(self, msg, code): super(CustomException, self).__init__(msg) self.code = code class AnotherException(Exception): pass
'retry_codes_name': 'bar_retry', 'retry_params_name': 'default' } } } } } _PAGE_DESCRIPTORS = { 'page_streaming_method': PageDescriptor( 'page_token', 'next_page_token', 'page_streams') } _BUNDLE_DESCRIPTORS = {'bundling_method': BundleDescriptor('bundled_field', [])} _RETRY_DICT = {'code_a': Exception, 'code_b': Exception, 'code_c': Exception} _FAKE_STATUS_CODE_1 = object() _FAKE_STATUS_CODE_2 = object() class CustomException(Exception): def __init__(self, msg, code):