|
| 1 | +package io.split.engine.evaluator; |
| 2 | + |
| 3 | +import com.google.common.collect.Lists; |
| 4 | +import io.split.cache.InMemoryCacheImp; |
| 5 | +import io.split.cache.SplitCache; |
| 6 | +import io.split.client.dtos.ConditionType; |
| 7 | +import io.split.client.dtos.MatcherCombiner; |
| 8 | +import io.split.client.dtos.Partition; |
| 9 | +import io.split.engine.experiments.ParsedCondition; |
| 10 | +import io.split.engine.experiments.ParsedSplit; |
| 11 | +import io.split.engine.matchers.AttributeMatcher; |
| 12 | +import io.split.engine.matchers.CombiningMatcher; |
| 13 | +import io.split.engine.matchers.strings.WhitelistMatcher; |
| 14 | +import org.junit.Test; |
| 15 | + |
| 16 | +import java.util.ArrayList; |
| 17 | +import java.util.List; |
| 18 | + |
| 19 | +public class EvaluatorIntegrationTest { |
| 20 | + private static final String DEFAULT_TREATMENT_VALUE = "defaultTreatment"; |
| 21 | + private static final String TRAFFIC_TYPE_VALUE = "tt"; |
| 22 | + private static final String TEST_LABEL_VALUE = "test label"; |
| 23 | + |
| 24 | + @Test |
| 25 | + public void TestTestInMemory() { |
| 26 | + SplitCache splitCache = new InMemoryCacheImp(); |
| 27 | + Evaluator evaluator = new EvaluatorImp(splitCache); |
| 28 | + |
| 29 | + Partition partition = new Partition(); |
| 30 | + partition.treatment = "on"; |
| 31 | + partition.size = 50; |
| 32 | + |
| 33 | + List<Partition> partitions = new ArrayList<>(); |
| 34 | + partitions.add(partition); |
| 35 | + |
| 36 | + AttributeMatcher whitelistAtt = AttributeMatcher.vanilla(new WhitelistMatcher(Lists.newArrayList("test_1", "admin"))); |
| 37 | + CombiningMatcher combiningMatcher = new CombiningMatcher(MatcherCombiner.AND, Lists.newArrayList(whitelistAtt)); |
| 38 | + |
| 39 | + ParsedCondition condition = new ParsedCondition(ConditionType.WHITELIST, combiningMatcher, partitions, TEST_LABEL_VALUE); |
| 40 | + |
| 41 | + List<ParsedCondition> conditions = new ArrayList<>(); |
| 42 | + conditions.add(condition); |
| 43 | + |
| 44 | + splitCache.put(ParsedSplit.createParsedSplitForTests("split_1", 0, false, DEFAULT_TREATMENT_VALUE, conditions, TRAFFIC_TYPE_VALUE, 223366551, 2)); |
| 45 | + splitCache.put(ParsedSplit.createParsedSplitForTests("split_2", 0, true, DEFAULT_TREATMENT_VALUE, conditions, TRAFFIC_TYPE_VALUE, 223366552, 2)); |
| 46 | + splitCache.put(ParsedSplit.createParsedSplitForTests("split_3", 0, false, DEFAULT_TREATMENT_VALUE, conditions, TRAFFIC_TYPE_VALUE, 223366553, 2)); |
| 47 | + |
| 48 | + EvaluatorImp.TreatmentLabelAndChangeNumber result = evaluator.evaluateFeature("test_1", null, "split_3", null); |
| 49 | + EvaluatorImp.TreatmentLabelAndChangeNumber result1 = evaluator.evaluateFeature("test_1", null, "split_3", null); |
| 50 | + EvaluatorImp.TreatmentLabelAndChangeNumber result2 = evaluator.evaluateFeature("test_1", null, "split_3", null); |
| 51 | + EvaluatorImp.TreatmentLabelAndChangeNumber result3 = evaluator.evaluateFeature("test_1", null, "split_3", null); |
| 52 | + } |
| 53 | +} |
0 commit comments