Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

TestFeatureStore usage #141

Closed
arahlf opened this issue Oct 3, 2018 · 5 comments
Closed

TestFeatureStore usage #141

arahlf opened this issue Oct 3, 2018 · 5 comments

Comments

@arahlf
Copy link

arahlf commented Oct 3, 2018

In the context of some unit tests, I'm using an LDClient configured in offline mode along with a TestFeatureStore that I'm using to stub out values of feature flags. This allows me to completely turn a flag on or off, but is there any way to make that more granular? Specifically, I'm setting some custom attributes on the LDUser, and the actual Feature Toggle when deployed has rules set to look at them, but is there any way to achieve that same effect with TestFeatureStore?

Also, I noticed in the Java docs that TestFeatureStore is deprecated with the hints of a file-based test fixture coming... any update on that?

Thanks

@eli-darkly
Copy link
Contributor

The file-based test fixture has been on our list for quite a while - I've done some work on it in Java and it shouldn't be too hard to finish it, but it's just taken a back seat to other feature work so I'm not sure what the plan is at present. Knowing that there's another request for it now may help to speed things up.

To your other question, no, currently TestFeatureStore doesn't support that. All it really is right now is an InMemoryFeatureStore with some convenience methods for constructing a flag that always returns the same value. Constructing different kinds of flags would require a much richer API that duplicates the internal flag model to some extent, which is probably not a path we want to take - there are a lot of different ways people might want to correlate users with values.

The current plan for the file-based fixture was that for each flag key, it would allow you to either specify JSON data for the complete flag model - allowing any kinds of rules - or just a simple value. I imagine that this could be extended with other options such as a mapping of user keys to values - would that work for your purposes or would you require something that is based on attributes? Either way, the advantage of implementing this in the fixture rather than in the client is that they would be separate projects, so adding features to the fixture would not require re-releasing the client.

@eli-darkly
Copy link
Contributor

Update: we're hoping to release the file-based fixture in Java this week.

@eli-darkly
Copy link
Contributor

Sorry, some design issues have been holding this up, but it is very close to being available.

@eli-darkly
Copy link
Contributor

eli-darkly commented Oct 26, 2018

OK, sorry for the delay, but we have just released Java SDK 4.5.0 which includes a file-based test fixture. Here's an example of how you could configure the client to use it:

    import com.launchdarkly.client.*;
    import com.launchdarkly.client.files.*;

    FileDataSourceFactory fileData = FileComponents.fileDataSource().filePaths("flags.json");
    LDConfig config  = new LDConfig.Builder()
        .updateProcessorFactory(fileData)
        .offline(true)
        .build();
    LDClient client = new LDClient(sdkKey, config);

There are several options for how the data files can be formatted (see the FileComponents class for full documentation), but here's the simplest possible version in JSON:

{
    "flagValues": {
        "myStringFlagKey": "someStringValue",
        "myBooleanFlagKey": true
    }
}

@eli-darkly
Copy link
Contributor

I'm going to close this issue now, but please feel free to reopen it or open a new one if you have any questions or problems regarding this feature.

LaunchDarklyCI pushed a commit that referenced this issue Oct 18, 2019
fix NewRelic reflection logic to avoid shading
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants