@Test public void testGetExperiments() throws IOException { List queryResult = new ArrayList(); Map map = mock(Map.class); queryResult.add(map); Experiment.ID id = Experiment.ID.newInstance(); ByteArrayOutputStream ba = new ByteArrayOutputStream(16); DataOutputStream da = new DataOutputStream(ba); da.writeLong(id.getRawID().getMostSignificantBits()); da.writeLong(id.getRawID().getLeastSignificantBits()); when(map.get("id")).thenReturn(ba.toByteArray()); when(transaction.select(anyString(), eq(Experiment.State.DELETED.toString()))).thenReturn(queryResult); List<Experiment.ID> result = repository.getExperiments(); assertThat(result.size(), is(1)); assertThat(result.get(0), is(id)); doThrow(new DatabaseException("Test")).when(transaction).select(anyString(), eq(Experiment.State.DELETED.toString())); BDDCatchException.when(repository).getExperiments(); BDDCatchException.then(caughtException()) .isInstanceOf(WasabiException.class) .hasMessage("Test") .hasNoCause(); doThrow(new RuntimeException("runtime exception")).when(transaction).select(anyString(), eq(Experiment.State.DELETED.toString())); BDDCatchException.when(repository).getExperiments(); BDDCatchException.then(caughtException()) .isInstanceOf(Exception.class) .hasMessage("Could not retrieve experiment IDs") .hasRootCauseExactlyInstanceOf(RuntimeException.class); }
@Override public List<Experiment.ID> getExperiments() throws RepositoryException { final String SQL = "select id from experiment " + "where state != ? order by id"; try { List<Map<String, Object>> experiments = newTransaction().select(SQL, DELETED.toString()); List<Experiment.ID> result = new ArrayList<>(); for (Map<String, Object> experiment : experiments) { result.add(Experiment.ID.valueOf((byte[]) experiment.get("id"))); } return result; } catch (WasabiException e) { throw e; } catch (Exception e) { throw new RepositoryException( "Could not retrieve experiment IDs", e); } }
DatabaseExperimentRepository implements ExperimentRepository { @Override public List<Experiment.ID> getExperiments() throws RepositoryException { final String SQL = "select id from experiment " + "where state != ? order by id"; try { List<Map<String, Object>> experiments = newTransaction().select(SQL, DELETED.toString()); List<Experiment.ID> result = new ArrayList<>(); for (Map<String, Object> experiment : experiments) { result.add(Experiment.ID.valueOf((byte[]) experiment.get("id"))); } return result; } catch (WasabiException e) { throw e; } catch (Exception e) { throw new RepositoryException( "Could not retrieve experiment IDs", e); } } }
DatabaseExperimentRepository implements ExperimentRepository { @Override public List<Experiment.ID> getExperiments() throws RepositoryException { final String SQL = "select id from experiment " + "where state != ? order by id"; try { List<Map<String, Object>> experiments = newTransaction().select(SQL, DELETED.toString()); List<Experiment.ID> result = new ArrayList<>(); for (Map<String, Object> experiment : experiments) { result.add(Experiment.ID.valueOf((byte[]) experiment.get("id"))); } return result; } catch (WasabiException e) { throw e; } catch (Exception e) { throw new RepositoryException( "Could not retrieve experiment IDs", e); } } @Inject  DatabaseExperimentRepository(TransactionFactory transactionFactory, ExperimentValidator validator,
                                        Flyway flyway); }
DatabaseExperimentRepository implements ExperimentRepository { @Override public List<Experiment.ID> getExperiments() throws RepositoryException { final String SQL = "select id from experiment " + "where state != ? order by id"; try { List<Map<String, Object>> experiments = newTransaction().select(SQL, DELETED.toString()); List<Experiment.ID> result = new ArrayList<>(); for (Map<String, Object> experiment : experiments) { result.add(Experiment.ID.valueOf((byte[]) experiment.get("id"))); } return result; } catch (WasabiException e) { throw e; } catch (Exception e) { throw new RepositoryException( "Could not retrieve experiment IDs", 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 List<Experiment.ID> getExperiments() throws RepositoryException { final String SQL = "select id from experiment " + "where state != ? order by id"; try { List<Map<String, Object>> experiments = newTransaction().select(SQL, DELETED.toString()); List<Experiment.ID> result = new ArrayList<>(); for (Map<String, Object> experiment : experiments) { result.add(Experiment.ID.valueOf((byte[]) experiment.get("id"))); } return result; } catch (WasabiException e) { throw e; } catch (Exception e) { throw new RepositoryException( "Could not retrieve experiment IDs", 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);  }