public final class TestData extends java.lang.Object implements DataSourceFactory
The above example uses a simple boolean flag, but more complex configurations are possible using the methods of the
TestData td = TestData.dataSource(); td.update(testData.flag("flag-key-1").booleanFlag().variationForAllUsers(true)); LDConfig config = new LDConfig.Builder() .dataSource(td) .build(); LDClient client = new LDClient(sdkKey, config); // flags can be updated at any time: td.update(testData.flag("flag-key-2") .variationForUser("some-user-key", true) .fallthroughVariation(false));
TestData.FlagBuilderthat is returned by
TestData.FlagBuildersupports 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
TestData instance is used to configure multiple
any changes made to the data will propagate to all of the
|Modifier and Type||Class and Description|
A builder for feature flag configurations to be used with
|Modifier and Type||Method and Description|
Called internally by the SDK to associate this test data source with an
Creates a new instance of the test data source.
Creates or copies a
Updates the test data with the specified flag configuration.
Simulates a change in the data source status.
public static TestData dataSource()
TestData for details.
public TestData.FlagBuilder flag(java.lang.String key)
TestData.FlagBuilderfor building a test flag configuration.
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
false variations, is
true for all users when targeting is turned on and
false otherwise, and currently has targeting turned on. You can change any of those
properties, and provide more complex behavior, using the
Once you have set the desired configuration, pass the builder to
key- the flag key
public TestData update(TestData.FlagBuilder flagBuilder)
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
TestData. If no
LDClient has been started yet,
it simply adds this flag to the test data which will be provided to any
you subsequently configure.
flagBuilder- a flag configuration builder
public TestData updateStatus(DataSourceStatusProvider.State newState, DataSourceStatusProvider.ErrorInfo newError)
Use this if you want to test the behavior of application code that uses
LDClient.getDataSourceStatusProvider() to track whether the data
source is having problems (for example, a network failure interruptsingthe streaming connection). It
does not actually stop the
TestData data source from working, so even if you have simulated
an outage, calling
update(FlagBuilder) will still send updates.
public DataSource createDataSource(ClientContext context, DataSourceUpdates dataSourceUpdates)
LDClientinstance. You do not need to call this method.