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

Commit 52f886a

Browse files
prepare 1.3.0 release (#9)
1 parent f76f86a commit 52f886a

File tree

5 files changed

+129
-32
lines changed

5 files changed

+129
-32
lines changed

.ldrelease/publish-docs.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/main/java/com/launchdarkly/sdk/EvaluationReason.java

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,32 @@ public static enum ErrorKind {
9595
*/
9696
EXCEPTION
9797
}
98+
99+
/**
100+
* Enumerated type defining the possible values of {@link #getBigSegmentsStatus()}.
101+
*/
102+
public static enum BigSegmentsStatus {
103+
/**
104+
* Indicates that the Big Segment query involved in the flag evaluation was successful, and that
105+
* the segment state is considered up to date.
106+
*/
107+
HEALTHY,
108+
/**
109+
* Indicates that the Big Segment query involved in the flag evaluation was successful, but that
110+
* the segment state may not be up to date.
111+
*/
112+
STALE,
113+
/**
114+
* Indicates that Big Segments could not be queried for the flag evaluation because the SDK
115+
* configuration did not include a Big Segment store.
116+
*/
117+
NOT_CONFIGURED,
118+
/**
119+
* Indicates that the Big Segment query involved in the flag evaluation failed, for instance due
120+
* to a database error.
121+
*/
122+
STORE_ERROR
123+
}
98124

99125
// static instances to avoid repeatedly allocating reasons for the same parameters
100126
private static final EvaluationReason OFF_INSTANCE = new EvaluationReason(Kind.OFF);
@@ -115,28 +141,30 @@ public static enum ErrorKind {
115141
private final boolean inExperiment;
116142
private final ErrorKind errorKind;
117143
private final Exception exception;
144+
private final BigSegmentsStatus bigSegmentsStatus;
118145

119146
private EvaluationReason(Kind kind, int ruleIndex, String ruleId, String prerequisiteKey, boolean inExperiment,
120-
ErrorKind errorKind, Exception exception) {
147+
ErrorKind errorKind, Exception exception, BigSegmentsStatus bigSegmentsStatus) {
121148
this.kind = kind;
122149
this.ruleIndex = ruleIndex;
123150
this.ruleId = ruleId;
124151
this.prerequisiteKey = prerequisiteKey;
125152
this.inExperiment = inExperiment;
126153
this.errorKind = errorKind;
127154
this.exception = exception;
155+
this.bigSegmentsStatus = bigSegmentsStatus;
128156
}
129157

130158
private EvaluationReason(Kind kind) {
131-
this(kind, -1, null, null, NOT_IN_EXPERIMENT, null, null);
159+
this(kind, -1, null, null, NOT_IN_EXPERIMENT, null, null, null);
132160
}
133161

134162
private EvaluationReason(Kind kind, boolean inExperiment) {
135-
this(kind, -1, null, null, inExperiment, null, null);
163+
this(kind, -1, null, null, inExperiment, null, null, null);
136164
}
137165

138166
private EvaluationReason(ErrorKind errorKind, Exception exception) {
139-
this(Kind.ERROR, -1, null, null, NOT_IN_EXPERIMENT, errorKind, exception);
167+
this(Kind.ERROR, -1, null, null, NOT_IN_EXPERIMENT, errorKind, exception, null);
140168
}
141169

142170
/**
@@ -215,7 +243,33 @@ public ErrorKind getErrorKind() {
215243
public Exception getException() {
216244
return exception;
217245
}
218-
246+
247+
/**
248+
* Describes the validity of Big Segment information, if and only if the flag evaluation required
249+
* querying at least one Big Segment. Otherwise it returns {@code null}.
250+
* <p>
251+
* Big Segments are a specific type of user segments. For more information, read the
252+
* <a href="https://docs.launchdarkly.com/home/users/big-segments">LaunchDarkly documentation
253+
* </a>.
254+
*
255+
* @return the {@link BigSegmentsStatus} from the evaluation or {@code null}
256+
*/
257+
public BigSegmentsStatus getBigSegmentsStatus() {
258+
return bigSegmentsStatus;
259+
}
260+
261+
/**
262+
* Returns a copy of this {@link EvaluationReason} with a specific {@link BigSegmentsStatus}
263+
* value.
264+
*
265+
* @param bigSegmentsStatus the new property value
266+
* @return a new reason object
267+
*/
268+
public EvaluationReason withBigSegmentsStatus(BigSegmentsStatus bigSegmentsStatus) {
269+
return new EvaluationReason(kind, ruleIndex, ruleId, prerequisiteKey, inExperiment, errorKind,
270+
exception, bigSegmentsStatus);
271+
}
272+
219273
/**
220274
* Returns a simple string representation of the reason.
221275
* <p>
@@ -250,14 +304,16 @@ public boolean equals(Object other) {
250304
Objects.equals(prerequisiteKey, o.prerequisiteKey) &&
251305
inExperiment == o.inExperiment &&
252306
Objects.equals(errorKind, o.errorKind) &&
253-
Objects.equals(exception, o.exception);
307+
Objects.equals(exception, o.exception) &&
308+
Objects.equals(bigSegmentsStatus, o.bigSegmentsStatus);
254309
}
255310
return false;
256311
}
257312

258313
@Override
259314
public int hashCode() {
260-
return Objects.hash(kind, ruleIndex, ruleId, prerequisiteKey, inExperiment, errorKind, exception);
315+
return Objects.hash(kind, ruleIndex, ruleId, prerequisiteKey, inExperiment, errorKind,
316+
exception, bigSegmentsStatus);
261317
}
262318

263319
/**
@@ -321,7 +377,7 @@ public static EvaluationReason ruleMatch(int ruleIndex, String ruleId) {
321377
* @return a reason object
322378
*/
323379
public static EvaluationReason ruleMatch(int ruleIndex, String ruleId, boolean inExperiment) {
324-
return new EvaluationReason(Kind.RULE_MATCH, ruleIndex, ruleId, null, inExperiment, null, null);
380+
return new EvaluationReason(Kind.RULE_MATCH, ruleIndex, ruleId, null, inExperiment, null, null, null);
325381
}
326382

327383
/**
@@ -331,7 +387,7 @@ public static EvaluationReason ruleMatch(int ruleIndex, String ruleId, boolean i
331387
* @return a reason object
332388
*/
333389
public static EvaluationReason prerequisiteFailed(String prerequisiteKey) {
334-
return new EvaluationReason(Kind.PREREQUISITE_FAILED, -1, null, prerequisiteKey, NOT_IN_EXPERIMENT, null, null);
390+
return new EvaluationReason(Kind.PREREQUISITE_FAILED, -1, null, prerequisiteKey, NOT_IN_EXPERIMENT, null, null, null);
335391
}
336392

337393
/**

src/main/java/com/launchdarkly/sdk/EvaluationReasonTypeAdapter.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static EvaluationReason parse(JsonReader reader) throws IOException {
2424
String prereqKey = null;
2525
boolean inExperiment = false;
2626
EvaluationReason.ErrorKind errorKind = null;
27+
EvaluationReason.BigSegmentsStatus bigSegmentsStatus = null;
2728

2829
reader.beginObject();
2930
while (reader.peek() != JsonToken.END_OBJECT) {
@@ -47,6 +48,9 @@ static EvaluationReason parse(JsonReader reader) throws IOException {
4748
case "errorKind":
4849
errorKind = readEnum(EvaluationReason.ErrorKind.class, reader);
4950
break;
51+
case "bigSegmentsStatus":
52+
bigSegmentsStatus = readEnum(EvaluationReason.BigSegmentsStatus.class, reader);
53+
break;
5054
default:
5155
reader.skipValue(); // ignore any unexpected property
5256
}
@@ -56,23 +60,34 @@ static EvaluationReason parse(JsonReader reader) throws IOException {
5660
if (kind == null) {
5761
throw new JsonParseException("EvaluationReason missing required property \"kind\"");
5862
}
63+
EvaluationReason reason;
5964
switch (kind) {
6065
case OFF:
61-
return EvaluationReason.off();
66+
reason = EvaluationReason.off();
67+
break;
6268
case FALLTHROUGH:
63-
return EvaluationReason.fallthrough(inExperiment);
69+
reason = EvaluationReason.fallthrough(inExperiment);
70+
break;
6471
case TARGET_MATCH:
65-
return EvaluationReason.targetMatch();
72+
reason = EvaluationReason.targetMatch();
73+
break;
6674
case RULE_MATCH:
67-
return EvaluationReason.ruleMatch(ruleIndex, ruleId, inExperiment);
75+
reason = EvaluationReason.ruleMatch(ruleIndex, ruleId, inExperiment);
76+
break;
6877
case PREREQUISITE_FAILED:
69-
return EvaluationReason.prerequisiteFailed(prereqKey);
78+
reason = EvaluationReason.prerequisiteFailed(prereqKey);
79+
break;
7080
case ERROR:
71-
return EvaluationReason.error(errorKind);
81+
reason = EvaluationReason.error(errorKind);
82+
break;
7283
default:
7384
// COVERAGE: compiler requires default but there are no other values
7485
return null;
7586
}
87+
if (bigSegmentsStatus != null) {
88+
return reason.withBigSegmentsStatus(bigSegmentsStatus);
89+
}
90+
return reason;
7691
}
7792

7893
@Override
@@ -114,6 +129,11 @@ public void write(JsonWriter writer, EvaluationReason reason) throws IOException
114129
default:
115130
break;
116131
}
132+
133+
if (reason.getBigSegmentsStatus() != null) {
134+
writer.name("bigSegmentsStatus");
135+
writer.value(reason.getBigSegmentsStatus().name());
136+
}
117137

118138
writer.endObject();
119139
}

src/test/java/com/launchdarkly/sdk/EvaluationReasonTest.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.launchdarkly.sdk;
22

3-
import org.junit.Test;
4-
5-
import java.util.List;
6-
3+
import static com.launchdarkly.sdk.EvaluationReason.BigSegmentsStatus.HEALTHY;
4+
import static com.launchdarkly.sdk.EvaluationReason.BigSegmentsStatus.STALE;
75
import static com.launchdarkly.sdk.EvaluationReason.ErrorKind.CLIENT_NOT_READY;
86
import static com.launchdarkly.sdk.EvaluationReason.ErrorKind.FLAG_NOT_FOUND;
97
import static com.launchdarkly.sdk.EvaluationReason.ErrorKind.WRONG_TYPE;
@@ -13,10 +11,14 @@
1311
import static com.launchdarkly.sdk.EvaluationReason.Kind.PREREQUISITE_FAILED;
1412
import static com.launchdarkly.sdk.EvaluationReason.Kind.RULE_MATCH;
1513
import static com.launchdarkly.sdk.EvaluationReason.Kind.TARGET_MATCH;
16-
import static java.util.Arrays.asList;
1714
import static org.junit.Assert.assertEquals;
1815
import static org.junit.Assert.assertNull;
1916
import static org.junit.Assert.assertSame;
17+
import static java.util.Arrays.asList;
18+
19+
import org.junit.Test;
20+
21+
import java.util.List;
2022

2123
@SuppressWarnings("javadoc")
2224
public class EvaluationReasonTest extends BaseTest {
@@ -66,10 +68,27 @@ public void basicProperties() {
6668
assertNull(EvaluationReason.prerequisiteFailed("key").getException());
6769
assertNull(EvaluationReason.error(FLAG_NOT_FOUND).getException());
6870
}
71+
72+
@Test
73+
public void bigSegmentsStatus() {
74+
assertNull(EvaluationReason.off().getBigSegmentsStatus());
75+
assertNull(EvaluationReason.fallthrough().getBigSegmentsStatus());
76+
assertNull(EvaluationReason.targetMatch().getBigSegmentsStatus());
77+
assertNull(EvaluationReason.ruleMatch(1, "id").getBigSegmentsStatus());
78+
assertNull(EvaluationReason.prerequisiteFailed("key").getBigSegmentsStatus());
79+
assertNull(EvaluationReason.error(FLAG_NOT_FOUND).getBigSegmentsStatus());
80+
81+
EvaluationReason reason = EvaluationReason.fallthrough();
82+
EvaluationReason withStatus = reason.withBigSegmentsStatus(STALE);
83+
assertEquals(STALE, withStatus.getBigSegmentsStatus());
84+
assertNull(reason.getBigSegmentsStatus());
85+
}
6986

7087
@Test
7188
public void simpleStringRepresentations() {
7289
assertEquals("OFF", EvaluationReason.off().toString());
90+
assertEquals("FALLTHROUGH", EvaluationReason.fallthrough().toString());
91+
assertEquals("FALLTHROUGH", EvaluationReason.fallthrough().withBigSegmentsStatus(HEALTHY).toString());
7392
assertEquals("TARGET_MATCH", EvaluationReason.targetMatch().toString());
7493
assertEquals("RULE_MATCH(1)", EvaluationReason.ruleMatch(1, null).toString());
7594
assertEquals("RULE_MATCH(1,id)", EvaluationReason.ruleMatch(1, "id").toString());
@@ -101,8 +120,11 @@ public void equalInstancesAreEqual() {
101120
List<List<EvaluationReason>> testValues = asList(
102121
asList(EvaluationReason.off(), EvaluationReason.off()),
103122
asList(EvaluationReason.fallthrough(), EvaluationReason.fallthrough()),
123+
asList(EvaluationReason.fallthrough().withBigSegmentsStatus(HEALTHY),
124+
EvaluationReason.fallthrough().withBigSegmentsStatus(HEALTHY)),
104125
asList(EvaluationReason.targetMatch(), EvaluationReason.targetMatch()),
105126
asList(EvaluationReason.ruleMatch(1, "id1"), EvaluationReason.ruleMatch(1, "id1")),
127+
asList(EvaluationReason.ruleMatch(1, "id1", true), EvaluationReason.ruleMatch(1, "id1", true)),
106128
asList(EvaluationReason.ruleMatch(1, "id2"), EvaluationReason.ruleMatch(1, "id2")),
107129
asList(EvaluationReason.ruleMatch(2, "id1"), EvaluationReason.ruleMatch(2, "id1")),
108130
asList(EvaluationReason.prerequisiteFailed("a"), EvaluationReason.prerequisiteFailed("a")),

src/test/java/com/launchdarkly/sdk/json/EvaluationReasonJsonSerializationTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package com.launchdarkly.sdk.json;
22

3+
import static com.launchdarkly.sdk.EvaluationReason.BigSegmentsStatus.HEALTHY;
4+
import static com.launchdarkly.sdk.EvaluationReason.BigSegmentsStatus.STORE_ERROR;
5+
import static com.launchdarkly.sdk.json.JsonTestHelpers.verifyDeserialize;
6+
import static com.launchdarkly.sdk.json.JsonTestHelpers.verifyDeserializeInvalidJson;
7+
import static com.launchdarkly.sdk.json.JsonTestHelpers.verifySerialize;
8+
import static com.launchdarkly.sdk.json.JsonTestHelpers.verifySerializeAndDeserialize;
9+
310
import com.launchdarkly.sdk.BaseTest;
411
import com.launchdarkly.sdk.EvaluationReason;
512

613
import org.junit.Test;
714

8-
import static com.launchdarkly.sdk.json.JsonTestHelpers.verifyDeserializeInvalidJson;
9-
import static com.launchdarkly.sdk.json.JsonTestHelpers.verifyDeserialize;
10-
import static com.launchdarkly.sdk.json.JsonTestHelpers.verifySerialize;
11-
import static com.launchdarkly.sdk.json.JsonTestHelpers.verifySerializeAndDeserialize;
12-
1315
@SuppressWarnings("javadoc")
1416
public class EvaluationReasonJsonSerializationTest extends BaseTest {
1517
@Test
@@ -18,13 +20,17 @@ public void reasonJsonSerializations() throws Exception {
1820
verifySerializeAndDeserialize(EvaluationReason.fallthrough(), "{\"kind\":\"FALLTHROUGH\"}");
1921
verifySerializeAndDeserialize(EvaluationReason.fallthrough(false), "{\"kind\":\"FALLTHROUGH\"}");
2022
verifySerializeAndDeserialize(EvaluationReason.fallthrough(true), "{\"kind\":\"FALLTHROUGH\",\"inExperiment\":true}");
23+
verifySerializeAndDeserialize(EvaluationReason.fallthrough().withBigSegmentsStatus(HEALTHY),
24+
"{\"kind\":\"FALLTHROUGH\",\"bigSegmentsStatus\":\"HEALTHY\"}");
2125
verifySerializeAndDeserialize(EvaluationReason.targetMatch(), "{\"kind\":\"TARGET_MATCH\"}");
2226
verifySerializeAndDeserialize(EvaluationReason.ruleMatch(1, "id"),
2327
"{\"kind\":\"RULE_MATCH\",\"ruleIndex\":1,\"ruleId\":\"id\"}");
2428
verifySerializeAndDeserialize(EvaluationReason.ruleMatch(1, "id", false),
2529
"{\"kind\":\"RULE_MATCH\",\"ruleIndex\":1,\"ruleId\":\"id\"}");
2630
verifySerializeAndDeserialize(EvaluationReason.ruleMatch(1, "id", true),
2731
"{\"kind\":\"RULE_MATCH\",\"ruleIndex\":1,\"ruleId\":\"id\",\"inExperiment\":true}");
32+
verifySerializeAndDeserialize(EvaluationReason.ruleMatch(1, null).withBigSegmentsStatus(STORE_ERROR),
33+
"{\"kind\":\"RULE_MATCH\",\"ruleIndex\":1,\"bigSegmentsStatus\":\"STORE_ERROR\"}");
2834
verifySerializeAndDeserialize(EvaluationReason.ruleMatch(1, null),
2935
"{\"kind\":\"RULE_MATCH\",\"ruleIndex\":1}");
3036
verifySerializeAndDeserialize(EvaluationReason.ruleMatch(1, null, false),

0 commit comments

Comments
 (0)