阿里sdk

This commit is contained in:
Robin
2026-02-20 17:56:24 +08:00
parent 39524692e5
commit f3af234308
524 changed files with 58345 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
//
// CacheKeyFunctionTest.m
// AlicloudHttpDNSTests
//
// Created by xuyecan on 2024/6/12.
// Copyright © 2024 alibaba-inc.com. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "TestBase.h"
@interface CacheKeyFunctionTest : TestBase
@end
static NSString *sdnsHost = @"sdns1.onlyforhttpdnstest.run.place";
@implementation CacheKeyFunctionTest
+ (void)setUp {
[super setUp];
}
- (void)setUp {
[super setUp];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
self.httpdns = [[HttpDnsService alloc] initWithAccountID:100000];
});
[self.httpdns setLogEnabled:YES];
[self.httpdns setPersistentCacheIPEnabled:YES];
[self.httpdns setReuseExpiredIPEnabled:NO];
[self.httpdns setLogHandler:self];
self.currentTimeStamp = [[NSDate date] timeIntervalSince1970];
}
- (void)testSimpleSpecifyingCacheKeySituation {
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
NSString *testHost = hostNameIpPrefixMap.allKeys.firstObject;
NSString *cacheKey = [NSString stringWithFormat:@"cacheKey-%@", testHost];
__block NSString *ipPrefix = hostNameIpPrefixMap[testHost];
// 使ttl
[self.httpdns setTtlDelegate:nil];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
HttpdnsResult *result = [self.httpdns resolveHostSync:testHost byIpType:HttpdnsQueryIPTypeIpv4 withSdnsParams:nil sdnsCacheKey:cacheKey];
XCTAssertNotNil(result);
XCTAssertTrue([result.host isEqualToString:testHost]);
XCTAssertGreaterThan(result.ttl, 0);
// ipip
XCTAssertLessThan([[NSDate date] timeIntervalSince1970], result.lastUpdatedTimeInterval + result.ttl);
NSString *firstIp = [result firstIpv4Address];
if (![firstIp hasPrefix:ipPrefix]) {
printf("XCTAssertWillFailed, host: %s, firstIp: %s, ipPrefix: %s\n", [testHost UTF8String], [firstIp UTF8String], [ipPrefix UTF8String]);
}
XCTAssertTrue([firstIp hasPrefix:ipPrefix]);
dispatch_semaphore_signal(semaphore);
});
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
[NSThread sleepForTimeInterval:3];
//
[self.httpdns.requestManager cleanAllHostMemoryCache];
// db
[self.httpdns.requestManager syncLoadCacheFromDbToMemory];
HttpdnsResult *result = [self.httpdns resolveHostSyncNonBlocking:testHost byIpType:HttpdnsQueryIPTypeIpv4];
// 使cacheKeynil
XCTAssertNil(result);
result = [self.httpdns resolveHostSyncNonBlocking:testHost byIpType:HttpdnsQueryIPTypeIpv4 withSdnsParams:nil sdnsCacheKey:cacheKey];
XCTAssertNotNil(result);
XCTAssertTrue([result.host isEqualToString:testHost]);
NSString *firstIp = [result firstIpv4Address];
XCTAssertTrue([firstIp hasPrefix:ipPrefix]);
}
@end