Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Tests for algo field and bugfix #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2017
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
5 changes: 3 additions & 2 deletions splitio/hashfns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from __future__ import absolute_import, division, print_function, \
unicode_literals

from splitio.splits import HashAlgorithm
from splitio.hashfns import legacy

try:
Expand All @@ -23,8 +24,8 @@ def _murmur_hash(key, seed):


_HASH_ALGORITHMS = {
'legacy': legacy.legacy_hash,
'murmur': _murmur_hash
HashAlgorithm.LEGACY: legacy.legacy_hash,
HashAlgorithm.MURMUR: _murmur_hash
}


Expand Down
18 changes: 11 additions & 7 deletions splitio/redis_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def missing_redis_dependencies(*args, **kwargs):
from splitio.matchers import UserDefinedSegmentMatcher
from splitio.metrics import BUCKETS
from splitio.segments import Segment
from splitio.splits import Split, SplitParser, HashAlgorithm
from splitio.splits import Split, SplitParser
from splitio.impressions import Impression
from splitio.utils import bytes_to_string

Expand Down Expand Up @@ -202,7 +202,6 @@ def add_split(self, split_name, split):
def get_split(self, split_name):

to_decode = self._redis.get(self._get_split_key(split_name))

if to_decode is None:
return None

Expand Down Expand Up @@ -665,9 +664,12 @@ def _parse_matcher_in_segment(self, partial_split, matcher, block_until_ready=Fa


class RedisSplit(Split):
def __init__(self, name, seed, killed, default_treatment, traffic_type_name, status, change_number, conditions=None, segment_cache=None, algo=HashAlgorithm.LEGACY):
"""A split implementation that mantains a reference to the segment cache so segments can
be easily pickled and unpickled.
def __init__(self, name, seed, killed, default_treatment, traffic_type_name,
status, change_number, conditions=None, segment_cache=None,
algo=None):
'''
A split implementation that mantains a reference to the segment cache
so segments can be easily pickled and unpickled.
:param name: Name of the feature
:type name: unicode
:param seed: Seed
Expand All @@ -680,8 +682,10 @@ def __init__(self, name, seed, killed, default_treatment, traffic_type_name, sta
:type conditions: list
:param segment_cache: A segment cache
:type segment_cache: SegmentCache
"""
super(RedisSplit, self).__init__(name, seed, killed, default_treatment, traffic_type_name, status, change_number, conditions)
'''
super(RedisSplit, self).__init__(name, seed, killed, default_treatment,
traffic_type_name, status,
change_number, conditions, algo)
self._segment_cache = segment_cache

@property
Expand Down
9 changes: 4 additions & 5 deletions splitio/splits.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ class HashAlgorithm(Enum):
"""
Hash algorithm names
"""
LEGACY = "legacy"
MURMUR = "murmur"
LEGACY = 1
MURMUR = 2


class Split(object):
def __init__(self, name, seed, killed, default_treatment, traffic_type_name,
status, change_number, conditions=None,
algo=HashAlgorithm.LEGACY):
status, change_number, conditions=None, algo=None):
"""
A class that represents a split. It associates a feature name with a set
of matchers (responsible of telling which condition to use) and
Expand All @@ -65,7 +64,7 @@ def __init__(self, name, seed, killed, default_treatment, traffic_type_name,
self._status = status
self._change_number = change_number
self._conditions = conditions if conditions is not None else []
self._algo = algo
self._algo = HashAlgorithm(algo) if algo else HashAlgorithm.LEGACY

@property
def name(self):
Expand Down
203 changes: 203 additions & 0 deletions splitio/tests/algoSplits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
{
"splits": [
{
"orgId": null,
"environment": null,
"trafficTypeId": null,
"trafficTypeName": null,
"name": "some_feature_1",
"changeNumber":1325599980,
"algo": 1,
"seed": -1222652054,
"status": "ACTIVE",
"killed": false,
"defaultTreatment": "off",
"conditions": [
{
"matcherGroup": {
"combiner": "AND",
"matchers": [
{
"matcherType": "WHITELIST",
"negate": false,
"userDefinedSegmentMatcherData": null,
"whitelistMatcherData": {
"whitelist": [
"whitelisted_user"
]
}
}
]
},
"partitions": [
{
"treatment": "on",
"size": 100
}
]
},
{
"matcherGroup": {
"combiner": "AND",
"matchers": [
{
"matcherType": "ALL_KEYS",
"negate": false,
"userDefinedSegmentMatcherData": null,
"whitelistMatcherData": null
}
]
},
"partitions": [
{
"treatment": "on",
"size": 0
},
{
"treatment": "off",
"size": 100
}
]
}
]
},
{
"orgId": null,
"environment": null,
"trafficTypeId": null,
"trafficTypeName": null,
"name": "some_feature_2",
"algo": 2,
"changeNumber":1325599980,
"seed": 1699838640,
"status": "ACTIVE",
"killed": false,
"defaultTreatment": "off",
"conditions": [
{
"matcherGroup": {
"combiner": "AND",
"matchers": [
{
"matcherType": "ALL_KEYS",
"negate": false,
"userDefinedSegmentMatcherData": null,
"whitelistMatcherData": null
}
]
},
"partitions": [
{
"treatment": "on",
"size": 100
},
{
"treatment": "off",
"size": 0
}
]
}
]
},
{
"orgId": null,
"environment": null,
"trafficTypeId": null,
"trafficTypeName": null,
"name": "some_feature_3",
"algo": null,
"changeNumber":1325599980,
"seed": -480091424,
"status": "ACTIVE",
"killed": true,
"defaultTreatment": "defTreatment",
"conditions": [
{
"matcherGroup": {
"combiner": "AND",
"matchers": [
{
"matcherType": "ALL_KEYS",
"negate": false,
"userDefinedSegmentMatcherData": null,
"whitelistMatcherData": null
}
]
},
"partitions": [
{
"treatment": "defTreatment",
"size": 100
},
{
"treatment": "off",
"size": 0
}
]
}
]
},
{
"orgId": null,
"environment": null,
"trafficTypeId": null,
"trafficTypeName": null,
"name": "some_feature_4",
"seed": 1548363147,
"changeNumber":1325599980,
"status": "ACTIVE",
"killed": false,
"defaultTreatment": "off",
"conditions": [
{
"matcherGroup": {
"combiner": "AND",
"matchers": [
{
"matcherType": "IN_SEGMENT",
"negate": false,
"userDefinedSegmentMatcherData": {
"segmentName": "employees"
},
"whitelistMatcherData": null
}
]
},
"partitions": [
{
"treatment": "on",
"size": 100
}
]
},
{
"matcherGroup": {
"combiner": "AND",
"matchers": [
{
"matcherType": "IN_SEGMENT",
"negate": false,
"userDefinedSegmentMatcherData": {
"segmentName": "human_beigns"
},
"whitelistMatcherData": null
}
]
},
"partitions": [
{
"treatment": "on",
"size": 30
},
{
"treatment": "off",
"size": 70
}
]
}
]
}
],
"since": -1,
"till": 1457726098069
}
Loading