From a97bae232b79bb4d67cf5fb71c09525205d3f14b Mon Sep 17 00:00:00 2001 From: longbai Date: Fri, 30 May 2014 18:05:06 +0800 Subject: [PATCH 1/4] remove transform api --- src/main/java/com/qiniu/api/rs/PutPolicy.java | 35 +------- .../java/com/qiniu/testing/TransformTest.java | 83 ------------------- 2 files changed, 4 insertions(+), 114 deletions(-) delete mode 100644 src/test/java/com/qiniu/testing/TransformTest.java diff --git a/src/main/java/com/qiniu/api/rs/PutPolicy.java b/src/main/java/com/qiniu/api/rs/PutPolicy.java index d4c99f999..27108be2d 100644 --- a/src/main/java/com/qiniu/api/rs/PutPolicy.java +++ b/src/main/java/com/qiniu/api/rs/PutPolicy.java @@ -41,7 +41,7 @@ public class PutPolicy { public int detectMime; /** 可选 */ public long fsizeLimit; - /**限定用户上传的文件类型 + /**限定用户上传的文件类型 * 可选 * */ public String mimeLimit; @@ -49,30 +49,9 @@ public class PutPolicy { public String persistentNotifyUrl; /** 可选 */ public String persistentOps; - - private long deadline; - /** - * - * 对文件先进行一次变换操作(比如将音频统一转为某种码率的mp3)再进行存储。 - * transform的值就是一个fop指令,比如 "avthumb/mp3"。其含义是对上传的文件 - * 执行这个 fop 指令,然后把结果保存到七牛。最后保存的是经过处理过的文件, - * 而不是用户上传的原始文件。 - * - **/ - public String transform; + private long deadline; - /** - * - * 单位: 秒 - * 文件变换操作执行的超时时间(单位:秒),上传和转码操作是同步进行的, - * 先上传后转码,这个时间只是转码所需时间,不包括上传文件所需时间。 - * 这个值太小可能会导致误判(最终存储成功了但客户端得到超时的错误), - * 但太大可能会导致服务端将其判断为低优先级任务。建议取一个相对准确的 - * 时间估计值*N(N不要超过5)。 - * - **/ - public long fopTimeout; public PutPolicy(String scope) { this.scope = scope; @@ -121,19 +100,13 @@ 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); - } stringer.key("deadline").value(this.deadline); stringer.endObject(); return stringer.toString(); } - + /** * makes an upload token. * @param mac @@ -141,7 +114,7 @@ public String marshal() throws JSONException { * @throws AuthException * @throws JSONException */ - + public String token(Mac mac) throws AuthException, JSONException { if (this.expires == 0) { this.expires = 3600; // 3600s, default. diff --git a/src/test/java/com/qiniu/testing/TransformTest.java b/src/test/java/com/qiniu/testing/TransformTest.java deleted file mode 100644 index 8d6074989..000000000 --- a/src/test/java/com/qiniu/testing/TransformTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.qiniu.testing; - -import java.io.*; - -import junit.framework.TestCase; - -import com.qiniu.api.auth.digest.Mac; -import com.qiniu.api.config.Config; -import com.qiniu.api.io.IoApi; -import com.qiniu.api.io.PutExtra; -import com.qiniu.api.io.PutRet; -import com.qiniu.api.net.CallRet; -import com.qiniu.api.rs.Entry; -import com.qiniu.api.rs.PutPolicy; -import com.qiniu.api.rs.RSClient; - -public class TransformTest extends TestCase { - - // because all the testcase concurrently executes - // so the key should be different. - public final String key = "IOTest-key"; - - public final String expectedHash = "FivxSqsM1SyWCnYeIGPUqZM5LL4b"; - - public String bucketName; - - public Mac mac; - @Override - public void setUp() { - 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"); - - assertNotNull(Config.ACCESS_KEY); - assertNotNull(Config.SECRET_KEY); - assertNotNull(Config.RS_HOST); - assertNotNull(bucketName); - mac = new Mac(Config.ACCESS_KEY, Config.SECRET_KEY); - } - - public void testPutTransform() throws Exception { - PutPolicy putPolicy = new PutPolicy(bucketName); - putPolicy.transform = "imageView/2/w/100/h/100"; - putPolicy.fopTimeout = 10; - - String uptoken = putPolicy.token(mac); - String dir = System.getProperty("user.dir"); - String localFile = dir + "/testdata/" + "logo.png"; - - PutExtra extra = new PutExtra(); - - PutRet ret = IoApi.putFile(uptoken, key, localFile, extra); - assertTrue(ret.ok()); - } - - @Override - public void tearDown() { - // delete the metadata from rs - // confirms it exists. - { - RSClient rs = new RSClient(mac); - Entry sr = rs.stat(bucketName, key); - System.out.println(sr.getHash()); - assertTrue(sr.ok()); - assertTrue(expectedHash.equals(sr.getHash())); - } - - // deletes it from rs - { - RSClient rs = new RSClient(mac); - CallRet cr = rs.delete(bucketName, key); - assertTrue(cr.ok()); - } - - // confirms that it's deleted - { - RSClient rs = new RSClient(mac); - Entry sr = rs.stat(bucketName, key); - assertTrue(!sr.ok()); - } - } -} \ No newline at end of file From b25ce117704c104624f7099a6142d514664a3f8b Mon Sep 17 00:00:00 2001 From: simon-liubin Date: Fri, 6 Jun 2014 14:45:24 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0persistentPipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/qiniu/api/rs/PutPolicy.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/qiniu/api/rs/PutPolicy.java b/src/main/java/com/qiniu/api/rs/PutPolicy.java index 27108be2d..1ae64c192 100644 --- a/src/main/java/com/qiniu/api/rs/PutPolicy.java +++ b/src/main/java/com/qiniu/api/rs/PutPolicy.java @@ -51,6 +51,12 @@ public class PutPolicy { public String persistentOps; private long deadline; + + /** + * 转码队列名,须预先开通 + * 资源上传成功后,触发转码时指定独立的队列进行转码 + */ + public String persistentPipeline; public PutPolicy(String scope) { @@ -100,6 +106,10 @@ public String marshal() throws JSONException { if (this.persistentOps != null && this.persistentOps.length() > 0) { stringer.key("persistentOps").value(this.persistentOps); } + if(persistentPipeline != null && persistentPipeline.trim().length() > 0){ + stringer.key("persistentPipeline").value(this.persistentPipeline); + } + stringer.key("deadline").value(this.deadline); stringer.endObject(); From 25bccd40d63c5ad6327a32687555b58a03965d28 Mon Sep 17 00:00:00 2001 From: longbai Date: Tue, 10 Jun 2014 13:07:40 +0800 Subject: [PATCH 3/4] update key --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8fbba21df..ff975f211 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ 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 From cf6773388c4bdaf018d61f653d825354cdc26f57 Mon Sep 17 00:00:00 2001 From: longbai Date: Tue, 10 Jun 2014 15:48:15 +0800 Subject: [PATCH 4/4] update test --- .travis.yml | 2 + .../java/com/qiniu/testing/BatchCopyTest.java | 26 ++++----- .../java/com/qiniu/testing/BatchMoveTest.java | 58 +++++++++---------- .../java/com/qiniu/testing/BatchStatTest.java | 8 +-- src/test/java/com/qiniu/testing/CopyTest.java | 28 ++------- .../java/com/qiniu/testing/FileopTest.java | 27 +++++---- src/test/java/com/qiniu/testing/IOTest.java | 30 +++++----- src/test/java/com/qiniu/testing/MoveTest.java | 26 ++------- .../com/qiniu/testing/ResumeableioTest.java | 36 ++++++------ 9 files changed, 102 insertions(+), 139 deletions(-) diff --git a/.travis.yml b/.travis.yml index ff975f211..74c25e0dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,3 +7,5 @@ before_script: - export QINIU_RS_HOST=http://rs.qbox.me - export QINIU_IO_HOST=http://iovip.qbox.me - export QINIU_TEST_BUCKET=javasdk + - export QINIU_TEST_SRC_BUCKET=testsrc + - export QINIU_TEST_DOMAIN=javasdk.qiniudn.com diff --git a/src/test/java/com/qiniu/testing/BatchCopyTest.java b/src/test/java/com/qiniu/testing/BatchCopyTest.java index 677e8f9ae..c2e7fa19e 100644 --- a/src/test/java/com/qiniu/testing/BatchCopyTest.java +++ b/src/test/java/com/qiniu/testing/BatchCopyTest.java @@ -26,13 +26,14 @@ 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 @@ -40,7 +41,6 @@ public void setUp() throws Exception { 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); } @@ -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 @@ -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())); @@ -173,7 +173,7 @@ public void testBatchCopy() throws Exception { } // the dest bucket should have the keys { - + RSClient rs = new RSClient(mac); List entries = new ArrayList(); @@ -228,7 +228,7 @@ public void tearDown() { // delete keys from the dest bucket { - + RSClient rs = new RSClient(mac); List entries = new ArrayList(); @@ -250,10 +250,10 @@ public void tearDown() { assertTrue(r.ok()); } } - + // use batchStat to check src bucket { - + RSClient rs = new RSClient(mac); List entries = new ArrayList(); @@ -271,7 +271,7 @@ public void tearDown() { // check batchCall assertTrue(!bsRet.ok()); } - + // use batchstat checks dest bucket again. { RSClient rs = new RSClient(mac); diff --git a/src/test/java/com/qiniu/testing/BatchMoveTest.java b/src/test/java/com/qiniu/testing/BatchMoveTest.java index 7785b74ba..584a2c41d 100644 --- a/src/test/java/com/qiniu/testing/BatchMoveTest.java +++ b/src/test/java/com/qiniu/testing/BatchMoveTest.java @@ -26,14 +26,14 @@ 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 @@ -41,7 +41,6 @@ public void setUp() throws Exception { 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); } @@ -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 @@ -107,41 +105,41 @@ public void testBatchMove() throws Exception { { RSClient rs = new RSClient(mac); List entries = new ArrayList(); - + 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 results = ret.results; for (CallRet r : results) { assertTrue(r.ok()); @@ -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 entries = new ArrayList(); 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 entries = new ArrayList(); 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 results = ret.results; for (Entry r : results) { assertTrue(r.ok()); @@ -221,7 +219,7 @@ public void tearDown() { // use batchstat checks it again. { - + RSClient rs = new RSClient(mac); List entries = new ArrayList(); diff --git a/src/test/java/com/qiniu/testing/BatchStatTest.java b/src/test/java/com/qiniu/testing/BatchStatTest.java index bcad3131c..093351d3f 100644 --- a/src/test/java/com/qiniu/testing/BatchStatTest.java +++ b/src/test/java/com/qiniu/testing/BatchStatTest.java @@ -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 @@ -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())); diff --git a/src/test/java/com/qiniu/testing/CopyTest.java b/src/test/java/com/qiniu/testing/CopyTest.java index 9fcf26ddd..2627d08f4 100644 --- a/src/test/java/com/qiniu/testing/CopyTest.java +++ b/src/test/java/com/qiniu/testing/CopyTest.java @@ -19,13 +19,12 @@ public class CopyTest extends TestCase { public final String expectedHash = "FmDZwqadA4-ib_15hYfQpb7UXUYR"; - public String bucketName; - public final String key = "CopyTest-key"; + public final String key = "java-CopyTest-key"; - public final String srcBucket = "junit_bucket_src"; - public final String destBucket = "junit_bucket_dest"; + 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 @@ -33,7 +32,6 @@ public void setUp() throws Exception { 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); } @@ -42,7 +40,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 @@ -62,22 +59,7 @@ public void setUp() throws Exception { } } - public void testMove() throws Exception { - // upload a file to the srcbucket - { - String uptoken = ""; - try { - uptoken = new PutPolicy(bucketName).token(mac); - } catch (AuthException ignore) { - } - String dir = System.getProperty("user.dir"); - String localFile = dir + "/testdata/" + "logo.png"; - - PutExtra extra = new PutExtra(); - PutRet ret = IoApi.putFile(uptoken, key, localFile, extra); - assertTrue(ret.ok()); - assertTrue(expectedHash.equals(ret.getHash())); - } + public void testCopy() throws Exception { // test move { RSClient rs = new RSClient(mac); diff --git a/src/test/java/com/qiniu/testing/FileopTest.java b/src/test/java/com/qiniu/testing/FileopTest.java index cc8a9a589..fe05548a5 100644 --- a/src/test/java/com/qiniu/testing/FileopTest.java +++ b/src/test/java/com/qiniu/testing/FileopTest.java @@ -22,14 +22,14 @@ public class FileopTest extends TestCase { - public String key = "FileopTest-key"; + public String key = "java-FileopTest-key"; - public String bucketName; + public String bucketName = System.getenv("QINIU_TEST_BUCKET");; public String expectedHash = "FmDZwqadA4-ib_15hYfQpb7UXUYR"; - public String domain = "http://junitbucket.qiniudn.com"; - + public String domain = System.getenv("QINIU_TEST_DOMAIN"); + public Mac mac; @Override @@ -40,7 +40,6 @@ public void setUp() throws Exception { Config.ACCESS_KEY = System.getenv("QINIU_ACCESS_KEY"); Config.SECRET_KEY = System.getenv("QINIU_SECRET_KEY"); Config.RS_HOST = System.getenv("QINIU_RS_HOST"); - this.bucketName = System.getenv("QINIU_TEST_BUCKET"); mac = new Mac(Config.ACCESS_KEY, Config.SECRET_KEY); } // check the config @@ -50,9 +49,9 @@ public void setUp() throws Exception { assertNotNull(Config.RS_HOST); assertNotNull(bucketName); } - + key = UUID.randomUUID().toString(); - + // upload an image { String uptoken = ""; @@ -64,7 +63,7 @@ public void setUp() throws Exception { String localFile = dir + "/testdata/" + "logo.png"; PutExtra extra = new PutExtra(); - + PutRet ret = IoApi.putFile(uptoken, key, localFile, extra); assertTrue(ret.ok()); assertTrue(expectedHash.equals(ret.getHash())); @@ -72,20 +71,20 @@ public void setUp() throws Exception { } public void testImageInfo() throws Exception { - String url = domain + "/" + key; + String url = "http://" + domain + "/" + key; ImageInfoRet ret = ImageInfo.call(url); assertTrue(ret.ok()); } public void testImageExif() throws Exception { - String url = domain + "/" + key; + String url = "http://" + domain + "/" + key; ExifRet ret = ImageExif.call(url); // logo.png has no exif assertTrue(!ret.ok()); } public void testImageView() throws Exception { - String url = "http://qiniuphotos.qiniudn.com/gogopher.jpg"; + String url = "http://testres.qiniudn.com/gogopher.jpg"; { ImageView iv = new ImageView(); iv.mode = 1; @@ -113,7 +112,7 @@ public void testImageView() throws Exception { } public void testImageViewMakeRequest() { - String testUrl = "http://iovip.qbox.me/file/xyz=="; + String testUrl = "http://testres.qiniudn.com/gogopher.jpg"; ImageView imgView = new ImageView(); // case 1 { @@ -133,7 +132,7 @@ public void testImageViewMakeRequest() { assertEquals(testUrl + "?imageView/2/h/200", url); } } - + public void testStat(){ RSClient rs = new RSClient(mac); Entry sr = rs.stat(bucketName, key); @@ -146,4 +145,4 @@ public void tearDown() { RSClient rs = new RSClient(mac); CallRet cr = rs.delete(bucketName, key); } -} \ No newline at end of file +} diff --git a/src/test/java/com/qiniu/testing/IOTest.java b/src/test/java/com/qiniu/testing/IOTest.java index 92aba663d..84fd78180 100644 --- a/src/test/java/com/qiniu/testing/IOTest.java +++ b/src/test/java/com/qiniu/testing/IOTest.java @@ -21,15 +21,15 @@ public class IOTest extends TestCase { // because all the testcase concurrently executes // so the key should be different. - private String key = "IOTest-key"; - - private String key2 = "IOTest-Stream-key"; - + private String key = "java-IOTest-key"; + + private String key2 = "java-IOTest-Stream-key"; + private final String expectedHash = "FmDZwqadA4-ib_15hYfQpb7UXUYR"; private final String expectedHash2 = "Fp9UwOPl9G3HmZsVFkJrMtdwSMp8"; private String bucketName; - + private Mac mac; @Override public void setUp() { @@ -38,7 +38,7 @@ public void setUp() { bucketName = System.getenv("QINIU_TEST_BUCKET"); mac = new Mac(Config.ACCESS_KEY, Config.SECRET_KEY); - + key = UUID.randomUUID().toString(); key2 = UUID.randomUUID().toString(); } @@ -50,11 +50,11 @@ public void testPut() throws Exception { String xvalue = "test_value"; String name = "nonxtest_name"; String value = "nonxtest_value"; - + PutPolicy putPolicy = new PutPolicy(bucketName); putPolicy.returnBody = "{\"hash\":\"$(etag)\",\"key\":\"$(key)\",\"fsize\":\"$(fsize)\",\""+xname+"\":\"$("+xname+")\",\""+name+"\":\"$("+name+")\"}"; String uptoken = putPolicy.token(mac); - + String dir = System.getProperty("user.dir"); String localFile = dir + "/testdata/" + "logo.png"; @@ -63,15 +63,15 @@ public void testPut() throws Exception { params.put(xname, xvalue); params.put(name, value); extra.params = params; - + PutRet ret = IoApi.putFile(uptoken, key, localFile, extra); assertTrue(ret.ok()); assertTrue(expectedHash.equals(ret.getHash())); - + JSONObject jsonObject = new JSONObject(ret.response); assertEquals(xvalue, getJsonValue(jsonObject, xname)); assertEquals(null, getJsonValue(jsonObject, name)); - + //test stream upload { String str="Hello,Qiniu"; @@ -85,7 +85,7 @@ public void testPut() throws Exception { assertEquals(null, getJsonValue(jsonObject, name)); } } - + private String getJsonValue(JSONObject jsonObject, String name){ try{ String value = jsonObject.getString(name); @@ -105,13 +105,13 @@ public void tearDown() { try{ rs.delete(bucketName, key2); }catch(Exception e){ - + } - + try{ rs.delete(bucketName, key); }catch(Exception e){ - + } } } diff --git a/src/test/java/com/qiniu/testing/MoveTest.java b/src/test/java/com/qiniu/testing/MoveTest.java index c143abbbe..7eb0412e8 100644 --- a/src/test/java/com/qiniu/testing/MoveTest.java +++ b/src/test/java/com/qiniu/testing/MoveTest.java @@ -19,14 +19,13 @@ public class MoveTest extends TestCase { public final String expectedHash = "FmDZwqadA4-ib_15hYfQpb7UXUYR"; - public String bucketName; - public final String key = "MoveTest-key"; + public final String key = "java-MoveTest-key"; - public final String srcBucket = "junit_bucket_src"; - public final String destBucket = "junit_bucket_dest"; + 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 @@ -34,7 +33,6 @@ public void setUp() throws Exception { 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); } @@ -43,7 +41,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 @@ -65,21 +62,6 @@ public void setUp() throws Exception { } public void testMove() throws Exception { - // upload a file to the srcbucket - { - String uptoken = ""; - try { - uptoken = new PutPolicy(bucketName).token(mac); - } catch (AuthException ignore) { - } - String dir = System.getProperty("user.dir"); - String localFile = dir + "/testdata/" + "logo.png"; - - PutExtra extra = new PutExtra(); - PutRet ret = IoApi.putFile(uptoken, key, localFile, extra); - assertTrue(ret.ok()); - assertTrue(expectedHash.equals(ret.getHash())); - } // test move { RSClient rs = new RSClient(mac); diff --git a/src/test/java/com/qiniu/testing/ResumeableioTest.java b/src/test/java/com/qiniu/testing/ResumeableioTest.java index b9660b41a..79c0889a8 100644 --- a/src/test/java/com/qiniu/testing/ResumeableioTest.java +++ b/src/test/java/com/qiniu/testing/ResumeableioTest.java @@ -35,7 +35,7 @@ public void setUp() { Config.SECRET_KEY = System.getenv("QINIU_SECRET_KEY"); Config.RS_HOST = System.getenv("QINIU_RS_HOST"); bucketName = System.getenv("QINIU_TEST_BUCKET"); - + assertNotNull(Config.ACCESS_KEY); assertNotNull(Config.SECRET_KEY); assertNotNull(Config.RS_HOST); @@ -44,40 +44,40 @@ public void setUp() { mimeType = null; currentKey = UUID.randomUUID().toString() + ".txt"; } - + public void testPut1MFile() throws Exception { file = createFile(1, "_1m_"); mimeType = "test/type1m"; uploadFile(); } - + public void testPut1MStream() throws Exception { file = createFile(1, "_1m_"); uploadStream(); } - + public void testPut4MFile() throws Exception { file = createFile(4, "_4m_"); uploadFile(); } - + public void testPut4MStream() throws Exception { file = createFile(4, "_4m_"); mimeType = "test/type4m"; uploadStream(); } - - public void testPut9MFile() throws Exception { - file = createFile(9, "_9m_"); + + public void testPut3MFile() throws Exception { + file = createFile(3, "_3m_"); uploadFile(); } - - public void testPut9MStream() throws Exception { - file = createFile(9, "_9m_"); - mimeType = "test/type9m"; + + public void testPut3MStream() throws Exception { + file = createFile(3, "_3m_"); + mimeType = "test/type3m"; uploadStream(); } - + private void uploadFile() throws AuthException, JSONException{ PutPolicy p = new PutPolicy(bucketName); @@ -92,7 +92,7 @@ private void uploadFile() throws AuthException, JSONException{ assertEquals(mimeType, mt); } } - + private void uploadStream() throws AuthException, JSONException, FileNotFoundException{ PutPolicy p = new PutPolicy(bucketName); @@ -108,7 +108,7 @@ private void uploadStream() throws AuthException, JSONException, FileNotFoundExc assertEquals(mimeType, mt); } } - + @Override public void tearDown() { @@ -119,7 +119,7 @@ public void tearDown() { }catch(Exception e){ e.printStackTrace(); } - + RSClient rs = new RSClient(mac); System.out.println("try to delete: " + currentKey); CallRet cr = rs.delete(bucketName, currentKey); @@ -129,7 +129,7 @@ public void tearDown() { /** * @param fileSize M * @return - * @throws IOException + * @throws IOException */ private File createFile(int fileSize, String temp) throws IOException { FileOutputStream fos = null; @@ -155,7 +155,7 @@ private File createFile(int fileSize, String temp) throws IOException { } } } - + private byte[] getByte(){ byte [] b = new byte[1024 * 4]; b[0] = 'A';