Skip to content

Conversation

@BenWhitehead
Copy link
Collaborator

  • Add GrpcConversions#timestampCodec convert between java.time.OffsetDateTime and com.google.protobuf.Timestamp
  • Add property test for timestampCodec
  • Replace all usage of "Long" methods in GrpcConversions with their appropriate java.time alternatives

@BenWhitehead BenWhitehead requested a review from a team as a code owner May 25, 2022 21:55
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: storage Issues related to the googleapis/java-storage API. labels May 25, 2022
…ecated methods

* Add GrpcConversions#timestampCodec convert between java.time.OffsetDateTime and com.google.protobuf.Timestamp
* Add property test for timestampCodec
* Replace all usage of "Long" methods in GrpcConversions with their appropriate java.time alternatives
private static final class Supp implements ArbitrarySupplier<Timestamp> {
@Override
public Arbitrary<Timestamp> get() {
return StorageArbitraries.timestamp();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you need this helper static method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Rather than the Arbitrary<Timestamp> from StorageArbitraries being registered globally, this method provides the resolution handle to jqwik so it knows how to generate arbitraries for the test method.

Above on line 41 @ForAll(supplier = Supp.class) points to this class as the means to resolve the Arbitrary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we'd rather it be registered globally, I can do that too.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, this is just to test the timestampCodec specifically; wouldn't you need a timestamp supplier for other tests such as bucket/ object metadata? I think that's what is confusing me. This is more of a question that can be answered after PR approval. Thanks Ben

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Other things would also need the timestamp supplier, which so far has been accessed and composed directly via StorageArbitraries#timestamp().

This supplier class is effectively wiring so that jqwik finds that method for the test.

Codec.of(this::crc32cEncode, this::crc32cDecode);

@VisibleForTesting
final Codec<OffsetDateTime, Timestamp> timestampCodec =
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't this in our codecs source instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Following the pattern from ApiaryConversions for that conversion to DataTime[1].

Give this conversion is specific to the use of protos it probably makes sense to keep it near the proto conversions. Or, is there another location you'd like to see this moved to?

[1]

@VisibleForTesting
final Codec<OffsetDateTime, DateTime> dateTimeCodec =
Codec.of(
odt -> {
ZoneOffset offset = odt.getOffset();
int i = Math.toIntExact(TimeUnit.SECONDS.toMinutes(offset.getTotalSeconds()));
return new DateTime(odt.toInstant().toEpochMilli(), i);
},
dt -> {
long milli = dt.getValue();
int timeZoneShiftMinutes = dt.getTimeZoneShift();
Duration timeZoneShift = Duration.of(timeZoneShiftMinutes, ChronoUnit.MINUTES);
int hours = Math.toIntExact(timeZoneShift.toHours());
int minutes =
Math.toIntExact(
timeZoneShift.minusHours(timeZoneShift.toHours()).getSeconds() / 60);
ZoneOffset offset = ZoneOffset.ofHoursMinutes(hours, minutes);
return Instant.ofEpochMilli(milli).atOffset(offset);
});

@BenWhitehead BenWhitehead merged commit 5c94149 into feat/grpc-storage Jun 1, 2022
@BenWhitehead BenWhitehead deleted the time-pt3 branch June 1, 2022 23:36
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: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants