|
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; |
|
44 | 45 | import static com.optimizely.ab.config.ProjectConfigTestUtils.validProjectConfigV3; |
45 | 46 | import static com.optimizely.ab.config.ProjectConfigTestUtils.validProjectConfigV4; |
46 | 47 | import static com.optimizely.ab.config.ValidProjectConfigV4.ATTRIBUTE_HOUSE_KEY; |
| 48 | +import static com.optimizely.ab.config.ValidProjectConfigV4.ATTRIBUTE_NATIONALITY_KEY; |
| 49 | +import static com.optimizely.ab.config.ValidProjectConfigV4.AUDIENCE_ENGLISH_CITIZENS_VALUE; |
47 | 50 | import static com.optimizely.ab.config.ValidProjectConfigV4.AUDIENCE_GRYFFINDOR_VALUE; |
48 | 51 | import static com.optimizely.ab.config.ValidProjectConfigV4.FEATURE_FLAG_MULTI_VARIATE_FEATURE; |
49 | 52 | import static com.optimizely.ab.config.ValidProjectConfigV4.FEATURE_FLAG_SINGLE_VARIABLE_STRING; |
@@ -562,7 +565,53 @@ public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTrafficI |
562 | 565 | verify(mockBucketer, times(2)).bucket(any(Experiment.class), anyString()); |
563 | 566 | } |
564 | 567 |
|
565 | | - //========= white list tests ==========/ |
| 568 | + /** |
| 569 | + * Verify that {@link DecisionService#getVariationForFeatureInRollout(FeatureFlag, String, Map)} |
| 570 | + * returns the variation of "Everyone Else" rule |
| 571 | + * when the user passes targeting for a rule, but was failed the traffic allocation for that rule, |
| 572 | + * and is bucketed successfully into the "Everyone Else" rule. |
| 573 | + * Fallback bucketing should not evaluate any other audiences. |
| 574 | + * Even though the user would satisfy a later rollout rule, they are never evaluated for it or bucketed into it. |
| 575 | + */ |
| 576 | + @Test |
| 577 | + public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTrafficInRuleButWouldPassForAnotherRuleAndPassesInEveryoneElse() { |
| 578 | + Bucketer mockBucketer = mock(Bucketer.class); |
| 579 | + Rollout rollout = ROLLOUT_2; |
| 580 | + Experiment englishCitizensRule = rollout.getExperiments().get(2); |
| 581 | + Variation englishCitizenVariation = englishCitizensRule.getVariations().get(0); |
| 582 | + Experiment everyoneElseRule = rollout.getExperiments().get(rollout.getExperiments().size() - 1); |
| 583 | + Variation expectedVariation = everyoneElseRule.getVariations().get(0); |
| 584 | + when(mockBucketer.bucket(any(Experiment.class), anyString())).thenReturn(null); |
| 585 | + when(mockBucketer.bucket(eq(everyoneElseRule), anyString())).thenReturn(expectedVariation); |
| 586 | + when(mockBucketer.bucket(eq(englishCitizensRule), anyString())).thenReturn(englishCitizenVariation); |
| 587 | + |
| 588 | + DecisionService decisionService = new DecisionService( |
| 589 | + mockBucketer, |
| 590 | + mockErrorHandler, |
| 591 | + v4ProjectConfig, |
| 592 | + null |
| 593 | + ); |
| 594 | + |
| 595 | + assertEquals(expectedVariation, |
| 596 | + decisionService.getVariationForFeatureInRollout( |
| 597 | + FEATURE_FLAG_MULTI_VARIATE_FEATURE, |
| 598 | + genericUserId, |
| 599 | + ProjectConfigTestUtils.createMapOfObjects( |
| 600 | + ProjectConfigTestUtils.createListOfObjects( |
| 601 | + ATTRIBUTE_HOUSE_KEY, ATTRIBUTE_NATIONALITY_KEY |
| 602 | + ), |
| 603 | + ProjectConfigTestUtils.createListOfObjects( |
| 604 | + AUDIENCE_GRYFFINDOR_VALUE, AUDIENCE_ENGLISH_CITIZENS_VALUE |
| 605 | + ) |
| 606 | + ) |
| 607 | + ) |
| 608 | + ); |
| 609 | + |
| 610 | + // verify user is only bucketed once for everyone else rule |
| 611 | + verify(mockBucketer, times(2)).bucket(any(Experiment.class), anyString()); |
| 612 | + } |
| 613 | + |
| 614 | + //========= white list tests ==========/ |
566 | 615 |
|
567 | 616 | /** |
568 | 617 | * Test {@link DecisionService#getWhitelistedVariation(Experiment, String)} correctly returns a whitelisted variation. |
|
0 commit comments