15
15
import static com .launchdarkly .client .TestUtil .jdouble ;
16
16
import static com .launchdarkly .client .TestUtil .jint ;
17
17
import static com .launchdarkly .client .TestUtil .js ;
18
- import static com .launchdarkly .client .TestUtil .makeClauseToMatchUser ;
19
- import static com .launchdarkly .client .TestUtil .makeClauseToNotMatchUser ;
20
18
import static com .launchdarkly .client .TestUtil .specificEventProcessor ;
21
19
import static com .launchdarkly .client .TestUtil .specificFeatureStore ;
22
20
import static com .launchdarkly .client .VersionedDataKind .FEATURES ;
23
21
import static org .junit .Assert .assertEquals ;
24
- import static org .junit .Assert .assertFalse ;
25
22
import static org .junit .Assert .assertNull ;
26
- import static org .junit .Assert .assertTrue ;
27
23
28
24
public class LDClientEventTest {
29
25
private static final LDUser user = new LDUser ("userkey" );
@@ -261,111 +257,6 @@ public void jsonVariationDetailSendsEventForUnknownFlag() throws Exception {
261
257
EvaluationReason .error (ErrorKind .FLAG_NOT_FOUND ));
262
258
}
263
259
264
- @ Test
265
- public void eventTrackingAndReasonCanBeForcedForRule () throws Exception {
266
- Clause clause = makeClauseToMatchUser (user );
267
- Rule rule = new RuleBuilder ().id ("id" ).clauses (clause ).variation (1 ).trackEvents (true ).build ();
268
- FeatureFlag flag = new FeatureFlagBuilder ("flag" )
269
- .on (true )
270
- .rules (Arrays .asList (rule ))
271
- .offVariation (0 )
272
- .variations (js ("off" ), js ("on" ))
273
- .build ();
274
- featureStore .upsert (FEATURES , flag );
275
-
276
- client .stringVariation ("flag" , user , "default" );
277
-
278
- // Note, we did not call stringVariationDetail and the flag is not tracked, but we should still get
279
- // tracking and a reason, because the rule-level trackEvents flag is on for the matched rule.
280
-
281
- assertEquals (1 , eventSink .events .size ());
282
- Event .FeatureRequest event = (Event .FeatureRequest )eventSink .events .get (0 );
283
- assertTrue (event .trackEvents );
284
- assertEquals (EvaluationReason .ruleMatch (0 , "id" ), event .reason );
285
- }
286
-
287
- @ Test
288
- public void eventTrackingAndReasonAreNotForcedIfFlagIsNotSetForMatchingRule () throws Exception {
289
- Clause clause0 = makeClauseToNotMatchUser (user );
290
- Clause clause1 = makeClauseToMatchUser (user );
291
- Rule rule0 = new RuleBuilder ().id ("id0" ).clauses (clause0 ).variation (1 ).trackEvents (true ).build ();
292
- Rule rule1 = new RuleBuilder ().id ("id1" ).clauses (clause1 ).variation (1 ).trackEvents (false ).build ();
293
- FeatureFlag flag = new FeatureFlagBuilder ("flag" )
294
- .on (true )
295
- .rules (Arrays .asList (rule0 , rule1 ))
296
- .offVariation (0 )
297
- .variations (js ("off" ), js ("on" ))
298
- .build ();
299
- featureStore .upsert (FEATURES , flag );
300
-
301
- client .stringVariation ("flag" , user , "default" );
302
-
303
- // It matched rule1, which has trackEvents: false, so we don't get the override behavior
304
-
305
- assertEquals (1 , eventSink .events .size ());
306
- Event .FeatureRequest event = (Event .FeatureRequest )eventSink .events .get (0 );
307
- assertFalse (event .trackEvents );
308
- assertNull (event .reason );
309
- }
310
-
311
- @ Test
312
- public void eventTrackingAndReasonCanBeForcedForFallthrough () throws Exception {
313
- FeatureFlag flag = new FeatureFlagBuilder ("flag" )
314
- .on (true )
315
- .fallthrough (new VariationOrRollout (0 , null ))
316
- .variations (js ("fall" ), js ("off" ), js ("on" ))
317
- .trackEventsFallthrough (true )
318
- .build ();
319
- featureStore .upsert (FEATURES , flag );
320
-
321
- client .stringVariation ("flag" , user , "default" );
322
-
323
- // Note, we did not call stringVariationDetail and the flag is not tracked, but we should still get
324
- // tracking and a reason, because trackEventsFallthrough is on and the evaluation fell through.
325
-
326
- assertEquals (1 , eventSink .events .size ());
327
- Event .FeatureRequest event = (Event .FeatureRequest )eventSink .events .get (0 );
328
- assertTrue (event .trackEvents );
329
- assertEquals (EvaluationReason .fallthrough (), event .reason );
330
- }
331
-
332
- @ Test
333
- public void eventTrackingAndReasonAreNotForcedForFallthroughIfFlagIsNotSet () throws Exception {
334
- FeatureFlag flag = new FeatureFlagBuilder ("flag" )
335
- .on (true )
336
- .fallthrough (new VariationOrRollout (0 , null ))
337
- .variations (js ("fall" ), js ("off" ), js ("on" ))
338
- .trackEventsFallthrough (false )
339
- .build ();
340
- featureStore .upsert (FEATURES , flag );
341
-
342
- client .stringVariation ("flag" , user , "default" );
343
-
344
- assertEquals (1 , eventSink .events .size ());
345
- Event .FeatureRequest event = (Event .FeatureRequest )eventSink .events .get (0 );
346
- assertFalse (event .trackEvents );
347
- assertNull (event .reason );
348
- }
349
-
350
- @ Test
351
- public void eventTrackingAndReasonAreNotForcedForFallthroughIfReasonIsNotFallthrough () throws Exception {
352
- FeatureFlag flag = new FeatureFlagBuilder ("flag" )
353
- .on (false ) // so the evaluation reason will be OFF, not FALLTHROUGH
354
- .offVariation (1 )
355
- .fallthrough (new VariationOrRollout (0 , null ))
356
- .variations (js ("fall" ), js ("off" ), js ("on" ))
357
- .trackEventsFallthrough (true )
358
- .build ();
359
- featureStore .upsert (FEATURES , flag );
360
-
361
- client .stringVariation ("flag" , user , "default" );
362
-
363
- assertEquals (1 , eventSink .events .size ());
364
- Event .FeatureRequest event = (Event .FeatureRequest )eventSink .events .get (0 );
365
- assertFalse (event .trackEvents );
366
- assertNull (event .reason );
367
- }
368
-
369
260
@ Test
370
261
public void eventIsSentForExistingPrererequisiteFlag () throws Exception {
371
262
FeatureFlag f0 = new FeatureFlagBuilder ("feature0" )
@@ -466,8 +357,6 @@ private void checkFeatureEvent(Event e, FeatureFlag flag, JsonElement value, Jso
466
357
assertEquals (defaultVal , fe .defaultVal );
467
358
assertEquals (prereqOf , fe .prereqOf );
468
359
assertEquals (reason , fe .reason );
469
- assertEquals (flag .isTrackEvents (), fe .trackEvents );
470
- assertEquals (flag .getDebugEventsUntilDate (), fe .debugEventsUntilDate );
471
360
}
472
361
473
362
private void checkUnknownFeatureEvent (Event e , String key , JsonElement defaultVal , String prereqOf ,
@@ -481,7 +370,5 @@ private void checkUnknownFeatureEvent(Event e, String key, JsonElement defaultVa
481
370
assertEquals (defaultVal , fe .defaultVal );
482
371
assertEquals (prereqOf , fe .prereqOf );
483
372
assertEquals (reason , fe .reason );
484
- assertFalse (fe .trackEvents );
485
- assertNull (fe .debugEventsUntilDate );
486
373
}
487
374
}
0 commit comments