@Test public void testExperimentFetchPrioritizedListEmpty() { Application.Name appName = Application.Name.valueOf("Test"); Experiment.ID deletedExperimentId = Experiment.ID.newInstance(); Experiment.Label experimentLabel = Experiment.Label.valueOf("SameNamePresetTwice"); Experiment deletedExperiment = createMockExperiment(deletedExperimentId, experimentLabel, Experiment.State.DELETED); Optional<PrioritizedExperimentList> prioritizedExperimentListOptional = Optional.of(new PrioritizedExperimentList()); when(metadataCache.getPrioritizedExperimentListMap(appName)).thenReturn(prioritizedExperimentListOptional); when(metadataCache.getExperimentById(deletedExperimentId)).thenReturn(Optional.of(deletedExperiment)); Experiment returnedExperiment = assignmentsImpl.getExperiment(appName, experimentLabel); assertNull(returnedExperiment); }
protected Experiment getExperiment(Application.Name applicationName, Experiment.Label experimentLabel) { Experiment result = null; if (metadataCacheEnabled) { Optional<PrioritizedExperimentList> prioritizedExperimentListOptional = metadataCache.getPrioritizedExperimentListMap(applicationName); if (prioritizedExperimentListOptional.isPresent()) { for (PrioritizedExperiment prioritizedExperiment : prioritizedExperimentListOptional.get().getPrioritizedExperiments()) { if (experimentLabel.equals(prioritizedExperiment.getLabel())) { result = metadataCache.getExperimentById(prioritizedExperiment.getID()).orElse(null); break; } } } } else { result = repository.getExperiment(applicationName, experimentLabel); } return result; }
AssignmentsImpl implements Assignments { protected Experiment getExperiment(Application.Name applicationName, Experiment.Label experimentLabel) { Experiment result = null; if (metadataCacheEnabled) { Optional<PrioritizedExperimentList> prioritizedExperimentListOptional = metadataCache.getPrioritizedExperimentListMap(applicationName); if (prioritizedExperimentListOptional.isPresent()) { for (PrioritizedExperiment prioritizedExperiment : prioritizedExperimentListOptional.get().getPrioritizedExperiments()) { if (experimentLabel.equals(prioritizedExperiment.getLabel())) { result = metadataCache.getExperimentById(prioritizedExperiment.getID()).orElse(null); break; } } } } else { result = repository.getExperiment(applicationName, experimentLabel); } return result; } }
AssignmentsImpl implements Assignments { protected Experiment getExperiment(Application.Name applicationName, Experiment.Label experimentLabel) { Experiment result = null; if (metadataCacheEnabled) { Optional<PrioritizedExperimentList> prioritizedExperimentListOptional = metadataCache.getPrioritizedExperimentListMap(applicationName); if (prioritizedExperimentListOptional.isPresent()) { for (PrioritizedExperiment prioritizedExperiment : prioritizedExperimentListOptional.get().getPrioritizedExperiments()) { if (experimentLabel.equals(prioritizedExperiment.getLabel())) { result = metadataCache.getExperimentById(prioritizedExperiment.getID()).orElse(null); break; } } } } else { result = repository.getExperiment(applicationName, experimentLabel); } return result; } AssignmentsImpl(AssignmentsRepository assignmentRepository); @Inject  AssignmentsImpl(Map<String, AssignmentIngestionExecutor> executors,
                           final @CassandraRepository ExperimentRepository repository,
                           final AssignmentsRepository assignmentsRepository,
                           final RuleCache ruleCache, final Pages pages,
                           final AssignmentDecorator assignmentDecorator,
                           final @Named(RULECACHE_THREADPOOL)
                                   ThreadPoolExecutor ruleCacheExecutor,
                           final EventLog eventLog,
                           final @Named(ASSIGNMENTS_METADATA_CACHE_ENABLED)
                                   Boolean metadataCacheEnabled,
                           final AssignmentsMetadataCache metadataCache,
                           final Experiments experimentUtil); }
