@Test public void testUpdateBucket() { Bucket bucket = mock(Bucket.class, RETURNS_DEEP_STUBS); given(bucket.getLabel()).willReturn(Label.valueOf("l1")); assertThat(bucket.getLabel().toString().trim().isEmpty(), is(not(nullValue()))); when(bucket.getAllocationPercent()).thenReturn(0.5); when(transaction.update(anyString(), Matchers.<Object>anyVararg())).thenReturn(1); when(bucket.isControl()).thenReturn(false); Bucket result = repository.updateBucket(bucket); assertThat(result, is(bucket)); verify(transaction, times(1)).update(anyString(), Matchers.<Object>anyVararg()); when(bucket.isControl()).thenReturn(true); result = repository.updateBucket(bucket); assertThat(result, is(bucket)); verify(transaction, times(3)).update(anyString(), Matchers.<Object>anyVararg()); }
@Override public Bucket updateBucket(Bucket bucket) throws RepositoryException { Preconditions.checkNotNull(bucket, "Parameter \"bucket\" cannot be null"); Preconditions.checkNotNull(bucket.getExperimentID(), "Bucket experiment ID cannot be null"); Preconditions.checkArgument( bucket.getLabel() != null && !bucket.getLabel().toString().trim().isEmpty(), "Bucket external label cannot be null or an empty string"); Preconditions.checkArgument(bucket.getAllocationPercent() >= 0d, "Bucket allocation percentage must be greater than or " + "equal to 0.0"); Preconditions.checkArgument(bucket.getAllocationPercent() <= 1d, "Bucket allocation percentage must be less than or equal to 1.0"); if (bucket.isControl()) { final String SQL = "update bucket set is_control = false where experiment_id=?"; newTransaction().update( SQL, bucket.getExperimentID()); } final String SQL = "update bucket " + "set description = ?, " + " allocation_percent = ?, " + " is_control = ?, " + " payload = ? " + "where experiment_id=? and label=?"; newTransaction().update( SQL, bucket.getDescription() != null ? bucket.getDescription() : "", bucket.getAllocationPercent(), bucket.isControl(), bucket.getPayload() != null ? bucket.getPayload() : "", bucket.getExperimentID(), bucket.getLabel().toString()); return bucket; }
DatabaseExperimentRepository implements ExperimentRepository { @Override public Bucket updateBucket(Bucket bucket) throws RepositoryException { Preconditions.checkNotNull(bucket, "Parameter \"bucket\" cannot be null"); Preconditions.checkNotNull(bucket.getExperimentID(), "Bucket experiment ID cannot be null"); Preconditions.checkArgument( bucket.getLabel() != null && !bucket.getLabel().toString().trim().isEmpty(), "Bucket external label cannot be null or an empty string"); Preconditions.checkArgument(bucket.getAllocationPercent() >= 0d, "Bucket allocation percentage must be greater than or " + "equal to 0.0"); Preconditions.checkArgument(bucket.getAllocationPercent() <= 1d, "Bucket allocation percentage must be less than or equal to 1.0"); if (bucket.isControl()) { final String SQL = "update bucket set is_control = false where experiment_id=?"; newTransaction().update( SQL, bucket.getExperimentID()); } final String SQL = "update bucket " + "set description = ?, " + " allocation_percent = ?, " + " is_control = ?, " + " payload = ? " + "where experiment_id=? and label=?"; newTransaction().update( SQL, bucket.getDescription() != null ? bucket.getDescription() : "", bucket.getAllocationPercent(), bucket.isControl(), bucket.getPayload() != null ? bucket.getPayload() : "", bucket.getExperimentID(), bucket.getLabel().toString()); return bucket; } }
DatabaseExperimentRepository implements ExperimentRepository { @Override public Bucket updateBucket(Bucket bucket) throws RepositoryException { Preconditions.checkNotNull(bucket, "Parameter \"bucket\" cannot be null"); Preconditions.checkNotNull(bucket.getExperimentID(), "Bucket experiment ID cannot be null"); Preconditions.checkArgument( bucket.getLabel() != null && !bucket.getLabel().toString().trim().isEmpty(), "Bucket external label cannot be null or an empty string"); Preconditions.checkArgument(bucket.getAllocationPercent() >= 0d, "Bucket allocation percentage must be greater than or " + "equal to 0.0"); Preconditions.checkArgument(bucket.getAllocationPercent() <= 1d, "Bucket allocation percentage must be less than or equal to 1.0"); if (bucket.isControl()) { final String SQL = "update bucket set is_control = false where experiment_id=?"; newTransaction().update( SQL, bucket.getExperimentID()); } final String SQL = "update bucket " + "set description = ?, " + " allocation_percent = ?, " + " is_control = ?, " + " payload = ? " + "where experiment_id=? and label=?"; newTransaction().update( SQL, bucket.getDescription() != null ? bucket.getDescription() : "", bucket.getAllocationPercent(), bucket.isControl(), bucket.getPayload() != null ? bucket.getPayload() : "", bucket.getExperimentID(), bucket.getLabel().toString()); return bucket; } @Inject  DatabaseExperimentRepository(TransactionFactory transactionFactory, ExperimentValidator validator,
                                        Flyway flyway); }
