@Test public void testIndexExperimentToUserEmptyBucket() { Assignment assignment = Assignment.newInstance(Experiment.ID.valueOf(this.experimentId)) .withApplicationName(APPLICATION_NAME) .withContext(Context.valueOf("test")) .withUserID(User.ID.valueOf("testuser1")) .build(); repository.indexExperimentsToUser(assignment); verify(experimentUserIndexAccessor, times(1)) .insertBy(eq(assignment.getUserID().toString()), eq(assignment.getContext().getContext()), eq(APPLICATION_NAME.toString()), eq(this.experimentId)); verify(experimentUserIndexAccessor, times(0)) .insertBy(eq(assignment.getUserID().toString()), eq(assignment.getContext().getContext()), eq(APPLICATION_NAME.toString()), eq(this.experimentId), any()); }
private void indexExperimentsToUser(List<Pair<Experiment, Assignment>> assignments) { try { Session session = driver.getSession(); final BatchStatement batchStatement = new BatchStatement(BatchStatement.Type.UNLOGGED); assignments.forEach(pair -> { Assignment assignment = pair.getRight(); LOGGER.debug("assignment={}", assignment); BoundStatement bs; if (isNull(assignment.getBucketLabel())) { bs = experimentUserIndexAccessor.insertBoundStatement(assignment.getUserID().toString(), assignment.getContext().toString(), assignment.getApplicationName().toString(), assignment.getExperimentID().getRawID()); } else { bs = experimentUserIndexAccessor.insertBoundStatement(assignment.getUserID().toString(), assignment.getContext().toString(), assignment.getApplicationName().toString(), assignment.getExperimentID().getRawID(), assignment.getBucketLabel().toString()); } batchStatement.add(bs); }); session.execute(batchStatement); LOGGER.debug("Finished experiment_user_index"); } catch (Exception e) { LOGGER.error("Error occurred while adding data in to experiment_user_index", e); } }
CassandraAssignmentsRepository implements AssignmentsRepository { private void indexExperimentsToUser(List<Pair<Experiment, Assignment>> assignments) { try { Session session = driver.getSession(); final BatchStatement batchStatement = new BatchStatement(BatchStatement.Type.UNLOGGED); assignments.forEach(pair -> { Assignment assignment = pair.getRight(); LOGGER.debug("assignment={}", assignment); BoundStatement bs; if (isNull(assignment.getBucketLabel())) { bs = experimentUserIndexAccessor.insertBoundStatement(assignment.getUserID().toString(), assignment.getContext().toString(), assignment.getApplicationName().toString(), assignment.getExperimentID().getRawID()); } else { bs = experimentUserIndexAccessor.insertBoundStatement(assignment.getUserID().toString(), assignment.getContext().toString(), assignment.getApplicationName().toString(), assignment.getExperimentID().getRawID(), assignment.getBucketLabel().toString()); } batchStatement.add(bs); }); session.execute(batchStatement); LOGGER.debug("Finished experiment_user_index"); } catch (Exception e) { LOGGER.error("Error occurred while adding data in to experiment_user_index", e); } } }
CassandraAssignmentsRepository implements AssignmentsRepository { private void indexExperimentsToUser(List<Pair<Experiment, Assignment>> assignments) { try { Session session = driver.getSession(); final BatchStatement batchStatement = new BatchStatement(BatchStatement.Type.UNLOGGED); assignments.forEach(pair -> { Assignment assignment = pair.getRight(); LOGGER.debug("assignment={}", assignment); BoundStatement bs; if (isNull(assignment.getBucketLabel())) { bs = experimentUserIndexAccessor.insertBoundStatement(assignment.getUserID().toString(), assignment.getContext().toString(), assignment.getApplicationName().toString(), assignment.getExperimentID().getRawID()); } else { bs = experimentUserIndexAccessor.insertBoundStatement(assignment.getUserID().toString(), assignment.getContext().toString(), assignment.getApplicationName().toString(), assignment.getExperimentID().getRawID(), assignment.getBucketLabel().toString()); } batchStatement.add(bs); }); session.execute(batchStatement); LOGGER.debug("Finished experiment_user_index"); } catch (Exception e) { LOGGER.error("Error occurred while adding data in to experiment_user_index", e); } } @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 { private void indexExperimentsToUser(List<Pair<Experiment, Assignment>> assignments) { try { Session session = driver.getSession(); final BatchStatement batchStatement = new BatchStatement(BatchStatement.Type.UNLOGGED); assignments.forEach(pair -> { Assignment assignment = pair.getRight(); LOGGER.debug("assignment={}", assignment); BoundStatement bs; if (isNull(assignment.getBucketLabel())) { bs = experimentUserIndexAccessor.insertBoundStatement(assignment.getUserID().toString(), assignment.getContext().toString(), assignment.getApplicationName().toString(), assignment.getExperimentID().getRawID()); } else { bs = experimentUserIndexAccessor.insertBoundStatement(assignment.getUserID().toString(), assignment.getContext().toString(), assignment.getApplicationName().toString(), assignment.getExperimentID().getRawID(), assignment.getBucketLabel().toString()); } batchStatement.add(bs); }); session.execute(batchStatement); LOGGER.debug("Finished experiment_user_index"); } catch (Exception e) { LOGGER.error("Error occurred while adding data in to experiment_user_index", e); } } @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 { private void indexExperimentsToUser(List<Pair<Experiment, Assignment>> assignments) { try { Session session = driver.getSession(); final BatchStatement batchStatement = new BatchStatement(BatchStatement.Type.UNLOGGED); assignments.forEach(pair -> { Assignment assignment = pair.getRight(); LOGGER.debug("assignment={}", assignment); BoundStatement bs; if (isNull(assignment.getBucketLabel())) { bs = experimentUserIndexAccessor.insertBoundStatement(assignment.getUserID().toString(), assignment.getContext().toString(), assignment.getApplicationName().toString(), assignment.getExperimentID().getRawID()); } else { bs = experimentUserIndexAccessor.insertBoundStatement(assignment.getUserID().toString(), assignment.getContext().toString(), assignment.getApplicationName().toString(), assignment.getExperimentID().getRawID(), assignment.getBucketLabel().toString()); } batchStatement.add(bs); }); session.execute(batchStatement); LOGGER.debug("Finished experiment_user_index"); } catch (Exception e) { LOGGER.error("Error occurred while adding data in to experiment_user_index", e); } } @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; }