AssignmentsImpl implements Assignments { protected Experiment getExperiment(Application.Name applicationName, Experiment.Label experimentLabel) { Experiment result = null; if (metadataCacheEnabled) { Optional<PrioritizedExperimentList> prioritizedExperimentListOptional = metadataCache.getPrioritizedExperimentListMap(applicationName); if (prioritizedExperimentListOptional.isPresent()) { for (PrioritizedExperiment prioritizedExperiment : prioritizedExperimentListOptional.get().getPrioritizedExperiments()) { if (experimentLabel.equals(prioritizedExperiment.getLabel())) { result = metadataCache.getExperimentById(prioritizedExperiment.getID()).orElse(null); break; } } } } else { result = repository.getExperiment(applicationName, experimentLabel); } return result; } AssignmentsImpl(AssignmentsRepository assignmentRepository); @Inject  AssignmentsImpl(Map<String, AssignmentIngestionExecutor> executors,
                           final @CassandraRepository ExperimentRepository repository,
                           final AssignmentsRepository assignmentsRepository,
                           final RuleCache ruleCache, final Pages pages,
                           final AssignmentDecorator assignmentDecorator,
                           final @Named(RULECACHE_THREADPOOL)
                                   ThreadPoolExecutor ruleCacheExecutor,
                           final EventLog eventLog,
                           final @Named(ASSIGNMENTS_METADATA_CACHE_ENABLED)
                                   Boolean metadataCacheEnabled,
                           final AssignmentsMetadataCache metadataCache,
                           final Experiments experimentUtil); @Override List<Assignment> doBatchAssignments(User.ID userID, Application.Name applicationName, Context context,
                                               boolean createAssignment, boolean overwrite, HttpHeaders headers,
                                               ExperimentBatch experimentBatch,boolean forceProfileCheck); @Override List<Assignment> doPageAssignments(Application.Name applicationName, Page.Name pageName, User.ID userID,
                                              Context context, boolean createAssignment, boolean ignoreSamplingPercent,
                                              HttpHeaders headers, SegmentationProfile segmentationProfile,boolean forceProfileCheck); @Override Assignment doSingleAssignment(User.ID userID, Application.Name applicationName, Experiment.Label experimentLabel,
                                         Context context, boolean createAssignment, boolean ignoreSamplingPercent,
                                         SegmentationProfile segmentationProfile, HttpHeaders headers, boolean forceProfileCheck); @Override Assignment getExistingAssignment(User.ID userID,
                                            Application.Name appName, Experiment.Label experimentLabel,
                                            Context context); @Override Assignment putAssignment(User.ID userID, Application.Name applicationName, Experiment.Label experimentLabel,
                                    Context context, Bucket.Label desiredBucketLabel, boolean overwrite); @Override StreamingOutput getAssignmentStream(Experiment.ID experimentID, Context context, Parameters parameters, Boolean ignoreNullBucket); @Override boolean doSegmentTest(Application.Name applicationName, Experiment.Label experimentLabel,
                                 Context context, SegmentationProfile segmentationProfile,
                                 HttpHeaders headers); @Override Map<String, Integer> queuesLength(); @Override Map<String, Object> queuesDetails(); @Override void flushMessages(); @Override void clearMetadataCache(); @Override Map<String, String> metadataCacheDetails(); }
AssignmentsImpl implements Assignments { protected Experiment getExperiment(Application.Name applicationName, Experiment.Label experimentLabel) { Experiment result = null; if (metadataCacheEnabled) { Optional<PrioritizedExperimentList> prioritizedExperimentListOptional = metadataCache.getPrioritizedExperimentListMap(applicationName); if (prioritizedExperimentListOptional.isPresent()) { for (PrioritizedExperiment prioritizedExperiment : prioritizedExperimentListOptional.get().getPrioritizedExperiments()) { if (experimentLabel.equals(prioritizedExperiment.getLabel())) { result = metadataCache.getExperimentById(prioritizedExperiment.getID()).orElse(null); break; } } } } else { result = repository.getExperiment(applicationName, experimentLabel); } return result; } AssignmentsImpl(AssignmentsRepository assignmentRepository); @Inject  AssignmentsImpl(Map<String, AssignmentIngestionExecutor> executors,
                           final @CassandraRepository ExperimentRepository repository,
                           final AssignmentsRepository assignmentsRepository,
                           final RuleCache ruleCache, final Pages pages,
                           final AssignmentDecorator assignmentDecorator,
                           final @Named(RULECACHE_THREADPOOL)
                                   ThreadPoolExecutor ruleCacheExecutor,
                           final EventLog eventLog,
                           final @Named(ASSIGNMENTS_METADATA_CACHE_ENABLED)
                                   Boolean metadataCacheEnabled,
                           final AssignmentsMetadataCache metadataCache,
                           final Experiments experimentUtil); @Override List<Assignment> doBatchAssignments(User.ID userID, Application.Name applicationName, Context context,
                                               boolean createAssignment, boolean overwrite, HttpHeaders headers,
                                               ExperimentBatch experimentBatch,boolean forceProfileCheck); @Override List<Assignment> doPageAssignments(Application.Name applicationName, Page.Name pageName, User.ID userID,
                                              Context context, boolean createAssignment, boolean ignoreSamplingPercent,
                                              HttpHeaders headers, SegmentationProfile segmentationProfile,boolean forceProfileCheck); @Override Assignment doSingleAssignment(User.ID userID, Application.Name applicationName, Experiment.Label experimentLabel,
                                         Context context, boolean createAssignment, boolean ignoreSamplingPercent,
                                         SegmentationProfile segmentationProfile, HttpHeaders headers, boolean forceProfileCheck); @Override Assignment getExistingAssignment(User.ID userID,
                                            Application.Name appName, Experiment.Label experimentLabel,
                                            Context context); @Override Assignment putAssignment(User.ID userID, Application.Name applicationName, Experiment.Label experimentLabel,
                                    Context context, Bucket.Label desiredBucketLabel, boolean overwrite); @Override StreamingOutput getAssignmentStream(Experiment.ID experimentID, Context context, Parameters parameters, Boolean ignoreNullBucket); @Override boolean doSegmentTest(Application.Name applicationName, Experiment.Label experimentLabel,
                                 Context context, SegmentationProfile segmentationProfile,
                                 HttpHeaders headers); @Override Map<String, Integer> queuesLength(); @Override Map<String, Object> queuesDetails(); @Override void flushMessages(); @Override void clearMetadataCache(); @Override Map<String, String> metadataCacheDetails();  }