This is an automated email from the ASF dual-hosted git repository.
domgarguilo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push:
new e17951d423 Use LazySingletons.RANDOM instead of creating new objects
(#6042)
e17951d423 is described below
commit e17951d423f106fe3a51baa531cd586ae1e78c48
Author: Dom G. <[email protected]>
AuthorDate: Thu Jan 8 10:04:59 2026 -0500
Use LazySingletons.RANDOM instead of creating new objects (#6042)
---
.../java/org/apache/accumulo/core/crypto/BlockedIOStreamTest.java | 3 ++-
.../java/org/apache/accumulo/core/file/rfile/AbstractRFileTest.java | 2 --
.../java/org/apache/accumulo/core/file/rfile/FencedRFileTest.java | 3 ++-
.../java/org/apache/accumulo/server/metadata/RootGcCandidates.java | 4 ++--
.../main/java/org/apache/accumulo/test/ScanServerMaxLatencyIT.java | 5 +++--
test/src/main/java/org/apache/accumulo/test/WriteAfterCloseIT.java | 3 ++-
.../main/java/org/apache/accumulo/test/compaction/ErasureCodeIT.java | 3 ++-
7 files changed, 13 insertions(+), 10 deletions(-)
diff --git
a/core/src/test/java/org/apache/accumulo/core/crypto/BlockedIOStreamTest.java
b/core/src/test/java/org/apache/accumulo/core/crypto/BlockedIOStreamTest.java
index 584db67a9e..c4bbc81690 100644
---
a/core/src/test/java/org/apache/accumulo/core/crypto/BlockedIOStreamTest.java
+++
b/core/src/test/java/org/apache/accumulo/core/crypto/BlockedIOStreamTest.java
@@ -19,6 +19,7 @@
package org.apache.accumulo.core.crypto;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.accumulo.core.util.LazySingletons.RANDOM;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -36,7 +37,7 @@ import org.junit.jupiter.api.Test;
public class BlockedIOStreamTest {
- private static final SecureRandom random = new SecureRandom();
+ private static final SecureRandom random = RANDOM.get();
@Test
public void testLargeBlockIO() throws IOException {
diff --git
a/core/src/test/java/org/apache/accumulo/core/file/rfile/AbstractRFileTest.java
b/core/src/test/java/org/apache/accumulo/core/file/rfile/AbstractRFileTest.java
index 7eed43d6db..2eeb2a9500 100644
---
a/core/src/test/java/org/apache/accumulo/core/file/rfile/AbstractRFileTest.java
+++
b/core/src/test/java/org/apache/accumulo/core/file/rfile/AbstractRFileTest.java
@@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.security.SecureRandom;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -70,7 +69,6 @@ import org.apache.hadoop.io.Text;
public abstract class AbstractRFileTest {
- protected static final SecureRandom random = new SecureRandom();
protected static final Collection<ByteSequence> EMPTY_COL_FAMS = List.of();
protected AccumuloConfiguration conf = null;
diff --git
a/core/src/test/java/org/apache/accumulo/core/file/rfile/FencedRFileTest.java
b/core/src/test/java/org/apache/accumulo/core/file/rfile/FencedRFileTest.java
index 574e7c9598..8cd59d8ab6 100644
---
a/core/src/test/java/org/apache/accumulo/core/file/rfile/FencedRFileTest.java
+++
b/core/src/test/java/org/apache/accumulo/core/file/rfile/FencedRFileTest.java
@@ -18,6 +18,7 @@
*/
package org.apache.accumulo.core.file.rfile;
+import static org.apache.accumulo.core.util.LazySingletons.RANDOM;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -487,7 +488,7 @@ public class FencedRFileTest extends AbstractRFileTest {
// test seeking to random location and reading all data from that point
// there was an off by one bug with this in the transient index
for (int i = 0; i < 12; i++) {
- index = random.nextInt(expectedKeys.size());
+ index = RANDOM.get().nextInt(expectedKeys.size());
seek(trfIter, expectedKeys.get(index));
for (; index < expectedKeys.size(); index++) {
assertTrue(trfIter.hasTop());
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/metadata/RootGcCandidates.java
b/server/base/src/main/java/org/apache/accumulo/server/metadata/RootGcCandidates.java
index 4b9fcc7932..7a2a17d08f 100644
---
a/server/base/src/main/java/org/apache/accumulo/server/metadata/RootGcCandidates.java
+++
b/server/base/src/main/java/org/apache/accumulo/server/metadata/RootGcCandidates.java
@@ -20,8 +20,8 @@ package org.apache.accumulo.server.metadata;
import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.accumulo.core.util.LazySingletons.GSON;
+import static org.apache.accumulo.core.util.LazySingletons.RANDOM;
-import java.security.SecureRandom;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
@@ -92,7 +92,7 @@ public class RootGcCandidates {
}
public Stream<GcCandidate> sortedStream() {
- var uidGen = new SecureRandom();
+ var uidGen = RANDOM.get();
return data.candidates.entrySet().stream().flatMap(entry -> {
String parent = entry.getKey();
SortedSet<String> names = entry.getValue();
diff --git
a/test/src/main/java/org/apache/accumulo/test/ScanServerMaxLatencyIT.java
b/test/src/main/java/org/apache/accumulo/test/ScanServerMaxLatencyIT.java
index 2feb238fd2..62d67a99fa 100644
--- a/test/src/main/java/org/apache/accumulo/test/ScanServerMaxLatencyIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/ScanServerMaxLatencyIT.java
@@ -20,6 +20,7 @@ package org.apache.accumulo.test;
import static
org.apache.accumulo.core.client.ScannerBase.ConsistencyLevel.EVENTUAL;
import static
org.apache.accumulo.core.client.ScannerBase.ConsistencyLevel.IMMEDIATE;
+import static org.apache.accumulo.core.util.LazySingletons.RANDOM;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -87,7 +88,7 @@ public class ScanServerMaxLatencyIT extends
ConfigurableMacBase {
// Write to table4 once, this is different than the other tables that
are continually being
// written to. table4 should minor compact 3 seconds after this write.
- writeElapsed(new SecureRandom(), client, table3, timer);
+ writeElapsed(RANDOM.get(), client, table3, timer);
boolean sawDataInTable4 = false;
List<Future<Void>> futures = new ArrayList<>();
@@ -178,7 +179,7 @@ public class ScanServerMaxLatencyIT extends
ConfigurableMacBase {
}
private static Callable<Void> createWriterTask(AccumuloClient client, String
table, Timer timer) {
- SecureRandom random = new SecureRandom();
+ SecureRandom random = RANDOM.get();
return () -> {
try (var writer = client.createBatchWriter(table)) {
while (true) {
diff --git a/test/src/main/java/org/apache/accumulo/test/WriteAfterCloseIT.java
b/test/src/main/java/org/apache/accumulo/test/WriteAfterCloseIT.java
index 194d3b29b4..6d66b26f22 100644
--- a/test/src/main/java/org/apache/accumulo/test/WriteAfterCloseIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/WriteAfterCloseIT.java
@@ -18,6 +18,7 @@
*/
package org.apache.accumulo.test;
+import static org.apache.accumulo.core.util.LazySingletons.RANDOM;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -77,7 +78,7 @@ public class WriteAfterCloseIT extends AccumuloClusterHarness
{
public static class SleepyConstraint implements Constraint {
- private static final SecureRandom rand = new SecureRandom();
+ private static final SecureRandom rand = RANDOM.get();
private static final long SLEEP_TIME = 4000;
diff --git
a/test/src/main/java/org/apache/accumulo/test/compaction/ErasureCodeIT.java
b/test/src/main/java/org/apache/accumulo/test/compaction/ErasureCodeIT.java
index 8699c70278..afc506bdea 100644
--- a/test/src/main/java/org/apache/accumulo/test/compaction/ErasureCodeIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/compaction/ErasureCodeIT.java
@@ -18,6 +18,7 @@
*/
package org.apache.accumulo.test.compaction;
+import static org.apache.accumulo.core.util.LazySingletons.RANDOM;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -130,7 +131,7 @@ public class ErasureCodeIT extends ConfigurableMacBase {
var options2 = Map.of(Property.TABLE_ENABLE_ERASURE_CODES.getKey(),
"disable");
c.tableOperations().create(table3, new
NewTableConfiguration().setProperties(options2));
- SecureRandom random = new SecureRandom();
+ SecureRandom random = RANDOM.get();
try (var writer = c.createMultiTableBatchWriter()) {
byte[] bytes = new byte[50_000];