Skip to content

Commit

Permalink
HDDS-9680. tiny refactoring - move eTag computer to static variable i…
Browse files Browse the repository at this point in the history
…n tests
  • Loading branch information
Slava Tutrinov committed Nov 27, 2023
1 parent 1f79f6b commit d3e9f8f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private CompleteMultipartUploadRequest.Part uploadPart(String uploadID,

CompleteMultipartUploadRequest.Part
part = new CompleteMultipartUploadRequest.Part();
part.seteTag(response.getHeaderString("ETag"));
part.setETag(response.getHeaderString("ETag"));
part.setPartNumber(partNumber);
return part;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@

class TestOzoneAtRestEncryption {

private static final String ETAG = "ETag";

private static MiniOzoneCluster cluster = null;
private static MiniKMS miniKMS;
private static OzoneClient ozClient = null;
Expand All @@ -119,6 +121,7 @@ class TestOzoneAtRestEncryption {
private static final int DEFAULT_CRYPTO_BUFFER_SIZE = 8 * 1024; // 8KB
// (this is the default Crypto Buffer size as determined by the config
// hadoop.security.crypto.buffer.size)
private static MessageDigest eTagProvider;

@BeforeAll
static void init() throws Exception {
Expand Down Expand Up @@ -168,6 +171,7 @@ static void init() throws Exception {

// create test key
createKey(TEST_KEY, cluster.getOzoneManager().getKmsProvider(), conf);
eTagProvider = MessageDigest.getInstance("Md5");
}

@AfterAll
Expand Down Expand Up @@ -631,9 +635,9 @@ private String uploadStreamPart(OzoneBucket bucket, String keyName,

ByteBuffer dataBuffer = ByteBuffer.wrap(data);
multipartStreamKey.write(dataBuffer, 0, length);
multipartStreamKey.getMetadata().put("ETag",
DatatypeConverter.printHexBinary(MessageDigest.getInstance("Md5")
.digest(data)).toLowerCase());
multipartStreamKey.getMetadata().put(ETAG,
DatatypeConverter.printHexBinary(eTagProvider.digest(data))
.toLowerCase());
multipartStreamKey.close();

OmMultipartCommitUploadPartInfo omMultipartCommitUploadPartInfo =
Expand All @@ -649,9 +653,9 @@ private String uploadPart(OzoneBucket bucket, String keyName,
OzoneOutputStream ozoneOutputStream = bucket.createMultipartKey(keyName,
data.length, partNumber, uploadID);
ozoneOutputStream.write(data, 0, data.length);
ozoneOutputStream.getMetadata().put("ETag",
DatatypeConverter.printHexBinary(MessageDigest.getInstance("Md5")
.digest(data)).toLowerCase());
ozoneOutputStream.getMetadata().put(ETAG,
DatatypeConverter.printHexBinary(eTagProvider.digest(data))
.toLowerCase());
ozoneOutputStream.close();

OmMultipartCommitUploadPartInfo omMultipartCommitUploadPartInfo =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,14 @@
*/
public class TestOzoneClientMultipartUploadWithFSO {

private static final String ETAG = "ETag";

private static ObjectStore store = null;
private static MiniOzoneCluster cluster = null;
private static OzoneClient ozClient = null;

private static String scmId = UUID.randomUUID().toString();
private static MessageDigest eTagProvider;

/**
* Set a timeout for each test.
Expand All @@ -131,6 +134,7 @@ public static void init() throws Exception {
OzoneConfiguration conf = new OzoneConfiguration();
OMRequestTestUtils.configureFSOptimizedPaths(conf, true);
startCluster(conf);
eTagProvider = MessageDigest.getInstance("Md5");
}

/**
Expand Down Expand Up @@ -229,7 +233,7 @@ public void testUploadPartWithNoOverride() throws IOException {
OzoneOutputStream ozoneOutputStream = bucket.createMultipartKey(keyName,
sampleData.length(), 1, uploadID);
ozoneOutputStream.write(string2Bytes(sampleData), 0, sampleData.length());
ozoneOutputStream.getMetadata().put("ETag", DigestUtils.md5Hex(sampleData));
ozoneOutputStream.getMetadata().put(ETAG, DigestUtils.md5Hex(sampleData));
ozoneOutputStream.close();

OmMultipartCommitUploadPartInfo commitUploadPartInfo = ozoneOutputStream
Expand Down Expand Up @@ -487,9 +491,9 @@ public void testCommitPartAfterCompleteUpload() throws Exception {
OzoneOutputStream ozoneOutputStream = bucket.createMultipartKey(keyName,
data.length, 1, uploadID);
ozoneOutputStream.write(data, 0, data.length);
ozoneOutputStream.getMetadata().put("ETag",
DatatypeConverter.printHexBinary(MessageDigest.getInstance("Md5")
.digest(data)).toLowerCase());
ozoneOutputStream.getMetadata().put(ETAG,
DatatypeConverter.printHexBinary(eTagProvider.digest(data))
.toLowerCase());
ozoneOutputStream.close();

OmMultipartCommitUploadPartInfo omMultipartCommitUploadPartInfo =
Expand All @@ -498,9 +502,9 @@ public void testCommitPartAfterCompleteUpload() throws Exception {
// Do not close output stream for part 2.
ozoneOutputStream = bucket.createMultipartKey(keyName,
data.length, 2, uploadID);
ozoneOutputStream.getMetadata().put("ETag",
DatatypeConverter.printHexBinary(MessageDigest.getInstance("Md5")
.digest(data)).toLowerCase());
ozoneOutputStream.getMetadata().put(ETAG,
DatatypeConverter.printHexBinary(eTagProvider.digest(data))
.toLowerCase());
ozoneOutputStream.write(data, 0, data.length);

Map<Integer, String> partsMap = new LinkedHashMap<>();
Expand Down Expand Up @@ -981,9 +985,9 @@ private Pair<String, String> uploadPart(OzoneBucket oBucket, String kName,
data.length, partNumber, uploadID);
ozoneOutputStream.write(data, 0,
data.length);
ozoneOutputStream.getMetadata().put("ETag",
DatatypeConverter.printHexBinary(MessageDigest.getInstance("Md5")
.digest(data)).toLowerCase());
ozoneOutputStream.getMetadata().put(ETAG,
DatatypeConverter.printHexBinary(eTagProvider.digest(data))
.toLowerCase());
ozoneOutputStream.close();

OmMultipartCommitUploadPartInfo omMultipartCommitUploadPartInfo =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivilegedExceptionAction;
import java.time.Instant;
import java.util.ArrayList;
Expand Down Expand Up @@ -161,6 +162,7 @@
import static org.slf4j.event.Level.DEBUG;

import org.apache.ozone.test.tag.Unhealthy;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
Expand All @@ -178,6 +180,8 @@
@TestMethodOrder(MethodOrderer.MethodName.class)
public abstract class TestOzoneRpcClientAbstract {

private static final String ETAG = "ETag";

private static MiniOzoneCluster cluster = null;
private static OzoneClient ozClient = null;
private static ObjectStore store = null;
Expand All @@ -197,6 +201,12 @@ public abstract class TestOzoneRpcClientAbstract {

private static String scmId = UUID.randomUUID().toString();
private static String clusterId;
private static MessageDigest eTagProvider;

@BeforeAll
public static void initialize() throws NoSuchAlgorithmException {
eTagProvider = MessageDigest.getInstance("Md5");
}


/**
Expand Down Expand Up @@ -237,7 +247,7 @@ static void shutdownCluster() throws IOException {
}

if (cluster != null) {
cluster.shutdown();
cluster.shutdown();3
}
}

Expand Down Expand Up @@ -1516,7 +1526,7 @@ public void testUsedBytesWithUploadPart() throws IOException {
sampleData.length(), 1, uploadID);
ozoneOutputStream.write(string2Bytes(sampleData), 0,
sampleData.length());
ozoneOutputStream.getMetadata().put("ETag", DigestUtils.md5Hex(sampleData));
ozoneOutputStream.getMetadata().put(ETAG, DigestUtils.md5Hex(sampleData));
ozoneOutputStream.close();

assertEquals(valueLength, store.getVolume(volumeName)
Expand Down Expand Up @@ -2682,7 +2692,7 @@ void testUploadPartWithNoOverride(ReplicationConfig replication)
OzoneOutputStream ozoneOutputStream = bucket.createMultipartKey(keyName,
sampleData.length(), 1, uploadID);
ozoneOutputStream.write(string2Bytes(sampleData), 0, sampleData.length());
ozoneOutputStream.getMetadata().put("ETag", DigestUtils.md5Hex(sampleData));
ozoneOutputStream.getMetadata().put(ETAG, DigestUtils.md5Hex(sampleData));
ozoneOutputStream.close();

OmMultipartCommitUploadPartInfo commitUploadPartInfo = ozoneOutputStream
Expand Down Expand Up @@ -2720,7 +2730,7 @@ void testUploadPartOverride(ReplicationConfig replication)
OzoneOutputStream ozoneOutputStream = bucket.createMultipartKey(keyName,
sampleData.length(), partNumber, uploadID);
ozoneOutputStream.write(string2Bytes(sampleData), 0, sampleData.length());
ozoneOutputStream.getMetadata().put("ETag", DigestUtils.md5Hex(sampleData));
ozoneOutputStream.getMetadata().put(ETAG, DigestUtils.md5Hex(sampleData));
ozoneOutputStream.close();

OmMultipartCommitUploadPartInfo commitUploadPartInfo = ozoneOutputStream
Expand All @@ -2736,7 +2746,7 @@ void testUploadPartOverride(ReplicationConfig replication)
ozoneOutputStream = bucket.createMultipartKey(keyName,
sampleData.length(), partNumber, uploadID);
ozoneOutputStream.write(string2Bytes(sampleData), 0, "name".length());
ozoneOutputStream.getMetadata().put("ETag", DigestUtils.md5Hex(sampleData));
ozoneOutputStream.getMetadata().put(ETAG, DigestUtils.md5Hex(sampleData));
ozoneOutputStream.close();

commitUploadPartInfo = ozoneOutputStream
Expand Down Expand Up @@ -3127,9 +3137,9 @@ void testCommitPartAfterCompleteUpload() throws Exception {
OzoneOutputStream ozoneOutputStream = bucket.createMultipartKey(keyName,
data.length, 1, uploadID);
ozoneOutputStream.write(data, 0, data.length);
ozoneOutputStream.getMetadata().put("ETag",
DatatypeConverter.printHexBinary(MessageDigest.getInstance("Md5")
.digest(data)).toLowerCase());
ozoneOutputStream.getMetadata().put(ETAG,
DatatypeConverter.printHexBinary(eTagProvider.digest(data))
.toLowerCase());
ozoneOutputStream.close();

OmMultipartCommitUploadPartInfo omMultipartCommitUploadPartInfo =
Expand All @@ -3138,9 +3148,9 @@ void testCommitPartAfterCompleteUpload() throws Exception {
// Do not close output stream for part 2.
ozoneOutputStream = bucket.createMultipartKey(keyName,
data.length, 2, omMultipartInfo.getUploadID());
ozoneOutputStream.getMetadata().put("ETag",
DatatypeConverter.printHexBinary(MessageDigest.getInstance("Md5")
.digest(data)).toLowerCase());
ozoneOutputStream.getMetadata().put(ETAG,
DatatypeConverter.printHexBinary(eTagProvider.digest(data))
.toLowerCase());
ozoneOutputStream.write(data, 0, data.length);

Map<Integer, String> partsMap = new LinkedHashMap<>();
Expand Down Expand Up @@ -3832,9 +3842,9 @@ private Pair<String, String> uploadPart(OzoneBucket bucket, String keyName,
data.length, partNumber, uploadID);
ozoneOutputStream.write(data, 0,
data.length);
ozoneOutputStream.getMetadata().put("ETag",
DatatypeConverter.printHexBinary(MessageDigest.getInstance("Md5")
.digest(data)).toLowerCase());
ozoneOutputStream.getMetadata().put(ETAG,
DatatypeConverter.printHexBinary(eTagProvider.digest(data))
.toLowerCase());
ozoneOutputStream.close();

OmMultipartCommitUploadPartInfo omMultipartCommitUploadPartInfo =
Expand Down

0 comments on commit d3e9f8f

Please sign in to comment.