@Test public void testGetBucketList() throws ExecutionException, InterruptedException { Experiment.ID expId1 = Experiment.ID.newInstance(); Set<Experiment.ID> expIdSet = new HashSet<>(); expIdSet.add(expId1); ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Bucket>> bucketsFuture = mock(ListenableFuture.class); when(mockBucketAccessor.asyncGetBucketByExperimentId(expId1.getRawID())).thenReturn(bucketsFuture); List<com.intuit.wasabi.repository.cassandra.pojo.Bucket> bucketList = new ArrayList<>(); com.intuit.wasabi.repository.cassandra.pojo.Bucket bucket1 = com.intuit.wasabi.repository.cassandra.pojo.Bucket.builder() .experimentId(expId1.getRawID()) .state(State.OPEN.toString()) .allocation(0.4d) .control(true) .label("Test-Bucket-1") .payload("Test-Bucket-1-Payload") .build(); bucketList.add(bucket1); Result<com.intuit.wasabi.repository.cassandra.pojo.Bucket> bucketResult = mock(Result.class); when(bucketResult.all()).thenReturn(bucketList); when(bucketsFuture.get()).thenReturn(bucketResult); Map<Experiment.ID, BucketList> actualResultMap = repository.getBucketList(expIdSet); assertThat(actualResultMap.get(expId1) != null, is(true)); assertThat(actualResultMap.get(expId1).getBuckets().size(), is(1)); assertThat(actualResultMap.get(expId1).getBuckets().get(0).getLabel().toString(), is("Test-Bucket-1")); }
@Override public Map<Experiment.ID, BucketList> getBucketList(Collection<Experiment.ID> experimentIds) { LOGGER.debug("Getting buckets list by experimentIDs {}", experimentIds); Map<Experiment.ID, BucketList> bucketMap = new HashMap<>(); try { Map<Experiment.ID, ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Bucket>>> bucketFutureMap = new HashMap<>(); experimentIds.forEach(experimentId -> { bucketFutureMap.put(experimentId, bucketAccessor.asyncGetBucketByExperimentId(experimentId.getRawID())); }); for (Experiment.ID expId : bucketFutureMap.keySet()) { bucketMap.put(expId, new BucketList()); ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Bucket>> bucketFuture = bucketFutureMap.get(expId); UninterruptibleUtil.getUninterruptibly(bucketFuture).all().forEach(bucketPojo -> { bucketMap.get(expId).addBucket(BucketHelper.makeBucket(bucketPojo)); } ); } } catch (Exception e) { LOGGER.error("getBucketList for {} failed", experimentIds, e); throw new RepositoryException("Could not fetch buckets for the list of experiments", e); } LOGGER.debug("Returning bucketMap {}", bucketMap); return bucketMap; }
CassandraExperimentRepository implements ExperimentRepository { @Override public Map<Experiment.ID, BucketList> getBucketList(Collection<Experiment.ID> experimentIds) { LOGGER.debug("Getting buckets list by experimentIDs {}", experimentIds); Map<Experiment.ID, BucketList> bucketMap = new HashMap<>(); try { Map<Experiment.ID, ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Bucket>>> bucketFutureMap = new HashMap<>(); experimentIds.forEach(experimentId -> { bucketFutureMap.put(experimentId, bucketAccessor.asyncGetBucketByExperimentId(experimentId.getRawID())); }); for (Experiment.ID expId : bucketFutureMap.keySet()) { bucketMap.put(expId, new BucketList()); ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Bucket>> bucketFuture = bucketFutureMap.get(expId); UninterruptibleUtil.getUninterruptibly(bucketFuture).all().forEach(bucketPojo -> { bucketMap.get(expId).addBucket(BucketHelper.makeBucket(bucketPojo)); } ); } } catch (Exception e) { LOGGER.error("getBucketList for {} failed", experimentIds, e); throw new RepositoryException("Could not fetch buckets for the list of experiments", e); } LOGGER.debug("Returning bucketMap {}", bucketMap); return bucketMap; } }
CassandraExperimentRepository implements ExperimentRepository { @Override public Map<Experiment.ID, BucketList> getBucketList(Collection<Experiment.ID> experimentIds) { LOGGER.debug("Getting buckets list by experimentIDs {}", experimentIds); Map<Experiment.ID, BucketList> bucketMap = new HashMap<>(); try { Map<Experiment.ID, ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Bucket>>> bucketFutureMap = new HashMap<>(); experimentIds.forEach(experimentId -> { bucketFutureMap.put(experimentId, bucketAccessor.asyncGetBucketByExperimentId(experimentId.getRawID())); }); for (Experiment.ID expId : bucketFutureMap.keySet()) { bucketMap.put(expId, new BucketList()); ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Bucket>> bucketFuture = bucketFutureMap.get(expId); UninterruptibleUtil.getUninterruptibly(bucketFuture).all().forEach(bucketPojo -> { bucketMap.get(expId).addBucket(BucketHelper.makeBucket(bucketPojo)); } ); } } catch (Exception e) { LOGGER.error("getBucketList for {} failed", experimentIds, e); throw new RepositoryException("Could not fetch buckets for the list of experiments", e); } LOGGER.debug("Returning bucketMap {}", bucketMap); return bucketMap; } @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, BucketList> getBucketList(Collection<Experiment.ID> experimentIds) { LOGGER.debug("Getting buckets list by experimentIDs {}", experimentIds); Map<Experiment.ID, BucketList> bucketMap = new HashMap<>(); try { Map<Experiment.ID, ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Bucket>>> bucketFutureMap = new HashMap<>(); experimentIds.forEach(experimentId -> { bucketFutureMap.put(experimentId, bucketAccessor.asyncGetBucketByExperimentId(experimentId.getRawID())); }); for (Experiment.ID expId : bucketFutureMap.keySet()) { bucketMap.put(expId, new BucketList()); ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Bucket>> bucketFuture = bucketFutureMap.get(expId); UninterruptibleUtil.getUninterruptibly(bucketFuture).all().forEach(bucketPojo -> { bucketMap.get(expId).addBucket(BucketHelper.makeBucket(bucketPojo)); } ); } } catch (Exception e) { LOGGER.error("getBucketList for {} failed", experimentIds, e); throw new RepositoryException("Could not fetch buckets for the list of experiments", e); } LOGGER.debug("Returning bucketMap {}", bucketMap); return bucketMap; } @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, BucketList> getBucketList(Collection<Experiment.ID> experimentIds) { LOGGER.debug("Getting buckets list by experimentIDs {}", experimentIds); Map<Experiment.ID, BucketList> bucketMap = new HashMap<>(); try { Map<Experiment.ID, ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Bucket>>> bucketFutureMap = new HashMap<>(); experimentIds.forEach(experimentId -> { bucketFutureMap.put(experimentId, bucketAccessor.asyncGetBucketByExperimentId(experimentId.getRawID())); }); for (Experiment.ID expId : bucketFutureMap.keySet()) { bucketMap.put(expId, new BucketList()); ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Bucket>> bucketFuture = bucketFutureMap.get(expId); UninterruptibleUtil.getUninterruptibly(bucketFuture).all().forEach(bucketPojo -> { bucketMap.get(expId).addBucket(BucketHelper.makeBucket(bucketPojo)); } ); } } catch (Exception e) { LOGGER.error("getBucketList for {} failed", experimentIds, e); throw new RepositoryException("Could not fetch buckets for the list of experiments", e); } LOGGER.debug("Returning bucketMap {}", bucketMap); return bucketMap; } @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);  }