HADOOP-18429. fix infinite loop in MutableGaugeFloat#incr(float) (#4823)
This commit is contained in:
parent
eccd2d0492
commit
7d39abd799
|
@ -69,7 +69,7 @@ public class MutableGaugeFloat extends MutableGauge {
|
|||
|
||||
private void incr(float delta) {
|
||||
while (true) {
|
||||
float current = value.get();
|
||||
float current = Float.intBitsToFloat(value.get());
|
||||
float next = current + delta;
|
||||
if (compareAndSet(current, next)) {
|
||||
setChanged();
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.metrics2.lib;
|
||||
|
||||
import static org.apache.hadoop.metrics2.impl.MsInfo.Context;
|
||||
import static org.apache.hadoop.metrics2.lib.Interns.info;
|
||||
import static org.apache.hadoop.test.MetricsAsserts.*;
|
||||
import static org.mockito.AdditionalMatchers.eq;
|
||||
|
@ -500,4 +501,15 @@ public class TestMutableMetrics {
|
|||
verify(mb, times(2)).addGauge(
|
||||
info("FooNumOps", "Number of ops for stat with 5s interval"), (long) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@link MutableGaugeFloat#incr()}.
|
||||
*/
|
||||
@Test(timeout = 30000)
|
||||
public void testMutableGaugeFloat() {
|
||||
MutableGaugeFloat mgf = new MutableGaugeFloat(Context, 3.2f);
|
||||
assertEquals(3.2f, mgf.value(), 0.0);
|
||||
mgf.incr();
|
||||
assertEquals(4.2f, mgf.value(), 0.0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue