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

ResponseProcessor State-setting and Tests #178

Merged
merged 7 commits into from
Oct 14, 2021

Conversation

JackSullivan
Copy link
Member

Description

Fixes an issue with multi-field ResponseProcessor instances where the end state of the produced object, when written back out into a configured/provenanced form and re-instantiated wouldn't be processed correctly by the postConfig call. Also added a test for roundtripping any type that is both Configurable and Provenanceable through their respective forms to ensure that the end results are structurally equal according to the ConfigurationData#structuralEquals method in OLCUT, and tests for this behavior in BinaryResponseProcessor and FieldResponseProcessor.

This change depends on OLCUT v5.2.0, and thus requires updating Tribuo to depend on that OLCUT version.

… `Provenancable` through provenance and back to check whether the produce the same object. Wrote a `structuralEquals` method on `ConfigurationData` to support it.
…anged

the logic in `FieldResponseProcessor.postConfig` to properly handle all
cases.
@Craigacp Craigacp added Oracle employee This PR is from an Oracle employee squash-commits Squash the commits when merging this PR labels Sep 27, 2021
Copy link
Member

@Craigacp Craigacp left a comment

Choose a reason for hiding this comment

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

I think the if/else in FieldResponseProcessor could be simplified a bit, otherwise it looks fine.

* and provenance representations are the same using {@link ConfigurationData#structuralEquals(List, List, String, String)}.
* @param itm The object whose equality is to be tested
*/
public static <P extends ObjectProvenance, C extends Configurable & Provenancable<P>> void testConfigurableRoundtrip(C itm) {
Copy link
Member

Choose a reason for hiding this comment

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

This type bound could be P extends ConfiguredObjectProvenance. Not sure if that limits its functionality any.

@@ -76,6 +81,27 @@ public static ImmutableFeatureMap mkFeatureMap(String... features) {
return ex;
}


Copy link
Member

Choose a reason for hiding this comment

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

There are two blank lines between this function and the surrounding ones, but we usually have one.

defaultValues = defaultValues == null ? Collections.nCopies(fieldNames.size(), defaultValue) : defaultValues;
} else if (fieldNames != null) { // multiple fields
if (defaultValues != null && defaultValues.size() == fieldNames.size()) { // check first for multiple defaults
// this is the default case, nothing needs to be done
Copy link
Member

Choose a reason for hiding this comment

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

Can we flip this around to get rid of the empty if branch? Maybe start with defaultValues == null && defaultValue == null to catch the else case, and then have the defaultValue != null one, then defaultValues != null && defaultValues.size() != fieldNames.size() to throw PropertyException.

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 that the empty branch is awkward, but I think this is actually a fair bit more readable. An earlier version without it had bugs that were almost impossible to identify by inspection. However, I'll write documentation for this method and its partner in BinaryResponseProcessor that explains the logic at play.

Copy link
Member

@Craigacp Craigacp left a comment

Choose a reason for hiding this comment

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

Looks good, just a minor point on the docs.

@@ -75,34 +75,42 @@
@ConfigurableName
private String configName;

/**
* We support specifying field names and default values both singly through {@link #fieldName} and {@link #positiveResponse}
* and in a list through {@link #fieldNames} and {@link #positiveResponses}. Canonically all internal logic is driven by
Copy link
Member

Choose a reason for hiding this comment

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

This is a weird javadoc comment as it's more for our benefit as developers rather than anyone who uses this class, so it probably should be a regular comment at the start of this method then it doesn't show up in the docs.

@@ -60,35 +60,41 @@
@ConfigurableName
private String configName;

/**
* We support specifying field names and default values both singly through {@link #fieldName} and {@link #defaultValue}
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as before. At minimum this should not that the method should not be called by user code as the default postConfig javadoc says.

Copy link
Member

@Craigacp Craigacp left a comment

Choose a reason for hiding this comment

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

LGTM

@Craigacp Craigacp merged commit e5dfb30 into oracle:main Oct 14, 2021
@JackSullivan JackSullivan deleted the response-processor-cycle-bugfix branch October 14, 2021 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Oracle employee This PR is from an Oracle employee squash-commits Squash the commits when merging this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants