Skip to content

Commit

Permalink
补充批量改变文件类型:
Browse files Browse the repository at this point in the history
 /**
         * 添加changeType指令
         */
        public BatchOperations addChangeTypeOps(String bucket, StorageType type, String... keys) {
            for (String key : keys) {
                ops.add(String.format("chtype/%s/type/%d", encodedEntry(bucket, key),type.ordinal()));
            }
            setExecBucket(bucket);
            return this;
        }
  • Loading branch information
hktry committed Sep 3, 2017
1 parent d975a15 commit c6c4835
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/main/java/com/qiniu/storage/BucketManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,16 @@ public BatchOperations addStatOps(String bucket, String... keys) {
setExecBucket(bucket);
return this;
}

/**
* 添加changeType指令
*/
public BatchOperations addChangeTypeOps(String bucket, StorageType type, String... keys) {
for (String key : keys) {
ops.add(String.format("chtype/%s/type/%d", encodedEntry(bucket, key),type.ordinal()));
}
setExecBucket(bucket);
return this;
}
public byte[] toBody() {
String body = StringUtils.join(ops, "&op=", "op=");
return StringUtils.utf8Bytes(body);
Expand Down
23 changes: 21 additions & 2 deletions src/test/java/com/qiniu/storage/BucketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import com.qiniu.common.Zone;
import com.qiniu.http.Response;
import com.qiniu.storage.model.*;
import com.qiniu.storage.BucketManager.StorageType;
import com.qiniu.util.StringUtils;
import junit.framework.TestCase;
import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -431,7 +431,26 @@ public void testBatchStat() {
}
}
}

@Test
public void testBatchChangeType() {
Map<String, String> bucketKeyMap = new HashMap<String, String>();
bucketKeyMap.put(TestConfig.testBucket_z0, TestConfig.testKey_z0);
bucketKeyMap.put(TestConfig.testBucket_na0, TestConfig.testKey_na0);
for (Map.Entry<String, String> entry : bucketKeyMap.entrySet()) {
String bucket = entry.getKey();
String key = entry.getValue();
String[] keyArray = new String[100];
keyArray[0]=key;
BucketManager.BatchOperations ops = new BucketManager.BatchOperations().addChangeTypeOps(bucket, StorageType.INFREQUENCY, keyArray);
try {
Response r = bucketManager.batch(ops);
BatchStatus[] bs = r.jsonToObject(BatchStatus[].class);
assertEquals(200, bs[0].code);
} catch (QiniuException e) {
fail(e.response.toString());
}
}
}
@Test
public void testBatchCopyChgmDelete() {
Map<String, String> bucketKeyMap = new HashMap<String, String>();
Expand Down

0 comments on commit c6c4835

Please sign in to comment.