Skip to content

Commit 2e34128

Browse files
authored
Merge pull request #312 from splitio/remove-legacy-bur
Remove legacy bur
2 parents 5524304 + 904dd5d commit 2e34128

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed

splitio/client/factory.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,15 @@ def _build_localhost_factory(cfg):
553553

554554
sdk_metadata = util.get_metadata(cfg)
555555
ready_event = threading.Event()
556-
synchronizer = LocalhostSynchronizer(synchronizers, tasks)
556+
synchronizer = LocalhostSynchronizer(synchronizers, tasks, localhost_mode)
557557
manager = Manager(ready_event, synchronizer, None, False, sdk_metadata, telemetry_runtime_producer)
558-
initialization_thread = threading.Thread(target=manager.start, name="SDKInitializer", daemon=True)
559-
initialization_thread.start()
558+
559+
# TODO: BUR is only applied for Localhost JSON mode, in future legacy and yaml will also use BUR
560+
if localhost_mode == LocalhostMode.JSON:
561+
initialization_thread = threading.Thread(target=manager.start, name="SDKInitializer", daemon=True)
562+
initialization_thread.start()
563+
else:
564+
manager.start()
560565

561566
recorder = StandardRecorder(
562567
ImpressionsManager(StrategyDebugMode(), telemetry_runtime_producer),

splitio/sync/synchronizer.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
from splitio.api import APIException
99
from splitio.util.backoff import Backoff
10-
from splitio.sync.split import _ON_DEMAND_FETCH_BACKOFF_BASE, _ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES, _ON_DEMAND_FETCH_BACKOFF_MAX_WAIT
11-
10+
from splitio.sync.split import _ON_DEMAND_FETCH_BACKOFF_BASE, _ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES, _ON_DEMAND_FETCH_BACKOFF_MAX_WAIT, LocalhostMode
1211

1312
_LOGGER = logging.getLogger(__name__)
1413
_SYNC_ALL_NO_RETRIES = -1
@@ -492,7 +491,7 @@ def stop_periodic_fetching(self):
492491
class LocalhostSynchronizer(BaseSynchronizer):
493492
"""LocalhostSynchronizer."""
494493

495-
def __init__(self, split_synchronizers, split_tasks):
494+
def __init__(self, split_synchronizers, split_tasks, localhost_mode):
496495
"""
497496
Class constructor.
498497
@@ -503,6 +502,7 @@ def __init__(self, split_synchronizers, split_tasks):
503502
"""
504503
self._split_synchronizers = split_synchronizers
505504
self._split_tasks = split_tasks
505+
self._localhost_mode = localhost_mode
506506
self._backoff = Backoff(
507507
_ON_DEMAND_FETCH_BACKOFF_BASE,
508508
_ON_DEMAND_FETCH_BACKOFF_MAX_WAIT)
@@ -511,6 +511,10 @@ def sync_all(self, till=None):
511511
"""
512512
Synchronize all splits.
513513
"""
514+
# TODO: to be removed when legacy and yaml use BUR
515+
if self._localhost_mode != LocalhostMode.JSON:
516+
return self.synchronize_splits()
517+
514518
self._backoff.reset()
515519
remaining_attempts = _ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES
516520
while remaining_attempts > 0:

splitio/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '9.4.0'
1+
__version__ = '9.4.0-rc2'

tests/integration/test_client_e2e.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,11 +1069,24 @@ def _synchronize_now(self):
10691069
self.factory._sync_manager._synchronizer._split_synchronizers._split_sync.synchronize_splits()
10701070

10711071
def test_incorrect_file_e2e(self):
1072-
factory = get_factory('localhost', config={'splitFile': 'filename'})
1072+
"""Test initialize factory with a incorrect file name."""
1073+
# TODO: secontion below is removed when legacu use BUR
1074+
# legacy and yaml
1075+
exception_raised = False
1076+
factory = None
1077+
try:
1078+
factory = get_factory('localhost', config={'splitFile': 'filename'})
1079+
except Exception as e:
1080+
exception_raised = True
1081+
1082+
assert(exception_raised)
1083+
1084+
# json using BUR
1085+
factory = get_factory('localhost', config={'splitFile': 'filename.json'})
10731086
exception_raised = False
10741087
try:
10751088
factory.block_until_ready(1)
1076-
except TimeoutException as e:
1089+
except Exception as e:
10771090
exception_raised = True
10781091

10791092
assert(exception_raised)
@@ -1082,6 +1095,7 @@ def test_incorrect_file_e2e(self):
10821095
factory.destroy(event)
10831096
event.wait()
10841097

1098+
10851099
def test_localhost_e2e(self):
10861100
"""Instantiate a client with a YAML file and issue get_treatment() calls."""
10871101
filename = os.path.join(os.path.dirname(__file__), 'files', 'file2.yaml')

tests/sync/test_synchronizer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from splitio.tasks.segment_sync import SegmentSynchronizationTask
1010
from splitio.tasks.impressions_sync import ImpressionsSyncTask, ImpressionsCountSyncTask
1111
from splitio.tasks.events_sync import EventsSyncTask
12-
from splitio.sync.split import SplitSynchronizer, LocalSplitSynchronizer
12+
from splitio.sync.split import SplitSynchronizer, LocalSplitSynchronizer, LocalhostMode
1313
from splitio.sync.segment import SegmentSynchronizer, LocalSegmentSynchronizer
1414
from splitio.sync.impression import ImpressionSynchronizer, ImpressionsCountSynchronizer
1515
from splitio.sync.event import EventSynchronizer
@@ -349,7 +349,7 @@ def test_synchronize_splits(self, mocker):
349349
split_sync = LocalSplitSynchronizer(mocker.Mock(), mocker.Mock(), mocker.Mock())
350350
segment_sync = LocalSegmentSynchronizer(mocker.Mock(), mocker.Mock(), mocker.Mock())
351351
synchronizers = SplitSynchronizers(split_sync, segment_sync, None, None, None)
352-
local_synchronizer = LocalhostSynchronizer(synchronizers, mocker.Mock())
352+
local_synchronizer = LocalhostSynchronizer(synchronizers, mocker.Mock(), mocker.Mock())
353353

354354
def synchronize_splits(*args, **kwargs):
355355
return ["segmentA", "segmentB"]
@@ -390,7 +390,7 @@ def segment_task_stop(*args, **kwargs):
390390
self.segment_task_stop_called = True
391391
segment_task.stop = segment_task_stop
392392

393-
local_synchronizer = LocalhostSynchronizer(synchronizers, tasks)
393+
local_synchronizer = LocalhostSynchronizer(synchronizers, tasks, LocalhostMode.JSON)
394394
local_synchronizer.start_periodic_fetching()
395395
assert(self.split_task_start_called)
396396
assert(self.segment_task_start_called)

0 commit comments

Comments
 (0)