Skip to content

Commit

Permalink
Merge pull request aliyun#182 from aliyun/refactor/sample
Browse files Browse the repository at this point in the history
调整demo代码结构
  • Loading branch information
duan007a authored Nov 29, 2018
2 parents b156824 + 20b095c commit 54a5efa
Show file tree
Hide file tree
Showing 24 changed files with 422 additions and 373 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ Products/
# big Resource for test
Example/AliyunOSSSDK-iOS-Example/Resources/

# Script files
# Python script generated files
Scripts/*.pyc
6 changes: 3 additions & 3 deletions AliyunOSSiOSTests/OSSCrc64Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ - (void)test_MultipartUploadNormal {
}

- (void)test_resumbleUploadCancelResumble {
NSString * objectkey = @"oss-browser.zip";
NSString * objectkey = @"bigfile.zip";
__block bool cancel = NO;
OSSResumableUploadRequest * resumableUpload = [OSSResumableUploadRequest new];
resumableUpload.bucketName = _privateBucketName;
Expand All @@ -248,7 +248,7 @@ - (void)test_resumbleUploadCancelResumble {
cancel = YES;
}
};
resumableUpload.uploadingFileURL = [[NSBundle mainBundle] URLForResource:@"oss-browser" withExtension:@"zip"];
resumableUpload.uploadingFileURL = [[NSBundle mainBundle] URLForResource:@"bigfile" withExtension:@"zip"];
OSSTask * resumeTask = [_client resumableUpload:resumableUpload];
[resumeTask continueWithBlock:^id(OSSTask *task) {
XCTAssertNotNil(task.error);
Expand All @@ -269,7 +269,7 @@ - (void)test_resumbleUploadCancelResumble {
resumableUpload.objectKey = objectkey;
resumableUpload.recordDirectoryPath = cachesDir;
resumableUpload.partSize = 100 * 1024;
resumableUpload.uploadingFileURL = [[NSBundle mainBundle] URLForResource:@"oss-browser" withExtension:@"zip"];
resumableUpload.uploadingFileURL = [[NSBundle mainBundle] URLForResource:@"bigfile" withExtension:@"zip"];
resumableUpload.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend);
if (bytesSent != 0) {
Expand Down
96 changes: 52 additions & 44 deletions AliyunOSSiOSTests/OSSHttp2Test.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
@interface OSSHttp2Tests : XCTestCase
{
OSSClient *_client;
NSString *bucketName;
NSString *http2endpoint;
NSString *_bucketName;
NSString *_http2endpoint;
}

@end
Expand All @@ -25,83 +25,91 @@ @implementation OSSHttp2Tests

- (void)setUp {
[super setUp];
bucketName = @"zuoqin-public";
http2endpoint = @"https://xx.couldplus.com";

[OSSLog enableLog];
_bucketName = @"aliyun-oss-ios-test-http2";
_http2endpoint = @"https://oss-cn-shanghai.aliyuncs.com";
[self setUpOSSClient];
[self createBucket];
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];

[self deleteBucket];
}

- (void)setUpOSSClient
{
OSSClientConfiguration *config = [OSSClientConfiguration new];

OSSAuthCredentialProvider *authProv = [[OSSAuthCredentialProvider alloc] initWithAuthServerUrl:OSS_STSTOKEN_URL];
_client = [[OSSClient alloc] initWithEndpoint:http2endpoint
_client = [[OSSClient alloc] initWithEndpoint:_http2endpoint
credentialProvider:authProv
clientConfiguration:config];
[OSSLog enableLog];

//upload test image
OSSPutObjectRequest * put = [OSSPutObjectRequest new];
put.bucketName = bucketName;
put.objectKey = OSS_IMAGE_KEY;
put.uploadingFileURL = [[NSBundle mainBundle] URLForResource:@"hasky" withExtension:@"jpeg"];
[[_client putObject:put] waitUntilFinished];
}

- (void)createBucket
{
OSSCreateBucketRequest *createBucket = [OSSCreateBucketRequest new];
createBucket.bucketName = _bucketName;

[[_client createBucket:createBucket] waitUntilFinished];
}

- (void)deleteBucket
{
[OSSTestUtils cleanBucket:_bucketName with:_client];
}

#pragma mark - putObject


//批量操作测试
- (void)testAPI_putObjectMultiTimes
{
NSMutableArray<OSSTask *> *allTasks = [NSMutableArray array];
int max = 30;
for (int i = 0; i < max; i++){
NSString *objectKey = @"putObject-wangwang.zip";
NSString *objectKey = @"http2-wangwang.zip";
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"wangwang" ofType:@"zip"];;
NSURL * fileURL = [NSURL fileURLWithPath:filePath];

OSSPutObjectRequest * put_request = [OSSPutObjectRequest new];
put_request.bucketName = bucketName;
put_request.objectKey = objectKey;
put_request.uploadingFileURL = fileURL;
OSSPutObjectRequest * putRequest = [OSSPutObjectRequest new];
putRequest.bucketName = _bucketName;
putRequest.objectKey = objectKey;
putRequest.uploadingFileURL = fileURL;

OSSTask * put_task = [_client putObject:put_request];
[[put_task continueWithBlock:^id(OSSTask *task) {
XCTAssertNil(task.error);
return nil;
}] waitUntilFinished];


OSSHeadObjectRequest * head = [OSSHeadObjectRequest new];
head.bucketName = bucketName;
head.objectKey = objectKey;
OSSTask *putTask = [_client putObject:putRequest];
[allTasks addObject:putTask];
}

OSSTask *complexTask = [OSSTask taskForCompletionOfAllTasks:allTasks];
[complexTask waitUntilFinished];
XCTAssertTrue(complexTask.error == nil);

[allTasks removeAllObjects];

for (int i = 0; i < max; i++){
NSString *objectKey = @"http2-wangwang.zip";
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"wangwang" ofType:@"zip"];;
NSURL * fileURL = [NSURL fileURLWithPath:filePath];

[[[_client headObject:head] continueWithBlock:^id(OSSTask *task) {
XCTAssertNil(task.error);
return nil;
}] waitUntilFinished];
OSSGetObjectRequest * getRequest = [OSSGetObjectRequest new];
getRequest.bucketName = _bucketName;
getRequest.objectKey = objectKey;
NSString *diskFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"local_test%zd.zip", i]];

NSString *tmpFilePath = [[NSString oss_documentDirectory] stringByAppendingPathComponent:@"tempfile"];
OSSGetObjectRequest * get_request = [OSSGetObjectRequest new];
get_request.bucketName = bucketName;
get_request.objectKey = objectKey;
get_request.downloadToFileURL = [NSURL fileURLWithPath:tmpFilePath];
getRequest.downloadToFileURL = [NSURL fileURLWithPath:diskFilePath];

OSSTask * get_task = [_client getObject:get_request];
[[get_task continueWithBlock:^id(OSSTask *task) {
XCTAssertNil(task.error);
OSSGetObjectResult * result = task.result;
XCTAssertNil(result.downloadedData);
return nil;
}] waitUntilFinished];
OSSTask *getTask = [_client getObject:getRequest];
[allTasks addObject:getTask];
}

complexTask = [OSSTask taskForCompletionOfAllTasks:allTasks];
[complexTask waitUntilFinished];
XCTAssertTrue(complexTask.error == nil);
}


Expand Down
26 changes: 13 additions & 13 deletions AliyunOSSiOSTests/OSSTestMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
#ifndef OSSTestMacros_h
#define OSSTestMacros_h

#define OSS_ACCESSKEY_ID @"******"
#define OSS_SECRETKEY_ID @"******"
#define OSS_ACCESSKEY_ID @"AccessKeyID" // 子账号id
#define OSS_SECRETKEY_ID @"AccessKeySecret" // 子账号secret

#define OSS_BUCKET_PUBLIC @"public"
#define OSS_BUCKET_PRIVATE @"private"
#define OSS_ENDPOINT @"http://oss-cn-region.aliyuncs.com"
#define OSS_IMG_ENDPOINT @"http://img-cn-region.aliyuncs.com"
#define OSS_MULTIPART_UPLOADKEY @"multipart_key"
#define OSS_RESUMABLE_UPLOADKEY @"resumable_key"
#define OSS_CALLBACK_URL @"http://oss-demo.aliyuncs.com:23450"
#define OSS_CNAME_URL @"http://www.cnametest.com/"
#define OSS_STSTOKEN_URL @"http://*.*.*.*:*/sts/getsts"
#define OSS_IMAGE_KEY @"hasky.jpeg"
#define OSS_BUCKET_PUBLIC @"public-bucket" // bucket名称
#define OSS_BUCKET_PRIVATE @"private-bucket" // bucket名称
#define OSS_ENDPOINT @"http://oss-cn-region.aliyuncs.com" // 访问的阿里云endpoint
#define OSS_IMG_ENDPOINT @"http://img-cn-region.aliyuncs.com" // 旧版本图片服务的endpoint
#define OSS_MULTIPART_UPLOADKEY @"multipart_key" // 分片上传的object key
#define OSS_RESUMABLE_UPLOADKEY @"resumable_key" // 断点续传的object key
#define OSS_CALLBACK_URL @"http://oss-demo.aliyuncs.com:23450" // 对象上传成功时回调的业务服务器地址
#define OSS_CNAME_URL @"http://www.cnametest.com/" // cname,用于替换bucket.endpoint的访问域名
#define OSS_STSTOKEN_URL @"http://*.*.*.*:****/sts/getsts" // sts授权服务器的地址
#define OSS_IMAGE_KEY @"testImage.png" // 测试图片的名称

