From 99e74dd6b72b0b5beb0b9a95d755517b844bef26 Mon Sep 17 00:00:00 2001 From: Sxci Date: Thu, 18 Jun 2020 16:16:01 +0800 Subject: [PATCH] add etagv2, update etag check on multiupload --- .../java/com/qiniu/storage/FixBlockUploader.java | 4 +--- .../storage/FixBlockUploaderWithRecorderTest.java | 4 ++-- .../com/qiniu/storage/FixBlockUploaderTest.java | 14 +++++++------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/qiniu/storage/FixBlockUploader.java b/src/main/java/com/qiniu/storage/FixBlockUploader.java index f07f83e63..b82699884 100644 --- a/src/main/java/com/qiniu/storage/FixBlockUploader.java +++ b/src/main/java/com/qiniu/storage/FixBlockUploader.java @@ -29,14 +29,12 @@ public class FixBlockUploader { private String host = null; /** - * @param blockSize must be multiples of 4M. + * @param blockSize block size, eg: 1024 * 1024 * 8. * @param configuration Nullable, if null, then create a new one. * @param client Nullable, if null, then create a new one with configuration. * @param recorder Nullable. */ public FixBlockUploader(int blockSize, Configuration configuration, Client client, Recorder recorder) { - assert blockSize > 0 && blockSize % (4 * 1024 * 1024) == 0 : "blockSize must be multiples of 4M "; - if (configuration == null) { configuration = new Configuration(); } diff --git a/src/test/java/com/qiniu/storage/FixBlockUploaderWithRecorderTest.java b/src/test/java/com/qiniu/storage/FixBlockUploaderWithRecorderTest.java index 35dbdda18..41a2da63b 100644 --- a/src/test/java/com/qiniu/storage/FixBlockUploaderWithRecorderTest.java +++ b/src/test/java/com/qiniu/storage/FixBlockUploaderWithRecorderTest.java @@ -5,7 +5,7 @@ import com.qiniu.http.Client; import com.qiniu.http.Response; import com.qiniu.storage.persistent.FileRecorder; -import com.qiniu.util.Etag; +import com.qiniu.util.EtagV2; import com.qiniu.util.StringMap; import com.qiniu.util.UrlSafeBase64; import org.junit.Before; @@ -96,7 +96,7 @@ public void breakThenUpload(final ExecutorService pool1, final ExecutorService p final File f = TempFile.createFileOld(size); final FixBlockUploader.FileBlockData fbd = new FixBlockUploader.FileBlockData(blockSize, f); System.out.println(f.getAbsolutePath()); - final String etag = Etag.file(f); + final String etag = EtagV2.file(f, blockSize); final String returnBody = "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"fsize\":\"$(fsize)\"" + ",\"fname\":\"$(fname)\",\"mimeType\":\"$(mimeType)\"}"; diff --git a/src/test/java/test/com/qiniu/storage/FixBlockUploaderTest.java b/src/test/java/test/com/qiniu/storage/FixBlockUploaderTest.java index 329dabcca..7ccf9a92b 100644 --- a/src/test/java/test/com/qiniu/storage/FixBlockUploaderTest.java +++ b/src/test/java/test/com/qiniu/storage/FixBlockUploaderTest.java @@ -7,7 +7,7 @@ import com.qiniu.storage.BucketManager; import com.qiniu.storage.Configuration; import com.qiniu.storage.FixBlockUploader; -import com.qiniu.util.Etag; +import com.qiniu.util.EtagV2; import com.qiniu.util.StringMap; import org.junit.Assert; import org.junit.Before; @@ -24,7 +24,7 @@ import static org.junit.Assert.assertEquals; public class FixBlockUploaderTest { - int blockSize = 1024 * 1024 * 8; + int blockSize = 1024 * 1021 * 7; Configuration config; Client client; FixBlockUploader up; @@ -147,7 +147,7 @@ private void template(boolean isStream, int size, boolean https, boolean fixFile f = TempFile.createFileOld(size); } System.out.println(f.getAbsolutePath()); - final String etag = Etag.file(f); + final String etag = EtagV2.file(f, blockSize); System.out.println(etag); final String returnBody = "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"fsize\":\"$(fsize)\"" + ",\"fname\":\"$(fname)\",\"mimeType\":\"$(mimeType)\"}"; @@ -200,7 +200,7 @@ private void template(boolean isStream, int size, boolean https, boolean fixFile @Test public void testEmptyKey() throws IOException { File f = TempFile.createFileOld(1); - String etag = Etag.file(f); + String etag = EtagV2.file(f, blockSize); String token = TestConfig.testAuth.uploadToken(bucket, null); Response res = up.upload(f, token, ""); System.out.println(res.getInfo()); @@ -212,7 +212,7 @@ public void testEmptyKey() throws IOException { @Test public void testNullKey() throws IOException { File f = TempFile.createFile(2); - String etag = Etag.file(f); + String etag = EtagV2.file(f, blockSize); String token = TestConfig.testAuth.uploadToken(bucket, null); Response res = up.upload(f, token, null); System.out.println(res.getInfo()); @@ -224,7 +224,7 @@ public void testNullKey() throws IOException { @Test public void testKey2() throws IOException { File f = TempFile.createFile(2); - String etag = Etag.file(f); + String etag = EtagV2.file(f, blockSize); String token = TestConfig.testAuth.uploadToken(bucket, "err"); try { Response res = up.upload(f, token, null); @@ -238,7 +238,7 @@ public void testKey2() throws IOException { @Test public void testMeat() throws IOException { File f = TempFile.createFile(1); - String etag = Etag.file(f); + String etag = EtagV2.file(f, blockSize); String returnBody = "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"fsize\":\"$(fsize)\"" + ",\"fname\":\"$(x:biubiu)_$(fname)\",\"mimeType\":\"$(mimeType)\",\"biu2biu\":\"$(x:biu2biu)\"}";