@Test public void testCreateExperimentFailedCassandraCreation() { NewExperiment testExp = NewExperiment.withID(experimentID) .withAppName(testApp) .withLabel(testLabel) .withSamplingPercent(samplingPercent) .withStartTime(startTime) .withEndTime(endTime) .withDescription(description).build(); doNothing().when(validator).validateNewExperiment(testExp); when(databaseRepository.createExperiment(testExp)).thenReturn(experimentID); doThrow(new RepositoryException()).when(cassandraRepository).createExperiment(testExp); try { expImpl.createExperiment(testExp, UserInfo.from(UserInfo.Username.valueOf("user")).build()); fail("Expected RepositoryException."); } catch (Exception e) { assertEquals(e.getClass(), RepositoryException.class); } verify(databaseRepository, times(1)).createExperiment(any(NewExperiment.class)); verify(databaseRepository, times(1)).deleteExperiment(testExp); verify(eventLog, times(0)).postEvent(any(ExperimentCreateEvent.class)); }
@Override public void createExperiment(NewExperiment newExperiment, UserInfo user) { LOGGER.debug("Create experiment started: experiment={}, UserInfo={} ", newExperiment, user); validator.validateNewExperiment(newExperiment); try { LOGGER.debug("Creating an experiment in MySQL..."); databaseRepository.createExperiment(newExperiment); try { cassandraRepository.createExperiment(newExperiment); } catch (Exception exceptionFromCassandra) { LOGGER.error("Exception occurred while creating an experiment in Cassandra... Experiment={}, UserInfo={}", newExperiment, user, exceptionFromCassandra); try { databaseRepository.deleteExperiment(newExperiment); } catch (Exception mysqlRollbackException) { LOGGER.error("An attempt to rollback of experiment in MySQL is failed...", mysqlRollbackException); } throw exceptionFromCassandra; } eventLog.postEvent(new ExperimentCreateEvent(user, newExperiment)); } catch (Exception experimentCreateException) { LOGGER.error("Exception occurred while creating an experiment... Experiment={}, UserInfo={}", newExperiment, user, experimentCreateException); throw experimentCreateException; } LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, message=EXPERIMENT_CREATED, applicationName={}, configuration={}",newExperiment.getApplicationName(),newExperiment); }
ExperimentsImpl implements Experiments { @Override public void createExperiment(NewExperiment newExperiment, UserInfo user) { LOGGER.debug("Create experiment started: experiment={}, UserInfo={} ", newExperiment, user); validator.validateNewExperiment(newExperiment); try { LOGGER.debug("Creating an experiment in MySQL..."); databaseRepository.createExperiment(newExperiment); try { cassandraRepository.createExperiment(newExperiment); } catch (Exception exceptionFromCassandra) { LOGGER.error("Exception occurred while creating an experiment in Cassandra... Experiment={}, UserInfo={}", newExperiment, user, exceptionFromCassandra); try { databaseRepository.deleteExperiment(newExperiment); } catch (Exception mysqlRollbackException) { LOGGER.error("An attempt to rollback of experiment in MySQL is failed...", mysqlRollbackException); } throw exceptionFromCassandra; } eventLog.postEvent(new ExperimentCreateEvent(user, newExperiment)); } catch (Exception experimentCreateException) { LOGGER.error("Exception occurred while creating an experiment... Experiment={}, UserInfo={}", newExperiment, user, experimentCreateException); throw experimentCreateException; } LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, message=EXPERIMENT_CREATED, applicationName={}, configuration={}",newExperiment.getApplicationName(),newExperiment); } }
ExperimentsImpl implements Experiments { @Override public void createExperiment(NewExperiment newExperiment, UserInfo user) { LOGGER.debug("Create experiment started: experiment={}, UserInfo={} ", newExperiment, user); validator.validateNewExperiment(newExperiment); try { LOGGER.debug("Creating an experiment in MySQL..."); databaseRepository.createExperiment(newExperiment); try { cassandraRepository.createExperiment(newExperiment); } catch (Exception exceptionFromCassandra) { LOGGER.error("Exception occurred while creating an experiment in Cassandra... Experiment={}, UserInfo={}", newExperiment, user, exceptionFromCassandra); try { databaseRepository.deleteExperiment(newExperiment); } catch (Exception mysqlRollbackException) { LOGGER.error("An attempt to rollback of experiment in MySQL is failed...", mysqlRollbackException); } throw exceptionFromCassandra; } eventLog.postEvent(new ExperimentCreateEvent(user, newExperiment)); } catch (Exception experimentCreateException) { LOGGER.error("Exception occurred while creating an experiment... Experiment={}, UserInfo={}", newExperiment, user, experimentCreateException); throw experimentCreateException; } LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, message=EXPERIMENT_CREATED, applicationName={}, configuration={}",newExperiment.getApplicationName(),newExperiment); } @Inject  ExperimentsImpl(@DatabaseRepository ExperimentRepository databaseRepository,
                           @CassandraRepository ExperimentRepository cassandraRepository, Experiments experiments,
                           Buckets buckets, Pages pages, Priorities priorities, ExperimentValidator validator,
                           RuleCache ruleCache, EventLog eventLog); }
ExperimentsImpl implements Experiments { @Override public void createExperiment(NewExperiment newExperiment, UserInfo user) { LOGGER.debug("Create experiment started: experiment={}, UserInfo={} ", newExperiment, user); validator.validateNewExperiment(newExperiment); try { LOGGER.debug("Creating an experiment in MySQL..."); databaseRepository.createExperiment(newExperiment); try { cassandraRepository.createExperiment(newExperiment); } catch (Exception exceptionFromCassandra) { LOGGER.error("Exception occurred while creating an experiment in Cassandra... Experiment={}, UserInfo={}", newExperiment, user, exceptionFromCassandra); try { databaseRepository.deleteExperiment(newExperiment); } catch (Exception mysqlRollbackException) { LOGGER.error("An attempt to rollback of experiment in MySQL is failed...", mysqlRollbackException); } throw exceptionFromCassandra; } eventLog.postEvent(new ExperimentCreateEvent(user, newExperiment)); } catch (Exception experimentCreateException) { LOGGER.error("Exception occurred while creating an experiment... Experiment={}, UserInfo={}", newExperiment, user, experimentCreateException); throw experimentCreateException; } LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, message=EXPERIMENT_CREATED, applicationName={}, configuration={}",newExperiment.getApplicationName(),newExperiment); } @Inject  ExperimentsImpl(@DatabaseRepository ExperimentRepository databaseRepository,
                           @CassandraRepository ExperimentRepository cassandraRepository, Experiments experiments,
                           Buckets buckets, Pages pages, Priorities priorities, ExperimentValidator validator,
                           RuleCache ruleCache, EventLog eventLog); @Override ExperimentList getExperiments(); @Override List<Application.Name> getApplications(); @Override Map<Application.Name, Set<String>> getTagsForApplications(Collection<Application.Name> applicationNames); @Override Experiment getExperiment(Experiment.ID id); @Override Experiment getExperiment(Application.Name appName, Experiment.Label label); @Override List<Experiment> getExperiments(Application.Name appName); @Override void createExperiment(NewExperiment newExperiment, UserInfo user); @Override void checkStateTransition(Experiment.ID experimentID, Experiment.State currentState,
                                     Experiment.State desiredState); @Override void checkForIllegalUpdate(Experiment experiment, Experiment updates); @Override void checkForIllegalTerminatedUpdate(Experiment experiment, Experiment updates); @Override void checkForIllegalPausedRunningUpdate(Experiment experiment, Experiment updates); @Override boolean buildUpdatedExperiment(Experiment experiment, Experiment updates, Experiment.Builder builder,
                                          List<ExperimentAuditInfo> changeList); @Override void updateSegmentationRule(Experiment experiment, UserInfo user); @Override Experiment updateExperiment(final Experiment.ID experimentID, final Experiment updates, final UserInfo user); @Override void updateExperimentState(final Experiment experiment, final Experiment.State state); }
ExperimentsImpl implements Experiments { @Override public void createExperiment(NewExperiment newExperiment, UserInfo user) { LOGGER.debug("Create experiment started: experiment={}, UserInfo={} ", newExperiment, user); validator.validateNewExperiment(newExperiment); try { LOGGER.debug("Creating an experiment in MySQL..."); databaseRepository.createExperiment(newExperiment); try { cassandraRepository.createExperiment(newExperiment); } catch (Exception exceptionFromCassandra) { LOGGER.error("Exception occurred while creating an experiment in Cassandra... Experiment={}, UserInfo={}", newExperiment, user, exceptionFromCassandra); try { databaseRepository.deleteExperiment(newExperiment); } catch (Exception mysqlRollbackException) { LOGGER.error("An attempt to rollback of experiment in MySQL is failed...", mysqlRollbackException); } throw exceptionFromCassandra; } eventLog.postEvent(new ExperimentCreateEvent(user, newExperiment)); } catch (Exception experimentCreateException) { LOGGER.error("Exception occurred while creating an experiment... Experiment={}, UserInfo={}", newExperiment, user, experimentCreateException); throw experimentCreateException; } LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, message=EXPERIMENT_CREATED, applicationName={}, configuration={}",newExperiment.getApplicationName(),newExperiment); } @Inject  ExperimentsImpl(@DatabaseRepository ExperimentRepository databaseRepository,
                           @CassandraRepository ExperimentRepository cassandraRepository, Experiments experiments,
                           Buckets buckets, Pages pages, Priorities priorities, ExperimentValidator validator,
                           RuleCache ruleCache, EventLog eventLog); @Override ExperimentList getExperiments(); @Override List<Application.Name> getApplications(); @Override Map<Application.Name, Set<String>> getTagsForApplications(Collection<Application.Name> applicationNames); @Override Experiment getExperiment(Experiment.ID id); @Override Experiment getExperiment(Application.Name appName, Experiment.Label label); @Override List<Experiment> getExperiments(Application.Name appName); @Override void createExperiment(NewExperiment newExperiment, UserInfo user); @Override void checkStateTransition(Experiment.ID experimentID, Experiment.State currentState,
                                     Experiment.State desiredState); @Override void checkForIllegalUpdate(Experiment experiment, Experiment updates); @Override void checkForIllegalTerminatedUpdate(Experiment experiment, Experiment updates); @Override void checkForIllegalPausedRunningUpdate(Experiment experiment, Experiment updates); @Override boolean buildUpdatedExperiment(Experiment experiment, Experiment updates, Experiment.Builder builder,
                                          List<ExperimentAuditInfo> changeList); @Override void updateSegmentationRule(Experiment experiment, UserInfo user); @Override Experiment updateExperiment(final Experiment.ID experimentID, final Experiment updates, final UserInfo user); @Override void updateExperimentState(final Experiment experiment, final Experiment.State state);  }