Skip to content

Commit 9795baa

Browse files
authored
Merge branch 'master' into mnoman/gitActionIntegrationTest
2 parents 2c7606f + 2f786a1 commit 9795baa

File tree

10 files changed

+58
-49
lines changed

10 files changed

+58
-49
lines changed

android/src/main/java/com/optimizely/optimizely_flutter_sdk/OptimizelyFlutterClient.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import com.optimizely.ab.android.sdk.OptimizelyManager;
3838
import com.optimizely.ab.error.RaiseExceptionErrorHandler;
3939
import com.optimizely.ab.event.BatchEventProcessor;
40-
import com.optimizely.ab.event.EventHandler;
4140
import com.optimizely.ab.event.EventProcessor;
4241
import com.optimizely.ab.event.LogEvent;
4342
import com.optimizely.ab.notification.DecisionNotification;
@@ -74,14 +73,14 @@ protected void initializeOptimizely(@NonNull ArgumentsParser argumentsParser, @N
7473
}
7574
// EventDispatcher Default Values
7675
Integer batchSize = 10;
77-
Long timeInterval = TimeUnit.MINUTES.toMillis(1L); // Minutes
76+
long timeInterval = TimeUnit.MINUTES.toMillis(1L); // Minutes
7877
Integer maxQueueSize = 10000;
7978

