Repository navigation
feat(storagecontrol): add Rapid Cache samples - #2343
sahusneha2004 wants to merge 2 commits into
Conversation
Adds create, get, list, update and disable Rapid Cache samples for Storage Control, with tests. Bumps google/cloud-storage-control to ^1.12. b/482946642 [Generated-by: AI]
There was a problem hiding this comment.
Code Review
This pull request updates the google/cloud-storage-control dependency and introduces new PHP code samples for managing the lifecycle of Rapid Cache instances, including creation, retrieval, listing, updating, and disabling. It also adds a comprehensive integration test suite. The feedback highlights a PSR-1/PSR-12 style guide violation regarding the test class name casing, and suggests guarding against a potential null pointer dereference in the update sample when retrieving the TTL from the response.
| /** | ||
| * Tests for the Rapid Cache storage control samples. | ||
| */ | ||
| class rapidCacheTest extends TestCase |
There was a problem hiding this comment.
According to the PSR-1 and PSR-12 style guides, class names MUST be declared in StudlyCaps. Please rename the class to RapidCacheTest to adhere to these standards. Additionally, the filename should ideally be renamed to RapidCacheTest.php to match the class name.
class RapidCacheTest extends TestCaseReferences
- PSR-1 Section 3 states that class names MUST be declared in StudlyCaps. (link)
| /** @var RapidCache $rapidCacheResult */ | ||
| $rapidCacheResult = $operation->getResult(); | ||
| printf('Updated Rapid Cache: %s' . PHP_EOL, $rapidCacheResult->getName()); | ||
| printf('TTL: %d seconds' . PHP_EOL, $rapidCacheResult->getTtl()->getSeconds()); |
There was a problem hiding this comment.
To prevent a potential null pointer dereference (fatal error) if the server does not return the TTL in the response, it is safer to check if the TTL is set before calling getSeconds(). In Protobuf PHP, you can use the hasTtl() method to verify if the message field is populated.
if ($rapidCacheResult->hasTtl()) {
printf('TTL: %d seconds' . PHP_EOL, $rapidCacheResult->getTtl()->getSeconds());
}…ation test Set the explicit cache name (ID = zone), cache_type rapid-cache-ultra and ttl 24h on create; wait for the disable LRO; tests assert running state, cache type, list membership and the updated ttl, and bound the disable wait. Aligns with googleapis/google-cloud-java#14529. b/482946642 [Generated-by: AI]
Adds Storage Control samples for Rapid Cache, plus a test:
create_rapid_cache.php(storage_control_create_rapid_cache): creates arapid-cache-ultracache in a zone and waits for the LRO to finish. The server assigns the cache name.get_rapid_cache.php(storage_control_get_rapid_cache)list_rapid_caches.php(storage_control_list_rapid_caches)update_rapid_cache.php(storage_control_update_rapid_cache): sets the TTL with update maskttl.disable_rapid_cache.php(storage_control_disable_rapid_cache): starts the disable LRO and prints the operation name. It does not wait, because the operation runs for more than an hour.test/rapidCacheTest.php: runs the whole lifecycle on a regional HNS + UBLA bucket, then pollsgetuntil the state isdisabled. Bucket deletion fails with 409 for a long time after a cache is disabled, so cleanup is best-effort: it retries briefly, then logs the name of any bucket it left behind.google/cloud-storage-controlto^1.12, which has the RapidCache API.b/482946642
Validation: php-cs-fixer and PHPStan both pass. The live test has not been run yet. Rapid Cache RPCs work only over gRPC, and the authoring environment has no
ext-grpc. CI does have it.[Generated-by: AI]
Update: aligned with googleapis/google-cloud-java#14529
The samples now follow the reference integration test (
ITRapidCacheTest). Where this section conflicts with the notes above, this section is current.projects/_/buckets/{bucket}/rapidCaches/{zone}(the backend requires the cache ID to equal the zone), withcache_typerapid-cache-ultraandttl86400s (24h). It also prints the state.totalPollTimeoutMillis0). Before, they used the 5-minute client default. If the operation fails, they print the error.$timeoutMillisargument (default 0 = no limit) bounds the wait. If the wait times out, the sample prints that the operation is still running. If the operation fails, it prints the error.State: running, the cache type, list membership, and TTL 172800s after update.getshowsState: disabledand does not fail.Validation:
php -l, php-cs-fixer (repo config), and PHPStan (repo config) all pass. The live test was not run locally becauseext-grpcis missing in the authoring environment.[Generated-by: AI]