Skip to content

Commit

Permalink
Merge pull request #251 from sxci/7.2.3
Browse files Browse the repository at this point in the history
7.2.3; changelog; autozonebuckettest
  • Loading branch information
longbai authored Jan 11, 2017
2 parents d82fc29 + 703cd66 commit 88015b4
Show file tree
Hide file tree
Showing 3 changed files with 354 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#Changelog

## 7.2.3 (2017-01-11)
### 增加
* CDN url 预取
* 获取带宽、流量数据
* 获取日志列表
* 时间戳防盗链签名

### 修正
* ETag 大文件块计算整数溢出问题
* autoZone 不支持rs、rsf等问题
* 不能设置使用 https 的问题

## 7.2.2 (2016-11-04)
### 增加
* stream 方式上传
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/qiniu/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public final class Constants {
/**
* 版本号
*/
public static final String VERSION = "7.2.2";
public static final String VERSION = "7.2.3";
/**
* 块大小,不能改变
*/
Expand Down
341 changes: 341 additions & 0 deletions src/test/java/com/qiniu/storage/AutoZoneBucketTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,341 @@
package com.qiniu.storage;

import com.qiniu.TestConfig;
import com.qiniu.common.QiniuException;
import com.qiniu.common.Zone;
import com.qiniu.http.Response;
import com.qiniu.storage.model.BatchStatus;
import com.qiniu.storage.model.FileInfo;
import com.qiniu.storage.model.FileListing;
import com.qiniu.util.StringMap;
import com.qiniu.util.StringUtils;
import org.junit.Test;

import static org.junit.Assert.*;

@SuppressWarnings("ConstantConditions")
public class AutoZoneBucketTest {
private BucketManager bucketManager = new BucketManager(TestConfig.testAuth, new Configuration(Zone.autoZone()));
private BucketManager dummyBucketManager = new BucketManager(TestConfig.dummyAuth,
new Configuration(Zone.autoZone()));

@Test
public void testBuckets() {
try {
String[] buckets = bucketManager.buckets();
assertTrue(StringUtils.inStringArray(TestConfig.bucket, buckets));
} catch (QiniuException e) {
fail(e.getMessage());
}

try {
dummyBucketManager.buckets();
fail();
} catch (QiniuException e) {
assertEquals(401, e.code());
}
}

@Test
public void testList() {
try {
FileListing l = bucketManager.listFiles(TestConfig.bucket, null, null, 2, null);
assertNotNull(l.items[0]);
assertNotNull(l.marker);
} catch (QiniuException e) {
e.printStackTrace();
assertEquals("", e.error());
assertEquals("", e.getMessage());
fail();
}
}

@Test
public void testListUseDelimiter() {
try {
bucketManager.copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, "test/", true);
bucketManager.copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, "test/1", true);
bucketManager.copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, "test/2", true);
bucketManager.copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, "test/3/", true);
FileListing l = bucketManager.listFiles(TestConfig.bucket, "test/", null, 10, "/");
assertEquals(3, l.items.length);
assertEquals(2, l.commonPrefixes.length);

} catch (QiniuException e) {
e.printStackTrace();
assertEquals("", e.error());
assertEquals("", e.getMessage());
fail();
}
}

@Test
public void testListIterator() {
BucketManager.FileListIterator it = bucketManager
.createFileListIterator(TestConfig.bucket, "", 20, null);

assertTrue(it.hasNext());
FileInfo[] items0 = it.next();
assertNotNull(items0[0]);

while (it.hasNext()) {
FileInfo[] items = it.next();
if (items.length > 1) {
assertNotNull(items[0]);
}
}
}

@Test
public void testStat() {
try {
FileInfo info = bucketManager.stat(TestConfig.bucket, TestConfig.key);
assertEquals("FmYW4RYti94tr4ncaKzcTJz9M4Y9", info.hash);
} catch (QiniuException e) {
e.printStackTrace();
fail();
}

try {
bucketManager.stat(TestConfig.bucket, "noFile");
fail();
} catch (QiniuException e) {
assertEquals(612, e.code());
}

try {
bucketManager.stat(TestConfig.bucket, null);
fail();
} catch (QiniuException e) {
assertEquals(612, e.code());
}

try {
bucketManager.stat("noBucket", "noFile");
fail();
} catch (QiniuException e) {
assertEquals(631, e.code());
}
}

@Test
public void testDelete() {
try {
bucketManager.delete(TestConfig.bucket, "del");
fail();
} catch (QiniuException e) {
assertEquals(612, e.code());
}

try {
bucketManager.delete(TestConfig.bucket, null);
fail();
} catch (QiniuException e) {
assertEquals(612, e.code());
}

try {
bucketManager.delete("noBucket", null);
fail();
} catch (QiniuException e) {
assertEquals(631, e.code());
}
}

