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 @@ -18,6 +18,9 @@
package org.apache.ozone.test;

import java.lang.reflect.Method;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInfo;

Expand All @@ -27,6 +30,7 @@
*/
public abstract class OzoneTestBase {

private static final AtomicInteger OBJECT_COUNTER = new AtomicInteger();
private TestInfo info;

@BeforeEach
Expand All @@ -40,4 +44,16 @@ protected String getTestName() {
.orElse("unknown");
}

/** @return unique lowercase name of maximum 60 characters, including (some of) the current test's name */
protected String uniqueObjectName() {
return uniqueObjectName(getTestName());
}

/** @return unique lowercase name of maximum 60 characters, including (some of) {@code prefix} */
public static String uniqueObjectName(String prefix) {
return Objects.requireNonNull(prefix, "prefix == null")
.substring(0, Math.min(prefix.length(), 50))
.toLowerCase(Locale.ROOT)
+ String.format("%010d", OBJECT_COUNTER.getAndIncrement());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -1424,16 +1423,16 @@ private String getBucketName() {
return getBucketName("");
}

private String getBucketName(String suffix) {
return ("v1-" + getTestName() + "bucket" + suffix).toLowerCase(Locale.ROOT);
private String getBucketName(String ignored) {
return uniqueObjectName();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have "v1-" / "v2-" prefixes still ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I don't really know about the difference between v1 and v2.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v1/v2 prefix was added in HDDS-14191 only to make the names unique across the two tests.

}

private String getKeyName() {
return getKeyName("");
}

private String getKeyName(String suffix) {
return (getTestName() + "key" + suffix).toLowerCase(Locale.ROOT);
private String getKeyName(String ignored) {
return uniqueObjectName();
}

private String multipartUpload(String bucketName, String key, File file, long partSize, String contentType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import javax.xml.bind.DatatypeConverter;
Expand Down Expand Up @@ -1066,16 +1065,16 @@ private String getBucketName() {
return getBucketName("");
}

private String getBucketName(String suffix) {
return ("v2-" + getTestName() + "bucket" + suffix).toLowerCase(Locale.ROOT);
private String getBucketName(String ignored) {
return uniqueObjectName();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

}

private String getKeyName() {
return getKeyName("");
}

private String getKeyName(String suffix) {
return (getTestName() + "key" + suffix).toLowerCase(Locale.ROOT);
private String getKeyName(String ignored) {
return uniqueObjectName();
}

private String multipartUpload(String bucketName, String key, File file, int partSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import java.util.LinkedList;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.fs.FSDataInputStream;
Expand Down Expand Up @@ -96,8 +95,6 @@
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class TestLeaseRecovery extends OzoneTestBase {

private static final AtomicInteger FILE_COUNTER = new AtomicInteger();

private MiniOzoneCluster cluster;

private OzoneClient client;
Expand Down Expand Up @@ -176,7 +173,7 @@ public void init() throws IOException, InterruptedException,

@BeforeEach
void beforeEach() throws Exception {
file = new Path(dir, "file-" + getTestName() + "-" + FILE_COUNTER.incrementAndGet());
file = new Path(dir, uniqueObjectName());
fs = (RootedOzoneFileSystem) FileSystem.get(conf);
}

Expand Down Expand Up @@ -266,7 +263,7 @@ public void testOBSRecoveryShouldFail() throws Exception {
OzoneBucket obsBucket = TestDataUtil.createVolumeAndBucket(client,
"vol2", "obs", BucketLayout.OBJECT_STORE);
String obsDir = OZONE_ROOT + obsBucket.getVolumeName() + OZONE_URI_DELIMITER + obsBucket.getName();
Path obsFile = new Path(obsDir, "file" + getTestName() + FILE_COUNTER.incrementAndGet());
Path obsFile = new Path(obsDir, uniqueObjectName());

assertThrows(IllegalArgumentException.class, () -> fs.recoverLease(obsFile));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void cleanup() throws Exception {
}

public String volumeName() {
return getTestName().toLowerCase();
return uniqueObjectName();
}

private void createSampleVol(String volume) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1389,8 +1389,4 @@ private long countBlocksPendingDeletion() {
throw new UncheckedIOException(e);
}
}

private static String uniqueObjectName(String prefix) {
return prefix + String.format("%010d", OBJECT_COUNTER.getAndIncrement());
}
}