Search in sources :

Example 1 with NoOpErrorHandler

use of com.optimizely.ab.error.NoOpErrorHandler in project java-sdk by optimizely.

the class OptimizelyTest method getVariationWithUnknownExperimentKeyAndNoOpErrorHandler.

/**
 * Verify that {@link Optimizely#getVariation(String, String)} handles the case where an unknown experiment
 * (i.e., not in the config) is passed through and a {@link NoOpErrorHandler} is used by default.
 */
@Test
public void getVariationWithUnknownExperimentKeyAndNoOpErrorHandler() throws Exception {
    Experiment unknownExperiment = createUnknownExperiment();
    Optimizely optimizely = Optimizely.builder(noAudienceDatafile, mockEventHandler).withErrorHandler(new NoOpErrorHandler()).build();
    logbackVerifier.expectMessage(Level.ERROR, "Experiment \"unknown_experiment\" is not in the datafile");
    // since we use a NoOpErrorHandler, we should fail and return null
    Variation actualVariation = optimizely.getVariation(unknownExperiment.getKey(), testUserId);
    // verify that null is returned, as no project config was available
    assertNull(actualVariation);
}
Also used : Experiment(com.optimizely.ab.config.Experiment) NoOpErrorHandler(com.optimizely.ab.error.NoOpErrorHandler) Variation(com.optimizely.ab.config.Variation) Test(org.junit.Test)

Example 2 with NoOpErrorHandler

use of com.optimizely.ab.error.NoOpErrorHandler in project java-sdk by optimizely.

the class EventBuilderTest method createConversionEventForcedVariationBucketingPrecedesAudienceEval.

/**
 * Verify that precedence is given to forced variation bucketing over audience evaluation when constructing a
 * conversion event.
 */
@Test
public void createConversionEventForcedVariationBucketingPrecedesAudienceEval() {
    EventType eventType;
    String whitelistedUserId;
    if (datafileVersion == 4) {
        eventType = validProjectConfig.getEventNameMapping().get(EVENT_BASIC_EVENT_KEY);
        whitelistedUserId = MULTIVARIATE_EXPERIMENT_FORCED_VARIATION_USER_ID_GRED;
    } else {
        eventType = validProjectConfig.getEventTypes().get(0);
        whitelistedUserId = "testUser1";
    }
    DecisionService decisionService = new DecisionService(new Bucketer(validProjectConfig), new NoOpErrorHandler(), validProjectConfig, mock(UserProfileService.class));
    // attributes are empty so user won't be in the audience for experiment using the event, but bucketing
    // will still take place
    Map<Experiment, Variation> experimentVariationMap = createExperimentVariationMap(validProjectConfig, decisionService, eventType.getKey(), whitelistedUserId, Collections.<String, String>emptyMap());
    LogEvent conversionEvent = builder.createConversionEvent(validProjectConfig, experimentVariationMap, whitelistedUserId, eventType.getId(), eventType.getKey(), Collections.<String, String>emptyMap(), Collections.<String, Object>emptyMap());
    assertNotNull(conversionEvent);
    EventBatch conversion = gson.fromJson(conversionEvent.getBody(), EventBatch.class);
    if (datafileVersion == 4) {
        // 2 experiments use the event
        // basic experiment has no audience
        // user is whitelisted in to one audience
        assertEquals(2, conversion.getVisitors().get(0).getSnapshots().get(0).getDecisions().size());
    } else {
        assertEquals(1, conversion.getVisitors().get(0).getSnapshots().get(0).getDecisions().size());
    }
}
Also used : EventType(com.optimizely.ab.config.EventType) LogEvent(com.optimizely.ab.event.LogEvent) Experiment(com.optimizely.ab.config.Experiment) NoOpErrorHandler(com.optimizely.ab.error.NoOpErrorHandler) UserProfileService(com.optimizely.ab.bucketing.UserProfileService) Variation(com.optimizely.ab.config.Variation) EventBatch(com.optimizely.ab.event.internal.payload.EventBatch) Bucketer(com.optimizely.ab.bucketing.Bucketer) DecisionService(com.optimizely.ab.bucketing.DecisionService) Test(org.junit.Test)

Example 3 with NoOpErrorHandler

use of com.optimizely.ab.error.NoOpErrorHandler in project java-sdk by optimizely.

the class OptimizelyTest method trackEventWithUnknownEventKeyAndNoOpErrorHandler.

/**
 * Verify that {@link Optimizely#track(String, String)} handles the case where an unknown event type
 * (i.e., not in the config) is passed through and a {@link NoOpErrorHandler} is used by default.
 */
@Test
public void trackEventWithUnknownEventKeyAndNoOpErrorHandler() throws Exception {
    EventType unknownEventType = createUnknownEventType();
    Optimizely optimizely = Optimizely.builder(validDatafile, mockEventHandler).withConfig(validProjectConfig).withErrorHandler(new NoOpErrorHandler()).build();
    logbackVerifier.expectMessage(Level.ERROR, "Event \"unknown_event_type\" is not in the datafile.");
    logbackVerifier.expectMessage(Level.INFO, "Not tracking event \"unknown_event_type\" for user \"userId\".");
    optimizely.track(unknownEventType.getKey(), testUserId);
    // verify that we did NOT dispatch an event
    verify(mockEventHandler, never()).dispatchEvent(any(LogEvent.class));
}
Also used : EventType(com.optimizely.ab.config.EventType) LogEvent(com.optimizely.ab.event.LogEvent) NoOpErrorHandler(com.optimizely.ab.error.NoOpErrorHandler) Test(org.junit.Test)

Aggregations

NoOpErrorHandler (com.optimizely.ab.error.NoOpErrorHandler)3 Test (org.junit.Test)3 EventType (com.optimizely.ab.config.EventType)2 Experiment (com.optimizely.ab.config.Experiment)2 Variation (com.optimizely.ab.config.Variation)2 LogEvent (com.optimizely.ab.event.LogEvent)2 Bucketer (com.optimizely.ab.bucketing.Bucketer)1 DecisionService (com.optimizely.ab.bucketing.DecisionService)1 UserProfileService (com.optimizely.ab.bucketing.UserProfileService)1 EventBatch (com.optimizely.ab.event.internal.payload.EventBatch)1