Skip to content

Commit ba64b15

Browse files
1 parent 6dc974f commit ba64b15

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

‎google/cloud/storage/_experimental/asyncio/retry/base_strategy.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import abc
22
from typing import Any, Iterable
33

4+
45
class _BaseResumptionStrategy(abc.ABC):
56
"""Abstract base class defining the interface for a bidi stream resumption strategy.
67

‎google/cloud/storage/_experimental/asyncio/retry/reads_resumption_strategy.py‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
_BaseResumptionStrategy,
77
)
88

9+
910
class _DownloadState:
1011
"""A helper class to track the state of a single range download."""
11-
def __init__(self, initial_offset: int, initial_length: int, user_buffer: IO[bytes]):
12+
13+
def __init__(
14+
self, initial_offset: int, initial_length: int, user_buffer: IO[bytes]
15+
):
1216
self.initial_offset = initial_offset
1317
self.initial_length = initial_length
1418
self.user_buffer = user_buffer
@@ -41,7 +45,9 @@ def generate_requests(self, state: dict) -> List[storage_v2.ReadRange]:
4145
pending_requests.append(new_request)
4246
return pending_requests
4347

44-
def update_state_from_response(self, response: storage_v2.BidiReadObjectResponse, state: dict) -> None:
48+
def update_state_from_response(
49+
self, response: storage_v2.BidiReadObjectResponse, state: dict
50+
) -> None:
4551
"""Processes a server response, performs integrity checks, and updates state."""
4652
for object_data_range in response.object_data_ranges:
4753
read_id = object_data_range.read_range.read_id
@@ -61,8 +67,13 @@ def update_state_from_response(self, response: storage_v2.BidiReadObjectResponse
6167
# Final Byte Count Verification
6268
if object_data_range.range_end:
6369
read_state.is_complete = True
64-
if read_state.initial_length != 0 and read_state.bytes_written != read_state.initial_length:
65-
raise DataCorruption(response, f"Byte count mismatch for read_id {read_id}")
70+
if (
71+
read_state.initial_length != 0
72+
and read_state.bytes_written != read_state.initial_length
73+
):
74+
raise DataCorruption(
75+
response, f"Byte count mismatch for read_id {read_id}"
76+
)
6677

6778
async def recover_state_on_failure(self, error: Exception, state: Any) -> None:
6879
"""Handles BidiReadObjectRedirectError for reads."""

‎tests/unit/asyncio/retry/test_reads_resumption_strategy.py‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ def test_update_state_processes_single_chunk_successfully(self):
105105
response = storage_v2.BidiReadObjectResponse(
106106
object_data_ranges=[
107107
storage_v2.types.ObjectRangeData(
108-
read_range=storage_v2.ReadRange(read_id=_READ_ID, read_offset=0, read_length=len(data)),
108+
read_range=storage_v2.ReadRange(
109+
read_id=_READ_ID, read_offset=0, read_length=len(data)
110+
),
109111
checksummed_data=storage_v2.ChecksummedData(content=data),
110112
)
111113
]
@@ -128,7 +130,9 @@ def test_update_state_from_response_offset_mismatch(self):
128130
response = storage_v2.BidiReadObjectResponse(
129131
object_data_ranges=[
130132
storage_v2.types.ObjectRangeData(
131-
read_range=storage_v2.ReadRange(read_id=_READ_ID, read_offset=0, read_length=4),
133+
read_range=storage_v2.ReadRange(
134+
read_id=_READ_ID, read_offset=0, read_length=4
135+
),
132136
checksummed_data=storage_v2.ChecksummedData(content=b"data"),
133137
)
134138
]
@@ -147,7 +151,9 @@ def test_update_state_from_response_final_byte_count_mismatch(self):
147151
response = storage_v2.BidiReadObjectResponse(
148152
object_data_ranges=[
149153
storage_v2.types.ObjectRangeData(
150-
read_range=storage_v2.ReadRange(read_id=_READ_ID, read_offset=0, read_length=4),
154+
read_range=storage_v2.ReadRange(
155+
read_id=_READ_ID, read_offset=0, read_length=4
156+
),
151157
checksummed_data=storage_v2.ChecksummedData(content=b"data"),
152158
range_end=True,
153159
)
@@ -169,7 +175,9 @@ def test_update_state_from_response_completes_download(self):
169175
response = storage_v2.BidiReadObjectResponse(
170176
object_data_ranges=[
171177
storage_v2.types.ObjectRangeData(
172-
read_range=storage_v2.ReadRange(read_id=_READ_ID, read_offset=0, read_length=len(data)),
178+
read_range=storage_v2.ReadRange(
179+
read_id=_READ_ID, read_offset=0, read_length=len(data)
180+
),
173181
checksummed_data=storage_v2.ChecksummedData(content=data),
174182
range_end=True,
175183
)
@@ -193,7 +201,9 @@ def test_update_state_from_response_completes_download_zero_length(self):
193201
response = storage_v2.BidiReadObjectResponse(
194202
object_data_ranges=[
195203
storage_v2.types.ObjectRangeData(
196-
read_range=storage_v2.ReadRange(read_id=_READ_ID, read_offset=0, read_length=len(data)),
204+
read_range=storage_v2.ReadRange(
205+
read_id=_READ_ID, read_offset=0, read_length=len(data)
206+
),
197207
checksummed_data=storage_v2.ChecksummedData(content=data),
198208
range_end=True,
199209
)

0 commit comments

Comments
 (0)