|
20 | 20 | import com.optimizely.ab.config.Experiment; |
21 | 21 | import com.optimizely.ab.config.FeatureFlag; |
22 | 22 | import com.optimizely.ab.config.ProjectConfig; |
| 23 | +import com.optimizely.ab.config.ProjectConfigTestUtils; |
23 | 24 | import com.optimizely.ab.config.Rollout; |
24 | 25 | import com.optimizely.ab.config.TrafficAllocation; |
25 | 26 | import com.optimizely.ab.config.ValidProjectConfigV4; |
|
43 | 44 | import static com.optimizely.ab.config.ProjectConfigTestUtils.validProjectConfigV3; |
44 | 45 | import static com.optimizely.ab.config.ProjectConfigTestUtils.validProjectConfigV4; |
45 | 46 | import static com.optimizely.ab.config.ValidProjectConfigV4.ATTRIBUTE_HOUSE_KEY; |
| 47 | +import static com.optimizely.ab.config.ValidProjectConfigV4.ATTRIBUTE_NATIONALITY_KEY; |
| 48 | +import static com.optimizely.ab.config.ValidProjectConfigV4.AUDIENCE_ENGLISH_CITIZENS_VALUE; |
46 | 49 | import static com.optimizely.ab.config.ValidProjectConfigV4.AUDIENCE_GRYFFINDOR_VALUE; |
47 | 50 | import static com.optimizely.ab.config.ValidProjectConfigV4.FEATURE_FLAG_MULTI_VARIATE_FEATURE; |
48 | 51 | import static com.optimizely.ab.config.ValidProjectConfigV4.FEATURE_FLAG_SINGLE_VARIABLE_STRING; |
@@ -425,7 +428,53 @@ public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTrafficI |
425 | 428 | verify(mockBucketer, times(2)).bucket(any(Experiment.class), anyString()); |
426 | 429 | } |
427 | 430 |
|
428 | | - //========= white list tests ==========/ |
| 431 | + /** |
| 432 | + * Verify that {@link DecisionService#getVariationForFeatureInRollout(FeatureFlag, String, Map)} |
| 433 | + * returns the variation of "Everyone Else" rule |
| 434 | + * when the user passes targeting for a rule, but was failed the traffic allocation for that rule, |
| 435 | + * and is bucketed successfully into the "Everyone Else" rule. |
| 436 | + * Fallback bucketing should not evaluate any other audiences. |
| 437 | + * Even though the user would satisfy a later rollout rule, they are never evaluated for it or bucketed into it. |
| 438 | + */ |
| 439 | + @Test |
| 440 | + public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTrafficInRuleButWouldPassForAnotherRuleAndPassesInEveryoneElse() { |
| 441 | + Bucketer mockBucketer = mock(Bucketer.class); |
| 442 | + Rollout rollout = ROLLOUT_2; |
| 443 | + Experiment englishCitizensRule = rollout.getExperiments().get(2); |
| 444 | + Variation englishCitizenVariation = englishCitizensRule.getVariations().get(0); |
| 445 | + Experiment everyoneElseRule = rollout.getExperiments().get(rollout.getExperiments().size() - 1); |
| 446 | + Variation expectedVariation = everyoneElseRule.getVariations().get(0); |
| 447 | + when(mockBucketer.bucket(any(Experiment.class), anyString())).thenReturn(null); |
| 448 | + when(mockBucketer.bucket(eq(everyoneElseRule), anyString())).thenReturn(expectedVariation); |
| 449 | + when(mockBucketer.bucket(eq(englishCitizensRule), anyString())).thenReturn(englishCitizenVariation); |
| 450 | + |
| 451 | + DecisionService decisionService = new DecisionService( |
| 452 | + mockBucketer, |
| 453 | + mockErrorHandler, |
| 454 | + v4ProjectConfig, |
| 455 | + null |
| 456 | + ); |
| 457 | + |
| 458 | + assertEquals(expectedVariation, |
| 459 | + decisionService.getVariationForFeatureInRollout( |
| 460 | + FEATURE_FLAG_MULTI_VARIATE_FEATURE, |
| 461 | + genericUserId, |
| 462 | + ProjectConfigTestUtils.createMapOfObjects( |
| 463 | + ProjectConfigTestUtils.createListOfObjects( |
| 464 | + ATTRIBUTE_HOUSE_KEY, ATTRIBUTE_NATIONALITY_KEY |
| 465 | + ), |
| 466 | + ProjectConfigTestUtils.createListOfObjects( |
| 467 | + AUDIENCE_GRYFFINDOR_VALUE, AUDIENCE_ENGLISH_CITIZENS_VALUE |
| 468 | + ) |
| 469 | + ) |
| 470 | + ) |
| 471 | + ); |
| 472 | + |
| 473 | + // verify user is only bucketed once for everyone else rule |
| 474 | + verify(mockBucketer, times(2)).bucket(any(Experiment.class), anyString()); |
| 475 | + } |
| 476 | + |
| 477 | + //========= white list tests ==========/ |
429 | 478 |
|
430 | 479 | /** |
431 | 480 | * Test {@link DecisionService#getWhitelistedVariation(Experiment, String)} correctly returns a whitelisted variation. |
|
0 commit comments