@Test public void testGetExperimentsForApps() throws ExecutionException, InterruptedException { Experiment.ID expId1 = Experiment.ID.newInstance(); Application.Name appName = Application.Name.valueOf("testApp1"); Set<Name> appNameSet = new HashSet<>(); appNameSet.add(appName); ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>> experimentsFuture = mock(ListenableFuture.class); when(mockExperimentAccessor.asyncGetExperimentByAppName(appName.toString())).thenReturn(experimentsFuture); List<com.intuit.wasabi.repository.cassandra.pojo.Experiment> expList = new ArrayList<>(); com.intuit.wasabi.repository.cassandra.pojo.Experiment exp1 = com.intuit.wasabi.repository.cassandra.pojo.Experiment.builder() .id(expId1.getRawID()) .appName(appName.toString()) .startTime(new Date()) .created(new Date()) .endTime(new Date()) .state(Experiment.State.RUNNING.toString()) .label("testExp1") .modified(new Date()) .samplePercent(90.00) .build(); expList.add(exp1); Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment> expResult = mock(Result.class); when(expResult.all()).thenReturn(expList); when(experimentsFuture.get()).thenReturn(expResult); Map<Application.Name, List<Experiment>> actualResultMap = repository.getExperimentsForApps(appNameSet); assertThat(actualResultMap.get(appName).size(), is(1)); assertThat(actualResultMap.get(appName).get(0).getID().getRawID(), is(exp1.getId())); }
@Override public Map<Application.Name, List<Experiment>> getExperimentsForApps(Collection<Application.Name> appNames) { Map<Application.Name, ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>>> experimentsFutureMap = new HashMap<>(appNames.size()); Map<Application.Name, List<Experiment>> experimentMap = new HashMap<>(appNames.size()); try { appNames.forEach(appName -> { experimentsFutureMap.put(appName, experimentAccessor.asyncGetExperimentByAppName(appName.toString())); LOGGER.debug("Sent experimentAccessor.asyncGetExperimentByAppName({})", appName); }); for (Application.Name appName : experimentsFutureMap.keySet()) { ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>> experimentsFuture = experimentsFutureMap.get(appName); final List<Experiment> appExperiments = new ArrayList<>(); UninterruptibleUtil.getUninterruptibly(experimentsFuture).all().stream().forEach(expPojo -> { appExperiments.add(ExperimentHelper.makeExperiment(expPojo)); }); experimentMap.put(appName, appExperiments); } LOGGER.debug("experimentMap=> {}", experimentMap); } catch (Exception e) { LOGGER.error("Error while getExperimentsForApps {}", appNames, e); throw new RepositoryException("Error while getExperimentsForApps", e); } LOGGER.debug("Returning experimentMap {}", experimentMap); return experimentMap; }
CassandraExperimentRepository implements ExperimentRepository { @Override public Map<Application.Name, List<Experiment>> getExperimentsForApps(Collection<Application.Name> appNames) { Map<Application.Name, ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>>> experimentsFutureMap = new HashMap<>(appNames.size()); Map<Application.Name, List<Experiment>> experimentMap = new HashMap<>(appNames.size()); try { appNames.forEach(appName -> { experimentsFutureMap.put(appName, experimentAccessor.asyncGetExperimentByAppName(appName.toString())); LOGGER.debug("Sent experimentAccessor.asyncGetExperimentByAppName({})", appName); }); for (Application.Name appName : experimentsFutureMap.keySet()) { ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>> experimentsFuture = experimentsFutureMap.get(appName); final List<Experiment> appExperiments = new ArrayList<>(); UninterruptibleUtil.getUninterruptibly(experimentsFuture).all().stream().forEach(expPojo -> { appExperiments.add(ExperimentHelper.makeExperiment(expPojo)); }); experimentMap.put(appName, appExperiments); } LOGGER.debug("experimentMap=> {}", experimentMap); } catch (Exception e) { LOGGER.error("Error while getExperimentsForApps {}", appNames, e); throw new RepositoryException("Error while getExperimentsForApps", e); } LOGGER.debug("Returning experimentMap {}", experimentMap); return experimentMap; } }
CassandraExperimentRepository implements ExperimentRepository { @Override public Map<Application.Name, List<Experiment>> getExperimentsForApps(Collection<Application.Name> appNames) { Map<Application.Name, ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>>> experimentsFutureMap = new HashMap<>(appNames.size()); Map<Application.Name, List<Experiment>> experimentMap = new HashMap<>(appNames.size()); try { appNames.forEach(appName -> { experimentsFutureMap.put(appName, experimentAccessor.asyncGetExperimentByAppName(appName.toString())); LOGGER.debug("Sent experimentAccessor.asyncGetExperimentByAppName({})", appName); }); for (Application.Name appName : experimentsFutureMap.keySet()) { ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>> experimentsFuture = experimentsFutureMap.get(appName); final List<Experiment> appExperiments = new ArrayList<>(); UninterruptibleUtil.getUninterruptibly(experimentsFuture).all().stream().forEach(expPojo -> { appExperiments.add(ExperimentHelper.makeExperiment(expPojo)); }); experimentMap.put(appName, appExperiments); } LOGGER.debug("experimentMap=> {}", experimentMap); } catch (Exception e) { LOGGER.error("Error while getExperimentsForApps {}", appNames, e); throw new RepositoryException("Error while getExperimentsForApps", e); } LOGGER.debug("Returning experimentMap {}", experimentMap); return experimentMap; } @Inject  CassandraExperimentRepository(CassandraDriver driver,
                                         ExperimentAccessor experimentAccessor,
                                         ExperimentLabelIndexAccessor experimentLabelIndexAccessor,
                                         BucketAccessor bucketAccessor,
                                         ApplicationListAccessor applicationListAccessor,
                                         BucketAuditLogAccessor bucketAuditLogAccessor,
                                         ExperimentAuditLogAccessor experimentAuditLogAccessor,
                                         StateExperimentIndexAccessor stateExperimentIndexAccessor,
                                         ExperimentValidator validator,
                                         ExperimentTagAccessor experimentTagAccessor,
                                         PrioritiesAccessor prioritiesAccessor); }
