@Test public void testGetOneExclusiveListSuccess() throws InterruptedException, ExecutionException { Exclusion exc = new Exclusion(base.getRawID(), pair.getRawID()); exclusions.add(exc); ListenableFuture<Result<Exclusion>> mockListenableFuture = mock(ListenableFuture.class); Mockito.when(accessor.asyncGetExclusions(base.getRawID())).thenReturn(mockListenableFuture); Mockito.when(mockListenableFuture.get()).thenReturn(resultDatastax); Mockito.when(resultDatastax.all()).thenReturn(exclusions); ArrayList<Experiment.ID> ids = new ArrayList<>(); ids.add(base); Map<ID, List<ID>> result = repository.getExclusivesList(ids); assertEquals("value should be equal", 1, result.size()); assertEquals("value should be equal", 1, result.get(base).size()); assertEquals("value should be equal", pair, result.get(base).get(0)); }
@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);  }