Skip to content

Commit

Permalink
check prefop id by GET
Browse files Browse the repository at this point in the history
  • Loading branch information
sxci committed Nov 13, 2020
1 parent eb7fbb6 commit 148c8f5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/main/java/com/qiniu/processing/OperationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,8 @@ public OperationStatus prefop(String persistentId) throws QiniuException {
* 返回结果的 class
*/
public <T> T prefop(String persistentId, Class<T> retClass) throws QiniuException {
StringMap params = new StringMap().put("id", persistentId);
byte[] data = StringUtils.utf8Bytes(params.formString());
String url = String.format("%s/status/get/prefop", configuration.apiHost());
Response response = this.client.post(url, data, null, Client.FormMime);
String url = String.format("%s/status/get/prefop?id=%s", configuration.apiHost(), persistentId);
Response response = this.client.get(url);
if (!response.isOK()) {
throw new QiniuException(response);
}
Expand Down
38 changes: 33 additions & 5 deletions src/test/java/test/com/qiniu/processing/PfopTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package test.com.qiniu.processing;

import com.google.gson.Gson;
import com.qiniu.common.QiniuException;
import com.qiniu.common.Zone;
import com.qiniu.processing.OperationManager;
Expand All @@ -12,7 +13,9 @@
import test.com.qiniu.ResCode;
import test.com.qiniu.TestConfig;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.fail;
Expand All @@ -24,10 +27,14 @@ public class PfopTest {
* 检测jobid是否不为空
*/
@Test
public void testPfop() {
public void testPfop() throws QiniuException {
Map<String, Zone> cases = new HashMap<String, Zone>();
cases.put(TestConfig.testBucket_z0, Zone.autoZone());
cases.put(TestConfig.testBucket_na0, Zone.autoZone());
List<String> ids = new ArrayList<>();

Configuration cfg = new Configuration();
OperationManager operationManager = new OperationManager(TestConfig.testAuth, cfg);

for (Map.Entry<String, Zone> entry : cases.entrySet()) {
String bucket = entry.getKey();
Expand All @@ -48,18 +55,38 @@ public void testPfop() {
System.out.println(fops);

try {
Configuration cfg = new Configuration(zone);
OperationManager operationManager = new OperationManager(TestConfig.testAuth, cfg);
String jobid = operationManager.pfop(bucket, TestConfig.testMp4FileKey, fops, null,
notifyURL, force);
Assert.assertNotNull(jobid);
Assert.assertNotEquals("", jobid);
String purl = "https://api.qiniu.com/status/get/prefop?id=" + jobid;
System.out.println(purl);
ids.add(jobid);
} catch (QiniuException e) {
fail(e.response.toString());
}
}
System.out.println("\n\n");
for (String jobid : ids) {
String purl = "https://api.qiniu.com/status/get/prefop?id=" + jobid;
System.out.println(purl);
OperationStatus status = operationManager.prefop(jobid);
System.out.println(new Gson().toJson(status));
Assert.assertEquals(jobid, status.id);
}

System.out.println("\n\n");
try{
Thread.sleep(1000 * 7);
} catch (Exception e) {
// ingore
}

for (String jobid : ids) {
String purl = "https://api.qiniu.com/status/get/prefop?id=" + jobid;
System.out.println(purl);
OperationStatus status = operationManager.prefop(jobid);
System.out.println(new Gson().toJson(status));
Assert.assertEquals(jobid, status.id);
}
}

/**
Expand All @@ -75,6 +102,7 @@ public void testPrefop() {
OperationStatus status = operationManager.prefop(jobid);
Assert.assertEquals(0, status.code);
} catch (QiniuException ex) {
ex.printStackTrace();
Assert.assertTrue(ResCode.find(ex.code(), ResCode.getPossibleResCode(612)));
}
}
Expand Down

0 comments on commit 148c8f5

Please sign in to comment.