def modify_push_config(self, name, push_config, options=None): from google.gax.errors import GaxError self._modify_push_config_called_with = name, push_config, options if self._random_gax_error: raise GaxError('error') if not self._modify_push_config_ok: raise GaxError('miss', self._make_grpc_not_found())
def delete_log_metric(self, metric_name, options=None): from google.gax.errors import GaxError self._delete_log_metric_called_with = metric_name, options if self._random_gax_error: raise GaxError('error') if self._log_metric_not_found: raise GaxError('notfound', self._make_grpc_not_found())
def create_log_metric(self, parent, metric, options): from google.gax.errors import GaxError self._create_log_metric_called_with = parent, metric, options if self._random_gax_error: raise GaxError('error') if self._create_log_metric_conflict: raise GaxError('conflict', self._make_grpc_failed_precondition())
def acknowledge(self, name, ack_ids, options=None): from google.gax.errors import GaxError self._acknowledge_called_with = name, ack_ids, options if self._random_gax_error: raise GaxError('error') if not self._acknowledge_ok: raise GaxError('miss', self._make_grpc_not_found())
def delete_subscription(self, name, options=None): from google.gax.errors import GaxError self._delete_subscription_called_with = name, options if self._random_gax_error: raise GaxError('error') if not self._delete_subscription_ok: raise GaxError('miss', self._make_grpc_not_found())
def update_instance(self, instance, field_mask, options=None): from google.gax.errors import GaxError self._updated_instance = (instance, field_mask, options) if self._random_gax_error: raise GaxError('error') if self._instance_not_found: raise GaxError('not found', self._make_grpc_not_found()) return self._update_instance_response
def drop_database(self, database, options=None): from google.gax.errors import GaxError self._dropped_database = database, options if self._random_gax_error: raise GaxError('error') if self._database_not_found: raise GaxError('not found', self._make_grpc_not_found()) return self._drop_database_response
def modify_ack_deadline(self, name, ack_ids, deadline, options=None): from google.gax.errors import GaxError self._modify_ack_deadline_called_with = (name, ack_ids, deadline, options) if self._random_gax_error: raise GaxError('error') if not self._modify_ack_deadline_ok: raise GaxError('miss', self._make_grpc_not_found())
def create_topic(self, name, options=None): from google.gax.errors import GaxError self._create_topic_called_with = name, options if self._random_gax_error: raise GaxError('error') if self._create_topic_conflict: raise GaxError('conflict', self._make_grpc_failed_precondition()) return self._create_topic_response
def delete_instance(self, name, options=None): from google.gax.errors import GaxError self._deleted_instance = name, options if self._random_gax_error: raise GaxError('error') if self._instance_not_found: raise GaxError('not found', self._make_grpc_not_found()) return self._delete_instance_response
def create_instance(self, parent, instance_id, instance, options=None): from google.gax.errors import GaxError self._created_instance = (parent, instance_id, instance, options) if self._random_gax_error: raise GaxError('error') if self._create_instance_conflict: raise GaxError('conflict', self._make_grpc_already_exists()) return self._create_instance_response
def list_topic_subscriptions(self, topic, options=None): from google.gax.errors import GaxError self._list_topic_subscriptions_called_with = topic, options if self._random_gax_error: raise GaxError('error') try: return self._list_topic_subscriptions_response except AttributeError: raise GaxError('miss', self._make_grpc_not_found())
def update_log_metric(self, metric_name, metric, options=None): from google.gax.errors import GaxError self._update_log_metric_called_with = metric_name, metric, options if self._random_gax_error: raise GaxError('error') try: return self._update_log_metric_response except AttributeError: raise GaxError('notfound', self._make_grpc_not_found())
def get_sink(self, sink_name, options): from google.gax.errors import GaxError self._get_sink_called_with = sink_name, options if self._random_gax_error: raise GaxError('error') try: return self._get_sink_response except AttributeError: raise GaxError('notfound', self._make_grpc_not_found())
def publish(self, topic, messages, options=None): from google.gax.errors import GaxError self._publish_called_with = topic, messages, options if self._random_gax_error: raise GaxError('error') try: return self._publish_response except AttributeError: raise GaxError('miss', self._make_grpc_not_found())
def get_subscription(self, name, options=None): from google.gax.errors import GaxError self._get_subscription_called_with = name, options if self._random_gax_error: raise GaxError('error') try: return self._get_subscription_response except AttributeError: raise GaxError('miss', self._make_grpc_not_found())
def pull(self, name, max_messages, return_immediately, options=None): from google.gax.errors import GaxError self._pull_called_with = (name, max_messages, return_immediately, options) if self._random_gax_error: raise GaxError('error') try: return self._pull_response except AttributeError: raise GaxError('miss', self._make_grpc_not_found())
def update_database_ddl(self, database, statements, operation_id, options=None): from google.gax.errors import GaxError self._updated_database_ddl = ( database, statements, operation_id, options) if self._random_gax_error: raise GaxError('error') if self._database_not_found: raise GaxError('not found', self._make_grpc_not_found()) return self._update_database_ddl_response
def create_subscription(self, name, topic, push_config, ack_deadline_seconds, options=None): from google.gax.errors import GaxError self._create_subscription_called_with = ( name, topic, push_config, ack_deadline_seconds, options) if self._random_gax_error: raise GaxError('error') if self._create_subscription_conflict: raise GaxError('conflict', self._make_grpc_failed_precondition()) return self._create_subscription_response
def create_database(self, parent, create_statement, extra_statements=None, options=None): from google.gax.errors import GaxError self._created_database = ( parent, create_statement, extra_statements, options) if self._random_gax_error: raise GaxError('error') if self._create_database_conflict: raise GaxError('conflict', self._make_grpc_already_exists()) if self._database_not_found: raise GaxError('not found', self._make_grpc_not_found()) return self._create_database_response
def commit(self, session, mutations, transaction_id='', single_use_transaction=None, options=None): from grpc import StatusCode from google.gax.errors import GaxError assert single_use_transaction is None self._committed = (session, mutations, transaction_id, options) if self._commit_error: raise GaxError('error', self._make_grpc_error(StatusCode.UNKNOWN)) if self._commit_abort_count > 0: self._commit_abort_count -= 1 grpc_error = self._make_grpc_error( StatusCode.ABORTED, trailing=self._trailing_metadata()) raise GaxError('conflict', grpc_error) return self._commit_response
def create_session(self, database, options=None): from google.gax.errors import GaxError self._create_session_called_with = database, options if self._random_gax_error: raise GaxError('error') return self._create_session_response
def rollback(self, session, transaction_id, options=None): from google.gax.errors import GaxError self._rolled_back = (session, transaction_id, options) if self._random_gax_error: raise GaxError('error') return self._rollback_response
def unit_of_work(txn, *args, **kw): called_with.append((txn, args, kw)) if len(called_with) < 2: grpc_error = gax_api._make_grpc_error( StatusCode.ABORTED, trailing=gax_api._trailing_metadata()) raise GaxError('conflict', grpc_error) txn.insert(TABLE_NAME, COLUMNS, VALUES)
def begin_transaction(self, session, options_, options=None): from google.gax.errors import GaxError self._begun = (session, options_, options) if self._random_gax_error: raise GaxError('error') return self._begin_transaction_response
def commit(self, session, mutations, transaction_id='', single_use_transaction=None, options=None): from google.gax.errors import GaxError assert single_use_transaction is None self._committed = (session, mutations, transaction_id, options) if self._random_gax_error: raise GaxError('error') return self._commit_response
def test_gax_error_not_mapped(self): from google.gax.errors import GaxError from grpc import StatusCode cause = self._make_rendezvous(StatusCode.CANCELLED, None) exc = GaxError(None, cause=cause) with self.assertRaises(GaxError): with self._call_fut(): self._fake_method(exc)
def streaming_read(self, session, table, columns, key_set, transaction=None, index='', limit=0, resume_token='', options=None): from google.gax.errors import GaxError self._streaming_read_with = ( session, table, columns, key_set, transaction, index, limit, resume_token, options) if self._random_gax_error: raise GaxError('error') return self._streaming_read_response
def execute_streaming_sql(self, session, sql, transaction=None, params=None, param_types=None, resume_token='', query_mode=None, options=None): from google.gax.errors import GaxError self._executed_streaming_sql_with = ( session, sql, transaction, params, param_types, resume_token, query_mode, options) if self._random_gax_error: raise GaxError('error') return self._execute_streaming_sql_response
def test_gax_error(self): from google.gax.errors import GaxError from grpc import StatusCode from google.cloud.exceptions import Forbidden # First, create low-level GrpcRendezvous exception. details = 'Some error details.' cause = self._make_rendezvous(StatusCode.PERMISSION_DENIED, details) # Then put it into a high-level GaxError. msg = 'GAX Error content.' exc = GaxError(msg, cause=cause) with self.assertRaises(Forbidden): with self._call_fut(): self._fake_method(exc)