@Test public void testGetExclusivesList() throws ExecutionException, InterruptedException { Experiment.ID expId1 = Experiment.ID.newInstance(); Experiment.ID expId2 = Experiment.ID.newInstance(); Experiment.ID expId3 = Experiment.ID.newInstance(); Set<Experiment.ID> expIdSet = new HashSet<>(); expIdSet.add(expId1); ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Exclusion>> experimentsFuture = Mockito.mock(ListenableFuture.class); Mockito.when(accessor.asyncGetExclusions(expId1.getRawID())).thenReturn(experimentsFuture); List<com.intuit.wasabi.repository.cassandra.pojo.Exclusion> expList = new ArrayList<>(); com.intuit.wasabi.repository.cassandra.pojo.Exclusion exp1 = com.intuit.wasabi.repository.cassandra.pojo.Exclusion.builder() .base(expId1.getRawID()) .pair(expId2.getRawID()) .build(); expList.add(exp1); com.intuit.wasabi.repository.cassandra.pojo.Exclusion exp2 = com.intuit.wasabi.repository.cassandra.pojo.Exclusion.builder() .base(expId1.getRawID()) .pair(expId3.getRawID()) .build(); expList.add(exp2); Result<com.intuit.wasabi.repository.cassandra.pojo.Exclusion> expResult = Mockito.mock(Result.class); Mockito.when(expResult.all()).thenReturn(expList); Mockito.when(experimentsFuture.get()).thenReturn(expResult); Map<Experiment.ID, List<Experiment.ID>> mutuallyExclusiveExperiments = repository.getExclusivesList(expIdSet); assertThat(mutuallyExclusiveExperiments.size(), is(1)); assertThat(nonNull(mutuallyExclusiveExperiments.get(expId1)), is(true)); assertThat(mutuallyExclusiveExperiments.get(expId1).size(), is(2)); assertThat(mutuallyExclusiveExperiments.get(expId1).contains(expId2), is(true)); assertThat(mutuallyExclusiveExperiments.get(expId1).contains(expId3), is(true)); }
@Override public Map<Experiment.ID, List<Experiment.ID>> getExclusivesList(Collection<Experiment.ID> experimentIds) { LOGGER.debug("Getting exclusions for {}", experimentIds); Map<Experiment.ID, ListenableFuture<Result<Exclusion>>> exclusionFutureMap = new HashMap<>(experimentIds.size()); Map<Experiment.ID, List<Experiment.ID>> exclusionMap = new HashMap<>(experimentIds.size()); try { experimentIds.stream().forEach(experimentId -> { exclusionFutureMap.put(experimentId, mutexAccessor.asyncGetExclusions(experimentId.getRawID())); LOGGER.debug("Sent exclusionAccessor.asyncGetExclusions ({})", experimentId.getRawID()); }); for (Experiment.ID expId : exclusionFutureMap.keySet()) { ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Exclusion>> exclusionFuture = exclusionFutureMap.get(expId); exclusionMap.put(expId, new ArrayList<>()); UninterruptibleUtil.getUninterruptibly(exclusionFuture).all().forEach(exclusionPojo -> { exclusionMap.get(expId).add(Experiment.ID.valueOf(exclusionPojo.getPair())); } ); } } catch (Exception e) { LOGGER.error("Error while getting exclusions for {}", experimentIds, e); throw new RepositoryException("Could not fetch mutually exclusive experiments for the list of experiments", e); } LOGGER.debug("Returning exclusions map {}", exclusionMap); return exclusionMap; }
CassandraMutexRepository implements MutexRepository { @Override public Map<Experiment.ID, List<Experiment.ID>> getExclusivesList(Collection<Experiment.ID> experimentIds) { LOGGER.debug("Getting exclusions for {}", experimentIds); Map<Experiment.ID, ListenableFuture<Result<Exclusion>>> exclusionFutureMap = new HashMap<>(experimentIds.size()); Map<Experiment.ID, List<Experiment.ID>> exclusionMap = new HashMap<>(experimentIds.size()); try { experimentIds.stream().forEach(experimentId -> { exclusionFutureMap.put(experimentId, mutexAccessor.asyncGetExclusions(experimentId.getRawID())); LOGGER.debug("Sent exclusionAccessor.asyncGetExclusions ({})", experimentId.getRawID()); }); for (Experiment.ID expId : exclusionFutureMap.keySet()) { ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Exclusion>> exclusionFuture = exclusionFutureMap.get(expId); exclusionMap.put(expId, new ArrayList<>()); UninterruptibleUtil.getUninterruptibly(exclusionFuture).all().forEach(exclusionPojo -> { exclusionMap.get(expId).add(Experiment.ID.valueOf(exclusionPojo.getPair())); } ); } } catch (Exception e) { LOGGER.error("Error while getting exclusions for {}", experimentIds, e); throw new RepositoryException("Could not fetch mutually exclusive experiments for the list of experiments", e); } LOGGER.debug("Returning exclusions map {}", exclusionMap); return exclusionMap; } }
CassandraMutexRepository implements MutexRepository { @Override public Map<Experiment.ID, List<Experiment.ID>> getExclusivesList(Collection<Experiment.ID> experimentIds) { LOGGER.debug("Getting exclusions for {}", experimentIds); Map<Experiment.ID, ListenableFuture<Result<Exclusion>>> exclusionFutureMap = new HashMap<>(experimentIds.size()); Map<Experiment.ID, List<Experiment.ID>> exclusionMap = new HashMap<>(experimentIds.size()); try { experimentIds.stream().forEach(experimentId -> { exclusionFutureMap.put(experimentId, mutexAccessor.asyncGetExclusions(experimentId.getRawID())); LOGGER.debug("Sent exclusionAccessor.asyncGetExclusions ({})", experimentId.getRawID()); }); for (Experiment.ID expId : exclusionFutureMap.keySet()) { ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Exclusion>> exclusionFuture = exclusionFutureMap.get(expId); exclusionMap.put(expId, new ArrayList<>()); UninterruptibleUtil.getUninterruptibly(exclusionFuture).all().forEach(exclusionPojo -> { exclusionMap.get(expId).add(Experiment.ID.valueOf(exclusionPojo.getPair())); } ); } } catch (Exception e) { LOGGER.error("Error while getting exclusions for {}", experimentIds, e); throw new RepositoryException("Could not fetch mutually exclusive experiments for the list of experiments", e); } LOGGER.debug("Returning exclusions map {}", exclusionMap); return exclusionMap; } @Inject  CassandraMutexRepository(
            ExperimentAccessor experimentAccessor,
            ExclusionAccessor mutexAccessor,
            CassandraDriver driver); }
