@Test public void testCheckForIllegalTerminatedUpdate() { Experiment testExp = Experiment.withID(experimentID) .withApplicationName(testApp) .withLabel(testLabel) .withRule("rule1") .withSamplingPercent(samplingPercent) .withStartTime(startTime) .withEndTime(endTime).build(); Experiment updateExp = Experiment.withID(experimentID) .withApplicationName(testApp) .withLabel(testLabel) .withSamplingPercent(samplingPercent) .withStartTime(startTime) .withRule("rule2") .withEndTime(endTime).build(); testExp.setState(Experiment.State.TERMINATED); updateExp.setApplicationName(Application.Name.valueOf("ChangedAppName")); try { expImpl.checkForIllegalTerminatedUpdate(testExp, updateExp); fail("Expected IllegalArgumentException."); } catch (Exception e) { assertEquals(e.getClass(), IllegalArgumentException.class); } updateExp.setApplicationName(testApp); updateExp.setLabel(Experiment.Label.valueOf("ChangedLabel")); try { expImpl.checkForIllegalTerminatedUpdate(testExp, updateExp); fail("Expected IllegalArgumentException."); } catch (Exception e) { assertEquals(e.getClass(), IllegalArgumentException.class); } updateExp.setLabel(testLabel); updateExp.setEndTime(new Date()); try { expImpl.checkForIllegalTerminatedUpdate(testExp, updateExp); fail("Expected IllegalArgumentException."); } catch (Exception e) { assertEquals(e.getClass(), IllegalArgumentException.class); } updateExp.setEndTime(endTime); updateExp.setSamplingPercent(100.0); try { expImpl.checkForIllegalTerminatedUpdate(testExp, updateExp); fail("Expected IllegalArgumentException."); } catch (Exception e) { assertEquals(e.getClass(), IllegalArgumentException.class); } updateExp.setSamplingPercent(samplingPercent); try { expImpl.checkForIllegalTerminatedUpdate(testExp, updateExp); } catch (Exception e) { assertEquals(e.getClass(), IllegalArgumentException.class); } }
@Override public void checkForIllegalTerminatedUpdate(Experiment experiment, Experiment updates) { if (experiment.getState().equals(TERMINATED)) { if (updates.getApplicationName() != null && !updates.getApplicationName().equals(experiment.getApplicationName())) { throw new IllegalArgumentException("Invalid application name \"" + updates.getApplicationName() + "\" " + "Cannot change application name when the experiment is in TERMINATED state"); } if (updates.getLabel() != null && !updates.getLabel().equals(experiment.getLabel())) { throw new IllegalArgumentException("Invalid label \"" + updates.getLabel() + "\" " + "Cannot change label when the experiment is in TERMINATED state"); } if (updates.getStartTime() != null && !updates.getStartTime().equals(experiment.getStartTime())) { throw new IllegalArgumentException("Invalid startTime \"" + updates.getStartTime() + "\" " + "Cannot change start time when the experiment is in TERMINATED state"); } if (updates.getEndTime() != null && !updates.getEndTime().equals(experiment.getEndTime())) { throw new IllegalArgumentException("Invalid endTime \"" + updates.getEndTime() + "\" " + "Cannot change end time when the experiment is in TERMINATED state"); } if (updates.getSamplingPercent() != null && !updates.getSamplingPercent().equals(experiment.getSamplingPercent())) { throw new IllegalArgumentException("Invalid sampling percentage \"" + updates.getSamplingPercent() + "\" " + "Cannot change sampling percentage when the experiment is in TERMINATED state"); } if (updates.getRule() != null && !updates.getRule().equals(experiment.getRule())) { throw new IllegalArgumentException("Invalid rule \"" + updates.getRule() + "\" " + "Cannot change sampling rule when the experiment is in TERMINATED state"); } } }
ExperimentsImpl implements Experiments { @Override public void checkForIllegalTerminatedUpdate(Experiment experiment, Experiment updates) { if (experiment.getState().equals(TERMINATED)) { if (updates.getApplicationName() != null && !updates.getApplicationName().equals(experiment.getApplicationName())) { throw new IllegalArgumentException("Invalid application name \"" + updates.getApplicationName() + "\" " + "Cannot change application name when the experiment is in TERMINATED state"); } if (updates.getLabel() != null && !updates.getLabel().equals(experiment.getLabel())) { throw new IllegalArgumentException("Invalid label \"" + updates.getLabel() + "\" " + "Cannot change label when the experiment is in TERMINATED state"); } if (updates.getStartTime() != null && !updates.getStartTime().equals(experiment.getStartTime())) { throw new IllegalArgumentException("Invalid startTime \"" + updates.getStartTime() + "\" " + "Cannot change start time when the experiment is in TERMINATED state"); } if (updates.getEndTime() != null && !updates.getEndTime().equals(experiment.getEndTime())) { throw new IllegalArgumentException("Invalid endTime \"" + updates.getEndTime() + "\" " + "Cannot change end time when the experiment is in TERMINATED state"); } if (updates.getSamplingPercent() != null && !updates.getSamplingPercent().equals(experiment.getSamplingPercent())) { throw new IllegalArgumentException("Invalid sampling percentage \"" + updates.getSamplingPercent() + "\" " + "Cannot change sampling percentage when the experiment is in TERMINATED state"); } if (updates.getRule() != null && !updates.getRule().equals(experiment.getRule())) { throw new IllegalArgumentException("Invalid rule \"" + updates.getRule() + "\" " + "Cannot change sampling rule when the experiment is in TERMINATED state"); } } } }
ExperimentsImpl implements Experiments { @Override public void checkForIllegalTerminatedUpdate(Experiment experiment, Experiment updates) { if (experiment.getState().equals(TERMINATED)) { if (updates.getApplicationName() != null && !updates.getApplicationName().equals(experiment.getApplicationName())) { throw new IllegalArgumentException("Invalid application name \"" + updates.getApplicationName() + "\" " + "Cannot change application name when the experiment is in TERMINATED state"); } if (updates.getLabel() != null && !updates.getLabel().equals(experiment.getLabel())) { throw new IllegalArgumentException("Invalid label \"" + updates.getLabel() + "\" " + "Cannot change label when the experiment is in TERMINATED state"); } if (updates.getStartTime() != null && !updates.getStartTime().equals(experiment.getStartTime())) { throw new IllegalArgumentException("Invalid startTime \"" + updates.getStartTime() + "\" " + "Cannot change start time when the experiment is in TERMINATED state"); } if (updates.getEndTime() != null && !updates.getEndTime().equals(experiment.getEndTime())) { throw new IllegalArgumentException("Invalid endTime \"" + updates.getEndTime() + "\" " + "Cannot change end time when the experiment is in TERMINATED state"); } if (updates.getSamplingPercent() != null && !updates.getSamplingPercent().equals(experiment.getSamplingPercent())) { throw new IllegalArgumentException("Invalid sampling percentage \"" + updates.getSamplingPercent() + "\" " + "Cannot change sampling percentage when the experiment is in TERMINATED state"); } if (updates.getRule() != null && !updates.getRule().equals(experiment.getRule())) { throw new IllegalArgumentException("Invalid rule \"" + updates.getRule() + "\" " + "Cannot change sampling rule when the experiment is in TERMINATED state"); } } } @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 checkForIllegalTerminatedUpdate(Experiment experiment, Experiment updates) { if (experiment.getState().equals(TERMINATED)) { if (updates.getApplicationName() != null && !updates.getApplicationName().equals(experiment.getApplicationName())) { throw new IllegalArgumentException("Invalid application name \"" + updates.getApplicationName() + "\" " + "Cannot change application name when the experiment is in TERMINATED state"); } if (updates.getLabel() != null && !updates.getLabel().equals(experiment.getLabel())) { throw new IllegalArgumentException("Invalid label \"" + updates.getLabel() + "\" " + "Cannot change label when the experiment is in TERMINATED state"); } if (updates.getStartTime() != null && !updates.getStartTime().equals(experiment.getStartTime())) { throw new IllegalArgumentException("Invalid startTime \"" + updates.getStartTime() + "\" " + "Cannot change start time when the experiment is in TERMINATED state"); } if (updates.getEndTime() != null && !updates.getEndTime().equals(experiment.getEndTime())) { throw new IllegalArgumentException("Invalid endTime \"" + updates.getEndTime() + "\" " + "Cannot change end time when the experiment is in TERMINATED state"); } if (updates.getSamplingPercent() != null && !updates.getSamplingPercent().equals(experiment.getSamplingPercent())) { throw new IllegalArgumentException("Invalid sampling percentage \"" + updates.getSamplingPercent() + "\" " + "Cannot change sampling percentage when the experiment is in TERMINATED state"); } if (updates.getRule() != null && !updates.getRule().equals(experiment.getRule())) { throw new IllegalArgumentException("Invalid rule \"" + updates.getRule() + "\" " + "Cannot change sampling rule when the experiment is in TERMINATED state"); } } } @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 checkForIllegalTerminatedUpdate(Experiment experiment, Experiment updates) { if (experiment.getState().equals(TERMINATED)) { if (updates.getApplicationName() != null && !updates.getApplicationName().equals(experiment.getApplicationName())) { throw new IllegalArgumentException("Invalid application name \"" + updates.getApplicationName() + "\" " + "Cannot change application name when the experiment is in TERMINATED state"); } if (updates.getLabel() != null && !updates.getLabel().equals(experiment.getLabel())) { throw new IllegalArgumentException("Invalid label \"" + updates.getLabel() + "\" " + "Cannot change label when the experiment is in TERMINATED state"); } if (updates.getStartTime() != null && !updates.getStartTime().equals(experiment.getStartTime())) { throw new IllegalArgumentException("Invalid startTime \"" + updates.getStartTime() + "\" " + "Cannot change start time when the experiment is in TERMINATED state"); } if (updates.getEndTime() != null && !updates.getEndTime().equals(experiment.getEndTime())) { throw new IllegalArgumentException("Invalid endTime \"" + updates.getEndTime() + "\" " + "Cannot change end time when the experiment is in TERMINATED state"); } if (updates.getSamplingPercent() != null && !updates.getSamplingPercent().equals(experiment.getSamplingPercent())) { throw new IllegalArgumentException("Invalid sampling percentage \"" + updates.getSamplingPercent() + "\" " + "Cannot change sampling percentage when the experiment is in TERMINATED state"); } if (updates.getRule() != null && !updates.getRule().equals(experiment.getRule())) { throw new IllegalArgumentException("Invalid rule \"" + updates.getRule() + "\" " + "Cannot change sampling rule when the experiment is in TERMINATED state"); } } } @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);  }