Skip to content

Making Optimizely Autocloseable #296

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

Merged
merged 8 commits into from
May 10, 2019
Merged

Conversation

aliabbasrizvi
Copy link
Contributor

Making Optimizely Autocloseable and calling close on EventHandler and ProjectConfigManager if they are Closeable themselves.

@aliabbasrizvi aliabbasrizvi requested a review from mikecdavis May 6, 2019 20:36
@coveralls
Copy link

Pull Request Test Coverage Report for Build 1024

  • 0 of 5 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 88.927%

Changes Missing Coverage Covered Lines Changed/Added Lines %
core-api/src/main/java/com/optimizely/ab/Optimizely.java 0 5 0.0%
Totals Coverage Status
Change from base Build 1020: -0.1%
Covered Lines: 3084
Relevant Lines: 3468

💛 - Coveralls

@coveralls
Copy link

coveralls commented May 6, 2019

Pull Request Test Coverage Report for Build 1042

  • 9 of 10 (90.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 88.73%

Changes Missing Coverage Covered Lines Changed/Added Lines %
core-api/src/main/java/com/optimizely/ab/Optimizely.java 9 10 90.0%
Totals Coverage Status
Change from base Build 1031: 0.004%
Covered Lines: 3110
Relevant Lines: 3505

💛 - Coveralls

@aliabbasrizvi aliabbasrizvi force-pushed the ali/optimizely_closeable branch from 32ced5e to 12d3483 Compare May 8, 2019 05:42
@aliabbasrizvi aliabbasrizvi requested a review from mikecdavis May 8, 2019 18:26
Copy link
Contributor

@mikecdavis mikecdavis left a comment

Choose a reason for hiding this comment

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

We should be catching these exceptions else close() isn't guaranteed for all closeables.

verify((Closeable) mockCloseableProjectConfigManager).close();
}

@Test(expected = IOException.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't want to throw an exception. I think we should be catching all exceptions.

@aliabbasrizvi aliabbasrizvi requested a review from mikecdavis May 9, 2019 00:51
public void close() {
if (eventHandler instanceof Closeable) {
try {
((Closeable) eventHandler).close();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe best to create a tryClose(Object obj) method.

private void tryClose(Object obj) {
    if (!(obj instanceof Closeable)) {
        return;
    }
    
    try {
        ((Closeable) obj).close();
    } catch (Exception e) {
        logger.warn("Unexpected exception on trying to close {}.", obj);
    }
}

*
* <b>NOTE:</b> There is a chance that this could be long running if the implementations of close are long running.
*/
@Override
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, spacing is not consistent.

@aliabbasrizvi aliabbasrizvi requested a review from mikecdavis May 9, 2019 19:09
Copy link
Contributor

@mikecdavis mikecdavis left a comment

Choose a reason for hiding this comment

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

LGTM

@aliabbasrizvi aliabbasrizvi merged commit 7284937 into master May 10, 2019
@aliabbasrizvi aliabbasrizvi deleted the ali/optimizely_closeable branch May 10, 2019 00:21
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.

3 participants