@Test
public void testRename() {
String key = "renameFrom" + Math.random();
try {
bucketManager.copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, key);
String key2 = "renameTo" + key;
bucketManager.rename(TestConfig.bucket, key, key2);
bucketManager.delete(TestConfig.bucket, key2);
} catch (QiniuException e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void testCopy() {
String key = "copyTo" + Math.random();
try {
bucketManager.copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, key);
bucketManager.delete(TestConfig.bucket, key);
} catch (QiniuException e) {
e.printStackTrace();
fail();
}
}

@Test
public void testChangeMime() {
try {
bucketManager.changeMime(TestConfig.bucket, "java-sdk.html", "text.html");
} catch (QiniuException e) {
e.printStackTrace();
fail();
}
}

@Test
public void testPrefetch() {
try {
bucketManager.prefetch(TestConfig.bucket, "java-sdk.html");
} catch (QiniuException e) {
e.printStackTrace();
fail();
}
}

@Test
public void testFetch() {
try {
bucketManager.fetch("http://developer.qiniu.com/docs/v6/sdk/java-sdk.html",
TestConfig.bucket, "fetch.html");
} catch (QiniuException e) {
fail();
}
}


@Test
public void testBatchCopy() {
String key = "copyTo" + Math.random();
BucketManager.Batch ops = new BucketManager.Batch().
copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, key);
try {
Response r = bucketManager.batch(ops);
BatchStatus[] bs = r.jsonToObject(BatchStatus[].class);
assertEquals(200, bs[0].code);
} catch (QiniuException e) {
e.printStackTrace();
fail();
}
ops = new BucketManager.Batch().delete(TestConfig.bucket, key);
try {
Response r = bucketManager.batch(ops);
BatchStatus[] bs = r.jsonToObject(BatchStatus[].class);
assertEquals(200, bs[0].code);
} catch (QiniuException e) {
e.printStackTrace();
}
}

@Test
public void testBatchMove() {
String key = "moveFrom" + Math.random();
try {
bucketManager.copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, key);
} catch (QiniuException e) {
e.printStackTrace();
fail();
}
String key2 = key + "to";
StringMap x = new StringMap().put(key, key2);
BucketManager.Batch ops = new BucketManager.Batch().move(TestConfig.bucket,
key, TestConfig.bucket, key2);
try {
Response r = bucketManager.batch(ops);
BatchStatus[] bs = r.jsonToObject(BatchStatus[].class);
assertEquals(200, bs[0].code);
} catch (QiniuException e) {
e.printStackTrace();
fail();
}
try {
bucketManager.delete(TestConfig.bucket, key2);
} catch (QiniuException e) {
e.printStackTrace();
fail();
}
}

@Test
public void testBatchRename() {
String key = "rename" + Math.random();
try {
bucketManager.copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, key);
} catch (QiniuException e) {
e.printStackTrace();
fail();
}
String key2 = key + "to";
BucketManager.Batch ops = new BucketManager.Batch().rename(TestConfig.bucket, key, key2);
try {
Response r = bucketManager.batch(ops);
BatchStatus[] bs = r.jsonToObject(BatchStatus[].class);
assertEquals(200, bs[0].code);
} catch (QiniuException e) {
e.printStackTrace();
fail();
}
try {
bucketManager.delete(TestConfig.bucket, key2);
} catch (QiniuException e) {
e.printStackTrace();
fail();
}
}

@Test
public void testBatchStat() {
String[] array = {"java-sdk.html"};
BucketManager.Batch ops = new BucketManager.Batch().stat(TestConfig.bucket, array);
try {
Response r = bucketManager.batch(ops);
BatchStatus[] bs = r.jsonToObject(BatchStatus[].class);
assertEquals(200, bs[0].code);
} catch (QiniuException e) {
e.printStackTrace();
fail();
}
}

@Test
public void testBatch() {
String[] array = {"java-sdk.html"};
String key = "copyFrom" + Math.random();

String key1 = "moveFrom" + Math.random();
String key2 = "moveTo" + Math.random();

String key3 = "moveFrom" + Math.random();
String key4 = "moveTo" + Math.random();

try {
bucketManager.copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, key1);
bucketManager.copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, key3);
} catch (QiniuException e) {
e.printStackTrace();
fail();
}

BucketManager.Batch ops = new BucketManager.Batch()
.copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, key)
.move(TestConfig.bucket, key1, TestConfig.bucket, key2)
.rename(TestConfig.bucket, key3, key4)
.stat(TestConfig.bucket, array)
.stat(TestConfig.bucket, array[0]);
try {
Response r = bucketManager.batch(ops);
BatchStatus[] bs = r.jsonToObject(BatchStatus[].class);
for (BatchStatus b : bs) {
assertEquals(200, b.code);
}
} catch (QiniuException e) {
e.printStackTrace();
fail();
}

BucketManager.Batch opsDel = new BucketManager.Batch().delete(TestConfig.bucket,
key, key1, key2, key3, key4);

try {
bucketManager.batch(opsDel);
} catch (QiniuException e) {
e.printStackTrace();
fail();
}
}
}

0 comments on commit 88015b4

Please sign in to comment.