Skip to content

Commit b58e617

Browse files
author
Ravindra Dingankar
committed
more review comments
1 parent 51be61b commit b58e617

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/util/TestSampleQuantiles.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ public class TestSampleQuantiles {
3737
new Quantile(0.95, 0.005), new Quantile(0.99, 0.001) };
3838

3939
SampleQuantiles estimator;
40+
Random rnd = new Random(0xDEADDEAD);
41+
final static int NUM_REPEATS = 10;
4042

41-
@Before
43+
@Before
4244
public void init() {
4345
estimator = new SampleQuantiles(quantiles);
4446
}
@@ -92,22 +94,21 @@ public void testClear() throws IOException {
9294
@Test
9395
public void testQuantileError() throws IOException {
9496
final int count = 100000;
95-
Random r = new Random(0xDEADDEAD);
9697
int[] values = new int[count];
9798
for (int i = 0; i < count; i++) {
9899
values[i] = i + 1;
99100
}
100101

101-
// Do 10 shuffle/insert/check cycles
102-
for (int i = 0; i < 10; i++) {
102+
// Repeat shuffle/insert/check cycles 10 times
103+
for (int i = 0; i < NUM_REPEATS; i++) {
103104

104105
// Shuffle
105-
Collections.shuffle(Arrays.asList(values), r);
106+
Collections.shuffle(Arrays.asList(values), rnd);
106107
estimator.clear();
107108

108109
// Insert
109-
for (int j = 0; j < count; j++) {
110-
estimator.insert(values[j]);
110+
for (int value : values) {
111+
estimator.insert(value);
111112
}
112113
Map<Quantile, Long> snapshot;
113114
snapshot = estimator.snapshot();
@@ -131,21 +132,20 @@ public void testQuantileError() throws IOException {
131132
public void testInverseQuantiles() throws IOException {
132133
SampleQuantiles inverseQuantilesEstimator = new SampleQuantiles(MutableInverseQuantiles.INVERSE_QUANTILES);
133134
final int count = 100000;
134-
Random r = new Random(0xDEADDEAD);
135135
int[] values = new int[count];
136136
for (int i = 0; i < count; i++) {
137137
values[i] = i + 1;
138138
}
139139

140-
// Do 10 shuffle/insert/check cycles
141-
for (int i = 0; i < 10; i++) {
140+
// Repeat shuffle/insert/check cycles 10 times
141+
for (int i = 0; i < NUM_REPEATS; i++) {
142142
// Shuffle
143-
Collections.shuffle(Arrays.asList(values), r);
143+
Collections.shuffle(Arrays.asList(values), rnd);
144144
inverseQuantilesEstimator.clear();
145145

146146
// Insert
147-
for (int j = 0; j < count; j++) {
148-
inverseQuantilesEstimator.insert(values[j]);
147+
for (int value : values) {
148+
inverseQuantilesEstimator.insert(value);
149149
}
150150
Map<Quantile, Long> snapshot;
151151
snapshot = inverseQuantilesEstimator.snapshot();

0 commit comments

Comments
 (0)