@@ -3115,6 +3115,118 @@ func TestUnsupportedandSemverMatcherRedis(t *testing.T) {
31153115 }
31163116}
31173117
3118+ var splitRuleBased = & dtos.SplitDTO {
3119+ Algo : 2 ,
3120+ ChangeNumber : 1494593336752 ,
3121+ DefaultTreatment : "off" ,
3122+ Killed : false ,
3123+ Name : "rbsplit" ,
3124+ Seed : - 1992295819 ,
3125+ Status : "ACTIVE" ,
3126+ TrafficAllocation : 100 ,
3127+ TrafficAllocationSeed : - 285565213 ,
3128+ TrafficTypeName : "user" ,
3129+ Configurations : map [string ]string {"on" : "{\" color\" : \" blue\" ,\" size\" : 13}" },
3130+ Conditions : []dtos.ConditionDTO {
3131+ {
3132+ ConditionType : "ROLLOUT" ,
3133+ Label : "default rule" ,
3134+ MatcherGroup : dtos.MatcherGroupDTO {
3135+ Combiner : "AND" ,
3136+ Matchers : []dtos.MatcherDTO {
3137+ {
3138+ KeySelector : & dtos.KeySelectorDTO {
3139+ TrafficType : "user" ,
3140+ },
3141+ MatcherType : "IN_RULE_BASED_SEGMENT" ,
3142+ UserDefinedSegment : & dtos.UserDefinedSegmentMatcherDataDTO {
3143+ SegmentName : "rbsegment1" ,
3144+ },
3145+ Negate : false ,
3146+ },
3147+ },
3148+ },
3149+ Partitions : []dtos.PartitionDTO {
3150+ {
3151+ Size : 100 ,
3152+ Treatment : "on" ,
3153+ },
3154+ {
3155+ Size : 0 ,
3156+ Treatment : "off" ,
3157+ },
3158+ },
3159+ },
3160+ },
3161+ }
3162+
3163+ var rbsegment1 = & dtos.RuleBasedSegmentDTO {
3164+ Name : "rbsegment1" ,
3165+ Conditions : []dtos.RuleBasedConditionDTO {
3166+ {
3167+ MatcherGroup : dtos.MatcherGroupDTO {
3168+ Combiner : "AND" ,
3169+ Matchers : []dtos.MatcherDTO {
3170+ {
3171+ KeySelector : & dtos.KeySelectorDTO {
3172+ TrafficType : "user" ,
3173+ Attribute : & attribute ,
3174+ },
3175+ MatcherType : "EQUAL_TO_SEMVER" ,
3176+ String : & semver ,
3177+ Whitelist : nil ,
3178+ Negate : false ,
3179+ },
3180+ },
3181+ },
3182+ },
3183+ },
3184+ TrafficTypeName : "user" ,
3185+ }
3186+
3187+ func TestRuleBasedSegmentRedis (t * testing.T ) {
3188+ redisConfig := & commonsCfg.RedisConfig {
3189+ Host : "localhost" ,
3190+ Port : 6379 ,
3191+ Password : "" ,
3192+ Prefix : "test-prefix-rulebased" ,
3193+ }
3194+
3195+ prefixedClient , _ := redis .NewRedisClient (redisConfig , logging .NewLogger (& logging.LoggerOptions {}))
3196+ raw , _ := json .Marshal (* splitRuleBased )
3197+ prefixedClient .Set ("SPLITIO.split.rbsplit" , raw , 0 )
3198+ rbraw , _ := json .Marshal (* rbsegment1 )
3199+ prefixedClient .Set ("SPLITIO.rbsegment.rbsegment1" , rbraw , 0 )
3200+
3201+ impTest := & ImpressionListenerTest {}
3202+ cfg := conf .Default ()
3203+ cfg .LabelsEnabled = true
3204+ cfg .Advanced .ImpressionListener = impTest
3205+ cfg .ImpressionsMode = commonsCfg .ImpressionsModeOptimized
3206+ cfg .OperationMode = conf .RedisConsumer
3207+ cfg .Redis = * redisConfig
3208+
3209+ factory , _ := NewSplitFactory ("test" , cfg )
3210+ client := factory .Client ()
3211+ client .BlockUntilReady (2 )
3212+
3213+ // Calls treatments to generate one valid impression
3214+ time .Sleep (300 * time .Millisecond ) // Let's wait until first call of recorders have finished
3215+ attributes := make (map [string ]interface {})
3216+ attributes ["version" ] = "3.4.5"
3217+ evaluation := client .Treatment ("user1" , "rbsplit" , attributes )
3218+ if evaluation != "on" {
3219+ t .Error ("evaluation for rbsplit should be on" )
3220+ }
3221+ client .Destroy ()
3222+
3223+ // Clean redis
3224+ keys , _ := prefixedClient .Keys ("SPLITIO*" )
3225+ for _ , k := range keys {
3226+ prefixedClient .Del (k )
3227+ }
3228+ }
3229+
31183230func TestPrerequisites (t * testing.T ) {
31193231 var isDestroyCalled = false
31203232 var splitsMock , _ = ioutil .ReadFile ("../../testdata/splits_mock_5.json" )
0 commit comments