CassandraMutexRepository implements MutexRepository { @Override public Map<Experiment.ID, List<Experiment.ID>> getExclusivesList(Collection<Experiment.ID> experimentIds) { LOGGER.debug("Getting exclusions for {}", experimentIds); Map<Experiment.ID, ListenableFuture<Result<Exclusion>>> exclusionFutureMap = new HashMap<>(experimentIds.size()); Map<Experiment.ID, List<Experiment.ID>> exclusionMap = new HashMap<>(experimentIds.size()); try { experimentIds.stream().forEach(experimentId -> { exclusionFutureMap.put(experimentId, mutexAccessor.asyncGetExclusions(experimentId.getRawID())); LOGGER.debug("Sent exclusionAccessor.asyncGetExclusions ({})", experimentId.getRawID()); }); for (Experiment.ID expId : exclusionFutureMap.keySet()) { ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Exclusion>> exclusionFuture = exclusionFutureMap.get(expId); exclusionMap.put(expId, new ArrayList<>()); UninterruptibleUtil.getUninterruptibly(exclusionFuture).all().forEach(exclusionPojo -> { exclusionMap.get(expId).add(Experiment.ID.valueOf(exclusionPojo.getPair())); } ); } } catch (Exception e) { LOGGER.error("Error while getting exclusions for {}", experimentIds, e); throw new RepositoryException("Could not fetch mutually exclusive experiments for the list of experiments", e); } LOGGER.debug("Returning exclusions map {}", exclusionMap); return exclusionMap; } @Inject  CassandraMutexRepository(
            ExperimentAccessor experimentAccessor,
            ExclusionAccessor mutexAccessor,
            CassandraDriver driver); @Override List<Experiment.ID> getExclusionList(Experiment.ID experimentID); @Override void deleteExclusion(Experiment.ID base, Experiment.ID pair); @Override void createExclusion(Experiment.ID baseID, Experiment.ID pairID); @Override ExperimentList getExclusions(Experiment.ID base); @Override ExperimentList getNotExclusions(Experiment.ID base); @Override Map<Experiment.ID, List<Experiment.ID>> getExclusivesList(Collection<Experiment.ID> experimentIds); }
CassandraMutexRepository implements MutexRepository { @Override public Map<Experiment.ID, List<Experiment.ID>> getExclusivesList(Collection<Experiment.ID> experimentIds) { LOGGER.debug("Getting exclusions for {}", experimentIds); Map<Experiment.ID, ListenableFuture<Result<Exclusion>>> exclusionFutureMap = new HashMap<>(experimentIds.size()); Map<Experiment.ID, List<Experiment.ID>> exclusionMap = new HashMap<>(experimentIds.size()); try { experimentIds.stream().forEach(experimentId -> { exclusionFutureMap.put(experimentId, mutexAccessor.asyncGetExclusions(experimentId.getRawID())); LOGGER.debug("Sent exclusionAccessor.asyncGetExclusions ({})", experimentId.getRawID()); }); for (Experiment.ID expId : exclusionFutureMap.keySet()) { ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Exclusion>> exclusionFuture = exclusionFutureMap.get(expId); exclusionMap.put(expId, new ArrayList<>()); UninterruptibleUtil.getUninterruptibly(exclusionFuture).all().forEach(exclusionPojo -> { exclusionMap.get(expId).add(Experiment.ID.valueOf(exclusionPojo.getPair())); } ); } } catch (Exception e) { LOGGER.error("Error while getting exclusions for {}", experimentIds, e); throw new RepositoryException("Could not fetch mutually exclusive experiments for the list of experiments", e); } LOGGER.debug("Returning exclusions map {}", exclusionMap); return exclusionMap; } @Inject  CassandraMutexRepository(
            ExperimentAccessor experimentAccessor,
            ExclusionAccessor mutexAccessor,
            CassandraDriver driver); @Override List<Experiment.ID> getExclusionList(Experiment.ID experimentID); @Override void deleteExclusion(Experiment.ID base, Experiment.ID pair); @Override void createExclusion(Experiment.ID baseID, Experiment.ID pairID); @Override ExperimentList getExclusions(Experiment.ID base); @Override ExperimentList getNotExclusions(Experiment.ID base); @Override Map<Experiment.ID, List<Experiment.ID>> getExclusivesList(Collection<Experiment.ID> experimentIds);  }