diff --git a/contract-tests/async_client_entity.py b/contract-tests/async_client_entity.py index 33b4ab63..34fb496a 100644 --- a/contract-tests/async_client_entity.py +++ b/contract-tests/async_client_entity.py @@ -18,11 +18,11 @@ ) from ldclient.config import HTTPConfig from ldclient.feature_store import CacheConfig -from ldclient.impl.datasourcev2.async_polling import ( +from ldclient.impl.datasource.async_polling import ( AsyncFallbackToFDv1PollingDataSourceBuilder, AsyncPollingDataSourceBuilder ) -from ldclient.impl.datasourcev2.async_streaming import ( +from ldclient.impl.datasource.async_streaming import ( AsyncStreamingDataSourceBuilder ) from ldclient.impl.util import Result @@ -83,7 +83,7 @@ async def start(self): datasystem_config = config_params.get('dataSystem') if datasystem_config is not None: - opts["datasystem_config"] = _build_async_data_system(datasystem_config, opts) + opts["data_system"] = _build_async_data_system(datasystem_config, opts) if config_params.get("events") is not None: events = config_params["events"] diff --git a/contract-tests/client_entity.py b/contract-tests/client_entity.py index a4a6b806..681b54a3 100644 --- a/contract-tests/client_entity.py +++ b/contract-tests/client_entity.py @@ -26,7 +26,7 @@ streaming_ds_builder ) from ldclient.feature_store import CacheConfig -from ldclient.impl.datasourcev2.polling import PollingDataSourceBuilder +from ldclient.impl.datasource.polling import PollingDataSourceBuilder from ldclient.integrations import Consul, DynamoDB, Redis from ldclient.interfaces import DataStoreMode @@ -129,7 +129,7 @@ def __init__(self, tag, config): datasystem.data_store(store, store_mode) - opts["datasystem_config"] = datasystem.build() + opts["data_system"] = datasystem.build() if config.get("events") is not None: events = config["events"] diff --git a/docs/api-testing.rst b/docs/api-testing.rst index ce496256..c9faee05 100644 --- a/docs/api-testing.rst +++ b/docs/api-testing.rst @@ -1,12 +1,12 @@ Test fixtures ============= -ldclient.integrations.test_datav2 module ----------------------------------------- +ldclient.integrations.test_data module +-------------------------------------- -The entry point for this feature is :class:`ldclient.integrations.test_datav2.TestDataV2`. +The entry point for this feature is :class:`ldclient.integrations.test_data.TestData`. -.. automodule:: ldclient.integrations.test_datav2 +.. automodule:: ldclient.integrations.test_data :members: :special-members: __init__ :show-inheritance: diff --git a/ldclient/async_client.py b/ldclient/async_client.py index c09893e2..0f5061fc 100644 --- a/ldclient/async_client.py +++ b/ldclient/async_client.py @@ -88,7 +88,7 @@ def __init__(self, config: AsyncConfig): self._config = config self._config._instance_id = str(uuid4()) - self._datasystem_config = config.datasystem_config or async_datasystem.default().build() + self._data_system_config = config.data_system or async_datasystem.default().build() self._lifecycle_lock = asyncio.Lock() self._started = False @@ -218,13 +218,13 @@ async def __start_up(self, start_wait: float): # The data system builds its data sources from builders. Give the shared # session to the builders before the data system starts. if not self._config.offline: - self._wire_data_source_sessions(self._datasystem_config) + self._wire_data_source_sessions(self._data_system_config) if self._config.offline: log.info("Started LaunchDarkly Client in offline mode") - elif _is_daemon_mode(self._datasystem_config): + elif _is_daemon_mode(self._data_system_config): log.info("Started LaunchDarkly Client in daemon mode") - elif _has_no_data_sources(self._datasystem_config): + elif _has_no_data_sources(self._data_system_config): log.warning("The data system has no data sources and no persistent store. All evaluations will return default values.") diagnostic_accumulator = self._set_event_processor(self._config) @@ -237,7 +237,7 @@ async def __start_up(self, start_wait: float): update_processor_ready = AsyncEvent() self._data_system.start(update_processor_ready) - if not self._config.offline and not _is_daemon_mode(self._datasystem_config): + if not self._config.offline and not _is_daemon_mode(self._data_system_config): if start_wait > 60: log.warning(f"Client was configured to block for up to {start_wait} seconds when initializing. We recommend blocking no longer than 60.") @@ -263,16 +263,16 @@ def _get_session(self): def _make_data_system(self) -> AsyncDataSystem: from ldclient.impl.datasystem.async_fdv2 import AsyncFDv2 - return AsyncFDv2(self._config, self._datasystem_config) + return AsyncFDv2(self._config, self._data_system_config) def _wire_data_source_sessions(self, data_system_config) -> None: """Provide the client's aiohttp session to any async data source builders so the sources they build share the client's connection pool.""" - from ldclient.impl.datasourcev2.async_polling import ( + from ldclient.impl.datasource.async_polling import ( AsyncFallbackToFDv1PollingDataSourceBuilder, AsyncPollingDataSourceBuilder ) - from ldclient.impl.datasourcev2.async_streaming import ( + from ldclient.impl.datasource.async_streaming import ( AsyncStreamingDataSourceBuilder ) diff --git a/ldclient/async_config.py b/ldclient/async_config.py index 391c1f80..d8be5628 100644 --- a/ldclient/async_config.py +++ b/ldclient/async_config.py @@ -166,7 +166,7 @@ def __init__( plugins: Optional[List[AsyncPlugin]] = None, enable_event_compression: bool = True, omit_anonymous_contexts: bool = False, - datasystem_config: Optional[AsyncDataSystemConfig] = None, + data_system: Optional[AsyncDataSystemConfig] = None, ): """ :param sdk_key: The SDK key for your LaunchDarkly account. This is always required. @@ -228,7 +228,7 @@ def __init__( set this to False to prevent extra CPU use, because the Relay Proxy decompresses and recompresses the payloads. :param omit_anonymous_contexts: Sets whether anonymous contexts should be omitted from index and identify events. - :param datasystem_config: Configuration for the data system, which controls how the SDK gets flag and + :param data_system: Configuration for the data system, which controls how the SDK gets flag and segment data. Build it with the functions in :mod:`ldclient.async_datasystem`. If it is not set, the SDK uses :func:`ldclient.async_datasystem.default`. """ @@ -263,7 +263,7 @@ def __init__( self.__enable_event_compression = enable_event_compression self.__omit_anonymous_contexts = omit_anonymous_contexts self.__instance_id: Optional[str] = None - self._datasystem_config = datasystem_config + self._data_system = data_system # for internal use only - probably should be part of the client logic def get_default(self, key, default): @@ -416,12 +416,12 @@ def _instance_id(self, value: Optional[str]) -> None: self.__instance_id = value @property - def datasystem_config(self) -> Optional[AsyncDataSystemConfig]: + def data_system(self) -> Optional[AsyncDataSystemConfig]: """ Configuration for the data system, which controls how the SDK gets flag and segment data. """ - return self._datasystem_config + return self._data_system def _validate(self): if self.offline is False and self.sdk_key == '': diff --git a/ldclient/async_datasystem.py b/ldclient/async_datasystem.py index fd4a32cc..c8718399 100644 --- a/ldclient/async_datasystem.py +++ b/ldclient/async_datasystem.py @@ -14,11 +14,11 @@ from ldclient.async_config import AsyncDataSystemConfig from ldclient.config import DataSourceBuilder -from ldclient.impl.datasourcev2.async_polling import ( +from ldclient.impl.datasource.async_polling import ( AsyncFallbackToFDv1PollingDataSourceBuilder, AsyncPollingDataSourceBuilder ) -from ldclient.impl.datasourcev2.async_streaming import ( +from ldclient.impl.datasource.async_streaming import ( AsyncStreamingDataSourceBuilder ) from ldclient.interfaces import ( diff --git a/ldclient/client.py b/ldclient/client.py index 0ca567c3..c9d48dc9 100644 --- a/ldclient/client.py +++ b/ldclient/client.py @@ -89,7 +89,7 @@ def __init__(self, config: Config, start_wait: float = 5): self._config = config self._config._instance_id = str(uuid4()) self._config._validate() - self._datasystem_config = config.datasystem_config or datasystem.default().build() + self._data_system_config = config.data_system or datasystem.default().build() self._event_processor = None self._event_factory_default = EventFactory(False) @@ -166,7 +166,7 @@ def _fork_breaks_client(self) -> bool: """ if self._config.offline: return False - if _is_daemon_mode(self._datasystem_config) and not self._config.send_events: + if _is_daemon_mode(self._data_system_config) and not self._config.send_events: return False return True @@ -177,7 +177,7 @@ def __start_up(self, start_wait: float): self.__hooks_lock = ReadWriteLock() self.__hooks = self._config.hooks + plugin_hooks # type: List[Hook] - self._data_system: DataSystem = FDv2(self._config, self._datasystem_config) + self._data_system: DataSystem = FDv2(self._config, self._data_system_config) self.__flag_tracker = FlagTrackerImpl( self._data_system.flag_change_listeners, @@ -201,9 +201,9 @@ def __start_up(self, start_wait: float): if self._config.offline: log.info("Started LaunchDarkly Client in offline mode") - elif _is_daemon_mode(self._datasystem_config): + elif _is_daemon_mode(self._data_system_config): log.info("Started LaunchDarkly Client in daemon mode") - elif _has_no_data_sources(self._datasystem_config): + elif _has_no_data_sources(self._data_system_config): log.warning("The data system has no data sources and no persistent store. All evaluations will return default values.") diagnostic_accumulator = self._set_event_processor(self._config) @@ -216,7 +216,7 @@ def __start_up(self, start_wait: float): update_processor_ready = threading.Event() self._data_system.start(update_processor_ready) - if not self._config.offline and not _is_daemon_mode(self._datasystem_config): + if not self._config.offline and not _is_daemon_mode(self._data_system_config): if start_wait > 60: log.warning(f"Client was configured to block for up to {start_wait} seconds when initializing. We recommend blocking no longer than 60.") diff --git a/ldclient/config.py b/ldclient/config.py index d19aa7e7..535dbc96 100644 --- a/ldclient/config.py +++ b/ldclient/config.py @@ -309,7 +309,7 @@ def __init__( plugins: Optional[List[Plugin]] = None, enable_event_compression: bool = True, omit_anonymous_contexts: bool = False, - datasystem_config: Optional[DataSystemConfig] = None, + data_system: Optional[DataSystemConfig] = None, ): """ :param sdk_key: The SDK key for your LaunchDarkly account. This is always required. @@ -371,7 +371,7 @@ def __init__( set this to False to prevent extra CPU use, because the Relay Proxy decompresses and recompresses the payloads. :param omit_anonymous_contexts: Sets whether anonymous contexts should be omitted from index and identify events. - :param datasystem_config: Configuration for the data system, which controls how the SDK gets flag and + :param data_system: Configuration for the data system, which controls how the SDK gets flag and segment data. Build it with the functions in :mod:`ldclient.datasystem`. If it is not set, the SDK uses :func:`ldclient.datasystem.default`. """ @@ -406,7 +406,7 @@ def __init__( self.__enable_event_compression = enable_event_compression self.__omit_anonymous_contexts = omit_anonymous_contexts self._instance_id: Optional[str] = None - self._datasystem_config = datasystem_config + self._data_system = data_system def with_wrapper_information(self, wrapper_name: Optional[str], wrapper_version: Optional[str] = None) -> 'Config': """Returns a new ``Config`` instance that is the same as this one, except for having different wrapper information. @@ -570,12 +570,12 @@ def omit_anonymous_contexts(self) -> bool: return self.__omit_anonymous_contexts @property - def datasystem_config(self) -> Optional[DataSystemConfig]: + def data_system(self) -> Optional[DataSystemConfig]: """ Configuration for the data system, which controls how the SDK gets flag and segment data. """ - return self._datasystem_config + return self._data_system def _validate(self): if self.offline is False and self.sdk_key == '': diff --git a/ldclient/datasystem.py b/ldclient/datasystem.py index d3a61a54..f4d10618 100644 --- a/ldclient/datasystem.py +++ b/ldclient/datasystem.py @@ -5,13 +5,13 @@ from typing import List, Optional from ldclient.config import DataSourceBuilder, DataSystemConfig -from ldclient.impl.datasourcev2.polling import ( +from ldclient.impl.datasource.polling import ( FallbackToFDv1PollingDataSourceBuilder, PollingDataSourceBuilder ) -from ldclient.impl.datasourcev2.streaming import StreamingDataSourceBuilder -from ldclient.impl.integrations.files.file_data_sourcev2 import ( - FileDataSourceV2Builder +from ldclient.impl.datasource.streaming import StreamingDataSourceBuilder +from ldclient.impl.integrations.files.file_data_source import ( + FileDataSourceBuilder ) from ldclient.interfaces import ( DataStoreMode, @@ -114,11 +114,11 @@ def streaming_ds_builder() -> StreamingDataSourceBuilder: return StreamingDataSourceBuilder() -def file_ds_builder(paths: List[str]) -> FileDataSourceV2Builder: +def file_ds_builder(paths: List[str]) -> FileDataSourceBuilder: """ Returns a builder for a file-based data source. """ - return FileDataSourceV2Builder(paths) + return FileDataSourceBuilder(paths) def default() -> ConfigBuilder: diff --git a/ldclient/impl/datasourcev2/__init__.py b/ldclient/impl/datasource/__init__.py similarity index 100% rename from ldclient/impl/datasourcev2/__init__.py rename to ldclient/impl/datasource/__init__.py diff --git a/ldclient/impl/datasourcev2/async_polling.py b/ldclient/impl/datasource/async_polling.py similarity index 98% rename from ldclient/impl/datasourcev2/async_polling.py rename to ldclient/impl/datasource/async_polling.py index 5c15b231..32db2ba0 100644 --- a/ldclient/impl/datasourcev2/async_polling.py +++ b/ldclient/impl/datasource/async_polling.py @@ -17,7 +17,7 @@ ) from ldclient.impl.aio.concurrency import AsyncEvent from ldclient.impl.aio.transport import AsyncHTTPTransport -from ldclient.impl.datasourcev2.polling_common import ( +from ldclient.impl.datasource.polling_common import ( FDV1_POLLING_ENDPOINT, PollAction, fdv1_polling_payload_to_changeset, @@ -100,7 +100,7 @@ def __init__( @property def name(self) -> str: """Returns the name of the initializer.""" - return "PollingDataSourceV2" + return "PollingDataSource" async def fetch(self, ss: SelectorStore) -> BasisResult: """ @@ -114,7 +114,7 @@ async def sync(self, ss: SelectorStore) -> AsyncGenerator[Update, None]: Update objects until the connection is closed or an unrecoverable error occurs. """ - log.info("Starting PollingDataSourceV2 synchronizer") + log.info("Starting PollingDataSource synchronizer") self._interrupt_event.clear() self._stop.clear() try: @@ -135,7 +135,7 @@ async def sync(self, ss: SelectorStore) -> AsyncGenerator[Update, None]: async def stop(self): """Signals the synchronizer to stop.""" - log.info("Stopping PollingDataSourceV2 synchronizer") + log.info("Stopping PollingDataSource synchronizer") self._interrupt_event.set() self._stop.set() diff --git a/ldclient/impl/datasourcev2/async_streaming.py b/ldclient/impl/datasource/async_streaming.py similarity index 99% rename from ldclient/impl/datasourcev2/async_streaming.py rename to ldclient/impl/datasource/async_streaming.py index c4fb51a7..5d06f1c2 100644 --- a/ldclient/impl/datasourcev2/async_streaming.py +++ b/ldclient/impl/datasource/async_streaming.py @@ -17,7 +17,7 @@ HTTPConfig ) from ldclient.impl.aio.transport import AsyncSSEFactory, make_client_session -from ldclient.impl.datasourcev2.streaming_common import ( +from ldclient.impl.datasource.streaming_common import ( classify_stream_error, process_message, with_fallback_signal @@ -241,7 +241,7 @@ async def stop(self): """ Stops the streaming synchronizer, closing any open connections. """ - log.info("Stopping StreamingDataSourceV2 synchronizer") + log.info("Stopping StreamingDataSource synchronizer") self._running = False if self._sse: await self._sse.close() diff --git a/ldclient/impl/datasourcev2/polling.py b/ldclient/impl/datasource/polling.py similarity index 98% rename from ldclient/impl/datasourcev2/polling.py rename to ldclient/impl/datasource/polling.py index 897c3c6d..ce9af58f 100644 --- a/ldclient/impl/datasourcev2/polling.py +++ b/ldclient/impl/datasource/polling.py @@ -18,7 +18,7 @@ DataSourceBuilderConfig, HTTPConfig ) -from ldclient.impl.datasourcev2.polling_common import ( +from ldclient.impl.datasource.polling_common import ( FDV1_POLLING_ENDPOINT, PollAction, fdv1_polling_payload_to_changeset, @@ -93,7 +93,7 @@ def __init__( @property def name(self) -> str: """Returns the name of the initializer.""" - return "PollingDataSourceV2" + return "PollingDataSource" def fetch(self, ss: SelectorStore) -> BasisResult: """ @@ -107,7 +107,7 @@ def sync(self, ss: SelectorStore) -> Generator[Update, None, None]: Update objects until the connection is closed or an unrecoverable error occurs. """ - log.info("Starting PollingDataSourceV2 synchronizer") + log.info("Starting PollingDataSource synchronizer") self._interrupt_event.clear() self._stop.clear() while self._stop.is_set() is False: @@ -125,7 +125,7 @@ def sync(self, ss: SelectorStore) -> Generator[Update, None, None]: def stop(self): """Stops the synchronizer.""" - log.info("Stopping PollingDataSourceV2 synchronizer") + log.info("Stopping PollingDataSource synchronizer") self._interrupt_event.set() self._stop.set() diff --git a/ldclient/impl/datasourcev2/polling_common.py b/ldclient/impl/datasource/polling_common.py similarity index 100% rename from ldclient/impl/datasourcev2/polling_common.py rename to ldclient/impl/datasource/polling_common.py diff --git a/ldclient/impl/datasourcev2/streaming.py b/ldclient/impl/datasource/streaming.py similarity index 98% rename from ldclient/impl/datasourcev2/streaming.py rename to ldclient/impl/datasource/streaming.py index 0821973b..7968ff60 100644 --- a/ldclient/impl/datasourcev2/streaming.py +++ b/ldclient/impl/datasource/streaming.py @@ -20,7 +20,7 @@ DataSourceBuilderConfig, HTTPConfig ) -from ldclient.impl.datasourcev2.streaming_common import ( +from ldclient.impl.datasource.streaming_common import ( classify_stream_error, process_message, with_fallback_signal @@ -249,7 +249,7 @@ def stop(self): """ Stops the streaming synchronizer, closing any open connections. """ - log.info("Stopping StreamingDataSourceV2 synchronizer") + log.info("Stopping StreamingDataSource synchronizer") self._running = False if self._sse: self._sse.close() diff --git a/ldclient/impl/datasourcev2/streaming_common.py b/ldclient/impl/datasource/streaming_common.py similarity index 100% rename from ldclient/impl/datasourcev2/streaming_common.py rename to ldclient/impl/datasource/streaming_common.py diff --git a/ldclient/impl/datasystem/async_fdv2.py b/ldclient/impl/datasystem/async_fdv2.py index e4cc51ea..2151ccd3 100644 --- a/ldclient/impl/datasystem/async_fdv2.py +++ b/ldclient/impl/datasystem/async_fdv2.py @@ -289,7 +289,7 @@ async def _commit() -> None: if err is not None: log.error("Failed to reinitialize data store", exc_info=err) - self._runner.spawn("AsyncFDv2-store-recovery", _commit) + self._runner.spawn("ldclient.datasystem.store_recovery", _commit) def start(self, set_on_ready: AsyncEvent): """ @@ -305,7 +305,7 @@ def start(self, set_on_ready: AsyncEvent): self._stop_event.clear() # Start the main coordination loop - self._runner.spawn("AsyncFDv2-main", lambda: self._run_main_loop(set_on_ready)) + self._runner.spawn("ldclient.datasystem.main", lambda: self._run_main_loop(set_on_ready)) async def stop(self): """Stop the AsyncFDv2 data system and all the work it is coordinating.""" @@ -359,7 +359,7 @@ async def _run_main_loop(self, set_on_ready: AsyncEvent): await self._run_synchronizers(set_on_ready) except Exception as e: - log.error("Error in AsyncFDv2 main loop: %s", e) + log.error("Error in data system main loop: %s", e) # Ensure ready event is set even on error if not set_on_ready.is_set(): set_on_ready.set() @@ -442,7 +442,7 @@ async def _run_synchronizers(self, set_on_ready: AsyncEvent): return self._runner.spawn( - "AsyncFDv2-synchronizers", + "ldclient.datasystem.synchronizers", lambda: self._synchronizer_loop(set_on_ready), ) @@ -539,7 +539,7 @@ async def _consume_synchronizer_results( action_queue: AsyncQueue = AsyncQueue() state_age = _StateAgeTracker() timer = AsyncRepeatingTask.at_interval( - label="AsyncFDv2-sync-cond-timer", + label="ldclient.datasystem.sync_condition", interval=10, initial_delay=10, callable=lambda: action_queue.put("check") @@ -556,7 +556,7 @@ async def reader(): try: timer.start() - sync_reader = spawn_handle("AsyncFDv2-sync-reader", reader) + sync_reader = spawn_handle("ldclient.datasystem.sync_reader", reader) while True: # Honor a stop request every iteration so a queue that always has diff --git a/ldclient/impl/datasystem/fdv2.py b/ldclient/impl/datasystem/fdv2.py index ec2b0b92..f0025d96 100644 --- a/ldclient/impl/datasystem/fdv2.py +++ b/ldclient/impl/datasystem/fdv2.py @@ -284,7 +284,7 @@ def start(self, set_on_ready: Event): main_thread = Thread( target=self._run_main_loop, args=(set_on_ready,), - name="FDv2-main", + name="ldclient.datasystem.main", daemon=True ) main_thread.start() @@ -346,7 +346,7 @@ def _run_main_loop(self, set_on_ready: Event): self._run_synchronizers(set_on_ready) except Exception as e: - log.error("Error in FDv2 main loop: %s", e) + log.error("Error in data system main loop: %s", e) # Ensure ready event is set even on error if not set_on_ready.is_set(): set_on_ready.set() @@ -511,7 +511,7 @@ def synchronizer_loop(self: 'FDv2'): sync_thread = Thread( target=synchronizer_loop, - name="FDv2-synchronizers", + name="ldclient.datasystem.synchronizers", args=(self,), daemon=True ) @@ -532,7 +532,7 @@ def _consume_synchronizer_results( action_queue: Queue = Queue() state_age = _StateAgeTracker() timer = RepeatingTask.at_interval( - label="FDv2-sync-cond-timer", + label="ldclient.datasystem.sync_condition", interval=10, initial_delay=10, callable=lambda: action_queue.put("check") @@ -547,7 +547,7 @@ def reader(self: 'FDv2'): sync_reader = Thread( target=reader, - name="FDv2-sync-reader", + name="ldclient.datasystem.sync_reader", args=(self,), daemon=True ) diff --git a/ldclient/impl/events/diagnostics.py b/ldclient/impl/events/diagnostics.py index 914f028c..7a0beab9 100644 --- a/ldclient/impl/events/diagnostics.py +++ b/ldclient/impl/events/diagnostics.py @@ -89,7 +89,7 @@ def _create_diagnostic_platform_object(): def _persistent_store(config): - datasystem_config = config.datasystem_config + datasystem_config = config.data_system return datasystem_config.data_store if datasystem_config is not None else None diff --git a/ldclient/impl/integrations/files/file_data_sourcev2.py b/ldclient/impl/integrations/files/file_data_source.py similarity index 95% rename from ldclient/impl/integrations/files/file_data_sourcev2.py rename to ldclient/impl/integrations/files/file_data_source.py index 032fc3fb..069baaf4 100644 --- a/ldclient/impl/integrations/files/file_data_sourcev2.py +++ b/ldclient/impl/integrations/files/file_data_source.py @@ -46,7 +46,7 @@ def _sanitize_json_item(item): item["version"] = 1 -class _FileDataSourceV2: +class _FileDataSource: """ Internal implementation of both Initializer and Synchronizer protocols for file-based data. @@ -79,7 +79,7 @@ def __init__(self, paths, poll_interval: float = 1, force_polling=False): @property def name(self) -> str: """Return the name of this data source.""" - return "FileDataV2" + return "FileData" def fetch(self, ss: SelectorStore) -> BasisResult: """ @@ -93,7 +93,7 @@ def fetch(self, ss: SelectorStore) -> BasisResult: try: with self._lock: if self._closed: - return _Fail("FileDataV2 source has been closed") + return _Fail("FileData source has been closed") # Load all files and build changeset result = self._load_all_to_changeset() @@ -311,9 +311,9 @@ def _start_auto_updater(self): ) if have_watchdog and not self._force_polling: - return _WatchdogAutoUpdaterV2(resolved_paths, self._on_file_change) + return _WatchdogAutoUpdater(resolved_paths, self._on_file_change) else: - return _PollingAutoUpdaterV2( + return _PollingAutoUpdater( resolved_paths, self._on_file_change, self._poll_interval ) @@ -367,7 +367,7 @@ def _on_file_change(self): # Watch for changes to data files using the watchdog package. This uses native OS filesystem notifications # if available for the current platform. -class _WatchdogAutoUpdaterV2: +class _WatchdogAutoUpdater: def __init__(self, resolved_paths, on_change_callback): watched_files = set(resolved_paths) @@ -393,7 +393,7 @@ def stop(self): # Watch for changes to data files by polling their modification times. This is used if auto-update is # on but the watchdog package is not installed. -class _PollingAutoUpdaterV2: +class _PollingAutoUpdater: def __init__(self, resolved_paths, on_change_callback, interval): self._paths = resolved_paths self._on_change = on_change_callback @@ -433,7 +433,7 @@ def _check_file_times(self): return ret -class FileDataSourceV2Builder(DataSourceBuilder): # pylint: disable=too-few-public-methods +class FileDataSourceBuilder(DataSourceBuilder): # pylint: disable=too-few-public-methods DEFAULT_POLL_INTERVAL = 1 def __init__(self, paths: str | list[str]): @@ -441,17 +441,17 @@ def __init__(self, paths: str | list[str]): self.__poll_interval: Optional[float] = None self.__force_polling = False - def poll_interval(self, interval: float) -> 'FileDataSourceV2Builder': + def poll_interval(self, interval: float) -> 'FileDataSourceBuilder': self.__poll_interval = interval return self - def force_polling(self, force: bool) -> 'FileDataSourceV2Builder': + def force_polling(self, force: bool) -> 'FileDataSourceBuilder': self.__force_polling = force return self - def build(self, config: DataSourceBuilderConfig) -> _FileDataSourceV2: # pylint: disable=unused-argument - """Builds the FileDataSourceV2 instance.""" - return _FileDataSourceV2( + def build(self, config: DataSourceBuilderConfig) -> _FileDataSource: # pylint: disable=unused-argument + """Builds the FileDataSource instance.""" + return _FileDataSource( self.__paths, self.__poll_interval or self.DEFAULT_POLL_INTERVAL, self.__force_polling diff --git a/ldclient/impl/integrations/test_datav2/__init__.py b/ldclient/impl/integrations/test_data/__init__.py similarity index 100% rename from ldclient/impl/integrations/test_datav2/__init__.py rename to ldclient/impl/integrations/test_data/__init__.py diff --git a/ldclient/impl/integrations/test_datav2/async_test_data_sourcev2.py b/ldclient/impl/integrations/test_data/async_test_data_source.py similarity index 93% rename from ldclient/impl/integrations/test_datav2/async_test_data_sourcev2.py rename to ldclient/impl/integrations/test_data/async_test_data_source.py index 569c82dd..85bfc211 100644 --- a/ldclient/impl/integrations/test_datav2/async_test_data_sourcev2.py +++ b/ldclient/impl/integrations/test_data/async_test_data_source.py @@ -17,11 +17,11 @@ ) -class _AsyncTestDataSourceV2: +class _AsyncTestDataSource: """ - Async implementation of both the Initializer and Synchronizer protocols for TestDataV2. + Async implementation of both the Initializer and Synchronizer protocols for TestData. - The async twin of :class:`_TestDataSourceV2`: it shares the same TestDataV2 flag + The async twin of :class:`_TestDataSource`: it shares the same TestData flag management but exposes ``async`` ``fetch``/``sync``/``stop`` and delivers updates through an :class:`asyncio.Queue` so it can drive the async data system. """ @@ -40,7 +40,7 @@ def __init__(self, test_data): @property def name(self) -> str: """Return the name of this data source.""" - return "TestDataV2" + return "TestData" async def fetch(self, ss: SelectorStore) -> BasisResult: """Implementation of the AsyncInitializer.fetch method.""" @@ -86,7 +86,7 @@ async def stop(self): def _enqueue(self, item) -> None: """Put an item on the update queue safely from any thread. - Flag updates can arrive on any thread (TestDataV2.update may be called + Flag updates can arrive on any thread (TestData.update may be called from user code), but an asyncio.Queue must only be touched from its own event loop. So schedule the put on the loop captured when sync() started. Before sync() runs there is no consumer and no loop to cross into, so put @@ -102,7 +102,7 @@ def _enqueue(self, item) -> None: pass def upsert_flag(self, flag_data: dict): - """Called by TestDataV2 when a flag is updated; queues the change for + """Called by TestData when a flag is updated; queues the change for delivery through the sync() generator.""" if self._closed: return @@ -142,7 +142,7 @@ def _make_basis(self) -> BasisResult: fetch() and the initial yield of sync().""" try: if self._closed: - return _Fail("TestDataV2 source has been closed") + return _Fail("TestData source has been closed") init_data = self._test_data._make_init_data() version = self._test_data._get_version() diff --git a/ldclient/impl/integrations/test_datav2/test_data_sourcev2.py b/ldclient/impl/integrations/test_data/test_data_source.py similarity index 95% rename from ldclient/impl/integrations/test_datav2/test_data_sourcev2.py rename to ldclient/impl/integrations/test_data/test_data_source.py index 5e5b90d6..b92c4032 100644 --- a/ldclient/impl/integrations/test_datav2/test_data_sourcev2.py +++ b/ldclient/impl/integrations/test_data/test_data_source.py @@ -18,11 +18,11 @@ ) -class _TestDataSourceV2: +class _TestDataSource: """ - Internal implementation of both Initializer and Synchronizer protocols for TestDataV2. + Internal implementation of both Initializer and Synchronizer protocols for TestData. - This component bridges the test data management in TestDataV2 with the FDv2 protocol + This component bridges the test data management in TestData with the FDv2 protocol interfaces. Each instance implements both Initializer and Synchronizer protocols and receives change notifications for dynamic updates. """ @@ -45,7 +45,7 @@ def __init__(self, test_data): @property def name(self) -> str: """Return the name of this data source.""" - return "TestDataV2" + return "TestData" def fetch(self, ss: SelectorStore) -> BasisResult: """ @@ -56,7 +56,7 @@ def fetch(self, ss: SelectorStore) -> BasisResult: try: with self._lock: if self._closed: - return _Fail("TestDataV2 source has been closed") + return _Fail("TestData source has been closed") # Get all current flags from test data init_data = self._test_data._make_init_data() @@ -148,7 +148,7 @@ def stop(self): def upsert_flag(self, flag_data: dict): """ - Called by TestDataV2 when a flag is updated. + Called by TestData when a flag is updated. This method converts the flag update into an FDv2 changeset and queues it for delivery through the sync() generator. diff --git a/ldclient/integrations/__init__.py b/ldclient/integrations/__init__.py index 71ee0f93..51166ba9 100644 --- a/ldclient/integrations/__init__.py +++ b/ldclient/integrations/__init__.py @@ -18,8 +18,8 @@ from ldclient.impl.integrations.dynamodb.dynamodb_feature_store import ( _DynamoDBFeatureStoreCore ) -from ldclient.impl.integrations.files.file_data_sourcev2 import ( - FileDataSourceV2Builder +from ldclient.impl.integrations.files.file_data_source import ( + FileDataSourceBuilder ) from ldclient.impl.integrations.redis.redis_big_segment_store import ( _RedisBigSegmentStore @@ -47,14 +47,14 @@ def new_feature_store( To use this method, you must first install the ``python-consul`` package. Then, pass the object returned by this method to :func:`ldclient.datasystem.persistent_store`, or to :func:`ldclient.datasystem.daemon` if another process keeps the store up to date, and set the - result as the ``datasystem_config`` of your client configuration (:class:`ldclient.config.Config`). + result as the ``data_system`` of your client configuration (:class:`ldclient.config.Config`). :: from ldclient import datasystem from ldclient.config import Config from ldclient.integrations import Consul store = Consul.new_feature_store() - config = Config('sdk-key', datasystem_config=datasystem.persistent_store(store).build()) + config = Config('sdk-key', data_system=datasystem.persistent_store(store).build()) :param host: hostname of the Consul server (uses ``localhost`` if omitted) :param port: port of the Consul server (uses 8500 if omitted) @@ -64,10 +64,8 @@ def new_feature_store( `python-consul API `_ :param caching: specifies whether local caching should be enabled and if so, sets the cache properties; defaults to :func:`ldclient.feature_store.CacheConfig.default()`. - When the SDK is configured to use FDv2 (by setting ``datasystem_config`` - on :class:`ldclient.config.Config`), the cache is automatically disabled - once the in-memory store has been initialized, so these settings only - affect the brief bootstrap window. See :class:`ldclient.feature_store.CacheConfig`. + The SDK disables the cache once the in-memory store has been initialized, + so these settings only affect the brief bootstrap window. See :class:`ldclient.feature_store.CacheConfig`. """ core = _ConsulFeatureStoreCore(host, port, prefix, consul_opts) return CachingStoreWrapper(core, caching) @@ -86,14 +84,14 @@ def new_feature_store(table_name: str, prefix: Optional[str] = None, dynamodb_op Then, pass the object returned by this method to :func:`ldclient.datasystem.persistent_store`, or to :func:`ldclient.datasystem.daemon` if another process keeps the store up to date, and set the - result as the ``datasystem_config`` of your client configuration (:class:`ldclient.config.Config`). + result as the ``data_system`` of your client configuration (:class:`ldclient.config.Config`). :: from ldclient import datasystem from ldclient.config import Config from ldclient.integrations import DynamoDB store = DynamoDB.new_feature_store("my-table-name") - config = Config('sdk-key', datasystem_config=datasystem.persistent_store(store).build()) + config = Config('sdk-key', data_system=datasystem.persistent_store(store).build()) Note that the DynamoDB table must already exist; the LaunchDarkly SDK does not create the table automatically, because it has no way of knowing what additional properties (such as permissions @@ -110,10 +108,8 @@ def new_feature_store(table_name: str, prefix: Optional[str] = None, dynamodb_op the `boto3 API `_ :param caching: specifies whether local caching should be enabled and if so, sets the cache properties; defaults to :func:`ldclient.feature_store.CacheConfig.default()`. - When the SDK is configured to use FDv2 (by setting ``datasystem_config`` - on :class:`ldclient.config.Config`), the cache is automatically disabled - once the in-memory store has been initialized, so these settings only - affect the brief bootstrap window. See :class:`ldclient.feature_store.CacheConfig`. + The SDK disables the cache once the in-memory store has been initialized, + so these settings only affect the brief bootstrap window. See :class:`ldclient.feature_store.CacheConfig`. """ core = _DynamoDBFeatureStoreCore(table_name, prefix, dynamodb_opts) return CachingStoreWrapper(core, caching) @@ -168,7 +164,7 @@ def async_feature_store(table_name: str, prefix: Optional[str] = None, dynamodb_ To use this method, you must first install the ``aioboto3`` package. Then, pass the object returned by this method to :func:`ldclient.async_datasystem.persistent_store`, or to :func:`ldclient.async_datasystem.daemon` if another process keeps the store up to date, and set - the result as the ``datasystem_config`` of your client configuration + the result as the ``data_system`` of your client configuration (:class:`ldclient.async_config.AsyncConfig`). :: @@ -176,7 +172,7 @@ def async_feature_store(table_name: str, prefix: Optional[str] = None, dynamodb_ from ldclient.async_config import AsyncConfig from ldclient.integrations import DynamoDB store = DynamoDB.async_feature_store("my-table-name") - config = AsyncConfig('sdk-key', datasystem_config=async_datasystem.persistent_store(store).build()) + config = AsyncConfig('sdk-key', data_system=async_datasystem.persistent_store(store).build()) The data layout matches :func:`new_feature_store`, so an async and a synchronous SDK can share one DynamoDB table. @@ -229,14 +225,14 @@ def new_feature_store( To use this method, you must first install the ``redis`` package. Then, pass the object returned by this method to :func:`ldclient.datasystem.persistent_store`, or to :func:`ldclient.datasystem.daemon` if another process keeps the store up to date, and set the - result as the ``datasystem_config`` of your client configuration (:class:`ldclient.config.Config`). + result as the ``data_system`` of your client configuration (:class:`ldclient.config.Config`). :: from ldclient import datasystem from ldclient.config import Config from ldclient.integrations import Redis store = Redis.new_feature_store() - config = Config('sdk-key', datasystem_config=datasystem.persistent_store(store).build()) + config = Config('sdk-key', data_system=datasystem.persistent_store(store).build()) :param url: the URL of the Redis host; defaults to ``DEFAULT_URL`` :param prefix: a namespace prefix to be prepended to all Redis keys; defaults to @@ -245,10 +241,8 @@ def new_feature_store( the maximum number of connections, use ``redis_opts={'max_connections': N}`` instead. :param caching: specifies whether local caching should be enabled and if so, sets the cache properties; defaults to :func:`ldclient.feature_store.CacheConfig.default()`. - When the SDK is configured to use FDv2 (by setting ``datasystem_config`` - on :class:`ldclient.config.Config`), the cache is automatically disabled - once the in-memory store has been initialized, so these settings only - affect the brief bootstrap window. See :class:`ldclient.feature_store.CacheConfig`. + The SDK disables the cache once the in-memory store has been initialized, + so these settings only affect the brief bootstrap window. See :class:`ldclient.feature_store.CacheConfig`. :param redis_opts: extra options for initializing Redis connection from the url, see `redis.connection.ConnectionPool.from_url` for more details. """ @@ -318,7 +312,7 @@ def async_feature_store(url: str = 'redis://localhost:6379/0', prefix: Optional[ To use this method, you must first install the ``redis`` package (version >=5.0.1). Then, pass the object returned by this method to :func:`ldclient.async_datasystem.persistent_store`, or to :func:`ldclient.async_datasystem.daemon` if another process keeps the store up to date, and set - the result as the ``datasystem_config`` of your client configuration + the result as the ``data_system`` of your client configuration (:class:`ldclient.async_config.AsyncConfig`). :: @@ -326,7 +320,7 @@ def async_feature_store(url: str = 'redis://localhost:6379/0', prefix: Optional[ from ldclient.async_config import AsyncConfig from ldclient.integrations import Redis store = Redis.async_feature_store() - config = AsyncConfig('sdk-key', datasystem_config=async_datasystem.persistent_store(store).build()) + config = AsyncConfig('sdk-key', data_system=async_datasystem.persistent_store(store).build()) The data layout matches :func:`new_feature_store`, so an async and a synchronous SDK can share one Redis instance. @@ -389,33 +383,33 @@ class Files: """Provides factory methods for integrations with filesystem data.""" @staticmethod - def new_data_source_v2(paths: str | List[str], poll_interval: float = 1, force_polling: bool = False) -> DataSourceBuilder: - """Provides a way to use local files as a source of feature flag state using the FDv2 protocol. + def new_data_source(paths: str | List[str], poll_interval: float = 1, force_polling: bool = False) -> DataSourceBuilder: + """Provides a way to use local files as a source of feature flag state. - This returns a builder that can be used with the FDv2 data system configuration as both an + This returns a builder that can be used with the data system configuration as both an Initializer and a Synchronizer. When used as an Initializer, it reads files once. When used as a Synchronizer, it watches for file changes and automatically updates when files are modified. - To use this component with the FDv2 data system, call ``new_data_source_v2`` and use the returned + To use this component, call ``new_data_source`` and use the returned builder with the custom data system configuration: :: from ldclient.integrations import Files from ldclient.datasystem import custom - file_source = Files.new_data_source_v2(paths=['my_flags.json']) + file_source = Files.new_data_source(paths=['my_flags.json']) # Use as initializer only data_system = custom().initializers([file_source]).build() - config = Config('sdk-key', datasystem_config=data_system) + config = Config('sdk-key', data_system=data_system) # Use as synchronizer only data_system = custom().synchronizers(file_source).build() - config = Config('sdk-key', datasystem_config=data_system) + config = Config('sdk-key', data_system=data_system) # Use as both initializer and synchronizer data_system = custom().initializers([file_source]).synchronizers(file_source).build() - config = Config('sdk-key', datasystem_config=data_system) + config = Config('sdk-key', data_system=data_system) This will cause the client not to connect to LaunchDarkly to get feature flags. The client may still make network connections to send analytics events, unless you have disabled @@ -440,7 +434,7 @@ def new_data_source_v2(paths: str | List[str], poll_interval: float = 1, force_p :return: a builder that creates the file data source """ return ( - FileDataSourceV2Builder(paths) + FileDataSourceBuilder(paths) .poll_interval(poll_interval) .force_polling(force_polling) ) diff --git a/ldclient/integrations/test_datav2.py b/ldclient/integrations/test_data.py similarity index 85% rename from ldclient/integrations/test_datav2.py rename to ldclient/integrations/test_data.py index 23afed97..8b908fc5 100644 --- a/ldclient/integrations/test_datav2.py +++ b/ldclient/integrations/test_data.py @@ -5,11 +5,11 @@ from ldclient.config import Config, DataSourceBuilder, DataSourceBuilderConfig from ldclient.context import Context -from ldclient.impl.integrations.test_datav2.async_test_data_sourcev2 import ( - _AsyncTestDataSourceV2 +from ldclient.impl.integrations.test_data.async_test_data_source import ( + _AsyncTestDataSource ) -from ldclient.impl.integrations.test_datav2.test_data_sourcev2 import ( - _TestDataSourceV2 +from ldclient.impl.integrations.test_data.test_data_source import ( + _TestDataSource ) from ldclient.impl.rwlock import ReadWriteLock @@ -21,34 +21,34 @@ def _variation_for_boolean(variation): return TRUE_VARIATION_INDEX if variation else FALSE_VARIATION_INDEX -class FlagRuleBuilderV2: +class FlagRuleBuilder: """ - A builder for feature flag rules to be used with :class:`ldclient.integrations.test_datav2.FlagBuilderV2`. + A builder for feature flag rules to be used with :class:`ldclient.integrations.test_data.FlagBuilder`. In the LaunchDarkly model, a flag can have any number of rules, and a rule can have any number of clauses. A clause is an individual test such as \"name is 'X'\". A rule matches a user if all of the rule's clauses match the user. To start defining a rule, use one of the flag builder's matching methods such as - :meth:`ldclient.integrations.test_datav2.FlagBuilderV2.if_match()`. + :meth:`ldclient.integrations.test_data.FlagBuilder.if_match()`. This defines the first clause for the rule. Optionally, you may add more clauses with the rule builder's methods such as - :meth:`ldclient.integrations.test_datav2.FlagRuleBuilderV2.and_match()` or - :meth:`ldclient.integrations.test_datav2.FlagRuleBuilderV2.and_not_match()`. - Finally, call :meth:`ldclient.integrations.test_datav2.FlagRuleBuilderV2.then_return()` + :meth:`ldclient.integrations.test_data.FlagRuleBuilder.and_match()` or + :meth:`ldclient.integrations.test_data.FlagRuleBuilder.and_not_match()`. + Finally, call :meth:`ldclient.integrations.test_data.FlagRuleBuilder.then_return()` to finish defining the rule. """ - def __init__(self, flag_builder: FlagBuilderV2): + def __init__(self, flag_builder: FlagBuilder): self._flag_builder = flag_builder self._clauses: List[dict] = [] self._variation: Optional[int] = None - def and_match(self, attribute: str, *values) -> FlagRuleBuilderV2: + def and_match(self, attribute: str, *values) -> FlagRuleBuilder: """ Adds another clause, using the \"is one of\" operator. - This is a shortcut for calling :meth:`ldclient.integrations.test_datav2.FlagRuleBuilderV2.and_match_context()` + This is a shortcut for calling :meth:`ldclient.integrations.test_data.FlagRuleBuilder.and_match_context()` with \"user\" as the context kind. **Example:** create a rule that returns ``True`` if the name is \"Patsy\" and the country is \"gb\" @@ -65,7 +65,7 @@ def and_match(self, attribute: str, *values) -> FlagRuleBuilderV2: """ return self.and_match_context(Context.DEFAULT_KIND, attribute, *values) - def and_match_context(self, context_kind: str, attribute: str, *values) -> FlagRuleBuilderV2: + def and_match_context(self, context_kind: str, attribute: str, *values) -> FlagRuleBuilder: """ Adds another clause, using the \"is one of\" operator. This matching expression only applies to contexts of a specific kind. @@ -87,11 +87,11 @@ def and_match_context(self, context_kind: str, attribute: str, *values) -> FlagR self._clauses.append({'contextKind': context_kind, 'attribute': attribute, 'op': 'in', 'values': list(values), 'negate': False}) return self - def and_not_match(self, attribute: str, *values) -> FlagRuleBuilderV2: + def and_not_match(self, attribute: str, *values) -> FlagRuleBuilder: """ Adds another clause, using the \"is not one of\" operator. - This is a shortcut for calling :meth:`ldclient.integrations.test_datav2.FlagRuleBuilderV2.and_not_match_context()` + This is a shortcut for calling :meth:`ldclient.integrations.test_data.FlagRuleBuilder.and_not_match_context()` with \"user\" as the context kind. **Example:** create a rule that returns ``True`` if the name is \"Patsy\" and the country is not \"gb\" @@ -108,7 +108,7 @@ def and_not_match(self, attribute: str, *values) -> FlagRuleBuilderV2: """ return self.and_not_match_context(Context.DEFAULT_KIND, attribute, *values) - def and_not_match_context(self, context_kind: str, attribute: str, *values) -> FlagRuleBuilderV2: + def and_not_match_context(self, context_kind: str, attribute: str, *values) -> FlagRuleBuilder: """ Adds another clause, using the \"is not one of\" operator. This matching expression only applies to contexts of a specific kind. @@ -130,7 +130,7 @@ def and_not_match_context(self, context_kind: str, attribute: str, *values) -> F self._clauses.append({'contextKind': context_kind, 'attribute': attribute, 'op': 'in', 'values': list(values), 'negate': True}) return self - def then_return(self, variation: Union[bool, int]) -> FlagBuilderV2: + def then_return(self, variation: Union[bool, int]) -> FlagBuilder: """ Finishes defining the rule, specifying the result as either a boolean or a variation index. @@ -151,7 +151,7 @@ def then_return(self, variation: Union[bool, int]) -> FlagBuilderV2: return self._flag_builder # Note that _build is private by convention, because we don't want developers to - # consider it part of the public API, but it is still called from FlagBuilderV2. + # consider it part of the public API, but it is still called from FlagBuilder. def _build(self, id: str) -> dict: """ Creates a dictionary representation of the rule @@ -162,12 +162,12 @@ def _build(self, id: str) -> dict: return {'id': 'rule' + id, 'variation': self._variation, 'clauses': self._clauses} -class FlagBuilderV2: +class FlagBuilder: """ - A builder for feature flag configurations to be used with :class:`ldclient.integrations.test_datav2.TestDataV2`. + A builder for feature flag configurations to be used with :class:`ldclient.integrations.test_data.TestData`. - :see: :meth:`ldclient.integrations.test_datav2.TestDataV2.flag()` - :see: :meth:`ldclient.integrations.test_datav2.TestDataV2.update()` + :see: :meth:`ldclient.integrations.test_data.TestData.flag()` + :see: :meth:`ldclient.integrations.test_data.TestData.update()` """ def __init__(self, key: str): @@ -178,18 +178,18 @@ def __init__(self, key: str): self._off_variation: Optional[int] = None self._fallthrough_variation: Optional[int] = None self._targets: Dict[str, Dict[int, Set[str]]] = {} - self._rules: List[FlagRuleBuilderV2] = [] + self._rules: List[FlagRuleBuilder] = [] # Note that _copy is private by convention, because we don't want developers to - # consider it part of the public API, but it is still called from TestDataV2. - def _copy(self) -> FlagBuilderV2: + # consider it part of the public API, but it is still called from TestData. + def _copy(self) -> FlagBuilder: """ Creates a deep copy of the flag builder. Subsequent updates to the - original ``FlagBuilderV2`` object will not update the copy and vice versa. + original ``FlagBuilder`` object will not update the copy and vice versa. :return: a copy of the flag builder object """ - to = FlagBuilderV2(self._key) + to = FlagBuilder(self._key) to._on = self._on to._variations = copy.copy(self._variations) @@ -202,13 +202,13 @@ def _copy(self) -> FlagBuilderV2: return to - def on(self, on: bool) -> FlagBuilderV2: + def on(self, on: bool) -> FlagBuilder: """ Sets targeting to be on or off for this flag. The effect of this depends on the rest of the flag configuration, just as it does on the real LaunchDarkly dashboard. In the default configuration that you get from calling - :meth:`ldclient.integrations.test_datav2.TestDataV2.flag()` with a new flag key, + :meth:`ldclient.integrations.test_data.TestData.flag()` with a new flag key, the flag will return ``False`` whenever targeting is off, and ``True`` when targeting is on. @@ -218,7 +218,7 @@ def on(self, on: bool) -> FlagBuilderV2: self._on = on return self - def fallthrough_variation(self, variation: Union[bool, int]) -> FlagBuilderV2: + def fallthrough_variation(self, variation: Union[bool, int]) -> FlagBuilder: """ Specifies the fallthrough variation. The fallthrough is the value that is returned if targeting is on and the user was not matched by a more specific @@ -238,7 +238,7 @@ def fallthrough_variation(self, variation: Union[bool, int]) -> FlagBuilderV2: self._fallthrough_variation = variation return self - def off_variation(self, variation: Union[bool, int]) -> FlagBuilderV2: + def off_variation(self, variation: Union[bool, int]) -> FlagBuilder: """ Specifies the fallthrough variation. This is the variation that is returned whenever targeting is off. @@ -257,12 +257,12 @@ def off_variation(self, variation: Union[bool, int]) -> FlagBuilderV2: self._off_variation = variation return self - def boolean_flag(self) -> FlagBuilderV2: + def boolean_flag(self) -> FlagBuilder: """ A shortcut for setting the flag to use the standard boolean configuration. This is the default for all new flags created with - :meth:`ldclient.integrations.test_datav2.TestDataV2.flag()`. + :meth:`ldclient.integrations.test_data.TestData.flag()`. The flag will have two variations, ``True`` and ``False`` (in that order); it will return ``False`` whenever targeting is off, and ``True`` when targeting is on @@ -278,7 +278,7 @@ def boolean_flag(self) -> FlagBuilderV2: def _is_boolean_flag(self): return len(self._variations) == 2 and self._variations[TRUE_VARIATION_INDEX] is True and self._variations[FALSE_VARIATION_INDEX] is False - def variations(self, *variations) -> FlagBuilderV2: + def variations(self, *variations) -> FlagBuilder: """ Changes the allowable variation values for the flag. @@ -303,7 +303,7 @@ def variations(self, *variations) -> FlagBuilderV2: return self - def variation_for_all(self, variation: Union[bool, int]) -> FlagBuilderV2: + def variation_for_all(self, variation: Union[bool, int]) -> FlagBuilder: """ Sets the flag to always return the specified variation for all contexts. @@ -322,7 +322,7 @@ def variation_for_all(self, variation: Union[bool, int]) -> FlagBuilderV2: return self.clear_rules().clear_targets().on(True).fallthrough_variation(variation) - def value_for_all(self, value: Any) -> FlagBuilderV2: + def value_for_all(self, value: Any) -> FlagBuilder: """ Sets the flag to always return the specified variation value for all users. @@ -336,7 +336,7 @@ def value_for_all(self, value: Any) -> FlagBuilderV2: """ return self.variations(value).variation_for_all(0).off_variation(0) - def variation_for_user(self, user_key: str, variation: Union[bool, int]) -> FlagBuilderV2: + def variation_for_user(self, user_key: str, variation: Union[bool, int]) -> FlagBuilder: """ Sets the flag to return the specified variation for a specific user key when targeting is on. @@ -353,7 +353,7 @@ def variation_for_user(self, user_key: str, variation: Union[bool, int]) -> Flag """ return self.variation_for_key(Context.DEFAULT_KIND, user_key, variation) - def variation_for_key(self, context_kind: str, context_key: str, variation: Union[bool, int]) -> FlagBuilderV2: + def variation_for_key(self, context_kind: str, context_key: str, variation: Union[bool, int]) -> FlagBuilder: """ Sets the flag to return the specified variation for a specific context, identified by context kind and key, when targeting is on. @@ -397,14 +397,14 @@ def variation_for_key(self, context_kind: str, context_key: str, variation: Unio return self - def _add_rule(self, flag_rule_builder: FlagRuleBuilderV2): + def _add_rule(self, flag_rule_builder: FlagRuleBuilder): self._rules.append(flag_rule_builder) - def if_match(self, attribute: str, *values) -> FlagRuleBuilderV2: + def if_match(self, attribute: str, *values) -> FlagRuleBuilder: """ Starts defining a flag rule, using the \"is one of\" operator. - This is a shortcut for calling :meth:`ldclient.integrations.test_datav2.FlagBuilderV2.if_match_context()` + This is a shortcut for calling :meth:`ldclient.integrations.test_data.FlagBuilder.if_match_context()` with \"user\" as the context kind. **Example:** create a rule that returns ``True`` if the name is \"Patsy\" or \"Edina\" @@ -420,7 +420,7 @@ def if_match(self, attribute: str, *values) -> FlagRuleBuilderV2: """ return self.if_match_context(Context.DEFAULT_KIND, attribute, *values) - def if_match_context(self, context_kind: str, attribute: str, *values) -> FlagRuleBuilderV2: + def if_match_context(self, context_kind: str, attribute: str, *values) -> FlagRuleBuilder: """ Starts defining a flag rule, using the \"is one of\" operator. This matching expression only applies to contexts of a specific kind. @@ -438,14 +438,14 @@ def if_match_context(self, context_kind: str, attribute: str, *values) -> FlagRu :param values: values to compare to :return: the flag rule builder """ - flag_rule_builder = FlagRuleBuilderV2(self) + flag_rule_builder = FlagRuleBuilder(self) return flag_rule_builder.and_match_context(context_kind, attribute, *values) - def if_not_match(self, attribute: str, *values) -> FlagRuleBuilderV2: + def if_not_match(self, attribute: str, *values) -> FlagRuleBuilder: """ Starts defining a flag rule, using the \"is not one of\" operator. - This is a shortcut for calling :meth:`ldclient.integrations.test_datav2.FlagBuilderV2.if_not_match_context()` + This is a shortcut for calling :meth:`ldclient.integrations.test_data.FlagBuilder.if_not_match_context()` with \"user\" as the context kind. **Example:** create a rule that returns ``True`` if the name is neither \"Saffron\" nor \"Bubble\" @@ -461,7 +461,7 @@ def if_not_match(self, attribute: str, *values) -> FlagRuleBuilderV2: """ return self.if_not_match_context(Context.DEFAULT_KIND, attribute, *values) - def if_not_match_context(self, context_kind: str, attribute: str, *values) -> FlagRuleBuilderV2: + def if_not_match_context(self, context_kind: str, attribute: str, *values) -> FlagRuleBuilder: """ Starts defining a flag rule, using the \"is not one of\" operator. This matching expression only applies to contexts of a specific kind. @@ -479,25 +479,25 @@ def if_not_match_context(self, context_kind: str, attribute: str, *values) -> Fl :param values: values to compare to :return: the flag rule builder """ - flag_rule_builder = FlagRuleBuilderV2(self) + flag_rule_builder = FlagRuleBuilder(self) return flag_rule_builder.and_not_match_context(context_kind, attribute, *values) - def clear_rules(self) -> FlagBuilderV2: + def clear_rules(self) -> FlagBuilder: """ Removes any existing rules from the flag. This undoes the effect of methods like - :meth:`ldclient.integrations.test_datav2.FlagBuilderV2.if_match()`. + :meth:`ldclient.integrations.test_data.FlagBuilder.if_match()`. :return: the same flag builder """ self._rules = [] return self - def clear_targets(self) -> FlagBuilderV2: + def clear_targets(self) -> FlagBuilder: """ Removes any existing targets from the flag. This undoes the effect of methods like - :meth:`ldclient.integrations.test_datav2.FlagBuilderV2.variation_for_user()`. + :meth:`ldclient.integrations.test_data.FlagBuilder.variation_for_user()`. :return: the same flag builder """ @@ -505,7 +505,7 @@ def clear_targets(self) -> FlagBuilderV2: return self # Note that _build is private by convention, because we don't want developers to - # consider it part of the public API, but it is still called from TestDataV2. + # consider it part of the public API, but it is still called from TestData. def _build(self, version: int) -> dict: """ Creates a dictionary representation of the flag @@ -538,30 +538,30 @@ def _build(self, version: int) -> dict: return base_flag_object -class TestDataV2: +class TestData: """ A mechanism for providing dynamically updatable feature flag state in a - simplified form to an SDK client in test scenarios using the FDv2 protocol. + simplified form to an SDK client in test scenarios. Unlike ``Files``, this mechanism does not use any external resources. It provides only the data that the application has put into it using the ``update`` method. :: from ldclient import datasystem - from ldclient.integrations.test_datav2 import TestDataV2 + from ldclient.integrations.test_data import TestData - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag('flag-key-1').variation_for_all(True)) - # Configure the data system with TestDataV2 as both initializer and synchronizer + # Configure the data system with TestData as both initializer and synchronizer data_config = datasystem.custom() data_config.initializers([td.builder]) data_config.synchronizers(td.builder) config = Config( sdk_key, - datasystem_config=data_config.build(), + data_system=data_config.build(), ) # flags can be updated at any time: @@ -570,11 +570,11 @@ class TestDataV2: fallthrough_variation(False)) The above example uses a simple boolean flag, but more complex configurations are possible using - the methods of the ``FlagBuilderV2`` that is returned by ``flag``. ``FlagBuilderV2`` + the methods of the ``FlagBuilder`` that is returned by ``flag``. ``FlagBuilder`` supports many of the ways a flag can be configured on the LaunchDarkly dashboard, but does not currently support 1. rule operators other than "in" and "not in", or 2. percentage rollouts. - If the same ``TestDataV2`` instance is used to configure multiple ``LDClient`` instances, + If the same ``TestData`` instance is used to configure multiple ``LDClient`` instances, any changes made to the data will propagate to all of the ``LDClient`` instances. """ @@ -589,25 +589,25 @@ def __init__(self): self._version = 0 @staticmethod - def data_source() -> TestDataV2: + def data_source() -> TestData: """ Creates a new instance of the test data source. :return: a new configurable test data source """ - return TestDataV2() + return TestData() - def flag(self, key: str) -> FlagBuilderV2: + def flag(self, key: str) -> FlagBuilder: """ - Creates or copies a ``FlagBuilderV2`` for building a test flag configuration. + Creates or copies a ``FlagBuilder`` for building a test flag configuration. - If this flag key has already been defined in this ``TestDataV2`` instance, then the builder + If this flag key has already been defined in this ``TestData`` instance, then the builder starts with the same configuration that was last provided for this flag. Otherwise, it starts with a new default configuration in which the flag has ``True`` and ``False`` variations, is ``True`` for all users when targeting is turned on and ``False`` otherwise, and currently has targeting turned on. You can change any of those - properties, and provide more complex behavior, using the ``FlagBuilderV2`` methods. + properties, and provide more complex behavior, using the ``FlagBuilder`` methods. Once you have set the desired configuration, pass the builder to ``update``. @@ -618,23 +618,23 @@ def flag(self, key: str) -> FlagBuilderV2: if key in self._flag_builders and self._flag_builders[key]: return self._flag_builders[key]._copy() - return FlagBuilderV2(key).boolean_flag() + return FlagBuilder(key).boolean_flag() - def update(self, flag_builder: FlagBuilderV2) -> TestDataV2: + def update(self, flag_builder: FlagBuilder) -> TestData: """ Updates the test data with the specified flag configuration. This has the same effect as if a flag were added or modified on the LaunchDarkly dashboard. It immediately propagates the flag change to any ``LDClient`` instance(s) that you have - already configured to use this ``TestDataV2``. If no ``LDClient`` has been started yet, + already configured to use this ``TestData``. If no ``LDClient`` has been started yet, it simply adds this flag to the test data which will be provided to any ``LDClient`` that you subsequently configure. - Any subsequent changes to this ``FlagBuilderV2`` instance do not affect the test data, + Any subsequent changes to this ``FlagBuilder`` instance do not affect the test data, unless you call ``update`` again. :param flag_builder: a flag configuration builder - :return: self (the TestDataV2 object) + :return: self (the TestData object) """ instances_copy = [] with self._lock.write(): @@ -679,7 +679,7 @@ def _add_instance(self, instance): @property def builder(self) -> DataSourceBuilder: """ - Creates a builder that can be used with the FDv2 data system. + Creates a builder that can be used with the data system. :return: a test data data source builder """ @@ -688,7 +688,7 @@ def builder(self) -> DataSourceBuilder: @property def async_builder(self) -> DataSourceBuilder: """ - Creates a builder that can be used with the async FDv2 data system. + Creates a builder that can be used with the async data system. .. caution:: This feature is experimental and should NOT be considered ready for production @@ -700,20 +700,20 @@ def async_builder(self) -> DataSourceBuilder: return AsyncTestDataSourceBuilder(self) -class TestDataSourceBuilder(DataSourceBuilder[_TestDataSourceV2]): # pylint: disable=too-few-public-methods - """Builder for TestDataV2 data sources that implements the DataSourceBuilder protocol.""" +class TestDataSourceBuilder(DataSourceBuilder[_TestDataSource]): # pylint: disable=too-few-public-methods + """Builder for TestData data sources that implements the DataSourceBuilder protocol.""" - def __init__(self, test_data: TestDataV2): + def __init__(self, test_data: TestData): self._test_data = test_data - def build(self, config: DataSourceBuilderConfig) -> _TestDataSourceV2: # pylint: disable=unused-argument - """Builds the TestDataSourceV2 instance.""" - return _TestDataSourceV2(self._test_data) + def build(self, config: DataSourceBuilderConfig) -> _TestDataSource: # pylint: disable=unused-argument + """Builds the TestDataSource instance.""" + return _TestDataSource(self._test_data) -class AsyncTestDataSourceBuilder(DataSourceBuilder[_AsyncTestDataSourceV2]): # pylint: disable=too-few-public-methods +class AsyncTestDataSourceBuilder(DataSourceBuilder[_AsyncTestDataSource]): # pylint: disable=too-few-public-methods """ - Builder for async TestDataV2 data sources that implements the DataSourceBuilder protocol. + Builder for async TestData data sources that implements the DataSourceBuilder protocol. .. caution:: This feature is experimental and should NOT be considered ready for production @@ -721,9 +721,9 @@ class AsyncTestDataSourceBuilder(DataSourceBuilder[_AsyncTestDataSourceV2]): # compatibility guarantees. """ - def __init__(self, test_data: TestDataV2): + def __init__(self, test_data: TestData): self._test_data = test_data - def build(self, config: DataSourceBuilderConfig) -> _AsyncTestDataSourceV2: # pylint: disable=unused-argument - """Builds the async TestDataSourceV2 instance.""" - return _AsyncTestDataSourceV2(self._test_data) + def build(self, config: DataSourceBuilderConfig) -> _AsyncTestDataSource: # pylint: disable=unused-argument + """Builds the async TestDataSource instance.""" + return _AsyncTestDataSource(self._test_data) diff --git a/ldclient/testing/impl/datasourcev2/test_async_polling.py b/ldclient/testing/impl/datasource/test_async_polling.py similarity index 99% rename from ldclient/testing/impl/datasourcev2/test_async_polling.py rename to ldclient/testing/impl/datasource/test_async_polling.py index 622a1a9e..27b26625 100644 --- a/ldclient/testing/impl/datasourcev2/test_async_polling.py +++ b/ldclient/testing/impl/datasource/test_async_polling.py @@ -6,7 +6,7 @@ import pytest -from ldclient.impl.datasourcev2.async_polling import ( +from ldclient.impl.datasource.async_polling import ( AsyncPollingDataSource, PollingResult ) @@ -72,7 +72,7 @@ def _ss() -> MockSelectorStore: def test_name(): src = _make_source([_Fail(error="failure message")]) - assert src.name == "PollingDataSourceV2" + assert src.name == "PollingDataSource" @pytest.mark.asyncio diff --git a/ldclient/testing/impl/datasourcev2/test_async_streaming.py b/ldclient/testing/impl/datasource/test_async_streaming.py similarity index 99% rename from ldclient/testing/impl/datasourcev2/test_async_streaming.py rename to ldclient/testing/impl/datasource/test_async_streaming.py index b3c55f02..30f49f81 100644 --- a/ldclient/testing/impl/datasourcev2/test_async_streaming.py +++ b/ldclient/testing/impl/datasource/test_async_streaming.py @@ -10,8 +10,8 @@ from ld_eventsource.sse_client import Event, Fault from ldclient.config import Config -from ldclient.impl.datasourcev2 import async_streaming -from ldclient.impl.datasourcev2.async_streaming import ( +from ldclient.impl.datasource import async_streaming +from ldclient.impl.datasource.async_streaming import ( STREAMING_ENDPOINT, AsyncStreamingDataSource, create_sse_client diff --git a/ldclient/testing/impl/datasourcev2/test_poll_interval_minimum.py b/ldclient/testing/impl/datasource/test_poll_interval_minimum.py similarity index 94% rename from ldclient/testing/impl/datasourcev2/test_poll_interval_minimum.py rename to ldclient/testing/impl/datasource/test_poll_interval_minimum.py index b812c1b4..255fcd23 100644 --- a/ldclient/testing/impl/datasourcev2/test_poll_interval_minimum.py +++ b/ldclient/testing/impl/datasource/test_poll_interval_minimum.py @@ -7,11 +7,11 @@ from ldclient.async_config import AsyncConfig from ldclient.config import Config -from ldclient.impl.datasourcev2.async_polling import ( +from ldclient.impl.datasource.async_polling import ( AsyncFallbackToFDv1PollingDataSourceBuilder, AsyncPollingDataSourceBuilder ) -from ldclient.impl.datasourcev2.polling import ( +from ldclient.impl.datasource.polling import ( FallbackToFDv1PollingDataSourceBuilder, PollingDataSourceBuilder ) diff --git a/ldclient/testing/impl/datasourcev2/test_polling_initializer.py b/ldclient/testing/impl/datasource/test_polling_initializer.py similarity index 99% rename from ldclient/testing/impl/datasourcev2/test_polling_initializer.py rename to ldclient/testing/impl/datasource/test_polling_initializer.py index d59cc7df..3215f19b 100644 --- a/ldclient/testing/impl/datasourcev2/test_polling_initializer.py +++ b/ldclient/testing/impl/datasource/test_polling_initializer.py @@ -3,7 +3,7 @@ import json from typing import Optional -from ldclient.impl.datasourcev2.polling import ( +from ldclient.impl.datasource.polling import ( PollingDataSource, PollingResult, Selector, @@ -37,7 +37,7 @@ def test_polling_has_a_name(): mock_requester = MockPollingRequester(_Fail(error="failure message")) ds = PollingDataSource(poll_interval=1.0, requester=mock_requester) - assert ds.name == "PollingDataSourceV2" + assert ds.name == "PollingDataSource" def test_error_is_returned_on_failure(): diff --git a/ldclient/testing/impl/datasourcev2/test_polling_payload_parsing.py b/ldclient/testing/impl/datasource/test_polling_payload_parsing.py similarity index 99% rename from ldclient/testing/impl/datasourcev2/test_polling_payload_parsing.py rename to ldclient/testing/impl/datasource/test_polling_payload_parsing.py index 1d21d589..7ad885d4 100644 --- a/ldclient/testing/impl/datasourcev2/test_polling_payload_parsing.py +++ b/ldclient/testing/impl/datasource/test_polling_payload_parsing.py @@ -2,7 +2,7 @@ import pytest -from ldclient.impl.datasourcev2.polling import ( +from ldclient.impl.datasource.polling import ( fdv1_polling_payload_to_changeset, polling_payload_to_changeset ) diff --git a/ldclient/testing/impl/datasourcev2/test_polling_synchronizer.py b/ldclient/testing/impl/datasource/test_polling_synchronizer.py similarity index 99% rename from ldclient/testing/impl/datasourcev2/test_polling_synchronizer.py rename to ldclient/testing/impl/datasource/test_polling_synchronizer.py index d1ff4f48..f7a97904 100644 --- a/ldclient/testing/impl/datasourcev2/test_polling_synchronizer.py +++ b/ldclient/testing/impl/datasource/test_polling_synchronizer.py @@ -4,7 +4,7 @@ import pytest from ld_eventsource.sse_client import Event -from ldclient.impl.datasourcev2.polling import PollingDataSource, PollingResult +from ldclient.impl.datasource.polling import PollingDataSource, PollingResult from ldclient.impl.datasystem.protocolv2 import ( DeleteObject, Error, diff --git a/ldclient/testing/impl/datasourcev2/test_request_query.py b/ldclient/testing/impl/datasource/test_request_query.py similarity index 95% rename from ldclient/testing/impl/datasourcev2/test_request_query.py rename to ldclient/testing/impl/datasource/test_request_query.py index 46fadf6c..7105bd18 100644 --- a/ldclient/testing/impl/datasourcev2/test_request_query.py +++ b/ldclient/testing/impl/datasource/test_request_query.py @@ -9,12 +9,12 @@ import pytest from ldclient.config import Config -from ldclient.impl.datasourcev2 import async_streaming, streaming -from ldclient.impl.datasourcev2.async_polling import ( +from ldclient.impl.datasource import async_streaming, streaming +from ldclient.impl.datasource.async_polling import ( AiohttpFDv1PollingRequester, AiohttpPollingRequester ) -from ldclient.impl.datasourcev2.polling import ( +from ldclient.impl.datasource.polling import ( Urllib3FDv1PollingRequester, Urllib3PollingRequester ) diff --git a/ldclient/testing/impl/datasourcev2/test_requester_http.py b/ldclient/testing/impl/datasource/test_requester_http.py similarity index 97% rename from ldclient/testing/impl/datasourcev2/test_requester_http.py rename to ldclient/testing/impl/datasource/test_requester_http.py index d6562b7e..997145f7 100644 --- a/ldclient/testing/impl/datasourcev2/test_requester_http.py +++ b/ldclient/testing/impl/datasource/test_requester_http.py @@ -9,12 +9,12 @@ import pytest from ldclient.config import Config -from ldclient.impl.datasourcev2 import async_streaming, streaming -from ldclient.impl.datasourcev2.async_polling import ( +from ldclient.impl.datasource import async_streaming, streaming +from ldclient.impl.datasource.async_polling import ( AiohttpFDv1PollingRequester, AiohttpPollingRequester ) -from ldclient.impl.datasourcev2.polling import ( +from ldclient.impl.datasource.polling import ( Urllib3FDv1PollingRequester, Urllib3PollingRequester ) diff --git a/ldclient/testing/impl/datasourcev2/test_stream_init_diagnostics.py b/ldclient/testing/impl/datasource/test_stream_init_diagnostics.py similarity index 98% rename from ldclient/testing/impl/datasourcev2/test_stream_init_diagnostics.py rename to ldclient/testing/impl/datasource/test_stream_init_diagnostics.py index 7a00dc62..ebea12b3 100644 --- a/ldclient/testing/impl/datasourcev2/test_stream_init_diagnostics.py +++ b/ldclient/testing/impl/datasource/test_stream_init_diagnostics.py @@ -14,9 +14,9 @@ from ld_eventsource.sse_client import Event, Fault from ldclient.config import Config -from ldclient.impl.datasourcev2 import async_streaming, streaming -from ldclient.impl.datasourcev2.async_streaming import AsyncStreamingDataSource -from ldclient.impl.datasourcev2.streaming import ( +from ldclient.impl.datasource import async_streaming, streaming +from ldclient.impl.datasource.async_streaming import AsyncStreamingDataSource +from ldclient.impl.datasource.streaming import ( STREAMING_ENDPOINT, StreamingDataSource ) diff --git a/ldclient/testing/impl/datasourcev2/test_stream_init_timing.py b/ldclient/testing/impl/datasource/test_stream_init_timing.py similarity index 93% rename from ldclient/testing/impl/datasourcev2/test_stream_init_timing.py rename to ldclient/testing/impl/datasource/test_stream_init_timing.py index 6cdfc426..14ec4347 100644 --- a/ldclient/testing/impl/datasourcev2/test_stream_init_timing.py +++ b/ldclient/testing/impl/datasource/test_stream_init_timing.py @@ -11,9 +11,9 @@ import pytest -from ldclient.impl.datasourcev2 import async_streaming, streaming -from ldclient.impl.datasourcev2.async_streaming import AsyncStreamingDataSource -from ldclient.impl.datasourcev2.streaming import StreamingDataSource +from ldclient.impl.datasource import async_streaming, streaming +from ldclient.impl.datasource.async_streaming import AsyncStreamingDataSource +from ldclient.impl.datasource.streaming import StreamingDataSource _CASES = [ pytest.param(streaming, StreamingDataSource, id="sync"), diff --git a/ldclient/testing/impl/datasourcev2/test_streaming_synchronizer.py b/ldclient/testing/impl/datasource/test_streaming_synchronizer.py similarity index 99% rename from ldclient/testing/impl/datasourcev2/test_streaming_synchronizer.py rename to ldclient/testing/impl/datasource/test_streaming_synchronizer.py index afea1186..a398b7e8 100644 --- a/ldclient/testing/impl/datasourcev2/test_streaming_synchronizer.py +++ b/ldclient/testing/impl/datasource/test_streaming_synchronizer.py @@ -11,7 +11,7 @@ from ld_eventsource.sse_client import Event, Fault from ldclient.config import Config, DataSourceBuilderConfig, HTTPConfig -from ldclient.impl.datasourcev2.streaming import ( +from ldclient.impl.datasource.streaming import ( STREAMING_ENDPOINT, SseClientBuilder, StreamingDataSource diff --git a/ldclient/testing/impl/datasystem/test_async_config.py b/ldclient/testing/impl/datasystem/test_async_config.py index c3758117..221382ea 100644 --- a/ldclient/testing/impl/datasystem/test_async_config.py +++ b/ldclient/testing/impl/datasystem/test_async_config.py @@ -4,11 +4,11 @@ from ldclient.async_config import AsyncDataSystemConfig from ldclient.config import DataSystemConfig -from ldclient.impl.datasourcev2.async_polling import ( +from ldclient.impl.datasource.async_polling import ( AsyncFallbackToFDv1PollingDataSourceBuilder, AsyncPollingDataSourceBuilder ) -from ldclient.impl.datasourcev2.async_streaming import ( +from ldclient.impl.datasource.async_streaming import ( AsyncStreamingDataSourceBuilder ) from ldclient.interfaces import AsyncFeatureStore, DataStoreMode diff --git a/ldclient/testing/impl/datasystem/test_async_datasystem.py b/ldclient/testing/impl/datasystem/test_async_datasystem.py index 859a8899..81f5f134 100644 --- a/ldclient/testing/impl/datasystem/test_async_datasystem.py +++ b/ldclient/testing/impl/datasystem/test_async_datasystem.py @@ -19,14 +19,14 @@ ) from ldclient.async_feature_store import AsyncInMemoryFeatureStore from ldclient.context import Context -from ldclient.impl.datasourcev2.async_polling import ( +from ldclient.impl.datasource.async_polling import ( AsyncFallbackToFDv1PollingDataSourceBuilder, AsyncPollingDataSourceBuilder ) -from ldclient.impl.datasourcev2.async_streaming import ( +from ldclient.impl.datasource.async_streaming import ( AsyncStreamingDataSourceBuilder ) -from ldclient.integrations.test_datav2 import TestDataV2 +from ldclient.integrations.test_data import TestData from ldclient.interfaces import DataStoreMode @@ -153,10 +153,10 @@ def test_client_gives_its_session_to_every_builder_of_the_default_config(): @pytest.mark.asyncio async def test_client_evaluates_flags_from_a_custom_config(): - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag('flag').on(True)) data_system = custom().synchronizers(td.async_builder).build() - config = AsyncConfig('sdk-key', send_events=False, datasystem_config=data_system) + config = AsyncConfig('sdk-key', send_events=False, data_system=data_system) async with AsyncLDClient(config) as client: assert await client.is_initialized() diff --git a/ldclient/testing/impl/datasystem/test_async_fdv2.py b/ldclient/testing/impl/datasystem/test_async_fdv2.py index 3966c588..20a7fd9c 100644 --- a/ldclient/testing/impl/datasystem/test_async_fdv2.py +++ b/ldclient/testing/impl/datasystem/test_async_fdv2.py @@ -17,7 +17,7 @@ _AsyncFeatureStoreClientWrapper ) from ldclient.impl.util import _LD_FD_FALLBACK_HEADER, _Fail, _Success -from ldclient.integrations.test_datav2 import TestDataV2 +from ldclient.integrations.test_data import TestData from ldclient.interfaces import ( AsyncFeatureStore, Basis, @@ -116,7 +116,7 @@ def _make_valid_update() -> Update: @pytest.mark.asyncio async def test_async_fdv2_basic_start_stop(): - td = TestDataV2.data_source() + td = TestData.data_source() data_system_config = DataSystemConfig( initializers=None, synchronizers=[td.async_builder], @@ -134,7 +134,7 @@ async def test_async_fdv2_basic_start_stop(): @pytest.mark.asyncio async def test_async_fdv2_synchronizer_receives_updates(): - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag("feature-flag").on(True)) data_system_config = DataSystemConfig( @@ -162,7 +162,7 @@ async def test_async_fdv2_synchronizer_receives_updates(): @pytest.mark.asyncio async def test_async_fdv2_flag_change_listener(): - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag("feature-flag").on(True)) data_system_config = DataSystemConfig( @@ -198,10 +198,10 @@ def listener(change: FlagChange): @pytest.mark.asyncio async def test_async_fdv2_two_phase_init(): - td_initializer = TestDataV2.data_source() + td_initializer = TestData.data_source() td_initializer.update(td_initializer.flag("feature-flag").on(True)) - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() td_synchronizer.update(td_synchronizer.flag("feature-flag").on(True)) td_synchronizer.update(td_synchronizer.flag("feature-flag").on(False)) @@ -249,7 +249,7 @@ async def test_async_fdv2_initializer_async(): @pytest.mark.asyncio async def test_async_fdv2_fallsback_to_secondary_synchronizer(): """When primary synchronizer yields nothing, should move to secondary.""" - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag("feature-flag").on(True)) # An async synchronizer that immediately stops (produces no updates) @@ -275,7 +275,7 @@ async def test_async_fdv2_fallsback_to_secondary_synchronizer(): @pytest.mark.asyncio async def test_async_fdv2_falls_back_to_fdv1_on_synchronizer_signal(): """Synchronizer yielding fallback_to_fdv1=True triggers FDv1 fallback.""" - td_fdv1 = TestDataV2.data_source() + td_fdv1 = TestData.data_source() td_fdv1.update(td_fdv1.flag("fdv1-flag").on(True)) # Primary synchronizer signals FDv1 fallback @@ -323,7 +323,7 @@ async def test_async_fdv2_data_availability_defaults_when_no_sources(): @pytest.mark.asyncio async def test_async_fdv2_data_availability_refreshed_with_data(): - td = TestDataV2.data_source() + td = TestData.data_source() data_system_config = DataSystemConfig( initializers=None, synchronizers=[td.async_builder], @@ -342,7 +342,7 @@ async def test_async_fdv2_data_availability_refreshed_with_data(): @pytest.mark.asyncio async def test_async_fdv2_disabled_immediately_signals_ready(): - td = TestDataV2.data_source() + td = TestData.data_source() data_system_config = DataSystemConfig( initializers=None, synchronizers=[td.async_builder], @@ -448,7 +448,7 @@ async def test_async_fdv2_initializer_header_fallback_engages_fdv1(): # This FDv2 synchronizer must never run because we fell back during init. fdv2_sync = ListAsyncSynchronizer("fdv2-should-not-run", []) - td_fdv1 = TestDataV2.data_source() + td_fdv1 = TestData.data_source() td_fdv1.update(td_fdv1.flag("fdv1-flag").on(True)) data_system_config = DataSystemConfig( @@ -513,7 +513,7 @@ async def test_async_fdv2_interrupted_without_header_falls_back_to_secondary(): [Update(state=DataSourceState.VALID, fallback_to_fdv1=False)], ) - td_fdv1 = TestDataV2.data_source() + td_fdv1 = TestData.data_source() td_fdv1.update(td_fdv1.flag("fdv1-should-not-appear").on(True)) data_system_config = DataSystemConfig( diff --git a/ldclient/testing/impl/datasystem/test_async_fdv2_persistence.py b/ldclient/testing/impl/datasystem/test_async_fdv2_persistence.py index b0eae019..ab9fd02a 100644 --- a/ldclient/testing/impl/datasystem/test_async_fdv2_persistence.py +++ b/ldclient/testing/impl/datasystem/test_async_fdv2_persistence.py @@ -21,7 +21,7 @@ ) from ldclient.impl.datasystem.async_store import AsyncStore from ldclient.impl.listeners import Listeners -from ldclient.integrations.test_datav2 import TestDataV2 +from ldclient.integrations.test_data import TestData from ldclient.interfaces import ( AsyncFeatureStore, DataStoreMode, @@ -139,7 +139,7 @@ async def _wait_for(event: asyncio.Event, timeout: float = 2.0): async def test_async_persistent_store_read_write_mode(): persistent_store = StubAsyncFeatureStore() - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag("new-flag").on(True)) data_system_config = AsyncDataSystemConfig( @@ -173,7 +173,7 @@ async def test_async_persistent_store_read_only_mode(): persistent_store = StubAsyncFeatureStore(initial) persistent_store.reset_operation_tracking() - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag("new-flag").on(True)) data_system_config = AsyncDataSystemConfig( @@ -204,7 +204,7 @@ async def test_async_persistent_store_read_only_mode(): async def test_async_persistent_store_delta_updates_read_write(): persistent_store = StubAsyncFeatureStore() - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag("feature-flag").on(True)) data_system_config = AsyncDataSystemConfig( @@ -247,7 +247,7 @@ def listener(_change: FlagChange): async def test_async_persistent_store_outage_recovery_flushes_on_recovery(): persistent_store = StubAsyncFeatureStore() - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag("feature-flag").on(True)) data_system_config = AsyncDataSystemConfig( @@ -300,7 +300,7 @@ def listener(change: FlagChange): async def test_async_persistent_store_outage_recovery_no_flush_when_not_stale(): persistent_store = StubAsyncFeatureStore() - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag("feature-flag").on(True)) data_system_config = AsyncDataSystemConfig( @@ -329,7 +329,7 @@ async def test_async_persistent_store_outage_recovery_no_flush_when_not_stale(): async def test_async_persistent_store_outage_recovery_no_flush_when_unavailable(): persistent_store = StubAsyncFeatureStore() - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag("feature-flag").on(True)) data_system_config = AsyncDataSystemConfig( @@ -409,7 +409,7 @@ async def test_async_store_view_reads_from_in_memory_after_swap(): async def _started_fdv2_with_store(store): - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag("feature-flag").on(True)) cfg = AsyncDataSystemConfig( data_store_mode=DataStoreMode.READ_WRITE, @@ -440,7 +440,7 @@ async def test_recovery_skipped_and_no_write_after_stop(): assert store.init_called_count == 0 assert store.init_after_close is False - assert not any(t.get_name() == "AsyncFDv2-store-recovery" for t in fdv2._runner._tasks) + assert not any(t.get_name() == "ldclient.datasystem.store_recovery" for t in fdv2._runner._tasks) @pytest.mark.asyncio @@ -463,10 +463,10 @@ async def slow_commit(): fdv2._persistent_store_outage_recovery(DataStoreStatus(available=True, stale=True)) await asyncio.wait_for(started.wait(), timeout=2) - assert any(t.get_name() == "AsyncFDv2-store-recovery" for t in fdv2._runner._tasks) + assert any(t.get_name() == "ldclient.datasystem.store_recovery" for t in fdv2._runner._tasks) await fdv2.stop() - assert not any(t.get_name() == "AsyncFDv2-store-recovery" for t in fdv2._runner._tasks) + assert not any(t.get_name() == "ldclient.datasystem.store_recovery" for t in fdv2._runner._tasks) @pytest.mark.asyncio diff --git a/ldclient/testing/impl/datasystem/test_fdv2_datasystem.py b/ldclient/testing/impl/datasystem/test_fdv2_datasystem.py index d4699e32..b512d899 100644 --- a/ldclient/testing/impl/datasystem/test_fdv2_datasystem.py +++ b/ldclient/testing/impl/datasystem/test_fdv2_datasystem.py @@ -22,7 +22,7 @@ _Fail, _Success ) -from ldclient.integrations.test_datav2 import TestDataV2 +from ldclient.integrations.test_data import TestData from ldclient.interfaces import ( Basis, BasisResult, @@ -77,10 +77,10 @@ def build(self, config: DataSourceBuilderConfig) -> Initializer: # pylint: disa def test_two_phase_init(): - td_initializer = TestDataV2.data_source() + td_initializer = TestData.data_source() td_initializer.update(td_initializer.flag("feature-flag").on(True)) - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() # Set this to true, and then to false to ensure the version number exceeded # the initializer version number. Otherwise, they start as the same version # and the latest value is ignored. @@ -124,7 +124,7 @@ def listener(flag_change: FlagChange): def test_can_stop_fdv2(): - td = TestDataV2.data_source() + td = TestData.data_source() data_system_config = DataSystemConfig( initializers=None, synchronizers=[td.builder], @@ -153,7 +153,7 @@ def listener(flag_change: FlagChange): def test_fdv2_data_availability_is_refreshed_with_data(): - td = TestDataV2.data_source() + td = TestData.data_source() data_system_config = DataSystemConfig( initializers=None, synchronizers=[td.builder], @@ -172,7 +172,7 @@ def test_fdv2_data_availability_is_refreshed_with_data(): def test_fdv2_fallsback_to_secondary_synchronizer(): mock: Synchronizer = Mock() mock.sync.return_value = iter([]) # Empty iterator to simulate no data - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag("feature-flag").on(True)) data_system_config = DataSystemConfig( initializers=[td.builder], @@ -207,7 +207,7 @@ def listener(flag_change: FlagChange): def test_fdv2_shutdown_down_if_both_synchronizers_fail(): mock: Synchronizer = Mock() mock.sync.return_value = iter([]) # Empty iterator to simulate no data - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag("feature-flag").on(True)) data_system_config = DataSystemConfig( initializers=[td.builder], @@ -249,7 +249,7 @@ def test_fdv2_falls_back_to_fdv1_on_polling_error_with_header(): ]) # Create FDv1 fallback data source with actual data - td_fdv1 = TestDataV2.data_source() + td_fdv1 = TestData.data_source() td_fdv1.update(td_fdv1.flag("fdv1-flag").on(True)) data_system_config = DataSystemConfig( @@ -299,7 +299,7 @@ def test_fdv2_falls_back_to_fdv1_on_polling_success_with_header(): ]) # Create FDv1 fallback data source - td_fdv1 = TestDataV2.data_source() + td_fdv1 = TestData.data_source() td_fdv1.update(td_fdv1.flag("fdv1-fallback-flag").on(True)) data_system_config = DataSystemConfig( @@ -337,7 +337,7 @@ def test_fdv2_falls_back_to_fdv1_with_initializer(): and that the FDv1 data replaces the initialized data. """ # Initialize with some data - td_initializer = TestDataV2.data_source() + td_initializer = TestData.data_source() td_initializer.update(td_initializer.flag("initial-flag").on(True)) # Create mock primary that signals fallback @@ -353,7 +353,7 @@ def test_fdv2_falls_back_to_fdv1_with_initializer(): ]) # Create FDv1 fallback with different data - td_fdv1 = TestDataV2.data_source() + td_fdv1 = TestData.data_source() td_fdv1.update(td_fdv1.flag("fdv1-replacement-flag").on(True)) data_system_config = DataSystemConfig( @@ -413,7 +413,7 @@ def test_fdv2_no_fallback_without_header(): ]) # Create FDv1 fallback (should not be used) - td_fdv1 = TestDataV2.data_source() + td_fdv1 = TestData.data_source() td_fdv1.update(td_fdv1.flag("fdv1-should-not-appear").on(True)) data_system_config = DataSystemConfig( @@ -456,7 +456,7 @@ def test_fdv2_stays_on_fdv1_after_fallback(): ]) # Create FDv1 fallback - td_fdv1 = TestDataV2.data_source() + td_fdv1 = TestData.data_source() td_fdv1.update(td_fdv1.flag("fdv1-flag").on(True)) data_system_config = DataSystemConfig( @@ -509,11 +509,11 @@ def test_fdv2_initializer_should_run_until_success(): os.write(f, initial_flag_data.encode("utf-8")) os.close(f) - td_initializer = TestDataV2.data_source() + td_initializer = TestData.data_source() td_initializer.update(td_initializer.flag("feature-flag").on(True)) # We actually do not care what this synchronizer does. - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() data_system_config = DataSystemConfig( initializers=[file_ds_builder([path]), td_initializer.builder], @@ -565,11 +565,11 @@ def test_fdv2_should_finish_initialization_on_first_successful_initializer(): os.write(f, initial_flag_data.encode("utf-8")) os.close(f) - td_initializer = TestDataV2.data_source() + td_initializer = TestData.data_source() td_initializer.update(td_initializer.flag("feature-flag").on(True)) # We actually do not care what this synchronizer does. - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() data_system_config = DataSystemConfig( initializers=[td_initializer.builder, file_ds_builder([path])], @@ -631,7 +631,7 @@ def test_fdv2_initializer_fallback_with_payload_engages_fdv1_synchronizer(): fdv2_sync_mock.stop = Mock() fdv2_sync_mock.sync.return_value = iter([]) - td_fdv1 = TestDataV2.data_source() + td_fdv1 = TestData.data_source() td_fdv1.update(td_fdv1.flag("fdv1-flag").on(True)) data_system_config = DataSystemConfig( @@ -733,7 +733,7 @@ def test_fdv2_synchronizer_fallback_on_success_with_payload(): ) ]) - td_fdv1 = TestDataV2.data_source() + td_fdv1 = TestData.data_source() td_fdv1.update(td_fdv1.flag("fdv1-flag").on(True)) data_system_config = DataSystemConfig( diff --git a/ldclient/testing/impl/datasystem/test_fdv2_persistence.py b/ldclient/testing/impl/datasystem/test_fdv2_persistence.py index 33ff74bb..40c93b65 100644 --- a/ldclient/testing/impl/datasystem/test_fdv2_persistence.py +++ b/ldclient/testing/impl/datasystem/test_fdv2_persistence.py @@ -7,7 +7,7 @@ from ldclient.config import Config, DataSystemConfig from ldclient.impl.datasystem import DataAvailability from ldclient.impl.datasystem.fdv2 import FDv2 -from ldclient.integrations.test_datav2 import TestDataV2 +from ldclient.integrations.test_data import TestData from ldclient.interfaces import DataStoreMode, FeatureStore, FlagChange from ldclient.testing.test_ldclient import make_client from ldclient.versioned_data_kind import FEATURES, SEGMENTS, VersionedDataKind @@ -143,7 +143,7 @@ def test_persistent_store_read_only_mode(): persistent_store = StubFeatureStore(initial_data) # Create synchronizer that will provide new data - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() td_synchronizer.update(td_synchronizer.flag("new-flag").on(True)) data_system_config = DataSystemConfig( @@ -190,7 +190,7 @@ def test_persistent_store_read_write_mode(): persistent_store.reset_operation_tracking() # Reset tracking after initial setup # Create synchronizer that will provide new data - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() td_synchronizer.update(td_synchronizer.flag("new-flag").on(True)) data_system_config = DataSystemConfig( @@ -223,7 +223,7 @@ def test_persistent_store_delta_updates_read_write(): persistent_store = StubFeatureStore() # Create synchronizer - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() td_synchronizer.update(td_synchronizer.flag("feature-flag").on(True)) data_system_config = DataSystemConfig( @@ -278,7 +278,7 @@ def test_persistent_store_delta_updates_read_only(): persistent_store = StubFeatureStore() # Create synchronizer - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() td_synchronizer.update(td_synchronizer.flag("feature-flag").on(True)) data_system_config = DataSystemConfig( @@ -326,11 +326,11 @@ def test_persistent_store_with_initializer_and_synchronizer(): persistent_store = StubFeatureStore() # Create initializer with one flag - td_initializer = TestDataV2.data_source() + td_initializer = TestData.data_source() td_initializer.update(td_initializer.flag("init-flag").on(True)) # Create synchronizer with another flag - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() td_synchronizer.update(td_synchronizer.flag("sync-flag").on(False)) data_system_config = DataSystemConfig( @@ -452,7 +452,7 @@ def test_data_store_status_provider(): """Test that data store status provider is correctly initialized""" persistent_store = StubFeatureStore() - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() td_synchronizer.update(td_synchronizer.flag("feature-flag").on(True)) data_system_config = DataSystemConfig( @@ -484,7 +484,7 @@ def test_data_store_status_monitoring_not_enabled_by_default(): """Test that monitoring is not enabled by default""" persistent_store = StubFeatureStore() - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() td_synchronizer.update(td_synchronizer.flag("feature-flag").on(True)) data_system_config = DataSystemConfig( @@ -506,7 +506,7 @@ def test_data_store_status_monitoring_enabled_when_supported(): persistent_store = StubFeatureStore() persistent_store.enable_monitoring() - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() td_synchronizer.update(td_synchronizer.flag("feature-flag").on(True)) data_system_config = DataSystemConfig( @@ -525,7 +525,7 @@ def test_data_store_status_monitoring_enabled_when_supported(): def test_no_persistent_store_status_provider_without_store(): """Test that data store status provider exists even without a persistent store""" - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() td_synchronizer.update(td_synchronizer.flag("feature-flag").on(True)) data_system_config = DataSystemConfig( @@ -556,7 +556,7 @@ def test_persistent_store_outage_recovery_flushes_on_recovery(): persistent_store = StubFeatureStore() # Create synchronizer with initial data - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() td_synchronizer.update(td_synchronizer.flag("feature-flag").on(True)) data_system_config = DataSystemConfig( @@ -610,7 +610,7 @@ def test_persistent_store_outage_recovery_no_flush_when_not_stale(): persistent_store = StubFeatureStore() - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() td_synchronizer.update(td_synchronizer.flag("feature-flag").on(True)) data_system_config = DataSystemConfig( @@ -644,7 +644,7 @@ def test_persistent_store_outage_recovery_no_flush_when_unavailable(): persistent_store = StubFeatureStore() - td_synchronizer = TestDataV2.data_source() + td_synchronizer = TestData.data_source() td_synchronizer.update(td_synchronizer.flag("feature-flag").on(True)) data_system_config = DataSystemConfig( @@ -822,7 +822,7 @@ def test_variation_does_not_throw_when_persistent_store_errors_during_warm_start data_store_mode=DataStoreMode.READ_ONLY, data_store=persistent_store, initializers=None, - synchronizers=[TestDataV2.data_source().builder], + synchronizers=[TestData.data_source().builder], ) fdv2 = FDv2(Config(sdk_key="dummy"), data_system_config) diff --git a/ldclient/testing/impl/datasystem/test_fdv2_status_lifecycle.py b/ldclient/testing/impl/datasystem/test_fdv2_status_lifecycle.py index 27b82039..8bc01913 100644 --- a/ldclient/testing/impl/datasystem/test_fdv2_status_lifecycle.py +++ b/ldclient/testing/impl/datasystem/test_fdv2_status_lifecycle.py @@ -15,7 +15,7 @@ from ldclient.config import Config, DataSourceBuilder, DataSystemConfig from ldclient.impl.datasystem.async_fdv2 import AsyncFDv2 from ldclient.impl.datasystem.fdv2 import FDv2 -from ldclient.integrations.test_datav2 import TestDataV2 +from ldclient.integrations.test_data import TestData from ldclient.interfaces import ( DataSourceErrorInfo, DataSourceErrorKind, @@ -72,8 +72,8 @@ def _failing_synchronizer() -> Mock: return synchronizer -def _test_data() -> TestDataV2: - td = TestDataV2.data_source() +def _test_data() -> TestData: + td = TestData.data_source() td.update(td.flag('flag').on(True)) return td diff --git a/ldclient/testing/impl/events/test_diagnostics.py b/ldclient/testing/impl/events/test_diagnostics.py index 32f2325a..fbdd7ac0 100644 --- a/ldclient/testing/impl/events/test_diagnostics.py +++ b/ldclient/testing/impl/events/test_diagnostics.py @@ -78,7 +78,7 @@ def test_create_diagnostic_config_custom(): flush_interval=1, stream_uri='https://test.com', poll_interval=60, - datasystem_config=datasystem.daemon(test_store).build(), + data_system=datasystem.daemon(test_store).build(), all_attributes_private=True, context_keys_capacity=10, context_keys_flush_interval=60, diff --git a/ldclient/testing/integrations/test_file_data_sourcev2.py b/ldclient/testing/integrations/test_file_data_source.py similarity index 91% rename from ldclient/testing/integrations/test_file_data_sourcev2.py rename to ldclient/testing/integrations/test_file_data_source.py index 10569d65..3cd880b1 100644 --- a/ldclient/testing/integrations/test_file_data_sourcev2.py +++ b/ldclient/testing/integrations/test_file_data_source.py @@ -126,10 +126,10 @@ def replace_file(path, content): def test_creates_valid_initializer(): - """Test that FileDataSourceV2 creates a working initializer.""" + """Test that FileDataSource creates a working initializer.""" path = make_temp_file(all_properties_json) try: - file_source = Files.new_data_source_v2(paths=[path]) + file_source = Files.new_data_source(paths=[path]) initializer = file_source.build(Config(sdk_key="dummy")) result = initializer.fetch(MockSelectorStore(Selector.no_selector())) @@ -158,7 +158,7 @@ def test_creates_valid_initializer(): def test_initializer_handles_missing_file(): """Test that initializer returns error for missing file.""" - file_source = Files.new_data_source_v2(paths=['no-such-file.json']) + file_source = Files.new_data_source(paths=['no-such-file.json']) initializer = file_source.build(Config(sdk_key="dummy")) result = initializer.fetch(MockSelectorStore(Selector.no_selector())) @@ -170,7 +170,7 @@ def test_initializer_handles_invalid_json(): """Test that initializer returns error for invalid JSON.""" path = make_temp_file('{"flagValues":{') try: - file_source = Files.new_data_source_v2(paths=[path]) + file_source = Files.new_data_source(paths=[path]) initializer = file_source.build(Config(sdk_key="dummy")) result = initializer.fetch(MockSelectorStore(Selector.no_selector())) @@ -185,7 +185,7 @@ def test_initializer_handles_duplicate_keys(): path1 = make_temp_file(flag_only_json) path2 = make_temp_file(flag_only_json) try: - file_source = Files.new_data_source_v2(paths=[path1, path2]) + file_source = Files.new_data_source(paths=[path1, path2]) initializer = file_source.build(Config(sdk_key="dummy")) result = initializer.fetch(MockSelectorStore(Selector.no_selector())) @@ -201,7 +201,7 @@ def test_initializer_loads_multiple_files(): path1 = make_temp_file(flag_only_json) path2 = make_temp_file(segment_only_json) try: - file_source = Files.new_data_source_v2(paths=[path1, path2]) + file_source = Files.new_data_source(paths=[path1, path2]) initializer = file_source.build(Config(sdk_key="dummy")) result = initializer.fetch(MockSelectorStore(Selector.no_selector())) @@ -225,7 +225,7 @@ def test_initializer_loads_yaml(): path = make_temp_file(all_properties_yaml) try: - file_source = Files.new_data_source_v2(paths=[path]) + file_source = Files.new_data_source(paths=[path]) initializer = file_source.build(Config(sdk_key="dummy")) result = initializer.fetch(MockSelectorStore(Selector.no_selector())) @@ -241,7 +241,7 @@ def test_initializer_handles_flag_values(): """Test that initializer properly converts flagValues to flags.""" path = make_temp_file(flag_values_only_json) try: - file_source = Files.new_data_source_v2(paths=[path]) + file_source = Files.new_data_source(paths=[path]) initializer = file_source.build(Config(sdk_key="dummy")) result = initializer.fetch(MockSelectorStore(Selector.no_selector())) @@ -262,10 +262,10 @@ def test_initializer_handles_flag_values(): def test_creates_valid_synchronizer(): - """Test that FileDataSourceV2 creates a working synchronizer.""" + """Test that FileDataSource creates a working synchronizer.""" path = make_temp_file(all_properties_json) try: - file_source = Files.new_data_source_v2(paths=[path], force_polling=True, poll_interval=0.1) + file_source = Files.new_data_source(paths=[path], force_polling=True, poll_interval=0.1) synchronizer = file_source.build(Config(sdk_key="dummy")) updates = [] @@ -309,7 +309,7 @@ def test_synchronizer_detects_file_changes(): """Test that synchronizer detects and reports file changes.""" path = make_temp_file(flag_only_json) try: - file_source = Files.new_data_source_v2(paths=[path], force_polling=True, poll_interval=0.1) + file_source = Files.new_data_source(paths=[path], force_polling=True, poll_interval=0.1) synchronizer = file_source.build(Config(sdk_key="dummy")) updates = [] @@ -357,7 +357,7 @@ def test_synchronizer_reports_error_on_invalid_file_update(): """Test that synchronizer reports error when file becomes invalid.""" path = make_temp_file(flag_only_json) try: - file_source = Files.new_data_source_v2(paths=[path], force_polling=True, poll_interval=0.1) + file_source = Files.new_data_source(paths=[path], force_polling=True, poll_interval=0.1) synchronizer = file_source.build(Config(sdk_key="dummy")) updates = [] @@ -402,7 +402,7 @@ def test_synchronizer_can_be_stopped(): """Test that synchronizer stops cleanly.""" path = make_temp_file(all_properties_json) try: - file_source = Files.new_data_source_v2(paths=[path]) + file_source = Files.new_data_source(paths=[path]) synchronizer = file_source.build(Config(sdk_key="dummy")) updates = [] @@ -436,7 +436,7 @@ def test_fetch_after_stop_returns_error(): """Test that fetch returns error after synchronizer is stopped.""" path = make_temp_file(all_properties_json) try: - file_source = Files.new_data_source_v2(paths=[path]) + file_source = Files.new_data_source(paths=[path]) initializer = file_source.build(Config(sdk_key="dummy")) # First fetch should work @@ -458,10 +458,10 @@ def test_source_name_property(): """Test that the data source has the correct name.""" path = make_temp_file(all_properties_json) try: - file_source = Files.new_data_source_v2(paths=[path]) + file_source = Files.new_data_source(paths=[path]) source = file_source.build(Config(sdk_key="dummy")) - assert source.name == "FileDataV2" + assert source.name == "FileData" finally: source.stop() os.remove(path) @@ -472,7 +472,7 @@ def test_accepts_single_path_string(): path = make_temp_file(flag_only_json) try: # Pass a single string instead of a list - file_source = Files.new_data_source_v2(paths=path) + file_source = Files.new_data_source(paths=path) initializer = file_source.build(Config(sdk_key="dummy")) result = initializer.fetch(MockSelectorStore(Selector.no_selector())) @@ -497,11 +497,11 @@ def test_initializer_does_not_allow_unsafe_yaml(): # This extended syntax defined by pyyaml allows arbitrary code execution. The data source # must use yaml.safe_load(), which does not support it. unsafe_yaml = ''' -!!python/object/apply:ldclient.testing.integrations.test_file_data_sourcev2.arbitrary_method_called_from_yaml ["hi"] +!!python/object/apply:ldclient.testing.integrations.test_file_data_source.arbitrary_method_called_from_yaml ["hi"] ''' path = make_temp_file(unsafe_yaml) try: - initializer = Files.new_data_source_v2(paths=[path]).build(Config(sdk_key="dummy")) + initializer = Files.new_data_source(paths=[path]).build(Config(sdk_key="dummy")) result = initializer.fetch(MockSelectorStore(Selector.no_selector())) assert isinstance(result, _Fail) finally: @@ -518,7 +518,7 @@ def has_segment(update): return update.change_set is not None and any(c.kind == ObjectKind.SEGMENT for c in update.change_set.changes) path = make_temp_file(flag_only_json) - synchronizer = Files.new_data_source_v2(paths=[path]).build(Config(sdk_key="dummy")) + synchronizer = Files.new_data_source(paths=[path]).build(Config(sdk_key="dummy")) try: initial = threading.Event() reloaded = threading.Event() diff --git a/ldclient/testing/integrations/test_test_data_sourcev2.py b/ldclient/testing/integrations/test_test_data_source.py similarity index 95% rename from ldclient/testing/integrations/test_test_data_sourcev2.py rename to ldclient/testing/integrations/test_test_data_source.py index e56e3ce8..a41e28d6 100644 --- a/ldclient/testing/integrations/test_test_data_sourcev2.py +++ b/ldclient/testing/integrations/test_test_data_source.py @@ -6,7 +6,7 @@ from ldclient.config import Config from ldclient.impl.util import _Fail, _Success -from ldclient.integrations.test_datav2 import FlagBuilderV2, TestDataV2 +from ldclient.integrations.test_data import FlagBuilder, TestData from ldclient.interfaces import ( ChangeType, DataSourceState, @@ -20,8 +20,8 @@ def test_creates_valid_initializer(): - """Test that TestDataV2 creates a working initializer""" - td = TestDataV2.data_source() + """Test that TestData creates a working initializer""" + td = TestData.data_source() initializer = td.builder.build(Config(sdk_key="dummy")) result = initializer.fetch(MockSelectorStore(Selector.no_selector())) @@ -35,8 +35,8 @@ def test_creates_valid_initializer(): def test_creates_valid_synchronizer(): - """Test that TestDataV2 creates a working synchronizer""" - td = TestDataV2.data_source() + """Test that TestData creates a working synchronizer""" + td = TestData.data_source() synchronizer = td.builder.build(Config(sdk_key="dummy")) updates = [] @@ -72,7 +72,7 @@ def collect_updates(): assert len(updates) == 1 -def verify_flag_builder_v2(desc: str, expected_props: dict, builder_actions: Callable[[FlagBuilderV2], FlagBuilderV2]): +def verify_flag_builder_v2(desc: str, expected_props: dict, builder_actions: Callable[[FlagBuilder], FlagBuilder]): """Helper function to verify flag builder behavior""" all_expected_props = { 'key': 'test-flag', @@ -89,7 +89,7 @@ def verify_flag_builder_v2(desc: str, expected_props: dict, builder_actions: Cal } all_expected_props.update(expected_props) - td = TestDataV2.data_source() + td = TestData.data_source() flag_builder = builder_actions(td.flag(key='test-flag')) built_flag = flag_builder._build(1) assert built_flag == all_expected_props, f"did not get expected flag properties for '{desc}' test" @@ -234,13 +234,13 @@ def verify_flag_builder_v2(desc: str, expected_props: dict, builder_actions: Cal pytest.param({}, lambda f: f.if_match_context('kind1', 'attr1', 'a').then_return(1).clear_rules(), id='clear rules'), ], ) -def test_flag_configs_parameterized_v2(expected_props: dict, builder_actions: Callable[[FlagBuilderV2], FlagBuilderV2]): +def test_flag_configs_parameterized_v2(expected_props: dict, builder_actions: Callable[[FlagBuilder], FlagBuilder]): verify_flag_builder_v2('x', expected_props, builder_actions) def test_initializer_fetches_flag_data(): """Test that initializer returns flag data correctly""" - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag('some-flag').variation_for_all(True)) initializer = td.builder.build(Config(sdk_key="dummy")) @@ -260,7 +260,7 @@ def test_initializer_fetches_flag_data(): def test_synchronizer_yields_initial_data(): """Test that synchronizer yields initial data correctly""" - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag('initial-flag').variation_for_all(False)) synchronizer = td.builder.build(Config(sdk_key="dummy")) @@ -281,7 +281,7 @@ def test_synchronizer_yields_initial_data(): def test_synchronizer_receives_updates(): """Test that synchronizer receives flag updates""" - td = TestDataV2.data_source() + td = TestData.data_source() synchronizer = td.builder.build(Config(sdk_key="dummy")) updates = [] @@ -325,7 +325,7 @@ def collect_updates(): def test_multiple_synchronizers_receive_updates(): """Test that multiple synchronizers receive the same updates""" - td = TestDataV2.data_source() + td = TestData.data_source() sync1 = td.builder.build(Config(sdk_key="dummy")) sync2 = td.builder.build(Config(sdk_key="dummy")) @@ -371,7 +371,7 @@ def collect_updates_2(): def test_closed_synchronizer_stops_yielding(): """Test that closed synchronizer stops yielding updates""" - td = TestDataV2.data_source() + td = TestData.data_source() synchronizer = td.builder.build(Config(sdk_key="dummy")) updates = [] @@ -396,12 +396,12 @@ def test_closed_synchronizer_stops_yielding(): # Should get exactly one error update indicating the synchronizer is closed assert len(additional_updates) == 1 assert additional_updates[0].state == DataSourceState.OFF - assert "TestDataV2 source has been closed" in additional_updates[0].error.message + assert "TestData source has been closed" in additional_updates[0].error.message def test_initializer_can_sync(): """Test that an initializer can call sync() and get initial data""" - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag('test-flag').variation_for_all(True)) initializer = td.builder.build(Config(sdk_key="dummy")) @@ -418,7 +418,7 @@ def test_initializer_can_sync(): def test_value_for_all(): """Test value_for_all method creates single-variation flag""" - td = TestDataV2.data_source() + td = TestData.data_source() flag = td.flag('value-flag').value_for_all('custom-value') built_flag = flag._build(1) @@ -428,7 +428,7 @@ def test_value_for_all(): def test_version_increment(): """Test that versions increment correctly""" - td = TestDataV2.data_source() + td = TestData.data_source() flag1 = td.flag('flag1').variation_for_all(True) td.update(flag1) @@ -443,7 +443,7 @@ def test_version_increment(): def test_error_handling_in_fetch(): """Test error handling in the fetch method""" - td = TestDataV2.data_source() + td = TestData.data_source() initializer = td.builder.build(Config(sdk_key="dummy")) # Close the initializer to trigger error condition @@ -451,4 +451,4 @@ def test_error_handling_in_fetch(): result = initializer.fetch(MockSelectorStore(Selector.no_selector())) assert isinstance(result, _Fail) - assert "TestDataV2 source has been closed" in result.error + assert "TestData source has been closed" in result.error diff --git a/ldclient/testing/test_async_client.py b/ldclient/testing/test_async_client.py index f4fdd287..40ac285d 100644 --- a/ldclient/testing/test_async_client.py +++ b/ldclient/testing/test_async_client.py @@ -11,7 +11,7 @@ from ldclient.async_client import AsyncLDClient from ldclient.async_config import AsyncConfig, AsyncDataSystemConfig from ldclient.context import Context -from ldclient.integrations.test_datav2 import TestDataV2 +from ldclient.integrations.test_data import TestData from ldclient.interfaces import DataStoreMode from ldclient.testing.mock_async_components import ( MockAsyncEventProcessor, @@ -26,12 +26,12 @@ def _offline_config(**kwargs): def _test_data_config(td=None, **kwargs): - """Return an AsyncConfig whose FDv2 data system syncs from TestDataV2.""" + """Return an AsyncConfig whose FDv2 data system syncs from TestData.""" if td is None: - td = TestDataV2.data_source() + td = TestData.data_source() return AsyncConfig( "test-sdk-key", - datasystem_config=AsyncDataSystemConfig(synchronizers=[td.async_builder]), + data_system=AsyncDataSystemConfig(synchronizers=[td.async_builder]), **kwargs, ) @@ -40,7 +40,7 @@ def _daemon_config(store, **kwargs): """Return an AsyncConfig whose FDv2 data system reads only from the given store.""" return AsyncConfig( "test-sdk-key", - datasystem_config=AsyncDataSystemConfig(data_store=store, data_store_mode=DataStoreMode.READ_ONLY), + data_system=AsyncDataSystemConfig(data_store=store, data_store_mode=DataStoreMode.READ_ONLY), **kwargs, ) @@ -101,10 +101,10 @@ async def test_default_variation_returns_default_when_not_started(): async def test_variation_returns_flag_value_when_initialized(): """After start(), variation() returns the flag value from the data source. - TestDataV2 supplies the flag without any network connection, so the + TestData supplies the flag without any network connection, so the client initializes as soon as the synchronizer delivers its basis. """ - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag('my-flag').value_for_all('hello')) client = AsyncLDClient(_test_data_config(td, send_events=False)) @@ -261,7 +261,7 @@ async def test_flag_tracker_available_before_start(): @pytest.mark.asyncio async def test_variation_detail_returns_reason(): """variation_detail() returns an EvaluationDetail with a non-None reason.""" - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag('detail-flag').value_for_all('hello')) async with AsyncLDClient(_test_data_config(td, send_events=False)) as client: @@ -490,7 +490,7 @@ async def test_cached_data_warnings_are_logged_once_per_client(caplog): client = AsyncLDClient(AsyncConfig( "test-sdk-key", send_events=False, - datasystem_config=AsyncDataSystemConfig( + data_system=AsyncDataSystemConfig( synchronizers=[_SilentAsyncSynchronizerBuilder()], data_store=store, data_store_mode=DataStoreMode.READ_ONLY, @@ -536,7 +536,7 @@ async def test_daemon_mode_does_not_log_cached_data_warnings(caplog): @pytest.mark.asyncio async def test_data_system_with_no_sources_and_no_store_logs_a_warning(caplog): caplog.set_level(logging.INFO) - client = AsyncLDClient(AsyncConfig("test-sdk-key", send_events=False, datasystem_config=AsyncDataSystemConfig())) + client = AsyncLDClient(AsyncConfig("test-sdk-key", send_events=False, data_system=AsyncDataSystemConfig())) await client.start(start_wait=0) await client.close() @@ -569,16 +569,16 @@ async def test_daemon_mode_logs_daemon_mode(caplog): def test_client_uses_the_default_data_system_when_none_is_set(): - from ldclient.impl.datasourcev2.async_polling import ( + from ldclient.impl.datasource.async_polling import ( AsyncFallbackToFDv1PollingDataSourceBuilder, AsyncPollingDataSourceBuilder ) - from ldclient.impl.datasourcev2.async_streaming import ( + from ldclient.impl.datasource.async_streaming import ( AsyncStreamingDataSourceBuilder ) client = AsyncLDClient(AsyncConfig("test-sdk-key", send_events=False)) - dsc = client._datasystem_config + dsc = client._data_system_config assert [type(b) for b in dsc.initializers] == [AsyncPollingDataSourceBuilder] assert [type(b) for b in dsc.synchronizers] == [AsyncStreamingDataSourceBuilder, AsyncPollingDataSourceBuilder] assert isinstance(dsc.fdv1_fallback_synchronizer, AsyncFallbackToFDv1PollingDataSourceBuilder) diff --git a/ldclient/testing/test_async_hooks.py b/ldclient/testing/test_async_hooks.py index b556bf7d..1ab085c9 100644 --- a/ldclient/testing/test_async_hooks.py +++ b/ldclient/testing/test_async_hooks.py @@ -144,7 +144,7 @@ def after_evaluation(self, series_context, data, detail): store._initialized = True config = AsyncConfig( "test-sdk-key", - datasystem_config=async_datasystem.daemon(store).build(), + data_system=async_datasystem.daemon(store).build(), send_events=False, hooks=[ContextVarHook()], ) @@ -234,7 +234,7 @@ async def get(self, kind, key): store._initialized = True config = AsyncConfig( "test-sdk-key", - datasystem_config=async_datasystem.daemon(store).build(), + data_system=async_datasystem.daemon(store).build(), send_events=False, hooks=[ContextVarHook()], ) diff --git a/ldclient/testing/test_async_ldclient_end_to_end_fdv2.py b/ldclient/testing/test_async_ldclient_end_to_end.py similarity index 92% rename from ldclient/testing/test_async_ldclient_end_to_end_fdv2.py rename to ldclient/testing/test_async_ldclient_end_to_end.py index aef068e8..09cd7b5c 100644 --- a/ldclient/testing/test_async_ldclient_end_to_end_fdv2.py +++ b/ldclient/testing/test_async_ldclient_end_to_end.py @@ -10,10 +10,10 @@ from ldclient.async_client import AsyncLDClient from ldclient.async_config import AsyncConfig, AsyncDataSystemConfig from ldclient.client import Context -from ldclient.impl.datasourcev2.async_polling import ( +from ldclient.impl.datasource.async_polling import ( AsyncPollingDataSourceBuilder ) -from ldclient.impl.datasourcev2.async_streaming import ( +from ldclient.impl.datasource.async_streaming import ( AsyncStreamingDataSourceBuilder ) from ldclient.testing.http_util import ( @@ -22,7 +22,7 @@ SequentialHandler, start_server ) -from ldclient.testing.test_ldclient_end_to_end_fdv2 import ( +from ldclient.testing.test_ldclient_end_to_end import ( always_true_flag, poll_response, sdk_key, @@ -38,7 +38,7 @@ def make_config(uri, synchronizer): base_uri=uri, stream_uri=uri, send_events=False, - datasystem_config=AsyncDataSystemConfig(synchronizers=[synchronizer]), + data_system=AsyncDataSystemConfig(synchronizers=[synchronizer]), ) @@ -109,7 +109,7 @@ async def test_async_client_fails_fast_in_polling_mode_with_401_error(): @pytest.mark.asyncio async def test_async_client_retries_poll_after_network_error(monkeypatch): # Lower the minimum poll interval so that the retry happens before the start wait ends. - monkeypatch.setattr('ldclient.impl.datasourcev2.async_polling.DEFAULT_POLL_INTERVAL', 0.05) + monkeypatch.setattr('ldclient.impl.datasource.async_polling.DEFAULT_POLL_INTERVAL', 0.05) with start_server() as server: server.for_path('/sdk/poll', SequentialHandler( CauseNetworkError(), CauseNetworkError(), CauseNetworkError(), poll_response([always_true_flag]))) diff --git a/ldclient/testing/test_config.py b/ldclient/testing/test_config.py index 29246f35..79046282 100644 --- a/ldclient/testing/test_config.py +++ b/ldclient/testing/test_config.py @@ -12,13 +12,13 @@ def test_with_wrapper_information(): dsc = datasystem.polling().build() - config = Config(sdk_key="SDK_KEY", datasystem_config=dsc, wrapper_name="original", wrapper_version="1.0.0") + config = Config(sdk_key="SDK_KEY", data_system=dsc, wrapper_name="original", wrapper_version="1.0.0") wrapped = config.with_wrapper_information("wrapper", "2.0.0") assert wrapped.wrapper_name == "wrapper" assert wrapped.wrapper_version == "2.0.0" assert wrapped.sdk_key == "SDK_KEY" - assert wrapped.datasystem_config is dsc + assert wrapped.data_system is dsc assert config.wrapper_name == "original" assert config.wrapper_version == "1.0.0" diff --git a/ldclient/testing/test_ldclient.py b/ldclient/testing/test_ldclient.py index 67af1414..521d5c29 100644 --- a/ldclient/testing/test_ldclient.py +++ b/ldclient/testing/test_ldclient.py @@ -6,13 +6,13 @@ from ldclient.client import Config, Context, LDClient from ldclient.datasystem import DataStoreMode from ldclient.feature_store import InMemoryFeatureStore -from ldclient.impl.datasourcev2.polling import ( +from ldclient.impl.datasource.polling import ( FallbackToFDv1PollingDataSourceBuilder, PollingDataSourceBuilder ) -from ldclient.impl.datasourcev2.streaming import StreamingDataSourceBuilder +from ldclient.impl.datasource.streaming import StreamingDataSourceBuilder from ldclient.impl.util import _Success -from ldclient.integrations.test_datav2 import TestDataV2 +from ldclient.integrations.test_data import TestData from ldclient.interfaces import ( Basis, BasisResult, @@ -46,7 +46,7 @@ def make_client(store=InMemoryFeatureStore()): events_uri=unreachable_uri, stream_uri=unreachable_uri, event_processor_class=MockEventProcessor, - datasystem_config=datasystem.daemon(store).build(), + data_system=datasystem.daemon(store).build(), ) ) @@ -58,7 +58,7 @@ def make_offline_client(): def make_daemon_client(store=None, **kwargs): config = Config( sdk_key="secret", - datasystem_config=datasystem.daemon(store or InMemoryFeatureStore()).build(), + data_system=datasystem.daemon(store or InMemoryFeatureStore()).build(), base_uri=unreachable_uri, events_uri=unreachable_uri, stream_uri=unreachable_uri, @@ -92,7 +92,7 @@ def count_events(c): def test_client_uses_the_default_data_system_when_none_is_set(): config = Config(sdk_key="secret", base_uri=unreachable_uri, stream_uri=unreachable_uri, send_events=False) with LDClient(config=config, start_wait=0) as client: - dsc = client._datasystem_config + dsc = client._data_system_config assert [type(b) for b in dsc.initializers] == [PollingDataSourceBuilder] assert [type(b) for b in dsc.synchronizers] == [StreamingDataSourceBuilder, PollingDataSourceBuilder] assert isinstance(dsc.fdv1_fallback_synchronizer, FallbackToFDv1PollingDataSourceBuilder) @@ -101,9 +101,9 @@ def test_client_uses_the_default_data_system_when_none_is_set(): def test_client_uses_the_configured_data_system(): dsc = datasystem.polling().build() - config = Config(sdk_key="secret", base_uri=unreachable_uri, send_events=False, datasystem_config=dsc) + config = Config(sdk_key="secret", base_uri=unreachable_uri, send_events=False, data_system=dsc) with LDClient(config=config, start_wait=0) as client: - assert client._datasystem_config is dsc + assert client._data_system_config is dsc def test_daemon_mode_client_is_initialized_with_an_empty_store(): @@ -127,7 +127,7 @@ def test_offline_mode_with_a_daemon_config_logs_only_offline_mode(caplog): def test_data_system_with_no_sources_and_no_store_logs_a_warning(caplog): - config = Config(sdk_key="secret", send_events=False, datasystem_config=datasystem.custom().build()) + config = Config(sdk_key="secret", send_events=False, data_system=datasystem.custom().build()) with LDClient(config=config, start_wait=0): pass assert "daemon mode" not in caplog.text @@ -147,10 +147,10 @@ def test_close_closes_the_persistent_store_in_daemon_mode(): def test_close_closes_the_persistent_store_with_a_synchronizer(): store = _ClosableStore() dsc = datasystem.custom() \ - .synchronizers(TestDataV2.data_source().builder) \ + .synchronizers(TestData.data_source().builder) \ .data_store(store, DataStoreMode.READ_WRITE) \ .build() - client = LDClient(config=Config(sdk_key="secret", send_events=False, datasystem_config=dsc)) + client = LDClient(config=Config(sdk_key="secret", send_events=False, data_system=dsc)) client.close() assert store.closed @@ -174,7 +174,7 @@ def test_defaults_and_online(): base_uri="http://localhost:3000", defaults={"foo": expected}, event_processor_class=MockEventProcessor, - datasystem_config=datasystem.daemon(InMemoryFeatureStore()).build(), + data_system=datasystem.daemon(InMemoryFeatureStore()).build(), ) ) actual = my_client.variation('foo', user, default="originalDefault") @@ -182,7 +182,7 @@ def test_defaults_and_online(): def test_defaults_and_online_no_default(): - my_client = LDClient(config=Config("SDK_KEY", base_uri="http://localhost:3000", defaults={"foo": "bar"}, event_processor_class=MockEventProcessor, datasystem_config=datasystem.daemon(InMemoryFeatureStore()).build())) + my_client = LDClient(config=Config("SDK_KEY", base_uri="http://localhost:3000", defaults={"foo": "bar"}, event_processor_class=MockEventProcessor, data_system=datasystem.daemon(InMemoryFeatureStore()).build())) assert "jim" == my_client.variation('baz', user, default="jim") @@ -242,7 +242,7 @@ def test_store_data_set_ordering(): .initializers([DependencyOrderingDataInitializerBuilder()]) \ .data_store(store, DataStoreMode.READ_WRITE) \ .build() - config = Config(sdk_key='SDK_KEY', send_events=False, datasystem_config=datasystem_config) + config = Config(sdk_key='SDK_KEY', send_events=False, data_system=datasystem_config) LDClient(config=config) data = store.received_data diff --git a/ldclient/testing/test_ldclient_end_to_end_fdv2.py b/ldclient/testing/test_ldclient_end_to_end.py similarity index 96% rename from ldclient/testing/test_ldclient_end_to_end_fdv2.py rename to ldclient/testing/test_ldclient_end_to_end.py index ac8f25ab..9417ba82 100644 --- a/ldclient/testing/test_ldclient_end_to_end_fdv2.py +++ b/ldclient/testing/test_ldclient_end_to_end.py @@ -15,7 +15,7 @@ from ldclient.config import Config, HTTPConfig from ldclient.feature_store import InMemoryFeatureStore from ldclient.hook import EvaluationSeriesContext, Hook, Metadata -from ldclient.integrations.test_datav2 import TestDataV2 +from ldclient.integrations.test_data import TestData from ldclient.testing.http_util import ( BasicResponse, CauseNetworkError, @@ -73,7 +73,7 @@ def make_config(uri, builder, **kwargs): base_uri=uri, stream_uri=uri, send_events=False, - datasystem_config=builder.build(), + data_system=builder.build(), **kwargs, ) @@ -113,7 +113,7 @@ def test_client_sends_event_without_diagnostics(): server.for_path('/sdk/poll', poll_response([always_true_flag])) events_server.for_path('/bulk', BasicResponse(202)) config = Config(sdk_key, base_uri=server.uri, events_uri=events_server.uri, diagnostic_opt_out=True, - datasystem_config=datasystem.polling().build()) + data_system=datasystem.polling().build()) with LDClient(config=config) as client: assert client.is_initialized() @@ -133,7 +133,7 @@ def test_client_sends_diagnostics(): server.for_path('/sdk/poll', poll_response([always_true_flag])) events_server.for_path('/diagnostic', BasicResponse(202)) config = Config(sdk_key, base_uri=server.uri, events_uri=events_server.uri, - datasystem_config=datasystem.polling().build()) + data_system=datasystem.polling().build()) with LDClient(config=config) as client: assert client.is_initialized() @@ -221,7 +221,7 @@ def test_client_retries_stream_after_recoverable_error(): def test_client_retries_poll_after_network_error(monkeypatch): # Lower the minimum poll interval so that the retry happens before the start wait ends. - monkeypatch.setattr('ldclient.impl.datasourcev2.polling.DEFAULT_POLL_INTERVAL', 0.05) + monkeypatch.setattr('ldclient.impl.datasource.polling.DEFAULT_POLL_INTERVAL', 0.05) with start_server() as server: # The requester retries once per poll, so two errors fail the whole first poll. server.for_path('/sdk/poll', SequentialHandler( @@ -405,7 +405,7 @@ def make_temp_file(content): def file_client(path): builder = datasystem.custom().synchronizers(datasystem.file_ds_builder([path])) - return LDClient(config=Config(sdk_key, send_events=False, datasystem_config=builder.build())) + return LDClient(config=Config(sdk_key, send_events=False, data_system=builder.build())) def test_evaluates_full_flag_from_file_data_source(): @@ -429,15 +429,15 @@ def test_evaluates_simplified_flag_from_file_data_source(): def make_test_data_client(td): builder = datasystem.custom().synchronizers(td.builder) - return LDClient(config=Config(sdk_key, send_events=False, datasystem_config=builder.build())) + return LDClient(config=Config(sdk_key, send_events=False, data_system=builder.build())) def rule_flag(td): return td.flag(key='test-flag').fallthrough_variation(False).if_match('firstName', 'Mike').and_not_match('country', 'gb').then_return(True) -def test_evaluates_flag_from_test_data_v2(): - td = TestDataV2.data_source() +def test_evaluates_flag_from_test_data(): + td = TestData.data_source() td.update(rule_flag(td)) with make_test_data_client(td) as client: @@ -456,8 +456,8 @@ def test_evaluates_flag_from_test_data_v2(): assert eval2.reason['kind'] == 'FALLTHROUGH' -def test_evaluates_all_flags_from_test_data_v2(): - td = TestDataV2.data_source() +def test_evaluates_all_flags_from_test_data(): + td = TestData.data_source() td.update(rule_flag(td)) with make_test_data_client(td) as client: diff --git a/ldclient/testing/test_ldclient_evaluation.py b/ldclient/testing/test_ldclient_evaluation.py index c68c1377..55afa0bf 100644 --- a/ldclient/testing/test_ldclient_evaluation.py +++ b/ldclient/testing/test_ldclient_evaluation.py @@ -169,7 +169,7 @@ def test_flag_using_big_segment(): segstore = MockBigSegmentStore() segstore.setup_metadata_always_up_to_date() segstore.setup_membership(_hash_for_user_key(user['key']), {_make_big_segment_ref(segment): True}) - config = Config(sdk_key='SDK_KEY', datasystem_config=datasystem.daemon(store).build(), big_segments=BigSegmentsConfig(store=segstore), event_processor_class=MockEventProcessor) + config = Config(sdk_key='SDK_KEY', data_system=datasystem.daemon(store).build(), big_segments=BigSegmentsConfig(store=segstore), event_processor_class=MockEventProcessor) with LDClient(config) as client: detail = client.variation_detail(flag['key'], user, False) assert detail.value is True @@ -480,7 +480,7 @@ def make_client_with_data_system(datasystem_config): events_uri=unreachable_uri, stream_uri=unreachable_uri, event_processor_class=MockEventProcessor, - datasystem_config=datasystem_config, + data_system=datasystem_config, ), start_wait=0, ) diff --git a/ldclient/testing/test_ldclient_events.py b/ldclient/testing/test_ldclient_events.py index bf07a102..9c22986d 100644 --- a/ldclient/testing/test_ldclient_events.py +++ b/ldclient/testing/test_ldclient_events.py @@ -41,7 +41,7 @@ def test_client_has_null_event_processor_if_offline(): def test_client_has_null_event_processor_if_send_events_off(): - config = Config(sdk_key="secret", base_uri=unreachable_uri, datasystem_config=datasystem.daemon(InMemoryFeatureStore()).build(), send_events=False) + config = Config(sdk_key="secret", base_uri=unreachable_uri, data_system=datasystem.daemon(InMemoryFeatureStore()).build(), send_events=False) with LDClient(config=config) as client: assert isinstance(client._event_processor, NullEventProcessor) diff --git a/ldclient/testing/test_ldclient_fork.py b/ldclient/testing/test_ldclient_fork.py index a019857d..d37a2244 100644 --- a/ldclient/testing/test_ldclient_fork.py +++ b/ldclient/testing/test_ldclient_fork.py @@ -16,7 +16,7 @@ from ldclient import datasystem from ldclient.client import Config, Context, LDClient from ldclient.feature_store import InMemoryFeatureStore -from ldclient.integrations.test_datav2 import TestDataV2 +from ldclient.integrations.test_data import TestData from ldclient.migrations import Stage from ldclient.testing.stub_util import MockEventProcessor @@ -34,7 +34,7 @@ def make_config(**kwargs) -> Config: events_uri=unreachable_uri, stream_uri=unreachable_uri, event_processor_class=MockEventProcessor, - datasystem_config=datasystem.custom().synchronizers(TestDataV2.data_source().builder).build(), + data_system=datasystem.custom().synchronizers(TestData.data_source().builder).build(), ) params.update(kwargs) return Config(**params) @@ -45,7 +45,7 @@ def make_client(**kwargs) -> LDClient: def make_daemon_client(**kwargs) -> LDClient: - return make_client(datasystem_config=datasystem.daemon(InMemoryFeatureStore()).build(), **kwargs) + return make_client(data_system=datasystem.daemon(InMemoryFeatureStore()).build(), **kwargs) def fork_warnings(caplog) -> list: diff --git a/ldclient/testing/test_ldclient_hooks.py b/ldclient/testing/test_ldclient_hooks.py index 56c0759e..2a562532 100644 --- a/ldclient/testing/test_ldclient_hooks.py +++ b/ldclient/testing/test_ldclient_hooks.py @@ -3,7 +3,7 @@ from ldclient import Config, Context, LDClient, datasystem from ldclient.evaluation import EvaluationDetail from ldclient.hook import EvaluationSeriesContext, Hook, Metadata -from ldclient.integrations.test_datav2 import TestDataV2 +from ldclient.integrations.test_data import TestData from ldclient.migrations import Stage @@ -30,7 +30,7 @@ def after_evaluation(self, series_context: EvaluationSeriesContext, data: dict, return self.__after_evaluation(series_context, data, detail) -def datasystem_config(td: TestDataV2): +def datasystem_config(td: TestData): return datasystem.custom().synchronizers(td.builder).build() @@ -45,7 +45,7 @@ def test_verify_hook_execution_order(): clientHook1 = MockHook(before_evaluation=record('clientHook1::before', calls), after_evaluation=record('clientHook1::after', calls)) clientHook2 = MockHook(before_evaluation=record('clientHook2::before', calls), after_evaluation=record('clientHook2::after', calls)) - config = Config('SDK_KEY', datasystem_config=datasystem_config(TestDataV2.data_source()), send_events=False, hooks=[configHook1, configHook2]) + config = Config('SDK_KEY', data_system=datasystem_config(TestData.data_source()), send_events=False, hooks=[configHook1, configHook2]) client = LDClient(config=config) client.add_hook(clientHook1) client.add_hook(clientHook2) @@ -59,7 +59,7 @@ def test_ignores_invalid_hooks(): calls = [] hook = MockHook(before_evaluation=record('before', calls), after_evaluation=record('after', calls)) - config = Config('SDK_KEY', datasystem_config=datasystem_config(TestDataV2.data_source()), send_events=False, hooks=[True, hook, 42]) + config = Config('SDK_KEY', data_system=datasystem_config(TestData.data_source()), send_events=False, hooks=[True, hook, 42]) client = LDClient(config=config) client.add_hook("Hook, Hook, give us the Hook!") client.add_hook(hook) @@ -74,10 +74,10 @@ def test_after_evaluation_receives_evaluation_detail(): details = [] hook = MockHook(before_evaluation=record('before', []), after_evaluation=lambda series_context, data, detail: details.append(detail)) - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag('flag-key').variation_for_all(True)) - config = Config('SDK_KEY', datasystem_config=datasystem_config(td), send_events=False, hooks=[hook]) + config = Config('SDK_KEY', data_system=datasystem_config(td), send_events=False, hooks=[hook]) client = LDClient(config=config) client.variation('flag-key', user, False) @@ -90,7 +90,7 @@ def test_passing_data_from_before_to_after(): calls = [] hook = MockHook(before_evaluation=lambda series_context, data: "from before", after_evaluation=lambda series_context, data, detail: calls.append(data)) - config = Config('SDK_KEY', datasystem_config=datasystem_config(TestDataV2.data_source()), send_events=False, hooks=[hook]) + config = Config('SDK_KEY', data_system=datasystem_config(TestData.data_source()), send_events=False, hooks=[hook]) client = LDClient(config=config) client.variation('flag-key', user, False) @@ -105,7 +105,7 @@ def raise_exception(series_context, data): calls = [] hook = MockHook(before_evaluation=raise_exception, after_evaluation=lambda series_context, data, detail: calls.append(data)) - config = Config('SDK_KEY', datasystem_config=datasystem_config(TestDataV2.data_source()), send_events=False, hooks=[hook]) + config = Config('SDK_KEY', data_system=datasystem_config(TestData.data_source()), send_events=False, hooks=[hook]) client = LDClient(config=config) client.variation('flag-key', user, False) @@ -122,7 +122,7 @@ def raise_exception(series_context, data): hook2 = MockHook(before_evaluation=raise_exception, after_evaluation=lambda series_context, data, detail: calls.append(data)) hook3 = MockHook(before_evaluation=lambda series_context, data: "third hook", after_evaluation=lambda series_context, data, detail: calls.append(data)) - config = Config('SDK_KEY', datasystem_config=datasystem_config(TestDataV2.data_source()), send_events=False, hooks=[hook1, hook2, hook3]) + config = Config('SDK_KEY', data_system=datasystem_config(TestData.data_source()), send_events=False, hooks=[hook1, hook2, hook3]) client = LDClient(config=config) client.variation('flag-key', user, False) @@ -138,10 +138,10 @@ def test_migration_evaluation_detail_contains_stage_value(): details = [] hook = MockHook(before_evaluation=record('before', []), after_evaluation=lambda series_context, data, detail: details.append(detail)) - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag('flag-key').variations("off").variation_for_all(0)) - config = Config('SDK_KEY', datasystem_config=datasystem_config(td), send_events=False, hooks=[hook]) + config = Config('SDK_KEY', data_system=datasystem_config(td), send_events=False, hooks=[hook]) client = LDClient(config=config) client.migration_variation('flag-key', user, Stage.LIVE) @@ -154,10 +154,10 @@ def test_migration_evaluation_detail_gets_default_if_flag_isnt_migration_flag(): details = [] hook = MockHook(before_evaluation=record('before', []), after_evaluation=lambda series_context, data, detail: details.append(detail)) - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag('flag-key').variations("nonstage").variation_for_all(0)) - config = Config('SDK_KEY', datasystem_config=datasystem_config(td), send_events=False, hooks=[hook]) + config = Config('SDK_KEY', data_system=datasystem_config(td), send_events=False, hooks=[hook]) client = LDClient(config=config) client.migration_variation('flag-key', user, Stage.LIVE) @@ -170,10 +170,10 @@ def test_migration_evaluation_detail_default_converts_to_off_if_invalid(): details = [] hook = MockHook(before_evaluation=record('before', []), after_evaluation=lambda series_context, data, detail: details.append(detail)) - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag('flag-key').variations("nonstage").variation_for_all(0)) - config = Config('SDK_KEY', datasystem_config=datasystem_config(td), send_events=False, hooks=[hook]) + config = Config('SDK_KEY', data_system=datasystem_config(td), send_events=False, hooks=[hook]) client = LDClient(config=config) client.migration_variation('flag-key', user, "invalid") @@ -186,10 +186,10 @@ def test_series_context_environment_id_is_none_without_environment_id(): contexts = [] hook = MockHook(before_evaluation=lambda series_context, data: contexts.append(series_context), after_evaluation=record('after', [])) - td = TestDataV2.data_source() + td = TestData.data_source() td.update(td.flag('flag-key').variation_for_all(True)) - config = Config('SDK_KEY', datasystem_config=datasystem_config(td), send_events=False, hooks=[hook]) + config = Config('SDK_KEY', data_system=datasystem_config(td), send_events=False, hooks=[hook]) client = LDClient(config=config) client.variation('flag-key', user, False) diff --git a/ldclient/testing/test_ldclient_listeners.py b/ldclient/testing/test_ldclient_listeners.py index c4d0ad4d..4bb0068c 100644 --- a/ldclient/testing/test_ldclient_listeners.py +++ b/ldclient/testing/test_ldclient_listeners.py @@ -17,7 +17,7 @@ def make_fdv2_full_transfer_events() -> str: def test_big_segment_store_status_unavailable(): - config = Config(sdk_key='SDK_KEY', event_processor_class=MockEventProcessor, datasystem_config=datasystem.custom().build()) + config = Config(sdk_key='SDK_KEY', event_processor_class=MockEventProcessor, data_system=datasystem.custom().build()) client = LDClient(config) assert client.big_segment_store_status_provider.status.available is False @@ -25,7 +25,7 @@ def test_big_segment_store_status_unavailable(): def test_big_segment_store_status_updates(): segstore = MockBigSegmentStore() segstore.setup_metadata_always_up_to_date() - config = Config(sdk_key='SDK_KEY', big_segments=BigSegmentsConfig(store=segstore, status_poll_interval=0.01), event_processor_class=MockEventProcessor, datasystem_config=datasystem.custom().build()) + config = Config(sdk_key='SDK_KEY', big_segments=BigSegmentsConfig(store=segstore, status_poll_interval=0.01), event_processor_class=MockEventProcessor, data_system=datasystem.custom().build()) statuses = Queue() with LDClient(config) as client: @@ -50,7 +50,7 @@ def test_big_segment_store_status_updates(): def test_data_source_status_default(): - config = Config(sdk_key='SDK_KEY', event_processor_class=MockEventProcessor, datasystem_config=datasystem.custom().build()) + config = Config(sdk_key='SDK_KEY', event_processor_class=MockEventProcessor, data_system=datasystem.custom().build()) client = LDClient(config) assert client.data_source_status_provider.status.state == DataSourceState.INITIALIZING @@ -59,7 +59,7 @@ def test_data_source_status_updates(): with start_server() as stream_server: with stream_content(make_fdv2_full_transfer_events()) as stream_handler: stream_server.for_path('/sdk/stream', stream_handler) - config = Config(sdk_key='sdk-key', stream_uri=stream_server.uri, send_events=False, datasystem_config=datasystem.streaming().build()) + config = Config(sdk_key='sdk-key', stream_uri=stream_server.uri, send_events=False, data_system=datasystem.streaming().build()) with LDClient(config=config) as client: assert client.data_source_status_provider.status.state == DataSourceState.VALID diff --git a/ldclient/testing/test_ldclient_singleton.py b/ldclient/testing/test_ldclient_singleton.py index 83e0a220..56ac9582 100644 --- a/ldclient/testing/test_ldclient_singleton.py +++ b/ldclient/testing/test_ldclient_singleton.py @@ -20,7 +20,7 @@ def make_fdv2_full_transfer_events() -> str: def make_streaming_config(key: str, stream_uri: str) -> Config: - return Config(key, stream_uri=stream_uri, send_events=False, datasystem_config=datasystem.streaming().build()) + return Config(key, stream_uri=stream_uri, send_events=False, data_system=datasystem.streaming().build()) def test_set_sdk_key_before_init():