Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add dictionary set, get, delete #19

Merged
merged 11 commits into from
Oct 18, 2022

Conversation

poppoerika
Copy link
Contributor

Added dictionary set, get, and delete APIs and tests to check those operations.

Ticket: #17

Comment on lines +128 to +144
private function ttlToMillis(?int $ttl = null): int
{
if (!$ttl) {
$ttl = $this->defaultTtlSeconds;
}
validateTtl($ttl);
return $ttl * 1000;
}

private function processCall(UnaryCall $call): mixed
{
[$response, $status] = $call->wait();
if ($status->code !== 0) {
throw _ErrorConverter::convert($status->code, $status->details, $call->getMetadata());
}
return $response;
}
Copy link
Collaborator

@pgautier404 pgautier404 Oct 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move these private function definitions up so they live between __construct() and set() please?

return new CacheDictionaryGetResponseMiss();
}
if ($dictionaryGetResponse->getFound()->getItems()->count() == 0) {
return new CacheDictionaryGetResponseError(new Exception("_DictionaryGetResponseResponse contained no data but was found"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception used to construct the Error response class needs to be an SdkError like the one above this on line 428. Please use UnknownError like you did above unless you think one of the other SdkError-derived classes works better.

Comment on lines +140 to +148
private function getBadAuthTokenClient(): SimpleCacheClient
{
$badEnvName = "_MOMENTO_BAD_AUTH_TOKEN";
putenv("{$badEnvName}={$this->BAD_AUTH_TOKEN}");
$authProvider = new EnvMomentoTokenProvider($badEnvName);
putenv($badEnvName);
return new SimpleCacheClient($authProvider, $this->DEFAULT_TTL_SECONDS);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to the top of the class, please, either before setUp() or after tearDown()?

@@ -77,13 +67,18 @@ public function testCreateSetGetDelete() {
$this->assertNotNull($response->asSuccess());
}

// Client initialization tests
public function testNegativeDefaultTtl() {
// Happy path test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this comment up so it appears before the testCreateSetGetDelete test.

$response = $this->client->createCache($this->TEST_CACHE_NAME);
$this->assertNotNull($response->asAlreadyExists());
}

// Create cache tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should come before the testCreateCacheAlreadyExists test please.

@poppoerika
Copy link
Contributor Author

@pgautier404 Apologize for removing the list tests you've added.
I need to be careful when I merge and use PhpStorm interface to manage these merges 🙇‍♀️
I addressed your feedback in this push.

pgautier404
pgautier404 previously approved these changes Oct 18, 2022
Copy link
Collaborator

@pgautier404 pgautier404 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Collaborator

@malandis malandis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few things:

  • Recommend storing the deadline in microseconds to avoid duplicated code
  • Recommend splitting data structures tests into multiple files, one for each data structure
  • Consistent test name format (no underscores)

$dictionarySetRequest->setItems([$this->toSingletonFieldValuePair($field, $value)]);
$dictionarySetRequest->setRefreshTtl($refreshTtl);
$dictionarySetRequest->setTtlMilliseconds($ttlMillis);
$call = $this->grpcManager->client->DictionarySet($dictionarySetRequest, ["cache" => [$cacheName]], ["timeout" => $this->deadline_seconds * self::$TIMEOUT_MULTIPLIER]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend pre-computing this so we don't multiply this out in all the functions, ie in the constructor store deadline_microseconds = $this->deadline_seconds * self::$TIMEOUT_MULTIPLIER and use that here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather avoid using deadline_microseconds because they're technically not microseconds. I think this is a great idea, but I'd like to think about it a bit . . . I'll make this change in an upcoming PR.

$this->assertEquals($value, $response->asHit()->value());
}

public function testDictionaryDeleteThrowExceptionForEmptyCacheName()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function name is now out of date -- returns error instead of throws exception :)

$this->assertEquals(MomentoErrorCode::INVALID_ARGUMENT_ERROR, $response->asError()->errorCode());
}

public function testDictionaryDeleteThrowExceptionForEmptyDictionaryName()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also out of date function name

@poppoerika
Copy link
Contributor Author

@malandis Thank you for the feedback!
Regarding splitting the tests, we'll address that in a follow-up PR. (#22)
I will update the test names though.

@poppoerika
Copy link
Contributor Author

@malandis We will address test names in a follow-up pr to get this pr merge first.

@poppoerika poppoerika merged commit 49f4f39 into main Oct 18, 2022
@malandis malandis deleted the chore/add-dictionary-set-get-delete branch November 1, 2024 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants