@Test public void createAssignmentObjectTest() throws IOException { Date date = new Date(); SegmentationProfile segmentationProfile = null; User.ID userID = User.ID.valueOf("test-user-1"); Context context = Context.valueOf("TEST"); boolean selectBucket = true; Experiment exp1 = Experiment.withID(Experiment.ID.valueOf(UUID.randomUUID())) .withApplicationName(Application.Name.valueOf("test-app-1")) .withLabel(Experiment.Label.valueOf("test-exp-1")) .withState(Experiment.State.RUNNING) .withIsPersonalizationEnabled(false) .build(); BucketList bucketList1 = new BucketList(); bucketList1.addBucket(Bucket.newInstance(exp1.getID(), Bucket.Label.valueOf("bucket-1")).withAllocationPercent(0.9d).withPayload("bucket1").withState(Bucket.State.OPEN).build()); bucketList1.addBucket(Bucket.newInstance(exp1.getID(), Bucket.Label.valueOf("bucket-2")).withAllocationPercent(0.1d).withPayload("bucket-2").withState(Bucket.State.OPEN).build()); when(assignmentDecorator.getBucketList(exp1, userID, segmentationProfile)).thenReturn(bucketList1); when(metadataCache.getExperimentById(exp1.getID())).thenReturn(Optional.of(exp1)); Assignment newAssignment = assignmentsImpl.createAssignmentObject(exp1, userID, context, selectBucket, bucketList1, date, segmentationProfile); assertTrue(newAssignment != null); assertTrue(newAssignment.getStatus().equals(Assignment.Status.NEW_ASSIGNMENT)); }
protected Assignment createAssignmentObject(Experiment experiment, User.ID userID, Context context, boolean selectBucket, BucketList bucketList, Date date, SegmentationProfile segmentationProfile) { Assignment.Builder builder = Assignment.newInstance(experiment.getID()) .withExperimentLabel(getExperimentLabel(experiment.getID())) .withApplicationName(experiment.getApplicationName()) .withUserID(userID) .withContext(context); if (selectBucket) { Bucket assignedBucket; BucketList bucketsExternal = getBucketList(experiment, userID, segmentationProfile, !Objects.isNull(bucketList) ); if (Objects.isNull(bucketsExternal) || bucketsExternal.getBuckets().isEmpty()) { assignedBucket = selectBucket(bucketList.getBuckets()); } else { assignedBucket = selectBucket(bucketsExternal.getBuckets()); } if (!Objects.isNull(assignedBucket)) { builder.withBucketLabel(assignedBucket.getLabel()); builder.withPayload(getBucketPayload(experiment.getID(), nonNull(assignedBucket.getLabel()) ? assignedBucket.getLabel().toString() : null)); } else { return nullAssignment(userID, experiment.getApplicationName(), experiment.getID(), Assignment.Status.NO_OPEN_BUCKETS); } } else { builder.withBucketLabel(null); } Assignment result = builder .withStatus(Assignment.Status.NEW_ASSIGNMENT) .withCreated(Optional.ofNullable(date).orElseGet(Date::new)) .withCacheable(false) .build(); LOGGER.debug("result => {}", result); return result; }
AssignmentsImpl implements Assignments { protected Assignment createAssignmentObject(Experiment experiment, User.ID userID, Context context, boolean selectBucket, BucketList bucketList, Date date, SegmentationProfile segmentationProfile) { Assignment.Builder builder = Assignment.newInstance(experiment.getID()) .withExperimentLabel(getExperimentLabel(experiment.getID())) .withApplicationName(experiment.getApplicationName()) .withUserID(userID) .withContext(context); if (selectBucket) { Bucket assignedBucket; BucketList bucketsExternal = getBucketList(experiment, userID, segmentationProfile, !Objects.isNull(bucketList) ); if (Objects.isNull(bucketsExternal) || bucketsExternal.getBuckets().isEmpty()) { assignedBucket = selectBucket(bucketList.getBuckets()); } else { assignedBucket = selectBucket(bucketsExternal.getBuckets()); } if (!Objects.isNull(assignedBucket)) { builder.withBucketLabel(assignedBucket.getLabel()); builder.withPayload(getBucketPayload(experiment.getID(), nonNull(assignedBucket.getLabel()) ? assignedBucket.getLabel().toString() : null)); } else { return nullAssignment(userID, experiment.getApplicationName(), experiment.getID(), Assignment.Status.NO_OPEN_BUCKETS); } } else { builder.withBucketLabel(null); } Assignment result = builder .withStatus(Assignment.Status.NEW_ASSIGNMENT) .withCreated(Optional.ofNullable(date).orElseGet(Date::new)) .withCacheable(false) .build(); LOGGER.debug("result => {}", result); return result; } }
AssignmentsImpl implements Assignments { protected Assignment createAssignmentObject(Experiment experiment, User.ID userID, Context context, boolean selectBucket, BucketList bucketList, Date date, SegmentationProfile segmentationProfile) { Assignment.Builder builder = Assignment.newInstance(experiment.getID()) .withExperimentLabel(getExperimentLabel(experiment.getID())) .withApplicationName(experiment.getApplicationName()) .withUserID(userID) .withContext(context); if (selectBucket) { Bucket assignedBucket; BucketList bucketsExternal = getBucketList(experiment, userID, segmentationProfile, !Objects.isNull(bucketList) ); if (Objects.isNull(bucketsExternal) || bucketsExternal.getBuckets().isEmpty()) { assignedBucket = selectBucket(bucketList.getBuckets()); } else { assignedBucket = selectBucket(bucketsExternal.getBuckets()); } if (!Objects.isNull(assignedBucket)) { builder.withBucketLabel(assignedBucket.getLabel()); builder.withPayload(getBucketPayload(experiment.getID(), nonNull(assignedBucket.getLabel()) ? assignedBucket.getLabel().toString() : null)); } else { return nullAssignment(userID, experiment.getApplicationName(), experiment.getID(), Assignment.Status.NO_OPEN_BUCKETS); } } else { builder.withBucketLabel(null); } Assignment result = builder .withStatus(Assignment.Status.NEW_ASSIGNMENT) .withCreated(Optional.ofNullable(date).orElseGet(Date::new)) .withCacheable(false) .build(); LOGGER.debug("result => {}", result); 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 Assignment createAssignmentObject(Experiment experiment, User.ID userID, Context context, boolean selectBucket, BucketList bucketList, Date date, SegmentationProfile segmentationProfile) { Assignment.Builder builder = Assignment.newInstance(experiment.getID()) .withExperimentLabel(getExperimentLabel(experiment.getID())) .withApplicationName(experiment.getApplicationName()) .withUserID(userID) .withContext(context); if (selectBucket) { Bucket assignedBucket; BucketList bucketsExternal = getBucketList(experiment, userID, segmentationProfile, !Objects.isNull(bucketList) ); if (Objects.isNull(bucketsExternal) || bucketsExternal.getBuckets().isEmpty()) { assignedBucket = selectBucket(bucketList.getBuckets()); } else { assignedBucket = selectBucket(bucketsExternal.getBuckets()); } if (!Objects.isNull(assignedBucket)) { builder.withBucketLabel(assignedBucket.getLabel()); builder.withPayload(getBucketPayload(experiment.getID(), nonNull(assignedBucket.getLabel()) ? assignedBucket.getLabel().toString() : null)); } else { return nullAssignment(userID, experiment.getApplicationName(), experiment.getID(), Assignment.Status.NO_OPEN_BUCKETS); } } else { builder.withBucketLabel(null); } Assignment result = builder .withStatus(Assignment.Status.NEW_ASSIGNMENT) .withCreated(Optional.ofNullable(date).orElseGet(Date::new)) .withCacheable(false) .build(); LOGGER.debug("result => {}", result); 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 Assignment createAssignmentObject(Experiment experiment, User.ID userID, Context context, boolean selectBucket, BucketList bucketList, Date date, SegmentationProfile segmentationProfile) { Assignment.Builder builder = Assignment.newInstance(experiment.getID()) .withExperimentLabel(getExperimentLabel(experiment.getID())) .withApplicationName(experiment.getApplicationName()) .withUserID(userID) .withContext(context); if (selectBucket) { Bucket assignedBucket; BucketList bucketsExternal = getBucketList(experiment, userID, segmentationProfile, !Objects.isNull(bucketList) ); if (Objects.isNull(bucketsExternal) || bucketsExternal.getBuckets().isEmpty()) { assignedBucket = selectBucket(bucketList.getBuckets()); } else { assignedBucket = selectBucket(bucketsExternal.getBuckets()); } if (!Objects.isNull(assignedBucket)) { builder.withBucketLabel(assignedBucket.getLabel()); builder.withPayload(getBucketPayload(experiment.getID(), nonNull(assignedBucket.getLabel()) ? assignedBucket.getLabel().toString() : null)); } else { return nullAssignment(userID, experiment.getApplicationName(), experiment.getID(), Assignment.Status.NO_OPEN_BUCKETS); } } else { builder.withBucketLabel(null); } Assignment result = builder .withStatus(Assignment.Status.NEW_ASSIGNMENT) .withCreated(Optional.ofNullable(date).orElseGet(Date::new)) .withCacheable(false) .build(); LOGGER.debug("result => {}", result); 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();  }