@Test public void testPopulateExperimentMetadataSuccessCase() throws ExecutionException, InterruptedException { Experiment.ID expId1 = Experiment.ID.newInstance(); Application.Name appName = Application.Name.valueOf("testApp1"); User.ID userID = User.ID.valueOf("testUser1"); Context context = Context.valueOf("TEST"); SegmentationProfile segmentationProfile = mock(SegmentationProfile.class); ExperimentBatch experimentBatch = ExperimentBatch.newInstance().withProfile(segmentationProfile.getProfile()).build(); Map<Experiment.ID, Boolean> allowAssignments = new HashMap<>(); allowAssignments.put(expId1, true); Optional<Map<Experiment.ID, Boolean>> allowAssignmentsOptional = Optional.of(allowAssignments); PrioritizedExperimentList appPriorities = new PrioritizedExperimentList(); Map<Experiment.ID, com.intuit.wasabi.experimentobjects.Experiment> experimentMap = new HashMap<>(); Map<Experiment.ID, BucketList> bucketMap = new HashMap<>(); Map<Experiment.ID, List<Experiment.ID>> exclusionMap = new HashMap<>(); ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Experiment>> experimentsFuture = mock(ListenableFuture.class); 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>> applicationFuture = mock(ListenableFuture.class); when(prioritiesAccessor.asyncGetPriorities(appName.toString())).thenReturn(applicationFuture); List<com.intuit.wasabi.repository.cassandra.pojo.Application> applicationList = new ArrayList<>(); com.intuit.wasabi.repository.cassandra.pojo.Application app1 = com.intuit.wasabi.repository.cassandra.pojo.Application.builder() .appName(appName.toString()) .priority(expId1.getRawID()) .build(); applicationList.add(app1); Result<com.intuit.wasabi.repository.cassandra.pojo.Application> applicationResult = mock(Result.class); when(applicationResult.all()).thenReturn(applicationList); when(applicationFuture.get()).thenReturn(applicationResult); ListenableFuture<Result<ExperimentUserByUserIdContextAppNameExperimentId>> userAssignmentFuture = mock(ListenableFuture.class); Bucket.Label bucketLabel = Bucket.Label.valueOf("testBucket1"); when(experimentUserIndexAccessor.asyncSelectBy(userID.toString(), appName.toString(), context.toString())).thenReturn(userAssignmentFuture); List<ExperimentUserByUserIdContextAppNameExperimentId> userAssignmentList = new ArrayList<>(); ExperimentUserByUserIdContextAppNameExperimentId ua1 = ExperimentUserByUserIdContextAppNameExperimentId.builder() .experimentId(expId1.getRawID()) .appName(appName.toString()) .context(context.toString()) .bucket(bucketLabel.toString()).build(); userAssignmentList.add(ua1); Result<ExperimentUserByUserIdContextAppNameExperimentId> uaResult = mock(Result.class); when(uaResult.all()).thenReturn(userAssignmentList); when(userAssignmentFuture.get()).thenReturn(uaResult); ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Bucket>> bucketFuture = mock(ListenableFuture.class); when(bucketAccessor.asyncGetBucketByExperimentId(expId1.getRawID())).thenReturn(bucketFuture); List<com.intuit.wasabi.repository.cassandra.pojo.Bucket> bucketList = new ArrayList<>(); com.intuit.wasabi.repository.cassandra.pojo.Bucket bucket1 = com.intuit.wasabi.repository.cassandra.pojo.Bucket.builder() .label(bucketLabel.toString()) .state(Bucket.State.OPEN.toString()) .experimentId(expId1.getRawID()) .build(); bucketList.add(bucket1); Result<com.intuit.wasabi.repository.cassandra.pojo.Bucket> bucketResult = mock(Result.class); when(bucketResult.all()).thenReturn(bucketList); when(bucketFuture.get()).thenReturn(bucketResult); ListenableFuture<Result<com.intuit.wasabi.repository.cassandra.pojo.Exclusion>> exclusionFuture = mock(ListenableFuture.class); when(exclusionAccessor.asyncGetExclusions(expId1.getRawID())).thenReturn(exclusionFuture); List<com.intuit.wasabi.repository.cassandra.pojo.Exclusion> exclusionList = new ArrayList<>(); Experiment.ID exclusionExpId1 = Experiment.ID.newInstance(); com.intuit.wasabi.repository.cassandra.pojo.Exclusion exclusion1 = com.intuit.wasabi.repository.cassandra.pojo.Exclusion.builder().base(expId1.getRawID()).pair(exclusionExpId1.getRawID()).build(); exclusionList.add(exclusion1); Result<com.intuit.wasabi.repository.cassandra.pojo.Exclusion> exclusionResult = mock(Result.class); when(exclusionResult.all()).thenReturn(exclusionList); when(exclusionFuture.get()).thenReturn(exclusionResult); repository.populateAssignmentsMetadata(userID, appName, context, experimentBatch, allowAssignmentsOptional, appPriorities, experimentMap, bucketMap, exclusionMap); assertThat(appPriorities.getPrioritizedExperiments().size(), is(1)); assertThat(appPriorities.getPrioritizedExperiments().get(0).getID(), is(expId1)); assertThat(experimentMap.get(expId1) != null, is(true)); assertThat(bucketMap.size(), is(1)); assertThat(exclusionMap.size(), is(1)); assertThat(exclusionMap.get(expId1).get(0).getRawID(), is(exclusion1.getPair())); }
@Override @Timed public void populateAssignmentsMetadata(User.ID userID, Application.Name appName, Context context, ExperimentBatch experimentBatch, Optional<Map<Experiment.ID, Boolean>> allowAssignments, PrioritizedExperimentList prioritizedExperimentList, Map<Experiment.ID, com.intuit.wasabi.experimentobjects.Experiment> experimentMap, Map<Experiment.ID, BucketList> bucketMap, Map<Experiment.ID, List<Experiment.ID>> exclusionMap ) { if (LOGGER.isDebugEnabled()) LOGGER.debug("populateExperimentMetadata - STARTED: userID={}, appName={}, context={}, experimentBatch={}, experimentIds={}", userID, appName, context, experimentBatch, allowAssignments); if (isNull(experimentBatch.getLabels()) && !allowAssignments.isPresent()) { LOGGER.error("Invalid input to CassandraAssignmentsRepository.populateExperimentMetadata(): Given input: userID={}, appName={}, context={}, experimentBatch={}, allowAssignments={}", userID, appName, context, experimentBatch, allowAssignments); return; } populateExperimentApplicationAndUserAssignments(userID, appName, context, prioritizedExperimentList, experimentMap); Set<Experiment.ID> experimentIds = allowAssignments.isPresent() ? allowAssignments.get().keySet() : new HashSet<>(); populateExperimentIdsAndExperimentBatch(allowAssignments, experimentMap, experimentBatch, experimentIds); populateBucketsAndExclusions(experimentIds, bucketMap, exclusionMap); if (LOGGER.isDebugEnabled()) LOGGER.debug("populateExperimentMetadata - FINISHED..."); }
CassandraAssignmentsRepository implements AssignmentsRepository { @Override @Timed public void populateAssignmentsMetadata(User.ID userID, Application.Name appName, Context context, ExperimentBatch experimentBatch, Optional<Map<Experiment.ID, Boolean>> allowAssignments, PrioritizedExperimentList prioritizedExperimentList, Map<Experiment.ID, com.intuit.wasabi.experimentobjects.Experiment> experimentMap, Map<Experiment.ID, BucketList> bucketMap, Map<Experiment.ID, List<Experiment.ID>> exclusionMap ) { if (LOGGER.isDebugEnabled()) LOGGER.debug("populateExperimentMetadata - STARTED: userID={}, appName={}, context={}, experimentBatch={}, experimentIds={}", userID, appName, context, experimentBatch, allowAssignments); if (isNull(experimentBatch.getLabels()) && !allowAssignments.isPresent()) { LOGGER.error("Invalid input to CassandraAssignmentsRepository.populateExperimentMetadata(): Given input: userID={}, appName={}, context={}, experimentBatch={}, allowAssignments={}", userID, appName, context, experimentBatch, allowAssignments); return; } populateExperimentApplicationAndUserAssignments(userID, appName, context, prioritizedExperimentList, experimentMap); Set<Experiment.ID> experimentIds = allowAssignments.isPresent() ? allowAssignments.get().keySet() : new HashSet<>(); populateExperimentIdsAndExperimentBatch(allowAssignments, experimentMap, experimentBatch, experimentIds); populateBucketsAndExclusions(experimentIds, bucketMap, exclusionMap); if (LOGGER.isDebugEnabled()) LOGGER.debug("populateExperimentMetadata - FINISHED..."); } }
CassandraAssignmentsRepository implements AssignmentsRepository { @Override @Timed public void populateAssignmentsMetadata(User.ID userID, Application.Name appName, Context context, ExperimentBatch experimentBatch, Optional<Map<Experiment.ID, Boolean>> allowAssignments, PrioritizedExperimentList prioritizedExperimentList, Map<Experiment.ID, com.intuit.wasabi.experimentobjects.Experiment> experimentMap, Map<Experiment.ID, BucketList> bucketMap, Map<Experiment.ID, List<Experiment.ID>> exclusionMap ) { if (LOGGER.isDebugEnabled()) LOGGER.debug("populateExperimentMetadata - STARTED: userID={}, appName={}, context={}, experimentBatch={}, experimentIds={}", userID, appName, context, experimentBatch, allowAssignments); if (isNull(experimentBatch.getLabels()) && !allowAssignments.isPresent()) { LOGGER.error("Invalid input to CassandraAssignmentsRepository.populateExperimentMetadata(): Given input: userID={}, appName={}, context={}, experimentBatch={}, allowAssignments={}", userID, appName, context, experimentBatch, allowAssignments); return; } populateExperimentApplicationAndUserAssignments(userID, appName, context, prioritizedExperimentList, experimentMap); Set<Experiment.ID> experimentIds = allowAssignments.isPresent() ? allowAssignments.get().keySet() : new HashSet<>(); populateExperimentIdsAndExperimentBatch(allowAssignments, experimentMap, experimentBatch, experimentIds); populateBucketsAndExclusions(experimentIds, bucketMap, exclusionMap); if (LOGGER.isDebugEnabled()) LOGGER.debug("populateExperimentMetadata - FINISHED..."); } @Inject  CassandraAssignmentsRepository(
            @CassandraRepository ExperimentRepository experimentRepository,
            @DatabaseRepository ExperimentRepository dbRepository,
            EventLog eventLog,
            ExperimentAccessor experimentAccessor,
            ExperimentUserIndexAccessor experimentUserIndexAccessor,

            UserAssignmentExportAccessor userAssignmentExportAccessor,

            BucketAccessor bucketAccessor,
            BucketAssignmentCountAccessor bucketAssignmentCountAccessor,

            StagingAccessor stagingAccessor,
            PrioritiesAccessor prioritiesAccessor,
            ExclusionAccessor exclusionAccessor,
            PageExperimentIndexAccessor pageExperimentIndexAccessor,
            CassandraDriver driver,
            MappingManager mappingManager,
            @Named("AssignmentsCountThreadPoolExecutor") ThreadPoolExecutor assignmentsCountExecutor,
            final @Named("assign.user.to.export") boolean assignUserToExport,
            final @Named("assign.bucket.count") boolean assignBucketCount,
            final @Named("default.time.format") String defaultTimeFormat); }
