Skip to content

Commit

Permalink
add etagv2, update etag check on multiupload
Browse files Browse the repository at this point in the history
  • Loading branch information
sxci committed Jun 18, 2020
1 parent 949ec33 commit 99e74dd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
4 changes: 1 addition & 3 deletions src/main/java/com/qiniu/storage/FixBlockUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)\"}";

Expand Down
14 changes: 7 additions & 7 deletions src/test/java/test/com/qiniu/storage/FixBlockUploaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand 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)\"}";
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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);
Expand All @@ -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)\"}";

Expand Down

0 comments on commit 99e74dd

Please sign in to comment.