test_oss_resumable.c 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423
  1. #include "CuTest.h"
  2. #include "aos_log.h"
  3. #include "aos_util.h"
  4. #include "aos_string.h"
  5. #include "aos_status.h"
  6. #include "oss_auth.h"
  7. #include "oss_util.h"
  8. #include "oss_xml.h"
  9. #include "oss_api.h"
  10. #include "oss_config.h"
  11. #include "oss_test_util.h"
  12. #include "aos_crc64.h"
  13. #if defined(WIN32)
  14. static char *test_local_file = "..\\oss_c_sdk_test\\BingWallpaper-2017-01-19.jpg";
  15. #else
  16. static char *test_local_file = "oss_c_sdk_test/BingWallpaper-2017-01-19.jpg";
  17. #endif
  18. void test_resumable_setup(CuTest *tc)
  19. {
  20. aos_pool_t *p = NULL;
  21. int is_cname = 0;
  22. aos_status_t *s = NULL;
  23. oss_request_options_t *options = NULL;
  24. oss_acl_e oss_acl = OSS_ACL_PRIVATE;
  25. /* create test bucket */
  26. aos_pool_create(&p, NULL);
  27. options = oss_request_options_create(p);
  28. init_test_request_options(options, is_cname);
  29. s = create_test_bucket(options, TEST_BUCKET_NAME, oss_acl);
  30. CuAssertIntEquals(tc, 200, s->code);
  31. aos_pool_destroy(p);
  32. }
  33. void test_resumable_cleanup(CuTest *tc)
  34. {
  35. aos_pool_t *p = NULL;
  36. int is_cname = 0;
  37. aos_string_t bucket;
  38. oss_request_options_t *options = NULL;
  39. aos_table_t *resp_headers = NULL;
  40. aos_pool_create(&p, NULL);
  41. options = oss_request_options_create(p);
  42. init_test_request_options(options, is_cname);
  43. /* delete test object */
  44. delete_test_object(options, TEST_BUCKET_NAME, "test_resumable_upload_without_checkpoint.jpg");
  45. delete_test_object(options, TEST_BUCKET_NAME, "test_resumable_upload_partsize.jpg");
  46. delete_test_object(options, TEST_BUCKET_NAME, "test_resumable_upload_threads.jpg");
  47. delete_test_object(options, TEST_BUCKET_NAME, "test_resumable_upload_with_checkpoint.jpg");
  48. delete_test_object(options, TEST_BUCKET_NAME, "test_resumable_upload_with_checkpoint_format_invalid.jpg");
  49. delete_test_object(options, TEST_BUCKET_NAME, "test_resumable_upload_with_file_size_unavailable.jpg");
  50. delete_test_object(options, TEST_BUCKET_NAME, "test_resumable_upload_with_uploadid_unavailable.jpg");
  51. delete_test_object(options, TEST_BUCKET_NAME, "test_resumable_upload_with_uploadid_available.jpg");
  52. delete_test_object(options, TEST_BUCKET_NAME, "test_resumable_upload_callback_without_checkpoint.jpg");
  53. delete_test_object(options, TEST_BUCKET_NAME, "test_resumable_upload_progress_without_checkpoint.jpg");
  54. delete_test_object(options, TEST_BUCKET_NAME, "test_resumable_upload_callback_with_checkpoint.jpg");
  55. delete_test_object(options, TEST_BUCKET_NAME, "test_resumable_upload_progress_with_checkpoint.jpg");
  56. /* delete test bucket */
  57. aos_str_set(&bucket, TEST_BUCKET_NAME);
  58. oss_delete_bucket(options, &bucket, &resp_headers);
  59. apr_sleep(apr_time_from_sec(3));
  60. aos_pool_destroy(p);
  61. }
  62. static int aos_curl_http_transport_perform_random_failure(aos_http_transport_t *t_)
  63. {
  64. aos_curl_http_transport_t *t = (aos_curl_http_transport_t *)(t_);
  65. int ret = aos_curl_http_transport_perform(t_);
  66. if (rand() % 4 == 0) {
  67. t->controller->error_code = AOSE_INTERNAL_ERROR;
  68. t->controller->reason = "Internal error for test";
  69. ret = t->controller->error_code;
  70. }
  71. return ret;
  72. }
  73. static int aos_curl_http_transport_perform_bad_crc64(aos_http_transport_t *t_)
  74. {
  75. aos_curl_http_transport_t *t = (aos_curl_http_transport_t *)(t_);
  76. int ret = aos_curl_http_transport_perform(t_);
  77. t->resp->crc64 = rand();
  78. return ret;
  79. }
  80. // ---------------------------- UT ----------------------------
  81. void test_resumable_oss_get_thread_num(CuTest *tc)
  82. {
  83. aos_pool_t *p = NULL;
  84. oss_resumable_clt_params_t *clt_params;
  85. int32_t thread_num = 0;
  86. aos_pool_create(&p, NULL);
  87. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 1024, AOS_FALSE, NULL);
  88. thread_num = oss_get_thread_num(clt_params);
  89. CuAssertIntEquals(tc, 1024, thread_num);
  90. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 0, AOS_FALSE, NULL);
  91. thread_num = oss_get_thread_num(clt_params);
  92. CuAssertIntEquals(tc, 1, thread_num);
  93. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, -1, AOS_FALSE, NULL);
  94. thread_num = oss_get_thread_num(clt_params);
  95. CuAssertIntEquals(tc, 1, thread_num);
  96. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 1025, AOS_FALSE, NULL);
  97. thread_num = oss_get_thread_num(clt_params);
  98. CuAssertIntEquals(tc, 1, thread_num);
  99. aos_pool_destroy(p);
  100. printf("test_resumable_oss_get_thread_num ok\n");
  101. }
  102. void test_resumable_oss_get_checkpoint_path(CuTest *tc)
  103. {
  104. aos_pool_t *p = NULL;
  105. oss_resumable_clt_params_t *clt_params;
  106. aos_string_t file_path = aos_null_string;
  107. aos_string_t checkpoint_path = aos_null_string;
  108. aos_pool_create(&p, NULL);
  109. aos_str_set(&file_path, "D:\\work\\oss\\BingWallpaper-2017-01-19.jpg");
  110. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 1024, AOS_FALSE, NULL);
  111. oss_get_upload_checkpoint_path(clt_params, &file_path, p, &checkpoint_path);
  112. CuAssertTrue(tc, checkpoint_path.data == NULL);
  113. CuAssertTrue(tc, checkpoint_path.len == 0);
  114. oss_get_download_checkpoint_path(clt_params, &file_path, p, &checkpoint_path);
  115. CuAssertTrue(tc, checkpoint_path.data == NULL);
  116. CuAssertTrue(tc, checkpoint_path.len == 0);
  117. aos_str_set(&checkpoint_path, "BingWallpaper-2017-01-19.jpg.checkpoint");
  118. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 1024, AOS_TRUE, checkpoint_path.data);
  119. oss_get_upload_checkpoint_path(clt_params, &file_path, p, &checkpoint_path);
  120. CuAssertStrEquals(tc, "BingWallpaper-2017-01-19.jpg.checkpoint", checkpoint_path.data);
  121. oss_get_download_checkpoint_path(clt_params, &file_path, p, &checkpoint_path);
  122. CuAssertStrEquals(tc, "BingWallpaper-2017-01-19.jpg.checkpoint", checkpoint_path.data);
  123. // win path
  124. aos_str_set(&file_path, "D:\\work\\oss\\BingWallpaper-2017-01-19.jpg");
  125. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 1024, AOS_TRUE, NULL);
  126. oss_get_upload_checkpoint_path(clt_params, &file_path, p, &checkpoint_path);
  127. CuAssertStrEquals(tc, "D:\\work\\oss\\BingWallpaper-2017-01-19.jpg.ucp", checkpoint_path.data);
  128. oss_get_download_checkpoint_path(clt_params, &file_path, p, &checkpoint_path);
  129. CuAssertStrEquals(tc, "D:\\work\\oss\\BingWallpaper-2017-01-19.jpg.dcp", checkpoint_path.data);
  130. aos_str_set(&checkpoint_path, "");
  131. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 1024, AOS_TRUE, NULL);
  132. oss_get_upload_checkpoint_path(clt_params, &file_path, p, &checkpoint_path);
  133. CuAssertStrEquals(tc, "D:\\work\\oss\\BingWallpaper-2017-01-19.jpg.ucp", checkpoint_path.data);
  134. aos_str_set(&checkpoint_path, "");
  135. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 1024, AOS_TRUE, NULL);
  136. oss_get_download_checkpoint_path(clt_params, &file_path, p, &checkpoint_path);
  137. CuAssertStrEquals(tc, "D:\\work\\oss\\BingWallpaper-2017-01-19.jpg.dcp", checkpoint_path.data);
  138. // linux path
  139. aos_str_set(&file_path, "/home/tim/work/oss/BingWallpaper-2017-01-19.jpg");
  140. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 1024, AOS_TRUE, NULL);
  141. oss_get_upload_checkpoint_path(clt_params, &file_path, p, &checkpoint_path);
  142. CuAssertStrEquals(tc, "/home/tim/work/oss/BingWallpaper-2017-01-19.jpg.ucp", checkpoint_path.data);
  143. oss_get_download_checkpoint_path(clt_params, &file_path, p, &checkpoint_path);
  144. CuAssertStrEquals(tc, "/home/tim/work/oss/BingWallpaper-2017-01-19.jpg.dcp", checkpoint_path.data);
  145. aos_str_set(&checkpoint_path, "");
  146. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 1024, AOS_TRUE, NULL);
  147. oss_get_upload_checkpoint_path(clt_params, &file_path, p, &checkpoint_path);
  148. CuAssertStrEquals(tc, "/home/tim/work/oss/BingWallpaper-2017-01-19.jpg.ucp", checkpoint_path.data);
  149. aos_str_set(&checkpoint_path, "");
  150. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 1024, AOS_TRUE, NULL);
  151. oss_get_download_checkpoint_path(clt_params, &file_path, p, &checkpoint_path);
  152. CuAssertStrEquals(tc, "/home/tim/work/oss/BingWallpaper-2017-01-19.jpg.dcp", checkpoint_path.data);
  153. aos_pool_destroy(p);
  154. printf("test_resumable_oss_get_checkpoint_path ok\n");
  155. }
  156. void test_resumable_oss_get_file_info(CuTest *tc)
  157. {
  158. aos_pool_t *p = NULL;
  159. aos_string_t file_path = aos_null_string;
  160. char *local_file = "test_resumable_oss_get_file_info.txt";
  161. apr_finfo_t finfo;
  162. int rv;
  163. aos_pool_create(&p, NULL);
  164. // invalid path
  165. aos_str_set(&file_path, "");
  166. rv = oss_get_file_info(&file_path, p, &finfo);
  167. CuAssertTrue(tc, APR_STATUS_IS_ENOENT(rv));
  168. // file not exist
  169. aos_str_set(&file_path, "/uvwxyz/abchij/test.udp");
  170. rv = oss_get_file_info(&file_path, p, &finfo);
  171. CuAssertTrue(tc, APR_STATUS_IS_ENOENT(rv));
  172. // empty file
  173. rv = fill_test_file(p, local_file, "");
  174. CuAssertIntEquals(tc, APR_SUCCESS, rv);
  175. aos_str_set(&file_path, local_file);
  176. rv = oss_get_file_info(&file_path, p, &finfo);
  177. CuAssertIntEquals(tc, AOSE_OK, rv);
  178. CuAssertTrue(tc, 0 == finfo.size);
  179. // normal
  180. rv = make_random_file(p, local_file, 1024);
  181. CuAssertIntEquals(tc, APR_SUCCESS, rv);
  182. rv = oss_get_file_info(&file_path, p, &finfo);
  183. CuAssertIntEquals(tc, AOSE_OK, rv);
  184. CuAssertTrue(tc, 1024 == finfo.size);
  185. apr_file_remove(local_file, p);
  186. aos_pool_destroy(p);
  187. printf("test_resumable_oss_get_file_info ok\n");
  188. }
  189. void test_resumable_oss_does_file_exist(CuTest *tc)
  190. {
  191. aos_pool_t *p = NULL;
  192. aos_string_t file_path = aos_null_string;
  193. char *local_file = "test_resumable_oss_does_file_exist.txt";
  194. int rv;
  195. aos_pool_create(&p, NULL);
  196. // invalid path
  197. aos_str_set(&file_path, "");
  198. rv = oss_does_file_exist(&file_path, p);
  199. CuAssertTrue(tc, !rv);
  200. // file not exist
  201. aos_str_set(&file_path, "/uvwxyz/abchij/test.udp");
  202. rv = oss_does_file_exist(&file_path, p);
  203. CuAssertTrue(tc, !rv);
  204. // normal
  205. rv = make_random_file(p, local_file, 1024);
  206. CuAssertIntEquals(tc, APR_SUCCESS, rv);
  207. aos_str_set(&file_path, local_file);
  208. rv = oss_does_file_exist(&file_path, p);
  209. CuAssertTrue(tc, rv);
  210. apr_file_remove(local_file, p);
  211. aos_pool_destroy(p);
  212. printf("test_resumable_oss_does_file_exist ok\n");
  213. }
  214. void test_resumable_oss_dump_checkpoint(CuTest *tc)
  215. {
  216. aos_pool_t *p = NULL;
  217. aos_string_t file_path = aos_null_string;
  218. char *cp_file = "test_resumable_oss_dump_checkpoint.ucp";
  219. oss_checkpoint_t *cp;
  220. apr_finfo_t finfo;
  221. aos_string_t upload_id;
  222. int64_t part_size;
  223. int rv;
  224. aos_pool_create(&p, NULL);
  225. // build checkpoint
  226. finfo.size = 510598;
  227. finfo.mtime = 1459922563;
  228. aos_str_set(&file_path, "D:\\work\\oss\\BingWallpaper-2017-01-19.jpg");
  229. aos_str_set(&upload_id, "0004B9894A22E5B1888A1E29F8236E2D");
  230. part_size = 1024 * 100;
  231. cp = oss_create_checkpoint_content(p);
  232. oss_build_upload_checkpoint(p, cp, &file_path, &finfo, &upload_id, part_size);
  233. aos_str_set(&file_path, cp_file);
  234. rv = oss_open_checkpoint_file(p, &file_path, cp);
  235. CuAssertIntEquals(tc, APR_SUCCESS, rv);
  236. rv = oss_dump_checkpoint(p, cp);
  237. CuAssertIntEquals(tc, AOSE_OK, rv);
  238. apr_file_close(cp->thefile);
  239. // write failed
  240. rv = apr_file_open(&cp->thefile, file_path.data, APR_READ, APR_UREAD | APR_GREAD, p);
  241. CuAssertIntEquals(tc, APR_SUCCESS, rv);
  242. rv = oss_dump_checkpoint(p, cp);
  243. CuAssertIntEquals(tc, AOSE_FILE_TRUNC_ERROR, rv);
  244. apr_file_close(cp->thefile);
  245. apr_file_remove(cp_file, p);
  246. aos_pool_destroy(p);
  247. printf("test_resumable_oss_dump_checkpoint ok\n");
  248. }
  249. void test_resumable_oss_load_checkpoint(CuTest *tc)
  250. {
  251. aos_pool_t *p = NULL;
  252. aos_string_t file_path = aos_null_string;
  253. char *cp_file = "test_resumable_oss_load_checkpoint.ucp";
  254. oss_checkpoint_t *cp;
  255. oss_checkpoint_t *cp_l;
  256. apr_finfo_t finfo;
  257. aos_string_t upload_id;
  258. int64_t part_size;
  259. int rv;
  260. aos_pool_create(&p, NULL);
  261. // build checkpoint
  262. finfo.size = 510598;
  263. finfo.mtime = 1459922563;
  264. aos_str_set(&file_path, "D:\\work\\oss\\BingWallpaper-2017-01-19.jpg");
  265. aos_str_set(&upload_id, "0004B9894A22E5B1888A1E29F8236E2D");
  266. part_size = 1024 * 100;
  267. cp = oss_create_checkpoint_content(p);
  268. oss_build_upload_checkpoint(p, cp, &file_path, &finfo, &upload_id, part_size);
  269. aos_str_set(&file_path, cp_file);
  270. rv = oss_open_checkpoint_file(p, &file_path, cp);
  271. CuAssertIntEquals(tc, APR_SUCCESS, rv);
  272. // dump
  273. rv = oss_dump_checkpoint(p, cp);
  274. CuAssertIntEquals(tc, AOSE_OK, rv);
  275. apr_file_close(cp->thefile);
  276. // load
  277. cp_l = oss_create_checkpoint_content(p);
  278. rv = oss_load_checkpoint(p, &file_path, cp_l);
  279. CuAssertIntEquals(tc, AOSE_OK, rv);
  280. CuAssertStrEquals(tc, cp->md5.data, cp_l->md5.data);
  281. CuAssertIntEquals(tc, cp->cp_type, cp_l->cp_type);
  282. CuAssertStrEquals(tc, cp->upload_id.data, cp_l->upload_id.data);
  283. CuAssertIntEquals(tc, cp->part_num, cp_l->part_num);
  284. CuAssertTrue(tc, cp->part_size == cp_l->part_size);
  285. // load failed
  286. aos_str_set(&file_path, "/uvwxyz/abchij/test.udp");
  287. rv = oss_load_checkpoint(p, &file_path, cp_l);
  288. CuAssertIntEquals(tc, AOSE_OPEN_FILE_ERROR, rv);
  289. // content invalid
  290. rv = make_random_file(p, cp_file, 1024);
  291. CuAssertIntEquals(tc, APR_SUCCESS, rv);
  292. aos_str_set(&file_path, cp_file);
  293. rv = oss_load_checkpoint(p, &file_path, cp_l);
  294. CuAssertIntEquals(tc, AOSE_XML_PARSE_ERROR, rv);
  295. apr_file_remove(cp_file, p);
  296. aos_pool_destroy(p);
  297. printf("test_resumable_oss_load_checkpoint ok\n");
  298. }
  299. void test_resumable_oss_is_upload_checkpoint_valid(CuTest *tc)
  300. {
  301. aos_pool_t *p = NULL;
  302. aos_string_t file_path = aos_null_string;
  303. oss_checkpoint_t *cp;
  304. apr_finfo_t finfo;
  305. aos_string_t upload_id;
  306. int64_t part_size;
  307. int rv;
  308. aos_pool_create(&p, NULL);
  309. // build checkpoint
  310. finfo.size = 510598;
  311. finfo.mtime = 1459922563;
  312. aos_str_set(&file_path, "D:\\work\\oss\\BingWallpaper-2017-01-19.jpg");
  313. aos_str_set(&upload_id, "0004B9894A22E5B1888A1E29F8236E2D");
  314. part_size = 1024 * 100;
  315. cp = oss_create_checkpoint_content(p);
  316. oss_build_upload_checkpoint(p, cp, &file_path, &finfo, &upload_id, part_size);
  317. rv = oss_is_upload_checkpoint_valid(p, cp, &finfo);
  318. CuAssertTrue(tc, rv);
  319. finfo.size = 510599;
  320. rv = oss_is_upload_checkpoint_valid(p, cp, &finfo);
  321. CuAssertTrue(tc, !rv);
  322. finfo.mtime = 1459922562;
  323. rv = oss_is_upload_checkpoint_valid(p, cp, &finfo);
  324. CuAssertTrue(tc, !rv);
  325. aos_pool_destroy(p);
  326. printf("test_resumable_oss_is_upload_checkpoint_valid ok\n");
  327. }
  328. void test_resumable_checkpoint_xml(CuTest *tc)
  329. {
  330. aos_pool_t *p = NULL;
  331. char *xml_doc = NULL;
  332. oss_checkpoint_t *cp;
  333. int64_t part_size = 0;
  334. int i = 0;
  335. oss_checkpoint_t *cp_actual;
  336. const char *xml_doc_expected =
  337. "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
  338. "<Checkpoint><MD5></MD5><Type>1</Type>"
  339. "<LocalFile>"
  340. "<Path>D:\\work\\oss\\BingWallpaper-2017-01-19.jpg</Path><Size>510598</Size>"
  341. "<LastModified>1459922563</LastModified><MD5>fba9dede5f27731c9771645a39863328</MD5>"
  342. "</LocalFile>"
  343. "<Object>"
  344. "<Key>~/oss/BingWallpaper-2017-01-19.jpg</Key><Size>510598</Size>"
  345. "<LastModified>Fri, 24 Feb 2012 06:07:48 GMT</LastModified><ETag>0F7230CAA4BE94CCBDC99C5500000000</ETag>"
  346. "</Object>"
  347. "<UploadId>0004B9894A22E5B1888A1E29F8236E2D</UploadId>"
  348. "<CPParts>"
  349. "<Number>5</Number><Size>102400</Size>"
  350. "<Parts>"
  351. "<Part><Index>0</Index><Offset>0</Offset><Size>102400</Size><Completed>1</Completed><ETag></ETag><Crc64>0</Crc64></Part>"
  352. "<Part><Index>1</Index><Offset>102400</Offset><Size>102400</Size><Completed>1</Completed><ETag></ETag><Crc64>0</Crc64></Part>"
  353. "<Part><Index>2</Index><Offset>204800</Offset><Size>102400</Size><Completed>1</Completed><ETag></ETag><Crc64>0</Crc64></Part>"
  354. "<Part><Index>3</Index><Offset>307200</Offset><Size>102400</Size><Completed>1</Completed><ETag></ETag><Crc64>0</Crc64></Part>"
  355. "<Part><Index>4</Index><Offset>409600</Offset><Size>100998</Size><Completed>1</Completed><ETag></ETag><Crc64>0</Crc64></Part>"
  356. "</Parts>"
  357. "</CPParts>"
  358. "</Checkpoint>\n";
  359. aos_pool_create(&p, NULL);
  360. cp = oss_create_checkpoint_content(p);
  361. cp->cp_type = OSS_CP_UPLOAD;
  362. aos_str_set(&cp->file_path, "D:\\work\\oss\\BingWallpaper-2017-01-19.jpg");
  363. cp->file_size = 510598;
  364. cp->file_last_modified = 1459922563;
  365. aos_str_set(&cp->file_md5,"fba9dede5f27731c9771645a39863328");
  366. aos_str_set(&cp->object_name, "~/oss/BingWallpaper-2017-01-19.jpg");
  367. cp->object_size = 510598;
  368. aos_str_set(&cp->object_last_modified, "Fri, 24 Feb 2012 06:07:48 GMT");
  369. aos_str_set(&cp->object_etag, "0F7230CAA4BE94CCBDC99C5500000000");
  370. aos_str_set(&cp->upload_id, "0004B9894A22E5B1888A1E29F8236E2D");
  371. part_size = 1024 * 100;
  372. oss_get_part_size(cp->file_size, &part_size);
  373. cp->part_size = part_size;
  374. for (i = 0; i * part_size < cp->file_size; i++) {
  375. cp->parts[i].index = i;
  376. cp->parts[i].offset = i * part_size;
  377. cp->parts[i].size = aos_min(part_size, (cp->file_size - i * part_size));
  378. cp->parts[i].completed = AOS_TRUE;
  379. aos_str_set(& cp->parts[i].etag, "");
  380. }
  381. cp->part_num = i;
  382. xml_doc = oss_build_checkpoint_xml(p ,cp);
  383. CuAssertStrEquals(tc, xml_doc_expected, xml_doc);
  384. cp_actual = oss_create_checkpoint_content(p);
  385. oss_checkpoint_parse_from_body(p, xml_doc, cp_actual);
  386. CuAssertIntEquals(tc, OSS_CP_UPLOAD, cp_actual->cp_type);
  387. CuAssertStrEquals(tc, "", cp_actual->md5.data);
  388. CuAssertStrEquals(tc, "D:\\work\\oss\\BingWallpaper-2017-01-19.jpg", cp_actual->file_path.data);
  389. CuAssertTrue(tc, 510598 == cp_actual->file_size);
  390. CuAssertTrue(tc, 1459922563 == cp_actual->file_last_modified);
  391. CuAssertStrEquals(tc, "fba9dede5f27731c9771645a39863328", cp_actual->file_md5.data);
  392. CuAssertStrEquals(tc, "~/oss/BingWallpaper-2017-01-19.jpg", cp_actual->object_name.data);
  393. CuAssertTrue(tc, 510598 == cp_actual->file_size);
  394. CuAssertStrEquals(tc, "Fri, 24 Feb 2012 06:07:48 GMT", cp_actual->object_last_modified.data);
  395. CuAssertStrEquals(tc, "0F7230CAA4BE94CCBDC99C5500000000", cp_actual->object_etag.data);
  396. CuAssertStrEquals(tc, "0004B9894A22E5B1888A1E29F8236E2D", cp_actual->upload_id.data);
  397. CuAssertIntEquals(tc, 5, cp_actual->part_num);
  398. CuAssertTrue(tc, 102400 == cp_actual->part_size);
  399. CuAssertIntEquals(tc, 4, cp_actual->parts[4].index);
  400. CuAssertTrue(tc, 409600 == cp_actual->parts[4].offset);
  401. CuAssertTrue(tc, 100998 == cp_actual->parts[4].size);
  402. CuAssertIntEquals(tc, 1, cp_actual->parts[4].completed);
  403. aos_pool_destroy(p);
  404. printf("test_resumable_checkpoint_xml ok\n");
  405. }
  406. // ---------------------------- FT ----------------------------
  407. void test_resumable_upload_without_checkpoint(CuTest *tc)
  408. {
  409. aos_pool_t *p = NULL;
  410. char *object_name = "test_resumable_upload_without_checkpoint.jpg";
  411. aos_string_t bucket;
  412. aos_string_t object;
  413. aos_string_t filename;
  414. aos_status_t *s = NULL;
  415. int is_cname = 0;
  416. aos_table_t *headers = NULL;
  417. aos_table_t *resp_headers = NULL;
  418. aos_list_t resp_body;
  419. oss_request_options_t *options = NULL;
  420. oss_resumable_clt_params_t *clt_params;
  421. int64_t content_length = 0;
  422. aos_pool_create(&p, NULL);
  423. options = oss_request_options_create(p);
  424. init_test_request_options(options, is_cname);
  425. headers = aos_table_make(p, 0);
  426. aos_str_set(&bucket, TEST_BUCKET_NAME);
  427. aos_str_set(&object, object_name);
  428. aos_list_init(&resp_body);
  429. aos_str_set(&filename, test_local_file);
  430. // upload object
  431. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_FALSE, NULL);
  432. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  433. clt_params, NULL, &resp_headers, &resp_body);
  434. CuAssertIntEquals(tc, 200, s->code);
  435. aos_pool_destroy(p);
  436. // head object
  437. aos_pool_create(&p, NULL);
  438. options = oss_request_options_create(p);
  439. init_test_request_options(options, is_cname);
  440. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  441. CuAssertIntEquals(tc, 200, s->code);
  442. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  443. CuAssertTrue(tc, content_length == get_file_size(test_local_file));
  444. aos_pool_destroy(p);
  445. printf("test_resumable_upload_without_checkpoint ok\n");
  446. }
  447. void test_resumable_upload_partsize(CuTest *tc)
  448. {
  449. aos_pool_t *p = NULL;
  450. char *object_name = "test_resumable_upload_partsize.jpg";
  451. aos_string_t bucket;
  452. aos_string_t object;
  453. aos_string_t filename;
  454. aos_status_t *s = NULL;
  455. int is_cname = 0;
  456. aos_table_t *headers = NULL;
  457. aos_table_t *resp_headers = NULL;
  458. aos_list_t resp_body;
  459. oss_request_options_t *options = NULL;
  460. oss_resumable_clt_params_t *clt_params;
  461. int64_t content_length = 0;
  462. aos_pool_create(&p, NULL);
  463. options = oss_request_options_create(p);
  464. init_test_request_options(options, is_cname);
  465. headers = aos_table_make(p, 0);
  466. aos_str_set(&bucket, TEST_BUCKET_NAME);
  467. aos_str_set(&object, object_name);
  468. aos_list_init(&resp_body);
  469. aos_str_set(&filename, test_local_file);
  470. // upload object with part size 10MB
  471. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 1024 * 10, 3, AOS_FALSE, NULL);
  472. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  473. clt_params, NULL, &resp_headers, &resp_body);
  474. CuAssertIntEquals(tc, 200, s->code);
  475. aos_pool_destroy(p);
  476. // head object
  477. aos_pool_create(&p, NULL);
  478. options = oss_request_options_create(p);
  479. init_test_request_options(options, is_cname);
  480. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  481. CuAssertIntEquals(tc, 200, s->code);
  482. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  483. CuAssertTrue(tc, content_length == get_file_size(test_local_file));
  484. aos_pool_destroy(p);
  485. // upload object with part size 200K
  486. aos_pool_create(&p, NULL);
  487. options = oss_request_options_create(p);
  488. init_test_request_options(options, is_cname);
  489. headers = aos_table_make(p, 0);
  490. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 200, 3, AOS_FALSE, NULL);
  491. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  492. clt_params, NULL, &resp_headers, &resp_body);
  493. CuAssertIntEquals(tc, 200, s->code);
  494. aos_pool_destroy(p);
  495. // head object
  496. aos_pool_create(&p, NULL);
  497. options = oss_request_options_create(p);
  498. init_test_request_options(options, is_cname);
  499. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  500. CuAssertIntEquals(tc, 200, s->code);
  501. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  502. CuAssertTrue(tc, content_length == get_file_size(test_local_file));
  503. aos_pool_destroy(p);
  504. printf("test_resumable_upload_partsize ok\n");
  505. }
  506. void test_resumable_upload_threads(CuTest *tc)
  507. {
  508. aos_pool_t *p = NULL;
  509. char *object_name = "test_resumable_upload_threads.jpg";
  510. aos_string_t bucket;
  511. aos_string_t object;
  512. aos_string_t filename;
  513. aos_status_t *s = NULL;
  514. int is_cname = 0;
  515. aos_table_t *headers = NULL;
  516. aos_table_t *resp_headers = NULL;
  517. aos_list_t resp_body;
  518. oss_request_options_t *options = NULL;
  519. oss_resumable_clt_params_t *clt_params;
  520. int64_t content_length = 0;
  521. aos_pool_create(&p, NULL);
  522. options = oss_request_options_create(p);
  523. init_test_request_options(options, is_cname);
  524. headers = aos_table_make(p, 0);
  525. aos_str_set(&bucket, TEST_BUCKET_NAME);
  526. aos_str_set(&object, object_name);
  527. aos_list_init(&resp_body);
  528. aos_str_set(&filename, test_local_file);
  529. // upload object with thread 1
  530. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 1, AOS_FALSE, NULL);
  531. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  532. clt_params, NULL, &resp_headers, &resp_body);
  533. CuAssertIntEquals(tc, 200, s->code);
  534. aos_pool_destroy(p);
  535. // head object
  536. aos_pool_create(&p, NULL);
  537. options = oss_request_options_create(p);
  538. init_test_request_options(options, is_cname);
  539. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  540. CuAssertIntEquals(tc, 200, s->code);
  541. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  542. CuAssertTrue(tc, content_length == get_file_size(test_local_file));
  543. aos_pool_destroy(p);
  544. // upload object with thread 5
  545. aos_pool_create(&p, NULL);
  546. options = oss_request_options_create(p);
  547. init_test_request_options(options, is_cname);
  548. headers = aos_table_make(p, 0);
  549. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 200, 5, AOS_FALSE, NULL);
  550. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  551. clt_params, NULL, &resp_headers, &resp_body);
  552. CuAssertIntEquals(tc, 200, s->code);
  553. aos_pool_destroy(p);
  554. // head object
  555. aos_pool_create(&p, NULL);
  556. options = oss_request_options_create(p);
  557. init_test_request_options(options, is_cname);
  558. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  559. CuAssertIntEquals(tc, 200, s->code);
  560. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  561. CuAssertTrue(tc, content_length == get_file_size(test_local_file));
  562. aos_pool_destroy(p);
  563. // upload object with thread 10
  564. aos_pool_create(&p, NULL);
  565. options = oss_request_options_create(p);
  566. init_test_request_options(options, is_cname);
  567. headers = aos_table_make(p, 0);
  568. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 10, AOS_FALSE, NULL);
  569. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  570. clt_params, NULL, &resp_headers, &resp_body);
  571. CuAssertIntEquals(tc, 200, s->code);
  572. aos_pool_destroy(p);
  573. // head object
  574. aos_pool_create(&p, NULL);
  575. options = oss_request_options_create(p);
  576. init_test_request_options(options, is_cname);
  577. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  578. CuAssertIntEquals(tc, 200, s->code);
  579. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  580. CuAssertTrue(tc, content_length == get_file_size(test_local_file));
  581. aos_pool_destroy(p);
  582. printf("test_resumable_upload_threads ok\n");
  583. }
  584. void test_resumable_upload_with_checkpoint(CuTest *tc)
  585. {
  586. aos_pool_t *p = NULL;
  587. char *object_name = "test_resumable_upload_with_checkpoint.jpg";
  588. aos_string_t bucket;
  589. aos_string_t object;
  590. aos_string_t filename;
  591. aos_status_t *s = NULL;
  592. int is_cname = 0;
  593. aos_table_t *headers = NULL;
  594. aos_table_t *resp_headers = NULL;
  595. aos_list_t resp_body;
  596. oss_request_options_t *options = NULL;
  597. oss_resumable_clt_params_t *clt_params;
  598. int64_t content_length = 0;
  599. aos_pool_create(&p, NULL);
  600. options = oss_request_options_create(p);
  601. init_test_request_options(options, is_cname);
  602. headers = aos_table_make(p, 0);
  603. aos_str_set(&bucket, TEST_BUCKET_NAME);
  604. aos_str_set(&object, object_name);
  605. aos_list_init(&resp_body);
  606. aos_str_set(&filename, test_local_file);
  607. // upload object
  608. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  609. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  610. clt_params, NULL, &resp_headers, &resp_body);
  611. CuAssertIntEquals(tc, 200, s->code);
  612. aos_pool_destroy(p);
  613. // head object
  614. aos_pool_create(&p, NULL);
  615. options = oss_request_options_create(p);
  616. init_test_request_options(options, is_cname);
  617. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  618. CuAssertIntEquals(tc, 200, s->code);
  619. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  620. CuAssertTrue(tc, content_length == get_file_size(test_local_file));
  621. aos_pool_destroy(p);
  622. printf("test_resumable_upload_with_checkpoint ok\n");
  623. }
  624. void test_resumable_upload_with_checkpoint_format_invalid(CuTest *tc)
  625. {
  626. aos_pool_t *p = NULL;
  627. char *object_name = "test_resumable_upload_with_checkpoint_format_invalid.jpg";
  628. aos_string_t bucket;
  629. aos_string_t object;
  630. aos_string_t filename;
  631. aos_status_t *s = NULL;
  632. int is_cname = 0;
  633. aos_table_t *headers = NULL;
  634. aos_table_t *resp_headers = NULL;
  635. aos_list_t resp_body;
  636. oss_request_options_t *options = NULL;
  637. oss_resumable_clt_params_t *clt_params;
  638. int64_t content_length = 0;
  639. aos_string_t checkpoint_path;
  640. aos_pool_create(&p, NULL);
  641. options = oss_request_options_create(p);
  642. init_test_request_options(options, is_cname);
  643. headers = aos_table_make(p, 0);
  644. aos_str_set(&bucket, TEST_BUCKET_NAME);
  645. aos_str_set(&object, object_name);
  646. aos_list_init(&resp_body);
  647. aos_str_set(&filename, test_local_file);
  648. // generate checkpoint
  649. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  650. oss_get_upload_checkpoint_path(clt_params, &filename, p, &checkpoint_path);
  651. fill_test_file(p, checkpoint_path.data, "HiOSS");
  652. // upload object
  653. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  654. clt_params, NULL, &resp_headers, &resp_body);
  655. CuAssertIntEquals(tc, 200, s->code);
  656. aos_pool_destroy(p);
  657. // head object
  658. aos_pool_create(&p, NULL);
  659. options = oss_request_options_create(p);
  660. init_test_request_options(options, is_cname);
  661. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  662. CuAssertIntEquals(tc, 200, s->code);
  663. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  664. CuAssertTrue(tc, content_length == get_file_size(test_local_file));
  665. aos_pool_destroy(p);
  666. printf("test_resumable_upload_with_checkpoint_format_invalid ok\n");
  667. }
  668. void test_resumable_upload_with_checkpoint_path_invalid(CuTest *tc)
  669. {
  670. aos_pool_t *p = NULL;
  671. char *object_name = "test_resumable_upload_with_checkpoint.jpg";
  672. aos_string_t bucket;
  673. aos_string_t object;
  674. aos_string_t filename;
  675. aos_status_t *s = NULL;
  676. int is_cname = 0;
  677. aos_table_t *headers = NULL;
  678. aos_table_t *resp_headers = NULL;
  679. aos_list_t resp_body;
  680. oss_request_options_t *options = NULL;
  681. oss_resumable_clt_params_t *clt_params;
  682. char *cp_path = "/uvwxyz/abchij/test.udp";
  683. aos_pool_create(&p, NULL);
  684. options = oss_request_options_create(p);
  685. init_test_request_options(options, is_cname);
  686. headers = aos_table_make(p, 0);
  687. aos_str_set(&bucket, TEST_BUCKET_NAME);
  688. aos_str_set(&object, object_name);
  689. aos_list_init(&resp_body);
  690. aos_str_set(&filename, test_local_file);
  691. // upload
  692. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, cp_path);
  693. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  694. clt_params, NULL, &resp_headers, &resp_body);
  695. CuAssertStrEquals(tc, "OpenFileFail", s->error_code);
  696. aos_pool_destroy(p);
  697. printf("test_resumable_upload_with_checkpoint_path_invalid ok\n");
  698. }
  699. void test_resumable_upload_with_file_size_unavailable(CuTest *tc)
  700. {
  701. aos_pool_t *p = NULL;
  702. char *object_name = "test_resumable_upload_with_file_size_unavailable.jpg";
  703. aos_string_t bucket;
  704. aos_string_t object;
  705. aos_string_t filename;
  706. aos_status_t *s = NULL;
  707. int is_cname = 0;
  708. aos_table_t *headers = NULL;
  709. aos_table_t *resp_headers = NULL;
  710. aos_list_t resp_body;
  711. oss_request_options_t *options = NULL;
  712. oss_resumable_clt_params_t *clt_params;
  713. int64_t content_length = 0;
  714. aos_string_t checkpoint_path;
  715. char *xml_doc = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
  716. "<Checkpoint>"
  717. "<MD5></MD5><Type>1</Type>"
  718. "<LocalFile>"
  719. "<Path>/home/baiyb/work/tmp/aliyun-oss-c-sdk-doing/BingWallpaper-2017-01-19.jpg</Path>"
  720. "<Size>0</Size><LastModified>1484790044000000</LastModified><MD5></MD5>"
  721. "</LocalFile>"
  722. "<Object>"
  723. "<Key></Key><Size>0</Size><LastModified></LastModified><ETag></ETag>"
  724. "</Object>"
  725. "<UploadId>750FBF7EB9104D4F8DDB74F0432A821F</UploadId>"
  726. "<CPParts>"
  727. "<Number>8</Number><Size>102400</Size>"
  728. "<Parts>"
  729. "<Part><Index>0</Index><Offset>0</Offset><Size>102400</Size><Completed>1</Completed><ETag>&quot;06336E9660D3D9610C79835D27F4D2EF&quot;</ETag></Part>"
  730. "<Part><Index>1</Index><Offset>102400</Offset><Size>102400</Size><Completed>1</Completed><ETag>&quot;D1C009C43EAA5E64B6B794E47BA37917&quot;</ETag></Part>"
  731. "<Part><Index>2</Index><Offset>204800</Offset><Size>102400</Size><Completed>1</Completed><ETag>&quot;073D2D906CEB0FADA1F2BA8A0BA54C1D&quot;</ETag></Part>"
  732. "<Part><Index>3</Index><Offset>307200</Offset><Size>102400</Size><Completed>1</Completed><ETag>&quot;7BA3B455E7B30D734F2CA29548E8BC56&quot;</ETag></Part>"
  733. "<Part><Index>4</Index><Offset>409600</Offset><Size>102400</Size><Completed>1</Completed><ETag>&quot;296F06C36E3746CD2A28824D3B4F0648&quot;</ETag></Part>"
  734. "<Part><Index>5</Index><Offset>512000</Offset><Size>102400</Size><Completed>1</Completed><ETag>&quot;06A0A19EC60DD4F51344D900BE543C53&quot;</ETag></Part>"
  735. "<Part><Index>6</Index><Offset>614400</Offset><Size>102400</Size><Completed>1</Completed><ETag>&quot;B7CE941E6AC00B6B3423572A87EA0B67&quot;</ETag></Part>"
  736. "<Part><Index>7</Index><Offset>716800</Offset><Size>52886</Size><Completed>1</Completed><ETag>&quot;AE5EEAEBB54232A6F71743AA45A32DA9&quot;</ETag></Part>"
  737. "</Parts>"
  738. "</CPParts>"
  739. "</Checkpoint>";
  740. aos_pool_create(&p, NULL);
  741. options = oss_request_options_create(p);
  742. init_test_request_options(options, is_cname);
  743. headers = aos_table_make(p, 0);
  744. aos_str_set(&bucket, TEST_BUCKET_NAME);
  745. aos_str_set(&object, object_name);
  746. aos_list_init(&resp_body);
  747. aos_str_set(&filename, test_local_file);
  748. // generate checkpoint
  749. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  750. oss_get_upload_checkpoint_path(clt_params, &filename, p, &checkpoint_path);
  751. fill_test_file(p, checkpoint_path.data, xml_doc);
  752. // upload object
  753. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  754. clt_params, NULL, &resp_headers, &resp_body);
  755. CuAssertIntEquals(tc, 200, s->code);
  756. aos_pool_destroy(p);
  757. // head object
  758. aos_pool_create(&p, NULL);
  759. options = oss_request_options_create(p);
  760. init_test_request_options(options, is_cname);
  761. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  762. CuAssertIntEquals(tc, 200, s->code);
  763. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  764. CuAssertTrue(tc, content_length == get_file_size(test_local_file));
  765. aos_pool_destroy(p);
  766. printf("test_resumable_upload_with_file_size_unavailable ok\n");
  767. }
  768. void test_resumable_upload_with_uploadid_unavailable(CuTest *tc)
  769. {
  770. aos_pool_t *p = NULL;
  771. char *object_name = "test_resumable_upload_with_uploadid_unavailable.jpg";
  772. aos_string_t bucket;
  773. aos_string_t object;
  774. aos_string_t filename;
  775. aos_status_t *s = NULL;
  776. int is_cname = 0;
  777. aos_table_t *headers = NULL;
  778. aos_table_t *resp_headers = NULL;
  779. aos_list_t resp_body;
  780. apr_finfo_t finfo;
  781. oss_request_options_t *options = NULL;
  782. oss_resumable_clt_params_t *clt_params;
  783. char *cp_path = "d:\\work\\oss\\test.ucp";
  784. char *xml_doc = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
  785. "<Checkpoint><MD5></MD5><Type>1</Type><LocalFile>"
  786. "<Path>oss_c_sdk_test/BingWallpaper-2017-01-19.jpg</Path>"
  787. "<Size>769686</Size><LastModified>%"
  788. APR_INT64_T_FMT
  789. "</LastModified><MD5></MD5></LocalFile>"
  790. "<Object><Key></Key><Size>0</Size><LastModified></LastModified><ETag></ETag></Object>"
  791. "<UploadId>F5F901B64DF34BEDA60C9B2B0984B</UploadId>"
  792. "<CPParts><Number>1</Number><Size>1048576</Size>"
  793. "<Parts><Part><Index>0</Index><Offset>0</Offset><Size>769686</Size><Completed>0</Completed><ETag></ETag></Part>"
  794. "</Parts></CPParts></Checkpoint>";
  795. aos_pool_create(&p, NULL);
  796. options = oss_request_options_create(p);
  797. init_test_request_options(options, is_cname);
  798. headers = aos_table_make(p, 0);
  799. aos_str_set(&bucket, TEST_BUCKET_NAME);
  800. aos_str_set(&object, object_name);
  801. aos_list_init(&resp_body);
  802. aos_str_set(&filename, test_local_file);
  803. // generate checkpoint
  804. oss_get_file_info(&filename, p, &finfo);
  805. xml_doc = apr_psprintf(p, xml_doc, finfo.mtime);
  806. fill_test_file(p, cp_path, xml_doc);
  807. // upload object
  808. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 1024, 1, AOS_TRUE, cp_path);
  809. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  810. clt_params, NULL, &resp_headers, &resp_body);
  811. CuAssertIntEquals(tc, 404, s->code);
  812. //CuAssertStrEquals(tc, "NoSuchUpload", s->error_code);
  813. apr_file_remove(cp_path, p);
  814. aos_pool_destroy(p);
  815. printf("test_resumable_upload_with_uploadid_unavailable ok\n");
  816. }
  817. void test_resumable_upload_with_uploadid_available(CuTest *tc)
  818. {
  819. aos_pool_t *p = NULL;
  820. aos_pool_t *pool = NULL;
  821. char *object_name = "test_resumable_upload_with_uploadid_available.jpg";
  822. aos_string_t bucket;
  823. aos_string_t object;
  824. aos_string_t filename;
  825. aos_status_t *s = NULL;
  826. int is_cname = 0;
  827. aos_table_t *headers = NULL;
  828. aos_table_t *resp_headers = NULL;
  829. aos_list_t resp_body;
  830. oss_request_options_t *options = NULL;
  831. oss_resumable_clt_params_t *clt_params;
  832. int64_t content_length = 0;
  833. aos_string_t checkpoint_path;
  834. aos_string_t upload_id;
  835. char *xml_doc = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
  836. "<Checkpoint>"
  837. "<MD5></MD5><Type>1</Type>"
  838. "<LocalFile>"
  839. "<Path>/home/baiyb/work/tmp/aliyun-oss-c-sdk-doing/BingWallpaper-2017-01-19.jpg</Path>"
  840. "<Size>769686</Size><LastModified>1484790044000000</LastModified><MD5></MD5>"
  841. "</LocalFile>"
  842. "<Object>"
  843. "<Key></Key><Size>0</Size><LastModified></LastModified><ETag></ETag>"
  844. "</Object>"
  845. "<UploadId>%.*s</UploadId>"
  846. "<CPParts>"
  847. "<Number>8</Number><Size>102400</Size>"
  848. "<Parts>"
  849. "<Part><Index>0</Index><Offset>0</Offset><Size>102400</Size><Completed>0</Completed><ETag></ETag></Part>"
  850. "<Part><Index>1</Index><Offset>102400</Offset><Size>102400</Size><Completed>0</Completed><ETag></ETag></Part>"
  851. "<Part><Index>2</Index><Offset>204800</Offset><Size>102400</Size><Completed>0</Completed><ETag></ETag></Part>"
  852. "<Part><Index>3</Index><Offset>307200</Offset><Size>102400</Size><Completed>0</Completed><ETag></ETag></Part>"
  853. "<Part><Index>4</Index><Offset>409600</Offset><Size>102400</Size><Completed>0</Completed><ETag></ETag></Part>"
  854. "<Part><Index>5</Index><Offset>512000</Offset><Size>102400</Size><Completed>0</Completed><ETag></ETag></Part>"
  855. "<Part><Index>6</Index><Offset>614400</Offset><Size>102400</Size><Completed>0</Completed><ETag></ETag></Part>"
  856. "<Part><Index>7</Index><Offset>716800</Offset><Size>52886</Size><Completed>0</Completed><ETag></ETag></Part>"
  857. "</Parts>"
  858. "</CPParts>"
  859. "</Checkpoint>";
  860. aos_str_set(&bucket, TEST_BUCKET_NAME);
  861. aos_str_set(&object, object_name);
  862. aos_list_init(&resp_body);
  863. aos_str_set(&filename, test_local_file);
  864. // generate upload id
  865. aos_pool_create(&p, NULL);
  866. aos_pool_create(&pool, NULL);
  867. options = oss_request_options_create(p);
  868. init_test_request_options(options, is_cname);
  869. s = oss_init_multipart_upload(options, &bucket, &object, &upload_id, headers, &resp_headers);
  870. CuAssertIntEquals(tc, 200, s->code);
  871. xml_doc = apr_psprintf(pool, xml_doc, upload_id.len, upload_id.data);
  872. aos_pool_destroy(p);
  873. // generate checkpoint
  874. aos_pool_create(&p, NULL);
  875. options = oss_request_options_create(p);
  876. init_test_request_options(options, is_cname);
  877. headers = aos_table_make(p, 0);
  878. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  879. oss_get_upload_checkpoint_path(clt_params, &filename, p, &checkpoint_path);
  880. fill_test_file(p, checkpoint_path.data, xml_doc);
  881. // upload object
  882. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  883. clt_params, NULL, &resp_headers, &resp_body);
  884. CuAssertIntEquals(tc, 200, s->code);
  885. aos_pool_destroy(p);
  886. // head object
  887. aos_pool_create(&p, NULL);
  888. options = oss_request_options_create(p);
  889. init_test_request_options(options, is_cname);
  890. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  891. CuAssertIntEquals(tc, 200, s->code);
  892. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  893. CuAssertTrue(tc, content_length == get_file_size(test_local_file));
  894. aos_pool_destroy(p);
  895. aos_pool_destroy(pool);
  896. printf("test_resumable_upload_with_uploadid_available ok\n");
  897. }
  898. void test_resumable_upload_with_file_path_invalid(CuTest *tc)
  899. {
  900. aos_pool_t *p = NULL;
  901. char *object_name = "test_resumable_upload_with_file_path_invalid.jpg";
  902. aos_string_t bucket;
  903. aos_string_t object;
  904. aos_string_t filename;
  905. aos_status_t *s = NULL;
  906. int is_cname = 0;
  907. aos_table_t *headers = NULL;
  908. aos_table_t *resp_headers = NULL;
  909. aos_list_t resp_body;
  910. oss_request_options_t *options = NULL;
  911. oss_resumable_clt_params_t *clt_params;
  912. aos_pool_create(&p, NULL);
  913. options = oss_request_options_create(p);
  914. init_test_request_options(options, is_cname);
  915. headers = aos_table_make(p, 0);
  916. aos_str_set(&bucket, TEST_BUCKET_NAME);
  917. aos_str_set(&object, object_name);
  918. aos_list_init(&resp_body);
  919. aos_str_set(&filename, "/uvwxyz/abchij/test.jpg");
  920. // upload
  921. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 1024, 1, AOS_TRUE, NULL);
  922. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  923. clt_params, NULL, &resp_headers, &resp_body);
  924. CuAssertStrEquals(tc, "OpenFileFail", s->error_code);
  925. aos_pool_destroy(p);
  926. printf("test_resumable_upload_with_file_path_invalid ok\n");
  927. }
  928. void test_resumable_upload_callback_without_checkpoint(CuTest *tc)
  929. {
  930. aos_pool_t *p = NULL;
  931. char *object_name = "test_resumable_upload_callback_without_checkpoint.jpg";
  932. aos_string_t bucket;
  933. aos_string_t object;
  934. aos_string_t filename;
  935. aos_status_t *s = NULL;
  936. int is_cname = 0;
  937. aos_table_t *headers = NULL;
  938. aos_table_t *resp_headers = NULL;
  939. aos_list_t resp_body;
  940. oss_request_options_t *options = NULL;
  941. oss_resumable_clt_params_t *clt_params;
  942. int64_t content_length = 0;
  943. aos_buf_t *content;
  944. char b64_buf[1024];
  945. int b64_len = 64;
  946. char *buf = NULL;
  947. int64_t len = 0;
  948. int64_t size = 0;
  949. int64_t pos = 0;
  950. char *callback = "{"
  951. "\"callbackUrl\":\"http://callback.oss-demo.com:23450\","
  952. "\"callbackHost\":\"oss-cn-hangzhou.aliyuncs.com\","
  953. "\"callbackBody\":\"bucket=${bucket}&object=${object}&size=${size}&mimeType=${mimeType}\","
  954. "\"callbackBodyType\":\"application/x-www-form-urlencoded\""
  955. "}";
  956. char *callback_var = "{"
  957. "\"x:var1\":\"value1\","
  958. "\"x:var2\":\"value2\""
  959. "}";
  960. aos_pool_create(&p, NULL);
  961. options = oss_request_options_create(p);
  962. init_test_request_options(options, is_cname);
  963. aos_str_set(&bucket, TEST_BUCKET_NAME);
  964. aos_str_set(&object, object_name);
  965. aos_list_init(&resp_body);
  966. aos_str_set(&filename, test_local_file);
  967. headers = aos_table_make(p, 2);
  968. b64_len = aos_base64_encode((unsigned char*)callback, strlen(callback), b64_buf);
  969. b64_buf[b64_len] = '\0';
  970. apr_table_set(headers, OSS_CALLBACK, apr_pstrdup(p, b64_buf));
  971. b64_len = aos_base64_encode((unsigned char*)callback_var, strlen(callback_var), b64_buf);
  972. b64_buf[b64_len] = '\0';
  973. apr_table_set(headers, OSS_CALLBACK_VAR, apr_pstrdup(p, b64_buf));
  974. // upload object
  975. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_FALSE, NULL);
  976. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  977. clt_params, NULL, &resp_headers, &resp_body);
  978. CuAssertIntEquals(tc, 200, s->code);
  979. /* get buffer len */
  980. len = aos_buf_list_len(&resp_body);
  981. buf = (char *)aos_pcalloc(p, (apr_size_t)(len + 1));
  982. buf[len] = '\0';
  983. /* copy buffer content to memory */
  984. aos_list_for_each_entry(aos_buf_t, content, &resp_body, node) {
  985. size = aos_buf_size(content);
  986. memcpy(buf + pos, content->pos, (size_t)size);
  987. pos += size;
  988. }
  989. CuAssertStrEquals(tc, buf, "{\"Status\":\"OK\"}");
  990. aos_pool_destroy(p);
  991. // head object
  992. aos_pool_create(&p, NULL);
  993. options = oss_request_options_create(p);
  994. init_test_request_options(options, is_cname);
  995. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  996. CuAssertIntEquals(tc, 200, s->code);
  997. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  998. CuAssertTrue(tc, content_length == get_file_size(test_local_file));
  999. aos_pool_destroy(p);
  1000. printf("test_resumable_upload_callback_without_checkpoint ok\n");
  1001. }
  1002. void test_resumable_upload_progress_without_checkpoint(CuTest *tc)
  1003. {
  1004. aos_pool_t *p = NULL;
  1005. char *object_name = "test_resumable_upload_progress_without_checkpoint.jpg";
  1006. aos_string_t bucket;
  1007. aos_string_t object;
  1008. aos_string_t filename;
  1009. aos_status_t *s = NULL;
  1010. int is_cname = 0;
  1011. aos_table_t *headers = NULL;
  1012. aos_table_t *resp_headers = NULL;
  1013. aos_list_t resp_body;
  1014. oss_request_options_t *options = NULL;
  1015. oss_resumable_clt_params_t *clt_params;
  1016. int64_t content_length = 0;
  1017. aos_pool_create(&p, NULL);
  1018. options = oss_request_options_create(p);
  1019. init_test_request_options(options, is_cname);
  1020. headers = aos_table_make(p, 0);
  1021. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1022. aos_str_set(&object, object_name);
  1023. aos_list_init(&resp_body);
  1024. aos_str_set(&filename, test_local_file);
  1025. // upload object
  1026. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_FALSE, NULL);
  1027. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  1028. clt_params, percentage, &resp_headers, &resp_body);
  1029. CuAssertIntEquals(tc, 200, s->code);
  1030. aos_pool_destroy(p);
  1031. // head object
  1032. aos_pool_create(&p, NULL);
  1033. options = oss_request_options_create(p);
  1034. init_test_request_options(options, is_cname);
  1035. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1036. CuAssertIntEquals(tc, 200, s->code);
  1037. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1038. CuAssertTrue(tc, content_length == get_file_size(test_local_file));
  1039. aos_pool_destroy(p);
  1040. printf("test_resumable_upload_progress_without_checkpoint ok\n");
  1041. }
  1042. void test_resumable_upload_callback_with_checkpoint(CuTest *tc)
  1043. {
  1044. aos_pool_t *p = NULL;
  1045. char *object_name = "test_resumable_upload_callback_with_checkpoint.jpg";
  1046. aos_string_t bucket;
  1047. aos_string_t object;
  1048. aos_string_t filename;
  1049. aos_status_t *s = NULL;
  1050. int is_cname = 0;
  1051. aos_table_t *headers = NULL;
  1052. aos_table_t *resp_headers = NULL;
  1053. aos_list_t resp_body;
  1054. oss_request_options_t *options = NULL;
  1055. oss_resumable_clt_params_t *clt_params;
  1056. int64_t content_length = 0;
  1057. aos_buf_t *content;
  1058. char b64_buf[1024];
  1059. int b64_len = 64;
  1060. char *buf = NULL;
  1061. int64_t len = 0;
  1062. int64_t size = 0;
  1063. int64_t pos = 0;
  1064. char *callback = "{"
  1065. "\"callbackUrl\":\"http://callback.oss-demo.com:23450\","
  1066. "\"callbackHost\":\"oss-cn-hangzhou.aliyuncs.com\","
  1067. "\"callbackBody\":\"bucket=${bucket}&object=${object}&size=${size}&mimeType=${mimeType}\","
  1068. "\"callbackBodyType\":\"application/x-www-form-urlencoded\""
  1069. "}";
  1070. char *callback_var = "{"
  1071. "\"x:var1\":\"value1\","
  1072. "\"x:var2\":\"value2\""
  1073. "}";
  1074. aos_pool_create(&p, NULL);
  1075. options = oss_request_options_create(p);
  1076. init_test_request_options(options, is_cname);
  1077. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1078. aos_str_set(&object, object_name);
  1079. aos_list_init(&resp_body);
  1080. aos_str_set(&filename, test_local_file);
  1081. headers = aos_table_make(p, 2);
  1082. b64_len = aos_base64_encode((unsigned char*)callback, strlen(callback), b64_buf);
  1083. b64_buf[b64_len] = '\0';
  1084. apr_table_set(headers, OSS_CALLBACK, apr_pstrdup(p, b64_buf));
  1085. b64_len = aos_base64_encode((unsigned char*)callback_var, strlen(callback_var), b64_buf);
  1086. b64_buf[b64_len] = '\0';
  1087. apr_table_set(headers, OSS_CALLBACK_VAR, apr_pstrdup(p, b64_buf));
  1088. // upload object
  1089. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  1090. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  1091. clt_params, NULL, &resp_headers, &resp_body);
  1092. CuAssertIntEquals(tc, 200, s->code);
  1093. /* get buffer len */
  1094. len = aos_buf_list_len(&resp_body);
  1095. buf = (char *)aos_pcalloc(p, (apr_size_t)(len + 1));
  1096. buf[len] = '\0';
  1097. /* copy buffer content to memory */
  1098. aos_list_for_each_entry(aos_buf_t, content, &resp_body, node) {
  1099. size = aos_buf_size(content);
  1100. memcpy(buf + pos, content->pos, (size_t)size);
  1101. pos += size;
  1102. }
  1103. CuAssertStrEquals(tc, buf, "{\"Status\":\"OK\"}");
  1104. aos_pool_destroy(p);
  1105. // head object
  1106. aos_pool_create(&p, NULL);
  1107. options = oss_request_options_create(p);
  1108. init_test_request_options(options, is_cname);
  1109. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1110. CuAssertIntEquals(tc, 200, s->code);
  1111. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1112. CuAssertTrue(tc, content_length == get_file_size(test_local_file));
  1113. aos_pool_destroy(p);
  1114. printf("test_resumable_upload_callback_with_checkpoint ok\n");
  1115. }
  1116. void test_resumable_upload_progress_with_checkpoint(CuTest *tc)
  1117. {
  1118. aos_pool_t *p = NULL;
  1119. char *object_name = "test_resumable_upload_progress_with_checkpoint.jpg";
  1120. aos_string_t bucket;
  1121. aos_string_t object;
  1122. aos_string_t filename;
  1123. aos_status_t *s = NULL;
  1124. int is_cname = 0;
  1125. aos_table_t *headers = NULL;
  1126. aos_table_t *resp_headers = NULL;
  1127. aos_list_t resp_body;
  1128. oss_request_options_t *options = NULL;
  1129. oss_resumable_clt_params_t *clt_params;
  1130. int64_t content_length = 0;
  1131. aos_pool_create(&p, NULL);
  1132. options = oss_request_options_create(p);
  1133. init_test_request_options(options, is_cname);
  1134. headers = aos_table_make(p, 0);
  1135. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1136. aos_str_set(&object, object_name);
  1137. aos_list_init(&resp_body);
  1138. aos_str_set(&filename, test_local_file);
  1139. // upload object
  1140. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  1141. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  1142. clt_params, percentage, &resp_headers, &resp_body);
  1143. CuAssertIntEquals(tc, 200, s->code);
  1144. aos_pool_destroy(p);
  1145. // head object
  1146. aos_pool_create(&p, NULL);
  1147. options = oss_request_options_create(p);
  1148. init_test_request_options(options, is_cname);
  1149. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1150. CuAssertIntEquals(tc, 200, s->code);
  1151. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1152. CuAssertTrue(tc, content_length == get_file_size(test_local_file));
  1153. aos_pool_destroy(p);
  1154. printf("test_resumable_upload_progress_with_checkpoint ok\n");
  1155. }
  1156. void test_resumable_upload_content_type(CuTest *tc)
  1157. {
  1158. aos_pool_t *p = NULL;
  1159. char *object_name = "test_resumable_upload_content_type.ts";
  1160. aos_string_t bucket;
  1161. aos_string_t object;
  1162. aos_string_t filename;
  1163. aos_status_t *s = NULL;
  1164. int is_cname = 0;
  1165. aos_table_t *headers = NULL;
  1166. aos_table_t *resp_headers = NULL;
  1167. aos_list_t resp_body;
  1168. oss_request_options_t *options = NULL;
  1169. oss_resumable_clt_params_t *clt_params;
  1170. int64_t content_length = 0;
  1171. char *content_type = NULL;
  1172. aos_pool_create(&p, NULL);
  1173. options = oss_request_options_create(p);
  1174. init_test_request_options(options, is_cname);
  1175. headers = aos_table_make(p, 0);
  1176. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1177. aos_str_set(&object, object_name);
  1178. aos_list_init(&resp_body);
  1179. aos_str_set(&filename, test_local_file);
  1180. // upload object
  1181. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  1182. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  1183. clt_params, NULL, &resp_headers, &resp_body);
  1184. CuAssertIntEquals(tc, 200, s->code);
  1185. aos_pool_destroy(p);
  1186. // head object
  1187. aos_pool_create(&p, NULL);
  1188. options = oss_request_options_create(p);
  1189. init_test_request_options(options, is_cname);
  1190. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1191. CuAssertIntEquals(tc, 200, s->code);
  1192. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1193. CuAssertTrue(tc, content_length == get_file_size(test_local_file));
  1194. content_type = (char*)(apr_table_get(resp_headers, OSS_CONTENT_TYPE));
  1195. CuAssertStrEquals(tc, "video/MP2T", content_type);
  1196. aos_pool_destroy(p);
  1197. printf("test_resumable_upload_content_type ok\n");
  1198. }
  1199. void test_resumable_download_without_checkpoint(CuTest *tc)
  1200. {
  1201. aos_pool_t *p = NULL;
  1202. char *object_name = "test_resumable_upload_without_checkpoint.jpg";
  1203. aos_string_t bucket;
  1204. aos_string_t object;
  1205. aos_string_t filename;
  1206. aos_status_t *s = NULL;
  1207. int is_cname = 0;
  1208. aos_table_t *headers = NULL;
  1209. aos_table_t *resp_headers = NULL;
  1210. oss_request_options_t *options = NULL;
  1211. oss_resumable_clt_params_t *clt_params;
  1212. unsigned long content_length;
  1213. aos_pool_create(&p, NULL);
  1214. options = oss_request_options_create(p);
  1215. init_test_request_options(options, is_cname);
  1216. headers = aos_table_make(p, 0);
  1217. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1218. aos_str_set(&object, object_name);
  1219. aos_str_set(&filename, object_name);
  1220. // download
  1221. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_FALSE, NULL);
  1222. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1223. clt_params, NULL, &resp_headers);
  1224. CuAssertIntEquals(tc, 200, s->code);
  1225. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1226. CuAssertIntEquals(tc, 200, s->code);
  1227. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1228. CuAssertTrue(tc, content_length == get_file_size(filename.data));
  1229. remove(filename.data);
  1230. aos_pool_destroy(p);
  1231. printf("test_resumable_download_without_checkpoint ok\n");
  1232. }
  1233. void test_resumable_download_with_checkpoint(CuTest *tc)
  1234. {
  1235. aos_pool_t *p = NULL;
  1236. char *object_name = "test_resumable_upload_with_checkpoint.jpg";
  1237. aos_string_t bucket;
  1238. aos_string_t object;
  1239. aos_string_t filename;
  1240. aos_status_t *s = NULL;
  1241. int is_cname = 0;
  1242. aos_table_t *headers = NULL;
  1243. aos_table_t *resp_headers = NULL;
  1244. oss_request_options_t *options = NULL;
  1245. oss_resumable_clt_params_t *clt_params;
  1246. unsigned long content_length;
  1247. aos_pool_create(&p, NULL);
  1248. options = oss_request_options_create(p);
  1249. init_test_request_options(options, is_cname);
  1250. headers = aos_table_make(p, 0);
  1251. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1252. aos_str_set(&object, object_name);
  1253. aos_str_set(&filename, object_name);
  1254. // download
  1255. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  1256. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1257. clt_params, NULL, &resp_headers);
  1258. CuAssertIntEquals(tc, 200, s->code);
  1259. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1260. CuAssertIntEquals(tc, 200, s->code);
  1261. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1262. CuAssertTrue(tc, content_length == get_file_size(filename.data));
  1263. remove(filename.data);
  1264. aos_pool_destroy(p);
  1265. printf("test_resumable_download_with_checkpoint ok\n");
  1266. }
  1267. void test_resumable_download_without_checkpoint_target_invalid(CuTest *tc)
  1268. {
  1269. aos_pool_t *p = NULL;
  1270. char *object_name = "test_resumable_upload_without_checkpoint.jpg";
  1271. aos_string_t bucket;
  1272. aos_string_t object;
  1273. aos_string_t filename;
  1274. aos_status_t *s = NULL;
  1275. int is_cname = 0;
  1276. aos_table_t *headers = NULL;
  1277. aos_table_t *resp_headers = NULL;
  1278. oss_request_options_t *options = NULL;
  1279. oss_resumable_clt_params_t *clt_params;
  1280. aos_pool_create(&p, NULL);
  1281. options = oss_request_options_create(p);
  1282. init_test_request_options(options, is_cname);
  1283. headers = aos_table_make(p, 0);
  1284. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1285. aos_str_set(&object, object_name);
  1286. aos_str_set(&filename, "a/b/c/d/e/f/g/h/i/j/k/l/m/n/~!@#$%^&*()");
  1287. // download
  1288. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_FALSE, NULL);
  1289. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1290. clt_params, NULL, &resp_headers);
  1291. CuAssertIntEquals(tc, AOSE_OPEN_FILE_ERROR, s->code);
  1292. aos_pool_destroy(p);
  1293. printf("test_resumable_download_without_checkpoint_target_invalid ok\n");
  1294. }
  1295. void test_resumable_download_with_checkpoint_target_invalid(CuTest *tc)
  1296. {
  1297. aos_pool_t *p = NULL;
  1298. char *object_name = "test_resumable_upload_with_checkpoint.jpg";
  1299. aos_string_t bucket;
  1300. aos_string_t object;
  1301. aos_string_t filename;
  1302. aos_status_t *s = NULL;
  1303. int is_cname = 0;
  1304. aos_table_t *headers = NULL;
  1305. aos_table_t *resp_headers = NULL;
  1306. oss_request_options_t *options = NULL;
  1307. oss_resumable_clt_params_t *clt_params;
  1308. aos_pool_create(&p, NULL);
  1309. options = oss_request_options_create(p);
  1310. init_test_request_options(options, is_cname);
  1311. headers = aos_table_make(p, 0);
  1312. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1313. aos_str_set(&object, object_name);
  1314. aos_str_set(&filename, "a/b/c/d/e/f/g/h/i/j/k/l/m/n/~!@#$%^&*()");
  1315. // download
  1316. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  1317. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1318. clt_params, NULL, &resp_headers);
  1319. CuAssertStrEquals(tc, AOS_OPEN_FILE_ERROR_CODE, s->error_code);
  1320. aos_pool_destroy(p);
  1321. printf("test_resumable_download_with_checkpoint_target_invalid ok\n");
  1322. }
  1323. void test_resumable_download_partsize(CuTest *tc)
  1324. {
  1325. aos_pool_t *p = NULL;
  1326. char *object_name = "test_resumable_upload_partsize.jpg";
  1327. aos_string_t bucket;
  1328. aos_string_t object;
  1329. aos_string_t filename;
  1330. aos_status_t *s = NULL;
  1331. int is_cname = 0;
  1332. aos_table_t *headers = NULL;
  1333. aos_table_t *resp_headers = NULL;
  1334. oss_request_options_t *options = NULL;
  1335. oss_resumable_clt_params_t *clt_params;
  1336. unsigned long content_length;
  1337. aos_pool_create(&p, NULL);
  1338. options = oss_request_options_create(p);
  1339. init_test_request_options(options, is_cname);
  1340. headers = aos_table_make(p, 0);
  1341. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1342. aos_str_set(&object, object_name);
  1343. aos_str_set(&filename, object_name);
  1344. // download
  1345. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 1024 * 10, 3, AOS_FALSE, NULL);
  1346. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1347. clt_params, NULL, &resp_headers);
  1348. CuAssertIntEquals(tc, 200, s->code);
  1349. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1350. CuAssertIntEquals(tc, 200, s->code);
  1351. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1352. CuAssertTrue(tc, content_length == get_file_size(filename.data));
  1353. remove(filename.data);
  1354. aos_pool_destroy(p);
  1355. printf("test_resumable_download_partsize ok\n");
  1356. }
  1357. void test_resumable_download_small_partsize(CuTest *tc)
  1358. {
  1359. aos_pool_t *p = NULL;
  1360. char *object_name = "test_resumable_upload_partsize.jpg";
  1361. aos_string_t bucket;
  1362. aos_string_t object;
  1363. aos_string_t filename;
  1364. aos_status_t *s = NULL;
  1365. int is_cname = 0;
  1366. aos_table_t *headers = NULL;
  1367. aos_table_t *resp_headers = NULL;
  1368. oss_request_options_t *options = NULL;
  1369. oss_resumable_clt_params_t *clt_params;
  1370. unsigned long content_length;
  1371. aos_pool_create(&p, NULL);
  1372. options = oss_request_options_create(p);
  1373. init_test_request_options(options, is_cname);
  1374. headers = aos_table_make(p, 0);
  1375. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1376. aos_str_set(&object, object_name);
  1377. aos_str_set(&filename, object_name);
  1378. // download
  1379. clt_params = oss_create_resumable_clt_params_content(p, 64, 16, AOS_FALSE, NULL);
  1380. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1381. clt_params, NULL, &resp_headers);
  1382. CuAssertIntEquals(tc, 200, s->code);
  1383. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1384. CuAssertIntEquals(tc, 200, s->code);
  1385. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1386. CuAssertTrue(tc, content_length == get_file_size(filename.data));
  1387. remove(filename.data);
  1388. aos_pool_destroy(p);
  1389. printf("test_resumable_download_small_partsize ok\n");
  1390. }
  1391. void test_resumable_download_threads(CuTest *tc)
  1392. {
  1393. aos_pool_t *p = NULL;
  1394. char *object_name = "test_resumable_upload_threads.jpg";
  1395. aos_string_t bucket;
  1396. aos_string_t object;
  1397. aos_string_t filename;
  1398. aos_status_t *s = NULL;
  1399. int is_cname = 0;
  1400. aos_table_t *headers = NULL;
  1401. aos_table_t *resp_headers = NULL;
  1402. oss_request_options_t *options = NULL;
  1403. oss_resumable_clt_params_t *clt_params;
  1404. unsigned long content_length;
  1405. aos_pool_create(&p, NULL);
  1406. options = oss_request_options_create(p);
  1407. init_test_request_options(options, is_cname);
  1408. headers = aos_table_make(p, 0);
  1409. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1410. aos_str_set(&object, object_name);
  1411. aos_str_set(&filename, object_name);
  1412. // download with thread 1
  1413. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 1, AOS_FALSE, NULL);
  1414. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1415. clt_params, NULL, &resp_headers);
  1416. CuAssertIntEquals(tc, 200, s->code);
  1417. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1418. CuAssertIntEquals(tc, 200, s->code);
  1419. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1420. CuAssertTrue(tc, content_length == get_file_size(filename.data));
  1421. remove(filename.data);
  1422. aos_pool_destroy(p);
  1423. printf("test_resumable_download_threads ok\n");
  1424. }
  1425. void test_resumable_download_with_checkpoint_format_invalid(CuTest *tc)
  1426. {
  1427. aos_pool_t *p = NULL;
  1428. char *object_name = "test_resumable_upload_with_checkpoint_format_invalid.jpg";
  1429. aos_string_t bucket;
  1430. aos_string_t object;
  1431. aos_string_t filename;
  1432. aos_string_t tmp_filename;
  1433. aos_status_t *s = NULL;
  1434. int is_cname = 0;
  1435. aos_table_t *headers = NULL;
  1436. aos_table_t *resp_headers = NULL;
  1437. oss_request_options_t *options = NULL;
  1438. oss_resumable_clt_params_t *clt_params;
  1439. unsigned long content_length;
  1440. aos_string_t checkpoint_path;
  1441. aos_pool_create(&p, NULL);
  1442. options = oss_request_options_create(p);
  1443. init_test_request_options(options, is_cname);
  1444. headers = aos_table_make(p, 0);
  1445. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1446. aos_str_set(&object, object_name);
  1447. aos_str_set(&filename, object_name);
  1448. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1449. CuAssertIntEquals(tc, 200, s->code);
  1450. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1451. // generate checkpoint
  1452. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  1453. oss_get_download_checkpoint_path(clt_params, &filename, p, &checkpoint_path);
  1454. fill_test_file(p, checkpoint_path.data, "HiOSS");
  1455. oss_get_temporary_file_name(p, &filename, &tmp_filename);
  1456. make_random_file(p, tmp_filename.data, content_length);
  1457. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1458. clt_params, NULL, &resp_headers);
  1459. CuAssertIntEquals(tc, 200, s->code);
  1460. CuAssertTrue(tc, content_length == get_file_size(filename.data));
  1461. remove(tmp_filename.data);
  1462. remove(filename.data);
  1463. aos_pool_destroy(p);
  1464. printf("test_resumable_download_with_checkpoint_format_invalid ok\n");
  1465. }
  1466. void test_resumable_download_with_checkpoint_info_invalid(CuTest *tc)
  1467. {
  1468. aos_pool_t *p = NULL;
  1469. char *object_name = "test_resumable_upload_with_checkpoint_format_invalid.jpg";
  1470. aos_string_t bucket;
  1471. aos_string_t object;
  1472. aos_string_t filename;
  1473. aos_string_t tmp_filename;
  1474. aos_status_t *s = NULL;
  1475. int is_cname = 0;
  1476. aos_table_t *headers = NULL;
  1477. aos_table_t *resp_headers = NULL;
  1478. oss_request_options_t *options = NULL;
  1479. oss_resumable_clt_params_t *clt_params;
  1480. unsigned long content_length;
  1481. aos_string_t checkpoint_path;
  1482. const char *object_last_modified = NULL;
  1483. const char *object_etag = NULL;
  1484. oss_checkpoint_t *checkpoint = NULL;
  1485. int rv;
  1486. aos_pool_create(&p, NULL);
  1487. options = oss_request_options_create(p);
  1488. init_test_request_options(options, is_cname);
  1489. headers = aos_table_make(p, 0);
  1490. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1491. aos_str_set(&object, object_name);
  1492. aos_str_set(&filename, object_name);
  1493. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1494. CuAssertIntEquals(tc, 200, s->code);
  1495. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1496. object_last_modified = apr_table_get(resp_headers, "Last-Modified");
  1497. object_etag = apr_table_get(resp_headers, "ETag");
  1498. // generate checkpoint
  1499. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  1500. oss_get_download_checkpoint_path(clt_params, &filename, p, &checkpoint_path);
  1501. checkpoint = oss_create_checkpoint_content(p);
  1502. oss_build_download_checkpoint(p, checkpoint, &filename, object.data,
  1503. content_length, object_last_modified, object_etag, 1024 * 99);
  1504. rv = oss_open_checkpoint_file(p, &checkpoint_path, checkpoint);
  1505. CuAssertIntEquals(tc, APR_SUCCESS, rv);
  1506. rv = oss_dump_checkpoint(p, checkpoint);
  1507. CuAssertIntEquals(tc, AOSE_OK, rv);
  1508. apr_file_close(checkpoint->thefile);
  1509. oss_get_temporary_file_name(p, &filename, &tmp_filename);
  1510. make_random_file(p, tmp_filename.data, content_length);
  1511. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1512. clt_params, NULL, &resp_headers);
  1513. CuAssertIntEquals(tc, 200, s->code);
  1514. CuAssertTrue(tc, content_length == get_file_size(filename.data));
  1515. remove(tmp_filename.data);
  1516. remove(filename.data);
  1517. aos_pool_destroy(p);
  1518. printf("test_resumable_download_with_checkpoint_info_invalid ok\n");
  1519. }
  1520. void test_resumable_download_with_checkpoint_info_valid(CuTest *tc)
  1521. {
  1522. aos_pool_t *p = NULL;
  1523. char *object_name = "test_resumable_upload_with_checkpoint_format_invalid.jpg";
  1524. aos_string_t bucket;
  1525. aos_string_t object;
  1526. aos_string_t filename;
  1527. aos_string_t tmp_filename;
  1528. aos_status_t *s = NULL;
  1529. int is_cname = 0;
  1530. aos_table_t *headers = NULL;
  1531. aos_table_t *resp_headers = NULL;
  1532. oss_request_options_t *options = NULL;
  1533. oss_resumable_clt_params_t *clt_params;
  1534. unsigned long content_length;
  1535. const char *object_last_modified = NULL;
  1536. const char *object_etag = NULL;
  1537. aos_string_t checkpoint_path;
  1538. oss_checkpoint_t *checkpoint = NULL;
  1539. int rv;
  1540. aos_pool_create(&p, NULL);
  1541. options = oss_request_options_create(p);
  1542. init_test_request_options(options, is_cname);
  1543. headers = aos_table_make(p, 0);
  1544. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1545. aos_str_set(&object, object_name);
  1546. aos_str_set(&filename, object_name);
  1547. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1548. CuAssertIntEquals(tc, 200, s->code);
  1549. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1550. object_last_modified = apr_table_get(resp_headers, "Last-Modified");
  1551. object_etag = apr_table_get(resp_headers, "ETag");
  1552. // generate checkpoint
  1553. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  1554. oss_get_download_checkpoint_path(clt_params, &filename, p, &checkpoint_path);
  1555. checkpoint = oss_create_checkpoint_content(p);
  1556. oss_build_download_checkpoint(p, checkpoint, &filename, object.data,
  1557. content_length, object_last_modified, object_etag, 1024 * 100);
  1558. rv = oss_open_checkpoint_file(p, &checkpoint_path, checkpoint);
  1559. CuAssertIntEquals(tc, APR_SUCCESS, rv);
  1560. rv = oss_dump_checkpoint(p, checkpoint);
  1561. CuAssertIntEquals(tc, AOSE_OK, rv);
  1562. apr_file_close(checkpoint->thefile);
  1563. oss_get_temporary_file_name(p, &filename, &tmp_filename);
  1564. make_random_file(p, tmp_filename.data, content_length);
  1565. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1566. clt_params, NULL, &resp_headers);
  1567. CuAssertIntEquals(tc, 200, s->code);
  1568. CuAssertTrue(tc, content_length == get_file_size(filename.data));
  1569. remove(tmp_filename.data);
  1570. remove(filename.data);
  1571. aos_pool_destroy(p);
  1572. printf("test_resumable_download_with_checkpoint_info_valid ok\n");
  1573. }
  1574. void test_resumable_download_with_checkpoint_path_invalid(CuTest *tc)
  1575. {
  1576. aos_pool_t *p = NULL;
  1577. char *object_name = "test_resumable_upload_with_checkpoint_format_invalid.jpg";
  1578. aos_string_t bucket;
  1579. aos_string_t object;
  1580. aos_string_t filename;
  1581. aos_status_t *s = NULL;
  1582. int is_cname = 0;
  1583. aos_table_t *headers = NULL;
  1584. aos_table_t *resp_headers = NULL;
  1585. oss_request_options_t *options = NULL;
  1586. oss_resumable_clt_params_t *clt_params;
  1587. char *cp_path = "/uvwxyz/abchij/test.udp";
  1588. aos_pool_create(&p, NULL);
  1589. options = oss_request_options_create(p);
  1590. init_test_request_options(options, is_cname);
  1591. headers = aos_table_make(p, 0);
  1592. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1593. aos_str_set(&object, object_name);
  1594. aos_str_set(&filename, object_name);
  1595. // generate checkpoint
  1596. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, cp_path);
  1597. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1598. clt_params, NULL, &resp_headers);
  1599. CuAssertStrEquals(tc, "OpenFileFail", s->error_code);
  1600. aos_pool_destroy(p);
  1601. printf("test_resumable_download_with_checkpoint_path_invalid ok\n");
  1602. }
  1603. void test_resumable_download_with_tmpfile_not_found(CuTest *tc)
  1604. {
  1605. aos_pool_t *p = NULL;
  1606. char *object_name = "test_resumable_upload_with_checkpoint.jpg";
  1607. aos_string_t bucket;
  1608. aos_string_t object;
  1609. aos_string_t filename;
  1610. aos_status_t *s = NULL;
  1611. int is_cname = 0;
  1612. aos_table_t *headers = NULL;
  1613. aos_table_t *resp_headers = NULL;
  1614. oss_request_options_t *options = NULL;
  1615. oss_resumable_clt_params_t *clt_params;
  1616. unsigned long content_length;
  1617. aos_string_t checkpoint_path;
  1618. const char *object_last_modified;
  1619. const char *object_etag;
  1620. oss_checkpoint_t *checkpoint = NULL;
  1621. int rv;
  1622. aos_pool_create(&p, NULL);
  1623. options = oss_request_options_create(p);
  1624. init_test_request_options(options, is_cname);
  1625. headers = aos_table_make(p, 0);
  1626. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1627. aos_str_set(&object, object_name);
  1628. aos_str_set(&filename, object_name);
  1629. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1630. CuAssertIntEquals(tc, 200, s->code);
  1631. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1632. object_last_modified = apr_table_get(resp_headers, "Last-Modified");
  1633. object_etag = apr_table_get(resp_headers, "ETag");
  1634. // generate checkpoint
  1635. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  1636. oss_get_download_checkpoint_path(clt_params, &filename, p, &checkpoint_path);
  1637. checkpoint = oss_create_checkpoint_content(p);
  1638. oss_build_download_checkpoint(p, checkpoint, &filename, object.data,
  1639. content_length, object_last_modified, object_etag, 1024 * 100);
  1640. rv = oss_open_checkpoint_file(p, &checkpoint_path, checkpoint);
  1641. CuAssertIntEquals(tc, APR_SUCCESS, rv);
  1642. rv = oss_dump_checkpoint(p, checkpoint);
  1643. CuAssertIntEquals(tc, AOSE_OK, rv);
  1644. apr_file_close(checkpoint->thefile);
  1645. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1646. clt_params, NULL, &resp_headers);
  1647. CuAssertIntEquals(tc, 200, s->code);
  1648. CuAssertTrue(tc, content_length == get_file_size(filename.data));
  1649. remove(filename.data);
  1650. aos_pool_destroy(p);
  1651. printf("test_resumable_download_with_tmpfile_not_found ok\n");
  1652. }
  1653. void test_resumable_download_with_tmpfile_invalid(CuTest *tc)
  1654. {
  1655. aos_pool_t *p = NULL;
  1656. char *object_name = "test_resumable_upload_with_checkpoint.jpg";
  1657. aos_string_t bucket;
  1658. aos_string_t object;
  1659. aos_string_t filename;
  1660. aos_string_t tmp_filename;
  1661. aos_status_t *s = NULL;
  1662. int is_cname = 0;
  1663. aos_table_t *headers = NULL;
  1664. aos_table_t *resp_headers = NULL;
  1665. oss_request_options_t *options = NULL;
  1666. oss_resumable_clt_params_t *clt_params;
  1667. unsigned long content_length;
  1668. aos_string_t checkpoint_path;
  1669. const char *object_last_modified;
  1670. const char *object_etag;
  1671. oss_checkpoint_t *checkpoint = NULL;
  1672. int rv;
  1673. aos_pool_create(&p, NULL);
  1674. options = oss_request_options_create(p);
  1675. init_test_request_options(options, is_cname);
  1676. headers = aos_table_make(p, 0);
  1677. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1678. aos_str_set(&object, object_name);
  1679. aos_str_set(&filename, object_name);
  1680. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1681. CuAssertIntEquals(tc, 200, s->code);
  1682. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1683. object_last_modified = apr_table_get(resp_headers, "Last-Modified");
  1684. object_etag = apr_table_get(resp_headers, "ETag");
  1685. // generate checkpoint
  1686. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  1687. oss_get_download_checkpoint_path(clt_params, &filename, p, &checkpoint_path);
  1688. checkpoint = oss_create_checkpoint_content(p);
  1689. oss_build_download_checkpoint(p, checkpoint, &filename, object.data,
  1690. content_length, object_last_modified, object_etag, 1024 * 100);
  1691. rv = oss_open_checkpoint_file(p, &checkpoint_path, checkpoint);
  1692. CuAssertIntEquals(tc, APR_SUCCESS, rv);
  1693. rv = oss_dump_checkpoint(p, checkpoint);
  1694. CuAssertIntEquals(tc, AOSE_OK, rv);
  1695. apr_file_close(checkpoint->thefile);
  1696. //length mismatch
  1697. oss_get_temporary_file_name(p, &filename, &tmp_filename);
  1698. make_random_file(p, tmp_filename.data, content_length + 1);
  1699. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1700. clt_params, NULL, &resp_headers);
  1701. CuAssertIntEquals(tc, 200, s->code);
  1702. CuAssertTrue(tc, content_length == get_file_size(filename.data));
  1703. remove(tmp_filename.data);
  1704. remove(filename.data);
  1705. aos_pool_destroy(p);
  1706. printf("test_resumable_download_with_tmpfile_invalid ok\n");
  1707. }
  1708. void test_resumable_download_without_checkpoint_object_not_found(CuTest *tc)
  1709. {
  1710. aos_pool_t *p = NULL;
  1711. char *object_name = "/a/b/c/d/e/f/g/h/i/j/k/j/m/n.fake";
  1712. aos_string_t bucket;
  1713. aos_string_t object;
  1714. aos_string_t filename;
  1715. aos_status_t *s = NULL;
  1716. int is_cname = 0;
  1717. aos_table_t *headers = NULL;
  1718. aos_table_t *resp_headers = NULL;
  1719. oss_request_options_t *options = NULL;
  1720. oss_resumable_clt_params_t *clt_params;
  1721. aos_pool_create(&p, NULL);
  1722. options = oss_request_options_create(p);
  1723. init_test_request_options(options, is_cname);
  1724. headers = aos_table_make(p, 0);
  1725. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1726. aos_str_set(&object, object_name);
  1727. aos_str_set(&filename, object_name);
  1728. // download
  1729. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_FALSE, NULL);
  1730. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1731. clt_params, NULL, &resp_headers);
  1732. CuAssertIntEquals(tc, 404, s->code);
  1733. aos_pool_destroy(p);
  1734. printf("test_resumable_download_without_checkpoint_object_not_found ok\n");
  1735. }
  1736. void test_resumable_download_with_checkpoint_object_not_found(CuTest *tc)
  1737. {
  1738. aos_pool_t *p = NULL;
  1739. char *object_name = "/a/b/c/d/e/f/g/h/i/j/k/j/m/n.fake";
  1740. aos_string_t bucket;
  1741. aos_string_t object;
  1742. aos_string_t filename;
  1743. aos_status_t *s = NULL;
  1744. int is_cname = 0;
  1745. aos_table_t *headers = NULL;
  1746. aos_table_t *resp_headers = NULL;
  1747. oss_request_options_t *options = NULL;
  1748. oss_resumable_clt_params_t *clt_params;
  1749. aos_pool_create(&p, NULL);
  1750. options = oss_request_options_create(p);
  1751. init_test_request_options(options, is_cname);
  1752. headers = aos_table_make(p, 0);
  1753. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1754. aos_str_set(&object, object_name);
  1755. aos_str_set(&filename, object_name);
  1756. // download
  1757. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  1758. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1759. clt_params, NULL, &resp_headers);
  1760. CuAssertIntEquals(tc, 404, s->code);
  1761. aos_pool_destroy(p);
  1762. printf("test_resumable_download_with_checkpoint_object_not_found ok\n");
  1763. }
  1764. void test_resumable_download_progress_without_checkpoint(CuTest *tc)
  1765. {
  1766. aos_pool_t *p = NULL;
  1767. char *object_name = "test_resumable_upload_progress_without_checkpoint.jpg";
  1768. aos_string_t bucket;
  1769. aos_string_t object;
  1770. aos_string_t filename;
  1771. aos_status_t *s = NULL;
  1772. int is_cname = 0;
  1773. aos_table_t *headers = NULL;
  1774. aos_table_t *resp_headers = NULL;
  1775. oss_request_options_t *options = NULL;
  1776. oss_resumable_clt_params_t *clt_params;
  1777. unsigned long content_length;
  1778. aos_pool_create(&p, NULL);
  1779. options = oss_request_options_create(p);
  1780. init_test_request_options(options, is_cname);
  1781. headers = aos_table_make(p, 0);
  1782. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1783. aos_str_set(&object, object_name);
  1784. aos_str_set(&filename, object_name);
  1785. // download
  1786. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_FALSE, NULL);
  1787. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1788. clt_params, percentage, &resp_headers);
  1789. CuAssertIntEquals(tc, 200, s->code);
  1790. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1791. CuAssertIntEquals(tc, 200, s->code);
  1792. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1793. CuAssertTrue(tc, content_length == get_file_size(filename.data));
  1794. remove(filename.data);
  1795. aos_pool_destroy(p);
  1796. printf("test_resumable_download_progress_without_checkpoint ok\n");
  1797. }
  1798. void test_resumable_download_progress_with_checkpoint(CuTest *tc)
  1799. {
  1800. aos_pool_t *p = NULL;
  1801. char *object_name = "test_resumable_upload_progress_with_checkpoint.jpg";
  1802. aos_string_t bucket;
  1803. aos_string_t object;
  1804. aos_string_t filename;
  1805. aos_status_t *s = NULL;
  1806. int is_cname = 0;
  1807. aos_table_t *headers = NULL;
  1808. aos_table_t *resp_headers = NULL;
  1809. oss_request_options_t *options = NULL;
  1810. oss_resumable_clt_params_t *clt_params;
  1811. unsigned long content_length;
  1812. aos_pool_create(&p, NULL);
  1813. options = oss_request_options_create(p);
  1814. init_test_request_options(options, is_cname);
  1815. headers = aos_table_make(p, 0);
  1816. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1817. aos_str_set(&object, object_name);
  1818. aos_str_set(&filename, object_name);
  1819. // download
  1820. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  1821. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1822. clt_params, percentage, &resp_headers);
  1823. CuAssertIntEquals(tc, 200, s->code);
  1824. s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
  1825. CuAssertIntEquals(tc, 200, s->code);
  1826. content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
  1827. CuAssertTrue(tc, content_length == get_file_size(filename.data));
  1828. remove(filename.data);
  1829. aos_pool_destroy(p);
  1830. printf("test_resumable_download_progress_with_checkpoint ok\n");
  1831. }
  1832. void test_resumable_download_without_checkpoint_random_failure(CuTest *tc)
  1833. {
  1834. int i;
  1835. aos_pool_t *p = NULL;
  1836. char *object_name = "test_resumable_upload_without_checkpoint.jpg";
  1837. aos_string_t bucket;
  1838. aos_string_t object;
  1839. aos_string_t filename;
  1840. aos_status_t *s = NULL;
  1841. int is_cname = 0;
  1842. aos_table_t *headers = NULL;
  1843. aos_table_t *resp_headers = NULL;
  1844. oss_request_options_t *options = NULL;
  1845. oss_resumable_clt_params_t *clt_params;
  1846. int failed_count = 0;
  1847. // mock
  1848. aos_http_transport_perform_pt old = aos_http_transport_perform;
  1849. aos_http_transport_perform = aos_curl_http_transport_perform_random_failure;
  1850. // download
  1851. for (i = 0; i < 20; i++) {
  1852. aos_pool_create(&p, NULL);
  1853. options = oss_request_options_create(p);
  1854. init_test_request_options(options, is_cname);
  1855. headers = aos_table_make(p, 0);
  1856. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1857. aos_str_set(&object, object_name);
  1858. aos_str_set(&filename, object_name);
  1859. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_FALSE, NULL);
  1860. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1861. clt_params, NULL, &resp_headers);
  1862. if (!aos_status_is_ok(s)) {
  1863. CuAssertStrEquals(tc, "Internal error for test", s->error_msg);
  1864. failed_count++;
  1865. }
  1866. aos_pool_destroy(p);
  1867. }
  1868. CuAssertTrue(tc, failed_count > 0);
  1869. // restore mock
  1870. aos_http_transport_perform = old;
  1871. // continue finish downloading
  1872. aos_pool_create(&p, NULL);
  1873. options = oss_request_options_create(p);
  1874. init_test_request_options(options, is_cname);
  1875. options->ctl->options->enable_crc = 1;
  1876. headers = aos_table_make(p, 0);
  1877. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1878. aos_str_set(&object, object_name);
  1879. aos_str_set(&filename, object_name);
  1880. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_FALSE, NULL);
  1881. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1882. clt_params, NULL, &resp_headers);
  1883. aos_pool_destroy(p);
  1884. CuAssertIntEquals(tc, 200, s->code);
  1885. remove(filename.data);
  1886. printf("test_resumable_download_without_checkpoint_random_failure ok\n");
  1887. }
  1888. void test_resumable_download_with_checkpoint_random_failure(CuTest *tc)
  1889. {
  1890. int i;
  1891. aos_pool_t *p = NULL;
  1892. char *object_name = "test_resumable_upload_with_checkpoint.jpg";
  1893. aos_string_t bucket;
  1894. aos_string_t object;
  1895. aos_string_t filename;
  1896. aos_status_t *s = NULL;
  1897. int is_cname = 0;
  1898. aos_table_t *headers = NULL;
  1899. aos_table_t *resp_headers = NULL;
  1900. oss_request_options_t *options = NULL;
  1901. oss_resumable_clt_params_t *clt_params;
  1902. int failed_count = 0;
  1903. // mock
  1904. aos_http_transport_perform_pt old = aos_http_transport_perform;
  1905. aos_http_transport_perform = aos_curl_http_transport_perform_random_failure;
  1906. // download
  1907. for (i = 0; i < 20; i++) {
  1908. aos_pool_create(&p, NULL);
  1909. options = oss_request_options_create(p);
  1910. init_test_request_options(options, is_cname);
  1911. headers = aos_table_make(p, 0);
  1912. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1913. aos_str_set(&object, object_name);
  1914. aos_str_set(&filename, object_name);
  1915. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  1916. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1917. clt_params, NULL, &resp_headers);
  1918. if (!aos_status_is_ok(s)) {
  1919. CuAssertStrEquals(tc, "Internal error for test", s->error_msg);
  1920. failed_count++;
  1921. }
  1922. aos_pool_destroy(p);
  1923. }
  1924. CuAssertTrue(tc, failed_count > 0);
  1925. // restore mock
  1926. aos_http_transport_perform = old;
  1927. // continue finish downloading
  1928. aos_pool_create(&p, NULL);
  1929. options = oss_request_options_create(p);
  1930. init_test_request_options(options, is_cname);
  1931. options->ctl->options->enable_crc = 1;
  1932. headers = aos_table_make(p, 0);
  1933. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1934. aos_str_set(&object, object_name);
  1935. aos_str_set(&filename, object_name);
  1936. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  1937. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1938. clt_params, NULL, &resp_headers);
  1939. aos_pool_destroy(p);
  1940. CuAssertIntEquals(tc, 200, s->code);
  1941. remove(filename.data);
  1942. printf("test_resumable_download_with_checkpoint_random_failure ok\n");
  1943. }
  1944. void test_resumable_download_with_checkpoint_crc64_mismatch(CuTest *tc)
  1945. {
  1946. aos_pool_t *p = NULL;
  1947. char *object_name = "test_resumable_upload_with_checkpoint.jpg";
  1948. aos_string_t bucket;
  1949. aos_string_t object;
  1950. aos_string_t filename;
  1951. aos_status_t *s = NULL;
  1952. int is_cname = 0;
  1953. aos_table_t *headers = NULL;
  1954. aos_table_t *resp_headers = NULL;
  1955. oss_request_options_t *options = NULL;
  1956. oss_resumable_clt_params_t *clt_params;
  1957. // mock
  1958. aos_http_transport_perform_pt old = aos_http_transport_perform;
  1959. aos_http_transport_perform = aos_curl_http_transport_perform_bad_crc64;
  1960. // download
  1961. aos_pool_create(&p, NULL);
  1962. options = oss_request_options_create(p);
  1963. init_test_request_options(options, is_cname);
  1964. options->ctl->options->enable_crc = 1;
  1965. headers = aos_table_make(p, 0);
  1966. aos_str_set(&bucket, TEST_BUCKET_NAME);
  1967. aos_str_set(&object, object_name);
  1968. aos_str_set(&filename, object_name);
  1969. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  1970. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  1971. clt_params, NULL, &resp_headers);
  1972. CuAssertIntEquals(tc, AOSE_CRC_INCONSISTENT_ERROR, s->code);
  1973. aos_pool_destroy(p);
  1974. // restore mock
  1975. aos_http_transport_perform = old;
  1976. remove(filename.data);
  1977. printf("test_resumable_download_with_checkpoint_crc64_mismatch ok\n");
  1978. }
  1979. CuSuite *test_oss_resumable()
  1980. {
  1981. CuSuite* suite = CuSuiteNew();
  1982. SUITE_ADD_TEST(suite, test_resumable_setup);
  1983. SUITE_ADD_TEST(suite, test_resumable_oss_get_thread_num);
  1984. SUITE_ADD_TEST(suite, test_resumable_oss_get_checkpoint_path);
  1985. SUITE_ADD_TEST(suite, test_resumable_oss_get_file_info);
  1986. SUITE_ADD_TEST(suite, test_resumable_oss_does_file_exist);
  1987. SUITE_ADD_TEST(suite, test_resumable_oss_dump_checkpoint);
  1988. SUITE_ADD_TEST(suite, test_resumable_oss_load_checkpoint);
  1989. SUITE_ADD_TEST(suite, test_resumable_oss_is_upload_checkpoint_valid);
  1990. SUITE_ADD_TEST(suite, test_resumable_checkpoint_xml);
  1991. SUITE_ADD_TEST(suite, test_resumable_upload_without_checkpoint);
  1992. SUITE_ADD_TEST(suite, test_resumable_upload_with_checkpoint);
  1993. SUITE_ADD_TEST(suite, test_resumable_upload_partsize);
  1994. SUITE_ADD_TEST(suite, test_resumable_upload_threads);
  1995. SUITE_ADD_TEST(suite, test_resumable_upload_with_checkpoint_format_invalid);
  1996. SUITE_ADD_TEST(suite, test_resumable_upload_with_checkpoint_path_invalid);
  1997. SUITE_ADD_TEST(suite, test_resumable_upload_with_file_size_unavailable);
  1998. SUITE_ADD_TEST(suite, test_resumable_upload_with_uploadid_unavailable);
  1999. SUITE_ADD_TEST(suite, test_resumable_upload_with_uploadid_available);
  2000. SUITE_ADD_TEST(suite, test_resumable_upload_with_file_path_invalid);
  2001. SUITE_ADD_TEST(suite, test_resumable_upload_callback_without_checkpoint);
  2002. SUITE_ADD_TEST(suite, test_resumable_upload_progress_without_checkpoint);
  2003. SUITE_ADD_TEST(suite, test_resumable_upload_callback_with_checkpoint);
  2004. SUITE_ADD_TEST(suite, test_resumable_upload_progress_with_checkpoint);
  2005. SUITE_ADD_TEST(suite, test_resumable_upload_content_type);
  2006. SUITE_ADD_TEST(suite, test_resumable_download_without_checkpoint);
  2007. SUITE_ADD_TEST(suite, test_resumable_download_with_checkpoint);
  2008. SUITE_ADD_TEST(suite, test_resumable_download_without_checkpoint_target_invalid);
  2009. SUITE_ADD_TEST(suite, test_resumable_download_with_checkpoint_target_invalid);
  2010. SUITE_ADD_TEST(suite, test_resumable_download_partsize);
  2011. SUITE_ADD_TEST(suite, test_resumable_download_small_partsize);
  2012. SUITE_ADD_TEST(suite, test_resumable_download_threads);
  2013. SUITE_ADD_TEST(suite, test_resumable_download_with_checkpoint_format_invalid);
  2014. SUITE_ADD_TEST(suite, test_resumable_download_with_checkpoint_info_invalid);
  2015. SUITE_ADD_TEST(suite, test_resumable_download_with_checkpoint_info_valid);
  2016. SUITE_ADD_TEST(suite, test_resumable_download_with_checkpoint_path_invalid);
  2017. SUITE_ADD_TEST(suite, test_resumable_download_with_tmpfile_invalid);
  2018. SUITE_ADD_TEST(suite, test_resumable_download_with_tmpfile_not_found);
  2019. SUITE_ADD_TEST(suite, test_resumable_download_without_checkpoint_object_not_found);
  2020. SUITE_ADD_TEST(suite, test_resumable_download_with_checkpoint_object_not_found);
  2021. SUITE_ADD_TEST(suite, test_resumable_download_progress_without_checkpoint);
  2022. SUITE_ADD_TEST(suite, test_resumable_download_progress_with_checkpoint);
  2023. SUITE_ADD_TEST(suite, test_resumable_download_without_checkpoint_random_failure);
  2024. SUITE_ADD_TEST(suite, test_resumable_download_with_checkpoint_random_failure);
  2025. SUITE_ADD_TEST(suite, test_resumable_download_with_checkpoint_crc64_mismatch);
  2026. SUITE_ADD_TEST(suite, test_resumable_cleanup);
  2027. return suite;
  2028. }