DatabaseExperimentRepository implements ExperimentRepository { @Override public Bucket updateBucket(Bucket bucket) throws RepositoryException { Preconditions.checkNotNull(bucket, "Parameter \"bucket\" cannot be null"); Preconditions.checkNotNull(bucket.getExperimentID(), "Bucket experiment ID cannot be null"); Preconditions.checkArgument( bucket.getLabel() != null && !bucket.getLabel().toString().trim().isEmpty(), "Bucket external label cannot be null or an empty string"); Preconditions.checkArgument(bucket.getAllocationPercent() >= 0d, "Bucket allocation percentage must be greater than or " + "equal to 0.0"); Preconditions.checkArgument(bucket.getAllocationPercent() <= 1d, "Bucket allocation percentage must be less than or equal to 1.0"); if (bucket.isControl()) { final String SQL = "update bucket set is_control = false where experiment_id=?"; newTransaction().update( SQL, bucket.getExperimentID()); } final String SQL = "update bucket " + "set description = ?, " + " allocation_percent = ?, " + " is_control = ?, " + " payload = ? " + "where experiment_id=? and label=?"; newTransaction().update( SQL, bucket.getDescription() != null ? bucket.getDescription() : "", bucket.getAllocationPercent(), bucket.isControl(), bucket.getPayload() != null ? bucket.getPayload() : "", bucket.getExperimentID(), bucket.getLabel().toString()); return bucket; } @Inject  DatabaseExperimentRepository(TransactionFactory transactionFactory, ExperimentValidator validator,
                                        Flyway flyway); @Override Experiment getExperiment(Experiment.ID experimentID); @Override Map<Application.Name, List<Experiment>> getExperimentsForApps(Collection<Application.Name> appNames); @Override Experiment getExperiment(Application.Name appName,
                                    Experiment.Label experimentLabel); @Override List<Experiment.ID> getExperiments(); @Override ExperimentList getExperiments(Collection<Experiment.ID> experimentIDs); @Override Map<Experiment.ID, Experiment> getExperimentsMap(Collection<Experiment.ID> experimentIDs); @Override Table<Experiment.ID, Experiment.Label, Experiment> getExperimentList(Application.Name appName); @Override List<Application.Name> getApplicationsList(); @Override Experiment.ID createExperiment(NewExperiment newExperiment); @Override Experiment updateExperiment(Experiment experiment); @Override Experiment updateExperimentState(Experiment experiment, State state); @Override Bucket getBucket(Experiment.ID experimentID,
                            Bucket.Label bucketLabel); @Override void createBucket(Bucket newBucket); @Override Bucket updateBucket(Bucket bucket); @Override Bucket updateBucketAllocationPercentage(Bucket bucket, Double desiredAllocationPercentage); @Override Bucket updateBucketState(Bucket bucket, Bucket.State desiredState); @Override BucketList updateBucketBatch(Experiment.ID experimentID, BucketList bucketList); @Override void deleteBucket(Experiment.ID experimentID,
                             Bucket.Label bucketLabel); @Override void logBucketChanges(Experiment.ID experimentID, Bucket.Label bucketLabel,
                                 List<Bucket.BucketAuditInfo> changeList); @Override void logExperimentChanges(Experiment.ID experimentID, List<Experiment.ExperimentAuditInfo> changeList); @Override List<Experiment> getExperiments(Application.Name appName); @Override void deleteExperiment(NewExperiment newExperiment); @Override void createIndicesForNewExperiment(NewExperiment newExperiment); @Override HashMap<Experiment.ID, BucketList> getBucketList(Collection<Experiment.ID> experimentIDCollection); @Override BucketList getBucketList(Experiment.ID experimentID); @Override BucketList getBuckets(Experiment.ID experimentID, boolean checkExperiment); @Override Statement createApplication(Application.Name applicationName); @Override Map<Application.Name, Set<String>> getTagListForApplications(Collection<Application.Name> applicationNames); @Override void updateStateIndex(Experiment experiment); }
