Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ public Set<String> getSegments() {

@Override
public boolean contains(Set<String> ruleBasedSegmentNames) {
return getSegments().containsAll(ruleBasedSegmentNames);
return _concurrentMap.keySet().containsAll(ruleBasedSegmentNames);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private List<ParsedRuleBasedSegment> stringsToParsedRuleBasedSegments(List<Strin

@Override
public boolean contains(Set<String> ruleBasedSegmentNames) {
return getSegments().containsAll(ruleBasedSegmentNames);
return _userStorageWrapper.getKeysByPrefix(PrefixAdapter.buildGetAllRuleBasedSegment()).containsAll(ruleBasedSegmentNames);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

public class RuleBasedSegmentCacheInMemoryImplTest extends TestCase {
Expand All @@ -31,6 +33,8 @@ public void testAddAndDeleteSegment(){
ruleBasedSegmentCache.update(Lists.newArrayList(parsedRuleBasedSegment), null, 123);
assertEquals(123, ruleBasedSegmentCache.getChangeNumber());
assertEquals(parsedRuleBasedSegment, ruleBasedSegmentCache.get("sample_rule_based_segment"));
assertTrue(ruleBasedSegmentCache.contains(new HashSet<>(Arrays.asList("sample_rule_based_segment"))));
assertFalse(ruleBasedSegmentCache.contains(new HashSet<>(Arrays.asList("sample_rule_based_segment", "123"))));

ruleBasedSegmentCache.update(null, Lists.newArrayList("sample_rule_based_segment"), 124);
assertEquals(124, ruleBasedSegmentCache.getChangeNumber());
Expand Down Expand Up @@ -62,5 +66,7 @@ public void testMultipleSegment(){
ruleBasedSegmentCache.update(Lists.newArrayList(parsedRuleBasedSegment1, parsedRuleBasedSegment2), null, 123);
assertEquals(Lists.newArrayList("another_rule_based_segment", "sample_rule_based_segment"), ruleBasedSegmentCache.ruleBasedSegmentNames());
assertEquals(Sets.newHashSet("segment2", "segment1", "employees"), ruleBasedSegmentCache.getSegments());
assertTrue(ruleBasedSegmentCache.contains(new HashSet<>(Arrays.asList("sample_rule_based_segment", "another_rule_based_segment"))));
assertTrue(ruleBasedSegmentCache.contains(new HashSet<>(Arrays.asList("sample_rule_based_segment"))));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.split.storages.pluggable.adapters;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import io.split.client.dtos.*;
import io.split.client.utils.Json;
import io.split.engine.ConditionsTestUtil;
Expand All @@ -16,10 +17,14 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static io.split.TestHelper.makeRuleBasedSegment;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class UserCustomRuleBasedSegmentAdapterConsumerTest {

Expand Down Expand Up @@ -66,10 +71,16 @@ public void testGetChangeNumberWithGsonFailing() {
public void testGetRuleBasedSegment() {
RuleBasedSegmentParser ruleBasedSegmentParser = new RuleBasedSegmentParser();
RuleBasedSegment ruleBasedSegment = getRuleBasedSegment(RULE_BASED_SEGMENT_NAME);
ParsedRuleBasedSegment expected = ruleBasedSegmentParser.parse(ruleBasedSegment);
ConcurrentMap<String, ParsedRuleBasedSegment> rbsCollection = Maps.newConcurrentMap();
rbsCollection.put(RULE_BASED_SEGMENT_NAME, expected);
Mockito.when(_userStorageWrapper.get(PrefixAdapter.buildRuleBasedSegmentKey(RULE_BASED_SEGMENT_NAME))).thenReturn(getRuleBasedSegmentAsJson(ruleBasedSegment));
Mockito.when(_userStorageWrapper.getKeysByPrefix("SPLITIO.rbsegment*")).thenReturn(new HashSet<>(Arrays.asList(RULE_BASED_SEGMENT_NAME)));
ParsedRuleBasedSegment result = _userCustomRuleBasedSegmentAdapterConsumer.get(RULE_BASED_SEGMENT_NAME);
ParsedRuleBasedSegment expected = ruleBasedSegmentParser.parse(ruleBasedSegment);
Assert.assertEquals(expected, result);
assertTrue(_userCustomRuleBasedSegmentAdapterConsumer.contains(new HashSet<>(Arrays.asList(RULE_BASED_SEGMENT_NAME))));
assertFalse(_userCustomRuleBasedSegmentAdapterConsumer.contains(new HashSet<>(Arrays.asList(RULE_BASED_SEGMENT_NAME, "123"))));

}

@Test
Expand Down Expand Up @@ -135,7 +146,7 @@ public void testGetSegments() {
Mockito.when(_userStorageWrapper.getMany(Mockito.anyObject())).
thenReturn(getManyExpected);
HashSet<String> segmentResult = (HashSet<String>) _userCustomRuleBasedSegmentAdapterConsumer.getSegments();
Assert.assertTrue(segmentResult.contains("employee"));
assertTrue(segmentResult.contains("employee"));
}

@Test
Expand Down