Skip to content

Commit 72ebe1d

Browse files
authored
Revert "FormUpload With InputStream"
1 parent 3be2b5b commit 72ebe1d

File tree

7 files changed

+57
-154
lines changed

7 files changed

+57
-154
lines changed

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ dependencies {
1616
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
1717
testCompile group: 'com.qiniu', name: 'happy-dns-java', version: '0.1.6'
1818
testCompile group: 'junit', name: 'junit', version: '4.12'
19-
compile group: 'commons-io', name: 'commons-io', version: '2.6'
2019
}
2120

2221

src/main/java/com/qiniu/common/Region.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public String getApiHost() {
5858
/**
5959
* 域名构造器
6060
*/
61-
public static class Builder {
61+
static class Builder {
6262
protected Region region;
6363

6464
public Builder() {

src/main/java/com/qiniu/storage/UploadManager.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import java.io.IOException;
1010
import java.io.InputStream;
1111

12-
import org.apache.commons.io.IOUtils;
13-
1412
/**
1513
* 七牛文件上传管理器,通过该类上传文件时,会自动根据定义的{@link Configuration#putThreshold}
1614
* 来判断是采用表单上传还是分片上传的方法,超过了定义的{@link Configuration#putThreshold}就会采用
@@ -88,37 +86,6 @@ public void accept(String key, Object value) {
8886
});
8987
return ret;
9088
}
91-
92-
/**
93-
* 上传字节流,表单形式
94-
* 合适小文件,大文件请用流式上传
95-
* @param inputStream
96-
* @param key
97-
* @param token
98-
* @return
99-
* @throws QiniuException
100-
*/
101-
public Response putWithForm(InputStream inputStream, String key, String token) throws QiniuException, IOException {
102-
return putWithForm(inputStream, key, token, null, null, false);
103-
}
104-
105-
/**
106-
* 上传字节流,表单形式
107-
* 合适小文件,大文件请用流式上传
108-
* @param inputStream
109-
* @param key
110-
* @param token
111-
* @param params
112-
* @param mime
113-
* @param checkCrc
114-
* @return
115-
* @throws QiniuException
116-
*/
117-
public Response putWithForm(InputStream inputStream, String key, String token, StringMap params,
118-
String mime, boolean checkCrc) throws QiniuException, IOException {
119-
byte[] data = IOUtils.toByteArray(inputStream);
120-
return put(data, key, token, params, mime, checkCrc);
121-
}
12289

12390
/**
12491
* 上传字节数组

src/test/java/test/com/qiniu/TestConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,12 @@ public static boolean isTravis() {
4343
return "travis".equals(System.getenv("QINIU_TEST_ENV"));
4444
}
4545

46+
public static void main(String[] args) {
47+
try {
48+
System.out.println("done");
49+
} catch (Exception e) {
50+
e.printStackTrace();
51+
}
52+
}
53+
4654
}

src/test/java/test/com/qiniu/rtc/RtcTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111

1212
public class RtcTest {
13-
1413
private Auth auth = TestConfig.testAuth;
1514
private RtcAppManager manager = new RtcAppManager(auth);
1615
private RtcRoomManager rmanager = new RtcRoomManager(auth);

src/test/java/test/com/qiniu/storage/FormUploadTest2.java

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/test/java/test/com/qiniu/streaming/StreamingTest.java

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,97 @@
11
package test.com.qiniu.streaming;
22

3+
import com.google.gson.JsonSyntaxException;
34
import com.qiniu.common.QiniuException;
45
import com.qiniu.streaming.StreamingManager;
56
import com.qiniu.streaming.model.ActivityRecords;
67
import com.qiniu.streaming.model.StreamAttribute;
78
import com.qiniu.streaming.model.StreamListing;
9+
import com.qiniu.streaming.model.StreamStatus;
810
import com.qiniu.util.Auth;
11+
import com.qiniu.util.Json;
912
import org.junit.Test;
1013
import test.com.qiniu.TestConfig;
1114

1215
import static org.junit.Assert.*;
1316

1417
/**
1518
* Created by bailong on 16/9/22
16-
* Updated by panyuan on 19/3/12
1719
*/
1820
public class StreamingTest {
19-
2021
private Auth auth = TestConfig.testAuth;
22+
2123
private String hub = "pilisdktest";
22-
private String stream = "javasdk";
23-
private String streamNoExist = "javasdk" + "NoExist";
24-
private String streamKeyPrefix = "javasdk";
24+
private String streamKeyPrefix = "pilijava" + System.currentTimeMillis();
2525
private StreamingManager manager = new StreamingManager(auth, hub);
2626

27-
/**
28-
* 测试获取不存在的流的信息
29-
* 检测返回状态码是否是612
30-
*/
31-
@Test
27+
28+
//@Test
3229
public void testGetNoExistStream() {
3330
try {
34-
manager.attribute(streamNoExist);
31+
manager.attribute("nnnoexist");
3532
fail("should not exist");
3633
} catch (QiniuException e) {
34+
e.printStackTrace();
3735
assertEquals(612, e.code());
3836
}
3937
}
4038

41-
/**
42-
* 测试创建、禁用、启用、获取流信息、列举
43-
* @throws QiniuException
44-
*/
45-
@Test
39+
// CHECKSTYLE:OFF
40+
//@Test
4641
public void testStreamOperation() throws QiniuException {
47-
StreamAttribute attr = manager.attribute(stream);
42+
// CHECKSTYLE:ON
43+
String streamKey = streamKeyPrefix + "-a";
44+
45+
manager.create(streamKey);
46+
47+
StreamAttribute attr = manager.attribute(streamKey);
4848
assertEquals(0, attr.disabledTill);
4949
assertNotEquals(0, attr.createdAt);
5050

5151
try {
52-
manager.create(stream);
52+
manager.create(streamKey);
5353
fail("has already existed");
5454
} catch (QiniuException e) {
5555
assertEquals(614, e.code());
5656
}
5757

58-
manager.disableTill(stream, -1);
58+
manager.disableTill(streamKey, -1);
5959

60-
attr = manager.attribute(stream);
60+
attr = manager.attribute(streamKey);
6161
assertEquals(-1, attr.disabledTill);
6262
assertNotEquals(0, attr.updatedAt);
6363

64-
manager.enable(stream);
65-
attr = manager.attribute(stream);
64+
manager.enable(streamKey);
65+
attr = manager.attribute(streamKey);
6666
assertEquals(0, attr.disabledTill);
6767
assertNotEquals(0, attr.updatedAt);
6868

6969
long t = System.currentTimeMillis() / 1000 + 3600;
70-
manager.disableTill(stream, t);
71-
attr = manager.attribute(stream);
70+
manager.disableTill(streamKey, t);
71+
attr = manager.attribute(streamKey);
7272
assertEquals(t, attr.disabledTill);
7373
assertNotEquals(0, attr.updatedAt);
7474

75-
manager.enable(stream);
76-
attr = manager.attribute(stream);
75+
manager.enable(streamKey);
76+
attr = manager.attribute(streamKey);
7777
assertEquals(0, attr.disabledTill);
7878
assertNotEquals(0, attr.updatedAt);
7979

8080
try {
81-
manager.status(stream);
81+
StreamStatus status = manager.status(streamKey);
8282
fail();
8383
} catch (QiniuException e) {
8484
assertEquals(619, e.code());
8585
}
8686

8787
try {
88-
manager.saveAs(stream, null, 0, 0);
88+
manager.saveAs(streamKey, null, 0, 0);
8989
fail();
9090
} catch (QiniuException e) {
9191
assertEquals(619, e.code());
9292
}
9393

94-
ActivityRecords records = manager.history(stream, System.currentTimeMillis() / 1000 - 1000, 0);
94+
ActivityRecords records = manager.history(streamKey, System.currentTimeMillis() / 1000 - 1000, 0);
9595
assertEquals(0, records.items.length);
9696

9797
StreamListing l = manager.listStreams(false, streamKeyPrefix, null);
@@ -118,31 +118,34 @@ public void testStreamOperation() throws QiniuException {
118118
assertFalse(it.hasNext());
119119
}
120120

121-
/**
122-
* 测试saveas
123-
* 检测返回状态码是否是404
124-
* @throws QiniuException
125-
*/
126-
@Test
121+
//@Test
127122
public void testSaveAs() throws QiniuException {
128123
try {
129-
manager.saveAs(streamNoExist, "f\"ff.m3u8");
124+
manager.saveAs("test--sd", "f\"ff.m3u8");
130125
} catch (QiniuException e) {
131-
assertEquals(404, e.response.statusCode);
126+
// 619 , no data; 612 stream not found, 但请求正常 //
127+
if (e.code() != 619 && e.code() != 612) {
128+
throw e;
129+
}
132130
}
133131
}
134132

135-
/**
136-
* 测试创建流
137-
* 检测返回状态码是否为614
138-
* @throws QiniuException
139-
*/
140-
@Test
133+
//@Test
141134
public void testCreate() throws QiniuException {
142135
try {
143-
manager.create(stream);
136+
String body = String.format("{\"key\":\"%s\"}", "stream\"Key");
137+
System.out.println(body);
138+
Json.decode(body);
139+
fail("json 解析不正确");
140+
} catch (JsonSyntaxException e) {
141+
142+
}
143+
try {
144+
manager.create("streamKey");
144145
} catch (QiniuException e) {
145-
assertEquals(614, e.code());
146+
if (e.code() != 614) {
147+
throw e;
148+
}
146149
}
147150
}
148151

0 commit comments

Comments
 (0)