class RedisSplitParserTests(TestCase, MockUtilsMixin):
    def setUp(self):
        self.some_matcher = mock.MagicMock()
        self.some_segment_cache = mock.MagicMock()
        self.split_parser = RedisSplitParser(self.some_segment_cache)
        self.redis_split_mock = self.patch('splitio.redis_support.RedisSplit')

        self.some_split = {
            'name': mock.MagicMock(),
            'seed': mock.MagicMock(),
            'killed': mock.MagicMock(),
            'defaultTreatment': mock.MagicMock(),
            'trafficTypeName': mock.MagicMock(),
            'status': mock.MagicMock(),
            'changeNumber': mock.MagicMock(),
            'algo': mock.MagicMock()
        }
        self.some_block_until_ready = mock.MagicMock()
        self.some_partial_split = mock.MagicMock()
        self.some_in_segment_matcher = {
            'matcherType': 'IN_SEGMENT',
            'userDefinedSegmentMatcherData': {
                'segmentName': mock.MagicMock()
            }
        }

    def test_parse_split_returns_redis_split(self):
        """Test that _parse_split returns a RedisSplit"""
        self.assertEqual(
            self.redis_split_mock.return_value,
            self.split_parser._parse_split(
                self.redis_split_mock,
                block_until_ready=self.some_block_until_ready))

    def test_parse_split_calls_redis_split_constructor(self):
        """Test that _parse_split calls RedisSplit constructor"""
        self.split_parser._parse_split(
            self.some_split, block_until_ready=self.some_block_until_ready)
        self.redis_split_mock.assert_called_once_with(
            self.some_split['name'],
            self.some_split['seed'],
            self.some_split['killed'],
            self.some_split['defaultTreatment'],
            self.some_split['trafficTypeName'],
            self.some_split['status'],
            self.some_split['changeNumber'],
            segment_cache=self.some_segment_cache,
            traffic_allocation=self.some_split.get('trafficAllocation'),
            traffic_allocation_seed=self.some_split.get(
                'trafficAllocationSeed'),
            algo=self.some_split['algo'])

    def test_parse_matcher_in_segment_registers_segment(self):
        """Test that _parse_matcher_in_segment registers segment"""
        self.split_parser._parse_matcher_in_segment(
            self.some_partial_split,
            self.some_in_segment_matcher,
            block_until_ready=self.some_block_until_ready)
        self.some_segment_cache.register_segment.assert_called()
Esempio n. 2
0
 def testAlgoHandlers(self):
     '''
     '''
     redis = get_redis({})
     segment_cache = RedisSegmentCache(redis)
     split_parser = RedisSplitParser(segment_cache)
     for sp in self._testData:
         split = split_parser.parse(sp['body'], True)
         self.assertEqual(split.algo, sp['algo'])
         self.assertEqual(get_hash_fn(split.algo), sp['hashfn'])
Esempio n. 3
0
def run(arguments):
    try:
        config = parse_config_file(arguments['<config_file>'])
        redis = get_redis(config)
        split_cache = RedisSplitCache(redis)
        sdk_api = api_factory(config)
        split_change_fetcher = ApiSplitChangeFetcher(sdk_api)
        segment_cache = RedisSegmentCache(redis)
        split_parser = RedisSplitParser(segment_cache)
        update_splits(split_cache, split_change_fetcher, split_parser)
    except:
        logger.exception('Exception caught updating splits')
Esempio n. 4
0
def _update_splits(seconds, config):
    try:
        while True:
            redis = get_redis(config)
            split_cache = RedisSplitCache(redis)
            sdk_api = api_factory(config)
            split_change_fetcher = ApiSplitChangeFetcher(sdk_api)
            segment_cache = RedisSegmentCache(redis)
            split_parser = RedisSplitParser(segment_cache)
            update_splits(split_cache, split_change_fetcher, split_parser)

            time.sleep(seconds)
    except:
        logger.exception('Exception caught updating splits')
    def setUp(self):
        self.some_matcher = mock.MagicMock()
        self.some_segment_cache = mock.MagicMock()
        self.split_parser = RedisSplitParser(self.some_segment_cache)
        self.redis_split_mock = self.patch('splitio.redis_support.RedisSplit')

        self.some_split = {
            'name': mock.MagicMock(),
            'seed': mock.MagicMock(),
            'killed': mock.MagicMock(),
            'defaultTreatment': mock.MagicMock(),
            'trafficTypeName': mock.MagicMock(),
            'status': mock.MagicMock(),
            'changeNumber': mock.MagicMock(),
            'algo': mock.MagicMock()
        }
        self.some_block_until_ready = mock.MagicMock()
        self.some_partial_split = mock.MagicMock()
        self.some_in_segment_matcher = {
            'matcherType': 'IN_SEGMENT',
            'userDefinedSegmentMatcherData': {
                'segmentName': mock.MagicMock()
            }
        }
Esempio n. 6
0
    def setUp(self):
        '''
        '''
        redis = get_redis({})
        segment_cache = RedisSegmentCache(redis)
        split_parser = RedisSplitParser(segment_cache)
        self._client = Client(RedisBroker(redis))

        self._splitObjects = {}

        raw_split = {
            'name':
            'test1',
            'algo':
            1,
            'killed':
            False,
            'status':
            'ACTIVE',
            'defaultTreatment':
            'default',
            'seed':
            -1222652054,
            'orgId':
            None,
            'environment':
            None,
            'trafficTypeId':
            None,
            'trafficTypeName':
            None,
            'changeNumber':
            1,
            'conditions': [{
                'conditionType': 'WHITELIST',
                'matcherGroup': {
                    'combiner':
                    'AND',
                    'matchers': [{
                        'matcherType': 'ALL_KEYS',
                        'negate': False,
                        'userDefinedSegmentMatcherData': None,
                        'whitelistMatcherData': None
                    }]
                },
                'partitions': [{
                    'treatment': 'on',
                    'size': 100
                }],
                'label': 'in segment all'
            }]
        }
        self._splitObjects['whitelist'] = split_parser.parse(raw_split, True)

        raw_split['name'] = 'test2'
        raw_split['conditions'][0]['conditionType'] = 'ROLLOUT'
        self._splitObjects['rollout1'] = split_parser.parse(raw_split, True)

        raw_split['name'] = 'test3'
        raw_split['trafficAllocation'] = 1
        raw_split['trafficAllocationSeed'] = -1
        self._splitObjects['rollout2'] = split_parser.parse(raw_split, True)

        raw_split['name'] = 'test4'
        raw_split['trafficAllocation'] = None  #must be mapped as 100
        raw_split['trafficAllocationSeed'] = -1
        self._splitObjects['rollout3'] = split_parser.parse(raw_split, True)