8079
if (argumentsParser.getEventBatchSize() != null) {
8180
batchSize = argumentsParser.getEventBatchSize();
8281
}
8382
if (argumentsParser.getEventTimeInterval() != null) {
84-
timeInterval = TimeUnit.SECONDS.toMillis(argumentsParser.getEventBatchSize());
83+
timeInterval = TimeUnit.SECONDS.toMillis(argumentsParser.getEventTimeInterval());
8584
}
8685
if (argumentsParser.getEventMaxQueueSize() != null) {
8786
maxQueueSize = argumentsParser.getEventMaxQueueSize();
@@ -101,22 +100,24 @@ protected void initializeOptimizely(@NonNull ArgumentsParser argumentsParser, @N
101100
.build();
102101

103102
// Datafile Download Interval
104-
long periodicDownloadInterval = 10 * 60; // seconds
103+
long datafilePeriodicDownloadInterval = 10 * 60; // seconds
105104

106-
if (argumentsParser.getPeriodicDownloadInterval() != null) {
107-
periodicDownloadInterval = argumentsParser.getPeriodicDownloadInterval();
105+
if (argumentsParser.getDatafilePeriodicDownloadInterval() != null) {
106+
datafilePeriodicDownloadInterval = argumentsParser.getDatafilePeriodicDownloadInterval();
108107
}
109108
// Delete old user context
110109
userContextsTracker.remove(sdkKey);
111-
getOptimizelyClient(sdkKey).close();
110+
if (getOptimizelyClient(sdkKey) != null) {
111+
getOptimizelyClient(sdkKey).close();
112+
}
112113
optimizelyManagerTracker.remove(sdkKey);
113114

114115
// Creating new instance
115116
OptimizelyManager optimizelyManager = OptimizelyManager.builder()
116117
.withEventProcessor(batchProcessor)
117118
.withEventHandler(eventHandler)
118119
.withNotificationCenter(notificationCenter)
119-
.withDatafileDownloadInterval(periodicDownloadInterval, TimeUnit.SECONDS)
120+
.withDatafileDownloadInterval(datafilePeriodicDownloadInterval, TimeUnit.SECONDS)
120121
.withErrorHandler(new RaiseExceptionErrorHandler())
121122
.withSDKKey(sdkKey)
122123
.build(context);

android/src/main/java/com/optimizely/optimizely_flutter_sdk/helper_classes/ArgumentsParser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ public Integer getEventBatchSize() {
7979
return (Integer) arguments.get(Constants.RequestParameterKey.EVENT_BATCH_SIZE);
8080
}
8181

82-
public Long getEventTimeInterval() {
83-
return (Long) arguments.get(Constants.RequestParameterKey.EVENT_TIME_INTERVAL);
82+
public Integer getEventTimeInterval() {
83+
return (Integer) arguments.get(Constants.RequestParameterKey.EVENT_TIME_INTERVAL);
8484
}
8585

8686
public Integer getEventMaxQueueSize() {
8787
return (Integer) arguments.get(Constants.RequestParameterKey.EVENT_MAX_QUEUE_SIZE);
8888
}
8989

90-
public Long getPeriodicDownloadInterval() {
91-
return (Long) arguments.get(Constants.RequestParameterKey.PERIODIC_DOWNLOAD_INTERVAL);
90+
public Integer getDatafilePeriodicDownloadInterval() {
91+
return (Integer) arguments.get(Constants.RequestParameterKey.DATAFILE_PERIODIC_DOWNLOAD_INTERVAL);
9292
}
9393
}

android/src/main/java/com/optimizely/optimizely_flutter_sdk/helper_classes/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static class RequestParameterKey {
5151
public static final String EVENT_BATCH_SIZE = "eventBatchSize";
5252
public static final String EVENT_TIME_INTERVAL = "eventTimeInterval";
5353
public static final String EVENT_MAX_QUEUE_SIZE = "eventMaxQueueSize";
54-
public static final String PERIODIC_DOWNLOAD_INTERVAL = "periodicDownloadInterval";
54+
public static final String DATAFILE_PERIODIC_DOWNLOAD_INTERVAL = "datafilePeriodicDownloadInterval";
5555
public static final String EVENT_KEY = "eventKey";
5656
public static final String EVENT_TAGS = "eventTags";
5757
public static final String FLAG_KEY = "flagKey";

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class _MyAppState extends State<MyApp> {
2525

2626
Future<void> runOptimizelySDK() async {
2727
var flutterSDK = OptimizelyFlutterSdk("X9mZd2WDywaUL9hZXyh9A",
28-
periodicDownloadInterval: 10 * 60,
28+
datafilePeriodicDownloadInterval: 10 * 60,
2929
eventOptions: const EventOptions(
3030
batchSize: 1, timeInterval: 60, maxQueueSize: 10000));
3131
var response = await flutterSDK.initializeClient();

ios/Classes/HelperClasses/Constants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct RequestParameterKey {
6868
static let eventBatchSize = "eventBatchSize"
6969
static let eventTimeInterval = "eventTimeInterval"
7070
static let eventMaxQueueSize = "eventMaxQueueSize"
71-
static let periodicDownloadInterval = "periodicDownloadInterval"
71+
static let datafilePeriodicDownloadInterval = "datafilePeriodicDownloadInterval"
7272
}
7373

7474
struct ResponseKey {

ios/Classes/SwiftOptimizelyFlutterSdkPlugin.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ public class SwiftOptimizelyFlutterSdkPlugin: NSObject, FlutterPlugin {
8383
let eventDispatcher = DefaultEventDispatcher(batchSize: batchSize, backingStore: .file, dataStoreName: "OPTEventQueue", timerInterval: timeInterval, maxQueueSize: maxQueueSize)
8484

8585
// Datafile Download Interval
86-
var periodicDownloadInterval = 10 * 60 // seconds
86+
var datafilePeriodicDownloadInterval = 10 * 60 // seconds
8787

88-
if let _periodicDownloadInterval = parameters[RequestParameterKey.periodicDownloadInterval] as? Int {
89-
periodicDownloadInterval = _periodicDownloadInterval
88+
if let _datafilePeriodicDownloadInterval = parameters[RequestParameterKey.datafilePeriodicDownloadInterval] as? Int {
89+
datafilePeriodicDownloadInterval = _datafilePeriodicDownloadInterval
9090
}
9191

9292
// Delete old user context
@@ -96,7 +96,7 @@ public class SwiftOptimizelyFlutterSdkPlugin: NSObject, FlutterPlugin {
9696
optimizelyClientsTracker.removeValue(forKey: sdkKey)
9797

9898
// Creating new instance
99-
let optimizelyInstance = OptimizelyClient(sdkKey:sdkKey, eventDispatcher: eventDispatcher, periodicDownloadInterval: periodicDownloadInterval)
99+
let optimizelyInstance = OptimizelyClient(sdkKey:sdkKey, eventDispatcher: eventDispatcher, periodicDownloadInterval: datafilePeriodicDownloadInterval)
100100

101101
optimizelyInstance.start{ [weak self] res in
102102
switch res {

lib/optimizely_flutter_sdk.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,26 @@ export 'package:optimizely_flutter_sdk/src/data_objects/event_options.dart'
4242

4343
/// The main client class for the Optimizely Flutter SDK.
4444
///
45-
/// To use, create an instance of OptimizelyFlutterSdk class with a valid sdkKey, periodicDownloadInterval (optional), eventOptions (optional) and
45+
/// To use, create an instance of OptimizelyFlutterSdk class with a valid sdkKey, datafilePeriodicDownloadInterval (optional), eventOptions (optional) and
4646
/// call initializeClient method.
4747
/// If successfull, call createUserContext to setup user context.
4848
/// Once done, all API's should be available.
4949
class OptimizelyFlutterSdk {
5050
final String _sdkKey;
51-
final int _periodicDownloadInterval;
51+
final int _datafilePeriodicDownloadInterval;
5252
final EventOptions _eventOptions;
5353

5454
OptimizelyFlutterSdk(this._sdkKey,
55-
{periodicDownloadInterval = 10 * 60, // Default time interval in seconds
55+
{datafilePeriodicDownloadInterval =
56+
10 * 60, // Default time interval in seconds
5657
EventOptions eventOptions = const EventOptions()})
57-
: _periodicDownloadInterval = periodicDownloadInterval,
58+
: _datafilePeriodicDownloadInterval = datafilePeriodicDownloadInterval,
5859
_eventOptions = eventOptions;
5960

6061
/// Starts Optimizely SDK (Synchronous) with provided sdkKey.
6162
Future<BaseResponse> initializeClient() async {
6263
return await OptimizelyClientWrapper.initializeClient(
63-
_sdkKey, _periodicDownloadInterval, _eventOptions);
64+
_sdkKey, _datafilePeriodicDownloadInterval, _eventOptions);
6465
}
6566

6667
/// Returns a snapshot of the current project configuration.

lib/src/optimizely_client_wrapper.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ class OptimizelyClientWrapper {
4444

4545
/// Starts Optimizely SDK (Synchronous) with provided sdkKey and options.
4646
static Future<BaseResponse> initializeClient(String sdkKey,
47-
int periodicDownloadInterval, EventOptions eventOptions) async {
47+
int datafilePeriodicDownloadInterval, EventOptions eventOptions) async {
4848
_channel.setMethodCallHandler(methodCallHandler);
4949
Map<String, dynamic> requestDict = {
5050
Constants.sdkKey: sdkKey,
51-
Constants.periodicDownloadInterval: periodicDownloadInterval,
51+
Constants.datafilePeriodicDownloadInterval:
52+
datafilePeriodicDownloadInterval,
5253
Constants.eventBatchSize: eventOptions.batchSize,
5354
Constants.eventTimeInterval: eventOptions.timeInterval,
5455
Constants.eventMaxQueueSize: eventOptions.maxQueueSize,

lib/src/utils/constants.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class Constants {
6262
static const String eventBatchSize = "eventBatchSize";
6363
static const String eventTimeInterval = "eventTimeInterval";
6464
static const String eventMaxQueueSize = "eventMaxQueueSize";
65-
static const String periodicDownloadInterval = "periodicDownloadInterval";
65+
static const String datafilePeriodicDownloadInterval =
66+
"datafilePeriodicDownloadInterval";
6667
static const String trackCallBackListener = "trackCallbackListener";
6768
static const String decisionCallBackListener = "decisionCallbackListener";
6869
static const String logEventCallbackListener = "logEventCallbackListener";

test/optimizely_flutter_sdk_test.dart

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ void main() {
3131
const String userId = "uid-351ea8";
3232
// To check if decide options properly reached the native sdk through channel
3333
List<String> decideOptions = [];
34-
// To check if event options and periodicDownloadInterval properly reached the native sdk through channel
34+
// To check if event options and datafilePeriodicDownloadInterval properly reached the native sdk through channel
3535
EventOptions eventOptions = const EventOptions();
36-
int periodicDownloadInterval = 0;
36+
int datafilePeriodicDownloadInterval = 0;
3737

3838
const MethodChannel channel = MethodChannel("optimizely_flutter_sdk");
3939
dynamic mockOptimizelyConfig;
@@ -64,8 +64,8 @@ void main() {
6464
batchSize: methodCall.arguments[Constants.eventBatchSize],
6565
maxQueueSize: methodCall.arguments[Constants.eventMaxQueueSize],
6666
timeInterval: methodCall.arguments[Constants.eventTimeInterval]);
67-
periodicDownloadInterval =
68-
methodCall.arguments[Constants.periodicDownloadInterval];
67+
datafilePeriodicDownloadInterval =
68+
methodCall.arguments[Constants.datafilePeriodicDownloadInterval];
6969
return {
7070
Constants.responseSuccess: true,
7171
Constants.responseReason: Constants.instanceCreated,
@@ -172,11 +172,12 @@ void main() {
172172
expect(response.reason, equals(Constants.instanceCreated));
173173
});
174174

175-
test("with no eventOptions and no periodicDownloadInterval", () async {
175+
test("with no eventOptions and no datafilePeriodicDownloadInterval",
176+
() async {
176177
// default values
177178
const expectedEventOptions =
178179
EventOptions(batchSize: 10, timeInterval: 60, maxQueueSize: 10000);
179-
const expectedPeriodicDownloadInterval = 10 * 60;
180+
const expectedDatafilePeriodicDownloadInterval = 10 * 60;
180181
var sdk = OptimizelyFlutterSdk(testSDKKey);
181182
var response = await sdk.initializeClient();
182183

@@ -187,17 +188,18 @@ void main() {
187188
equals(expectedEventOptions.maxQueueSize));
188189
expect(eventOptions.timeInterval,
189190
equals(expectedEventOptions.timeInterval));
190-
expect(
191-
periodicDownloadInterval, equals(expectedPeriodicDownloadInterval));
191+
expect(datafilePeriodicDownloadInterval,
192+
equals(expectedDatafilePeriodicDownloadInterval));
192193
});
193194

194-
test("with eventOptions and periodicDownloadInterval", () async {
195+
test("with eventOptions and datafilePeriodicDownloadInterval", () async {
195196
const expectedEventOptions =
196197
EventOptions(batchSize: 20, timeInterval: 30, maxQueueSize: 200);
197-
const expectedPeriodicDownloadInterval = 40;
198+
const expectedDatafilePeriodicDownloadInterval = 40;
198199
var sdk = OptimizelyFlutterSdk(testSDKKey,
199200
eventOptions: expectedEventOptions,
200-
periodicDownloadInterval: expectedPeriodicDownloadInterval);
201+
datafilePeriodicDownloadInterval:
202+
expectedDatafilePeriodicDownloadInterval);
201203
var response = await sdk.initializeClient();
202204

203205
expect(response.success, equals(true));
@@ -207,17 +209,19 @@ void main() {
207209
equals(expectedEventOptions.maxQueueSize));
208210
expect(eventOptions.timeInterval,
209211
equals(expectedEventOptions.timeInterval));
210-
expect(
211-
periodicDownloadInterval, equals(expectedPeriodicDownloadInterval));
212+
expect(datafilePeriodicDownloadInterval,
213+
equals(expectedDatafilePeriodicDownloadInterval));
212214
});
213215

214-
test("with no eventOptions and periodicDownloadInterval", () async {
216+
test("with no eventOptions and datafilePeriodicDownloadInterval",
217+
() async {
215218
// default values
216219
const expectedEventOptions =
217220
EventOptions(batchSize: 10, timeInterval: 60, maxQueueSize: 10000);
218-
const expectedPeriodicDownloadInterval = 500;
221+
const expectedDatafilePeriodicDownloadInterval = 500;
219222
var sdk = OptimizelyFlutterSdk(testSDKKey,
220-
periodicDownloadInterval: expectedPeriodicDownloadInterval);
223+
datafilePeriodicDownloadInterval:
224+
expectedDatafilePeriodicDownloadInterval);
221225
var response = await sdk.initializeClient();
222226

223227
expect(response.success, equals(true));
@@ -227,15 +231,16 @@ void main() {
227231
equals(expectedEventOptions.maxQueueSize));
228232
expect(eventOptions.timeInterval,
229233
equals(expectedEventOptions.timeInterval));
230-
expect(
231-
periodicDownloadInterval, equals(expectedPeriodicDownloadInterval));
234+
expect(datafilePeriodicDownloadInterval,
235+
equals(expectedDatafilePeriodicDownloadInterval));
232236
});
233237

234-
test("with eventOptions and no periodicDownloadInterval", () async {
238+
test("with eventOptions and no datafilePeriodicDownloadInterval",
239+
() async {
235240
// default values
236241
const expectedEventOptions =
237242
EventOptions(batchSize: 50, timeInterval: 80, maxQueueSize: 20000);
238-
const expectedPeriodicDownloadInterval = 10 * 60;
243+
const expectedDatafilePeriodicDownloadInterval = 10 * 60;
239244
var sdk = OptimizelyFlutterSdk(testSDKKey,
240245
eventOptions: expectedEventOptions);
241246
var response = await sdk.initializeClient();
@@ -247,8 +252,8 @@ void main() {
247252
equals(expectedEventOptions.maxQueueSize));
248253
expect(eventOptions.timeInterval,
249254
equals(expectedEventOptions.timeInterval));
250-
expect(
251-
periodicDownloadInterval, equals(expectedPeriodicDownloadInterval));
255+
expect(datafilePeriodicDownloadInterval,
256+
equals(expectedDatafilePeriodicDownloadInterval));
252257
});
253258
});
254259
group("close()", () {

0 commit comments

Comments
 (0)