#define OSS_DOWNLOAD_FILE_NAME @"OSS_DOWNLOAD_FILE_NAME"
#define OSS_DOWNLOAD_FILE_NAME @"OSS_DOWNLOAD_FILE_NAME" // 用于下载的object key

#endif /* OSSTestMacros_h */
52 changes: 26 additions & 26 deletions Example/AliyunOSSSDK-Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
4C7B5BEB2043A15100FDD612 /* wangwang.zip in Resources */ = {isa = PBXBuildFile; fileRef = 4C7B5BE82043A15100FDD612 /* wangwang.zip */; };
D1805035212EA0F700A1E647 /* OSSHttp2Test.m in Sources */ = {isa = PBXBuildFile; fileRef = D1805034212EA0F700A1E647 /* OSSHttp2Test.m */; };
D810A00B2092F76900425D19 /* OSSUtilsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D810A00A2092F76900425D19 /* OSSUtilsTests.m */; };
D8125E91211BCC4C00DB687C /* DownloadService.m in Sources */ = {isa = PBXBuildFile; fileRef = D8125E90211BCC4C00DB687C /* DownloadService.m */; };
D8125E96211DAFA500DB687C /* OSSClientTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D8125E95211DAFA500DB687C /* OSSClientTests.m */; };
D827E4101FCD0FC60085380C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D827E40F1FCD0FC60085380C /* AppDelegate.m */; };
D827E4131FCD0FC60085380C /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D827E4121FCD0FC60085380C /* ViewController.m */; };
Expand All @@ -38,8 +37,6 @@
D83D585B1FC6820B0022761B /* OSSSignTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D83D58531FC680850022761B /* OSSSignTests.m */; };
D83D58CE1FC6B3100022761B /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D83D58BF1FC6B3100022761B /* ViewController.m */; };
D83D58D11FC6B3100022761B /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D83D58C51FC6B3100022761B /* AppDelegate.m */; };
D83D58D21FC6B3100022761B /* ImageService.m in Sources */ = {isa = PBXBuildFile; fileRef = D83D58C81FC6B3100022761B /* ImageService.m */; };
D83D58D31FC6B3100022761B /* OssService.m in Sources */ = {isa = PBXBuildFile; fileRef = D83D58C91FC6B3100022761B /* OssService.m */; };
D83D58D81FC6B4350022761B /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D87182F61FC55F36000DD9EC /* SystemConfiguration.framework */; };
D83D58D91FC6B43E0022761B /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D87182FA1FC560D6000DD9EC /* CoreTelephony.framework */; };
D83D58DA1FC6B4450022761B /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = D87182F81FC55F46000DD9EC /* libresolv.tbd */; };
Expand All @@ -66,6 +63,9 @@
D87183D11FC58201000DD9EC /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D87182F61FC55F36000DD9EC /* SystemConfiguration.framework */; };
D87183D21FC5820B000DD9EC /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D87182FA1FC560D6000DD9EC /* CoreTelephony.framework */; };
D87A0E022057F54B006D2F48 /* ConcurrencyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D87A0E012057F54B006D2F48 /* ConcurrencyTests.m */; };
D88AD7EB2180205600B34D47 /* OSSManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D88AD7E52180205600B34D47 /* OSSManager.m */; };
D88AD7EC2180205600B34D47 /* OSSWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = D88AD7E62180205600B34D47 /* OSSWrapper.m */; };
D88AD7ED2180205600B34D47 /* DownloadService.m in Sources */ = {isa = PBXBuildFile; fileRef = D88AD7EA2180205600B34D47 /* DownloadService.m */; };
D8C41A641FCC002C0091699B /* test.xml in Resources */ = {isa = PBXBuildFile; fileRef = D83D58F91FC700C70022761B /* test.xml */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -111,8 +111,6 @@
4C7B5BE82043A15100FDD612 /* wangwang.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = wangwang.zip; sourceTree = "<group>"; };
D1805034212EA0F700A1E647 /* OSSHttp2Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSSHttp2Test.m; sourceTree = "<group>"; };
D810A00A2092F76900425D19 /* OSSUtilsTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSSUtilsTests.m; sourceTree = "<group>"; };
D8125E8F211BCC4C00DB687C /* DownloadService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DownloadService.h; sourceTree = "<group>"; };
D8125E90211BCC4C00DB687C /* DownloadService.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DownloadService.m; sourceTree = "<group>"; };
D8125E95211DAFA500DB687C /* OSSClientTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSSClientTests.m; sourceTree = "<group>"; };
D827E40C1FCD0FC60085380C /* AliyunOSSSDK-OSX-Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "AliyunOSSSDK-OSX-Example.app"; sourceTree = BUILT_PRODUCTS_DIR; };
D827E40E1FCD0FC60085380C /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -142,10 +140,6 @@
D83D58BD1FC6B3100022761B /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
D83D58BF1FC6B3100022761B /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
D83D58C51FC6B3100022761B /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
D83D58C81FC6B3100022761B /* ImageService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageService.m; sourceTree = "<group>"; };
D83D58C91FC6B3100022761B /* OssService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OssService.m; sourceTree = "<group>"; };
D83D58CA1FC6B3100022761B /* ImageService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageService.h; sourceTree = "<group>"; };
D83D58CB1FC6B3100022761B /* OssService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OssService.h; sourceTree = "<group>"; };
D83D58CC1FC6B3100022761B /* ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
D83D58DD1FC6B61F0022761B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
D83D58DE1FC6B61F0022761B /* AliyunOSSSDK-iOS-Example-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AliyunOSSSDK-iOS-Example-Prefix.pch"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -174,6 +168,12 @@
D87183C01FC572C6000DD9EC /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D87183C11FC572C6000DD9EC /* OSSReachabilityTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSSReachabilityTests.m; sourceTree = "<group>"; };
D87A0E012057F54B006D2F48 /* ConcurrencyTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ConcurrencyTests.m; sourceTree = "<group>"; };
D88AD7E52180205600B34D47 /* OSSManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSSManager.m; sourceTree = "<group>"; };
D88AD7E62180205600B34D47 /* OSSWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSSWrapper.m; sourceTree = "<group>"; };
D88AD7E72180205600B34D47 /* DownloadService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DownloadService.h; sourceTree = "<group>"; };
D88AD7E82180205600B34D47 /* OSSManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSSManager.h; sourceTree = "<group>"; };
D88AD7E92180205600B34D47 /* OSSWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSSWrapper.h; sourceTree = "<group>"; };
D88AD7EA2180205600B34D47 /* DownloadService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DownloadService.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -242,28 +242,15 @@
D83D58BC1FC6B3100022761B /* Classes */ = {
isa = PBXGroup;
children = (
D88AD7E42180205600B34D47 /* Wrapper */,
D83D58BD1FC6B3100022761B /* AppDelegate.h */,
D83D58C51FC6B3100022761B /* AppDelegate.m */,
D83D58CC1FC6B3100022761B /* ViewController.h */,
D83D58BF1FC6B3100022761B /* ViewController.m */,
D83D58C71FC6B3100022761B /* Services */,
);
path = Classes;
sourceTree = "<group>";
};
D83D58C71FC6B3100022761B /* Services */ = {
isa = PBXGroup;
children = (
D83D58C81FC6B3100022761B /* ImageService.m */,
D83D58C91FC6B3100022761B /* OssService.m */,
D83D58CA1FC6B3100022761B /* ImageService.h */,
D83D58CB1FC6B3100022761B /* OssService.h */,
D8125E8F211BCC4C00DB687C /* DownloadService.h */,
D8125E90211BCC4C00DB687C /* DownloadService.m */,
);
path = Services;
sourceTree = "<group>";
};
D83D58DC1FC6B61F0022761B /* Supporting Files */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -369,6 +356,19 @@
path = ../AliyunOSSiOSTests;
sourceTree = "<group>";
};
D88AD7E42180205600B34D47 /* Wrapper */ = {
isa = PBXGroup;
children = (
D88AD7E52180205600B34D47 /* OSSManager.m */,
D88AD7E62180205600B34D47 /* OSSWrapper.m */,
D88AD7E72180205600B34D47 /* DownloadService.h */,
D88AD7E82180205600B34D47 /* OSSManager.h */,
D88AD7E92180205600B34D47 /* OSSWrapper.h */,
D88AD7EA2180205600B34D47 /* DownloadService.m */,
);
path = Wrapper;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -530,12 +530,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D83D58D31FC6B3100022761B /* OssService.m in Sources */,
D83D58D21FC6B3100022761B /* ImageService.m in Sources */,
D83D58D11FC6B3100022761B /* AppDelegate.m in Sources */,
D8125E91211BCC4C00DB687C /* DownloadService.m in Sources */,
D83D58E21FC6B61F0022761B /* main.m in Sources */,
D83D58CE1FC6B3100022761B /* ViewController.m in Sources */,
D88AD7ED2180205600B34D47 /* DownloadService.m in Sources */,
D88AD7EB2180205600B34D47 /* OSSManager.m in Sources */,
D88AD7EC2180205600B34D47 /* OSSWrapper.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Loading

0 comments on commit 54a5efa

Please sign in to comment.