@Test public void testUpdateBucketAssignmentCountDown() { Experiment.ID experimentId = Experiment.ID.valueOf(this.experimentId); Experiment mockedExperiment = mock(Experiment.class); when(mockedExperiment.getID()).thenReturn(experimentId); Bucket.Label bucketLabel = Bucket.Label.valueOf("testBucket"); Assignment mockedAssignment = mock(Assignment.class); when(mockedAssignment.getBucketLabel()).thenReturn(bucketLabel); repository.updateBucketAssignmentCount(mockedExperiment, mockedAssignment, false); verify(bucketAssignmentCountAccessor, times(0)) .incrementCountBy(eq(this.experimentId), eq(bucketLabel.toString())); verify(bucketAssignmentCountAccessor, times(1)) .decrementCountBy(eq(this.experimentId), eq(bucketLabel.toString())); }
@Override public void updateBucketAssignmentCount(Experiment experiment, Assignment assignment, boolean countUp) { Optional<Bucket.Label> labelOptional = Optional.ofNullable(assignment.getBucketLabel()); try { if (countUp) { bucketAssignmentCountAccessor.incrementCountBy(experiment.getID().getRawID(), labelOptional.orElseGet(() -> NULL_LABEL).toString() ); } else { bucketAssignmentCountAccessor.decrementCountBy(experiment.getID().getRawID(), labelOptional.orElseGet(() -> NULL_LABEL).toString() ); } } catch (WriteTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException("Could not update the bucket count for experiment " + experiment.getID() + " bucket " + labelOptional.orElseGet(() -> NULL_LABEL).toString(), e); } }
CassandraAssignmentsRepository implements AssignmentsRepository { @Override public void updateBucketAssignmentCount(Experiment experiment, Assignment assignment, boolean countUp) { Optional<Bucket.Label> labelOptional = Optional.ofNullable(assignment.getBucketLabel()); try { if (countUp) { bucketAssignmentCountAccessor.incrementCountBy(experiment.getID().getRawID(), labelOptional.orElseGet(() -> NULL_LABEL).toString() ); } else { bucketAssignmentCountAccessor.decrementCountBy(experiment.getID().getRawID(), labelOptional.orElseGet(() -> NULL_LABEL).toString() ); } } catch (WriteTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException("Could not update the bucket count for experiment " + experiment.getID() + " bucket " + labelOptional.orElseGet(() -> NULL_LABEL).toString(), e); } } }
CassandraAssignmentsRepository implements AssignmentsRepository { @Override public void updateBucketAssignmentCount(Experiment experiment, Assignment assignment, boolean countUp) { Optional<Bucket.Label> labelOptional = Optional.ofNullable(assignment.getBucketLabel()); try { if (countUp) { bucketAssignmentCountAccessor.incrementCountBy(experiment.getID().getRawID(), labelOptional.orElseGet(() -> NULL_LABEL).toString() ); } else { bucketAssignmentCountAccessor.decrementCountBy(experiment.getID().getRawID(), labelOptional.orElseGet(() -> NULL_LABEL).toString() ); } } catch (WriteTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException("Could not update the bucket count for experiment " + experiment.getID() + " bucket " + labelOptional.orElseGet(() -> NULL_LABEL).toString(), 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 { @Override public void updateBucketAssignmentCount(Experiment experiment, Assignment assignment, boolean countUp) { Optional<Bucket.Label> labelOptional = Optional.ofNullable(assignment.getBucketLabel()); try { if (countUp) { bucketAssignmentCountAccessor.incrementCountBy(experiment.getID().getRawID(), labelOptional.orElseGet(() -> NULL_LABEL).toString() ); } else { bucketAssignmentCountAccessor.decrementCountBy(experiment.getID().getRawID(), labelOptional.orElseGet(() -> NULL_LABEL).toString() ); } } catch (WriteTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException("Could not update the bucket count for experiment " + experiment.getID() + " bucket " + labelOptional.orElseGet(() -> NULL_LABEL).toString(), 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 { @Override public void updateBucketAssignmentCount(Experiment experiment, Assignment assignment, boolean countUp) { Optional<Bucket.Label> labelOptional = Optional.ofNullable(assignment.getBucketLabel()); try { if (countUp) { bucketAssignmentCountAccessor.incrementCountBy(experiment.getID().getRawID(), labelOptional.orElseGet(() -> NULL_LABEL).toString() ); } else { bucketAssignmentCountAccessor.decrementCountBy(experiment.getID().getRawID(), labelOptional.orElseGet(() -> NULL_LABEL).toString() ); } } catch (WriteTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException("Could not update the bucket count for experiment " + experiment.getID() + " bucket " + labelOptional.orElseGet(() -> NULL_LABEL).toString(), 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; }