|
1 | 1 | package io.split.storages.pluggable.adapters; |
2 | 2 |
|
3 | 3 | import com.google.common.collect.Lists; |
| 4 | +import com.google.common.collect.Maps; |
4 | 5 | import io.split.client.dtos.*; |
5 | 6 | import io.split.client.utils.Json; |
6 | 7 | import io.split.engine.ConditionsTestUtil; |
|
16 | 17 | import java.lang.reflect.Field; |
17 | 18 | import java.lang.reflect.Modifier; |
18 | 19 | import java.util.*; |
| 20 | +import java.util.concurrent.ConcurrentMap; |
| 21 | +import java.util.concurrent.atomic.AtomicLong; |
19 | 22 | import java.util.stream.Collectors; |
20 | 23 | import java.util.stream.Stream; |
21 | 24 |
|
22 | 25 | import static io.split.TestHelper.makeRuleBasedSegment; |
| 26 | +import static org.junit.Assert.assertFalse; |
| 27 | +import static org.junit.Assert.assertTrue; |
23 | 28 |
|
24 | 29 | public class UserCustomRuleBasedSegmentAdapterConsumerTest { |
25 | 30 |
|
@@ -66,10 +71,16 @@ public void testGetChangeNumberWithGsonFailing() { |
66 | 71 | public void testGetRuleBasedSegment() { |
67 | 72 | RuleBasedSegmentParser ruleBasedSegmentParser = new RuleBasedSegmentParser(); |
68 | 73 | RuleBasedSegment ruleBasedSegment = getRuleBasedSegment(RULE_BASED_SEGMENT_NAME); |
| 74 | + ParsedRuleBasedSegment expected = ruleBasedSegmentParser.parse(ruleBasedSegment); |
| 75 | + ConcurrentMap<String, ParsedRuleBasedSegment> rbsCollection = Maps.newConcurrentMap(); |
| 76 | + rbsCollection.put(RULE_BASED_SEGMENT_NAME, expected); |
69 | 77 | Mockito.when(_userStorageWrapper.get(PrefixAdapter.buildRuleBasedSegmentKey(RULE_BASED_SEGMENT_NAME))).thenReturn(getRuleBasedSegmentAsJson(ruleBasedSegment)); |
| 78 | + Mockito.when(_userStorageWrapper.getKeysByPrefix("SPLITIO.rbsegment*")).thenReturn(new HashSet<>(Arrays.asList(RULE_BASED_SEGMENT_NAME))); |
70 | 79 | ParsedRuleBasedSegment result = _userCustomRuleBasedSegmentAdapterConsumer.get(RULE_BASED_SEGMENT_NAME); |
71 | | - ParsedRuleBasedSegment expected = ruleBasedSegmentParser.parse(ruleBasedSegment); |
72 | 80 | Assert.assertEquals(expected, result); |
| 81 | + assertTrue(_userCustomRuleBasedSegmentAdapterConsumer.contains(new HashSet<>(Arrays.asList(RULE_BASED_SEGMENT_NAME)))); |
| 82 | + assertFalse(_userCustomRuleBasedSegmentAdapterConsumer.contains(new HashSet<>(Arrays.asList(RULE_BASED_SEGMENT_NAME, "123")))); |
| 83 | + |
73 | 84 | } |
74 | 85 |
|
75 | 86 | @Test |
@@ -135,7 +146,7 @@ public void testGetSegments() { |
135 | 146 | Mockito.when(_userStorageWrapper.getMany(Mockito.anyObject())). |
136 | 147 | thenReturn(getManyExpected); |
137 | 148 | HashSet<String> segmentResult = (HashSet<String>) _userCustomRuleBasedSegmentAdapterConsumer.getSegments(); |
138 | | - Assert.assertTrue(segmentResult.contains("employee")); |
| 149 | + assertTrue(segmentResult.contains("employee")); |
139 | 150 | } |
140 | 151 |
|
141 | 152 | @Test |
|
0 commit comments