@Test public void getExperimentMultipleResultTest() { Page.Name pageName = Page.Name.valueOf("testPage1"); List<PageExperimentByAppNamePage> mockedResult = new ArrayList<>(); mockedResult.add( PageExperimentByAppNamePage.builder() .experimentId(UUID.randomUUID()) .page(pageName.toString()) .appName(APPLICATION_NAME.toString()) .assign(true) .build() ); mockedResult.add( PageExperimentByAppNamePage.builder() .experimentId(UUID.randomUUID()) .page(pageName.toString()) .appName(APPLICATION_NAME.toString()) .assign(false) .build() ); List<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experiments = new ArrayList<>(); for (int i = 0; i < mockedResult.size(); i++) { experiments.add( com.intuit.wasabi.repository.cassandra.pojo.Experiment.builder() .id(mockedResult.get(i).getExperimentId()) .label("testLabel" + (i + 1)) .build()); } when(pageExperimentIndexAccessor.selectBy(eq(APPLICATION_NAME.toString()), eq(pageName.toString()))).thenReturn(mockedResultMapping); when(mockedResultMapping.iterator()).thenReturn(mockedResult.iterator()); for (com.intuit.wasabi.repository.cassandra.pojo.Experiment experiment : experiments) { Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment> mocked = mock(Result.class); when(experimentAccessor.selectBy(eq(experiment.getId()))).thenReturn(mocked); when(mocked.one()).thenReturn(experiment); } List<PageExperiment> result = repository.getExperiments(APPLICATION_NAME, pageName); assertThat(result.size(), is(mockedResult.size())); for (int i = 0; i < mockedResult.size(); i++) { assertThat(result.get(i).getAllowNewAssignment(), is(mockedResult.get(i).isAssign())); assertThat(result.get(i).getId().getRawID(), is(mockedResult.get(i).getExperimentId())); assertThat(result.get(i).getLabel().toString(), is(experiments.get(i).getLabel())); } }
@Override public List<PageExperiment> getExperiments(Application.Name applicationName, Page.Name pageName) { Stream<PageExperimentByAppNamePage> resultList = Stream.empty(); try { Result<PageExperimentByAppNamePage> result = pageExperimentIndexAccessor.selectBy(applicationName.toString(), pageName.toString()); resultList = StreamSupport.stream( Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException(new StringBuilder("Could not retrieve the experiments for applicationName:\"").append(applicationName).append("\", page:\"").append(pageName).append("\"").toString(), e); } return resultList .map(t -> { Optional<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experiment = Optional.ofNullable(experimentAccessor.selectBy(t.getExperimentId()).one()); PageExperiment.Builder builder = new PageExperiment.Builder( Experiment.ID.valueOf(t.getExperimentId()), null, t.isAssign() ); if (experiment.isPresent()) { builder.setLabel(Experiment.Label.valueOf(experiment.get().getLabel())); } return builder.build(); } ).filter(t -> t.getLabel() != null) .collect(Collectors.toList()); }
CassandraPagesRepository implements PagesRepository { @Override public List<PageExperiment> getExperiments(Application.Name applicationName, Page.Name pageName) { Stream<PageExperimentByAppNamePage> resultList = Stream.empty(); try { Result<PageExperimentByAppNamePage> result = pageExperimentIndexAccessor.selectBy(applicationName.toString(), pageName.toString()); resultList = StreamSupport.stream( Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException(new StringBuilder("Could not retrieve the experiments for applicationName:\"").append(applicationName).append("\", page:\"").append(pageName).append("\"").toString(), e); } return resultList .map(t -> { Optional<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experiment = Optional.ofNullable(experimentAccessor.selectBy(t.getExperimentId()).one()); PageExperiment.Builder builder = new PageExperiment.Builder( Experiment.ID.valueOf(t.getExperimentId()), null, t.isAssign() ); if (experiment.isPresent()) { builder.setLabel(Experiment.Label.valueOf(experiment.get().getLabel())); } return builder.build(); } ).filter(t -> t.getLabel() != null) .collect(Collectors.toList()); } }
CassandraPagesRepository implements PagesRepository { @Override public List<PageExperiment> getExperiments(Application.Name applicationName, Page.Name pageName) { Stream<PageExperimentByAppNamePage> resultList = Stream.empty(); try { Result<PageExperimentByAppNamePage> result = pageExperimentIndexAccessor.selectBy(applicationName.toString(), pageName.toString()); resultList = StreamSupport.stream( Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException(new StringBuilder("Could not retrieve the experiments for applicationName:\"").append(applicationName).append("\", page:\"").append(pageName).append("\"").toString(), e); } return resultList .map(t -> { Optional<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experiment = Optional.ofNullable(experimentAccessor.selectBy(t.getExperimentId()).one()); PageExperiment.Builder builder = new PageExperiment.Builder( Experiment.ID.valueOf(t.getExperimentId()), null, t.isAssign() ); if (experiment.isPresent()) { builder.setLabel(Experiment.Label.valueOf(experiment.get().getLabel())); } return builder.build(); } ).filter(t -> t.getLabel() != null) .collect(Collectors.toList()); } @Inject  CassandraPagesRepository(ExperimentAccessor experimentAccessor,
                                    PageExperimentIndexAccessor pageExperimentIndexAccessor,
                                    ExperimentPageAccessor experimentPageAccessor,
                                    AppPageIndexAccessor appPageIndexAccessor,
                                    ExperimentAuditLogAccessor experimentAuditLogAccessor,
                                    MappingManager mappingManager); }
CassandraPagesRepository implements PagesRepository { @Override public List<PageExperiment> getExperiments(Application.Name applicationName, Page.Name pageName) { Stream<PageExperimentByAppNamePage> resultList = Stream.empty(); try { Result<PageExperimentByAppNamePage> result = pageExperimentIndexAccessor.selectBy(applicationName.toString(), pageName.toString()); resultList = StreamSupport.stream( Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException(new StringBuilder("Could not retrieve the experiments for applicationName:\"").append(applicationName).append("\", page:\"").append(pageName).append("\"").toString(), e); } return resultList .map(t -> { Optional<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experiment = Optional.ofNullable(experimentAccessor.selectBy(t.getExperimentId()).one()); PageExperiment.Builder builder = new PageExperiment.Builder( Experiment.ID.valueOf(t.getExperimentId()), null, t.isAssign() ); if (experiment.isPresent()) { builder.setLabel(Experiment.Label.valueOf(experiment.get().getLabel())); } return builder.build(); } ).filter(t -> t.getLabel() != null) .collect(Collectors.toList()); } @Inject  CassandraPagesRepository(ExperimentAccessor experimentAccessor,
                                    PageExperimentIndexAccessor pageExperimentIndexAccessor,
                                    ExperimentPageAccessor experimentPageAccessor,
                                    AppPageIndexAccessor appPageIndexAccessor,
                                    ExperimentAuditLogAccessor experimentAuditLogAccessor,
                                    MappingManager mappingManager); @Override void postPages(Application.Name applicationName, Experiment.ID experimentID, ExperimentPageList experimentPageList); @Override void deletePage(Application.Name applicationName, Experiment.ID experimentID, Page.Name pageName); @Override List<Page> getPageList(Application.Name applicationName); @Override Map<Page.Name, List<PageExperiment>> getPageExperimentList(Application.Name applicationName); @Override ExperimentPageList getExperimentPages(Experiment.ID experimentID); @Override List<PageExperiment> getExperiments(Application.Name applicationName, Page.Name pageName); @Override List<PageExperiment> getExperimentsWithoutLabels(Application.Name applicationName, Page.Name pageName); @Override Map<Pair<Application.Name, Page.Name>, List<PageExperiment>> getExperimentsWithoutLabels(Collection<Pair<Application.Name, Page.Name>> appAndPagePairs); @Override void erasePageData(Application.Name applicationName, Experiment.ID experimentID); }
CassandraPagesRepository implements PagesRepository { @Override public List<PageExperiment> getExperiments(Application.Name applicationName, Page.Name pageName) { Stream<PageExperimentByAppNamePage> resultList = Stream.empty(); try { Result<PageExperimentByAppNamePage> result = pageExperimentIndexAccessor.selectBy(applicationName.toString(), pageName.toString()); resultList = StreamSupport.stream( Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException(new StringBuilder("Could not retrieve the experiments for applicationName:\"").append(applicationName).append("\", page:\"").append(pageName).append("\"").toString(), e); } return resultList .map(t -> { Optional<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experiment = Optional.ofNullable(experimentAccessor.selectBy(t.getExperimentId()).one()); PageExperiment.Builder builder = new PageExperiment.Builder( Experiment.ID.valueOf(t.getExperimentId()), null, t.isAssign() ); if (experiment.isPresent()) { builder.setLabel(Experiment.Label.valueOf(experiment.get().getLabel())); } return builder.build(); } ).filter(t -> t.getLabel() != null) .collect(Collectors.toList()); } @Inject  CassandraPagesRepository(ExperimentAccessor experimentAccessor,
                                    PageExperimentIndexAccessor pageExperimentIndexAccessor,
                                    ExperimentPageAccessor experimentPageAccessor,
                                    AppPageIndexAccessor appPageIndexAccessor,
                                    ExperimentAuditLogAccessor experimentAuditLogAccessor,
                                    MappingManager mappingManager); @Override void postPages(Application.Name applicationName, Experiment.ID experimentID, ExperimentPageList experimentPageList); @Override void deletePage(Application.Name applicationName, Experiment.ID experimentID, Page.Name pageName); @Override List<Page> getPageList(Application.Name applicationName); @Override Map<Page.Name, List<PageExperiment>> getPageExperimentList(Application.Name applicationName); @Override ExperimentPageList getExperimentPages(Experiment.ID experimentID); @Override List<PageExperiment> getExperiments(Application.Name applicationName, Page.Name pageName); @Override List<PageExperiment> getExperimentsWithoutLabels(Application.Name applicationName, Page.Name pageName); @Override Map<Pair<Application.Name, Page.Name>, List<PageExperiment>> getExperimentsWithoutLabels(Collection<Pair<Application.Name, Page.Name>> appAndPagePairs); @Override void erasePageData(Application.Name applicationName, Experiment.ID experimentID);  }