@Test public void testCreateExperiment() throws Exception { Experiment.ID id = Experiment.ID.newInstance(); NewExperiment mockedNewExperiment = NewExperiment.withID(id).withSamplingPercent(1.0) .withLabel(Experiment.Label.valueOf("testLabel")) .withStartTime(new Date()) .withDescription("TEST") .withEndTime(new Date()) .withAppName(Application.Name.valueOf("TestApp")).build(); doNothing().when(transaction).insert(anyString(), Matchers.anyVararg()); Experiment.ID result = repository.createExperiment(mockedNewExperiment); assertThat(result, is(id)); doThrow(new DatabaseException("Test")).when(transaction).insert(anyString(), Matchers.anyVararg()); BDDCatchException.when(repository).createExperiment(mockedNewExperiment); BDDCatchException.then(caughtException()) .isInstanceOf(WasabiException.class) .hasMessage("Test") .hasNoCause(); doThrow(new RuntimeException("RTE")).when(transaction).insert(anyString(), Matchers.anyVararg()); BDDCatchException.when(repository).createExperiment(mockedNewExperiment); BDDCatchException.then(caughtException()) .isInstanceOf(Exception.class) .hasMessageContaining("Could not persist experiment in database") .hasRootCauseExactlyInstanceOf(RuntimeException.class); }
@Override public Experiment.ID createExperiment(NewExperiment newExperiment) throws RepositoryException { final String SQL = "insert into experiment " + "(id, description, sampling_percent, label, " + "start_time, end_time, app_name, state) " + "values (?, ?, ?, ?, ?, ?, ?, ?)"; try { newTransaction().insert( SQL, newExperiment.getID(), newExperiment.getDescription() != null ? newExperiment.getDescription() : "", newExperiment.getSamplingPercent(), newExperiment.getLabel().toString(), newExperiment.getStartTime(), newExperiment.getEndTime(), newExperiment.getApplicationName().toString(), State.DRAFT.toString()); return newExperiment.getID(); } catch (WasabiException e) { throw e; } catch (Exception e) { throw new RepositoryException( "Could not persist experiment in database \"" + newExperiment.toString() + "\"", e); } }
DatabaseExperimentRepository implements ExperimentRepository { @Override public Experiment.ID createExperiment(NewExperiment newExperiment) throws RepositoryException { final String SQL = "insert into experiment " + "(id, description, sampling_percent, label, " + "start_time, end_time, app_name, state) " + "values (?, ?, ?, ?, ?, ?, ?, ?)"; try { newTransaction().insert( SQL, newExperiment.getID(), newExperiment.getDescription() != null ? newExperiment.getDescription() : "", newExperiment.getSamplingPercent(), newExperiment.getLabel().toString(), newExperiment.getStartTime(), newExperiment.getEndTime(), newExperiment.getApplicationName().toString(), State.DRAFT.toString()); return newExperiment.getID(); } catch (WasabiException e) { throw e; } catch (Exception e) { throw new RepositoryException( "Could not persist experiment in database \"" + newExperiment.toString() + "\"", e); } } }
DatabaseExperimentRepository implements ExperimentRepository { @Override public Experiment.ID createExperiment(NewExperiment newExperiment) throws RepositoryException { final String SQL = "insert into experiment " + "(id, description, sampling_percent, label, " + "start_time, end_time, app_name, state) " + "values (?, ?, ?, ?, ?, ?, ?, ?)"; try { newTransaction().insert( SQL, newExperiment.getID(), newExperiment.getDescription() != null ? newExperiment.getDescription() : "", newExperiment.getSamplingPercent(), newExperiment.getLabel().toString(), newExperiment.getStartTime(), newExperiment.getEndTime(), newExperiment.getApplicationName().toString(), State.DRAFT.toString()); return newExperiment.getID(); } catch (WasabiException e) { throw e; } catch (Exception e) { throw new RepositoryException( "Could not persist experiment in database \"" + newExperiment.toString() + "\"", e); } } @Inject  DatabaseExperimentRepository(TransactionFactory transactionFactory, ExperimentValidator validator,
                                        Flyway flyway); }
