Skip to content

HDDS-12524. Reuse TestDataUtil.createKey in more tests #8270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 16, 2025
Merged
Prev Previous commit
Next Next commit
Fixed tests
  • Loading branch information
chiacyu committed Apr 11, 2025
commit ed0331143d45bc33365fcd16ecac129c74a48f3b
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -112,6 +113,7 @@
import org.apache.hadoop.ozone.client.OzoneKeyDetails;
import org.apache.hadoop.ozone.client.OzoneVolume;
import org.apache.hadoop.ozone.client.VolumeArgs;
import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
import org.apache.hadoop.ozone.client.protocol.ClientProtocol;
import org.apache.hadoop.ozone.om.OMConfigKeys;
import org.apache.hadoop.ozone.om.OMMetrics;
Expand Down Expand Up @@ -340,8 +342,12 @@ void testListStatusWithIntermediateDirWithECEnabled()
String key = "object-dir/object-name1";

// write some test data into bucket
TestDataUtil.createKey(objectStore.getVolume(volumeName).getBucket(bucketName), key,
new ECReplicationConfig("RS-3-2-1024k"), RandomUtils.nextBytes(1));
try (OzoneOutputStream outputStream = objectStore.getVolume(volumeName).
getBucket(bucketName).createKey(key, 1,
new ECReplicationConfig("RS-3-2-1024k"),
new HashMap<>())) {
outputStream.write(RandomUtils.nextBytes(1));
}

List<String> dirs = Arrays.asList(volumeName, bucketName, "object-dir",
"object-name1");
Expand Down Expand Up @@ -1489,8 +1495,11 @@ void testSymlinkList() throws Exception {

// add key in source bucket
final String key = "object-dir/object-name1";
TestDataUtil.createKey(objectStore.getVolume(volumeName).getBucket(bucketName),
key, RandomUtils.nextBytes(1));
try (OzoneOutputStream outputStream = objectStore.getVolume(srcVolume)
.getBucket(srcBucket)
.createKey(key, 1)) {
outputStream.write(RandomUtils.nextBytes(1));
}
assertEquals(objectStore.getVolume(srcVolume)
.getBucket(srcBucket).getKey(key).getName(), key);

Expand Down Expand Up @@ -1537,8 +1546,11 @@ void testSymlinkPosixDelete() throws Exception {

// add key to srcBucket
final String key = "object-dir/object-name1";
TestDataUtil.createKey(objectStore.getVolume(volumeName).getBucket(bucketName),
key, RandomUtils.nextBytes(1));
try (OzoneOutputStream outputStream = objectStore.getVolume(srcVolume)
.getBucket(srcBucket)
.createKey(key, 1)) {
outputStream.write(RandomUtils.nextBytes(1));
}
assertEquals(objectStore.getVolume(srcVolume)
.getBucket(srcBucket).getKey(key).getName(), key);

Expand Down Expand Up @@ -2219,8 +2231,12 @@ void testCreateAndCheckECFileDiskUsage() throws Exception {
Path bucketPathTest = new Path(volPathTest, bucketName);

// write some test data into bucket
TestDataUtil.createKey(objectStore.getVolume(volumeName).getBucket(bucketName),
key, new ECReplicationConfig("RS-3-2-1024k"), RandomUtils.nextBytes(1));
try (OzoneOutputStream outputStream = objectStore.getVolume(volumeName).
getBucket(bucketName).createKey(key, 1,
new ECReplicationConfig("RS-3-2-1024k"),
new HashMap<>())) {
outputStream.write(RandomUtils.nextBytes(1));
}
// make sure the disk usage matches the expected value
Path filePath = new Path(bucketPathTest, key);
ContentSummary contentSummary = ofs.getContentSummary(filePath);
Expand All @@ -2242,9 +2258,13 @@ void testCreateAndCheckRatisFileDiskUsage() throws Exception {
Path filePathTest = new Path(bucketPathTest, key);

// write some test data into bucket
byte[] bytes = new byte[1];
TestDataUtil.createKey(objectStore.getVolume(volumeName).getBucket(bucketName),
key, RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.THREE), bytes);
try (OzoneOutputStream outputStream = objectStore.getVolume(volumeName).
getBucket(bucketName).createKey(key, 1,
RatisReplicationConfig.getInstance(
HddsProtos.ReplicationFactor.THREE),
new HashMap<>())) {
outputStream.write(RandomUtils.nextBytes(1));
}
// make sure the disk usage matches the expected value
ContentSummary contentSummary = ofs.getContentSummary(filePathTest);
long length = contentSummary.getLength();
Expand Down