diff --git a/contract-tests/client_entity.rb b/contract-tests/client_entity.rb index a5768ef0..ba012107 100644 --- a/contract-tests/client_entity.rb +++ b/contract-tests/client_entity.rb @@ -52,10 +52,10 @@ def initialize(log, config) data_system.fdv1_compatible_synchronizer(build_fdv1_fallback_builder(fdv1_fallback_config)) end - opts[:data_system_config] = data_system.build + opts[:data_system] = data_system.build else # Without a data system configuration, the client does not connect to LaunchDarkly for data. - opts[:data_system_config] = LaunchDarkly::DataSystem.custom.build + opts[:data_system] = LaunchDarkly::DataSystem.custom.build end if config[:events] diff --git a/lib/ldclient-rb/config.rb b/lib/ldclient-rb/config.rb index ce0950ed..c324c02b 100644 --- a/lib/ldclient-rb/config.rb +++ b/lib/ldclient-rb/config.rb @@ -37,7 +37,7 @@ class Config # @option opts [BigSegmentsConfig] :big_segments See {#big_segments}. # @option opts [Hash] :application See {#application} # @option opts [Boolean] :omit_anonymous_contexts See {#omit_anonymous_contexts} - # @option opts [DataSystemConfig] :data_system_config See {#data_system_config} + # @option opts [DataSystemConfig] :data_system See {#data_system} # @option hooks [Array e - Impl::Util.log_exception(@logger, "Unexpected exception in FileDataSourcePollerV2", e) + Impl::Util.log_exception(@logger, "Unexpected exception in FileDataSourcePoller", e) end end end - @thread.name = "LD/FileDataSourceV2" + @thread.name = "LD/FileDataSource" end def stop diff --git a/lib/ldclient-rb/impl/integrations/test_data/test_data_source_v2.rb b/lib/ldclient-rb/impl/integrations/test_data/test_data_source.rb similarity index 96% rename from lib/ldclient-rb/impl/integrations/test_data/test_data_source_v2.rb rename to lib/ldclient-rb/impl/integrations/test_data/test_data_source.rb index 990ef572..982194cb 100644 --- a/lib/ldclient-rb/impl/integrations/test_data/test_data_source_v2.rb +++ b/lib/ldclient-rb/impl/integrations/test_data/test_data_source.rb @@ -9,19 +9,19 @@ module Impl module Integrations module TestData # - # 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. # - class TestDataSourceV2 + class TestDataSource include LaunchDarkly::Interfaces::DataSystem::Initializer include LaunchDarkly::Interfaces::DataSystem::Synchronizer # @api private # - # @param test_data [LaunchDarkly::Integrations::TestDataV2] the test data instance + # @param test_data [LaunchDarkly::Integrations::TestData] the test data instance # def initialize(test_data) @test_data = test_data @@ -36,7 +36,7 @@ def initialize(test_data) # @return [String] # def name - 'TestDataV2' + 'TestData' end # @@ -131,7 +131,7 @@ def stop end # - # 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. @@ -187,7 +187,7 @@ def upsert_flag(flag_data) end # - # Called by TestDataV2 when a segment is updated. + # Called by TestData when a segment is updated. # # This method converts the segment update into an FDv2 changeset and # queues it for delivery through the sync() generator. @@ -251,7 +251,7 @@ def upsert_segment(segment_data) begin @lock.synchronize do if @closed - next LaunchDarkly::Result.fail('TestDataV2 source has been closed') + next LaunchDarkly::Result.fail('TestData source has been closed') end init_data, version = yield diff --git a/lib/ldclient-rb/integrations.rb b/lib/ldclient-rb/integrations.rb index d8ff7488..aa5122ef 100644 --- a/lib/ldclient-rb/integrations.rb +++ b/lib/ldclient-rb/integrations.rb @@ -2,5 +2,5 @@ require "ldclient-rb/integrations/dynamodb" require "ldclient-rb/integrations/file_data" require "ldclient-rb/integrations/redis" -require "ldclient-rb/integrations/test_data_v2" +require "ldclient-rb/integrations/test_data" require "ldclient-rb/integrations/util/persistent_data_store_wrapper" diff --git a/lib/ldclient-rb/integrations/dynamodb.rb b/lib/ldclient-rb/integrations/dynamodb.rb index 92416ab6..4aa21bcc 100644 --- a/lib/ldclient-rb/integrations/dynamodb.rb +++ b/lib/ldclient-rb/integrations/dynamodb.rb @@ -23,7 +23,7 @@ module DynamoDB # # @example Configuring the feature store # store = LaunchDarkly::Integrations::DynamoDB::new_feature_store("my-table-name") - # config = LaunchDarkly::Config.new(data_system_config: LaunchDarkly::DataSystem.persistent_store(store).build) + # config = LaunchDarkly::Config.new(data_system: LaunchDarkly::DataSystem.persistent_store(store).build) # client = LaunchDarkly::LDClient.new(my_sdk_key, config) # # Note that the specified table must already exist in DynamoDB. It must have a partition key called diff --git a/lib/ldclient-rb/integrations/file_data.rb b/lib/ldclient-rb/integrations/file_data.rb index 7b48dc4e..e2139b00 100644 --- a/lib/ldclient-rb/integrations/file_data.rb +++ b/lib/ldclient-rb/integrations/file_data.rb @@ -1,4 +1,4 @@ -require 'ldclient-rb/impl/integrations/file_data_source_v2' +require 'ldclient-rb/impl/integrations/file_data_source' module LaunchDarkly module Integrations @@ -9,13 +9,13 @@ module Integrations # Reading flags from a file is only intended for pre-production environments. Production # environments should always be configured to receive flag updates from LaunchDarkly. # - # To use this component, call {FileData.data_source_v2}, and use its return value as an + # To use this component, call {FileData.data_source}, and use its return value as an # initializer or synchronizer in the data system configuration. In the options to - # `data_source_v2`, set `paths` to the file path(s) of your data file(s): + # `data_source`, set `paths` to the file path(s) of your data file(s): # - # file_source = LaunchDarkly::Integrations::FileData.data_source_v2(paths: [ myFilePath ]) + # file_source = LaunchDarkly::Integrations::FileData.data_source(paths: [ myFilePath ]) # data_system = LaunchDarkly::DataSystem.custom.synchronizers([file_source]).build - # config = LaunchDarkly::Config.new(data_system_config: data_system) + # config = LaunchDarkly::Config.new(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 @@ -96,49 +96,49 @@ module FileData # @option options [Float] :poll_interval The minimum interval, in seconds, between checks for # file modifications - used only if the native file-watching mechanism from 'listen' is not # being used. The default value is 1 second. - # @return [FileDataSourceV2Builder] a builder that can be used as an FDv2 initializer or synchronizer + # @return [FileDataSourceBuilder] a builder that can be used as an FDv2 initializer or synchronizer # # @example Using as an initializer - # file_source = LaunchDarkly::Integrations::FileData.data_source_v2(paths: ['flags.json']) + # file_source = LaunchDarkly::Integrations::FileData.data_source(paths: ['flags.json']) # data_system_config = LaunchDarkly::DataSystemConfig.new( # initializers: [file_source] # ) # config = LaunchDarkly::Config.new(data_system: data_system_config) # # @example Using as a synchronizer - # file_source = LaunchDarkly::Integrations::FileData.data_source_v2(paths: ['flags.json']) + # file_source = LaunchDarkly::Integrations::FileData.data_source(paths: ['flags.json']) # data_system_config = LaunchDarkly::DataSystemConfig.new( # synchronizers: [file_source] # ) # config = LaunchDarkly::Config.new(data_system: data_system_config) # # @example Using as both initializer and synchronizer - # file_source = LaunchDarkly::Integrations::FileData.data_source_v2(paths: ['flags.json']) + # file_source = LaunchDarkly::Integrations::FileData.data_source(paths: ['flags.json']) # data_system_config = LaunchDarkly::DataSystemConfig.new( # initializers: [file_source], # synchronizers: [file_source] # ) # config = LaunchDarkly::Config.new(data_system: data_system_config) # - def self.data_source_v2(options = {}) + def self.data_source(options = {}) paths = options[:paths] || [] poll_interval = options[:poll_interval] || 1 - FileDataSourceV2Builder.new(paths, poll_interval) + FileDataSourceBuilder.new(paths, poll_interval) end end # - # Builder for FileDataSourceV2. + # Builder for FileDataSource. # - class FileDataSourceV2Builder + class FileDataSourceBuilder def initialize(paths, poll_interval) @paths = paths @poll_interval = poll_interval end def build(_sdk_key, config) - Impl::Integrations::FileDataSourceV2.new( + Impl::Integrations::FileDataSource.new( config.logger, paths: @paths, poll_interval: @poll_interval diff --git a/lib/ldclient-rb/integrations/redis.rb b/lib/ldclient-rb/integrations/redis.rb index ce272d55..6188f1d1 100644 --- a/lib/ldclient-rb/integrations/redis.rb +++ b/lib/ldclient-rb/integrations/redis.rb @@ -42,7 +42,7 @@ def self.default_prefix # # @example Configuring the feature store # store = LaunchDarkly::Integrations::Redis::new_feature_store(redis_url: "redis://my-server") - # config = LaunchDarkly::Config.new(data_system_config: LaunchDarkly::DataSystem.persistent_store(store).build) + # config = LaunchDarkly::Config.new(data_system: LaunchDarkly::DataSystem.persistent_store(store).build) # client = LaunchDarkly::LDClient.new(my_sdk_key, config) # # @param opts [Hash] the configuration options diff --git a/lib/ldclient-rb/integrations/test_data_v2.rb b/lib/ldclient-rb/integrations/test_data.rb similarity index 87% rename from lib/ldclient-rb/integrations/test_data_v2.rb rename to lib/ldclient-rb/integrations/test_data.rb index e742d3d5..39ecfd83 100644 --- a/lib/ldclient-rb/integrations/test_data_v2.rb +++ b/lib/ldclient-rb/integrations/test_data.rb @@ -1,7 +1,7 @@ -require 'ldclient-rb/impl/integrations/test_data/test_data_source_v2' +require 'ldclient-rb/impl/integrations/test_data/test_data_source' require 'ldclient-rb/impl/model/feature_flag' require 'ldclient-rb/impl/model/serialization' -require 'ldclient-rb/integrations/test_data_v2/flag_builder_v2' +require 'ldclient-rb/integrations/test_data/flag_builder' require 'concurrent/atomics' require 'json' require 'set' @@ -16,12 +16,12 @@ module Integrations # provides only the data that the application has put into it using the {#update} method. # # @example - # require 'ldclient-rb/integrations/test_data_v2' + # require 'ldclient-rb/integrations/test_data' # - # td = LaunchDarkly::Integrations::TestDataV2.data_source + # td = LaunchDarkly::Integrations::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 # # Note: This example assumes FDv2 data system configuration is available # # data_config = LaunchDarkly::Impl::DataSystem::Config.custom # # data_config.initializers([td.method(:build_initializer)]) @@ -29,7 +29,7 @@ module Integrations # # # config = LaunchDarkly::Config.new( # # sdk_key, - # # data_system_config: data_config.build + # # data_system: data_config.build # # ) # # # flags can be updated at any time: @@ -38,17 +38,17 @@ module Integrations # .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. # - class TestDataV2 + class TestData # Creates a new instance of the test data source. # - # @return [TestDataV2] a new configurable test data source + # @return [TestData] a new configurable test data source def self.data_source self.new end @@ -67,20 +67,20 @@ def initialize end # - # 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 contexts 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}. # # @param key [String] the flag key - # @return [FlagBuilderV2] a flag configuration builder + # @return [FlagBuilder] a flag configuration builder # def flag(key) existing_builder = @lock.with_read_lock do @@ -92,7 +92,7 @@ def flag(key) end if existing_builder.nil? - LaunchDarkly::Integrations::TestDataV2::FlagBuilderV2.new(key).boolean_flag + LaunchDarkly::Integrations::TestData::FlagBuilder.new(key).boolean_flag else existing_builder.clone end @@ -103,29 +103,29 @@ def flag(key) # # 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 [FlagBuilderV2] a flag configuration builder - # @return [TestDataV2] the TestDataV2 instance + # @param flag_builder [FlagBuilder] a flag configuration builder + # @return [TestData] the TestData instance # def update(flag_builder) @update_lock.synchronize do instances_copy = [] new_flag = nil @lock.with_write_lock do - flag_key = flag_builder._key.to_sym + flag_key = flag_builder.key.to_sym old_flag = @current_flags[flag_key] old_version = old_flag ? old_flag[:version] : 0 new_flag = flag_builder.build(old_version + 1) @current_flags[flag_key] = new_flag - @flag_builders[flag_builder._key] = flag_builder.clone + @flag_builders[flag_builder.key] = flag_builder.clone # Create a copy of instances while holding the lock to avoid race conditions instances_copy = @instances.dup @@ -159,7 +159,7 @@ def get_version end # @api private - # @param instance [LaunchDarkly::Impl::Integrations::TestData::TestDataSourceV2] the TestDataSourceV2 instance to remove + # @param instance [LaunchDarkly::Impl::Integrations::TestData::TestDataSource] the TestDataSource instance to remove def closed_instance(instance) @lock.with_write_lock do @instances.delete(instance) if @instances.include?(instance) @@ -171,7 +171,7 @@ def closed_instance(instance) # Adds an instance and takes the current data in one step. The instance then receives each # change that the returned data does not hold, and no change that it holds. # - # @param instance [LaunchDarkly::Impl::Integrations::TestData::TestDataSourceV2] the TestDataSourceV2 instance to add + # @param instance [LaunchDarkly::Impl::Integrations::TestData::TestDataSource] the TestDataSource instance to add # @return [Array(Hash, Integer)] the data, in the form of {#make_init_data}, and the next version def subscribe(instance) @lock.with_write_lock do @@ -186,12 +186,12 @@ def subscribe(instance) # Copies a full feature flag data model object into the test data. # # It immediately propagates the change to any `LDClient` instance(s) that you have already - # configured to use this `TestDataV2`. If no `LDClient` has been started yet, it simply adds + # 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. # # Use this method if you need to use advanced flag configuration properties that are not supported by - # the simplified {FlagBuilderV2} API. Otherwise use the regular {#flag}/{#update} mechanism to avoid + # the simplified {FlagBuilder} API. Otherwise use the regular {#flag}/{#update} mechanism to avoid # dependencies on details of the data model. # # You cannot make incremental changes with {#flag}/{#update} to a flag that you add in this way. @@ -205,7 +205,7 @@ def subscribe(instance) # # @param flag [Hash, String, LaunchDarkly::Impl::Model::FeatureFlag] the flag configuration as a hash # with symbol or string keys, a JSON string, or a FeatureFlag model object. - # @return [TestDataV2] the TestDataV2 instance + # @return [TestData] the TestData instance # @raise [ArgumentError] if the flag is not a valid flag configuration # def use_preconfigured_flag(flag) @@ -237,7 +237,7 @@ def use_preconfigured_flag(flag) # Copies a full segment data model object into the test data. # # It immediately propagates the change to any `LDClient` instance(s) that you have already - # configured to use this `TestDataV2`. If no `LDClient` has been started yet, it simply adds + # configured to use this `TestData`. If no `LDClient` has been started yet, it simply adds # this segment to the test data which will be provided to any LDClient that you subsequently # configure. # @@ -252,7 +252,7 @@ def use_preconfigured_flag(flag) # # @param segment [Hash, String, LaunchDarkly::Impl::Model::Segment] the segment configuration as a hash # with symbol or string keys, a JSON string, or a Segment model object. - # @return [TestDataV2] the TestDataV2 instance + # @return [TestData] the TestData instance # @raise [ArgumentError] if the segment is not a valid segment configuration # def use_preconfigured_segment(segment) @@ -380,17 +380,17 @@ def use_preconfigured_segment(segment) # Returns a builder for creating a data source that can be used with the FDv2 data system # as either an initializer or synchronizer. # - # @return [TestDataV2Builder] a builder for a test data source + # @return [TestDataBuilder] a builder for a test data source # def test_data_ds_builder - TestDataV2Builder.new(self) + TestDataBuilder.new(self) end end # - # Builder for TestDataV2 data sources (works for both initializers and synchronizers). + # Builder for TestData data sources (works for both initializers and synchronizers). # - class TestDataV2Builder + class TestDataBuilder def initialize(test_data) @test_data = test_data end @@ -400,10 +400,10 @@ def initialize(test_data) # # @param sdk_key [String] the SDK key (unused, for interface compatibility) # @param config [LaunchDarkly::Config] the SDK configuration (unused, for interface compatibility) - # @return [LaunchDarkly::Impl::Integrations::TestData::TestDataSourceV2] a test data source + # @return [LaunchDarkly::Impl::Integrations::TestData::TestDataSource] a test data source # def build(sdk_key, config) - LaunchDarkly::Impl::Integrations::TestData::TestDataSourceV2.new(@test_data) + LaunchDarkly::Impl::Integrations::TestData::TestDataSource.new(@test_data) end end end diff --git a/lib/ldclient-rb/integrations/test_data_v2/flag_builder_v2.rb b/lib/ldclient-rb/integrations/test_data/flag_builder.rb similarity index 90% rename from lib/ldclient-rb/integrations/test_data_v2/flag_builder_v2.rb rename to lib/ldclient-rb/integrations/test_data/flag_builder.rb index b279b5fe..3ef3bab1 100644 --- a/lib/ldclient-rb/integrations/test_data_v2/flag_builder_v2.rb +++ b/lib/ldclient-rb/integrations/test_data/flag_builder.rb @@ -4,7 +4,7 @@ module LaunchDarkly module Integrations - class TestDataV2 + class TestData # Constants for boolean flag variation indices TRUE_VARIATION_INDEX = 0 FALSE_VARIATION_INDEX = 1 @@ -15,18 +15,18 @@ def self.variation_for_boolean(variation) end # - # A builder for feature flag configurations to be used with {TestDataV2}. + # A builder for feature flag configurations to be used with {TestData}. # - # @see TestDataV2#flag - # @see TestDataV2#update + # @see TestData#flag + # @see TestData#update # - class FlagBuilderV2 - # @api private - attr_reader :_key + class FlagBuilder + # @return [String] the flag key + attr_reader :key # @api private def initialize(key) - @_key = key + @key = key @_on = true @_variations = [] @_off_variation = nil @@ -39,7 +39,7 @@ def initialize(key) end # Creates a deep copy of the flag builder when the object is duplicated or cloned. - # Subsequent updates to the original `FlagBuilderV2` object will not update the + # Subsequent updates to the original `FlagBuilder` object will not update the # copy and vice versa. # # This method is automatically invoked by Ruby's `dup` and `clone` methods. @@ -59,11 +59,11 @@ def initialize_copy(other) # # 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 - # {TestDataV2#flag} with a new flag key, the flag will return `false` + # {TestData#flag} with a new flag key, the flag will return `false` # whenever targeting is off, and `true` when targeting is on. # # @param on [Boolean] true if targeting should be on - # @return [FlagBuilderV2] the flag builder + # @return [FlagBuilder] the flag builder # def on(on) @_on = on @@ -80,11 +80,11 @@ def on(on) # # @param variation [Boolean, Integer] true or false or the desired fallthrough variation index: # 0 for the first, 1 for the second, etc. - # @return [FlagBuilderV2] the flag builder + # @return [FlagBuilder] the flag builder # def fallthrough_variation(variation) if LaunchDarkly::Impl::Util.bool?(variation) - boolean_flag.fallthrough_variation(TestDataV2.variation_for_boolean(variation)) + boolean_flag.fallthrough_variation(TestData.variation_for_boolean(variation)) else @_fallthrough_variation = variation self @@ -100,11 +100,11 @@ def fallthrough_variation(variation) # # @param variation [Boolean, Integer] true or false or the desired off variation index: # 0 for the first, 1 for the second, etc. - # @return [FlagBuilderV2] the flag builder + # @return [FlagBuilder] the flag builder # def off_variation(variation) if LaunchDarkly::Impl::Util.bool?(variation) - boolean_flag.off_variation(TestDataV2.variation_for_boolean(variation)) + boolean_flag.off_variation(TestData.variation_for_boolean(variation)) else @_off_variation = variation self @@ -115,7 +115,7 @@ def off_variation(variation) # Sets the migration settings for this flag. # # @param settings [Hash, nil] the settings from {FlagMigrationSettingsBuilder#build} - # @return [FlagBuilderV2] the flag builder + # @return [FlagBuilder] the flag builder # def migration_settings(settings) @_migration_settings = settings @@ -129,7 +129,7 @@ def migration_settings(settings) # General usage does not require this method. # # @param ratio [Integer] - # @return [FlagBuilderV2] the flag builder + # @return [FlagBuilder] the flag builder # def sampling_ratio(ratio) @_sampling_ratio = ratio @@ -143,7 +143,7 @@ def sampling_ratio(ratio) # General usage does not require this method. # # @param exclude [Boolean] - # @return [FlagBuilderV2] the flag builder + # @return [FlagBuilder] the flag builder # def exclude_from_summaries(exclude) @_exclude_from_summaries = exclude @@ -153,13 +153,13 @@ def exclude_from_summaries(exclude) # # A shortcut for setting the flag to use the standard boolean configuration. # - # This is the default for all new flags created with {TestDataV2#flag}. + # This is the default for all new flags created with {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 # if no other settings specify otherwise. # - # @return [FlagBuilderV2] the flag builder + # @return [FlagBuilder] the flag builder # def boolean_flag return self if boolean_flag? @@ -181,7 +181,7 @@ def boolean_flag # td.flag('new-flag').variations('red', 'green', 'blue') # # @param variations [Array] the desired variations - # @return [FlagBuilderV2] the flag builder + # @return [FlagBuilder] the flag builder # def variations(*variations) @_variations = variations @@ -199,11 +199,11 @@ def variations(*variations) # # @param variation [Boolean, Integer] true or false or the desired variation index to return: # 0 for the first, 1 for the second, etc. - # @return [FlagBuilderV2] the flag builder + # @return [FlagBuilder] the flag builder # def variation_for_all(variation) if LaunchDarkly::Impl::Util.bool?(variation) - return boolean_flag.variation_for_all(TestDataV2.variation_for_boolean(variation)) + return boolean_flag.variation_for_all(TestData.variation_for_boolean(variation)) end clear_rules.clear_targets.on(true).fallthrough_variation(variation) @@ -218,7 +218,7 @@ def variation_for_all(variation) # are removed. # # @param value [Object] the desired value to be returned for all contexts - # @return [FlagBuilderV2] the flag builder + # @return [FlagBuilder] the flag builder # def value_for_all(value) variations(value).variation_for_all(0).off_variation(0) @@ -239,7 +239,7 @@ def value_for_all(value) # @param user_key [String] a user key # @param variation [Boolean, Integer] true or false or the desired variation index to return: # 0 for the first, 1 for the second, etc. - # @return [FlagBuilderV2] the flag builder + # @return [FlagBuilder] the flag builder # def variation_for_user(user_key, variation) variation_for_key(LaunchDarkly::LDContext::KIND_DEFAULT, user_key, variation) @@ -258,11 +258,11 @@ def variation_for_user(user_key, variation) # @param context_key [String] the context key # @param variation [Boolean, Integer] true or false or the desired variation index to return: # 0 for the first, 1 for the second, etc. - # @return [FlagBuilderV2] the flag builder + # @return [FlagBuilder] the flag builder # def variation_for_key(context_kind, context_key, variation) if LaunchDarkly::Impl::Util.bool?(variation) - return boolean_flag.variation_for_key(context_kind, context_key, TestDataV2.variation_for_boolean(variation)) + return boolean_flag.variation_for_key(context_kind, context_key, TestData.variation_for_boolean(variation)) end targets = @_targets[context_kind] @@ -295,7 +295,7 @@ def variation_for_key(context_kind, context_key, variation) # # @param attribute [String] the user attribute to match against # @param values [Array] values to compare to - # @return [FlagRuleBuilderV2] the flag rule builder + # @return [FlagRuleBuilder] the flag rule builder # def if_match(attribute, *values) if_match_context(LaunchDarkly::LDContext::KIND_DEFAULT, attribute, *values) @@ -314,10 +314,10 @@ def if_match(attribute, *values) # @param context_kind [String] the context kind # @param attribute [String] the context attribute to match against # @param values [Array] values to compare to - # @return [FlagRuleBuilderV2] the flag rule builder + # @return [FlagRuleBuilder] the flag rule builder # def if_match_context(context_kind, attribute, *values) - flag_rule_builder = FlagRuleBuilderV2.new(self) + flag_rule_builder = FlagRuleBuilder.new(self) flag_rule_builder.and_match_context(context_kind, attribute, *values) end @@ -334,7 +334,7 @@ def if_match_context(context_kind, attribute, *values) # # @param attribute [String] the user attribute to match against # @param values [Array] values to compare to - # @return [FlagRuleBuilderV2] the flag rule builder + # @return [FlagRuleBuilder] the flag rule builder # def if_not_match(attribute, *values) if_not_match_context(LaunchDarkly::LDContext::KIND_DEFAULT, attribute, *values) @@ -353,10 +353,10 @@ def if_not_match(attribute, *values) # @param context_kind [String] the context kind # @param attribute [String] the context attribute to match against # @param values [Array] values to compare to - # @return [FlagRuleBuilderV2] the flag rule builder + # @return [FlagRuleBuilder] the flag rule builder # def if_not_match_context(context_kind, attribute, *values) - flag_rule_builder = FlagRuleBuilderV2.new(self) + flag_rule_builder = FlagRuleBuilder.new(self) flag_rule_builder.and_not_match_context(context_kind, attribute, *values) end @@ -364,7 +364,7 @@ def if_not_match_context(context_kind, attribute, *values) # Removes any existing rules from the flag. # This undoes the effect of methods like {#if_match}. # - # @return [FlagBuilderV2] the same flag builder + # @return [FlagBuilder] the same flag builder # def clear_rules @_rules = [] @@ -375,7 +375,7 @@ def clear_rules # Removes any existing targets from the flag. # This undoes the effect of methods like {#variation_for_user}. # - # @return [FlagBuilderV2] the same flag builder + # @return [FlagBuilder] the same flag builder # def clear_targets @_targets = {} @@ -383,7 +383,7 @@ def clear_targets end # 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. # # Creates a dictionary representation of the flag # @@ -393,7 +393,7 @@ def clear_targets # def build(version) base_flag_object = { - key: @_key, + key: @key, version: version, on: @_on, variations: @_variations, @@ -458,7 +458,7 @@ def add_rule(flag_rule_builder) end # - # A builder for the migration settings of a flag, for use with {FlagBuilderV2#migration_settings}. + # A builder for the migration settings of a flag, for use with {FlagBuilder#migration_settings}. # # A migration flag has settings that a standard feature flag does not have. These settings control # things such as the rate at which the SDK checks reads for consistency between origins. @@ -492,22 +492,22 @@ def build end # - # A builder for feature flag rules to be used with {FlagBuilderV2}. + # A builder for feature flag rules to be used with {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 context if all of the # rule's clauses match the context. # # To start defining a rule, use one of the flag builder's matching methods such as - # {FlagBuilderV2#if_match}. This defines the first clause for the rule. + # {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 # {#and_match} or {#and_not_match}. # Finally, call {#then_return} to finish defining the rule. # - class FlagRuleBuilderV2 + class FlagRuleBuilder # @api private # - # @param flag_builder [FlagBuilderV2] the flag builder instance + # @param flag_builder [FlagBuilder] the flag builder instance # def initialize(flag_builder) @_flag_builder = flag_builder @@ -535,7 +535,7 @@ def initialize_copy(other) # # @param attribute [String] the user attribute to match against # @param values [Array] values to compare to - # @return [FlagRuleBuilderV2] the flag rule builder + # @return [FlagRuleBuilder] the flag rule builder # def and_match(attribute, *values) and_match_context(LaunchDarkly::LDContext::KIND_DEFAULT, attribute, *values) @@ -555,7 +555,7 @@ def and_match(attribute, *values) # @param context_kind [String] the context kind # @param attribute [String] the context attribute to match against # @param values [Array] values to compare to - # @return [FlagRuleBuilderV2] the flag rule builder + # @return [FlagRuleBuilder] the flag rule builder # def and_match_context(context_kind, attribute, *values) @_clauses << { @@ -582,7 +582,7 @@ def and_match_context(context_kind, attribute, *values) # # @param attribute [String] the user attribute to match against # @param values [Array] values to compare to - # @return [FlagRuleBuilderV2] the flag rule builder + # @return [FlagRuleBuilder] the flag rule builder # def and_not_match(attribute, *values) and_not_match_context(LaunchDarkly::LDContext::KIND_DEFAULT, attribute, *values) @@ -602,7 +602,7 @@ def and_not_match(attribute, *values) # @param context_kind [String] the context kind # @param attribute [String] the context attribute to match against # @param values [Array] values to compare to - # @return [FlagRuleBuilderV2] the flag rule builder + # @return [FlagRuleBuilder] the flag rule builder # def and_not_match_context(context_kind, attribute, *values) @_clauses << { @@ -624,12 +624,12 @@ def and_not_match_context(context_kind, attribute, *values) # # @param variation [Boolean, Integer] true or false or the desired variation index: # 0 for the first, 1 for the second, etc. - # @return [FlagBuilderV2] the flag builder with this rule added + # @return [FlagBuilder] the flag builder with this rule added # def then_return(variation) if LaunchDarkly::Impl::Util.bool?(variation) @_flag_builder.boolean_flag - return then_return(TestDataV2.variation_for_boolean(variation)) + return then_return(TestData.variation_for_boolean(variation)) end @_variation = variation @@ -638,7 +638,7 @@ def then_return(variation) end # 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. # # Creates a dictionary representation of the rule # diff --git a/lib/ldclient-rb/interfaces/data_source.rb b/lib/ldclient-rb/interfaces/data_source.rb index f3204c60..bee492bd 100644 --- a/lib/ldclient-rb/interfaces/data_source.rb +++ b/lib/ldclient-rb/interfaces/data_source.rb @@ -90,7 +90,7 @@ class Status # This could be because the SDK client was explicitly shut down. In the FDv2 data system, it can also # mean the data source stopped after an error it does not retry. # - # Unless the SDK is configured with {LaunchDarkly::Config#data_system_config}, no other state follows + # Unless the SDK is configured with {LaunchDarkly::Config#data_system}, no other state follows # this one. # OFF = :off diff --git a/lib/ldclient-rb/ldclient.rb b/lib/ldclient-rb/ldclient.rb index d19292b9..9c0219ed 100644 --- a/lib/ldclient-rb/ldclient.rb +++ b/lib/ldclient-rb/ldclient.rb @@ -55,11 +55,11 @@ class LDClient # @return [LDClient] The LaunchDarkly client instance # def initialize(sdk_key, config = Config.default, wait_for_sec = 5) - @data_system_config = config.data_system_config || DataSystem.default.build + @data_system_config = config.data_system || DataSystem.default.build # The SDK key is required unless the client never sends it. That is the case in offline mode, and # when events are disabled and no data source needs the SDK key (for example, daemon mode, or only - # FileData or TestDataV2 sources). + # FileData or TestData sources). if !config.offline? && sdk_key.nil? if config.send_events || LDClient.data_sources_need_sdk_key?(@data_system_config) raise ArgumentError, "sdk_key must not be nil" diff --git a/spec/impl/data_source/status_provider_spec.rb b/spec/impl/data_source/status_provider_spec.rb index a870e054..fb17d41a 100644 --- a/spec/impl/data_source/status_provider_spec.rb +++ b/spec/impl/data_source/status_provider_spec.rb @@ -10,7 +10,7 @@ module LaunchDarkly module Impl module DataSource - describe StatusProviderV2 do + describe StatusProvider do let(:broadcaster) { double("broadcaster", broadcast: nil) } let(:valid) { LaunchDarkly::Interfaces::DataSource::Status::VALID } let(:interrupted) { LaunchDarkly::Interfaces::DataSource::Status::INTERRUPTED } @@ -23,7 +23,7 @@ def make_error end it "keeps the public state_since as a wall-clock time" do - provider = StatusProviderV2.new(broadcaster) + provider = StatusProvider.new(broadcaster) provider.update_status(valid, nil) expect(provider.status.state_since).to be_a(Time) @@ -31,7 +31,7 @@ def make_error it "measures time in state on the monotonic clock and resets it on state change" do now = 1_000.0 - provider = StatusProviderV2.new(broadcaster, clock: -> { now }) + provider = StatusProvider.new(broadcaster, clock: -> { now }) now = 1_030.0 _, seconds = provider.status_and_seconds_in_state @@ -49,7 +49,7 @@ def make_error it "does not reset the duration when the state is unchanged" do now = 1_000.0 - provider = StatusProviderV2.new(broadcaster, clock: -> { now }) + provider = StatusProvider.new(broadcaster, clock: -> { now }) provider.update_status(valid, nil) since = provider.status.state_since @@ -65,7 +65,7 @@ def make_error it "keeps both stamps when INTERRUPTED during INITIALIZING is coerced to INITIALIZING" do now = 1_000.0 - provider = StatusProviderV2.new(broadcaster, clock: -> { now }) + provider = StatusProvider.new(broadcaster, clock: -> { now }) since = provider.status.state_since now = 1_030.0 @@ -79,7 +79,7 @@ def make_error it "keeps both stamps when a return to INITIALIZING is coerced to the current state" do now = 1_000.0 - provider = StatusProviderV2.new(broadcaster, clock: -> { now }) + provider = StatusProvider.new(broadcaster, clock: -> { now }) provider.update_status(valid, nil) since = provider.status.state_since @@ -94,7 +94,7 @@ def make_error it "ignores a nil state" do now = 1_000.0 - provider = StatusProviderV2.new(broadcaster, clock: -> { now }) + provider = StatusProvider.new(broadcaster, clock: -> { now }) provider.update_status(valid, nil) since = provider.status.state_since @@ -109,7 +109,7 @@ def make_error describe "listeners" do let(:broadcaster) { LaunchDarkly::Impl::Broadcaster.new(SynchronousExecutor.new, $null_log) } - let(:provider) { StatusProviderV2.new(broadcaster) } + let(:provider) { StatusProvider.new(broadcaster) } it "are called only when the status changes" do listener = ListenerSpy.new @@ -150,7 +150,7 @@ def make_error end it "is unaffected by wall-clock steps" do - provider = StatusProviderV2.new(broadcaster) + provider = StatusProvider.new(broadcaster) provider.update_status(valid, nil) Timecop.freeze(Time.now + 3600) do diff --git a/spec/impl/data_store/feature_store_client_wrapper_spec.rb b/spec/impl/data_store/feature_store_client_wrapper_spec.rb index eed7eca5..506b79d5 100644 --- a/spec/impl/data_store/feature_store_client_wrapper_spec.rb +++ b/spec/impl/data_store/feature_store_client_wrapper_spec.rb @@ -8,7 +8,7 @@ module LaunchDarkly module Impl module DataStore - describe FeatureStoreClientWrapperV2 do + describe FeatureStoreClientWrapper do let(:logger) { double.as_null_object } let(:status_sink) { double(update_status: nil) } @@ -62,7 +62,7 @@ def ignore_error inner = double("store", stop: nil, monitoring_enabled?: true) allow(inner).to receive(:available?).and_return(false, true) allow(inner).to receive(:init).and_raise(StandardError.new("init error")) - sink = LaunchDarkly::Impl::DataStore::StatusProviderV2.new(inner, broadcaster) + sink = LaunchDarkly::Impl::DataStore::StatusProvider.new(inner, broadcaster) ensure_stop(described_class.new(inner, sink, logger)) do |wrapper| ignore_error { wrapper.init({}) } diff --git a/spec/impl/data_store/in_memory_feature_store_v2_spec.rb b/spec/impl/data_store/in_memory_feature_store_spec.rb similarity index 99% rename from spec/impl/data_store/in_memory_feature_store_v2_spec.rb rename to spec/impl/data_store/in_memory_feature_store_spec.rb index 1cc8f610..3a39b732 100644 --- a/spec/impl/data_store/in_memory_feature_store_v2_spec.rb +++ b/spec/impl/data_store/in_memory_feature_store_spec.rb @@ -4,9 +4,9 @@ module LaunchDarkly module Impl module DataStore - describe InMemoryFeatureStoreV2 do + describe InMemoryFeatureStore do let(:logger) { double.as_null_object } - subject { InMemoryFeatureStoreV2.new(logger) } + subject { InMemoryFeatureStore.new(logger) } let(:flag_key) { "test-flag" } let(:flag) do diff --git a/spec/impl/data_store/store_spec.rb b/spec/impl/data_store/store_spec.rb index 2d6e9f62..8654a71d 100644 --- a/spec/impl/data_store/store_spec.rb +++ b/spec/impl/data_store/store_spec.rb @@ -14,7 +14,7 @@ module DataStore let(:change_set_broadcaster) { LaunchDarkly::Impl::Broadcaster.new(Concurrent::SingleThreadExecutor.new, logger) } subject { Store.new(flag_change_broadcaster, change_set_broadcaster, logger) } - let(:flag_key) { :test_flag } # Use symbol like TestDataV2 does + let(:flag_key) { :test_flag } # Use symbol like TestData does let(:flag_data) do { key: flag_key.to_s, # key field in the object should be string @@ -25,7 +25,7 @@ module DataStore } end - let(:segment_key) { :test_segment } # Use symbol like TestDataV2 does + let(:segment_key) { :test_segment } # Use symbol like TestData does let(:segment_data) do { key: segment_key.to_s, # key field in the object should be string @@ -169,7 +169,7 @@ def disable_cache subject.apply(change_set, false) expect(subject.initialized?).to be true - # InMemoryFeatureStoreV2's get method handles both string and symbol keys + # InMemoryFeatureStore's get method handles both string and symbol keys result = subject.get_active_store.get(LaunchDarkly::Interfaces::DataStore::FEATURES, flag_key) expect(result).not_to be_nil expect(result.key).to eq(flag_key.to_s) # key field is string diff --git a/spec/impl/data_system/fdv2_datasystem_spec.rb b/spec/impl/data_system/fdv2_datasystem_spec.rb index fc9f2980..f8d7b5c5 100644 --- a/spec/impl/data_system/fdv2_datasystem_spec.rb +++ b/spec/impl/data_system/fdv2_datasystem_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" require "mock_components" require "ldclient-rb/impl/data_system/fdv2" -require "ldclient-rb/integrations/test_data_v2" +require "ldclient-rb/integrations/test_data" require "ldclient-rb/data_system" require "ldclient-rb/impl/data_system" @@ -25,10 +25,10 @@ def build(_sdk_key, _config) describe "two-phase initialization" do it "initializes from initializer then syncs from synchronizer" do - td_initializer = LaunchDarkly::Integrations::TestDataV2.data_source + td_initializer = LaunchDarkly::Integrations::TestData.data_source td_initializer.update(td_initializer.flag("flagkey").on(true)) - td_synchronizer = LaunchDarkly::Integrations::TestDataV2.data_source + td_synchronizer = LaunchDarkly::Integrations::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. @@ -76,7 +76,7 @@ def build(_sdk_key, _config) describe "stopping FDv2" do it "prevents flag updates after stop" do - td = LaunchDarkly::Integrations::TestDataV2.data_source + td = LaunchDarkly::Integrations::TestData.data_source data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new .initializers(nil) .synchronizers([td.test_data_ds_builder]) @@ -108,7 +108,7 @@ def build(_sdk_key, _config) describe "data availability" do it "reports refreshed availability when data is loaded" do - td = LaunchDarkly::Integrations::TestDataV2.data_source + td = LaunchDarkly::Integrations::TestData.data_source data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new .initializers(nil) .synchronizers([td.test_data_ds_builder]) @@ -240,7 +240,7 @@ def with_data_system(initializers, synchronizers) end it "is not available before initialization" do - td = LaunchDarkly::Integrations::TestDataV2.data_source + td = LaunchDarkly::Integrations::TestData.data_source data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new .initializers(nil) .synchronizers([td.test_data_ds_builder]) @@ -291,7 +291,7 @@ def with_data_system(initializers, synchronizers) # Return empty - sync yields nothing (synchronizer fails) allow(mock_primary).to receive(:sync) - td = LaunchDarkly::Integrations::TestDataV2.data_source + td = LaunchDarkly::Integrations::TestData.data_source td.update(td.flag("flagkey").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -345,7 +345,7 @@ def with_data_system(initializers, synchronizers) # Return empty - sync yields nothing (synchronizer fails) allow(mock_secondary).to receive(:sync) - td = LaunchDarkly::Integrations::TestDataV2.data_source + td = LaunchDarkly::Integrations::TestData.data_source td.update(td.flag("flagkey").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -391,7 +391,7 @@ def with_data_system(initializers, synchronizers) allow(mock_primary).to receive(:sync).and_yield(update) # Create FDv1 fallback data source with actual data - td_fdv1 = LaunchDarkly::Integrations::TestDataV2.data_source + td_fdv1 = LaunchDarkly::Integrations::TestData.data_source td_fdv1.update(td_fdv1.flag("fdv1flag").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -440,7 +440,7 @@ def with_data_system(initializers, synchronizers) allow(mock_primary).to receive(:sync).and_yield(update) # Create FDv1 fallback data source - td_fdv1 = LaunchDarkly::Integrations::TestDataV2.data_source + td_fdv1 = LaunchDarkly::Integrations::TestData.data_source td_fdv1.update(td_fdv1.flag("fdv1fallbackflag").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -485,7 +485,7 @@ def with_data_system(initializers, synchronizers) describe "FDv1 fallback with initializer" do it "falls back to FDv1 and replaces initialized data" do # Initialize with some data - td_initializer = LaunchDarkly::Integrations::TestDataV2.data_source + td_initializer = LaunchDarkly::Integrations::TestData.data_source td_initializer.update(td_initializer.flag("initialflag").on(true)) # Create mock primary that signals fallback @@ -500,7 +500,7 @@ def with_data_system(initializers, synchronizers) allow(mock_primary).to receive(:sync).and_yield(update) # Create FDv1 fallback with different data - td_fdv1 = LaunchDarkly::Integrations::TestDataV2.data_source + td_fdv1 = LaunchDarkly::Integrations::TestData.data_source td_fdv1.update(td_fdv1.flag("fdv1replacementflag").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -558,7 +558,7 @@ def with_data_system(initializers, synchronizers) allow(mock_secondary).to receive(:sync).and_yield(valid_update) # Create FDv1 fallback (should not be used) - td_fdv1 = LaunchDarkly::Integrations::TestDataV2.data_source + td_fdv1 = LaunchDarkly::Integrations::TestData.data_source td_fdv1.update(td_fdv1.flag("fdv1-should-not-appear").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -600,7 +600,7 @@ def with_data_system(initializers, synchronizers) allow(mock_primary).to receive(:sync).and_yield(update) # Create FDv1 fallback - td_fdv1 = LaunchDarkly::Integrations::TestDataV2.data_source + td_fdv1 = LaunchDarkly::Integrations::TestData.data_source td_fdv1.update(td_fdv1.flag("fdv1flag").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -660,7 +660,7 @@ def build(_sdk_key, _config) it "switches to the FDv1 fallback synchronizer when an initializer requests fallback" do # Initializer returns a successful payload AND fallback_to_fdv1 -- the SDK should # apply the payload, then run only the FDv1 fallback synchronizer. - td_initializer = LaunchDarkly::Integrations::TestDataV2.data_source + td_initializer = LaunchDarkly::Integrations::TestData.data_source td_initializer.update(td_initializer.flag("initialflag").on(true)) initializer_fetch = td_initializer.test_data_ds_builder.build(sdk_key, config).fetch(nil) fallback_fetch = LaunchDarkly::Interfaces::DataSystem::FetchResult.new( @@ -675,7 +675,7 @@ def build(_sdk_key, _config) allow(mock_primary).to receive(:stop) allow(mock_primary).to receive(:sync) - td_fdv1 = LaunchDarkly::Integrations::TestDataV2.data_source + td_fdv1 = LaunchDarkly::Integrations::TestData.data_source td_fdv1.update(td_fdv1.flag("fdv1flag").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -746,7 +746,7 @@ def build(_sdk_key, _config) describe "data source status" do it "publishes the valid status before releasing ready waiters" do - td = LaunchDarkly::Integrations::TestDataV2.data_source + td = LaunchDarkly::Integrations::TestData.data_source td.update(td.flag("flagkey").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -763,7 +763,7 @@ def build(_sdk_key, _config) end it "publishes the valid status when an initializer supplies the basis" do - td = LaunchDarkly::Integrations::TestDataV2.data_source + td = LaunchDarkly::Integrations::TestData.data_source td.update(td.flag("flagkey").on(true)) # With no synchronizers, the initializer is the only thing that can diff --git a/spec/impl/data_system/fdv2_persistence_spec.rb b/spec/impl/data_system/fdv2_persistence_spec.rb index 082e0f45..eda46226 100644 --- a/spec/impl/data_system/fdv2_persistence_spec.rb +++ b/spec/impl/data_system/fdv2_persistence_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" require "ldclient-rb/impl/data_system/fdv2" -require "ldclient-rb/integrations/test_data_v2" +require "ldclient-rb/integrations/test_data" require "ldclient-rb/data_system" require "ldclient-rb/impl/data_system" @@ -118,7 +118,7 @@ def get_data_snapshot persistent_store = StubFeatureStore.new # Create and populate synchronizer BEFORE building config - td_synchronizer = LaunchDarkly::Integrations::TestDataV2.data_source + td_synchronizer = LaunchDarkly::Integrations::TestData.data_source td_synchronizer.update(td_synchronizer.flag("flagkey").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -174,7 +174,7 @@ def get_data_snapshot it "does not flush when store comes back online without stale data" do persistent_store = StubFeatureStore.new - td_synchronizer = LaunchDarkly::Integrations::TestDataV2.data_source + td_synchronizer = LaunchDarkly::Integrations::TestData.data_source td_synchronizer.update(td_synchronizer.flag("flagkey").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -204,7 +204,7 @@ def get_data_snapshot it "does not flush when store is unavailable" do persistent_store = StubFeatureStore.new - td_synchronizer = LaunchDarkly::Integrations::TestDataV2.data_source + td_synchronizer = LaunchDarkly::Integrations::TestData.data_source td_synchronizer.update(td_synchronizer.flag("flagkey").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -234,7 +234,7 @@ def get_data_snapshot it "works in READ_WRITE mode with persistent store" do persistent_store = StubFeatureStore.new - td_synchronizer = LaunchDarkly::Integrations::TestDataV2.data_source + td_synchronizer = LaunchDarkly::Integrations::TestData.data_source td_synchronizer.update(td_synchronizer.flag("flagkey").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -277,7 +277,7 @@ def get_data_snapshot persistent_store.reset_operation_tracking # Create synchronizer with new data - td_synchronizer = LaunchDarkly::Integrations::TestDataV2.data_source + td_synchronizer = LaunchDarkly::Integrations::TestData.data_source td_synchronizer.update(td_synchronizer.flag("newflag").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -301,7 +301,7 @@ def get_data_snapshot it "writes delta updates to persistent store in READ_WRITE mode" do persistent_store = StubFeatureStore.new - td_synchronizer = LaunchDarkly::Integrations::TestDataV2.data_source + td_synchronizer = LaunchDarkly::Integrations::TestData.data_source td_synchronizer.update(td_synchronizer.flag("flagkey").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -347,7 +347,7 @@ def get_data_snapshot it "does not write delta updates to persistent store in READ_ONLY mode" do persistent_store = StubFeatureStore.new - td_synchronizer = LaunchDarkly::Integrations::TestDataV2.data_source + td_synchronizer = LaunchDarkly::Integrations::TestData.data_source td_synchronizer.update(td_synchronizer.flag("flagkey").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -391,11 +391,11 @@ def get_data_snapshot persistent_store = StubFeatureStore.new # Create initializer with one flag - td_initializer = LaunchDarkly::Integrations::TestDataV2.data_source + td_initializer = LaunchDarkly::Integrations::TestData.data_source td_initializer.update(td_initializer.flag("init-flag").on(true)) # Create synchronizer with another flag - td_synchronizer = LaunchDarkly::Integrations::TestDataV2.data_source + td_synchronizer = LaunchDarkly::Integrations::TestData.data_source td_synchronizer.update(td_synchronizer.flag("sync-flag").on(false)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -434,7 +434,7 @@ def get_data_snapshot it "handles data store status provider correctly" do persistent_store = StubFeatureStore.new - td_synchronizer = LaunchDarkly::Integrations::TestDataV2.data_source + td_synchronizer = LaunchDarkly::Integrations::TestData.data_source td_synchronizer.update(td_synchronizer.flag("flagkey").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new @@ -461,7 +461,7 @@ def get_data_snapshot end it "has data store status provider even without persistent store" do - td_synchronizer = LaunchDarkly::Integrations::TestDataV2.data_source + td_synchronizer = LaunchDarkly::Integrations::TestData.data_source td_synchronizer.update(td_synchronizer.flag("flagkey").on(true)) data_system_config = LaunchDarkly::DataSystem::ConfigBuilder.new diff --git a/spec/impl/data_system/polling_initializer_spec.rb b/spec/impl/data_system/polling_initializer_spec.rb index 7dfcdabb..c059168b 100644 --- a/spec/impl/data_system/polling_initializer_spec.rb +++ b/spec/impl/data_system/polling_initializer_spec.rb @@ -95,7 +95,7 @@ def selector mock_requester = MockPollingRequester.new(LaunchDarkly::Result.fail("failure message")) ds = PollingDataSource.new(1.0, mock_requester, logger) - expect(ds.name).to eq("PollingDataSourceV2") + expect(ds.name).to eq("PollingDataSource") end it "error is returned on failure" do diff --git a/spec/impl/migrations/migrator_spec.rb b/spec/impl/migrations/migrator_spec.rb index dddf5f61..fe3712f2 100644 --- a/spec/impl/migrations/migrator_spec.rb +++ b/spec/impl/migrations/migrator_spec.rb @@ -14,7 +14,7 @@ module Migrations subject { Migrator } let(:default_config) { LaunchDarkly::Config.new({ diagnostic_opt_out: true, logger: $null_log }) } let(:data_source) { - td = LaunchDarkly::Integrations::TestDataV2.data_source + td = LaunchDarkly::Integrations::TestData.data_source [ LaunchDarkly::Migrations::STAGE_OFF, @@ -49,7 +49,7 @@ def default_builder(client) LaunchDarkly::Migrations::OP_WRITE, ].each do |op| it "for #{op}" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| builder = default_builder(client) payload_old = nil @@ -100,7 +100,7 @@ def default_builder(client) {label: "write complete", stage: LaunchDarkly::Migrations::STAGE_COMPLETE, op: LaunchDarkly::Migrations::OP_WRITE, expected: ["new"]}, ].each do |test_param| it "for #{test_param[:label]}" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| with_processor_and_sender(default_config, 0) do |ep, sender| override_client_event_processor(client, ep) @@ -152,7 +152,7 @@ def default_builder(client) {label: "write complete", stage: LaunchDarkly::Migrations::STAGE_COMPLETE, op: LaunchDarkly::Migrations::OP_WRITE, expected: [:new]}, ].each do |test_param| it "for #{test_param[:label]}" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| with_processor_and_sender(default_config, 0) do |ep, sender| override_client_event_processor(client, ep) @@ -200,7 +200,7 @@ def default_builder(client) { stage: LaunchDarkly::Migrations::STAGE_COMPLETE, old: false, new: true }, ].each do |params| it "for #{params[:stage]} stage" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| builder = default_builder(client) called_old = false @@ -237,7 +237,7 @@ def default_builder(client) { stage: LaunchDarkly::Migrations::STAGE_COMPLETE, origin: "new" }, ].each do |params| it "for #{params[:stage]} stage" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| builder = default_builder(client) builder.read(->(_) { raise "old error" }, ->(_) { raise "new error" }) @@ -255,7 +255,7 @@ def default_builder(client) describe "support execution order" do it "parallel" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| builder = default_builder(client) builder.read( @@ -280,7 +280,7 @@ def default_builder(client) end it "serial" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| builder = default_builder(client) builder.read_execution_order(LaunchDarkly::Migrations::MigratorBuilder::EXECUTION_SERIAL) @@ -306,7 +306,7 @@ def default_builder(client) end it "random" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| builder = default_builder(client) builder.read_execution_order(LaunchDarkly::Migrations::MigratorBuilder::EXECUTION_RANDOM) @@ -343,7 +343,7 @@ def default_builder(client) {label: "live when different", stage: LaunchDarkly::Migrations::STAGE_LIVE, old_return: "same", new_return: "different", expected: false}, ].each do |test_param| it "for #{test_param[:label]}" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| with_processor_and_sender(default_config, 0) do |ep, sender| override_client_event_processor(client, ep) @@ -382,7 +382,7 @@ def default_builder(client) {label: "live when different", stage: LaunchDarkly::Migrations::STAGE_LIVE}, ].each do |test_param| it "for #{test_param[:label]} unless there is an error" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| with_processor_and_sender(default_config, 0) do |ep, sender| override_client_event_processor(client, ep) @@ -419,7 +419,7 @@ def default_builder(client) {label: "live", stage: LaunchDarkly::Migrations::STAGE_LIVE}, ].each do |test_param| it "for #{test_param[:label]} when an exception occurs" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| with_processor_and_sender(default_config, 0) do |ep, sender| override_client_event_processor(client, ep) @@ -464,7 +464,7 @@ def default_builder(client) {label: "complete", stage: LaunchDarkly::Migrations::STAGE_COMPLETE, expected: ["new"]}, ].each do |test_param| it "for #{test_param[:label]}" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| with_processor_and_sender(default_config, 0) do |ep, sender| override_client_event_processor(client, ep) @@ -508,7 +508,7 @@ def default_builder(client) { stage: LaunchDarkly::Migrations::STAGE_COMPLETE, old: false, new: true }, ].each do |params| it "for #{params[:stage]}" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| builder = default_builder(client) called_old = false @@ -545,7 +545,7 @@ def default_builder(client) { stage: LaunchDarkly::Migrations::STAGE_COMPLETE, origin: "new" }, ].each do |params| it "for #{params[:stage]} stage" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| builder = default_builder(client) builder.write(->(_) { raise "old error" }, ->(_) { raise "new error" }) @@ -576,7 +576,7 @@ def default_builder(client) # LaunchDarkly::Migrations::STAGE_COMPLETE doesn't run both so we can ignore it. ].each do |params| it "for #{params[:stage]} stage" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| builder = default_builder(client) called_old = false @@ -614,7 +614,7 @@ def default_builder(client) {label: "write complete", stage: LaunchDarkly::Migrations::STAGE_COMPLETE, expected: "new"}, ].each do |test_param| it test_param[:label] do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| with_processor_and_sender(default_config, 0) do |ep, sender| override_client_event_processor(client, ep) @@ -655,7 +655,7 @@ def default_builder(client) {label: "ramp down", stage: LaunchDarkly::Migrations::STAGE_RAMPDOWN, old_fail: true, new_fail: false, expected: "old"}, ].each do |test_param| it "for #{test_param[:label]}" do - with_client(test_config(data_system_config: test_data_system(data_source))) do |client| + with_client(test_config(data_system: test_data_system(data_source))) do |client| with_processor_and_sender(default_config, 0) do |ep, sender| override_client_event_processor(client, ep) diff --git a/spec/impl/migrations/tracker_spec.rb b/spec/impl/migrations/tracker_spec.rb index 94e237de..57625caf 100644 --- a/spec/impl/migrations/tracker_spec.rb +++ b/spec/impl/migrations/tracker_spec.rb @@ -1,12 +1,12 @@ require 'ldclient-rb/interfaces' require "ldclient-rb" -require "ldclient-rb/integrations/test_data_v2" +require "ldclient-rb/integrations/test_data" module LaunchDarkly module Impl module Migrations describe OpTracker do - let(:flag_data) { LaunchDarkly::Integrations::TestDataV2::FlagBuilderV2.new("feature").build(1) } + let(:flag_data) { LaunchDarkly::Integrations::TestData::FlagBuilder.new("feature").build(1) } let(:flag) { LaunchDarkly::Impl::Model::FeatureFlag.new(flag_data) } let(:context) { LaunchDarkly::LDContext.with_key("user-key") } let(:detail) { LaunchDarkly::EvaluationDetail.new(true, 0, LaunchDarkly::EvaluationReason.fallthrough) } @@ -76,10 +76,10 @@ def minimal_tracker() end it "with explicit sampling ratio of 1" do - settings = LaunchDarkly::Integrations::TestDataV2::FlagBuilderV2::FlagMigrationSettingsBuilder.new + settings = LaunchDarkly::Integrations::TestData::FlagBuilder::FlagMigrationSettingsBuilder.new settings.check_ratio(1) - builder = LaunchDarkly::Integrations::TestDataV2::FlagBuilderV2.new("feature") + builder = LaunchDarkly::Integrations::TestData::FlagBuilder.new("feature") builder.migration_settings(settings.build) flag = LaunchDarkly::Impl::Model::FeatureFlag.new(builder.build(1)) context = LaunchDarkly::LDContext.with_key("user-key") @@ -100,10 +100,10 @@ def minimal_tracker() end it "unless disabled with sampling ratio of 0" do - settings = LaunchDarkly::Integrations::TestDataV2::FlagBuilderV2::FlagMigrationSettingsBuilder.new + settings = LaunchDarkly::Integrations::TestData::FlagBuilder::FlagMigrationSettingsBuilder.new settings.check_ratio(0) - builder = LaunchDarkly::Integrations::TestDataV2::FlagBuilderV2.new("feature") + builder = LaunchDarkly::Integrations::TestData::FlagBuilder.new("feature") builder.migration_settings(settings.build) flag = LaunchDarkly::Impl::Model::FeatureFlag.new(builder.build(1)) context = LaunchDarkly::LDContext.with_key("user-key") @@ -123,10 +123,10 @@ def minimal_tracker() end it "when supplied a non-trivial sampling ratio" do - settings = LaunchDarkly::Integrations::TestDataV2::FlagBuilderV2::FlagMigrationSettingsBuilder.new + settings = LaunchDarkly::Integrations::TestData::FlagBuilder::FlagMigrationSettingsBuilder.new settings.check_ratio(10) - builder = LaunchDarkly::Integrations::TestDataV2::FlagBuilderV2.new("feature") + builder = LaunchDarkly::Integrations::TestData::FlagBuilder.new("feature") builder.migration_settings(settings.build) flag = LaunchDarkly::Impl::Model::FeatureFlag.new(builder.build(1)) context = LaunchDarkly::LDContext.with_key("user-key") diff --git a/spec/integrations/file_data_source_v2_spec.rb b/spec/integrations/file_data_source_spec.rb similarity index 87% rename from spec/integrations/file_data_source_v2_spec.rb rename to spec/integrations/file_data_source_spec.rb index 2927eaff..d9c1aa40 100644 --- a/spec/integrations/file_data_source_v2_spec.rb +++ b/spec/integrations/file_data_source_spec.rb @@ -2,22 +2,22 @@ require "spec_helper" require "tempfile" -require "ldclient-rb/impl/integrations/file_data_source_v2" +require "ldclient-rb/impl/integrations/file_data_source" require "ldclient-rb/integrations/file_data" require "ldclient-rb/interfaces/data_system" require "mock_components" # The "does not allow Ruby objects in YAML" example uses this class and flag. -$created_bad_class_v2 = false -class BadClassWeShouldNotInstantiateV2 < Hash +$created_bad_class = false +class BadClassWeShouldNotInstantiate < Hash def []=(key, value) - $created_bad_class_v2 = true + $created_bad_class = true end end module LaunchDarkly module Integrations - RSpec.describe "FileDataSourceV2" do + RSpec.describe "FileDataSource" do let(:logger) { $null_log } let(:all_properties_json) { <<-EOF @@ -131,7 +131,7 @@ def no_selector_store it "creates valid initializer" do file = make_temp_file(all_properties_json) - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: [file.path]) + source = Impl::Integrations::FileDataSource.new(logger, paths: [file.path]) begin result = source.fetch(no_selector_store) @@ -161,7 +161,7 @@ def no_selector_store end it "handles missing file" do - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: ['no-such-file.json']) + source = Impl::Integrations::FileDataSource.new(logger, paths: ['no-such-file.json']) begin result = source.fetch(no_selector_store) @@ -176,7 +176,7 @@ def no_selector_store it "handles invalid JSON" do file = make_temp_file('{"flagValues":{') - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: [file.path]) + source = Impl::Integrations::FileDataSource.new(logger, paths: [file.path]) begin result = source.fetch(no_selector_store) @@ -192,7 +192,7 @@ def no_selector_store file1 = make_temp_file(flag_only_json) file2 = make_temp_file(flag_only_json) - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: [file1.path, file2.path]) + source = Impl::Integrations::FileDataSource.new(logger, paths: [file1.path, file2.path]) begin result = source.fetch(no_selector_store) @@ -208,7 +208,7 @@ def no_selector_store file1 = make_temp_file(flag_only_json) file2 = make_temp_file(segment_only_json) - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: [file1.path, file2.path]) + source = Impl::Integrations::FileDataSource.new(logger, paths: [file1.path, file2.path]) begin result = source.fetch(no_selector_store) @@ -229,7 +229,7 @@ def no_selector_store it "loads YAML" do file = make_temp_file(all_properties_yaml) - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: [file.path]) + source = Impl::Integrations::FileDataSource.new(logger, paths: [file.path]) begin result = source.fetch(no_selector_store) @@ -244,7 +244,7 @@ def no_selector_store it "handles flag values" do file = make_temp_file(flag_values_only_json) - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: [file.path]) + source = Impl::Integrations::FileDataSource.new(logger, paths: [file.path]) begin result = source.fetch(no_selector_store) @@ -271,7 +271,7 @@ def no_selector_store it "creates valid synchronizer" do file = make_temp_file(all_properties_json) - source = Impl::Integrations::FileDataSourceV2.new( + source = Impl::Integrations::FileDataSource.new( logger, paths: [file.path], poll_interval: 0.1 @@ -307,7 +307,7 @@ def no_selector_store it "detects file changes" do file = make_temp_file(flag_only_json) - source = Impl::Integrations::FileDataSourceV2.new( + source = Impl::Integrations::FileDataSource.new( logger, paths: [file.path], poll_interval: 0.1 @@ -354,7 +354,7 @@ def no_selector_store it "reports error on invalid file update" do file = make_temp_file(flag_only_json) - source = Impl::Integrations::FileDataSourceV2.new( + source = Impl::Integrations::FileDataSource.new( logger, paths: [file.path], poll_interval: 0.1 @@ -396,7 +396,7 @@ def no_selector_store it "can be stopped" do file = make_temp_file(all_properties_json) - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: [file.path]) + source = Impl::Integrations::FileDataSource.new(logger, paths: [file.path]) updates = [] @@ -426,7 +426,7 @@ def no_selector_store it "returns error" do file = make_temp_file(all_properties_json) - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: [file.path]) + source = Impl::Integrations::FileDataSource.new(logger, paths: [file.path]) # First fetch should work result = source.fetch(no_selector_store) @@ -446,10 +446,10 @@ def no_selector_store it "returns correct name" do file = make_temp_file(all_properties_json) - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: [file.path]) + source = Impl::Integrations::FileDataSource.new(logger, paths: [file.path]) begin - expect(source.name).to eq("FileDataV2") + expect(source.name).to eq("FileData") ensure source.stop end @@ -461,7 +461,7 @@ def no_selector_store file = make_temp_file(flag_only_json) # Pass a single string instead of a list - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: file.path) + source = Impl::Integrations::FileDataSource.new(logger, paths: file.path) begin result = source.fetch(no_selector_store) @@ -474,11 +474,11 @@ def no_selector_store end end - describe "public API (data_source_v2)" do + describe "public API (data_source)" do it "creates builder that works as initializer" do file = make_temp_file(all_properties_json) - builder = FileData.data_source_v2(paths: [file.path]) + builder = FileData.data_source(paths: [file.path]) config = LaunchDarkly::Config.new(logger: logger) source = builder.build('sdk-key', config) @@ -496,7 +496,7 @@ def no_selector_store it "creates builder that works as synchronizer" do file = make_temp_file(all_properties_json) - builder = FileData.data_source_v2(paths: [file.path], poll_interval: 0.1) + builder = FileData.data_source(paths: [file.path], poll_interval: 0.1) config = LaunchDarkly::Config.new(logger: logger) source = builder.build('sdk-key', config) @@ -527,25 +527,25 @@ def no_selector_store describe "security" do let(:unsafe_yaml) { <<-EOF ---- !ruby/hash:BadClassWeShouldNotInstantiateV2 +--- !ruby/hash:BadClassWeShouldNotInstantiate foo: bar EOF } it "does not allow Ruby objects in YAML" do # The file holds a hash of a custom Ruby class. An unsafe YAML load creates the object and calls its - # []= method, which sets $created_bad_class_v2. A safe load refuses the file. - $created_bad_class_v2 = false + # []= method, which sets $created_bad_class. A safe load refuses the file. + $created_bad_class = false file = make_temp_file(unsafe_yaml) - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: [file.path]) + source = Impl::Integrations::FileDataSource.new(logger, paths: [file.path]) begin result = source.fetch(no_selector_store) expect(result.success?).to eq(false) expect(result.error).to include("Unable to load flag data") - expect($created_bad_class_v2).to eq(false) + expect($created_bad_class).to eq(false) ensure source.stop end @@ -565,7 +565,7 @@ def no_selector_store ] malicious_paths.each do |malicious_path| - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: [malicious_path]) + source = Impl::Integrations::FileDataSource.new(logger, paths: [malicious_path]) begin result = source.fetch(no_selector_store) @@ -581,7 +581,7 @@ def no_selector_store describe "reload without the listen gem" do around do |example| - klass = Impl::Integrations::FileDataSourceV2 + klass = Impl::Integrations::FileDataSource saved = klass.class_variable_get(:@@have_listen) klass.class_variable_set(:@@have_listen, false) begin @@ -593,12 +593,12 @@ def no_selector_store it "detects file changes with the polling watcher" do poller_started = Queue.new - expect(Impl::Integrations::FileDataSourcePollerV2).to receive(:new).and_wrap_original do |original, *args| + expect(Impl::Integrations::FileDataSourcePoller).to receive(:new).and_wrap_original do |original, *args| original.call(*args).tap { poller_started << true } end file = make_temp_file(flag_only_json) - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: [file.path], poll_interval: 0.1) + source = Impl::Integrations::FileDataSource.new(logger, paths: [file.path], poll_interval: 0.1) updates = Queue.new begin @@ -642,7 +642,7 @@ def first_sync_update(source) end it "reports OFF for a missing file" do - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: ['no-such-file.json']) + source = Impl::Integrations::FileDataSource.new(logger, paths: ['no-such-file.json']) begin update = first_sync_update(source) @@ -658,7 +658,7 @@ def first_sync_update(source) it "reports OFF for a malformed file" do file = make_temp_file('{"flagValues":{') - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: [file.path]) + source = Impl::Integrations::FileDataSource.new(logger, paths: [file.path]) begin update = first_sync_update(source) @@ -677,7 +677,7 @@ def first_sync_update(source) it "produces a full flag" do file = make_temp_file(flag_values_only_json) - source = Impl::Integrations::FileDataSourceV2.new(logger, paths: [file.path]) + source = Impl::Integrations::FileDataSource.new(logger, paths: [file.path]) begin result = source.fetch(no_selector_store) @@ -705,10 +705,10 @@ def first_sync_update(source) it "evaluates flags from a synchronizer" do file = make_temp_file(all_properties_json) data_system = LaunchDarkly::DataSystem.custom - .synchronizers([FileData.data_source_v2(paths: [file.path])]) + .synchronizers([FileData.data_source(paths: [file.path])]) .build - with_client(test_config(data_system_config: data_system)) do |client| + with_client(test_config(data_system: data_system)) do |client| expect(client.initialized?).to eq(true) expect(client.variation("flag1", user, "default")).to eq("on") expect(client.variation("flag2", user, "default")).to eq("value2") @@ -718,10 +718,10 @@ def first_sync_update(source) it "evaluates flags from an initializer" do file = make_temp_file(all_properties_json) data_system = LaunchDarkly::DataSystem.custom - .initializers([FileData.data_source_v2(paths: [file.path])]) + .initializers([FileData.data_source(paths: [file.path])]) .build - with_client(test_config(data_system_config: data_system)) do |client| + with_client(test_config(data_system: data_system)) do |client| expect(client.initialized?).to eq(true) expect(client.variation("flag1", user, "default")).to eq("on") expect(client.variation("flag2", user, "default")).to eq("value2") diff --git a/spec/integrations/test_data_v2/flag_builder_v2_spec.rb b/spec/integrations/test_data/flag_builder_spec.rb similarity index 81% rename from spec/integrations/test_data_v2/flag_builder_v2_spec.rb rename to spec/integrations/test_data/flag_builder_spec.rb index 4a897962..5ced9e9a 100644 --- a/spec/integrations/test_data_v2/flag_builder_v2_spec.rb +++ b/spec/integrations/test_data/flag_builder_spec.rb @@ -1,9 +1,9 @@ -require "ldclient-rb/integrations/test_data_v2" +require "ldclient-rb/integrations/test_data" require "spec_helper" module LaunchDarkly module Integrations - describe 'TestDataV2' do + describe 'TestData' do def boolean_flag_hash(key, version, overrides = {}) { key: key, @@ -18,12 +18,12 @@ def boolean_flag_hash(key, version, overrides = {}) end it 'flag defaults to a boolean flag' do - td = TestDataV2.data_source + td = TestData.data_source expect(td.flag('flag').build(1)).to eql(boolean_flag_hash('flag', 1)) end it 'flag returns a copy of the stored builder' do - td = TestDataV2.data_source + td = TestData.data_source td.update(td.flag('flag').variation_for_all(true)) expect(td.flag('flag').build(1)[:fallthrough]).to eql({ variation: 0 }) @@ -33,13 +33,13 @@ def boolean_flag_hash(key, version, overrides = {}) end it 'update gives a new flag version 1' do - td = TestDataV2.data_source + td = TestData.data_source td.update(td.flag('flag')) expect(td.make_init_data[:flags][:flag]).to eql(boolean_flag_hash('flag', 1)) end it 'update increments the version of an existing flag' do - td = TestDataV2.data_source + td = TestData.data_source td.update(td.flag('flag')) td.update(td.flag('flag').variation_for_all(false)) expect(td.make_init_data[:flags][:flag]).to eql(boolean_flag_hash('flag', 2, fallthrough: { variation: 1 })) @@ -51,7 +51,7 @@ def boolean_flag_hash(key, version, overrides = {}) end it 'update does not store later changes to the builder' do - td = TestDataV2.data_source + td = TestData.data_source builder = td.flag('flag') td.update(builder) builder.variation_for_all(false) @@ -60,9 +60,13 @@ def boolean_flag_hash(key, version, overrides = {}) expect(td.flag('flag').build(1)).to eql(boolean_flag_hash('flag', 1)) end - describe 'FlagBuilderV2' do + describe 'FlagBuilder' do + it 'returns its flag key' do + expect(TestData.data_source.flag('flag').key).to eq('flag') + end + it 'defaults to targeting on with the key and version' do - f = TestDataV2::FlagBuilderV2.new('flag').build(1) + f = TestData::FlagBuilder.new('flag').build(1) expect(f).to eql({ key: 'flag', version: 1, @@ -74,68 +78,68 @@ def boolean_flag_hash(key, version, overrides = {}) end it 'can set targeting off' do - f = TestDataV2::FlagBuilderV2.new('flag').on(false).build(1) + f = TestData::FlagBuilder.new('flag').on(false).build(1) expect(f[:on]).to eq(false) end it 'can set targeting on' do - f = TestDataV2::FlagBuilderV2.new('flag').on(false).on(true).build(1) + f = TestData::FlagBuilder.new('flag').on(false).on(true).build(1) expect(f[:on]).to eq(true) end it 'can set the fallthrough variation by index' do - f = TestDataV2::FlagBuilderV2.new('flag').fallthrough_variation(2).build(1) + f = TestData::FlagBuilder.new('flag').fallthrough_variation(2).build(1) expect(f[:fallthrough]).to eql({ variation: 2 }) expect(f[:variations]).to eql([]) expect(f.keys).to_not include(:offVariation) end it 'can set the off variation by index' do - f = TestDataV2::FlagBuilderV2.new('flag').off_variation(2).build(1) + f = TestData::FlagBuilder.new('flag').off_variation(2).build(1) expect(f[:offVariation]).to eq(2) expect(f[:variations]).to eql([]) expect(f.keys).to_not include(:fallthrough) end it 'can set a list of variations' do - f = TestDataV2::FlagBuilderV2.new('flag').variations('red', 'green', 'blue').build(1) + f = TestData::FlagBuilder.new('flag').variations('red', 'green', 'blue').build(1) expect(f[:variations]).to eql(%w[red green blue]) end it 'has the boolean_flag shortcut method' do - f = TestDataV2::FlagBuilderV2.new('flag').boolean_flag.build(1) + f = TestData::FlagBuilder.new('flag').boolean_flag.build(1) expect(f).to eql(boolean_flag_hash('flag', 1)) end it 'boolean_flag keeps the settings of a flag that is already boolean' do - f = TestDataV2::FlagBuilderV2.new('flag').boolean_flag.off_variation(0).fallthrough_variation(1) + f = TestData::FlagBuilder.new('flag').boolean_flag.off_variation(0).fallthrough_variation(1) .boolean_flag.build(1) expect(f).to eql(boolean_flag_hash('flag', 1, offVariation: 0, fallthrough: { variation: 1 })) end it 'off_variation with a boolean changes the flag to a boolean flag' do - f = TestDataV2::FlagBuilderV2.new('flag').variations('a', 'b', 'c').off_variation(true).build(1) + f = TestData::FlagBuilder.new('flag').variations('a', 'b', 'c').off_variation(true).build(1) expect(f).to eql(boolean_flag_hash('flag', 1, offVariation: 0)) - f2 = TestDataV2::FlagBuilderV2.new('flag').off_variation(false).build(1) + f2 = TestData::FlagBuilder.new('flag').off_variation(false).build(1) expect(f2).to eql(boolean_flag_hash('flag', 1)) end it 'fallthrough_variation with a boolean changes the flag to a boolean flag' do - f = TestDataV2::FlagBuilderV2.new('flag').variations('a', 'b', 'c').fallthrough_variation(false).build(1) + f = TestData::FlagBuilder.new('flag').variations('a', 'b', 'c').fallthrough_variation(false).build(1) expect(f).to eql(boolean_flag_hash('flag', 1, fallthrough: { variation: 1 })) - f2 = TestDataV2::FlagBuilderV2.new('flag').fallthrough_variation(true).build(1) + f2 = TestData::FlagBuilder.new('flag').fallthrough_variation(true).build(1) expect(f2).to eql(boolean_flag_hash('flag', 1)) end it 'can set the variation for all contexts with a boolean' do - f = TestDataV2::FlagBuilderV2.new('flag').on(false).variation_for_all(false).build(1) + f = TestData::FlagBuilder.new('flag').on(false).variation_for_all(false).build(1) expect(f).to eql(boolean_flag_hash('flag', 1, fallthrough: { variation: 1 })) end it 'can set the variation for all contexts with an index' do - f = TestDataV2::FlagBuilderV2.new('flag').variations('a', 'b', 'c').off_variation(0).on(false) + f = TestData::FlagBuilder.new('flag').variations('a', 'b', 'c').off_variation(0).on(false) .variation_for_all(2).build(1) expect(f).to eql({ key: 'flag', @@ -150,7 +154,7 @@ def boolean_flag_hash(key, version, overrides = {}) end it 'clears existing rules and targets when setting the variation for all contexts' do - f = TestDataV2::FlagBuilderV2.new('flag') + f = TestData::FlagBuilder.new('flag') .if_match('name', 'ben') .then_return(false) .variation_for_user('ben', false) @@ -161,7 +165,7 @@ def boolean_flag_hash(key, version, overrides = {}) end it 'can set a single value for all contexts' do - f = TestDataV2::FlagBuilderV2.new('flag') + f = TestData::FlagBuilder.new('flag') .boolean_flag .if_match('name', 'ben') .then_return(false) @@ -176,14 +180,14 @@ def boolean_flag_hash(key, version, overrides = {}) end it 'can set a variation for a user key with a boolean' do - f = TestDataV2::FlagBuilderV2.new('flag').variation_for_user('ben', false).build(1) + f = TestData::FlagBuilder.new('flag').variation_for_user('ben', false).build(1) expect(f[:variations]).to eql([true, false]) expect(f[:targets]).to eql([{ variation: 1, values: ['ben'] }]) expect(f[:contextTargets]).to eql([{ contextKind: 'user', variation: 1, values: [] }]) end it 'can set a variation for a user key with an index' do - f = TestDataV2::FlagBuilderV2.new('flag').variations('a', 'b', 'c') + f = TestData::FlagBuilder.new('flag').variations('a', 'b', 'c') .variation_for_user('ben', 2) .variation_for_user('amy', 2) .build(1) @@ -193,13 +197,13 @@ def boolean_flag_hash(key, version, overrides = {}) end it 'can set a variation for a key of another context kind' do - f = TestDataV2::FlagBuilderV2.new('flag').variation_for_key('org', 'acme', true).build(1) + f = TestData::FlagBuilder.new('flag').variation_for_key('org', 'acme', true).build(1) expect(f.keys).to_not include(:targets) expect(f[:contextTargets]).to eql([{ contextKind: 'org', variation: 0, values: ['acme'] }]) end it 'moves a key to the new variation when its variation changes' do - f = TestDataV2::FlagBuilderV2.new('flag') + f = TestData::FlagBuilder.new('flag') .variation_for_user('ben', false) .variation_for_user('ben', true) .build(1) @@ -210,7 +214,7 @@ def boolean_flag_hash(key, version, overrides = {}) end it 'can clear targets' do - f = TestDataV2::FlagBuilderV2.new('flag') + f = TestData::FlagBuilder.new('flag') .variation_for_user('ben', false) .variation_for_key('org', 'acme', true) .clear_targets @@ -219,7 +223,7 @@ def boolean_flag_hash(key, version, overrides = {}) end it 'clone gives an independent copy of the targets' do - f = TestDataV2::FlagBuilderV2.new('flag').variation_for_user('ben', false) + f = TestData::FlagBuilder.new('flag').variation_for_user('ben', false) f2 = f.clone.variation_for_user('ben', true).variation_for_user('amy', false) expect(f.build(1)[:targets]).to eql([{ variation: 1, values: ['ben'] }]) @@ -230,7 +234,7 @@ def boolean_flag_hash(key, version, overrides = {}) end it 'dup gives an independent copy of the settings' do - fb = TestDataV2::FlagBuilderV2.new('flag').variation_for_all(true) + fb = TestData::FlagBuilder.new('flag').variation_for_all(true) expect(fb.dup.build(1)).to eql(fb.build(1)) fcopy = fb.dup.variation_for_all(false).build(1) @@ -240,13 +244,13 @@ def boolean_flag_hash(key, version, overrides = {}) end it 'clone gives an independent copy of the variations' do - fb = TestDataV2::FlagBuilderV2.new('flag').variations('a', 'b') + fb = TestData::FlagBuilder.new('flag').variations('a', 'b') fb.clone.build(1)[:variations] << 'c' expect(fb.build(1)[:variations]).to eql(%w[a b]) end it 'clone gives an independent copy of the rules' do - fb = TestDataV2::FlagBuilderV2.new('flag').if_match('name', 'ben').then_return(true) + fb = TestData::FlagBuilder.new('flag').if_match('name', 'ben').then_return(true) fcopy = fb.clone.if_match('name', 'amy').then_return(false) expect(fb.build(1)[:rules].length).to eq(1) @@ -262,28 +266,28 @@ def clause(attribute, values, negate, context_kind = 'user') end it 'can build a rule with if_match' do - f = TestDataV2::FlagBuilderV2.new('flag').if_match('name', 'ben', 'amy').then_return(true).build(1) + f = TestData::FlagBuilder.new('flag').if_match('name', 'ben', 'amy').then_return(true).build(1) expect(f[:rules]).to eql([ { id: 'rule0', variation: 0, clauses: [clause('name', %w[ben amy], false)] }, ]) end it 'can build a rule with if_not_match' do - f = TestDataV2::FlagBuilderV2.new('flag').if_not_match('name', 'ben').then_return(false).build(1) + f = TestData::FlagBuilder.new('flag').if_not_match('name', 'ben').then_return(false).build(1) expect(f[:rules]).to eql([ { id: 'rule0', variation: 1, clauses: [clause('name', ['ben'], true)] }, ]) end it 'can build a rule with if_match_context' do - f = TestDataV2::FlagBuilderV2.new('flag').if_match_context('org', 'name', 'acme').then_return(true).build(1) + f = TestData::FlagBuilder.new('flag').if_match_context('org', 'name', 'acme').then_return(true).build(1) expect(f[:rules]).to eql([ { id: 'rule0', variation: 0, clauses: [clause('name', ['acme'], false, 'org')] }, ]) end it 'can build a rule with if_not_match_context' do - f = TestDataV2::FlagBuilderV2.new('flag').if_not_match_context('org', 'name', 'acme').then_return(true) + f = TestData::FlagBuilder.new('flag').if_not_match_context('org', 'name', 'acme').then_return(true) .build(1) expect(f[:rules]).to eql([ { id: 'rule0', variation: 0, clauses: [clause('name', ['acme'], true, 'org')] }, @@ -291,7 +295,7 @@ def clause(attribute, values, negate, context_kind = 'user') end it 'can add clauses with and_match and and_not_match' do - f = TestDataV2::FlagBuilderV2.new('flag') + f = TestData::FlagBuilder.new('flag') .if_match('name', 'ben') .and_match('country', 'us') .and_not_match('state', 'ca') @@ -311,7 +315,7 @@ def clause(attribute, values, negate, context_kind = 'user') end it 'can add clauses with and_match_context and and_not_match_context' do - f = TestDataV2::FlagBuilderV2.new('flag') + f = TestData::FlagBuilder.new('flag') .if_match('name', 'ben') .and_match_context('org', 'name', 'acme') .and_not_match_context('org', 'country', 'fr') @@ -331,7 +335,7 @@ def clause(attribute, values, negate, context_kind = 'user') end it 'then_return with a boolean changes the flag to a boolean flag' do - f = TestDataV2::FlagBuilderV2.new('flag').variations('a', 'b', 'c').if_match('name', 'ben') + f = TestData::FlagBuilder.new('flag').variations('a', 'b', 'c').if_match('name', 'ben') .then_return(false).build(1) expect(f).to eql(boolean_flag_hash('flag', 1, rules: [ { id: 'rule0', variation: 1, clauses: [clause('name', ['ben'], false)] }, @@ -339,7 +343,7 @@ def clause(attribute, values, negate, context_kind = 'user') end it 'then_return with an index keeps the variations' do - f = TestDataV2::FlagBuilderV2.new('flag').variations('a', 'b', 'c').if_match('name', 'ben') + f = TestData::FlagBuilder.new('flag').variations('a', 'b', 'c').if_match('name', 'ben') .then_return(2).build(1) expect(f[:variations]).to eql(%w[a b c]) expect(f[:rules]).to eql([ @@ -348,7 +352,7 @@ def clause(attribute, values, negate, context_kind = 'user') end it 'numbers the rule ids in order' do - f = TestDataV2::FlagBuilderV2.new('flag') + f = TestData::FlagBuilder.new('flag') .if_match('name', 'ben').then_return(true) .if_not_match('name', 'amy').then_return(false) .build(1) @@ -359,7 +363,7 @@ def clause(attribute, values, negate, context_kind = 'user') end it 'can clear rules' do - f = TestDataV2::FlagBuilderV2.new('flag') + f = TestData::FlagBuilder.new('flag') .if_match('name', 'ben').then_return(true) .if_match('name', 'amy').then_return(false) .clear_rules diff --git a/spec/integrations/test_data_v2_spec.rb b/spec/integrations/test_data_spec.rb similarity index 89% rename from spec/integrations/test_data_v2_spec.rb rename to spec/integrations/test_data_spec.rb index 0c519fa8..68be5259 100644 --- a/spec/integrations/test_data_v2_spec.rb +++ b/spec/integrations/test_data_spec.rb @@ -1,21 +1,21 @@ -require "ldclient-rb/integrations/test_data_v2" -require "ldclient-rb/impl/integrations/test_data/test_data_source_v2" +require "ldclient-rb/integrations/test_data" +require "ldclient-rb/impl/integrations/test_data/test_data_source" require "spec_helper" require "json" require "set" module LaunchDarkly module Integrations - describe 'TestDataV2' do + describe 'TestData' do it 'initializes with empty flags and segments' do - td = TestDataV2.data_source + td = TestData.data_source init_data = td.make_init_data expect(init_data[:flags]).to eq({}) expect(init_data[:segments]).to eq({}) end it 'stores flags' do - td = TestDataV2.data_source + td = TestData.data_source td.update(td.flag('myflag').variation_for_all(true)) init_data = td.make_init_data expect(init_data[:flags].keys).to include(:myflag) @@ -23,7 +23,7 @@ module Integrations end it 'stores preconfigured segments' do - td = TestDataV2.data_source + td = TestData.data_source td.use_preconfigured_segment({ key: 'mysegment', version: 100, included: ['user1'] }) init_data = td.make_init_data expect(init_data[:segments].keys).to include(:mysegment) @@ -33,7 +33,7 @@ module Integrations end it 'handles segments with string-keyed hashes' do - td = TestDataV2.data_source + td = TestData.data_source # Use string keys instead of symbol keys td.use_preconfigured_segment({ 'key' => 'mysegment', 'version' => 100, 'included' => ['user1'], 'excluded' => ['user2'] }) init_data = td.make_init_data @@ -45,7 +45,7 @@ module Integrations end it 'increments segment version on update' do - td = TestDataV2.data_source + td = TestData.data_source td.use_preconfigured_segment({ key: 'mysegment', version: 100 }) td.use_preconfigured_segment({ key: 'mysegment', included: ['user2'] }) init_data = td.make_init_data @@ -54,7 +54,7 @@ module Integrations end it 'stores preconfigured flags with their own version' do - td = TestDataV2.data_source + td = TestData.data_source td.use_preconfigured_flag({ key: 'myflag', version: 100, on: true, variations: ['a'] }) flag = td.make_init_data[:flags][:myflag] expect(flag[:key]).to eq('myflag') @@ -63,13 +63,13 @@ module Integrations end it 'gives a preconfigured flag with no version version 1' do - td = TestDataV2.data_source + td = TestData.data_source td.use_preconfigured_flag({ 'key' => 'myflag', 'variations' => ['a'] }) expect(td.make_init_data[:flags][:myflag][:version]).to eq(1) end it 'increments the version when a preconfigured flag replaces a flag' do - td = TestDataV2.data_source + td = TestData.data_source td.use_preconfigured_flag({ key: 'myflag', version: 100, variations: ['a'] }) td.use_preconfigured_flag({ key: 'myflag', version: 5, variations: ['b'] }) flag = td.make_init_data[:flags][:myflag] @@ -78,42 +78,42 @@ module Integrations end it 'accepts a FeatureFlag model as a preconfigured flag' do - td = TestDataV2.data_source + td = TestData.data_source model = LaunchDarkly::Impl::Model::FeatureFlag.new({ key: 'myflag', version: 3, variations: ['a'] }) td.use_preconfigured_flag(model) expect(td.make_init_data[:flags][:myflag][:version]).to eq(3) end it 'starts a new flag builder after a preconfigured flag replaces a built flag' do - td = TestDataV2.data_source + td = TestData.data_source td.update(td.flag('myflag').variations('x', 'y')) td.use_preconfigured_flag({ key: 'myflag', variations: ['a'] }) expect(td.flag('myflag').build(1)[:variations]).to eq([true, false]) end it 'sends a preconfigured flag to a running data source' do - td = TestDataV2.data_source - source = LaunchDarkly::Impl::Integrations::TestData::TestDataSourceV2.new(td) + td = TestData.data_source + source = LaunchDarkly::Impl::Integrations::TestData::TestDataSource.new(td) td.subscribe(source) expect(source).to receive(:upsert_flag).with(hash_including(key: 'myflag', version: 7)) td.use_preconfigured_flag({ key: 'myflag', version: 7, variations: ['a'] }) end it 'keeps a provided version that is greater than the version of the flag it replaces' do - td = TestDataV2.data_source + td = TestData.data_source td.use_preconfigured_flag({ key: 'myflag', version: 5, variations: ['a'] }) td.use_preconfigured_flag({ key: 'myflag', version: 100, variations: ['b'] }) expect(td.make_init_data[:flags][:myflag][:version]).to eq(100) end it 'gives a new preconfigured flag with version 0 version 1' do - td = TestDataV2.data_source + td = TestData.data_source td.use_preconfigured_flag({ key: 'myflag', version: 0, variations: ['a'] }) expect(td.make_init_data[:flags][:myflag][:version]).to eq(1) end it 'converts string keys at every level of a preconfigured flag to symbols' do - td = TestDataV2.data_source + td = TestData.data_source flag_json = '{"key":"myflag","version":3,"on":true,"fallthrough":{"variation":0},"variations":["a"],' \ '"rules":[{"id":"r","variation":0,"clauses":[{"attribute":"key","op":"in","values":["u"]}]}]}' td.use_preconfigured_flag(JSON.parse(flag_json)) @@ -123,13 +123,13 @@ module Integrations end it 'accepts a preconfigured flag as a JSON string' do - td = TestDataV2.data_source + td = TestData.data_source td.use_preconfigured_flag('{"key":"myflag","version":3,"variations":["a"]}') expect(td.make_init_data[:flags][:myflag][:version]).to eq(3) end it 'stores a copy of a preconfigured flag' do - td = TestDataV2.data_source + td = TestData.data_source flag = { key: 'myflag', version: 1, fallthrough: { variation: 0 }, variations: ['a'] } td.use_preconfigured_flag(flag) flag[:fallthrough][:variation] = 1 @@ -140,7 +140,7 @@ module Integrations end it 'does not change a stored flag when its rule builder changes later' do - td = TestDataV2.data_source + td = TestData.data_source builder = td.flag('myflag') rule = builder.if_match('name', 'alice') rule.then_return(true) @@ -167,7 +167,7 @@ module Integrations 'a hash key that is not a string or symbol' => { key: 'myflag', variations: [{ 1 => 'a' }] }, }.each do |name, flag| it "with #{name}" do - td = TestDataV2.data_source + td = TestData.data_source td.use_preconfigured_flag({ key: 'other', version: 1, variations: ['a'] }) expect { td.use_preconfigured_flag(flag) }.to raise_error(ArgumentError) expect(td.make_init_data[:flags].keys).to eq([:other]) @@ -183,7 +183,7 @@ module Integrations 'a malformed rule' => { key: 'myseg', rules: ['oops'] }, }.each do |name, segment| it "with #{name}" do - td = TestDataV2.data_source + td = TestData.data_source expect { td.use_preconfigured_segment(segment) }.to raise_error(ArgumentError) expect(td.make_init_data[:segments]).to eq({}) end @@ -193,25 +193,25 @@ module Integrations it 'rejects a preconfigured flag that is nested too deeply' do deep = 'a' 150.times { deep = [deep] } - td = TestDataV2.data_source + td = TestData.data_source expect { td.use_preconfigured_flag({ key: 'myflag', variations: [deep] }) }.to raise_error(ArgumentError) end it 'rejects a preconfigured flag that contains itself' do flag = { key: 'myflag', variations: [] } flag[:variations] << flag - td = TestDataV2.data_source + td = TestData.data_source expect { td.use_preconfigured_flag(flag) }.to raise_error(ArgumentError) end it 'stores Set values of a preconfigured segment as arrays' do - td = TestDataV2.data_source + td = TestData.data_source td.use_preconfigured_segment({ key: 'myseg', included: Set['u1', 'u2'] }) expect(td.make_init_data[:segments][:myseg][:included]).to eq(%w[u1 u2]) end it 'stores symbol values of a preconfigured flag as strings' do - td = TestDataV2.data_source + td = TestData.data_source td.use_preconfigured_flag({ key: 'myflag', variations: [:a], rules: [{ id: 'r', variation: 0, clauses: [{ attribute: 'key', op: :in, values: ['u'] }] }] }) flag = td.make_init_data[:flags][:myflag] expect(flag[:variations]).to eq(['a']) @@ -219,7 +219,7 @@ module Integrations end it 'converts string keys at every level of a preconfigured segment to symbols' do - td = TestDataV2.data_source + td = TestData.data_source td.use_preconfigured_segment(JSON.parse('{"key":"myseg","rules":[{"id":"r","clauses":[{"attribute":"key","op":"in","values":["u"]}]}]}')) expect(td.make_init_data[:segments][:myseg][:rules][0][:clauses][0][:op]).to eq('in') end @@ -242,7 +242,7 @@ module Integrations end def expect_delivery_in_order - td = TestDataV2.data_source + td = TestData.data_source td.subscribe(instance) first = Thread.new { yield td, 1 } second = nil @@ -271,36 +271,36 @@ def expect_delivery_in_order end end - describe 'FlagBuilderV2 event and migration settings' do + describe 'FlagBuilder event and migration settings' do it 'omits the settings by default' do - flag = TestDataV2.data_source.flag('myflag').build(1) + flag = TestData.data_source.flag('myflag').build(1) expect(flag).not_to include(:migration, :samplingRatio, :excludeFromSummaries) end it 'includes migration settings' do - settings = TestDataV2::FlagBuilderV2::FlagMigrationSettingsBuilder.new.check_ratio(10).build - flag = TestDataV2.data_source.flag('myflag').migration_settings(settings).build(1) + settings = TestData::FlagBuilder::FlagMigrationSettingsBuilder.new.check_ratio(10).build + flag = TestData.data_source.flag('myflag').migration_settings(settings).build(1) expect(flag[:migration]).to eq({ checkRatio: 10 }) end it 'builds no migration settings for the default check ratio' do - expect(TestDataV2::FlagBuilderV2::FlagMigrationSettingsBuilder.new.check_ratio(1).build).to be_nil + expect(TestData::FlagBuilder::FlagMigrationSettingsBuilder.new.check_ratio(1).build).to be_nil end it 'includes a sampling ratio other than 1' do - td = TestDataV2.data_source + td = TestData.data_source expect(td.flag('myflag').sampling_ratio(10).build(1)[:samplingRatio]).to eq(10) expect(td.flag('myflag').sampling_ratio(1).build(1)).not_to include(:samplingRatio) end it 'includes exclude from summaries when set' do - td = TestDataV2.data_source + td = TestData.data_source expect(td.flag('myflag').exclude_from_summaries(true).build(1)[:excludeFromSummaries]).to be true expect(td.flag('myflag').exclude_from_summaries(false).build(1)).not_to include(:excludeFromSummaries) end it 'copies the settings when the builder is copied' do - td = TestDataV2.data_source + td = TestData.data_source td.update(td.flag('myflag').sampling_ratio(10).exclude_from_summaries(true)) flag = td.flag('myflag').build(1) expect(flag[:samplingRatio]).to eq(10) @@ -309,7 +309,7 @@ def expect_delivery_in_order end it 'returns the value_for_all value whether targeting is on or off' do - td = TestDataV2.data_source + td = TestData.data_source flag = td.flag('myflag').value_for_all('x').build(1) expect(flag[:variations]).to eq(['x']) expect(flag[:fallthrough]).to eq({ variation: 0 }) @@ -319,10 +319,10 @@ def expect_delivery_in_order expect(off_flag[:offVariation]).to eq(0) end - describe 'TestDataSourceV2' do + describe 'TestDataSource' do it 'does not deliver a change from before sync starts after the initial data' do - td = TestDataV2.data_source - source = LaunchDarkly::Impl::Integrations::TestData::TestDataSourceV2.new(td) + td = TestData.data_source + source = LaunchDarkly::Impl::Integrations::TestData::TestDataSource.new(td) td.update(td.flag('myflag').variation_for_all(true)) td.update(td.flag('myflag').variation_for_all(false)) @@ -342,8 +342,8 @@ def expect_delivery_in_order end it 'does not receive changes after it is used as an initializer' do - td = TestDataV2.data_source - source = LaunchDarkly::Impl::Integrations::TestData::TestDataSourceV2.new(td) + td = TestData.data_source + source = LaunchDarkly::Impl::Integrations::TestData::TestDataSource.new(td) source.fetch(nil) expect(source).not_to receive(:upsert_flag) @@ -351,11 +351,11 @@ def expect_delivery_in_order end it 'includes both flags and segments in fetch' do - td = TestDataV2.data_source + td = TestData.data_source td.update(td.flag('myflag').variation_for_all(true)) td.use_preconfigured_segment({ key: 'mysegment', included: ['user1'] }) - source = LaunchDarkly::Impl::Integrations::TestData::TestDataSourceV2.new(td) + source = LaunchDarkly::Impl::Integrations::TestData::TestDataSource.new(td) result = source.fetch(nil) expect(result.success?).to be true @@ -376,8 +376,8 @@ def expect_delivery_in_order end it 'propagates segment updates' do - td = TestDataV2.data_source - source = LaunchDarkly::Impl::Integrations::TestData::TestDataSourceV2.new(td) + td = TestData.data_source + source = LaunchDarkly::Impl::Integrations::TestData::TestDataSource.new(td) updates = [] sync_thread = Thread.new do diff --git a/spec/ldclient_cached_data_warning_spec.rb b/spec/ldclient_cached_data_warning_spec.rb index ac4180a6..08360a39 100644 --- a/spec/ldclient_cached_data_warning_spec.rb +++ b/spec/ldclient_cached_data_warning_spec.rb @@ -19,7 +19,7 @@ def cached_data_config data_system = silent_data_system_builder .data_store(initialized_store, LaunchDarkly::Interfaces::DataSystem::DataStoreMode::READ_WRITE) .build - test_config(logger: logger, data_system_config: data_system) + test_config(logger: logger, data_system: data_system) end def evaluation_warnings(logger) diff --git a/spec/ldclient_end_to_end_spec.rb b/spec/ldclient_end_to_end_spec.rb index 6cae27c6..780492e8 100644 --- a/spec/ldclient_end_to_end_spec.rb +++ b/spec/ldclient_end_to_end_spec.rb @@ -15,7 +15,7 @@ module LaunchDarkly with_server do |poll_server| poll_server.setup_ok_response("/sdk/poll", fdv2_poll_payload(flags: FLAGS_WITH_ALWAYS_TRUE_FLAG), "application/json") - with_client(test_config(data_system_config: polling_data_system_builder(poll_server.base_uri.to_s).build)) do |client| + with_client(test_config(data_system: polling_data_system_builder(poll_server.base_uri.to_s).build)) do |client| expect(client.initialized?).to be true expect(client.variation(ALWAYS_TRUE_FLAG[:key], basic_context, false)).to be true end @@ -26,7 +26,7 @@ module LaunchDarkly with_server do |poll_server| poll_server.setup_status_response("/sdk/poll", 401) - config = test_config(data_system_config: polling_data_system_builder(poll_server.base_uri.to_s).build) + config = test_config(data_system: polling_data_system_builder(poll_server.base_uri.to_s).build) started_at = Time.now ensure_close(LDClient.new(sdk_key, config, 5)) do |client| expect(Time.now - started_at).to be < 5 @@ -48,7 +48,7 @@ module LaunchDarkly .synchronizers([DataSystem.streaming_ds_builder.base_uri(stream_server.base_uri.to_s)]) .build # The SSE worker thread can log after the example ends, so the logger cannot be a test double. - config = test_config(data_system_config: data_system, logger: $null_log) + config = test_config(data_system: data_system, logger: $null_log) started_at = Time.now ensure_close(LDClient.new(sdk_key, config, 5)) do |client| expect(Time.now - started_at).to be < 5 @@ -121,7 +121,7 @@ module LaunchDarkly }) polling = DataSystem.polling_ds_builder.base_uri("http://fake-polling-server").socket_factory(socket_factory) config = test_config( - data_system_config: DataSystem.custom.synchronizers([polling]).build, + data_system: DataSystem.custom.synchronizers([polling]).build, send_events: true, events_uri: "http://fake-events-server", diagnostic_opt_out: true, diff --git a/spec/ldclient_evaluation_spec.rb b/spec/ldclient_evaluation_spec.rb index 83e03116..8ecacc0d 100644 --- a/spec/ldclient_evaluation_spec.rb +++ b/spec/ldclient_evaluation_spec.rb @@ -21,29 +21,29 @@ module LaunchDarkly end it "returns the value for an existing feature" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.update(td.flag("flagkey").variations("value").variation_for_all(0)) - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| expect(client.variation("flagkey", basic_context, "default")).to eq "value" end end it "returns the default value if a feature evaluates to nil" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.use_preconfigured_flag({ # TestData normally won't construct a flag with offVariation: nil key: "flagkey", on: false, offVariation: nil, }) - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| expect(client.variation("flagkey", basic_context, "default")).to eq "default" end end it "can evaluate a flag that references a segment" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source segment = SegmentBuilder.new("segmentkey").included(basic_context.key).build td.use_preconfigured_segment(segment) td.use_preconfigured_flag( @@ -51,13 +51,13 @@ module LaunchDarkly RuleBuilder.new.variation(0).clause(Clauses.match_segment(segment)) ).build) - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| expect(client.variation("flagkey", basic_context, false)).to be true end end it "can evaluate a flag that references a big segment" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source segment = SegmentBuilder.new("segmentkey").unbounded(true).generation(1).build td.use_preconfigured_segment(segment) td.use_preconfigured_flag( @@ -69,7 +69,7 @@ module LaunchDarkly segstore.setup_segment_for_context(basic_context.key, segment, true) big_seg_config = BigSegmentsConfig.new(store: segstore) - with_client(test_config(data_system_config: test_data_system(td), big_segments: big_seg_config)) do |client| + with_client(test_config(data_system: test_data_system(td), big_segments: big_seg_config)) do |client| expect(client.variation("flagkey", basic_context, false)).to be true end end @@ -93,10 +93,10 @@ module LaunchDarkly end it "returns a value for an existing feature" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.update(td.flag("flagkey").variations("value").on(false).off_variation(0)) - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| result = client.variation_detail("flagkey", basic_context, "default") expected = EvaluationDetail.new("value", 0, EvaluationReason::off) expect(result).to eq expected @@ -104,14 +104,14 @@ module LaunchDarkly end it "returns the default value if a feature evaluates to nil" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.use_preconfigured_flag({ # TestData normally won't construct a flag with offVariation: nil key: "flagkey", on: false, offVariation: nil, }) - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| result = client.variation_detail("flagkey", basic_context, "default") expected = EvaluationDetail.new("default", nil, EvaluationReason::off) expect(result).to eq expected @@ -120,7 +120,7 @@ module LaunchDarkly end it "includes big segment status in reason when evaluating a flag that references a big segment" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source segment = SegmentBuilder.new("segmentkey").unbounded(true).generation(1).build td.use_preconfigured_segment(segment) td.use_preconfigured_flag( @@ -133,7 +133,7 @@ module LaunchDarkly segstore.setup_metadata(Time.now) big_seg_config = BigSegmentsConfig.new(store: segstore) - with_client(test_config(data_system_config: test_data_system(td), big_segments: big_seg_config)) do |client| + with_client(test_config(data_system: test_data_system(td), big_segments: big_seg_config)) do |client| result = client.variation_detail("flagkey", basic_context, false) expect(result.value).to be true expect(result.reason.big_segments_status).to eq(BigSegmentsStatus::HEALTHY) @@ -145,7 +145,7 @@ module LaunchDarkly let(:flag1) { { key: "key1", version: 100, offVariation: 0, variations: [ 'value1' ], trackEvents: false } } let(:flag2) { { key: "key2", version: 200, offVariation: 1, variations: %w[x value2], trackEvents: true, debugEventsUntilDate: 1000 } } let(:test_data) { - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.use_preconfigured_flag(flag1) td.use_preconfigured_flag(flag2) td @@ -153,7 +153,7 @@ module LaunchDarkly it "returns flags state" do - with_client(test_config(data_system_config: test_data_system(test_data))) do |client| + with_client(test_config(data_system: test_data_system(test_data))) do |client| state = client.all_flags_state({ key: 'userkey', kind: 'user' }) expect(state.valid?).to be true @@ -182,7 +182,7 @@ module LaunchDarkly end it "correctly includes only top level prerequisite keys" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.use_preconfigured_flag({ key: "top-level-has-prereqs-1", on: true, @@ -207,7 +207,7 @@ module LaunchDarkly td.use_preconfigured_flag({ key: "prereq2", on: true, version: 200, fallthrough: { variation: 0 }, variations: [ 'value' ] }) td.use_preconfigured_flag({ key: "prereq3", on: true, version: 200, fallthrough: { variation: 0 }, variations: [ 'value' ] }) - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| state = client.all_flags_state({ key: 'userkey', kind: 'user' }) expect(state.valid?).to be true @@ -239,13 +239,13 @@ module LaunchDarkly end it "can be filtered for only client-side flags" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.use_preconfigured_flag({ key: "server-side-1", offVariation: 0, variations: [ 'a' ], clientSide: false }) td.use_preconfigured_flag({ key: "server-side-2", offVariation: 0, variations: [ 'b' ], clientSide: false }) td.use_preconfigured_flag({ key: "client-side-1", offVariation: 0, variations: [ 'value1' ], clientSide: true }) td.use_preconfigured_flag({ key: "client-side-2", offVariation: 0, variations: [ 'value2' ], clientSide: true }) - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| state = client.all_flags_state({ key: 'userkey', kind: 'user' }, client_side_only: true) expect(state.valid?).to be true @@ -256,12 +256,12 @@ module LaunchDarkly it "can omit details for untracked flags" do future_time = (Time.now.to_f * 1000).to_i + 100000 - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.use_preconfigured_flag({ key: "key1", version: 100, offVariation: 0, variations: [ 'value1' ], trackEvents: false }) td.use_preconfigured_flag({ key: "key2", version: 200, offVariation: 1, variations: %w[x value2], trackEvents: true }) td.use_preconfigured_flag({ key: "key3", version: 300, offVariation: 1, variations: %w[x value3], debugEventsUntilDate: future_time }) - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| state = client.all_flags_state({ key: 'userkey', kind: 'user' }, { details_only_for_tracked_flags: true }) expect(state.valid?).to be true @@ -294,7 +294,7 @@ module LaunchDarkly end it "returns empty state for nil context" do - with_client(test_config(data_system_config: test_data_system(test_data))) do |client| + with_client(test_config(data_system: test_data_system(test_data))) do |client| state = client.all_flags_state(nil) expect(state.valid?).to be false expect(state.values_map).to eq({}) @@ -302,7 +302,7 @@ module LaunchDarkly end it "returns empty state for nil context key" do - with_client(test_config(data_system_config: test_data_system(test_data))) do |client| + with_client(test_config(data_system: test_data_system(test_data))) do |client| state = client.all_flags_state({}) expect(state.valid?).to be false expect(state.values_map).to eq({}) @@ -310,7 +310,7 @@ module LaunchDarkly end it "returns empty state if offline" do - with_client(test_config(data_system_config: test_data_system(test_data), offline: true)) do |offline_client| + with_client(test_config(data_system: test_data_system(test_data), offline: true)) do |offline_client| state = offline_client.all_flags_state({ key: 'userkey' }) expect(state.valid?).to be false expect(state.values_map).to eq({}) @@ -318,7 +318,7 @@ module LaunchDarkly end it "returns empty state if store is not initialize" do - with_client(test_config(data_system_config: silent_data_system_builder.build), 0) do |offline_client| + with_client(test_config(data_system: silent_data_system_builder.build), 0) do |offline_client| state = offline_client.all_flags_state({ key: 'userkey' }) expect(state.valid?).to be false expect(state.values_map).to eq({}) diff --git a/spec/ldclient_events_spec.rb b/spec/ldclient_events_spec.rb index f12b134c..b51052a0 100644 --- a/spec/ldclient_events_spec.rb +++ b/spec/ldclient_events_spec.rb @@ -29,11 +29,11 @@ def event_processor(client) end it "known flag" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.update(td.flag("flagkey").variations("value").variation_for_all(0)) context = basic_context - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| expect(event_processor(client)).to receive(:record_eval_event).with( context, 'flagkey', 1, 0, 'value', nil, 'default', false, nil, nil, nil, false ) @@ -42,12 +42,12 @@ def event_processor(client) end it "does not send event, and logs error, if context is nil" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.update(td.flag("flagkey").variations("value").variation_for_all(0)) logger = double.as_null_object - with_client(test_config(data_system_config: test_data_system(td), logger: logger)) do |client| + with_client(test_config(data_system: test_data_system(td), logger: logger)) do |client| expect(event_processor(client)).not_to receive(:record_eval_event) expect(logger).to receive(:error) client.variation("flagkey", nil, "default") @@ -55,13 +55,13 @@ def event_processor(client) end it "does not send event, and logs error, if context key is nil" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.update(td.flag("flagkey").variations("value").variation_for_all(0)) logger = double.as_null_object keyless_user = { key: nil } - with_client(test_config(data_system_config: test_data_system(td), logger: logger)) do |client| + with_client(test_config(data_system: test_data_system(td), logger: logger)) do |client| expect(event_processor(client)).not_to receive(:record_eval_event) expect(logger).to receive(:error) client.variation("flagkey", keyless_user, "default") @@ -69,7 +69,7 @@ def event_processor(client) end it "sets trackEvents and reason if trackEvents is set for matched rule" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.use_preconfigured_flag( FlagBuilder.new("flagkey").version(100).on(true).variations("value") .rule(RuleBuilder.new.variation(0).id("id").track_events(true) @@ -78,7 +78,7 @@ def event_processor(client) ) context = basic_context - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| expect(event_processor(client)).to receive(:record_eval_event).with( context, 'flagkey', 100, 0, 'value', LaunchDarkly::EvaluationReason::rule_match(0, 'id'), 'default', true, nil, nil, nil, false @@ -88,14 +88,14 @@ def event_processor(client) end it "sets trackEvents and reason if trackEventsFallthrough is set and we fell through" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.use_preconfigured_flag( FlagBuilder.new("flagkey").version(100).on(true).variations("value").fallthrough_variation(0) .track_events_fallthrough(true).build ) context = basic_context - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| expect(event_processor(client)).to receive(:record_eval_event).with( context, 'flagkey', 100, 0, 'value', LaunchDarkly::EvaluationReason::fallthrough, 'default', true, nil, nil, nil, false @@ -119,11 +119,11 @@ def event_processor(client) end it "known flag" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.update(td.flag("flagkey").variations("value").on(false).off_variation(0)) context = basic_context - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| expect(event_processor(client)).to receive(:record_eval_event).with( context, 'flagkey', 1, 0, 'value', LaunchDarkly::EvaluationReason::off, 'default', false, nil, nil, nil, false @@ -133,12 +133,12 @@ def event_processor(client) end it "does not send event, and logs error, if context is nil" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.update(td.flag("flagkey").variations("value").on(false).off_variation(0)) logger = double.as_null_object - with_client(test_config(data_system_config: test_data_system(td), logger: logger)) do |client| + with_client(test_config(data_system: test_data_system(td), logger: logger)) do |client| expect(event_processor(client)).not_to receive(:record_eval_event) expect(logger).to receive(:error) client.variation_detail("flagkey", nil, "default") @@ -146,12 +146,12 @@ def event_processor(client) end it "does not send event, and logs warning, if context key is nil" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.update(td.flag("flagkey").variations("value").on(false).off_variation(0)) logger = double.as_null_object - with_client(test_config(data_system_config: test_data_system(td), logger: logger)) do |client| + with_client(test_config(data_system: test_data_system(td), logger: logger)) do |client| expect(event_processor(client)).not_to receive(:record_eval_event) expect(logger).to receive(:error) client.variation_detail("flagkey", { key: nil }, "default") diff --git a/spec/ldclient_fork_spec.rb b/spec/ldclient_fork_spec.rb index 41e020a1..b2a06f52 100644 --- a/spec/ldclient_fork_spec.rb +++ b/spec/ldclient_fork_spec.rb @@ -17,11 +17,11 @@ def pretend_forked # A data source runs on its own thread, so a fork breaks the client. def client_config - test_config(logger: logger, data_system_config: test_data_system(Integrations::TestDataV2.data_source)) + test_config(logger: logger, data_system: test_data_system(Integrations::TestData.data_source)) end def daemon_config(send_events:) - Config.new(data_system_config: DataSystem.daemon(MockFeatureStore.new).build, send_events: send_events, logger: logger) + Config.new(data_system: DataSystem.daemon(MockFeatureStore.new).build, send_events: send_events, logger: logger) end def fork_warnings(logger) diff --git a/spec/ldclient_hooks_spec.rb b/spec/ldclient_hooks_spec.rb index 72691f6e..39c91732 100644 --- a/spec/ldclient_hooks_spec.rb +++ b/spec/ldclient_hooks_spec.rb @@ -102,12 +102,12 @@ module LaunchDarkly context "passing data" do it "hook receives EvaluationDetail" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.update(td.flag("flagkey").variations("value").variation_for_all(0)) detail = nil config_hook = MockHook.new(->(_, _) { }, ->(_, _, d) { detail = d }) - with_client(test_config(data_system_config: test_data_system(td), hooks: [config_hook])) do |client| + with_client(test_config(data_system: test_data_system(td), hooks: [config_hook])) do |client| client.variation("flagkey", basic_context, "default") expect(detail.value).to eq "value" @@ -134,7 +134,7 @@ module LaunchDarkly poll_server.setup_ok_response("/sdk/poll", fdv2_poll_payload, "application/json", { "X-LD-EnvID" => "env-abc" }) config = test_config( - data_system_config: polling_data_system_builder(poll_server.base_uri.to_s).build, + data_system: polling_data_system_builder(poll_server.base_uri.to_s).build, hooks: [config_hook] ) with_client(config) do |client| @@ -181,12 +181,12 @@ module LaunchDarkly context "migration variation" do it "EvaluationDetail contains stage value" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.update(td.flag("flagkey").variations("off").variation_for_all(0)) detail = nil config_hook = MockHook.new(->(_, _) { }, ->(_, _, d) { detail = d }) - with_client(test_config(data_system_config: test_data_system(td), hooks: [config_hook])) do |client| + with_client(test_config(data_system: test_data_system(td), hooks: [config_hook])) do |client| client.migration_variation("flagkey", basic_context, LaunchDarkly::Migrations::STAGE_LIVE) expect(detail.value).to eq LaunchDarkly::Migrations::STAGE_OFF.to_s @@ -196,12 +196,12 @@ module LaunchDarkly end it "EvaluationDetail gets default if flag doesn't evaluate to stage" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.update(td.flag("flagkey").variations("nonstage").variation_for_all(0)) detail = nil config_hook = MockHook.new(->(_, _) { }, ->(_, _, d) { detail = d }) - with_client(test_config(data_system_config: test_data_system(td), hooks: [config_hook])) do |client| + with_client(test_config(data_system: test_data_system(td), hooks: [config_hook])) do |client| client.migration_variation("flagkey", basic_context, LaunchDarkly::Migrations::STAGE_LIVE) expect(detail.value).to eq LaunchDarkly::Migrations::STAGE_LIVE.to_s @@ -211,12 +211,12 @@ module LaunchDarkly end it "EvaluationDetail default gets converted to off if invalid" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.update(td.flag("flagkey").variations("nonstage").variation_for_all(0)) detail = nil config_hook = MockHook.new(->(_, _) { }, ->(_, _, d) { detail = d }) - with_client(test_config(data_system_config: test_data_system(td), hooks: [config_hook])) do |client| + with_client(test_config(data_system: test_data_system(td), hooks: [config_hook])) do |client| client.migration_variation("flagkey", basic_context, :invalid) expect(detail.value).to eq LaunchDarkly::Migrations::STAGE_OFF.to_s diff --git a/spec/ldclient_migration_variation_spec.rb b/spec/ldclient_migration_variation_spec.rb index a0ca73d4..78fcc554 100644 --- a/spec/ldclient_migration_variation_spec.rb +++ b/spec/ldclient_migration_variation_spec.rb @@ -5,9 +5,9 @@ module LaunchDarkly describe "LDClient migration variation tests" do it "returns off if default stage is invalid" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| result, tracker = client.migration_variation("flagkey", basic_context, "invalid stage should default to off") expect(result).to eq(LaunchDarkly::Migrations::STAGE_OFF) @@ -16,9 +16,9 @@ module LaunchDarkly end it "returns error if flag isn't found" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| result, tracker = client.migration_variation("flagkey", basic_context, LaunchDarkly::Migrations::STAGE_LIVE) expect(result).to eq(LaunchDarkly::Migrations::STAGE_LIVE) @@ -27,10 +27,10 @@ module LaunchDarkly end it "flag doesn't return a valid stage" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.update(td.flag("flagkey").variations("value").variation_for_all(0)) - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| result, tracker = client.migration_variation("flagkey", basic_context, LaunchDarkly::Migrations::STAGE_LIVE) tracker.operation(LaunchDarkly::Migrations::OP_READ) tracker.invoked(LaunchDarkly::Migrations::ORIGIN_OLD) @@ -46,10 +46,10 @@ module LaunchDarkly end it "flag doesn't return a valid stage and default is invalid" do - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.update(td.flag("flagkey").variations("value").variation_for_all(0)) - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| result, tracker = client.migration_variation("flagkey", basic_context, "invalid stage") tracker.operation(LaunchDarkly::Migrations::OP_READ) tracker.invoked(LaunchDarkly::Migrations::ORIGIN_OLD) @@ -66,10 +66,10 @@ module LaunchDarkly it "can determine correct stage from flag" do LaunchDarkly::Migrations::VALID_STAGES.each do |stage| - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source td.update(td.flag("flagkey").variations(stage).variation_for_all(0)) - with_client(test_config(data_system_config: test_data_system(td))) do |client| + with_client(test_config(data_system: test_data_system(td))) do |client| result, tracker = client.migration_variation("flagkey", basic_context, LaunchDarkly::Migrations::STAGE_LIVE) expect(result).to eq(stage) diff --git a/spec/ldclient_spec.rb b/spec/ldclient_spec.rb index 0587f667..da7adbf7 100644 --- a/spec/ldclient_spec.rb +++ b/spec/ldclient_spec.rb @@ -10,7 +10,7 @@ def daemon_data_system end def file_data_system - DataSystem.custom.synchronizers([Integrations::FileData.data_source_v2(paths: [])]).build + DataSystem.custom.synchronizers([Integrations::FileData.data_source(paths: [])]).build end context "constructor requirement of non-nil sdk key" do @@ -19,11 +19,11 @@ def file_data_system end it "is not enforced in daemon mode if send_events is false" do - ensure_close(subject.new(nil, Config.new({ data_system_config: daemon_data_system, send_events: false }))) {} + ensure_close(subject.new(nil, Config.new({ data_system: daemon_data_system, send_events: false }))) {} end it "is not enforced if using file data and send_events is false" do - ensure_close(subject.new(nil, Config.new({ data_system_config: file_data_system, send_events: false }))) {} + ensure_close(subject.new(nil, Config.new({ data_system: file_data_system, send_events: false }))) {} end it "is enforced in streaming mode even if send_events is false" do @@ -34,26 +34,26 @@ def file_data_system it "is enforced in polling mode even if send_events is false" do expect { - subject.new(nil, Config.new({ data_system_config: DataSystem.polling.build, send_events: false })) + subject.new(nil, Config.new({ data_system: DataSystem.polling.build, send_events: false })) }.to raise_error(ArgumentError) end it "is enforced in daemon mode if send_events is true" do expect { - subject.new(nil, Config.new({ data_system_config: daemon_data_system })) + subject.new(nil, Config.new({ data_system: daemon_data_system })) }.to raise_error(ArgumentError) end it "is enforced if using file data and send_events is true" do expect { - subject.new(nil, Config.new({ data_system_config: file_data_system })) + subject.new(nil, Config.new({ data_system: file_data_system })) }.to raise_error(ArgumentError) end it "is enforced if the FDv1 fallback needs the SDK key even if send_events is false" do data_system = DataSystem.custom.fdv1_compatible_synchronizer(DataSystem.fdv1_fallback_ds_builder).build expect { - subject.new(nil, Config.new({ data_system_config: data_system, send_events: false })) + subject.new(nil, Config.new({ data_system: data_system, send_events: false })) }.to raise_error(ArgumentError) end end @@ -70,7 +70,7 @@ def file_data_system end it "when in daemon mode" do - client = subject.new("sdk-key", Config.new(data_system_config: daemon_data_system)) + client = subject.new("sdk-key", Config.new(data_system: daemon_data_system)) client.close() end end @@ -103,14 +103,14 @@ def file_data_system it "passes data set to feature store in correct order on init" do store = CapturingFeatureStore.new - td = Integrations::TestDataV2.data_source + td = Integrations::TestData.data_source dependency_ordering_test_data[LaunchDarkly::Interfaces::DataStore::FEATURES].each { |_, flag| td.use_preconfigured_flag(flag) } dependency_ordering_test_data[LaunchDarkly::Interfaces::DataStore::SEGMENTS].each { |_, segment| td.use_preconfigured_segment(segment) } data_system = test_data_system_builder(td) .data_store(store, LaunchDarkly::Interfaces::DataSystem::DataStoreMode::READ_WRITE) .build - with_client(test_config(data_system_config: data_system)) do |_| + with_client(test_config(data_system: data_system)) do |_| data = store.received_data expect(data).not_to be_nil expect(data.count).to eq(2) diff --git a/spec/mock_components.rb b/spec/mock_components.rb index 53acfd4e..4f0784c7 100644 --- a/spec/mock_components.rb +++ b/spec/mock_components.rb @@ -3,7 +3,7 @@ require "ldclient-rb/impl/big_segments" require "ldclient-rb/impl/evaluator" require "ldclient-rb/data_system" -require "ldclient-rb/integrations/test_data_v2" +require "ldclient-rb/integrations/test_data" require "ldclient-rb/interfaces" def sdk_key @@ -51,7 +51,7 @@ def null_logger def base_config { - data_system_config: null_data_system, + data_system: null_data_system, send_events: false, logger: null_logger, }