CassandraExperimentRepository implements ExperimentRepository { @Override public Map<Application.Name, List<Experiment>> getExperimentsForApps(Collection<Application.Name> appNames) { Map<Application.Name, ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>>> experimentsFutureMap = new HashMap<>(appNames.size()); Map<Application.Name, List<Experiment>> experimentMap = new HashMap<>(appNames.size()); try { appNames.forEach(appName -> { experimentsFutureMap.put(appName, experimentAccessor.asyncGetExperimentByAppName(appName.toString())); LOGGER.debug("Sent experimentAccessor.asyncGetExperimentByAppName({})", appName); }); for (Application.Name appName : experimentsFutureMap.keySet()) { ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>> experimentsFuture = experimentsFutureMap.get(appName); final List<Experiment> appExperiments = new ArrayList<>(); UninterruptibleUtil.getUninterruptibly(experimentsFuture).all().stream().forEach(expPojo -> { appExperiments.add(ExperimentHelper.makeExperiment(expPojo)); }); experimentMap.put(appName, appExperiments); } LOGGER.debug("experimentMap=> {}", experimentMap); } catch (Exception e) { LOGGER.error("Error while getExperimentsForApps {}", appNames, e); throw new RepositoryException("Error while getExperimentsForApps", e); } LOGGER.debug("Returning experimentMap {}", experimentMap); return experimentMap; } @Inject  CassandraExperimentRepository(CassandraDriver driver,
                                         ExperimentAccessor experimentAccessor,
                                         ExperimentLabelIndexAccessor experimentLabelIndexAccessor,
                                         BucketAccessor bucketAccessor,
                                         ApplicationListAccessor applicationListAccessor,
                                         BucketAuditLogAccessor bucketAuditLogAccessor,
                                         ExperimentAuditLogAccessor experimentAuditLogAccessor,
                                         StateExperimentIndexAccessor stateExperimentIndexAccessor,
                                         ExperimentValidator validator,
                                         ExperimentTagAccessor experimentTagAccessor,
                                         PrioritiesAccessor prioritiesAccessor); ExperimentAccessor getExperimentAccessor(); void setExperimentAccessor(ExperimentAccessor experimentAccessor); ExperimentLabelIndexAccessor getExperimentLabelIndexAccessor(); void setExperimentLabelIndexAccessor(
            ExperimentLabelIndexAccessor experimentLabelIndexAccessor); BucketAccessor getBucketAccessor(); void setBucketAccessor(BucketAccessor bucketAccessor); ApplicationListAccessor getApplicationListAccessor(); void setApplicationListAccessor(
            ApplicationListAccessor applicationListAccessor); StateExperimentIndexAccessor getStateExperimentIndexAccessor(); void setStateExperimentIndexAccessor(
            StateExperimentIndexAccessor stateExperimentIndexAccessor); BucketAuditLogAccessor getBucketAuditLogAccessor(); void setBucketAuditLogAccessor(
            BucketAuditLogAccessor bucketAuditLogAccessor); ExperimentAuditLogAccessor getExperimentAuditLogAccessor(); void setExperimentAuditLogAccessor(
            ExperimentAuditLogAccessor experimentAuditLogAccessor); @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 Experiment.ID createExperiment(NewExperiment newExperiment); Statement updateExperimentTags(Application.Name applicationName, Experiment.ID expId, Set<String> tags); @Override void createIndicesForNewExperiment(NewExperiment newExperiment); @Override Map<Experiment.ID, BucketList> getBucketList(Collection<Experiment.ID> experimentIds); @Override BucketList getBucketList(Experiment.ID experimentID); @Override Experiment updateExperiment(Experiment experiment); @Override Experiment updateExperimentState(Experiment experiment, State state); @Override List<Experiment.ID> getExperiments(); @Override List<Experiment> getExperiments(Application.Name appName); @Override void deleteExperiment(NewExperiment newExperiment); @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 Bucket getBucket(Experiment.ID experimentID, Bucket.Label bucketLabel); @Override void createBucket(Bucket newBucket); @Override Bucket updateBucket(Bucket bucket); CassandraDriver getDriver(); void setDriver(CassandraDriver driver); @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<BucketAuditInfo> changeList); @Override void logExperimentChanges(Experiment.ID experimentID, List<ExperimentAuditInfo> changeList); @Override BucketList getBuckets(Experiment.ID experimentID, boolean checkExperiment); @Override void updateStateIndex(Experiment experiment); @Override Statement createApplication(Application.Name applicationName); @Override Map<Application.Name, Set<String>> getTagListForApplications(Collection<Application.Name> applicationNames); }
