@Test public void testGetPrioritiesForApplications() throws ExecutionException, InterruptedException { Application.Name appName = Application.Name.valueOf("testApp1"); Set<Application.Name> appNameSet = new HashSet<>(); appNameSet.add(appName); Experiment.ID expId1 = Experiment.ID.newInstance(); ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>> experimentsFuture = mock(ListenableFuture.class); Mockito.when(experimentAccessor.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); ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Application>> appsFuture = mock(ListenableFuture.class); Mockito.when(accessor.asyncGetPriorities(appName.toString())).thenReturn(appsFuture); List<UUID> priorities = new ArrayList<>(); priorities.add(expId1.getRawID()); List<com.intuit.wasabi.repository.cassandra.pojo.Application> appsList = new ArrayList<>(); com.intuit.wasabi.repository.cassandra.pojo.Application app1 = com.intuit.wasabi.repository.cassandra.pojo.Application.builder() .appName(appName.toString()) .priorities(priorities) .build(); appsList.add(app1); Result<com.intuit.wasabi.repository.cassandra.pojo.Application> appResult = mock(Result.class); when(appResult.all()).thenReturn(appsList); when(appsFuture.get()).thenReturn(appResult); Map<Application.Name, PrioritizedExperimentList> appPrioritiesMap = repository.getPriorities(appNameSet); assertThat(appPrioritiesMap.size(), is(1)); assertThat(nonNull(appPrioritiesMap.get(appName)), is(true)); assertThat(appPrioritiesMap.get(appName).getPrioritizedExperiments().get(0).getID().getRawID(), is(expId1.getRawID())); }
@Override public PrioritizedExperimentList getPriorities( Application.Name applicationName) { LOGGER.debug("Getting priorities for {} ", applicationName); PrioritizedExperimentList prioritizedExperimentList = new PrioritizedExperimentList(); try { List<ID> priorityList = getPriorityList(applicationName); LOGGER.debug("Received priorities list {} for {} ", new Object[]{ priorityList, applicationName}); if (priorityList != null) { final List<UUID> priorityUUIDs = priorityList.stream() .map(id -> id.getRawID()).collect(Collectors.toList()); List<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experimentPojos = priorityUUIDs.stream().map(uuid -> experimentAccessor.getExperimentById(uuid).one()) .collect(Collectors.toList()); LOGGER.debug("Received experimentPojos {} for priorityUUIDs {}", new Object[]{experimentPojos, priorityUUIDs}); int priorityValue = 1; for (com.intuit.wasabi.repository.cassandra.pojo.Experiment experimentPojo : experimentPojos) { prioritizedExperimentList .addPrioritizedExperiment(PrioritizedExperiment .from(ExperimentHelper .makeExperiment(experimentPojo), priorityValue).build()); priorityValue += 1; } } } catch (Exception e) { LOGGER.error("Exception while getting priority list for {} ", new Object[]{applicationName}, e); throw new RepositoryException( "Unable to retrieve the priority list for application: \"" + applicationName.toString() + "\"" + e); } LOGGER.debug("Returning prioritizedExperimentList {} ", prioritizedExperimentList); return prioritizedExperimentList; }
CassandraPrioritiesRepository implements PrioritiesRepository { @Override public PrioritizedExperimentList getPriorities( Application.Name applicationName) { LOGGER.debug("Getting priorities for {} ", applicationName); PrioritizedExperimentList prioritizedExperimentList = new PrioritizedExperimentList(); try { List<ID> priorityList = getPriorityList(applicationName); LOGGER.debug("Received priorities list {} for {} ", new Object[]{ priorityList, applicationName}); if (priorityList != null) { final List<UUID> priorityUUIDs = priorityList.stream() .map(id -> id.getRawID()).collect(Collectors.toList()); List<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experimentPojos = priorityUUIDs.stream().map(uuid -> experimentAccessor.getExperimentById(uuid).one()) .collect(Collectors.toList()); LOGGER.debug("Received experimentPojos {} for priorityUUIDs {}", new Object[]{experimentPojos, priorityUUIDs}); int priorityValue = 1; for (com.intuit.wasabi.repository.cassandra.pojo.Experiment experimentPojo : experimentPojos) { prioritizedExperimentList .addPrioritizedExperiment(PrioritizedExperiment .from(ExperimentHelper .makeExperiment(experimentPojo), priorityValue).build()); priorityValue += 1; } } } catch (Exception e) { LOGGER.error("Exception while getting priority list for {} ", new Object[]{applicationName}, e); throw new RepositoryException( "Unable to retrieve the priority list for application: \"" + applicationName.toString() + "\"" + e); } LOGGER.debug("Returning prioritizedExperimentList {} ", prioritizedExperimentList); return prioritizedExperimentList; } }
CassandraPrioritiesRepository implements PrioritiesRepository { @Override public PrioritizedExperimentList getPriorities( Application.Name applicationName) { LOGGER.debug("Getting priorities for {} ", applicationName); PrioritizedExperimentList prioritizedExperimentList = new PrioritizedExperimentList(); try { List<ID> priorityList = getPriorityList(applicationName); LOGGER.debug("Received priorities list {} for {} ", new Object[]{ priorityList, applicationName}); if (priorityList != null) { final List<UUID> priorityUUIDs = priorityList.stream() .map(id -> id.getRawID()).collect(Collectors.toList()); List<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experimentPojos = priorityUUIDs.stream().map(uuid -> experimentAccessor.getExperimentById(uuid).one()) .collect(Collectors.toList()); LOGGER.debug("Received experimentPojos {} for priorityUUIDs {}", new Object[]{experimentPojos, priorityUUIDs}); int priorityValue = 1; for (com.intuit.wasabi.repository.cassandra.pojo.Experiment experimentPojo : experimentPojos) { prioritizedExperimentList .addPrioritizedExperiment(PrioritizedExperiment .from(ExperimentHelper .makeExperiment(experimentPojo), priorityValue).build()); priorityValue += 1; } } } catch (Exception e) { LOGGER.error("Exception while getting priority list for {} ", new Object[]{applicationName}, e); throw new RepositoryException( "Unable to retrieve the priority list for application: \"" + applicationName.toString() + "\"" + e); } LOGGER.debug("Returning prioritizedExperimentList {} ", prioritizedExperimentList); return prioritizedExperimentList; } @Inject  CassandraPrioritiesRepository(PrioritiesAccessor prioritiesAccessor,
                                         ExperimentAccessor experimentAccessor); }
