MAPREDUCE-3595. Add missing TestCounters#testCounterValue test from branch 1 to 0.23 (Contributed by Tom White)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1227380 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f445eb31f1
commit
be285fc27f
@ -398,6 +398,9 @@ Release 0.23.1 - Unreleased
|
|||||||
MAPREDUCE-3529. TokenCache does not cache viewfs credentials correctly
|
MAPREDUCE-3529. TokenCache does not cache viewfs credentials correctly
|
||||||
(sseth)
|
(sseth)
|
||||||
|
|
||||||
|
MAPREDUCE-3595. Add missing TestCounters#testCounterValue test from branch
|
||||||
|
1 to 0.23 (Tom White via sseth)
|
||||||
|
|
||||||
Release 0.23.0 - 2011-11-01
|
Release 0.23.0 - 2011-11-01
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import org.apache.hadoop.mapred.Counters.Counter;
|
import org.apache.hadoop.mapred.Counters.Counter;
|
||||||
import org.apache.hadoop.mapreduce.FileSystemCounter;
|
import org.apache.hadoop.mapreduce.FileSystemCounter;
|
||||||
@ -98,6 +99,37 @@ public void testCounters() throws IOException {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify counter value works
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Test
|
||||||
|
public void testCounterValue() {
|
||||||
|
Counters counters = new Counters();
|
||||||
|
final int NUMBER_TESTS = 100;
|
||||||
|
final int NUMBER_INC = 10;
|
||||||
|
final Random rand = new Random();
|
||||||
|
for (int i = 0; i < NUMBER_TESTS; i++) {
|
||||||
|
long initValue = rand.nextInt();
|
||||||
|
long expectedValue = initValue;
|
||||||
|
Counter counter = counters.findCounter("foo", "bar");
|
||||||
|
counter.setValue(initValue);
|
||||||
|
assertEquals("Counter value is not initialized correctly",
|
||||||
|
expectedValue, counter.getValue());
|
||||||
|
for (int j = 0; j < NUMBER_INC; j++) {
|
||||||
|
int incValue = rand.nextInt();
|
||||||
|
counter.increment(incValue);
|
||||||
|
expectedValue += incValue;
|
||||||
|
assertEquals("Counter value is not incremented correctly",
|
||||||
|
expectedValue, counter.getValue());
|
||||||
|
}
|
||||||
|
expectedValue = rand.nextInt();
|
||||||
|
counter.setValue(expectedValue);
|
||||||
|
assertEquals("Counter value is not set correctly",
|
||||||
|
expectedValue, counter.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Test
|
@Test
|
||||||
public void testLegacyNames() {
|
public void testLegacyNames() {
|
||||||
|
Loading…
Reference in New Issue
Block a user