11package test .com .qiniu .streaming ;
22
3+ import com .google .gson .JsonSyntaxException ;
34import com .qiniu .common .QiniuException ;
45import com .qiniu .streaming .StreamingManager ;
56import com .qiniu .streaming .model .ActivityRecords ;
67import com .qiniu .streaming .model .StreamAttribute ;
78import com .qiniu .streaming .model .StreamListing ;
9+ import com .qiniu .streaming .model .StreamStatus ;
810import com .qiniu .util .Auth ;
11+ import com .qiniu .util .Json ;
912import org .junit .Test ;
1013import test .com .qiniu .TestConfig ;
1114
1215import static org .junit .Assert .*;
1316
1417/**
1518 * Created by bailong on 16/9/22
16- * Updated by panyuan on 19/3/12
1719 */
1820public 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