CassandraExperimentRepository implements ExperimentRepository { @Override public Map<Application.Name, List<Experiment>> getExperimentsForApps(Collection<Application.Name> appNames) { Map<Application.Name, ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>>> experimentsFutureMap = new HashMap<>(appNames.size()); Map<Application.Name, List<Experiment>> experimentMap = new HashMap<>(appNames.size()); try { appNames.forEach(appName -> { experimentsFutureMap.put(appName, experimentAccessor.asyncGetExperimentByAppName(appName.toString())); LOGGER.debug("Sent experimentAccessor.asyncGetExperimentByAppName({})", appName); }); for (Application.Name appName : experimentsFutureMap.keySet()) { ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>> experimentsFuture = experimentsFutureMap.get(appName); final List<Experiment> appExperiments = new ArrayList<>(); UninterruptibleUtil.getUninterruptibly(experimentsFuture).all().stream().forEach(expPojo -> { appExperiments.add(ExperimentHelper.makeExperiment(expPojo)); }); experimentMap.put(appName, appExperiments); } LOGGER.debug("experimentMap=> {}", experimentMap); } catch (Exception e) { LOGGER.error("Error while getExperimentsForApps {}", appNames, e); throw new RepositoryException("Error while getExperimentsForApps", e); } LOGGER.debug("Returning experimentMap {}", experimentMap); return experimentMap; } @Inject  CassandraExperimentRepository(CassandraDriver driver,
                                         ExperimentAccessor experimentAccessor,
                                         ExperimentLabelIndexAccessor experimentLabelIndexAccessor,
                                         BucketAccessor bucketAccessor,
                                         ApplicationListAccessor applicationListAccessor,
                                         BucketAuditLogAccessor bucketAuditLogAccessor,
                                         ExperimentAuditLogAccessor experimentAuditLogAccessor,
                                         StateExperimentIndexAccessor stateExperimentIndexAccessor,
                                         ExperimentValidator validator,
                                         ExperimentTagAccessor experimentTagAccessor,
                                         PrioritiesAccessor prioritiesAccessor); ExperimentAccessor getExperimentAccessor(); void setExperimentAccessor(ExperimentAccessor experimentAccessor); ExperimentLabelIndexAccessor getExperimentLabelIndexAccessor(); void setExperimentLabelIndexAccessor(
            ExperimentLabelIndexAccessor experimentLabelIndexAccessor); BucketAccessor getBucketAccessor(); void setBucketAccessor(BucketAccessor bucketAccessor); ApplicationListAccessor getApplicationListAccessor(); void setApplicationListAccessor(
            ApplicationListAccessor applicationListAccessor); StateExperimentIndexAccessor getStateExperimentIndexAccessor(); void setStateExperimentIndexAccessor(
            StateExperimentIndexAccessor stateExperimentIndexAccessor); BucketAuditLogAccessor getBucketAuditLogAccessor(); void setBucketAuditLogAccessor(
            BucketAuditLogAccessor bucketAuditLogAccessor); ExperimentAuditLogAccessor getExperimentAuditLogAccessor(); void setExperimentAuditLogAccessor(
            ExperimentAuditLogAccessor experimentAuditLogAccessor); @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 Experiment.ID createExperiment(NewExperiment newExperiment); Statement updateExperimentTags(Application.Name applicationName, Experiment.ID expId, Set<String> tags); @Override void createIndicesForNewExperiment(NewExperiment newExperiment); @Override Map<Experiment.ID, BucketList> getBucketList(Collection<Experiment.ID> experimentIds); @Override BucketList getBucketList(Experiment.ID experimentID); @Override Experiment updateExperiment(Experiment experiment); @Override Experiment updateExperimentState(Experiment experiment, State state); @Override List<Experiment.ID> getExperiments(); @Override List<Experiment> getExperiments(Application.Name appName); @Override void deleteExperiment(NewExperiment newExperiment); @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 Bucket getBucket(Experiment.ID experimentID, Bucket.Label bucketLabel); @Override void createBucket(Bucket newBucket); @Override Bucket updateBucket(Bucket bucket); CassandraDriver getDriver(); void setDriver(CassandraDriver driver); @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<BucketAuditInfo> changeList); @Override void logExperimentChanges(Experiment.ID experimentID, List<ExperimentAuditInfo> changeList); @Override BucketList getBuckets(Experiment.ID experimentID, boolean checkExperiment); @Override void updateStateIndex(Experiment experiment); @Override Statement createApplication(Application.Name applicationName); @Override Map<Application.Name, Set<String>> getTagListForApplications(Collection<Application.Name> applicationNames);  }