Skip to content

Commit babc4b8

Browse files
[FSSDK-11177] decision service update
1 parent 19c70cc commit babc4b8

File tree

5 files changed

+7
-40
lines changed

5 files changed

+7
-40
lines changed

OptimizelySDK.Tests/CmabTests/DecisionServiceCmabTest.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,7 @@ private Experiment CreateCmabExperiment(string id, string key, int trafficAlloca
629629
Status = "Running",
630630
TrafficAllocation = new TrafficAllocation[0],
631631
ForcedVariations = new Dictionary<string, string>(), // UserIdToKeyVariations is an alias for this
632-
Cmab = new Entity.Cmab(attributeIds ?? new List<string>())
633-
{
634-
TrafficAllocation = trafficAllocation
635-
}
632+
Cmab = new Entity.Cmab(attributeIds ?? new List<string>(), trafficAllocation)
636633
};
637634
}
638635

OptimizelySDK.Tests/CmabTests/DefaultCmabServiceTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ private static Experiment CreateExperiment(string ruleId, List<string> attribute
649649
return new Experiment
650650
{
651651
Id = ruleId,
652-
Cmab = attributeIds == null ? null : new Entity.Cmab(attributeIds),
652+
Cmab = attributeIds == null ? null : new Entity.Cmab(attributeIds, 10000),
653653
};
654654
}
655655

OptimizelySDK.Tests/CmabTests/OptimizelyUserContextCmabTest.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,8 @@ private void ConfigureCmabExperiment(ProjectConfig config,
517517

518518
Assert.IsNotNull(experiment, $"Experiment {experimentKey} should exist for CMAB tests.");
519519

520-
experiment.Cmab = new Entity.Cmab(attributeList)
521-
{
522-
TrafficAllocation = trafficAllocation
523-
};
524-
520+
experiment.Cmab = new Entity.Cmab(attributeList, trafficAllocation);
521+
525522
config.ExperimentIdMap[experiment.Id] = experiment;
526523
if (config.ExperimentKeyMap.ContainsKey(experiment.Key))
527524
{

OptimizelySDK/Bucketing/DecisionService.cs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -312,23 +312,13 @@ OptimizelyDecideOption[] options
312312
var reasons = new DecisionReasons();
313313
var userId = user.GetUserId();
314314

315-
// Check if CMAB is properly configured
316-
if (experiment.Cmab == null)
317-
{
318-
var message = string.Format(CmabConstants.CMAB_EXPERIMENT_NOT_PROPERLY_CONFIGURED,
319-
experiment.Key);
320-
Logger.Log(LogLevel.ERROR, reasons.AddInfo(message));
321-
return Result<VariationDecisionResult>.NewResult(
322-
new VariationDecisionResult(null, null, true), reasons);
323-
}
324-
325315
// Create dummy traffic allocation for CMAB
326316
var cmabTrafficAllocation = new List<TrafficAllocation>
327317
{
328318
new TrafficAllocation
329319
{
330320
EntityId = "$",
331-
EndOfRange = experiment.Cmab.TrafficAllocation ?? 0,
321+
EndOfRange = experiment.Cmab.TrafficAllocation,
332322
},
333323
};
334324

@@ -347,27 +337,10 @@ OptimizelyDecideOption[] options
347337
new VariationDecisionResult(null), reasons);
348338
}
349339

350-
// User is in CMAB traffic allocation, fetch decision from CMAB service
351-
if (CmabService == null)
352-
{
353-
var message = "CMAB service is not initialized.";
354-
Logger.Log(LogLevel.ERROR, reasons.AddInfo(message));
355-
return Result<VariationDecisionResult>.NewResult(
356-
new VariationDecisionResult(null, null, true), reasons);
357-
}
358-
359340
try
360341
{
361342
var cmabDecision = CmabService.GetDecision(config, user, experiment.Id, options);
362343

363-
if (cmabDecision == null || string.IsNullOrEmpty(cmabDecision.VariationId))
364-
{
365-
var message = string.Format(CmabConstants.CMAB_FETCH_FAILED, experiment.Key);
366-
Logger.Log(LogLevel.ERROR, reasons.AddInfo(message));
367-
return Result<VariationDecisionResult>.NewResult(
368-
new VariationDecisionResult(null, null, true), reasons);
369-
}
370-
371344
// Get the variation from the project config
372345
var variation = config.GetVariationFromIdByExperimentId(experiment.Id,
373346
cmabDecision.VariationId);

OptimizelySDK/Entity/Cmab.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public class Cmab
3636
/// Determines what portion of traffic should be allocated to CMAB decision making.
3737
/// </summary>
3838
[JsonProperty("trafficAllocation")]
39-
public int? TrafficAllocation { get; set; }
39+
public int TrafficAllocation { get; set; }
4040

4141
/// <summary>
4242
/// Initializes a new instance of the Cmab class with specified values.
4343
/// </summary>
4444
/// <param name="attributeIds">List of attribute IDs for CMAB</param>
4545
/// <param name="trafficAllocation">Traffic allocation value</param>
46-
public Cmab(List<string> attributeIds, int? trafficAllocation = null)
46+
public Cmab(List<string> attributeIds, int trafficAllocation)
4747
{
4848
AttributeIds = attributeIds ?? new List<string>();
4949
TrafficAllocation = trafficAllocation;

0 commit comments

Comments
 (0)