Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:qiniu/java-sdk into update/local…
Browse files Browse the repository at this point in the history
…-error-code
  • Loading branch information
sxci committed Jun 10, 2014
2 parents 19f9e7e + 4508678 commit 74f999f
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 255 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
language: java

before_script:
- export QINIU_ACCESS_KEY=iN7NgwM31j4-BZacMjPrOQBs34UG1maYCAQmhdCV
- export QINIU_SECRET_KEY=6QTOr2Jg1gcZEWDQXKOGZh5PziC2MCV5KsntT70j
- export QINIU_ACCESS_KEY=QWYn5TFQsLLU1pL5MFEmX3s5DmHdUThav9WyOWOm
- export QINIU_SECRET_KEY=Bxckh6FA-Fbs9Yt3i3cbKVK22UPBmAOHJcL95pGz
- export QINIU_UP_HOST=http://up.qbox.me
- export QINIU_RS_HOST=http://rs.qbox.me
- export QINIU_IO_HOST=http://iovip.qbox.me
- export QINIU_TEST_BUCKET=junit_bucket
- export QINIU_TEST_BUCKET=javasdk
- export QINIU_TEST_SRC_BUCKET=testsrc
- export QINIU_TEST_DOMAIN=javasdk.qiniudn.com
43 changes: 13 additions & 30 deletions src/main/java/com/qiniu/api/rs/PutPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,23 @@ public class PutPolicy {
public int detectMime;
/** 可选 */
public long fsizeLimit;
/**限定用户上传的文件类型
/**限定用户上传的文件类型
* 可选
* */
public String mimeLimit;
/** 可选 */
public String persistentNotifyUrl;
/** 可选 */
public String persistentOps;

private long deadline;

/**
*
* 对文件先进行一次变换操作(比如将音频统一转为某种码率的mp3)再进行存储。
* transform的值就是一个fop指令,比如 "avthumb/mp3"。其含义是对上传的文件
* 执行这个 fop 指令,然后把结果保存到七牛。最后保存的是经过处理过的文件,
* 而不是用户上传的原始文件。
*
**/
public String transform;
private long deadline;

/**
* 转码队列名,须预先开通
* 资源上传成功后,触发转码时指定独立的队列进行转码
*/
public String persistentPipeline;

/**
*
* 单位: 秒
* 文件变换操作执行的超时时间(单位:秒),上传和转码操作是同步进行的,
* 先上传后转码,这个时间只是转码所需时间,不包括上传文件所需时间。
* 这个值太小可能会导致误判(最终存储成功了但客户端得到超时的错误),
* 但太大可能会导致服务端将其判断为低优先级任务。建议取一个相对准确的
* 时间估计值*N(N不要超过5)。
*
**/
public long fopTimeout;

public PutPolicy(String scope) {
this.scope = scope;
Expand Down Expand Up @@ -121,27 +106,25 @@ public String marshal() throws JSONException {
if (this.persistentOps != null && this.persistentOps.length() > 0) {
stringer.key("persistentOps").value(this.persistentOps);
}
if (this.transform != null && this.transform.length() > 0) {
stringer.key("transform").value(this.transform);
}
if (this.fopTimeout > 0) {
stringer.key("fopTimeout").value(this.fopTimeout);
if(persistentPipeline != null && persistentPipeline.trim().length() > 0){
stringer.key("persistentPipeline").value(this.persistentPipeline);
}

stringer.key("deadline").value(this.deadline);
stringer.endObject();

return stringer.toString();
}


/**
* makes an upload token.
* @param mac
* @return
* @throws AuthException
* @throws JSONException
*/

public String token(Mac mac) throws AuthException, JSONException {
if (this.expires == 0) {
this.expires = 3600; // 3600s, default.
Expand Down
26 changes: 13 additions & 13 deletions src/test/java/com/qiniu/testing/BatchCopyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ public class BatchCopyTest extends TestCase {
public final String expectedHash = "FmDZwqadA4-ib_15hYfQpb7UXUYR";

public String bucketName;
public final String key1 = "BatchCopyTest-key1";
public final String key2 = "BatchCopyTest-key2";
public final String key1 = "java-BatchCopyTest-key1";
public final String key2 = "java-BatchCopyTest-key2";

public final String srcBucket = System.getenv("QINIU_TEST_SRC_BUCKET");
public final String destBucket = System.getenv("QINIU_TEST_BUCKET");

public final String srcBucket = "junit_bucket_src";
public final String destBucket = "junit_bucket_dest";
public Mac mac;

@Override
public void setUp() throws Exception {
// get the config
{
Config.ACCESS_KEY = System.getenv("QINIU_ACCESS_KEY");
Config.SECRET_KEY = System.getenv("QINIU_SECRET_KEY");
Config.RS_HOST = System.getenv("QINIU_RS_HOST");
bucketName = System.getenv("QINIU_TEST_BUCKET");
mac = new Mac(Config.ACCESS_KEY, Config.SECRET_KEY);
}

Expand All @@ -49,7 +49,6 @@ public void setUp() throws Exception {
assertNotNull(Config.ACCESS_KEY);
assertNotNull(Config.SECRET_KEY);
assertNotNull(Config.RS_HOST);
assertNotNull(bucketName);
}

// upload a file to src bucket with key1, key2
Expand All @@ -63,8 +62,9 @@ public void setUp() throws Exception {
String localFile = dir + "/testdata/" + "logo.png";

PutExtra extra = new PutExtra();

PutRet ret = IoApi.putFile(uptoken, key1, localFile, extra);

assertTrue(ret.ok());
assertTrue(expectedHash.equals(ret.getHash()));

Expand Down Expand Up @@ -173,7 +173,7 @@ public void testBatchCopy() throws Exception {
}
// the dest bucket should have the keys
{

RSClient rs = new RSClient(mac);

List<EntryPath> entries = new ArrayList<EntryPath>();
Expand Down Expand Up @@ -228,7 +228,7 @@ public void tearDown() {

// delete keys from the dest bucket
{

RSClient rs = new RSClient(mac);
List<EntryPath> entries = new ArrayList<EntryPath>();

Expand All @@ -250,10 +250,10 @@ public void tearDown() {
assertTrue(r.ok());
}
}

// use batchStat to check src bucket
{

RSClient rs = new RSClient(mac);
List<EntryPath> entries = new ArrayList<EntryPath>();

Expand All @@ -271,7 +271,7 @@ public void tearDown() {
// check batchCall
assertTrue(!bsRet.ok());
}

// use batchstat checks dest bucket again.
{
RSClient rs = new RSClient(mac);
Expand Down
58 changes: 28 additions & 30 deletions src/test/java/com/qiniu/testing/BatchMoveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,21 @@ public class BatchMoveTest extends TestCase {
public final String expectedHash = "FmDZwqadA4-ib_15hYfQpb7UXUYR";

public String bucketName;
public final String key1 = "BatchMoveTest-key1";
public final String key2 = "BatchMoveTest-key2";
public final String srcBucket = "junit_bucket_src";
public final String destBucket = "junit_bucket_dest";
public final String key1 = "java-BatchMoveTest-key1";
public final String key2 = "java-BatchMoveTest-key2";

public final String srcBucket = System.getenv("QINIU_TEST_SRC_BUCKET");
public final String destBucket = System.getenv("QINIU_TEST_BUCKET");

public Mac mac;

@Override
public void setUp() throws Exception {
// get the config
{
Config.ACCESS_KEY = System.getenv("QINIU_ACCESS_KEY");
Config.SECRET_KEY = System.getenv("QINIU_SECRET_KEY");
Config.RS_HOST = System.getenv("QINIU_RS_HOST");
bucketName = System.getenv("QINIU_TEST_BUCKET");
mac = new Mac(Config.ACCESS_KEY, Config.SECRET_KEY);
}

Expand All @@ -50,7 +49,6 @@ public void setUp() throws Exception {
assertNotNull(Config.ACCESS_KEY);
assertNotNull(Config.SECRET_KEY);
assertNotNull(Config.RS_HOST);
assertNotNull(bucketName);
}

// upload a file to the bucket with key1, key2
Expand Down Expand Up @@ -107,41 +105,41 @@ public void testBatchMove() throws Exception {
{
RSClient rs = new RSClient(mac);
List<EntryPathPair> entries = new ArrayList<EntryPathPair>();

EntryPathPair pair1 = new EntryPathPair();

EntryPath src = new EntryPath();
src.bucket = srcBucket;
src.key = key1;

EntryPath dest = new EntryPath();
dest.bucket = destBucket;
dest.key = key1;

pair1.src = src;
pair1.dest = dest;

EntryPathPair pair2 = new EntryPathPair();

EntryPath src2 = new EntryPath();
src2.bucket = srcBucket;
src2.key = key2;

EntryPath dest2 = new EntryPath();
dest2.bucket = destBucket;
dest2.key = key2;

pair2.src = src2;
pair2.dest = dest2;

entries.add(pair1);
entries.add(pair2);

BatchCallRet ret = rs.batchMove(entries);

// check batchMove
assertTrue(ret.ok());

List<CallRet> results = ret.results;
for (CallRet r : results) {
assertTrue(r.ok());
Expand All @@ -150,41 +148,41 @@ public void testBatchMove() throws Exception {
// the src keys should not be available in src bucket
{
RSClient rs = new RSClient(mac);

List<EntryPath> entries = new ArrayList<EntryPath>();
EntryPath e1 = new EntryPath();
e1.bucket = srcBucket;
e1.key = key1;

EntryPath e2 = new EntryPath();
e2.bucket = srcBucket;
e2.key = key2;

entries.add(e1);
entries.add(e2);

BatchStatRet ret = rs.batchStat(entries);
assertTrue(!ret.ok());
}
// the dest bucket should have the keys
{
RSClient rs = new RSClient(mac);

List<EntryPath> entries = new ArrayList<EntryPath>();
EntryPath e1 = new EntryPath();
e1.bucket = destBucket;
e1.key = key1;

EntryPath e2 = new EntryPath();
e2.bucket = destBucket;
e2.key = key2;

entries.add(e1);
entries.add(e2);

BatchStatRet ret = rs.batchStat(entries);
assertTrue(ret.ok());

List<Entry> results = ret.results;
for (Entry r : results) {
assertTrue(r.ok());
Expand Down Expand Up @@ -221,7 +219,7 @@ public void tearDown() {

// use batchstat checks it again.
{

RSClient rs = new RSClient(mac);
List<EntryPath> entries = new ArrayList<EntryPath>();

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/qiniu/testing/BatchStatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public class BatchStatTest extends TestCase {
public final String expectedHash = "FmDZwqadA4-ib_15hYfQpb7UXUYR";

public String bucketName;
public final String key1 = "BatchStatTest-key1";
public final String key2 = "BatchStatTest-key2";
public final String key1 = "java-BatchStatTest-key1";
public final String key2 = "java-BatchStatTest-key2";
public Mac mac;

@Override
public void setUp() throws Exception {
// get the config
Expand Down Expand Up @@ -59,7 +59,7 @@ public void setUp() throws Exception {
String localFile = dir + "/testdata/" + "logo.png";

PutExtra extra = new PutExtra();

PutRet ret = IoApi.putFile(uptoken, key1, localFile, extra);
assertTrue(ret.ok());
assertTrue(expectedHash.equals(ret.getHash()));
Expand Down
Loading

0 comments on commit 74f999f

Please sign in to comment.