Skip to content

Commit c22ab94

Browse files
Changed property names and removed unused variables.
1 parent 8f28453 commit c22ab94

File tree

2 files changed

+29
-54
lines changed

2 files changed

+29
-54
lines changed

OptimizelySDKEventDispatcher/OptimizelySDKEventDispatcher/OPTLYEventDispatcher.m

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#import "OPTLYEventDispatcher.h"
1818

1919
// --- Event URLs ----
20-
NSString * const OPTLYEventDispatcherImpressionEventURL = @"https://logx.optimizely.com/log/decision"; // @"https://p13nlog.dz.optimizely.com/log/decision";
21-
NSString * const OPTLYEventDispatcherConversionEventURL = @"https://logx.optimizely.com/log/event"; // @"https://p13nlog.dz.optimizely.com/log/event";
20+
NSString * const OPTLYEventDispatcherImpressionEventURL = @"https://logx.optimizely.com/log/decision";
21+
NSString * const OPTLYEventDispatcherConversionEventURL = @"https://logx.optimizely.com/log/event";
2222

2323
// Default interval and timeout values (in ms) if not set by users
2424
NSInteger const OPTLYEventDispatcherDefaultDispatchIntervalTime_ms = 1000;
@@ -27,8 +27,8 @@
2727
@interface OPTLYEventDispatcher()
2828
@property (nonatomic, strong) OPTLYDataStore *dataStore;
2929
@property (nonatomic, strong) NSTimer *timer;
30-
@property (nonatomic, assign) uint64_t dispatchEventBackoffRetries;
31-
@property (nonatomic, assign) uint64_t dispatchEventCall;
30+
@property (nonatomic, assign) uint64_t flushEventBackoffRetries;
31+
@property (nonatomic, assign) uint64_t flushEventCall;
3232
@property (nonatomic, assign) uint64_t maxDispatchBackoffRetries;
3333
@end
3434

