@Test public void testParticipateNetworkFailureReturnsControl() throws IOException { Call<ParticipateResponse> mockCall = mock(Call.class); when(mockCall.execute()).thenThrow(new IOException()); when(mockApi.participate(Matchers.<Experiment>anyObject(), Matchers.<List<Alternative>>anyObject(), Matchers.<Alternative>anyObject(), anyDouble(), Matchers.<Boolean>eq(null))) .thenReturn(mockCall); Sixpack sixpack = new Sixpack(mockApi); Alternative greenAlternative = new Alternative("green"); Alternative redAlternative = new Alternative("red"); Experiment experiment = new ExperimentBuilder(sixpack) .withName("test-experience") .withAlternatives(greenAlternative, redAlternative) .build(); ParticipatingExperiment participatingExperiment = sixpack.participate(experiment); assertEquals(new ParticipatingExperiment(sixpack, experiment, greenAlternative), participatingExperiment); }
ParticipatingExperiment participate(final Experiment experiment) { logParticipate(experiment); try { Response<ParticipateResponse> response = api.participate(experiment, new ArrayList<>(experiment.alternatives), experiment.forcedChoice, experiment.trafficFraction, null ).execute(); if (response.isSuccessful()) { return new ParticipatingExperiment(Sixpack.this, experiment, response.body().getSelectedAlternative()); } else { return getControlParticipation(experiment); } } catch (RuntimeException | IOException e) { logException(experiment, e); return getControlParticipation(experiment); } }
Sixpack { ParticipatingExperiment participate(final Experiment experiment) { logParticipate(experiment); try { Response<ParticipateResponse> response = api.participate(experiment, new ArrayList<>(experiment.alternatives), experiment.forcedChoice, experiment.trafficFraction, null ).execute(); if (response.isSuccessful()) { return new ParticipatingExperiment(Sixpack.this, experiment, response.body().getSelectedAlternative()); } else { return getControlParticipation(experiment); } } catch (RuntimeException | IOException e) { logException(experiment, e); return getControlParticipation(experiment); } } }
Sixpack { ParticipatingExperiment participate(final Experiment experiment) { logParticipate(experiment); try { Response<ParticipateResponse> response = api.participate(experiment, new ArrayList<>(experiment.alternatives), experiment.forcedChoice, experiment.trafficFraction, null ).execute(); if (response.isSuccessful()) { return new ParticipatingExperiment(Sixpack.this, experiment, response.body().getSelectedAlternative()); } else { return getControlParticipation(experiment); } } catch (RuntimeException | IOException e) { logException(experiment, e); return getControlParticipation(experiment); } } Sixpack(final HttpUrl sixpackUrl, final String clientId, final OkHttpClient client);   Sixpack(final SixpackApi api);   Sixpack(final SixpackApi api, final String clientId); }
Sixpack { ParticipatingExperiment participate(final Experiment experiment) { logParticipate(experiment); try { Response<ParticipateResponse> response = api.participate(experiment, new ArrayList<>(experiment.alternatives), experiment.forcedChoice, experiment.trafficFraction, null ).execute(); if (response.isSuccessful()) { return new ParticipatingExperiment(Sixpack.this, experiment, response.body().getSelectedAlternative()); } else { return getControlParticipation(experiment); } } catch (RuntimeException | IOException e) { logException(experiment, e); return getControlParticipation(experiment); } } Sixpack(final HttpUrl sixpackUrl, final String clientId, final OkHttpClient client);   Sixpack(final SixpackApi api);   Sixpack(final SixpackApi api, final String clientId); ExperimentBuilder experiment(); String getClientId(); void setLogLevel(LogLevel logLevel); LogLevel getLogLevel(); void setLogger(final Logger logger); static String generateRandomClientId(); }
Sixpack { ParticipatingExperiment participate(final Experiment experiment) { logParticipate(experiment); try { Response<ParticipateResponse> response = api.participate(experiment, new ArrayList<>(experiment.alternatives), experiment.forcedChoice, experiment.trafficFraction, null ).execute(); if (response.isSuccessful()) { return new ParticipatingExperiment(Sixpack.this, experiment, response.body().getSelectedAlternative()); } else { return getControlParticipation(experiment); } } catch (RuntimeException | IOException e) { logException(experiment, e); return getControlParticipation(experiment); } } Sixpack(final HttpUrl sixpackUrl, final String clientId, final OkHttpClient client);   Sixpack(final SixpackApi api);   Sixpack(final SixpackApi api, final String clientId); ExperimentBuilder experiment(); String getClientId(); void setLogLevel(LogLevel logLevel); LogLevel getLogLevel(); void setLogger(final Logger logger); static String generateRandomClientId(); static final HttpUrl DEFAULT_URL; static final String NAME_REGEX; static final Pattern NAME_PATTERN; static final LogLevel DEFAULT_LOG_LEVEL; static final String SIXPACK_LOG_TAG; }