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 validation to Registrar. Add RegistrarTest to exercise it. #361

Merged
merged 18 commits into from
Jun 23, 2022

Conversation

johnrandolph
Copy link
Collaborator

@johnrandolph johnrandolph commented Jun 14, 2022

ValidatorTest
Add validation test emptySystemBlock which verifies that removing system{} from metadata produces metadata report

LocalDevice
Add optionally calling validate() on metadata load, and processing the report.

Registrar
Wire controlling validation in LocalDevice through Registrar.
Add option -t to enable validation.
Some refactoring of main for testing purposes.

RegistrarTest
Add test framework for Registrar.
Add a test for successful and failed validation.
Note these tests are not run anywhere -- where should we run them?

@johnrandolph johnrandolph changed the title Add ValidationTest Add RegistrarTest Jun 14, 2022
@johnrandolph johnrandolph changed the title Add RegistrarTest Add validation to Registrar. Add RegistrarTest to exercise it. Jun 22, 2022
@johnrandolph johnrandolph requested a review from grafnu June 22, 2022 17:02
@johnrandolph johnrandolph marked this pull request as ready for review June 22, 2022 17:03
executeWithRegistrar(registrar, argList);
}

public static void executeWithRegistrar(Registrar registrar, ArrayList<String> argList) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this need to be static? Can't it just be a regular class method on Registrar?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I moved this from main() which was static and was looking to be consistent but make the most minimal change. WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

New attempt, PTAL

@@ -705,6 +725,9 @@ private void loadSiteMetadata() {

File siteMetadataFile = new File(siteDir, SITE_METADATA_JSON);
try (InputStream targetStream = new FileInputStream(siteMetadataFile)) {
// At this time, do not validate the Metadata schema because, by its nature of being
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm confused by this comment -- it says "do not validate" and then the code right after is validate()... ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes but we ignore the return value, the report.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Still confused -- if it's ignored then why is it calling validate()? Do you mean something like "At this time, only validate the structure of the Metadata schema because it's only a partial overlay, and defer any in-depth validation until after merge?"

@grafnu
Copy link
Collaborator

grafnu commented Jun 22, 2022 via email

@johnrandolph
Copy link
Collaborator Author

I would make it non-static. I get the minimal change part but in this case I think it's worth it...

On Wed, Jun 22, 2022, 2:27 PM John R @.> wrote: @.* commented on this pull request. ------------------------------ In validator/src/main/java/com/google/daq/mqtt/registrar/Registrar.java <#361 (comment)>: > @@ -107,6 +111,10 @@ public class Registrar { public static void main(String[] args) { ArrayList argList = new ArrayList<>(List.of(args)); Registrar registrar = new Registrar(); + executeWithRegistrar(registrar, argList); + } + + public static void executeWithRegistrar(Registrar registrar, ArrayList argList) { I moved this from main() which was static and was looking to be consistent but make the most minimal change. WDYT? — Reply to this email directly, view it on GitHub <#361 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIEPDZN7RWNP5GBQQ2QZBDVQOAKXANCNFSM5YYOYBAA . You are receiving this because your review was requested.Message ID: @.***>

To me, this would suggest we need to move the argv passing code entirely outside of the class, and pass options into Registrar class, to make a clean boundary. WDYT?

@grafnu
Copy link
Collaborator

grafnu commented Jun 23, 2022

To me, this would suggest we need to move the argv passing code entirely outside of the class, and pass options into Registrar class, to make a clean boundary. WDYT?

I'm largely ambivalent about that -- personally I don't see any great value in having a separate class for it, but it doesn't hurt anything. Either way is fine with me...Ideally we'd have more of a shared front-end with common options, etc... but I think that itself would be a bunch of work!

}

private static boolean processArgs(List<String> argList, Registrar registrar) {
public static void processArgs(List<String> argList, Registrar registrar) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Still not sure why this is static? The general adage with static methods for Java is to avoid them unless they need to be static for some reason. I think this comes down to the issue that you can't mock/override a static method, so it makes future testing/extension a problem sometimes. Not likely in this case, but just on general practice. E.g., I would expect this to be just a regular method on the Registrar class (no need to pass in the explicit parameter). Anyway, that's mainly the Java-style that I've always used, but it's been so long that I'm not 100% sure where it came from. I checked the Java style guide and it doesn't say anything about it. Doesn't really matter -- I also optimize for "least number of words" and if you made it a class method, all references to "registrar." go away reducing the overall footprint of the class -- and there's no world in which you would call this method without a registrar class!

@johnrandolph johnrandolph merged commit 93b3195 into faucetsdn:master Jun 23, 2022
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.

None yet

2 participants