You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Dawid Weiss (Issue Comment Edited) (JIRA)" <ji...@apache.org> on 2012/03/04 22:22:59 UTC

[jira] [Issue Comment Edited] (LUCENE-3847) LuceneTestCase should check for modifications on System properties

    [ https://issues.apache.org/jira/browse/LUCENE-3847?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13222013#comment-13222013 ] 

Dawid Weiss edited comment on LUCENE-3847 at 3/4/12 9:22 PM:
-------------------------------------------------------------

I've implemented this invariant and it works like a charm. Did you know TimeZone.getDefault() has a side-effect of setting (!) user.timezone system property? If you did, I'll buy you a beer next time we meet :)

Anyway, lots of Solr tests leave behind system properties. Instead of trying to fix them one by one I went kind of the easy route and created a class and test rule that simply reverts all system properties from before the entry scope. This has been applied to AbstractSolrTestCase and SolrTestCaseJ4 and since these are subclasses of LuceneTestCase, the invariant will always hold, no matter what.

If Solr folks wish to fix tests one by one (which may be a good idea or a bad idea -- there's lots of them), then comment out these two:
{code}
  @ClassRule
  public static TestRule solrClassRules = 
    RuleChain.outerRule(new SystemPropertiesRestoreRule());

  @Rule
  public TestRule solrTestRules = 
    RuleChain.outerRule(new SystemPropertiesRestoreRule());
{code}
                
      was (Author: dweiss):
    I've implemented this invariant and it works as a charm. Did you know TimeZone.getDefault() has a side-effect of setting (!) user.timezone system property? If you did, I'll buy you a beer next time we meet :)

Anyway, lots of Solr tests leave behind system properties. Instead of trying to fix them one by one I went kind of the easy route and created a class and test rule that simply reverts all system properties from before the entry scope. This has been applied to AbstractSolrTestCase and SolrTestCaseJ4 and since these are subclasses of LuceneTestCase, the invariant will always hold, no matter what.

If Solr folks wish to fix tests one by one (which may be a good idea or a bad idea -- there's lots of them), then comment out these two:
{code}
  @ClassRule
  public static TestRule solrClassRules = 
    RuleChain.outerRule(new SystemPropertiesRestoreRule());

  @Rule
  public TestRule solrTestRules = 
    RuleChain.outerRule(new SystemPropertiesRestoreRule());
{code}
                  
> LuceneTestCase should check for modifications on System properties
> ------------------------------------------------------------------
>
>                 Key: LUCENE-3847
>                 URL: https://issues.apache.org/jira/browse/LUCENE-3847
>             Project: Lucene - Java
>          Issue Type: Improvement
>          Components: general/test
>            Reporter: Dawid Weiss
>            Assignee: Dawid Weiss
>            Priority: Minor
>             Fix For: 3.6, 4.0
>
>
> - fail the test if changes have been detected.
> - revert the state of system properties before the suite.
> - cleanup after the suite.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org