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

refactor(init): build invalid instance if datafile cannot be parsed. #209

Merged
merged 2 commits into from
Sep 5, 2018

Conversation

mikeproeng37
Copy link
Contributor

@mikeproeng37 mikeproeng37 commented Aug 31, 2018

Summary

  • Refactor the Java SDK to follow the rest of the Full Stack SDKs in not throwing or preventing SDK initialization when an invalid datafile is passed in. Instead we will return an Optimizely instance with the isValid property set to false. When accessing any of the SDK APIs, we will first check if the instance is valid before proceeding. If not valid, we will return the sensible defaults for each API.
  • If we run into problems parsing the datafile, then we will pass the exception to the ErrorHandler so the developer can be notified of these kinds of failures.

This does constitute a breaking API change since we will no longer be throwing ConfigParseException from the Builder.build() method. As such, this will be released in version 3 of the SDK.

Missing

This PR is to get initial feedback and is therefore missing unit tests for the invalid state in feature variable APIs. Will add those once I get some feedback regarding this approach.

@VisibleForTesting
void initialize() {
void initialize(@Nonnull String datafile, @Nullable ProjectConfig projectConfig) {
if (projectConfig == null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This step de-couples the "building" of the Optimizely instance from the "initialization", which is where we start populating state.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we should probably discuss this. As far as I know for threading purposes, you would not reuse these components but instead, initialize a new instance. This actually brings up an interesting point of Android datafile handler: Should the datafile handler reinitialize or have a shutdown mechanism?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, will take this offline.

@coveralls
Copy link

coveralls commented Aug 31, 2018

Pull Request Test Coverage Report for Build 602

  • 41 of 57 (71.93%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.4%) to 88.972%

Changes Missing Coverage Covered Lines Changed/Added Lines %
core-api/src/main/java/com/optimizely/ab/Optimizely.java 41 57 71.93%
Totals Coverage Status
Change from base Build 600: -0.4%
Covered Lines: 2380
Relevant Lines: 2675

💛 - Coveralls

Copy link
Contributor

@shihpatrick shihpatrick left a comment

Choose a reason for hiding this comment

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

lgtm

@VisibleForTesting
void initialize() {
void initialize(@Nonnull String datafile, @Nullable ProjectConfig projectConfig) {
if (projectConfig == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we should probably discuss this. As far as I know for threading purposes, you would not reuse these components but instead, initialize a new instance. This actually brings up an interesting point of Android datafile handler: Should the datafile handler reinitialize or have a shutdown mechanism?

@mikeproeng37 mikeproeng37 merged commit 7347f06 into master Sep 5, 2018
@mikeproeng37 mikeproeng37 deleted the mng/add-is-valid-state branch September 21, 2018 22:35
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.

4 participants