-
Notifications
You must be signed in to change notification settings - Fork 89
chore(grpc): refactor model to/from Pb methods to be abstracted by Codec #1344
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
Conversation
| Conversions.apiary().blobInfo().encode(this), | ||
| Conversions.apiary() | ||
| .blobInfo() | ||
| .encode(((BlobInfo) obj))); // TODO: remove this excessive allocation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you say remove excessive allocation, are you saying the Blob should retain a reference to it's encoding so you can don't have to do .encode(this)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think we should implement equals & hash code in terms of the properties of the class and not in terms of it's converted result.
| @Test | ||
| public void testCreateBucket() { | ||
| doReturn(BUCKET_INFO1.toPb()) | ||
| doReturn(Conversions.apiary().bucketInfo().encode(BUCKET_INFO1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to complete moving to mockito from easymock in main branch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually yeah, though I'm not sure it's an immediate need compared to features for gRPC.
3729d4f to
eca9821
Compare
* Introduce new internal API Codec<From, To> which provides a symmetric pair of conversion functions between two types * Add ApiaryConversions.java to contain all the new Codecs for each of the existing apiary toPb/fromPb methods * Update StorageImpl and associated classes to use new codecs rather than old model methods * Add clirr rule to allow removing accidental public HmacKeyMetadata#toPb * Add BucketInfo#asBucket to convert from a BucketInfo to the syntax class Bucket with a specified instance of Storage * Add BlobInfo#asBlob to convert from a BlobInfo to the syntax class Blob with a specified instance of Storage * Add Utils#ifNonNull to help tersify a lot of the conversion code in ApiaryConversions
eca9821 to
0701d61
Compare
frankyn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, missing codec for Notification:
google-cloud-storage/src/main/java/com/google/cloud/storage/Notification.java: static Notification fromPb(
google-cloud-storage/src/main/java/com/google/cloud/storage/Notification.java: storage, new NotificationInfo.BuilderImpl(NotificationInfo.fromPb(notificationPb)));
google-cloud-storage/src/main/java/com/google/cloud/storage/NotificationInfo.java: return NotificationInfo.fromPb(pb);
google-cloud-storage/src/main/java/com/google/cloud/storage/NotificationInfo.java: static NotificationInfo fromPb(
google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java: return Notification.fromPb(
google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java: return answer == null ? null : Notification.fromPb(this, answer);
google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java: return Notification.fromPb(getOptions().getService(), notificationPb);
google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java: IamConfiguration fromPb = Conversions.apiary().iamConfiguration().decode(iamConfiguration);
google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java: assertEquals(PublicAccessPrevention.UNKNOWN, fromPb.getPublicAccessPrevention());
google-cloud-storage/src/test/java/com/google/cloud/storage/NotificationInfoTest.java: NOTIFICATION_INFO, NotificationInfo.fromPb(NOTIFICATION_INFO.toPb()));
google-cloud-storage/src/test/java/com/google/cloud/storage/NotificationInfoTest.java: compareBucketsNotification(notificationInfo, Notification.fromPb(notificationInfo.toPb()));
google-cloud-storage/src/test/java/com/google/cloud/storage/NotificationTest.java: NOTIFICATION_INFO, Notification.fromPb(storage, NOTIFICATION_INFO.toPb()));
google-cloud-storage/src/test/java/com/google/cloud/storage/AclTest.java
Outdated
Show resolved
Hide resolved
|
Refactored the notification conversions as well, thanks for the reminder. Ready for re-review. |
| } | ||
|
|
||
| private static void checkTopicFormat(String topic) { | ||
| private static void checkTopicFormat(String topic) { // todo: why does this exist? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidentally added I'm assuming, but we can remove it.
…dec (#1344) * Introduce new internal API Codec<From, To> which provides a symmetric pair of conversion functions between two types * Add ApiaryConversions.java to contain all the new Codecs for each of the existing apiary toPb/fromPb methods * Update StorageImpl and associated classes to use new codecs rather than old model methods * Add clirr rule to allow removing accidental public HmacKeyMetadata#toPb * Add BucketInfo#asBucket to convert from a BucketInfo to the syntax class Bucket with a specified instance of Storage * Add BlobInfo#asBlob to convert from a BlobInfo to the syntax class Blob with a specified instance of Storage * Add Utils#ifNonNull to help tersify a lot of the conversion code in ApiaryConversions
Uh oh!
There was an error while loading. Please reload this page.