DatabaseExperimentRepository implements ExperimentRepository { @Override public Experiment.ID createExperiment(NewExperiment newExperiment) throws RepositoryException { final String SQL = "insert into experiment " + "(id, description, sampling_percent, label, " + "start_time, end_time, app_name, state) " + "values (?, ?, ?, ?, ?, ?, ?, ?)"; try { newTransaction().insert( SQL, newExperiment.getID(), newExperiment.getDescription() != null ? newExperiment.getDescription() : "", newExperiment.getSamplingPercent(), newExperiment.getLabel().toString(), newExperiment.getStartTime(), newExperiment.getEndTime(), newExperiment.getApplicationName().toString(), State.DRAFT.toString()); return newExperiment.getID(); } catch (WasabiException e) { throw e; } catch (Exception e) { throw new RepositoryException( "Could not persist experiment in database \"" + newExperiment.toString() + "\"", e); } } @Inject  DatabaseExperimentRepository(TransactionFactory transactionFactory, ExperimentValidator validator,
                                        Flyway flyway); @Override Experiment getExperiment(Experiment.ID experimentID); @Override Map<Application.Name, List<Experiment>> getExperimentsForApps(Collection<Application.Name> appNames); @Override Experiment getExperiment(Application.Name appName,
                                    Experiment.Label experimentLabel); @Override List<Experiment.ID> getExperiments(); @Override ExperimentList getExperiments(Collection<Experiment.ID> experimentIDs); @Override Map<Experiment.ID, Experiment> getExperimentsMap(Collection<Experiment.ID> experimentIDs); @Override Table<Experiment.ID, Experiment.Label, Experiment> getExperimentList(Application.Name appName); @Override List<Application.Name> getApplicationsList(); @Override Experiment.ID createExperiment(NewExperiment newExperiment); @Override Experiment updateExperiment(Experiment experiment); @Override Experiment updateExperimentState(Experiment experiment, State state); @Override Bucket getBucket(Experiment.ID experimentID,
                            Bucket.Label bucketLabel); @Override void createBucket(Bucket newBucket); @Override Bucket updateBucket(Bucket bucket); @Override Bucket updateBucketAllocationPercentage(Bucket bucket, Double desiredAllocationPercentage); @Override Bucket updateBucketState(Bucket bucket, Bucket.State desiredState); @Override BucketList updateBucketBatch(Experiment.ID experimentID, BucketList bucketList); @Override void deleteBucket(Experiment.ID experimentID,
                             Bucket.Label bucketLabel); @Override void logBucketChanges(Experiment.ID experimentID, Bucket.Label bucketLabel,
                                 List<Bucket.BucketAuditInfo> changeList); @Override void logExperimentChanges(Experiment.ID experimentID, List<Experiment.ExperimentAuditInfo> changeList); @Override List<Experiment> getExperiments(Application.Name appName); @Override void deleteExperiment(NewExperiment newExperiment); @Override void createIndicesForNewExperiment(NewExperiment newExperiment); @Override HashMap<Experiment.ID, BucketList> getBucketList(Collection<Experiment.ID> experimentIDCollection); @Override BucketList getBucketList(Experiment.ID experimentID); @Override BucketList getBuckets(Experiment.ID experimentID, boolean checkExperiment); @Override Statement createApplication(Application.Name applicationName); @Override Map<Application.Name, Set<String>> getTagListForApplications(Collection<Application.Name> applicationNames); @Override void updateStateIndex(Experiment experiment); }
DatabaseExperimentRepository implements ExperimentRepository { @Override public Experiment.ID createExperiment(NewExperiment newExperiment) throws RepositoryException { final String SQL = "insert into experiment " + "(id, description, sampling_percent, label, " + "start_time, end_time, app_name, state) " + "values (?, ?, ?, ?, ?, ?, ?, ?)"; try { newTransaction().insert( SQL, newExperiment.getID(), newExperiment.getDescription() != null ? newExperiment.getDescription() : "", newExperiment.getSamplingPercent(), newExperiment.getLabel().toString(), newExperiment.getStartTime(), newExperiment.getEndTime(), newExperiment.getApplicationName().toString(), State.DRAFT.toString()); return newExperiment.getID(); } catch (WasabiException e) { throw e; } catch (Exception e) { throw new RepositoryException( "Could not persist experiment in database \"" + newExperiment.toString() + "\"", e); } } @Inject  DatabaseExperimentRepository(TransactionFactory transactionFactory, ExperimentValidator validator,
                                        Flyway flyway); @Override Experiment getExperiment(Experiment.ID experimentID); @Override Map<Application.Name, List<Experiment>> getExperimentsForApps(Collection<Application.Name> appNames); @Override Experiment getExperiment(Application.Name appName,
                                    Experiment.Label experimentLabel); @Override List<Experiment.ID> getExperiments(); @Override ExperimentList getExperiments(Collection<Experiment.ID> experimentIDs); @Override Map<Experiment.ID, Experiment> getExperimentsMap(Collection<Experiment.ID> experimentIDs); @Override Table<Experiment.ID, Experiment.Label, Experiment> getExperimentList(Application.Name appName); @Override List<Application.Name> getApplicationsList(); @Override Experiment.ID createExperiment(NewExperiment newExperiment); @Override Experiment updateExperiment(Experiment experiment); @Override Experiment updateExperimentState(Experiment experiment, State state); @Override Bucket getBucket(Experiment.ID experimentID,
                            Bucket.Label bucketLabel); @Override void createBucket(Bucket newBucket); @Override Bucket updateBucket(Bucket bucket); @Override Bucket updateBucketAllocationPercentage(Bucket bucket, Double desiredAllocationPercentage); @Override Bucket updateBucketState(Bucket bucket, Bucket.State desiredState); @Override BucketList updateBucketBatch(Experiment.ID experimentID, BucketList bucketList); @Override void deleteBucket(Experiment.ID experimentID,
                             Bucket.Label bucketLabel); @Override void logBucketChanges(Experiment.ID experimentID, Bucket.Label bucketLabel,
                                 List<Bucket.BucketAuditInfo> changeList); @Override void logExperimentChanges(Experiment.ID experimentID, List<Experiment.ExperimentAuditInfo> changeList); @Override List<Experiment> getExperiments(Application.Name appName); @Override void deleteExperiment(NewExperiment newExperiment); @Override void createIndicesForNewExperiment(NewExperiment newExperiment); @Override HashMap<Experiment.ID, BucketList> getBucketList(Collection<Experiment.ID> experimentIDCollection); @Override BucketList getBucketList(Experiment.ID experimentID); @Override BucketList getBuckets(Experiment.ID experimentID, boolean checkExperiment); @Override Statement createApplication(Application.Name applicationName); @Override Map<Application.Name, Set<String>> getTagListForApplications(Collection<Application.Name> applicationNames); @Override void updateStateIndex(Experiment experiment);  }