Commit 034a89c8 authored by 汪洋's avatar 汪洋

将存储区改为Document

parent b0f06ec9
......@@ -21,8 +21,6 @@
#ifdef POD_CONFIGURATION_APP_STORE
NSString *url = @"http://log.gmei.com/log/collect";
#elif POD_CONFIGURATION_UNIT_TEST
NSString *url = @"http://jaguar.gmei/log/collect";
#else
NSString *url = @"http://log.test.gengmei.cc/log/collect";
#endif
......
......@@ -8,6 +8,7 @@
#import <XCTest/XCTest.h>
#import "PhobosUtil.h"
@import GMPhobos;
@interface GMPhobosUtilTest : XCTestCase
@property (nonatomic, retain) NSMutableArray *mockArray;
......@@ -17,6 +18,9 @@
- (void)setUp {
[super setUp];
NSString *url = @"http://log.test.gengmei.cc/log/collect";
[Phobos setSharedClient:[Phobos clientWithAppName:@"gengmei_test" channelId:@"AppStore"]];
[Phobos sharedClient].serverAPI = url;
_mockArray = [[NSMutableArray alloc] init];
for (int i=0; i<50; i++) {
[_mockArray addObject:@{@"app":@{@"channel":@"App Store",@"name":@"gengmei_doctor",@"version":@"1.8.0"},
......@@ -57,7 +61,7 @@
*/
- (void)testSendDataToMars{
XCTestExpectation *expectation = [self expectationWithDescription:@"Testing Async Method Works!"];
NSData *mockData = [self encodeAndCompressArray:_mockArray];
[PhobosUtil sendData:mockData success:^(NSInteger code) {
[expectation fulfill];
......@@ -65,7 +69,7 @@
}];
//如果超时,则认为发送失败
[self waitForExpectationsWithTimeout:3 handler:^(NSError *error) {
[self waitForExpectationsWithTimeout:60 handler:^(NSError *error) {
if(error)
{
XCTFail(@"Expectation Failed with error: %@", error);
......
......@@ -36,7 +36,7 @@ NSString *const MockCityId = @"beijing";
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
[_cache removeObjectAtDiskWithkey:PhobosCacheKey];
[_cache removeObjectAtDucmentPathWithkey:PhobosCacheKey];
}
/**
......@@ -48,7 +48,7 @@ NSString *const MockCityId = @"beijing";
[_client setUserId:MockUserId];
[_client setCurrentCityId:MockCityId];
[Phobos track:MockEventId];
NSArray *array = [_cache fetchObjectAtDiskWithkey:PhobosCacheKey];
NSArray *array = [_cache fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count == 1, @"array is empty");
NSDictionary *dict = [array objectAtIndex:0];
[self verfiyDict:dict];
......@@ -62,7 +62,7 @@ NSString *const MockCityId = @"beijing";
*/
- (void)testTrackEventWithoutAttr{
[Phobos track:MockEventId];
NSArray *array = [_cache fetchObjectAtDiskWithkey:PhobosCacheKey];
NSArray *array = [_cache fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count == 1, @"array is empty");
NSDictionary *dict = [array objectAtIndex:0];
[self verfiyDict:dict];
......@@ -77,7 +77,7 @@ NSString *const MockCityId = @"beijing";
- (void)testTrackEventWithAttr{
NSDictionary *attr = @{@"attr":@"track_attr"};
[Phobos track:MockEventId attributes:attr];
NSArray *array = [_cache fetchObjectAtDiskWithkey:PhobosCacheKey];
NSArray *array = [_cache fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count == 1, @"array is empty");
NSDictionary *dict = [array objectAtIndex:0];
[self verfiyDict:dict];
......@@ -98,7 +98,7 @@ NSString *const MockCityId = @"beijing";
// When
[Phobos track:MockEventId attributes:attr sendNow:YES];
// Then
NSArray *array = [_cache fetchObjectAtDiskWithkey:PhobosCacheKey];
NSArray *array = [_cache fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count == 0, @"array should be empty");
}
......@@ -142,7 +142,7 @@ NSString *const MockCityId = @"beijing";
[controller viewWillAppear:true];
[controller viewWillDisappear:true];
[self paramUnNilCheck];
NSArray *array = [[WMCacheService sharedInstance] fetchObjectAtDiskWithkey:PhobosCacheKey];
NSArray *array = [[WMCacheService sharedInstance] fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count != 0, @"PhobosCacheKey 下面应该有数据");
NSDictionary *dic = array[0][@"params"];
......@@ -156,7 +156,7 @@ NSString *const MockCityId = @"beijing";
}
- (void)paramUnNilCheck {
NSArray *array = [[WMCacheService sharedInstance] fetchObjectAtDiskWithkey:PhobosCacheKey];
NSArray *array = [[WMCacheService sharedInstance] fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count != 0, @"PhobosCacheKey 下面应该有数据");
NSDictionary *dic = array[0][@"params"];
......
......@@ -108,10 +108,11 @@ static NSString *sdkVersion = @"110";
[Phobos track:@"device_opened" attributes:dict sendNow:YES];
/** 第一次打开APP埋点 **/
if (![cache fetchObjectAtDiskWithkey:PhobosHaveOpenApp]) {
// 当不再支持7.6.15版本时,只保留
if (![cache fetchObjectAtDiskWithkey:PhobosHaveOpenApp] || ![cache fetchObjectAtDucmentPathWithkey:PhobosHaveOpenApp]) {
[Phobos track:@"device_activated" attributes:@{} sendNow:YES];
[Phobos track:@"device_activated" attributes:@{} sendNow:NO];
[cache storeObjectAtDiskWithkey:PhobosHaveOpenApp object:PhobosHaveOpenApp];
[cache storeObjectAtDucmentPathWithkey:PhobosHaveOpenApp object:PhobosHaveOpenApp];
}
}
......@@ -154,7 +155,7 @@ static NSString *sdkVersion = @"110";
_serialId = 0;
_sessionId = [[NSUUID UUID] UUIDString];
WMCacheService *cache = [WMCacheService sharedInstance];
[cache storeObjectAtDiskWithkey:PhobosBeginTime object:[PhobosUtil currentTime]];
[cache storeObjectAtDucmentPathWithkey:PhobosBeginTime object:[PhobosUtil currentTime]];
}
/**
......@@ -201,7 +202,7 @@ static NSString *sdkVersion = @"110";
- (void)handleSessionOver{
WMCacheService *cache = [WMCacheService sharedInstance];
//进入后台的同时,把记录时间同步到服务端,把已使用时间清空
double beginTime = [[cache fetchObjectAtDiskWithkey:PhobosBeginTime] doubleValue];
double beginTime = [[cache fetchObjectAtDucmentPathWithkey:PhobosBeginTime] doubleValue];
if (beginTime == 0) {
return;
}
......@@ -220,7 +221,7 @@ static NSString *sdkVersion = @"110";
@"build_model": [UIDevice deviceVersion],
};
[Phobos track:@"on_app_session_over" attributes:dict];
[cache removeObjectAtDiskWithkey:PhobosBeginTime];
[cache removeObjectAtDucmentPathWithkey:PhobosBeginTime];
//当前session结束之后,把id置为0
_serialId = 0;
}
......@@ -252,7 +253,7 @@ static NSString *sdkVersion = @"110";
+ (void)track:(NSString *)eventId attributes:(NSDictionary *)attributes{
[self track:eventId attributes:attributes sendNow:NO];
NSArray *array = [[WMCacheService sharedInstance] fetchObjectAtDiskWithkey:PhobosCacheKey];
NSArray *array = [[WMCacheService sharedInstance] fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
//超过一定数量的话,统一发送一次
if (array.count > PhobosShardCount) {
[sharedClient sendArray:array cleanCacheRightNow:YES];
......@@ -398,13 +399,13 @@ static NSString *sdkVersion = @"110";
phobosLog([NSString stringWithFormat:@"save dictionary: %@",data]);
}
WMCacheService *cache = [WMCacheService sharedInstance];
NSMutableArray *dataArray = [cache fetchObjectAtDiskWithkey:PhobosCacheKey];
NSMutableArray *dataArray = [cache fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
if (dataArray) {
[dataArray addObject:data];
}else{
dataArray = [NSMutableArray arrayWithObject:data];
}
[cache storeObjectAtDiskWithkey:PhobosCacheKey object:dataArray];
[cache storeObjectAtDucmentPathWithkey:PhobosCacheKey object:dataArray];
}
/**
......@@ -413,7 +414,7 @@ static NSString *sdkVersion = @"110";
* @since 0.0.1
*/
- (void)fetchDataAndSend{
NSArray *paramsArray = [[WMCacheService sharedInstance] fetchObjectAtDiskWithkey:PhobosCacheKey];
NSArray *paramsArray = [[WMCacheService sharedInstance] fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
if (paramsArray.count>0) {
[self sendArray:paramsArray cleanCacheRightNow:YES];
}
......@@ -423,7 +424,7 @@ static NSString *sdkVersion = @"110";
从缓存区获取数据,发给服务器,请求成功的时候,把缓存区的数据删除掉
*/
- (void)sendArray {
NSMutableArray *dataArray = [[WMCacheService sharedInstance] fetchObjectAtDiskWithkey:PhobosTempCacheKey];
NSMutableArray *dataArray = [[WMCacheService sharedInstance] fetchObjectAtDucmentPathWithkey:PhobosTempCacheKey];
if (_logEnabled) {
phobosLog([NSString stringWithFormat:@"array prepare to fly --✈: %@",dataArray]);
}
......@@ -433,7 +434,7 @@ static NSString *sdkVersion = @"110";
if (compressedData) {
[PhobosUtil sendData:compressedData success:^(NSInteger code) {
phobosLog(@"✈ ---------- ✈ data arrived Mars");
[[WMCacheService sharedInstance] removeObjectAtDiskWithkey:PhobosTempCacheKey];
[[WMCacheService sharedInstance] removeObjectAtDucmentPathWithkey:PhobosTempCacheKey];
}];
}
}
......@@ -453,17 +454,17 @@ static NSString *sdkVersion = @"110";
@try {
//1.获取缓存区的数据,把新数据追加进去
WMCacheService *cache = [WMCacheService sharedInstance];
NSMutableArray *dataArray = [cache fetchObjectAtDiskWithkey:PhobosTempCacheKey];
NSMutableArray *dataArray = [cache fetchObjectAtDucmentPathWithkey:PhobosTempCacheKey];
if (dataArray) {
[dataArray addObjectsFromArray:array];
}else{
dataArray = [NSMutableArray arrayWithArray:array];
}
[cache storeObjectAtDiskWithkey:PhobosTempCacheKey object:dataArray];
[cache storeObjectAtDucmentPathWithkey:PhobosTempCacheKey object:dataArray];
//2.把缓存区的数据发送给服务器
[self sendArray];
//3.把原有的数据删除
[cache removeObjectAtDiskWithkey:PhobosCacheKey];
[cache removeObjectAtDucmentPathWithkey:PhobosCacheKey];
}
@catch (NSException *exception) {
phobosLog(exception);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment