@Test public void testGetExperimentsMap() throws ExecutionException, InterruptedException { Application.Name appName = Application.Name.valueOf("testApp1"); Experiment.ID expId1 = Experiment.ID.newInstance(); Experiment.ID expId2 = Experiment.ID.newInstance(); Set<Experiment.ID> expIdSet = new HashSet<>(); expIdSet.add(expId1); expIdSet.add(expId2); ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>> experimentsFuture = mock(ListenableFuture.class); when(mockExperimentAccessor.asyncGetExperimentById(expId1.getRawID())).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); ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>> experimentsFuture2 = mock(ListenableFuture.class); when(mockExperimentAccessor.asyncGetExperimentById(expId2.getRawID())).thenReturn(experimentsFuture2); List<com.intuit.wasabi.repository.cassandra.pojo.Experiment> expList2 = new ArrayList<>(); com.intuit.wasabi.repository.cassandra.pojo.Experiment exp2 = com.intuit.wasabi.repository.cassandra.pojo.Experiment.builder() .id(expId2.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(); expList2.add(exp2); Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment> expResult2 = mock(Result.class); when(expResult2.all()).thenReturn(expList2); when(experimentsFuture2.get()).thenReturn(expResult2); Map<Experiment.ID, Experiment> actualResultMap = repository.getExperimentsMap(expIdSet); assertThat(actualResultMap.size(), is(2)); assertThat(actualResultMap.get(expId1).getID().getRawID(), is(exp1.getId())); assertThat(actualResultMap.get(expId2).getID().getRawID(), is(exp2.getId())); }
@Override public Map<Experiment.ID, Experiment> getExperimentsMap(Collection<Experiment.ID> experimentIds) { Map<Experiment.ID, ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>>> experimentsFutureMap = new HashMap<>(experimentIds.size()); Map<Experiment.ID, Experiment> experimentMap = new HashMap<>(experimentIds.size()); try { experimentIds.forEach(expId -> { experimentsFutureMap.put(expId, experimentAccessor.asyncGetExperimentById(expId.getRawID())); LOGGER.debug("Sent experimentAccessor.asyncGetExperimentById({})", expId); }); for (Experiment.ID expId : experimentsFutureMap.keySet()) { ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>> experimentsFuture = experimentsFutureMap.get(expId); UninterruptibleUtil.getUninterruptibly(experimentsFuture).all().stream().forEach(expPojo -> { Experiment exp = ExperimentHelper.makeExperiment(expPojo); experimentMap.put(exp.getID(), exp); }); } } catch (Exception e) { LOGGER.error("Error while preparing experimentMap for {}", experimentIds, e); throw new RepositoryException("Error while preparing experimentMap", e); } LOGGER.debug("Returning experimentMap {}", experimentMap); return experimentMap; }
CassandraExperimentRepository implements ExperimentRepository { @Override public Map<Experiment.ID, Experiment> getExperimentsMap(Collection<Experiment.ID> experimentIds) { Map<Experiment.ID, ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>>> experimentsFutureMap = new HashMap<>(experimentIds.size()); Map<Experiment.ID, Experiment> experimentMap = new HashMap<>(experimentIds.size()); try { experimentIds.forEach(expId -> { experimentsFutureMap.put(expId, experimentAccessor.asyncGetExperimentById(expId.getRawID())); LOGGER.debug("Sent experimentAccessor.asyncGetExperimentById({})", expId); }); for (Experiment.ID expId : experimentsFutureMap.keySet()) { ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>> experimentsFuture = experimentsFutureMap.get(expId); UninterruptibleUtil.getUninterruptibly(experimentsFuture).all().stream().forEach(expPojo -> { Experiment exp = ExperimentHelper.makeExperiment(expPojo); experimentMap.put(exp.getID(), exp); }); } } catch (Exception e) { LOGGER.error("Error while preparing experimentMap for {}", experimentIds, e); throw new RepositoryException("Error while preparing experimentMap", e); } LOGGER.debug("Returning experimentMap {}", experimentMap); return experimentMap; } }
CassandraExperimentRepository implements ExperimentRepository { @Override public Map<Experiment.ID, Experiment> getExperimentsMap(Collection<Experiment.ID> experimentIds) { Map<Experiment.ID, ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>>> experimentsFutureMap = new HashMap<>(experimentIds.size()); Map<Experiment.ID, Experiment> experimentMap = new HashMap<>(experimentIds.size()); try { experimentIds.forEach(expId -> { experimentsFutureMap.put(expId, experimentAccessor.asyncGetExperimentById(expId.getRawID())); LOGGER.debug("Sent experimentAccessor.asyncGetExperimentById({})", expId); }); for (Experiment.ID expId : experimentsFutureMap.keySet()) { ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>> experimentsFuture = experimentsFutureMap.get(expId); UninterruptibleUtil.getUninterruptibly(experimentsFuture).all().stream().forEach(expPojo -> { Experiment exp = ExperimentHelper.makeExperiment(expPojo); experimentMap.put(exp.getID(), exp); }); } } catch (Exception e) { LOGGER.error("Error while preparing experimentMap for {}", experimentIds, e); throw new RepositoryException("Error while preparing experimentMap", 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<Experiment.ID, Experiment> getExperimentsMap(Collection<Experiment.ID> experimentIds) { Map<Experiment.ID, ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>>> experimentsFutureMap = new HashMap<>(experimentIds.size()); Map<Experiment.ID, Experiment> experimentMap = new HashMap<>(experimentIds.size()); try { experimentIds.forEach(expId -> { experimentsFutureMap.put(expId, experimentAccessor.asyncGetExperimentById(expId.getRawID())); LOGGER.debug("Sent experimentAccessor.asyncGetExperimentById({})", expId); }); for (Experiment.ID expId : experimentsFutureMap.keySet()) { ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>> experimentsFuture = experimentsFutureMap.get(expId); UninterruptibleUtil.getUninterruptibly(experimentsFuture).all().stream().forEach(expPojo -> { Experiment exp = ExperimentHelper.makeExperiment(expPojo); experimentMap.put(exp.getID(), exp); }); } } catch (Exception e) { LOGGER.error("Error while preparing experimentMap for {}", experimentIds, e); throw new RepositoryException("Error while preparing experimentMap", 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<Experiment.ID, Experiment> getExperimentsMap(Collection<Experiment.ID> experimentIds) { Map<Experiment.ID, ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>>> experimentsFutureMap = new HashMap<>(experimentIds.size()); Map<Experiment.ID, Experiment> experimentMap = new HashMap<>(experimentIds.size()); try { experimentIds.forEach(expId -> { experimentsFutureMap.put(expId, experimentAccessor.asyncGetExperimentById(expId.getRawID())); LOGGER.debug("Sent experimentAccessor.asyncGetExperimentById({})", expId); }); for (Experiment.ID expId : experimentsFutureMap.keySet()) { ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>> experimentsFuture = experimentsFutureMap.get(expId); UninterruptibleUtil.getUninterruptibly(experimentsFuture).all().stream().forEach(expPojo -> { Experiment exp = ExperimentHelper.makeExperiment(expPojo); experimentMap.put(exp.getID(), exp); }); } } catch (Exception e) { LOGGER.error("Error while preparing experimentMap for {}", experimentIds, e); throw new RepositoryException("Error while preparing experimentMap", 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);  }