Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/java/com/launchdarkly/client/LDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,24 @@ public JsonElement jsonVariation(String featureKey, LDUser user, JsonElement def
return value;
}

@Override
public boolean isFlagKnown(String featureKey) {
if (!initialized()) {
logger.warn("Evaluation called before Client has been initialized for feature flag " + featureKey + "; returning unknown");
return false;
}

try {
if (config.featureStore.get(featureKey) != null) {
return true;
}
} catch (Exception e) {
logger.error("Encountered exception in LaunchDarkly client", e);
}

return false;
}

private JsonElement evaluate(String featureKey, LDUser user, JsonElement defaultValue, VariationType expectedType) {
if (user == null || user.getKey() == null) {
logger.warn("Null user or null user key when evaluating flag: " + featureKey + "; returning default value");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/launchdarkly/client/LDClientInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public interface LDClientInterface extends Closeable {

JsonElement jsonVariation(String featureKey, LDUser user, JsonElement defaultValue);

boolean isFlagKnown(String featureKey);

@Override
void close() throws IOException;

Expand Down
43 changes: 43 additions & 0 deletions src/test/java/com/launchdarkly/client/LDClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,49 @@ public void testTestFeatureStoreJsonVariationArray() throws Exception {
verifyAll();
}

@Test
public void testIsFlagKnown() throws Exception {
TestFeatureStore testFeatureStore = new TestFeatureStore();
LDConfig config = new LDConfig.Builder()
.startWaitMillis(10L)
.stream(false)
.featureStore(testFeatureStore)
.build();

expect(initFuture.get(10L, TimeUnit.MILLISECONDS)).andReturn(new Object());
expect(pollingProcessor.start()).andReturn(initFuture);
expect(pollingProcessor.initialized()).andReturn(true).times(2);
replayAll();

client = createMockClient(config);

testFeatureStore.setIntegerValue("key", 1);
assertTrue("Flag is known", client.isFlagKnown("key"));
assertFalse("Flag is unknown", client.isFlagKnown("unKnownKey"));
verifyAll();
}

@Test
public void testIsFlagKnownCallBeforeInitialization() throws Exception {
TestFeatureStore testFeatureStore = new TestFeatureStore();
LDConfig config = new LDConfig.Builder()
.startWaitMillis(10L)
.stream(false)
.featureStore(testFeatureStore)
.build();

expect(initFuture.get(10L, TimeUnit.MILLISECONDS)).andReturn(new Object());
expect(pollingProcessor.start()).andReturn(initFuture);
expect(pollingProcessor.initialized()).andReturn(false).times(1);
replayAll();

client = createMockClient(config);

testFeatureStore.setIntegerValue("key", 1);
assertFalse("Flag is marked as unknown", client.isFlagKnown("key"));
verifyAll();
}

@Test
public void testUseLdd() throws IOException {
LDConfig config = new LDConfig.Builder()
Expand Down