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

Add Version information to RC template #491

Merged
merged 4 commits into from
Nov 10, 2020
Merged

Conversation

lahirumaramba
Copy link
Member

@lahirumaramba lahirumaramba commented Nov 3, 2020

  • Add Version information to the Template
  • Create new Version type
  • Create new User type
  • Note: Since Version and User types are output only, I did not implement equal() and hashcode() operations. Instead, unit tests are checking for each property in Version and User individually. I also removed the equality operations from Template, as well.
  • Based on PR review feedback, implement equality in all public types (including Version and User) to keep consistency.

Related to: #446

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

It looks pretty solid. I only had some minor nits. But I do think we should support equals on the new classes. A developer might want to do something like the following:

if (!template1.getVersion().equals(template2.getVersion()) {
  // do something
}

It's also consistent with other classes in this package. WDYT?

if (!Strings.isNullOrEmpty(versionResponse.getUpdateTime())) {
// Update Time is a timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds.
// example: "2014-10-02T15:01:23.045123456Z"
// SimpleDateFormat cannot handle nanoseconds, therefore we drop nanoseconds from the string.
Copy link
Member Author

@lahirumaramba lahirumaramba Nov 4, 2020

Choose a reason for hiding this comment

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

I noticed that the update time is represented in FC3339 UTC "Zulu" format, accurate to nanoseconds. Added new code here to convert the timestamp to milliseconds properly.

DateTime does not handle nanoseconds so I had to drop them from the timestamp string before parsing. Otherwise SimpleDateFormat considers nanoseconds as milliseconds and add it back to the time making the parsed date/time incorrect.

Apparently, there are better ways to handle nanoseconds in Java8 (LocalDateTime and Instant) :)

@lahirumaramba
Copy link
Member Author

Implemented equal() in all public types (including Version and User) to keep consistency

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

Thanks. This looks great. Just a few nits.

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

LGTM with a couple of suggestions.

// SimpleDateFormat cannot handle nanoseconds, therefore we strip nanoseconds from the string.
String updateTime = versionResponse.getUpdateTime();
int indexOfPeriod = !updateTime.contains(".") ? 0 : updateTime.indexOf(".");
String updateTimeWithoutNanoseconds = updateTime.substring(0, indexOfPeriod);
Copy link
Contributor

Choose a reason for hiding this comment

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

indexOfPeriod can be possibly 0, in which case this will do substring(0, 0). I think following makes more sense to me:

String updateTime = versionResponse.getUpdateTime();
int indexOfPeriod = updateTime.indexOf('.');
if (indexOfPeriod != -1) {
  updateTime = updateTime.substring(0, indexOfPeriod);
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree! This is better. Update the code. Thanks!

@@ -132,5 +132,12 @@ public void testEquality() {
assertNotEquals(templateThree, templateFive);
assertNotEquals(templateThree, templateSeven);
assertNotEquals(templateFive, templateSeven);

final Template templateNine = new Template()
Copy link
Contributor

Choose a reason for hiding this comment

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

It's ok to define some of these as class level constants. For example templateNine can be a class-level constant, and templateTen can be initialized in the corresponding test case as a local var. Same goes for others.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see what you mean now! Moved to class level constants. Thanks!

@lahirumaramba lahirumaramba merged commit daf8b2c into remote-config Nov 10, 2020
@lahirumaramba lahirumaramba deleted the lm-rc-version branch November 10, 2020 20:22
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.

2 participants