Skip to content

Conversation

@BenWhitehead
Copy link
Collaborator

@BenWhitehead BenWhitehead commented Apr 6, 2022

  • 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

@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/java-storage API. label Apr 6, 2022
Conversions.apiary().blobInfo().encode(this),
Conversions.apiary()
.blobInfo()
.encode(((BlobInfo) obj))); // TODO: remove this excessive allocation
Copy link
Contributor

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)?

Copy link
Collaborator Author

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))
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

@product-auto-label product-auto-label bot added the size: xl Pull request size is extra large. label Apr 13, 2022
@BenWhitehead BenWhitehead force-pushed the codec-refactor branch 2 times, most recently from 3729d4f to eca9821 Compare May 2, 2022 20:38
* 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
@BenWhitehead BenWhitehead marked this pull request as ready for review May 2, 2022 20:41
@BenWhitehead BenWhitehead requested review from a team as code owners May 2, 2022 20:41
Copy link
Contributor

@frankyn frankyn left a 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()));

@BenWhitehead
Copy link
Collaborator Author

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?
Copy link
Contributor

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.

@BenWhitehead BenWhitehead merged commit 6eb30e9 into feat/grpc-storage May 5, 2022
@BenWhitehead BenWhitehead deleted the codec-refactor branch May 5, 2022 18:07
sydney-munro pushed a commit that referenced this pull request Jun 7, 2022
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the googleapis/java-storage API. size: xl Pull request size is extra large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants