Skip to content

Commit b610c2d

Browse files
committed
add proxy test
1 parent 718f6f2 commit b610c2d

File tree

8 files changed

+97
-5
lines changed

8 files changed

+97
-5
lines changed

QiniuSDK/QiniuSDK.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
#import "QNUploadOption.h"
1414
#import "QNUploadManager.h"
1515
#import "QNFileRecorder.h"
16+
#import "QNConfiguration.h"

QiniuSDK/Storage/QNConfiguration.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,11 @@ typedef void (^QNConfigurationBuilderBlock)(QNConfigurationBuilder *builder);
6464
@property (readonly) UInt32 timeoutInterval;
6565

6666

67-
@property (nonatomic, strong, readonly) id <QNRecorderDelegate> recorder;
67+
@property (nonatomic, readonly) id <QNRecorderDelegate> recorder;
6868

69-
@property (nonatomic, strong, readonly) QNRecorderKeyGenerator recorderKeyGen;
70-
71-
@property (nonatomic, strong, readonly) NSDictionary *proxy;
69+
@property (nonatomic, readonly) QNRecorderKeyGenerator recorderKeyGen;
7270

71+
@property (nonatomic, readonly) NSDictionary *proxy;
7372

7473
+ (instancetype)build:(QNConfigurationBuilderBlock)block;
7574

QiniuSDK/Storage/QNConfiguration.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ - (instancetype)initWithBuilder:(QNConfigurationBuilder *)builder {
2727
_putThreshold = builder.putThreshold;
2828
_retryMax = builder.retryMax;
2929
_timeoutInterval = builder.timeoutInterval;
30+
31+
_recorder = builder.recorder;
32+
_recorderKeyGen = builder.recorderKeyGen;
33+
34+
_proxy = builder.proxy;
3035
}
3136
return self;
3237
}

QiniuSDK/Storage/QNUploadManager.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ - (void)putFile:(NSString *)filePath
191191
recorderKey = _config.recorderKeyGen(key, filePath);
192192
}
193193

194+
NSLog(@"recorder %@", _config.recorder);
195+
194196
QNResumeUpload *up = [[QNResumeUpload alloc]
195197
initWithData:data
196198
withSize:fileSize

QiniuSDKTests/QNFileRecorderTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ - (void)template:(int)size pos:(float)pos {
7676
info = nil;
7777
__block BOOL failed = NO;
7878
opt = [[QNUploadOption alloc] initWithMime:nil progressHandler: ^(NSString *key, float percent) {
79-
if (percent < pos - 256 * 1024 / (size * 1024.0)) {
79+
if (percent < pos - (256 * 1024.0) / (size * 1024.0)) {
8080
failed = YES;
8181
}
8282
NSLog(@"continue progress %f", percent);

QiniuSDKTests/QNFormUploadTest.m

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,38 @@ - (void)testNoKey {
164164
XCTAssert([@"FgoKnypncpQlV6tTVddq9EL49l4B" isEqualToString:testResp[@"key"]], @"Pass");
165165
}
166166

167+
- (void)testProxy {
168+
__block QNResponseInfo *testInfo = nil;
169+
__block NSDictionary *testResp = nil;
170+
__block NSString *key = nil;
171+
172+
NSDictionary *proxyDict = @{
173+
@"HTTPEnable" : [NSNumber numberWithInt:1],
174+
(NSString *)kCFStreamPropertyHTTPProxyHost : @"183.136.139.16",
175+
(NSString *)kCFStreamPropertyHTTPProxyPort : @8888,
176+
};
177+
178+
QNConfiguration *config = [QNConfiguration build: ^(QNConfigurationBuilder *builder) {
179+
builder.proxy = proxyDict;
180+
builder.zone = [[QNZone alloc] initWithUpHost:@"upnono.qiniu.com" upHostBackup:@"" upIp:@""];
181+
}];
182+
183+
QNUploadManager *upManager = [[QNUploadManager alloc] initWithConfiguration:config];
184+
185+
NSData *data = [@"Hello, World!" dataUsingEncoding:NSUTF8StringEncoding];
186+
[upManager putData:data key:nil token:g_token complete: ^(QNResponseInfo *info, NSString *k, NSDictionary *resp) {
187+
key = k;
188+
testInfo = info;
189+
testResp = resp;
190+
} option:nil];
191+
192+
AGWW_WAIT_WHILE(testInfo == nil, 100.0);
193+
NSLog(@"%@", testInfo);
194+
NSLog(@"%@", testResp);
195+
XCTAssert(key == nil, @"Pass");
196+
XCTAssert(testInfo.isOK, @"Pass");
197+
XCTAssert(testInfo.reqId, @"Pass");
198+
XCTAssert([@"FgoKnypncpQlV6tTVddq9EL49l4B" isEqualToString:testResp[@"key"]], @"Pass");
199+
}
200+
167201
@end

QiniuSDKTests/QNResumeUploadTest.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,37 @@ - (void)test8M {
133133
[self template:8 * 1024 + 1];
134134
}
135135

136+
- (void)testProxy {
137+
NSDictionary *proxyDict = @{
138+
@"HTTPEnable" : [NSNumber numberWithInt:1],
139+
(NSString *)kCFStreamPropertyHTTPProxyHost : @"183.136.139.16",
140+
(NSString *)kCFStreamPropertyHTTPProxyPort : @8888,
141+
};
142+
143+
QNConfiguration *config = [QNConfiguration build: ^(QNConfigurationBuilder *builder) {
144+
builder.proxy = proxyDict;
145+
builder.zone = [[QNZone alloc] initWithUpHost:@"upnono.qiniu.com" upHostBackup:@"" upIp:@""];
146+
}];
147+
148+
QNUploadManager *upManager = [[QNUploadManager alloc] initWithConfiguration:config];
149+
150+
int size = 6 * 1024;
151+
NSURL *tempFile = [QNTempFile createTempfileWithSize:size * 1024];
152+
NSString *keyUp = [NSString stringWithFormat:@"%dkproxy", size];
153+
__block QNResponseInfo *info = nil;
154+
__block NSString *key = nil;
155+
[upManager putFile:tempFile.path key:keyUp token:g_token complete: ^(QNResponseInfo *i, NSString *k, NSDictionary *resp) {
156+
key = k;
157+
info = i;
158+
} option:nil];
159+
160+
AGWW_WAIT_WHILE(key == nil, 60 * 30);
161+
NSLog(@"info %@", info);
162+
XCTAssert(info.isOK, @"Pass");
163+
XCTAssert([keyUp isEqualToString:key], @"Pass");
164+
165+
[QNTempFile removeTempfile:tempFile];
166+
}
167+
136168
#endif
137169
@end

QiniuSDKTests/QNSessionTest.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,25 @@ - (void)testPost {
8383
XCTAssert(testInfo.error != nil, @"Pass");
8484
}
8585

86+
- (void)testProxy {
87+
NSDictionary *proxyDict = @{
88+
@"HTTPEnable" : [NSNumber numberWithInt:1],
89+
(NSString *)kCFStreamPropertyHTTPProxyHost : @"183.136.139.16",
90+
(NSString *)kCFStreamPropertyHTTPProxyPort : @8888,
91+
};
92+
93+
QNSessionManager *httpManager = [[QNSessionManager alloc] initWithProxy:proxyDict timeout:60];
94+
NSData *data = [@"Hello, World!" dataUsingEncoding:NSUTF8StringEncoding];
95+
__block QNResponseInfo *testInfo = nil;
96+
[httpManager post:@"http://up123.qiniu.com" withData:data withParams:nil withHeaders:nil withCompleteBlock: ^(QNResponseInfo *info, NSDictionary *resp) {
97+
testInfo = info;
98+
} withProgressBlock:nil withCancelBlock:nil];
99+
100+
AGWW_WAIT_WHILE(testInfo == nil, 100.0);
101+
NSLog(@"%@", testInfo);
102+
XCTAssert(testInfo.reqId, @"Pass");
103+
}
104+
86105
@end
87106

88107
#endif

0 commit comments

Comments
 (0)