Skip to content

Commit 09099f7

Browse files
committed
Completely remove Random parameters
1 parent 756ca4e commit 09099f7

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,6 @@ public long getBufferSize() {
11431143
static abstract class TestBase {
11441144
private final long everyN;
11451145

1146-
protected final Random rand = ThreadLocalRandom.current();
11471146
protected final Configuration conf;
11481147
protected final TestOptions opts;
11491148

@@ -1174,14 +1173,15 @@ static abstract class TestBase {
11741173
this.testName = this.getClass().getSimpleName();
11751174
everyN = (long) (opts.totalRows / (opts.totalRows * opts.sampleRate));
11761175
if (options.isValueZipf()) {
1177-
this.zipf = new RandomDistribution.Zipf(this.rand, 1, options.getValueSize(), 1.2);
1176+
this.zipf =
1177+
new RandomDistribution.Zipf(ThreadLocalRandom.current(), 1, options.getValueSize(), 1.2);
11781178
}
11791179
LOG.info("Sampling 1 every " + everyN + " out of " + opts.perClientRunRows + " total rows.");
11801180
}
11811181

1182-
int getValueLength(final Random r) {
1182+
int getValueLength() {
11831183
if (this.opts.isValueRandom()) {
1184-
return r.nextInt(opts.valueSize);
1184+
return ThreadLocalRandom.current().nextInt(opts.valueSize);
11851185
} else if (this.opts.isValueZipf()) {
11861186
return Math.abs(this.zipf.nextInt());
11871187
} else {
@@ -1715,9 +1715,9 @@ boolean testRow(final long i, final long startTime) throws IOException, Interrup
17151715
byte[] familyName = Bytes.toBytes(FAMILY_NAME_BASE + family);
17161716
for (int column = 0; column < opts.columns; column++) {
17171717
byte[] qualifier = column == 0 ? COLUMN_ZERO : Bytes.toBytes("" + column);
1718-
byte[] value = generateData(this.rand, getValueLength(this.rand));
1718+
byte[] value = generateData(getValueLength());
17191719
if (opts.useTags) {
1720-
byte[] tag = generateData(this.rand, TAG_LENGTH);
1720+
byte[] tag = generateData(TAG_LENGTH);
17211721
Tag[] tags = new Tag[opts.noOfTags];
17221722
for (int n = 0; n < opts.noOfTags; n++) {
17231723
Tag t = new ArrayBackedTag((byte) n, tag);
@@ -2368,9 +2368,9 @@ boolean testRow(final long i, final long startTime) throws IOException {
23682368
byte familyName[] = Bytes.toBytes(FAMILY_NAME_BASE + family);
23692369
for (int column = 0; column < opts.columns; column++) {
23702370
byte[] qualifier = column == 0 ? COLUMN_ZERO : Bytes.toBytes("" + column);
2371-
byte[] value = generateData(this.rand, getValueLength(this.rand));
2371+
byte[] value = generateData(getValueLength());
23722372
if (opts.useTags) {
2373-
byte[] tag = generateData(this.rand, TAG_LENGTH);
2373+
byte[] tag = generateData(TAG_LENGTH);
23742374
Tag[] tags = new Tag[opts.noOfTags];
23752375
for (int n = 0; n < opts.noOfTags; n++) {
23762376
Tag t = new ArrayBackedTag((byte) n, tag);
@@ -2453,7 +2453,7 @@ boolean testRow(final long i, final long startTime) throws IOException {
24532453

24542454
// write the serverName columns
24552455
MetaTableAccessor.updateRegionLocation(connection, regionInfo,
2456-
ServerName.valueOf("localhost", 60010, rand.nextLong()), i,
2456+
ServerName.valueOf("localhost", 60010, ThreadLocalRandom.current().nextLong()), i,
24572457
EnvironmentEdgeManager.currentTime());
24582458
return true;
24592459
}
@@ -2472,7 +2472,7 @@ static class FilteredScanTest extends TableTest {
24722472

24732473
@Override
24742474
boolean testRow(long i, final long startTime) throws IOException {
2475-
byte[] value = generateData(this.rand, getValueLength(this.rand));
2475+
byte[] value = generateData(getValueLength());
24762476
Scan scan = constructScan(value);
24772477
ResultScanner scanner = null;
24782478
try {
@@ -2548,10 +2548,11 @@ public static byte[] format(final long number) {
25482548
* test, generation of the key and value consumes about 30% of CPU time.
25492549
* @return Generated random value to insert into a table cell.
25502550
*/
2551-
public static byte[] generateData(final Random r, int length) {
2551+
public static byte[] generateData(int length) {
25522552
byte[] b = new byte[length];
25532553
int i;
25542554

2555+
Random r = ThreadLocalRandom.current();
25552556
for (i = 0; i < (length - 8); i += 8) {
25562557
b[i] = (byte) (65 + r.nextInt(26));
25572558
b[i + 1] = b[i];

hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/TestPerformanceEvaluation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public void testZipfian() throws NoSuchMethodException, SecurityException, Insta
181181
ctor.setAccessible(true);
182182
Histogram histogram = (Histogram) ctor.newInstance(new UniformReservoir(1024 * 500));
183183
for (int i = 0; i < 100; i++) {
184-
histogram.update(rrt.getValueLength(null));
184+
histogram.update(rrt.getValueLength());
185185
}
186186
Snapshot snapshot = histogram.getSnapshot();
187187
double stddev = snapshot.getStdDev();

hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestCellBasedHFileOutputFormat2.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,23 +506,19 @@ public void testJobConfiguration() throws Exception {
506506
}
507507

508508
private byte[][] generateRandomStartKeys(int numKeys) {
509-
Random random = new Random();
510509
byte[][] ret = new byte[numKeys][];
511510
// first region start key is always empty
512511
ret[0] = HConstants.EMPTY_BYTE_ARRAY;
513512
for (int i = 1; i < numKeys; i++) {
514-
ret[i] =
515-
PerformanceEvaluation.generateData(random, PerformanceEvaluation.DEFAULT_VALUE_LENGTH);
513+
ret[i] = PerformanceEvaluation.generateData(PerformanceEvaluation.DEFAULT_VALUE_LENGTH);
516514
}
517515
return ret;
518516
}
519517

520518
private byte[][] generateRandomSplitKeys(int numKeys) {
521-
Random random = new Random();
522519
byte[][] ret = new byte[numKeys][];
523520
for (int i = 0; i < numKeys; i++) {
524-
ret[i] =
525-
PerformanceEvaluation.generateData(random, PerformanceEvaluation.DEFAULT_VALUE_LENGTH);
521+
ret[i] = PerformanceEvaluation.generateData(PerformanceEvaluation.DEFAULT_VALUE_LENGTH);
526522
}
527523
return ret;
528524
}

hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat2.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@
3434
import java.util.List;
3535
import java.util.Map;
3636
import java.util.Map.Entry;
37-
import java.util.Random;
3837
import java.util.Set;
3938
import java.util.UUID;
4039
import java.util.concurrent.Callable;
4140
import java.util.concurrent.ConcurrentHashMap;
4241
import java.util.concurrent.CopyOnWriteArrayList;
4342
import java.util.concurrent.ExecutorService;
44-
import java.util.concurrent.ThreadLocalRandom;
4543
import java.util.stream.Collectors;
4644
import java.util.stream.Stream;
4745
import org.apache.hadoop.conf.Configuration;
@@ -543,23 +541,19 @@ public void testJobConfiguration() throws Exception {
543541
}
544542

545543
private byte[][] generateRandomStartKeys(int numKeys) {
546-
Random random = ThreadLocalRandom.current();
547544
byte[][] ret = new byte[numKeys][];
548545
// first region start key is always empty
549546
ret[0] = HConstants.EMPTY_BYTE_ARRAY;
550547
for (int i = 1; i < numKeys; i++) {
551-
ret[i] =
552-
PerformanceEvaluation.generateData(random, PerformanceEvaluation.DEFAULT_VALUE_LENGTH);
548+
ret[i] = PerformanceEvaluation.generateData(PerformanceEvaluation.DEFAULT_VALUE_LENGTH);
553549
}
554550
return ret;
555551
}
556552

557553
private byte[][] generateRandomSplitKeys(int numKeys) {
558-
Random random = ThreadLocalRandom.current();
559554
byte[][] ret = new byte[numKeys][];
560555
for (int i = 0; i < numKeys; i++) {
561-
ret[i] =
562-
PerformanceEvaluation.generateData(random, PerformanceEvaluation.DEFAULT_VALUE_LENGTH);
556+
ret[i] = PerformanceEvaluation.generateData(PerformanceEvaluation.DEFAULT_VALUE_LENGTH);
563557
}
564558
return ret;
565559
}

0 commit comments

Comments
 (0)