HADOOP-18429. fix infinite loop in MutableGaugeFloat#incr(float) (#4823)
This commit is contained in:
parent
eccd2d0492
commit
7d39abd799
@ -69,7 +69,7 @@ private final boolean compareAndSet(float expect, float update) {
|
|||||||
|
|
||||||
private void incr(float delta) {
|
private void incr(float delta) {
|
||||||
while (true) {
|
while (true) {
|
||||||
float current = value.get();
|
float current = Float.intBitsToFloat(value.get());
|
||||||
float next = current + delta;
|
float next = current + delta;
|
||||||
if (compareAndSet(current, next)) {
|
if (compareAndSet(current, next)) {
|
||||||
setChanged();
|
setChanged();
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package org.apache.hadoop.metrics2.lib;
|
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.metrics2.lib.Interns.info;
|
||||||
import static org.apache.hadoop.test.MetricsAsserts.*;
|
import static org.apache.hadoop.test.MetricsAsserts.*;
|
||||||
import static org.mockito.AdditionalMatchers.eq;
|
import static org.mockito.AdditionalMatchers.eq;
|
||||||
@ -500,4 +501,15 @@ public void testMutableQuantilesEmptyRollover() throws Exception {
|
|||||||
verify(mb, times(2)).addGauge(
|
verify(mb, times(2)).addGauge(
|
||||||
info("FooNumOps", "Number of ops for stat with 5s interval"), (long) 0);
|
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
Block a user