Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void testSeek() throws Exception {

// Seek to random positions between 0 and the block size.
for (int i = 0; i < 10; i++) {
pos = RandomUtils.nextInt(0, blockSize);
pos = RandomUtils.secure().randomInt(0, blockSize);
seekAndVerify(pos);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
class TestBlockOutputStreamCorrectness {

private static final int DATA_SIZE = 256 * (int) OzoneConsts.MB;
private static final byte[] DATA = RandomUtils.nextBytes(DATA_SIZE);
private static final byte[] DATA = RandomUtils.secure().randomBytes(DATA_SIZE);

@ParameterizedTest
@ValueSource(ints = { 1, 1024, 1024 * 1024 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public void testSeekToPartialOffsetFails() {
}

private Integer getRandomStreamIndex(Set<Integer> set) {
return set.stream().skip(RandomUtils.nextInt(0, set.size()))
return set.stream().skip(RandomUtils.secure().randomInt(0, set.size()))
.findFirst().orElse(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public static ContainerCommandResponseProto getEchoResponse(
ContainerProtos.EchoResponseProto.Builder echo =
ContainerProtos.EchoResponseProto
.newBuilder()
.setPayload(UnsafeByteOperations.unsafeWrap(RandomUtils.nextBytes(responsePayload)));
.setPayload(UnsafeByteOperations.unsafeWrap(RandomUtils.secure().randomBytes(responsePayload)));

return getSuccessResponseBuilder(msg)
.setEcho(echo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ void testCorrectness() {

final int len = 1 << 10;
for (int i = 0; i < 1000; i++) {
checkBytes(RandomUtils.nextBytes(len), RandomUtils.nextInt(0, len));
checkBytes(RandomUtils.secure().randomBytes(len),
RandomUtils.secure().randomInt(0, len));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class TestChecksumImplsComputeSameValues {
@Test
public void testCRC32ImplsMatch() {
data.clear();
data.put(RandomUtils.nextBytes(data.remaining()));
data.put(RandomUtils.secure().randomBytes(data.remaining()));
for (int bpc : bytesPerChecksum) {
List<ChecksumByteBuffer> impls = new ArrayList<>();
impls.add(new PureJavaCrc32ByteBuffer());
Expand All @@ -58,7 +58,7 @@ public void testCRC32ImplsMatch() {
@Test
public void testCRC32CImplsMatch() {
data.clear();
data.put(RandomUtils.nextBytes(data.remaining()));
data.put(RandomUtils.secure().randomBytes(data.remaining()));
for (int bpc : bytesPerChecksum) {
List<ChecksumByteBuffer> impls = new ArrayList<>();
impls.add(new PureJavaCrc32CByteBuffer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ protected long getReportFrequency() {
return containerReportInterval + getRandomReportDelay();
}

@SuppressWarnings("java:S2245") // no need for secure random
private long getRandomReportDelay() {
return RandomUtils.nextLong(0, containerReportInterval);
return RandomUtils.secure().randomLong(0, containerReportInterval);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ protected long getReportFrequency() {
return pipelineReportInterval + getRandomReportDelay();
}

@SuppressWarnings("java:S2245") // no need for secure random
private long getRandomReportDelay() {
return RandomUtils.nextLong(0, pipelineReportInterval);
return RandomUtils.secure().randomLong(0, pipelineReportInterval);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void testTopNOrderedChoosingPolicy(ContainerLayoutVersion layout)
List<Integer> numberOfBlocks = new ArrayList<Integer>();
// create [numContainers + 1] containers
for (int i = 0; i <= numContainers; i++) {
long containerId = RandomUtils.nextLong();
long containerId = RandomUtils.secure().randomLong();
KeyValueContainerData data =
new KeyValueContainerData(containerId,
layout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ static ChecksumData checksum(ByteString data) {
private ContainerCommandRequestProto getWriteChunkRequest0(
String datanodeId, Long containerId, Long localId, int chunkNum) {
final int lenOfBytes = 32;
ByteString chunkData = ByteString.copyFrom(RandomUtils.nextBytes(32));
ByteString chunkData = ByteString.copyFrom(RandomUtils.secure().randomBytes(32));

ContainerProtos.ChunkInfo chunk = ContainerProtos.ChunkInfo
.newBuilder()
Expand Down Expand Up @@ -638,7 +638,7 @@ private ContainerCommandRequestProto getWriteChunkRequest0(
}

static ContainerCommandRequestProto newPutSmallFile(Long containerId, Long localId) {
ByteString chunkData = ByteString.copyFrom(RandomUtils.nextBytes(32));
ByteString chunkData = ByteString.copyFrom(RandomUtils.secure().randomBytes(32));
return newPutSmallFile(new BlockID(containerId, localId), chunkData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void onNext(SendContainerRequest value) {

// WHEN
OutputStream out = startUpload(subject, callback);
out.write(RandomUtils.nextBytes(4));
out.write(RandomUtils.secure().randomBytes(4));
out.close();

// THEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private static long missingInitialValue() {
}

private static long validInitialValue() {
return RandomUtils.nextLong(1, 100);
return RandomUtils.secure().randomLong(1, 100);
}

private static Builder paramsBuilder(AtomicLong savedValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class TestManagedSecretKey {
@Test
public void testSignAndVerifySuccess() throws Exception {
// Data can be signed and verified by same key.
byte[] data = RandomUtils.nextBytes(100);
byte[] data = RandomUtils.secure().randomBytes(100);
ManagedSecretKey secretKey = generateHmac(now(), ofDays(1));
byte[] signature = secretKey.sign(data);
assertTrue(secretKey.isValidSignature(data, signature));
Expand All @@ -62,10 +62,10 @@ public void testSignAndVerifySuccess() throws Exception {

@Test
public void testVerifyFailure() throws Exception {
byte[] data = RandomUtils.nextBytes(100);
byte[] data = RandomUtils.secure().randomBytes(100);
ManagedSecretKey secretKey = generateHmac(now(), ofDays(1));
// random signature is not valid.
assertFalse(secretKey.isValidSignature(data, RandomUtils.nextBytes(100)));
assertFalse(secretKey.isValidSignature(data, RandomUtils.secure().randomBytes(100)));

// Data sign by one key can't be verified by another key.
byte[] signature = secretKey.sign(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testSignToken() {

// Verify an invalid signed OzoneMaster Token with Ozone Master.
assertFalse(secretKey.isValidSignature(tokenId.getBytes(),
RandomUtils.nextBytes(128)));
RandomUtils.secure().randomBytes(128)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public void setup() {
@Test
public void testMetrics() {
// crate mock metrics
int threadCount = RandomUtils.nextInt();
int maxThreadCount = RandomUtils.nextInt();
int idleThreadCount = RandomUtils.nextInt();
int threadQueueWaitingTaskCount = RandomUtils.nextInt();
int threadCount = RandomUtils.secure().randomInt();
int maxThreadCount = RandomUtils.secure().randomInt();
int idleThreadCount = RandomUtils.secure().randomInt();
int threadQueueWaitingTaskCount = RandomUtils.secure().randomInt();
String name = "s3g";

when(threadPool.getThreads()).thenReturn(threadCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ public static StorageContainerManager getScm(OzoneConfiguration conf,
private static ContainerInfo.Builder getDefaultContainerInfoBuilder(
final HddsProtos.LifeCycleState state) {
return new ContainerInfo.Builder()
.setContainerID(RandomUtils.nextLong())
.setContainerID(RandomUtils.secure().randomLong())
.setReplicationConfig(
RatisReplicationConfig
.getInstance(ReplicationFactor.THREE))
Expand Down Expand Up @@ -816,7 +816,7 @@ public static List<ContainerInfo> getContainerInfo(int numContainers) {
for (int i = 0; i < numContainers; i++) {
ContainerInfo.Builder builder = new ContainerInfo.Builder();
containerInfoList.add(builder
.setContainerID(RandomUtils.nextLong())
.setContainerID(RandomUtils.secure().randomLong())
.setReplicationConfig(ratisReplicationConfig)
.build());
}
Expand All @@ -837,7 +837,7 @@ public static List<ContainerInfo> getECContainerInfo(int numContainers, int data
for (int i = 0; i < numContainers; i++) {
ContainerInfo.Builder builder = new ContainerInfo.Builder();
containerInfoList.add(builder
.setContainerID(RandomUtils.nextLong())
.setContainerID(RandomUtils.secure().randomLong())
.setOwner("test-owner")
.setPipelineID(PipelineID.randomId())
.setReplicationConfig(eCReplicationConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ private Map<Long, List<Long>> generateData(int dataSize) throws IOException {
private Map<Long, List<Long>> generateData(int dataSize,
HddsProtos.LifeCycleState state) throws IOException {
Map<Long, List<Long>> blockMap = new HashMap<>();
int continerIDBase = RandomUtils.nextInt(0, 100);
int localIDBase = RandomUtils.nextInt(0, 1000);
int continerIDBase = RandomUtils.secure().randomInt(0, 100);
int localIDBase = RandomUtils.secure().randomInt(0, 1000);
for (int i = 0; i < dataSize; i++) {
long containerID = continerIDBase + i;
updateContainerMetadata(containerID, state);
Expand Down Expand Up @@ -752,7 +752,7 @@ public void testRandomOperateTransactions() throws Exception {
List<Long> txIDs;
// Randomly add/get/commit/increase transactions.
for (int i = 0; i < 100; i++) {
int state = RandomUtils.nextInt(0, 4);
int state = RandomUtils.secure().randomInt(0, 4);
if (state == 0) {
addTransactions(generateData(10), true);
added += 10;
Expand Down Expand Up @@ -851,7 +851,7 @@ public void testDeletedBlockTransactions()
// add two transactions for same container
containerID = blocks.get(0).getContainerID();
Map<Long, List<Long>> deletedBlocksMap = new HashMap<>();
long localId = RandomUtils.nextLong();
long localId = RandomUtils.secure().randomLong();
deletedBlocksMap.put(containerID, new LinkedList<>(
Collections.singletonList(localId)));
addTransactions(deletedBlocksMap, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ public void testOutOfServiceNodesNotSelected(int datanodeCount) {

for (int i = 0; i < 10; i++) {
// Set a random DN to in_service and ensure it is always picked
int index = RandomUtils.nextInt(0, dnInfos.size());
int index = RandomUtils.secure().randomInt(0, dnInfos.size());
dnInfos.get(index).setNodeStatus(NodeStatus.inServiceHealthy());
try {
List<DatanodeDetails> datanodeDetails =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class TestReplicatedBlockChecksumComputer {
@Test
public void testComputeMd5Crc() throws IOException {
final int lenOfBytes = 32;
byte[] randomChunkChecksum = RandomUtils.nextBytes(lenOfBytes);
byte[] randomChunkChecksum = RandomUtils.secure().randomBytes(lenOfBytes);

MD5Hash emptyBlockMD5 = MD5Hash.digest(randomChunkChecksum);
byte[] emptyBlockMD5Hash = emptyBlockMD5.getDigest();
Expand All @@ -54,7 +54,7 @@ public void testComputeMd5Crc() throws IOException {
@Test
public void testComputeCompositeCrc() throws IOException {
final int lenOfBytes = 32;
byte[] randomChunkChecksum = RandomUtils.nextBytes(lenOfBytes);
byte[] randomChunkChecksum = RandomUtils.secure().randomBytes(lenOfBytes);

CrcComposer crcComposer =
CrcComposer.newCrcComposer(DataChecksum.Type.CRC32C, 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,12 @@ public boolean shouldStopOm() {
if (failedOmSet.size() >= numOzoneManagers / 2) {
return false;
}
return RandomUtils.nextBoolean();
return RandomUtils.secure().randomBoolean();
}

// Datanode specific
private int getNumberOfDnToFail() {
return RandomUtils.nextBoolean() ? 1 : 2;
return RandomUtils.secure().randomBoolean() ? 1 : 2;
}

public Set<DatanodeDetails> dnToFail() {
Expand Down Expand Up @@ -395,7 +395,7 @@ public boolean shouldStopScm() {
if (failedScmSet.size() >= numStorageContainerManagers / 2) {
return false;
}
return RandomUtils.nextBoolean();
return RandomUtils.secure().randomBoolean();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public void stop() throws Exception {
}

public static boolean isFastRestart() {
return RandomUtils.nextBoolean();
return RandomUtils.secure().randomBoolean();
}

public static int getBoundedRandomIndex(int size) {
return RandomUtils.nextInt(0, size);
return RandomUtils.secure().randomInt(0, size);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public AgedDirLoadGenerator(DataBuffer dataBuffer, LoadBucket fsBucket) {

@Override
public void generateLoad() throws Exception {
int index = RandomUtils.nextInt(0, maxDirIndex);
int index = RandomUtils.secure().randomInt(0, maxDirIndex);
String keyName = getKeyName(index);
fsBucket.readDirectory(keyName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public AgedLoadGenerator(DataBuffer data, LoadBucket agedLoadBucket) {

@Override
public void generateLoad() throws Exception {
if (RandomUtils.nextInt(0, 100) <= 10) {
if (RandomUtils.secure().randomInt(0, 100) <= 10) {
synchronized (agedFileAllocationIndex) {
int index = agedFileAllocationIndex.getAndIncrement();
ByteBuffer buffer = dataBuffer.getBuffer(index);
Expand All @@ -66,7 +66,7 @@ public void generateLoad() throws Exception {
private Optional<Integer> randomKeyToRead() {
int currentIndex = agedFileWrittenIndex.get();
return currentIndex != 0
? Optional.of(RandomUtils.nextInt(0, currentIndex))
? Optional.of(RandomUtils.secure().randomInt(0, currentIndex))
: Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public DataBuffer(int numBuffers) {
for (int i = 0; i < numBuffers; i++) {
int size = (int) StorageUnit.KB.toBytes(1 << i);
ByteBuffer buffer = ByteBuffer.allocate(size);
buffer.put(RandomUtils.nextBytes(size));
buffer.put(RandomUtils.secure().randomBytes(size));
this.buffers.add(buffer);
}
// TODO: add buffers of sizes of prime numbers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public FilesystemLoadGenerator(DataBuffer dataBuffer, LoadBucket fsBucket) {

@Override
public void generateLoad() throws Exception {
int index = RandomUtils.nextInt();
int index = RandomUtils.secure().randomInt();
ByteBuffer buffer = dataBuffer.getBuffer(index);
String keyName = getKeyName(index);
fsBucket.writeKey(true, buffer, keyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public LoadBucket(OzoneBucket bucket, OzoneConfiguration conf,
}

private boolean isFsOp() {
return RandomUtils.nextBoolean();
return RandomUtils.secure().randomBoolean();
}

// Write ops.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void load(long runTimeMillis) {

while (Time.monotonicNow() - startTime < runTimeMillis) {
LoadGenerator gen =
generators.get(RandomUtils.nextInt(0, numGenerators));
generators.get(RandomUtils.secure().randomInt(0, numGenerators));

try {
gen.generateLoad();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private String createNewPath(int i, String s) {

@Override
public void generateLoad() throws Exception {
int index = RandomUtils.nextInt(0, maxDirDepth);
int index = RandomUtils.secure().randomInt(0, maxDirDepth);
String str = this.pathMap.compute(index, this::createNewPath);
fsBucket.createDirectory(str);
fsBucket.readDirectory(str);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public RandomDirLoadGenerator(DataBuffer dataBuffer, LoadBucket fsBucket) {

@Override
public void generateLoad() throws Exception {
int index = RandomUtils.nextInt();
int index = RandomUtils.secure().randomInt();
String keyName = getKeyName(index);
fsBucket.createDirectory(keyName);
fsBucket.readDirectory(keyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public RandomLoadGenerator(DataBuffer dataBuffer, LoadBucket bucket) {

@Override
public void generateLoad() throws Exception {
int index = RandomUtils.nextInt();
int index = RandomUtils.secure().randomInt();
ByteBuffer buffer = dataBuffer.getBuffer(index);
String keyName = getKeyName(index);
ozoneBucket.writeKey(buffer, keyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ReadOnlyLoadGenerator(DataBuffer dataBuffer, LoadBucket replBucket) {

@Override
public void generateLoad() throws Exception {
int index = RandomUtils.nextInt(0, NUM_KEYS);
int index = RandomUtils.secure().randomInt(0, NUM_KEYS);
ByteBuffer buffer = dataBuffer.getBuffer(index);
String keyName = getKeyName(index);
replBucket.readKey(buffer, keyName);
Expand Down
Loading