ASF GitHub Bot commented on METRON-1299:

GitHub user ottobackwards opened a pull request:


    METRON-1299 In MetronError tests, don't test for HostName if getHostName 
wouldn't work

    MetronError ignores exceptions from 
InetAddress.getLocalHost().getHostName() and leaves the field unset.
    The unit test however assumes it would be set, and someone has logged a 
jira on this, since it makes the build fail.
    Changed the test so that it only verifies the hostName if it would have 
    ### Testing
    - Code review
    - Tests Pass
    > no non-test changes in pr
     private void addHostname(JSONObject errorMessage) {
        try {
        } catch (UnknownHostException ex) {
          // Leave the hostname field off if it cannot be found
    ### For all changes:
    - [x] Is there a JIRA ticket associated with this PR? If not one needs to 
be created at [Metron 
    - [x] Does your PR title start with METRON-XXXX where XXXX is the JIRA 
number you are trying to resolve? Pay particular attention to the hyphen "-" 
    - [x] Has your PR been rebased against the latest commit within the target 
branch (typically master)?

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ottobackwards/metron error_addHost

Alternatively you can review and apply these changes as the patch at:


To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #924
commit cee3acba914f97ca7d2faf6e7822c97928a4e242
Author: Otto Fowler <ottobackwards@...>
Date:   2018-02-02T21:57:47Z

    do not test for hostName if calling hostName throws, since it will be null


> MetronError tests fail if hostname isn't set
> --------------------------------------------
>                 Key: METRON-1299
>                 URL: https://issues.apache.org/jira/browse/METRON-1299
>             Project: Metron
>          Issue Type: Bug
>    Affects Versions: 0.4.1
>         Environment: openSUSE Tumbleweed 20171102, OpenJDK 1.8.0_144
>            Reporter: Stuart Bertram
>            Assignee: Otto Fowler
>            Priority: Major
> If I run "mvn package" in the root Metron directory then compilation fails 
> because of a null reference in  
> {{./metron-platform/metron-common/src/test/java/org/apache/metron/common/error/MetronErrorTest.java}}.
>  This happens in {{getJSONObjectShouldReturnBasicInformation}} on line 56 
> because  {{errorJSON.get(Constants.ErrorFields.HOSTNAME.getName())}} is 
> assumed to return a string and the {{length()}} method is called on it. 
> Because the assert doesn't use a message then no obvious reason why it fails 
> is logged.
> The underlying problem is that 
> {{metron-platform/metron-common/src/main/java/org/apache/metron/common/error/MetronError.java}}
>  falls through to a {{catch}} block in {{addHostname()}} when 
> {{netAddress.getLocalHost().getHostName()}} exceptions with {{Name or service 
> not known}} for the host name.
> Setting a hostname that resolves is a build requirement that is out of 
> Metron's control, but if the code specifically handles the fact that it won't 
> always be retrieved then it seems problematic to have tests that assume it 
> works _and_ not make it clear what the failure is when it occurs.

This message was sent by Atlassian JIRA

Reply via email to