|
16 | 16 | */ |
17 | 17 | package com.optimizely.ab.bucketing; |
18 | 18 |
|
| 19 | +import java.util.Collections; |
19 | 20 | import java.util.List; |
20 | 21 |
|
21 | 22 | import javax.annotation.Nonnull; |
@@ -111,8 +112,23 @@ private DecisionResponse<Variation> bucketToVariation(@Nonnull ExperimentCore ex |
111 | 112 | int bucketValue = generateBucketValue(hashCode); |
112 | 113 | logger.debug("Assigned bucket {} to user with bucketingId \"{}\" when bucketing to a variation.", bucketValue, bucketingId); |
113 | 114 |
|
| 115 | + if (experiment instanceof Experiment && ((Experiment) experiment).getCmab() != null) { |
| 116 | + // Override traffic allocations for CMAB experiments |
| 117 | + String message = reasons.addInfo("Using CMAB traffic allocation for experiment \"%s\"", experimentKey); |
| 118 | + logger.info(message); |
| 119 | + trafficAllocations = Collections.singletonList( |
| 120 | + new TrafficAllocation("$", ((Experiment) experiment).getCmab().getTrafficAllocation()) |
| 121 | + ); |
| 122 | + } |
| 123 | + |
114 | 124 | String bucketedVariationId = bucketToEntity(bucketValue, trafficAllocations); |
115 | | - if (bucketedVariationId != null) { |
| 125 | + if ("$".equals(bucketedVariationId)) { |
| 126 | + // for cmab experiments |
| 127 | + String message = reasons.addInfo("User with bucketingId \"%s\" is bucketed into CMAB for experiment \"%s\"", bucketingId, experimentKey); |
| 128 | + logger.info(message); |
| 129 | + return new DecisionResponse(new Variation("$", "$"), reasons); |
| 130 | + } |
| 131 | + else if (bucketedVariationId != null) { |
116 | 132 | Variation bucketedVariation = experiment.getVariationIdToVariationMap().get(bucketedVariationId); |
117 | 133 | String variationKey = bucketedVariation.getKey(); |
118 | 134 | String message = reasons.addInfo("User with bucketingId \"%s\" is in variation \"%s\" of experiment \"%s\".", bucketingId, variationKey, |
|
0 commit comments