Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a38c396
feat(zb-experimental): add async write object stream
chandra-siri Nov 13, 2025
aaee2f3
remove unused import and add license info
chandra-siri Nov 13, 2025
4db8bf1
remove unwated test
chandra-siri Nov 13, 2025
8dbd158
feat(zb-experimental): implement "open" for write_object_stream
chandra-siri Nov 14, 2025
03f1fde
remove unused import
chandra-siri Nov 14, 2025
f0d3439
feat(zb-experimental): implement close
chandra-siri Nov 14, 2025
e3b6f9e
feat(zb-experimental): implement send & recv
chandra-siri Nov 14, 2025
b24535f
feat(zb-experimental): Add Async_appendable_object_writer.py
chandra-siri Nov 14, 2025
eae1b36
feat(zb-experimental): implement state_lookup
chandra-siri Nov 14, 2025
788848a
implement tests for state_lookup
chandra-siri Nov 14, 2025
3930823
add type annotation for state_lookup
chandra-siri Nov 14, 2025
222aef2
state_lookup should return persisted_size instead of proto
chandra-siri Nov 14, 2025
6fa5e11
add doc string for AsyncAppendableObjectWriter
chandra-siri Nov 16, 2025
a8eba4f
Merge branch 'bidi-writes-5' of github.com:googleapis/python-storage …
chandra-siri Nov 16, 2025
244635f
Merge branch 'main' into bidi-writes-4
chandra-siri Nov 17, 2025
1981418
add missedout test after merge conflict resolution
chandra-siri Nov 17, 2025
ebd5c10
Merge branch 'bidi-writes-4' of github.com:googleapis/python-storage …
chandra-siri Nov 17, 2025
2a22cf7
Merge branch 'bidi-writes-5' of github.com:googleapis/python-storage …
chandra-siri Nov 17, 2025
4599302
Merge branch 'main' of github.com:googleapis/python-storage into bidi…
chandra-siri Nov 17, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

"""
from typing import Optional
from google.cloud import _storage_v2
from google.cloud.storage._experimental.asyncio.async_grpc_client import (
AsyncGrpcClient,
)
Expand Down Expand Up @@ -112,9 +113,16 @@ def __init__(
self.offset: Optional[int] = None
self.persisted_size: Optional[int] = None

async def state_lookup(self):
async def state_lookup(self) -> int:
"""Returns the persisted_size."""
raise NotImplementedError("state_lookup is not implemented yet.")
await self.write_obj_stream.send(
_storage_v2.BidiWriteObjectRequest(
state_lookup=True,
)
)
response = await self.write_obj_stream.recv()
self.persisted_size = response.persisted_size
return self.persisted_size

async def open(self) -> None:
"""Opens the underlying bidi-gRPC stream."""
Expand Down
32 changes: 29 additions & 3 deletions tests/unit/asyncio/test_async_appendable_object_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
from google.cloud.storage._experimental.asyncio.async_appendable_object_writer import (
AsyncAppendableObjectWriter,
)
from google.cloud import _storage_v2


BUCKET = "test-bucket"
OBJECT = "test-object"
GENERATION = 123
WRITE_HANDLE = b"test-write-handle"
PERSISTED_SIZE = 456


@pytest.fixture
Expand Down Expand Up @@ -82,14 +85,37 @@ def test_init_with_optional_args(mock_write_object_stream, mock_client):
)


@pytest.mark.asyncio
@mock.patch(
"google.cloud.storage._experimental.asyncio.async_appendable_object_writer._AsyncWriteObjectStream"
)
async def test_state_lookup(mock_write_object_stream, mock_client):
"""Test state_lookup method."""
# Arrange
writer = AsyncAppendableObjectWriter(mock_client, BUCKET, OBJECT)
mock_stream = mock_write_object_stream.return_value
mock_stream.send = mock.AsyncMock()
mock_stream.recv = mock.AsyncMock(
return_value=_storage_v2.BidiWriteObjectResponse(persisted_size=PERSISTED_SIZE)
)

expected_request = _storage_v2.BidiWriteObjectRequest(state_lookup=True)

# Act
response = await writer.state_lookup()

# Assert
mock_stream.send.assert_awaited_once_with(expected_request)
mock_stream.recv.assert_awaited_once()
assert writer.persisted_size == PERSISTED_SIZE
assert response == PERSISTED_SIZE


@pytest.mark.asyncio
async def test_unimplemented_methods_raise_error(mock_client):
"""Test that all currently unimplemented methods raise NotImplementedError."""
writer = AsyncAppendableObjectWriter(mock_client, BUCKET, OBJECT)

with pytest.raises(NotImplementedError):
await writer.state_lookup()

with pytest.raises(NotImplementedError):
await writer.open()

Expand Down