Search in sources :

Example 6 with Rollout

use of com.optimizely.ab.config.Rollout in project java-sdk by optimizely.

the class DecisionServiceTest method getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTargetingInPreviousRulesButPassesRule3.

/**
 * Verify that {@link DecisionService#getVariationForFeatureInRollout(FeatureFlag, String, Map)}
 * returns the variation of "English Citizens" rule
 * when the user fails targeting for previous rules, but passes targeting and traffic for Rule 3.
 */
@Test
public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTargetingInPreviousRulesButPassesRule3() {
    Bucketer mockBucketer = mock(Bucketer.class);
    Rollout rollout = ROLLOUT_2;
    Experiment englishCitizensRule = rollout.getExperiments().get(2);
    Variation englishCitizenVariation = englishCitizensRule.getVariations().get(0);
    Experiment everyoneElseRule = rollout.getExperiments().get(rollout.getExperiments().size() - 1);
    Variation everyoneElseVariation = everyoneElseRule.getVariations().get(0);
    when(mockBucketer.bucket(any(Experiment.class), anyString())).thenReturn(null);
    when(mockBucketer.bucket(eq(everyoneElseRule), anyString())).thenReturn(everyoneElseVariation);
    when(mockBucketer.bucket(eq(englishCitizensRule), anyString())).thenReturn(englishCitizenVariation);
    DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, v4ProjectConfig, null);
    FeatureDecision featureDecision = decisionService.getVariationForFeatureInRollout(FEATURE_FLAG_MULTI_VARIATE_FEATURE, genericUserId, Collections.singletonMap(ATTRIBUTE_NATIONALITY_KEY, AUDIENCE_ENGLISH_CITIZENS_VALUE));
    assertEquals(englishCitizenVariation, featureDecision.variation);
    assertEquals(FeatureDecision.DecisionSource.ROLLOUT, featureDecision.decisionSource);
    // verify user is only bucketed once for everyone else rule
    verify(mockBucketer, times(1)).bucket(any(Experiment.class), anyString());
}
Also used : Experiment(com.optimizely.ab.config.Experiment) Rollout(com.optimizely.ab.config.Rollout) Variation(com.optimizely.ab.config.Variation) Test(org.junit.Test)

Example 7 with Rollout

use of com.optimizely.ab.config.Rollout in project java-sdk by optimizely.

the class DecisionServiceTest method getVariationForFeatureInRolloutReturnsVariationWhenUserFailsAllAudienceButSatisfiesTraffic.

/**
 * Verify that {@link DecisionService#getVariationForFeatureInRollout(FeatureFlag, String, Map)}
 * returns the variation of "Everyone Else" rule
 * when the user fails targeting for all rules, but is bucketed into the "Everyone Else" rule.
 */
@Test
public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsAllAudienceButSatisfiesTraffic() {
    Bucketer mockBucketer = mock(Bucketer.class);
    Rollout rollout = ROLLOUT_2;
    Experiment everyoneElseRule = rollout.getExperiments().get(rollout.getExperiments().size() - 1);
    Variation expectedVariation = everyoneElseRule.getVariations().get(0);
    when(mockBucketer.bucket(eq(everyoneElseRule), anyString())).thenReturn(expectedVariation);
    DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, v4ProjectConfig, null);
    FeatureDecision featureDecision = decisionService.getVariationForFeatureInRollout(FEATURE_FLAG_MULTI_VARIATE_FEATURE, genericUserId, Collections.<String, String>emptyMap());
    assertEquals(expectedVariation, featureDecision.variation);
    assertEquals(FeatureDecision.DecisionSource.ROLLOUT, featureDecision.decisionSource);
    // verify user is only bucketed once for everyone else rule
    verify(mockBucketer, times(1)).bucket(any(Experiment.class), anyString());
}
Also used : Experiment(com.optimizely.ab.config.Experiment) Rollout(com.optimizely.ab.config.Rollout) Variation(com.optimizely.ab.config.Variation) Test(org.junit.Test)

Example 8 with Rollout

use of com.optimizely.ab.config.Rollout in project java-sdk by optimizely.

the class DecisionServiceTest method getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTrafficInRuleAndPassesInEveryoneElse.

/**
 * Verify that {@link DecisionService#getVariationForFeatureInRollout(FeatureFlag, String, Map)}
 * returns the variation of "Everyone Else" rule
 * when the user passes targeting for a rule, but was failed the traffic allocation for that rule,
 * and is bucketed successfully into the "Everyone Else" rule.
 */
@Test
public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTrafficInRuleAndPassesInEveryoneElse() {
    Bucketer mockBucketer = mock(Bucketer.class);
    Rollout rollout = ROLLOUT_2;
    Experiment everyoneElseRule = rollout.getExperiments().get(rollout.getExperiments().size() - 1);
    Variation expectedVariation = everyoneElseRule.getVariations().get(0);
    when(mockBucketer.bucket(any(Experiment.class), anyString())).thenReturn(null);
    when(mockBucketer.bucket(eq(everyoneElseRule), anyString())).thenReturn(expectedVariation);
    DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, v4ProjectConfig, null);
    FeatureDecision featureDecision = decisionService.getVariationForFeatureInRollout(FEATURE_FLAG_MULTI_VARIATE_FEATURE, genericUserId, Collections.singletonMap(ATTRIBUTE_HOUSE_KEY, AUDIENCE_GRYFFINDOR_VALUE));
    assertEquals(expectedVariation, featureDecision.variation);
    assertEquals(FeatureDecision.DecisionSource.ROLLOUT, featureDecision.decisionSource);
    // verify user is only bucketed once for everyone else rule
    verify(mockBucketer, times(2)).bucket(any(Experiment.class), anyString());
}
Also used : Experiment(com.optimizely.ab.config.Experiment) Rollout(com.optimizely.ab.config.Rollout) Variation(com.optimizely.ab.config.Variation) Test(org.junit.Test)

Example 9 with Rollout

use of com.optimizely.ab.config.Rollout in project java-sdk by optimizely.

the class DecisionServiceTest method getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTrafficInRuleButWouldPassForAnotherRuleAndPassesInEveryoneElse.

/**
 * Verify that {@link DecisionService#getVariationForFeatureInRollout(FeatureFlag, String, Map)}
 * returns the variation of "Everyone Else" rule
 * when the user passes targeting for a rule, but was failed the traffic allocation for that rule,
 * and is bucketed successfully into the "Everyone Else" rule.
 * Fallback bucketing should not evaluate any other audiences.
 *  Even though the user would satisfy a later rollout rule, they are never evaluated for it or bucketed into it.
 */
@Test
public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTrafficInRuleButWouldPassForAnotherRuleAndPassesInEveryoneElse() {
    Bucketer mockBucketer = mock(Bucketer.class);
    Rollout rollout = ROLLOUT_2;
    Experiment englishCitizensRule = rollout.getExperiments().get(2);
    Variation englishCitizenVariation = englishCitizensRule.getVariations().get(0);
    Experiment everyoneElseRule = rollout.getExperiments().get(rollout.getExperiments().size() - 1);
    Variation expectedVariation = everyoneElseRule.getVariations().get(0);
    when(mockBucketer.bucket(any(Experiment.class), anyString())).thenReturn(null);
    when(mockBucketer.bucket(eq(everyoneElseRule), anyString())).thenReturn(expectedVariation);
    when(mockBucketer.bucket(eq(englishCitizensRule), anyString())).thenReturn(englishCitizenVariation);
    DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, v4ProjectConfig, null);
    FeatureDecision featureDecision = decisionService.getVariationForFeatureInRollout(FEATURE_FLAG_MULTI_VARIATE_FEATURE, genericUserId, ProjectConfigTestUtils.createMapOfObjects(ProjectConfigTestUtils.createListOfObjects(ATTRIBUTE_HOUSE_KEY, ATTRIBUTE_NATIONALITY_KEY), ProjectConfigTestUtils.createListOfObjects(AUDIENCE_GRYFFINDOR_VALUE, AUDIENCE_ENGLISH_CITIZENS_VALUE)));
    assertEquals(expectedVariation, featureDecision.variation);
    assertEquals(FeatureDecision.DecisionSource.ROLLOUT, featureDecision.decisionSource);
    // verify user is only bucketed once for everyone else rule
    verify(mockBucketer, times(2)).bucket(any(Experiment.class), anyString());
}
Also used : Experiment(com.optimizely.ab.config.Experiment) Rollout(com.optimizely.ab.config.Rollout) Variation(com.optimizely.ab.config.Variation) Test(org.junit.Test)

Aggregations

Experiment (com.optimizely.ab.config.Experiment)9 Rollout (com.optimizely.ab.config.Rollout)9 Variation (com.optimizely.ab.config.Variation)7 Test (org.junit.Test)6 FeatureFlag (com.optimizely.ab.config.FeatureFlag)4 Audience (com.optimizely.ab.config.audience.Audience)3 Attribute (com.optimizely.ab.config.Attribute)2 EventType (com.optimizely.ab.config.EventType)2 Group (com.optimizely.ab.config.Group)2 LiveVariable (com.optimizely.ab.config.LiveVariable)2 ProjectConfig (com.optimizely.ab.config.ProjectConfig)2 List (java.util.List)2 Matchers.anyString (org.mockito.Matchers.anyString)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 JsonObject (com.google.gson.JsonObject)1 Type (java.lang.reflect.Type)1 Nonnull (javax.annotation.Nonnull)1