@Test public void testGetTagList() throws ExecutionException, InterruptedException { Application.Name app01 = Application.Name.valueOf("app01"); Application.Name app02 = Application.Name.valueOf("app02"); List<Application.Name> appNames = Arrays.asList(app01, app02); Set<String> exp1 = new TreeSet<>(Arrays.asList("tag1", "tag3")); Set<String> exp2 = new TreeSet<>(Arrays.asList("tag4")); List<ExperimentTagsByApplication> exp1Tags = Arrays.asList(ExperimentTagsByApplication.builder() .tags(exp1).appName(app01.toString()).build()); List<ExperimentTagsByApplication> exp2Tags = Arrays.asList(ExperimentTagsByApplication.builder() .tags(exp2).appName(app02.toString()).build()); ListenableFuture<Result<ExperimentTagsByApplication>> dbResultFuture1 = mock(ListenableFuture.class); ListenableFuture<Result<ExperimentTagsByApplication>> dbResultFuture2 = mock(ListenableFuture.class); Result<ExperimentTagsByApplication> dbResult1 = mock(Result.class); Result<ExperimentTagsByApplication> dbResult2 = mock(Result.class); when(mockExperimentTagAccessor.getExperimentTagsAsync("app01")).thenReturn(dbResultFuture1); when(mockExperimentTagAccessor.getExperimentTagsAsync("app02")).thenReturn(dbResultFuture2); when(dbResultFuture1.get()).thenReturn(dbResult1); when(dbResultFuture2.get()).thenReturn(dbResult2); when(dbResult1.all()).thenReturn(exp1Tags); when(dbResult2.all()).thenReturn(exp2Tags); Map<Name, Set<String>> callResult = repository.getTagListForApplications(appNames); assertEquals(2, callResult.size()); assertArrayEquals(exp1.toArray(), callResult.get(app01).toArray()); assertArrayEquals(exp2.toArray(), callResult.get(app02).toArray()); }
@Override public Map<Application.Name, Set<String>> getTagListForApplications(Collection<Application.Name> applicationNames) { LOGGER.debug("Retrieving Experiment Tags for applications {}", applicationNames); try { List<ListenableFuture<Result<ExperimentTagsByApplication>>> futures = new ArrayList<>(); for (Application.Name appName : applicationNames) { ListenableFuture<Result<ExperimentTagsByApplication>> resultSetFuture = experimentTagAccessor .getExperimentTagsAsync(appName.toString()); futures.add(resultSetFuture); } Map<Application.Name, Set<String>> result = new HashMap<>(); for (ListenableFuture<Result<ExperimentTagsByApplication>> future : futures) { List<ExperimentTagsByApplication> expTagApplication = future.get().all(); Set<String> allTagsForApplication = new TreeSet<>(); for (ExperimentTagsByApplication expTagsByApp : expTagApplication) { allTagsForApplication.addAll(expTagsByApp.getTags()); } if (!expTagApplication.isEmpty()) result.put(Application.Name.valueOf(expTagApplication.get(0).getAppName()), allTagsForApplication); } return result; } catch (Exception e) { LOGGER.error("Error while retieving ExperimentTags for {}", applicationNames, e); throw new RepositoryException("Unable to get ExperimentTags for applications: \"" + applicationNames.toString() + "\"" + e); } }
CassandraExperimentRepository implements ExperimentRepository { @Override public Map<Application.Name, Set<String>> getTagListForApplications(Collection<Application.Name> applicationNames) { LOGGER.debug("Retrieving Experiment Tags for applications {}", applicationNames); try { List<ListenableFuture<Result<ExperimentTagsByApplication>>> futures = new ArrayList<>(); for (Application.Name appName : applicationNames) { ListenableFuture<Result<ExperimentTagsByApplication>> resultSetFuture = experimentTagAccessor .getExperimentTagsAsync(appName.toString()); futures.add(resultSetFuture); } Map<Application.Name, Set<String>> result = new HashMap<>(); for (ListenableFuture<Result<ExperimentTagsByApplication>> future : futures) { List<ExperimentTagsByApplication> expTagApplication = future.get().all(); Set<String> allTagsForApplication = new TreeSet<>(); for (ExperimentTagsByApplication expTagsByApp : expTagApplication) { allTagsForApplication.addAll(expTagsByApp.getTags()); } if (!expTagApplication.isEmpty()) result.put(Application.Name.valueOf(expTagApplication.get(0).getAppName()), allTagsForApplication); } return result; } catch (Exception e) { LOGGER.error("Error while retieving ExperimentTags for {}", applicationNames, e); throw new RepositoryException("Unable to get ExperimentTags for applications: \"" + applicationNames.toString() + "\"" + e); } } }
CassandraExperimentRepository implements ExperimentRepository { @Override public Map<Application.Name, Set<String>> getTagListForApplications(Collection<Application.Name> applicationNames) { LOGGER.debug("Retrieving Experiment Tags for applications {}", applicationNames); try { List<ListenableFuture<Result<ExperimentTagsByApplication>>> futures = new ArrayList<>(); for (Application.Name appName : applicationNames) { ListenableFuture<Result<ExperimentTagsByApplication>> resultSetFuture = experimentTagAccessor .getExperimentTagsAsync(appName.toString()); futures.add(resultSetFuture); } Map<Application.Name, Set<String>> result = new HashMap<>(); for (ListenableFuture<Result<ExperimentTagsByApplication>> future : futures) { List<ExperimentTagsByApplication> expTagApplication = future.get().all(); Set<String> allTagsForApplication = new TreeSet<>(); for (ExperimentTagsByApplication expTagsByApp : expTagApplication) { allTagsForApplication.addAll(expTagsByApp.getTags()); } if (!expTagApplication.isEmpty()) result.put(Application.Name.valueOf(expTagApplication.get(0).getAppName()), allTagsForApplication); } return result; } catch (Exception e) { LOGGER.error("Error while retieving ExperimentTags for {}", applicationNames, e); throw new RepositoryException("Unable to get ExperimentTags for applications: \"" + applicationNames.toString() + "\"" + e); } } @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, Set<String>> getTagListForApplications(Collection<Application.Name> applicationNames) { LOGGER.debug("Retrieving Experiment Tags for applications {}", applicationNames); try { List<ListenableFuture<Result<ExperimentTagsByApplication>>> futures = new ArrayList<>(); for (Application.Name appName : applicationNames) { ListenableFuture<Result<ExperimentTagsByApplication>> resultSetFuture = experimentTagAccessor .getExperimentTagsAsync(appName.toString()); futures.add(resultSetFuture); } Map<Application.Name, Set<String>> result = new HashMap<>(); for (ListenableFuture<Result<ExperimentTagsByApplication>> future : futures) { List<ExperimentTagsByApplication> expTagApplication = future.get().all(); Set<String> allTagsForApplication = new TreeSet<>(); for (ExperimentTagsByApplication expTagsByApp : expTagApplication) { allTagsForApplication.addAll(expTagsByApp.getTags()); } if (!expTagApplication.isEmpty()) result.put(Application.Name.valueOf(expTagApplication.get(0).getAppName()), allTagsForApplication); } return result; } catch (Exception e) { LOGGER.error("Error while retieving ExperimentTags for {}", applicationNames, e); throw new RepositoryException("Unable to get ExperimentTags for applications: \"" + applicationNames.toString() + "\"" + e); } } @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, Set<String>> getTagListForApplications(Collection<Application.Name> applicationNames) { LOGGER.debug("Retrieving Experiment Tags for applications {}", applicationNames); try { List<ListenableFuture<Result<ExperimentTagsByApplication>>> futures = new ArrayList<>(); for (Application.Name appName : applicationNames) { ListenableFuture<Result<ExperimentTagsByApplication>> resultSetFuture = experimentTagAccessor .getExperimentTagsAsync(appName.toString()); futures.add(resultSetFuture); } Map<Application.Name, Set<String>> result = new HashMap<>(); for (ListenableFuture<Result<ExperimentTagsByApplication>> future : futures) { List<ExperimentTagsByApplication> expTagApplication = future.get().all(); Set<String> allTagsForApplication = new TreeSet<>(); for (ExperimentTagsByApplication expTagsByApp : expTagApplication) { allTagsForApplication.addAll(expTagsByApp.getTags()); } if (!expTagApplication.isEmpty()) result.put(Application.Name.valueOf(expTagApplication.get(0).getAppName()), allTagsForApplication); } return result; } catch (Exception e) { LOGGER.error("Error while retieving ExperimentTags for {}", applicationNames, e); throw new RepositoryException("Unable to get ExperimentTags for applications: \"" + applicationNames.toString() + "\"" + e); } } @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);  }