CassandraAssignmentsRepository implements AssignmentsRepository { @Override @Timed public void populateAssignmentsMetadata(User.ID userID, Application.Name appName, Context context, ExperimentBatch experimentBatch, Optional<Map<Experiment.ID, Boolean>> allowAssignments, PrioritizedExperimentList prioritizedExperimentList, Map<Experiment.ID, com.intuit.wasabi.experimentobjects.Experiment> experimentMap, Map<Experiment.ID, BucketList> bucketMap, Map<Experiment.ID, List<Experiment.ID>> exclusionMap ) { if (LOGGER.isDebugEnabled()) LOGGER.debug("populateExperimentMetadata - STARTED: userID={}, appName={}, context={}, experimentBatch={}, experimentIds={}", userID, appName, context, experimentBatch, allowAssignments); if (isNull(experimentBatch.getLabels()) && !allowAssignments.isPresent()) { LOGGER.error("Invalid input to CassandraAssignmentsRepository.populateExperimentMetadata(): Given input: userID={}, appName={}, context={}, experimentBatch={}, allowAssignments={}", userID, appName, context, experimentBatch, allowAssignments); return; } populateExperimentApplicationAndUserAssignments(userID, appName, context, prioritizedExperimentList, experimentMap); Set<Experiment.ID> experimentIds = allowAssignments.isPresent() ? allowAssignments.get().keySet() : new HashSet<>(); populateExperimentIdsAndExperimentBatch(allowAssignments, experimentMap, experimentBatch, experimentIds); populateBucketsAndExclusions(experimentIds, bucketMap, exclusionMap); if (LOGGER.isDebugEnabled()) LOGGER.debug("populateExperimentMetadata - FINISHED..."); } @Inject  CassandraAssignmentsRepository(
            @CassandraRepository ExperimentRepository experimentRepository,
            @DatabaseRepository ExperimentRepository dbRepository,
            EventLog eventLog,
            ExperimentAccessor experimentAccessor,
            ExperimentUserIndexAccessor experimentUserIndexAccessor,

            UserAssignmentExportAccessor userAssignmentExportAccessor,

            BucketAccessor bucketAccessor,
            BucketAssignmentCountAccessor bucketAssignmentCountAccessor,

            StagingAccessor stagingAccessor,
            PrioritiesAccessor prioritiesAccessor,
            ExclusionAccessor exclusionAccessor,
            PageExperimentIndexAccessor pageExperimentIndexAccessor,
            CassandraDriver driver,
            MappingManager mappingManager,
            @Named("AssignmentsCountThreadPoolExecutor") ThreadPoolExecutor assignmentsCountExecutor,
            final @Named("assign.user.to.export") boolean assignUserToExport,
            final @Named("assign.bucket.count") boolean assignBucketCount,
            final @Named("default.time.format") String defaultTimeFormat); @Override @Timed void populateAssignmentsMetadata(User.ID userID, Application.Name appName, Context context, ExperimentBatch experimentBatch, Optional<Map<Experiment.ID, Boolean>> allowAssignments,
                                            PrioritizedExperimentList prioritizedExperimentList,
                                            Map<Experiment.ID, com.intuit.wasabi.experimentobjects.Experiment> experimentMap,
                                            Map<Experiment.ID, BucketList> bucketMap,
                                            Map<Experiment.ID, List<Experiment.ID>> exclusionMap
    ); @Override @Timed List<Pair<Experiment, String>> getAssignments(User.ID userID,
                                                         Application.Name appLabel,
                                                         Context context,
                                                         Map<Experiment.ID, Experiment> experimentMap); @Override @Timed Assignment getAssignment(User.ID userID, Application.Name appName, Experiment.ID experimentID, Context context); @Override @Timed void assignUsersInBatch(List<Pair<Experiment, Assignment>> assignments, Date date); @Override void assignUserToExports(Assignment assignment, Date date); @Override void deleteAssignment(Experiment experiment, User.ID userID, Context context, Application.Name appName, Assignment currentAssignment); @Override StreamingOutput getAssignmentStream(Experiment.ID experimentID, Context context, Parameters parameters, Boolean ignoreNullBucket); @Override @Timed void pushAssignmentToStaging(String type, String exception, String data); void pushAssignmentsToStaging(String type, String exception, Collection<String> data); Map<UUID, String> getBatchPayloadsFromStaging(int batchSize); void deleteFromStaging(UUID timeUUID); @Override void updateBucketAssignmentCount(Experiment experiment, Assignment assignment, boolean countUp); @Override AssignmentCounts getBucketAssignmentCount(Experiment experiment); @Override Map<Experiment.ID, AssignmentCounts> getBucketAssignmentCountsInParallel(List<Experiment.ID> experimentIds); }
