Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into rst
  • Loading branch information
asthamohta authored May 24, 2023
commit c5ccdcc99aab2c181c05a416a0725117c3394014
13 changes: 13 additions & 0 deletions google/cloud/spanner_v1/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,16 @@ def _check_rst_stream_error(exc):
)
if not resumable_error:
raise


def _metadata_with_leader_aware_routing(value, **kw):
"""Create RPC metadata containing a leader aware routing header

Args:
value (bool): header value

Returns:
List[Tuple[str, str]]: RPC metadata with leader aware routing header
"""
return ("x-goog-spanner-route-to-leader", str(value).lower())

14 changes: 14 additions & 0 deletions tests/unit/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ def test(self):
self.assertEqual(metadata, [("google-cloud-resource-prefix", prefix)])



class Test_retry(unittest.TestCase):
class test_class:
def test_fxn(self):
Expand Down Expand Up @@ -747,3 +748,16 @@ def test_check_rst_stream_error(self):
)

self.assertEqual(test_api.test_fxn.call_count, 3)

class Test_metadata_with_leader_aware_routing(unittest.TestCase):
def _call_fut(self, *args, **kw):
from google.cloud.spanner_v1._helpers import _metadata_with_leader_aware_routing

return _metadata_with_leader_aware_routing(*args, **kw)

def test(self):
value = True
metadata = self._call_fut(True)
self.assertEqual(
metadata, ("x-goog-spanner-route-to-leader", str(value).lower())
)
You are viewing a condensed version of this merge commit. You can view the full changes here.