DatabaseExperimentRepository implements ExperimentRepository { @Override public Bucket updateBucket(Bucket bucket) throws RepositoryException { Preconditions.checkNotNull(bucket, "Parameter \"bucket\" cannot be null"); Preconditions.checkNotNull(bucket.getExperimentID(), "Bucket experiment ID cannot be null"); Preconditions.checkArgument( bucket.getLabel() != null && !bucket.getLabel().toString().trim().isEmpty(), "Bucket external label cannot be null or an empty string"); Preconditions.checkArgument(bucket.getAllocationPercent() >= 0d, "Bucket allocation percentage must be greater than or " + "equal to 0.0"); Preconditions.checkArgument(bucket.getAllocationPercent() <= 1d, "Bucket allocation percentage must be less than or equal to 1.0"); if (bucket.isControl()) { final String SQL = "update bucket set is_control = false where experiment_id=?"; newTransaction().update( SQL, bucket.getExperimentID()); } final String SQL = "update bucket " + "set description = ?, " + " allocation_percent = ?, " + " is_control = ?, " + " payload = ? " + "where experiment_id=? and label=?"; newTransaction().update( SQL, bucket.getDescription() != null ? bucket.getDescription() : "", bucket.getAllocationPercent(), bucket.isControl(), bucket.getPayload() != null ? bucket.getPayload() : "", bucket.getExperimentID(), bucket.getLabel().toString()); return bucket; } @Inject  DatabaseExperimentRepository(TransactionFactory transactionFactory, ExperimentValidator validator,
                                        Flyway flyway); @Override Experiment getExperiment(Experiment.ID experimentID); @Override Map<Application.Name, List<Experiment>> getExperimentsForApps(Collection<Application.Name> appNames); @Override Experiment getExperiment(Application.Name appName,
                                    Experiment.Label experimentLabel); @Override List<Experiment.ID> getExperiments(); @Override ExperimentList getExperiments(Collection<Experiment.ID> experimentIDs); @Override Map<Experiment.ID, Experiment> getExperimentsMap(Collection<Experiment.ID> experimentIDs); @Override Table<Experiment.ID, Experiment.Label, Experiment> getExperimentList(Application.Name appName); @Override List<Application.Name> getApplicationsList(); @Override Experiment.ID createExperiment(NewExperiment newExperiment); @Override Experiment updateExperiment(Experiment experiment); @Override Experiment updateExperimentState(Experiment experiment, State state); @Override Bucket getBucket(Experiment.ID experimentID,
                            Bucket.Label bucketLabel); @Override void createBucket(Bucket newBucket); @Override Bucket updateBucket(Bucket bucket); @Override Bucket updateBucketAllocationPercentage(Bucket bucket, Double desiredAllocationPercentage); @Override Bucket updateBucketState(Bucket bucket, Bucket.State desiredState); @Override BucketList updateBucketBatch(Experiment.ID experimentID, BucketList bucketList); @Override void deleteBucket(Experiment.ID experimentID,
                             Bucket.Label bucketLabel); @Override void logBucketChanges(Experiment.ID experimentID, Bucket.Label bucketLabel,
                                 List<Bucket.BucketAuditInfo> changeList); @Override void logExperimentChanges(Experiment.ID experimentID, List<Experiment.ExperimentAuditInfo> changeList); @Override List<Experiment> getExperiments(Application.Name appName); @Override void deleteExperiment(NewExperiment newExperiment); @Override void createIndicesForNewExperiment(NewExperiment newExperiment); @Override HashMap<Experiment.ID, BucketList> getBucketList(Collection<Experiment.ID> experimentIDCollection); @Override BucketList getBucketList(Experiment.ID experimentID); @Override BucketList getBuckets(Experiment.ID experimentID, boolean checkExperiment); @Override Statement createApplication(Application.Name applicationName); @Override Map<Application.Name, Set<String>> getTagListForApplications(Collection<Application.Name> applicationNames); @Override void updateStateIndex(Experiment experiment);  }