CassandraAssignmentsRepository implements AssignmentsRepository { @Override @Timed public void populateAssignmentsMetadata(User.ID userID, Application.Name appName, Context context, ExperimentBatch experimentBatch, Optional<Map<Experiment.ID, Boolean>> allowAssignments, PrioritizedExperimentList prioritizedExperimentList, Map<Experiment.ID, com.intuit.wasabi.experimentobjects.Experiment> experimentMap, Map<Experiment.ID, BucketList> bucketMap, Map<Experiment.ID, List<Experiment.ID>> exclusionMap ) { if (LOGGER.isDebugEnabled()) LOGGER.debug("populateExperimentMetadata - STARTED: userID={}, appName={}, context={}, experimentBatch={}, experimentIds={}", userID, appName, context, experimentBatch, allowAssignments); if (isNull(experimentBatch.getLabels()) && !allowAssignments.isPresent()) { LOGGER.error("Invalid input to CassandraAssignmentsRepository.populateExperimentMetadata(): Given input: userID={}, appName={}, context={}, experimentBatch={}, allowAssignments={}", userID, appName, context, experimentBatch, allowAssignments); return; } populateExperimentApplicationAndUserAssignments(userID, appName, context, prioritizedExperimentList, experimentMap); Set<Experiment.ID> experimentIds = allowAssignments.isPresent() ? allowAssignments.get().keySet() : new HashSet<>(); populateExperimentIdsAndExperimentBatch(allowAssignments, experimentMap, experimentBatch, experimentIds); populateBucketsAndExclusions(experimentIds, bucketMap, exclusionMap); if (LOGGER.isDebugEnabled()) LOGGER.debug("populateExperimentMetadata - FINISHED..."); } @Inject  CassandraAssignmentsRepository(
            @CassandraRepository ExperimentRepository experimentRepository,
            @DatabaseRepository ExperimentRepository dbRepository,
            EventLog eventLog,
            ExperimentAccessor experimentAccessor,
            ExperimentUserIndexAccessor experimentUserIndexAccessor,

            UserAssignmentExportAccessor userAssignmentExportAccessor,

            BucketAccessor bucketAccessor,
            BucketAssignmentCountAccessor bucketAssignmentCountAccessor,

            StagingAccessor stagingAccessor,
            PrioritiesAccessor prioritiesAccessor,
            ExclusionAccessor exclusionAccessor,
            PageExperimentIndexAccessor pageExperimentIndexAccessor,
            CassandraDriver driver,
            MappingManager mappingManager,
            @Named("AssignmentsCountThreadPoolExecutor") ThreadPoolExecutor assignmentsCountExecutor,
            final @Named("assign.user.to.export") boolean assignUserToExport,
            final @Named("assign.bucket.count") boolean assignBucketCount,
            final @Named("default.time.format") String defaultTimeFormat); @Override @Timed void populateAssignmentsMetadata(User.ID userID, Application.Name appName, Context context, ExperimentBatch experimentBatch, Optional<Map<Experiment.ID, Boolean>> allowAssignments,
                                            PrioritizedExperimentList prioritizedExperimentList,
                                            Map<Experiment.ID, com.intuit.wasabi.experimentobjects.Experiment> experimentMap,
                                            Map<Experiment.ID, BucketList> bucketMap,
                                            Map<Experiment.ID, List<Experiment.ID>> exclusionMap
    ); @Override @Timed List<Pair<Experiment, String>> getAssignments(User.ID userID,
                                                         Application.Name appLabel,
                                                         Context context,
                                                         Map<Experiment.ID, Experiment> experimentMap); @Override @Timed Assignment getAssignment(User.ID userID, Application.Name appName, Experiment.ID experimentID, Context context); @Override @Timed void assignUsersInBatch(List<Pair<Experiment, Assignment>> assignments, Date date); @Override void assignUserToExports(Assignment assignment, Date date); @Override void deleteAssignment(Experiment experiment, User.ID userID, Context context, Application.Name appName, Assignment currentAssignment); @Override StreamingOutput getAssignmentStream(Experiment.ID experimentID, Context context, Parameters parameters, Boolean ignoreNullBucket); @Override @Timed void pushAssignmentToStaging(String type, String exception, String data); void pushAssignmentsToStaging(String type, String exception, Collection<String> data); Map<UUID, String> getBatchPayloadsFromStaging(int batchSize); void deleteFromStaging(UUID timeUUID); @Override void updateBucketAssignmentCount(Experiment experiment, Assignment assignment, boolean countUp); @Override AssignmentCounts getBucketAssignmentCount(Experiment experiment); @Override Map<Experiment.ID, AssignmentCounts> getBucketAssignmentCountsInParallel(List<Experiment.ID> experimentIds); static final Bucket.Label NULL_LABEL; }