@@ -45,8 +45,8 @@ - (instancetype)init {
4545
- (instancetype)initWithBuilder:(OPTLYEventDispatcherBuilder *)builder {
4646
self = [super init];
4747
if (self != nil) {
48-
_dispatchEventBackoffRetries = 0;
49-
_dispatchEventCall = 0;
48+
_flushEventBackoffRetries = 0;
49+
_flushEventCall = 0;
5050
_timer = nil;
5151
_eventHandlerDispatchInterval = OPTLYEventDispatcherDefaultDispatchIntervalTime_ms;
5252
_eventHandlerDispatchTimeout = OPTLYEventDispatcherDefaultDispatchTimeout_ms;
@@ -203,8 +203,8 @@ - (void)dispatchEvent:(nonnull NSDictionary *)event
203203
[strongSelf.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
204204

205205
if (![strongSelf isTimerEnabled]) {
206-
strongSelf.dispatchEventBackoffRetries = 0;
207-
strongSelf.dispatchEventCall = 0;
206+
strongSelf.flushEventBackoffRetries = 0;
207+
strongSelf.flushEventCall = 0;
208208
[strongSelf setupNetworkTimer:^{
209209
if (callback) {
210210
callback(data, response, error);
@@ -263,18 +263,18 @@ - (void)flushEvents:(void(^)())callback
263263

264264
// setup the network timer if needed and reset all the counters
265265
if (![strongSelf isTimerEnabled]) {
266-
strongSelf.dispatchEventBackoffRetries = 0;
267-
strongSelf.dispatchEventCall = 0;
266+
strongSelf.flushEventBackoffRetries = 0;
267+
strongSelf.flushEventCall = 0;
268268
[strongSelf setupNetworkTimer:nil];
269269
}
270270

271-
strongSelf.dispatchEventCall++;
272-
OPTLYLogDebug(@"Dispatch event call - %ld", strongSelf.dispatchEventCall);
271+
strongSelf.flushEventCall++;
272+
OPTLYLogDebug(@"Dispatch event call - %ld", strongSelf.flushEventCall);
273273

274274
//exponential backoff: only dispatch at a power of two interval; o/w return
275-
if (![strongSelf isPowerOf2:strongSelf.dispatchEventCall]) {
275+
if (![strongSelf isPowerOf2:strongSelf.flushEventCall]) {
276276

277-
NSString *logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesEventDispatcherFlushEventsBackoffSkipRetry, strongSelf.dispatchEventCall];
277+
NSString *logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesEventDispatcherFlushEventsBackoffSkipRetry, strongSelf.flushEventCall];
278278
[strongSelf.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
279279

280280
if (callback) {
@@ -284,9 +284,9 @@ - (void)flushEvents:(void(^)())callback
284284
}
285285

286286
// stop trying to flush if max retries have been exceeded
287-
if (strongSelf.dispatchEventBackoffRetries > strongSelf.maxDispatchBackoffRetries) {
287+
if (strongSelf.flushEventBackoffRetries > strongSelf.maxDispatchBackoffRetries) {
288288

289-
NSString *logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesEventDispatcherFlushEventsBackoffMaxRetries, strongSelf.dispatchEventBackoffRetries];
289+
NSString *logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesEventDispatcherFlushEventsBackoffMaxRetries, strongSelf.flushEventBackoffRetries];
290290
[strongSelf.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
291291

292292
[self disableNetworkTimer:^{
@@ -297,8 +297,8 @@ - (void)flushEvents:(void(^)())callback
297297
return;
298298
}
299299

300-
strongSelf.dispatchEventBackoffRetries++;
301-
OPTLYLogDebug(@"Backoff retry - %ld.", strongSelf.dispatchEventBackoffRetries);
300+
strongSelf.flushEventBackoffRetries++;
301+
OPTLYLogDebug(@"Backoff retry - %ld.", strongSelf.flushEventBackoffRetries);
302302

303303
[strongSelf flushSavedEvents:OPTLYDataStoreEventTypeImpression cachedData:YES];
304304
[strongSelf flushSavedEvents:OPTLYDataStoreEventTypeConversion cachedData:YES];
@@ -328,11 +328,7 @@ - (void)flushSavedEvent:(NSDictionary *)event
328328
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
329329

330330
if (callback) {
331-
NSDictionary *errorMessage = [NSDictionary dictionaryWithObject:logMessage forKey:NSLocalizedDescriptionKey];
332-
NSError *error = [NSError errorWithDomain:OPTLYErrorHandlerMessagesDomain
333-
code:OPTLYErrorTypesEventDispatch
334-
userInfo:errorMessage];
335-
callback(nil, nil, error);
331+
callback(nil, nil, nil);
336332
}
337333
return;
338334
}

OptimizelySDKEventDispatcher/OptimizelySDKEventDispatcherTests/OPTLYEventDispatcherTest.m

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ @interface OPTLYEventDispatcher(test)
3030
@property (nonatomic, strong) OPTLYDataStore *dataStore;
3131
@property (nonatomic, strong) NSTimer *timer;
3232
@property (nonatomic, assign) NSInteger maxDispatchBackoffRetries;
33-
@property (nonatomic, assign) uint32_t dispatchEventBackoffRetries;
34-
@property (nonatomic, assign) uint32_t dispatchEventCall;
33+
@property (nonatomic, assign) uint32_t flushEventBackoffRetries;
34+
@property (nonatomic, assign) uint32_t flushEventCall;
3535
- (void)flushSavedEvent:(NSDictionary *)event
3636
eventType:(OPTLYDataStoreEventType)eventType
3737
cachedData:(BOOL)cachedData
@@ -63,7 +63,7 @@ - (void)setUp {
6363
self.testURL = [NSURL URLWithString:kTestURLString];
6464
self.parameters = @{@"testKey1" : @"testValue2", @"testKey2" : @"testValue2"};
6565
self.eventDispatcher = [OPTLYEventDispatcher new];
66-
self.eventDispatcher.dispatchEventBackoffRetries = 0;
66+
self.eventDispatcher.flushEventBackoffRetries = 0;
6767
}
6868

6969
- (void)tearDown {
@@ -198,12 +198,6 @@ - (void)eventDispatchFailureCheck:(OPTLYDataStoreEventType)eventType {
198198
// test dispatch attempt does not exceed the max retries
199199
// also check that the dispatch attempt is only made at power of 2 attempt count
200200
- (void)testMaxDispatchBackoffRetriesAndPowerOf2 {
201-
202-
BOOL usedCachedData = NO;
203-
#if TARGET_OS_TV
204-
usedCachedData = YES;
205-
#endif
206-
207201
[self stubFailureResponse];
208202

209203
OPTLYEventDispatcher *eventDispatcher = [OPTLYEventDispatcher initWithBuilderBlock:^(OPTLYEventDispatcherBuilder *builder) {
@@ -223,25 +217,25 @@ - (void)testMaxDispatchBackoffRetriesAndPowerOf2 {
223217
}
224218
__weak typeof(self) weakSelf = self;
225219
for (NSInteger i = 1; i < numberOfRetries; ++i) {
226-
//NSLog(@"Dispatch attempt - %ld. Dispatch event call - %u", i, eventDispatcher.dispatchEventCall);
220+
//NSLog(@"Dispatch attempt - %ld. Dispatch event call - %u", i, eventDispatcher.flushEventCall);
227221
[eventDispatcher flushEvents:^{
228-
NSLog(@"************ i - %ld, backoff retry - %u, dispatch call - %u", i, eventDispatcher.dispatchEventBackoffRetries, eventDispatcher.dispatchEventCall);
222+
NSLog(@"************ i - %ld, backoff retry - %u, dispatch call - %u", i, eventDispatcher.flushEventBackoffRetries, eventDispatcher.flushEventCall);
229223
// check that the dispatch attempt is only made at power of 2 attempt count
230224
NSInteger backoffRetryExpected = log2(i)+1;
231-
XCTAssert(eventDispatcher.dispatchEventBackoffRetries == backoffRetryExpected, @"Invalid value for the backoff retry count - %ld, %u, %ld", i, eventDispatcher.dispatchEventBackoffRetries, backoffRetryExpected);
225+
XCTAssert(eventDispatcher.flushEventBackoffRetries == backoffRetryExpected, @"Invalid value for the backoff retry count - %ld, %u, %ld", i, eventDispatcher.flushEventBackoffRetries, backoffRetryExpected);
232226

233-
XCTAssert(eventDispatcher.dispatchEventBackoffRetries <= eventDispatcher.maxDispatchBackoffRetries + 1, @"dispatch retries exceeded max - %u", eventDispatcher.dispatchEventBackoffRetries);
227+
XCTAssert(eventDispatcher.flushEventBackoffRetries <= eventDispatcher.maxDispatchBackoffRetries + 1, @"dispatch retries exceeded max - %u", eventDispatcher.flushEventBackoffRetries);
234228

235-
NSLog(@"dispatchEventCall - %u", eventDispatcher.dispatchEventCall);
236-
if (eventDispatcher.dispatchEventCall == numberOfRetries - 1) {
229+
NSLog(@"flushEventCall - %u", eventDispatcher.flushEventCall);
230+
if (eventDispatcher.flushEventCall == numberOfRetries - 1) {
237231
[weakSelf checkNetworkTimerIsEnabled:eventDispatcher
238232
timeInterval:kEventHandlerDispatchInterval];
239233
[expectation fulfill];
240234
}
241235
}];
242236
}
243237

244-
[self waitForExpectationsWithTimeout:20.0 handler:^(NSError *error) {
238+
[self waitForExpectationsWithTimeout:5.0 handler:^(NSError *error) {
245239
if (error) {
246240
NSLog(@"Timeout error for dispatchConversionEvent: %@", error);
247241
}
@@ -250,11 +244,6 @@ - (void)testMaxDispatchBackoffRetriesAndPowerOf2 {
250244

251245
- (void)testflushEventsSuccessSavedEvents {
252246

253-
BOOL usedCachedData = NO;
254-
#if TARGET_OS_TV
255-
usedCachedData = YES;
256-
#endif
257-
258247
[self stubSuccessResponse];
259248

260249
XCTestExpectation *expectation = [self expectationWithDescription:@"Wait for dispatchConversionEvent failure."];
@@ -282,11 +271,6 @@ - (void)testflushEventsSuccessSavedEvents {
282271

283272
- (void)testflushEventsSuccessNoSavedEvents {
284273

285-
BOOL usedCachedData = NO;
286-
#if TARGET_OS_TV
287-
usedCachedData = YES;
288-
#endif
289-
290274
[self stubSuccessResponse];
291275

292276
XCTestExpectation *expectation = [self expectationWithDescription:@"Wait for dispatchConversionEvent failure."];
@@ -308,11 +292,6 @@ - (void)testflushEventsSuccessNoSavedEvents {
308292

309293
- (void)testflushEventsFailureSavedEvents {
310294

311-
BOOL usedCachedData = NO;
312-
#if TARGET_OS_TV
313-
usedCachedData = YES;
314-
#endif
315-
316295
[self stubSuccessResponse];
317296

318297
XCTestExpectation *expectation = [self expectationWithDescription:@"Wait for dispatchConversionEvent failure."];

0 commit comments

Comments
 (0)