@Test public void testGetDateHourRangeListNoFromAndToDate() { Experiment.ID experimentId = Experiment.ID.valueOf(this.experimentId); Parameters parameters = mock(Parameters.class); Experiment experimentResult = mock(Experiment.class); when(parameters.getFromTime()).thenReturn(null); when(parameters.getToTime()).thenReturn(null); when(experimentResult.getCreationTime()).thenReturn(new Date()); when(experimentRepository.getExperiment(eq(experimentId))).thenReturn(experimentResult); List<Date> result = repository.getDateHourRangeList(experimentId, parameters); assertThat(result.size(), is(1)); }
List<Date> getDateHourRangeList(Experiment.ID experimentID, Parameters parameters) { final Experiment id = experimentRepository.getExperiment(experimentID); if (isNull(id)) { throw new ExperimentNotFoundException(experimentID); } final Optional<Date> from_ts = Optional.ofNullable(parameters.getFromTime()); final Optional<Date> to_ts = Optional.ofNullable(parameters.getToTime()); return getUserAssignmentPartitions( from_ts.orElseGet(id::getCreationTime), to_ts.orElseGet(Date::new) ); }
CassandraAssignmentsRepository implements AssignmentsRepository { List<Date> getDateHourRangeList(Experiment.ID experimentID, Parameters parameters) { final Experiment id = experimentRepository.getExperiment(experimentID); if (isNull(id)) { throw new ExperimentNotFoundException(experimentID); } final Optional<Date> from_ts = Optional.ofNullable(parameters.getFromTime()); final Optional<Date> to_ts = Optional.ofNullable(parameters.getToTime()); return getUserAssignmentPartitions( from_ts.orElseGet(id::getCreationTime), to_ts.orElseGet(Date::new) ); } }
CassandraAssignmentsRepository implements AssignmentsRepository { List<Date> getDateHourRangeList(Experiment.ID experimentID, Parameters parameters) { final Experiment id = experimentRepository.getExperiment(experimentID); if (isNull(id)) { throw new ExperimentNotFoundException(experimentID); } final Optional<Date> from_ts = Optional.ofNullable(parameters.getFromTime()); final Optional<Date> to_ts = Optional.ofNullable(parameters.getToTime()); return getUserAssignmentPartitions( from_ts.orElseGet(id::getCreationTime), to_ts.orElseGet(Date::new) ); } @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 { List<Date> getDateHourRangeList(Experiment.ID experimentID, Parameters parameters) { final Experiment id = experimentRepository.getExperiment(experimentID); if (isNull(id)) { throw new ExperimentNotFoundException(experimentID); } final Optional<Date> from_ts = Optional.ofNullable(parameters.getFromTime()); final Optional<Date> to_ts = Optional.ofNullable(parameters.getToTime()); return getUserAssignmentPartitions( from_ts.orElseGet(id::getCreationTime), to_ts.orElseGet(Date::new) ); } @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 { List<Date> getDateHourRangeList(Experiment.ID experimentID, Parameters parameters) { final Experiment id = experimentRepository.getExperiment(experimentID); if (isNull(id)) { throw new ExperimentNotFoundException(experimentID); } final Optional<Date> from_ts = Optional.ofNullable(parameters.getFromTime()); final Optional<Date> to_ts = Optional.ofNullable(parameters.getToTime()); return getUserAssignmentPartitions( from_ts.orElseGet(id::getCreationTime), to_ts.orElseGet(Date::new) ); } @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; }