You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by "cpugputpu (Jira)" <ji...@apache.org> on 2020/03/02 10:11:00 UTC

[jira] [Updated] (HADOOP-16897) Sort fields in ReflectionUtils.java

     [ https://issues.apache.org/jira/browse/HADOOP-16897?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

cpugputpu updated HADOOP-16897:
-------------------------------
    Description: 
The tests in _org.apache.hadoop.metrics2.impl.TestMetricsSystemImpl#testInitFirstVerifyCallBacks_ and _org.apache.hadoop.metrics2.impl.TestMetricsSystemImpl#testInitFirstVerifyStopInvokedImmediately_ can fail.

java.lang.AssertionError:

Element 0 for metrics expected:<MetricCounterLong{info=MetricsInfoImpl

{name=C1, description=C1 desc}

, value=1}>

but was:<MetricGaugeLong{info=MetricsInfoImpl

{name=G1, description=G1 desc}

, value=2}>

at org.junit.Assert.fail(Assert.java:88)

at org.junit.Assert.failNotEquals(Assert.java:834)

at org.junit.Assert.assertEquals(Assert.java:118)

at org.apache.hadoop.test.MoreAsserts.assertEquals(MoreAsserts.java:60)

at org.apache.hadoop.metrics2.impl.TestMetricsSystemImpl.checkMetricsRecords(TestMetricsSystemImpl.java:439)

at org.apache.hadoop.metrics2.impl.TestMetricsSystemImpl.testInitFirstVerifyCallBacks(TestMetricsSystemImpl.java:178)

 

The root cause of this failure can be analyzed in the following stack trace:

_java.lang.Class.*getDeclaredFields*(Class.java:1916)_
 _org.apache.hadoop.util.ReflectionUtils.getDeclaredFieldsIncludingInherited(ReflectionUtils.java:353)_
 _org.apache.hadoop.metrics2.lib.MetricsSourceBuilder.<init>(MetricsSourceBuilder.java:68)_
 _org.apache.hadoop.metrics2.lib.MetricsAnnotations.newSourceBuilder(MetricsAnnotations.java:43)_
 _org.apache.hadoop.metrics2.impl.MetricsSystemImpl.register(MetricsSystemImpl.java:223)_
 _org.apache.hadoop.metrics2.impl.TestMetricsSystemImpl.testInitFirstVerifyCallBacks(TestMetricsSystemImpl.java:156)_

The specification about getDeclaredFields() says that "the elements in the returned array are not sorted and are not in any particular order". The documentation is here for your reference: [https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getDeclaredFields--]
 And the behaviour might be different for different JVM versions or vendors

 

The fix is to sort the fields returned by getDeclaredFields() so that the non-deterministic behaviour can be eliminated completely. In this way, the test becomes more stable.

 

 

 

 

  was:
The tests in _org.apache.hadoop.metrics2.impl.TestMetricsSystemImpl#testInitFirstVerifyCallBacks_ and _org.apache.hadoop.metrics2.impl.TestMetricsSystemImpl#testInitFirstVerifyStopInvokedImmediately_ can fail.

java.lang.AssertionError:

Element 0 for metrics expected:<MetricCounterLong\{info=MetricsInfoImpl{name=C1, description=C1 desc}, value=1}>

but was:<MetricGaugeLong\{info=MetricsInfoImpl{name=G1, description=G1 desc}, value=2}>

at org.junit.Assert.fail(Assert.java:88)

at org.junit.Assert.failNotEquals(Assert.java:834)

at org.junit.Assert.assertEquals(Assert.java:118)

at org.apache.hadoop.test.MoreAsserts.assertEquals(MoreAsserts.java:60)

at org.apache.hadoop.metrics2.impl.TestMetricsSystemImpl.checkMetricsRecords(TestMetricsSystemImpl.java:439)

at org.apache.hadoop.metrics2.impl.TestMetricsSystemImpl.testInitFirstVerifyCallBacks(TestMetricsSystemImpl.java:178)

 

The root cause of this failure can be analyzed in the following stack trace:

_java.lang.Class.*getDeclaredFields*(Class.java:1916)_
_org.apache.hadoop.util.ReflectionUtils.getDeclaredFieldsIncludingInherited(ReflectionUtils.java:353)_
_org.apache.hadoop.metrics2.lib.MetricsSourceBuilder.<init>(MetricsSourceBuilder.java:68)_
_org.apache.hadoop.metrics2.lib.MetricsAnnotations.newSourceBuilder(MetricsAnnotations.java:43)_
_org.apache.hadoop.metrics2.impl.MetricsSystemImpl.register(MetricsSystemImpl.java:223)_
_org.apache.hadoop.metrics2.impl.TestMetricsSystemImpl.testInitFirstVerifyCallBacks(TestMetricsSystemImpl.java:156)_

The specification about getDeclaredFields() says that "the elements in the returned array are not sorted and are not in any particular order". The documentation is here for your reference: https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getDeclaredFields--
And the behaviour might be different for different JVM versions or vendors

 

The fix is to sort the fields returned by getDeclaredFields() so that the non-deterministic behaviour can be eliminated completely. In this way, the test becomes more stable.

 

 

 

 


> Sort fields in ReflectionUtils.java
> -----------------------------------
>
>                 Key: HADOOP-16897
>                 URL: https://issues.apache.org/jira/browse/HADOOP-16897
>             Project: Hadoop Common
>          Issue Type: Bug
>          Components: util
>            Reporter: cpugputpu
>            Priority: Minor
>
> The tests in _org.apache.hadoop.metrics2.impl.TestMetricsSystemImpl#testInitFirstVerifyCallBacks_ and _org.apache.hadoop.metrics2.impl.TestMetricsSystemImpl#testInitFirstVerifyStopInvokedImmediately_ can fail.
> java.lang.AssertionError:
> Element 0 for metrics expected:<MetricCounterLong{info=MetricsInfoImpl
> {name=C1, description=C1 desc}
> , value=1}>
> but was:<MetricGaugeLong{info=MetricsInfoImpl
> {name=G1, description=G1 desc}
> , value=2}>
> at org.junit.Assert.fail(Assert.java:88)
> at org.junit.Assert.failNotEquals(Assert.java:834)
> at org.junit.Assert.assertEquals(Assert.java:118)
> at org.apache.hadoop.test.MoreAsserts.assertEquals(MoreAsserts.java:60)
> at org.apache.hadoop.metrics2.impl.TestMetricsSystemImpl.checkMetricsRecords(TestMetricsSystemImpl.java:439)
> at org.apache.hadoop.metrics2.impl.TestMetricsSystemImpl.testInitFirstVerifyCallBacks(TestMetricsSystemImpl.java:178)
>  
> The root cause of this failure can be analyzed in the following stack trace:
> _java.lang.Class.*getDeclaredFields*(Class.java:1916)_
>  _org.apache.hadoop.util.ReflectionUtils.getDeclaredFieldsIncludingInherited(ReflectionUtils.java:353)_
>  _org.apache.hadoop.metrics2.lib.MetricsSourceBuilder.<init>(MetricsSourceBuilder.java:68)_
>  _org.apache.hadoop.metrics2.lib.MetricsAnnotations.newSourceBuilder(MetricsAnnotations.java:43)_
>  _org.apache.hadoop.metrics2.impl.MetricsSystemImpl.register(MetricsSystemImpl.java:223)_
>  _org.apache.hadoop.metrics2.impl.TestMetricsSystemImpl.testInitFirstVerifyCallBacks(TestMetricsSystemImpl.java:156)_
> The specification about getDeclaredFields() says that "the elements in the returned array are not sorted and are not in any particular order". The documentation is here for your reference: [https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getDeclaredFields--]
>  And the behaviour might be different for different JVM versions or vendors
>  
> The fix is to sort the fields returned by getDeclaredFields() so that the non-deterministic behaviour can be eliminated completely. In this way, the test becomes more stable.
>  
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org