CassandraPrioritiesRepository implements PrioritiesRepository { @Override public PrioritizedExperimentList getPriorities( Application.Name applicationName) { LOGGER.debug("Getting priorities for {} ", applicationName); PrioritizedExperimentList prioritizedExperimentList = new PrioritizedExperimentList(); try { List<ID> priorityList = getPriorityList(applicationName); LOGGER.debug("Received priorities list {} for {} ", new Object[]{ priorityList, applicationName}); if (priorityList != null) { final List<UUID> priorityUUIDs = priorityList.stream() .map(id -> id.getRawID()).collect(Collectors.toList()); List<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experimentPojos = priorityUUIDs.stream().map(uuid -> experimentAccessor.getExperimentById(uuid).one()) .collect(Collectors.toList()); LOGGER.debug("Received experimentPojos {} for priorityUUIDs {}", new Object[]{experimentPojos, priorityUUIDs}); int priorityValue = 1; for (com.intuit.wasabi.repository.cassandra.pojo.Experiment experimentPojo : experimentPojos) { prioritizedExperimentList .addPrioritizedExperiment(PrioritizedExperiment .from(ExperimentHelper .makeExperiment(experimentPojo), priorityValue).build()); priorityValue += 1; } } } catch (Exception e) { LOGGER.error("Exception while getting priority list for {} ", new Object[]{applicationName}, e); throw new RepositoryException( "Unable to retrieve the priority list for application: \"" + applicationName.toString() + "\"" + e); } LOGGER.debug("Returning prioritizedExperimentList {} ", prioritizedExperimentList); return prioritizedExperimentList; } @Inject  CassandraPrioritiesRepository(PrioritiesAccessor prioritiesAccessor,
                                         ExperimentAccessor experimentAccessor); @Override PrioritizedExperimentList getPriorities(
            Application.Name applicationName); @Override Map<Application.Name, PrioritizedExperimentList> getPriorities(Collection<Application.Name> applicationNames); @Override int getPriorityListLength(Application.Name applicationName); @Override void createPriorities(Application.Name applicationName,
                                 List<Experiment.ID> priorityIds); @Override List<Experiment.ID> getPriorityList(Application.Name applicationName); }
CassandraPrioritiesRepository implements PrioritiesRepository { @Override public PrioritizedExperimentList getPriorities( Application.Name applicationName) { LOGGER.debug("Getting priorities for {} ", applicationName); PrioritizedExperimentList prioritizedExperimentList = new PrioritizedExperimentList(); try { List<ID> priorityList = getPriorityList(applicationName); LOGGER.debug("Received priorities list {} for {} ", new Object[]{ priorityList, applicationName}); if (priorityList != null) { final List<UUID> priorityUUIDs = priorityList.stream() .map(id -> id.getRawID()).collect(Collectors.toList()); List<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experimentPojos = priorityUUIDs.stream().map(uuid -> experimentAccessor.getExperimentById(uuid).one()) .collect(Collectors.toList()); LOGGER.debug("Received experimentPojos {} for priorityUUIDs {}", new Object[]{experimentPojos, priorityUUIDs}); int priorityValue = 1; for (com.intuit.wasabi.repository.cassandra.pojo.Experiment experimentPojo : experimentPojos) { prioritizedExperimentList .addPrioritizedExperiment(PrioritizedExperiment .from(ExperimentHelper .makeExperiment(experimentPojo), priorityValue).build()); priorityValue += 1; } } } catch (Exception e) { LOGGER.error("Exception while getting priority list for {} ", new Object[]{applicationName}, e); throw new RepositoryException( "Unable to retrieve the priority list for application: \"" + applicationName.toString() + "\"" + e); } LOGGER.debug("Returning prioritizedExperimentList {} ", prioritizedExperimentList); return prioritizedExperimentList; } @Inject  CassandraPrioritiesRepository(PrioritiesAccessor prioritiesAccessor,
                                         ExperimentAccessor experimentAccessor); @Override PrioritizedExperimentList getPriorities(
            Application.Name applicationName); @Override Map<Application.Name, PrioritizedExperimentList> getPriorities(Collection<Application.Name> applicationNames); @Override int getPriorityListLength(Application.Name applicationName); @Override void createPriorities(Application.Name applicationName,
                                 List<Experiment.ID> priorityIds); @Override List<Experiment.ID> getPriorityList(Application.Name applicationName);  }