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

Commit 5ead1d8

Browse files
prepare 5.5.1 release (#239)
1 parent e8a7259 commit 5ead1d8

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ ext.versions = [
7474
"jackson": "2.11.2",
7575
"launchdarklyJavaSdkCommon": "1.2.0",
7676
"okhttp": "4.8.1", // specify this for the SDK build instead of relying on the transitive dependency from okhttp-eventsource
77-
"okhttpEventsource": "2.3.1",
77+
"okhttpEventsource": "2.3.2",
7878
"slf4j": "1.7.21",
7979
"snakeyaml": "1.26",
8080
"jedis": "2.9.0"

src/test/java/com/launchdarkly/sdk/server/LDClientEndToEndTest.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
import com.google.gson.JsonObject;
55
import com.launchdarkly.sdk.LDUser;
66
import com.launchdarkly.sdk.LDValue;
7+
import com.launchdarkly.sdk.server.interfaces.DataSourceStatusProvider;
78

89
import org.junit.Test;
910

1011
import java.net.URI;
12+
import java.time.Duration;
13+
import java.util.concurrent.BlockingQueue;
14+
import java.util.concurrent.LinkedBlockingQueue;
1115

1216
import static com.launchdarkly.sdk.server.Components.externalUpdatesOnly;
1317
import static com.launchdarkly.sdk.server.Components.noEvents;
@@ -112,19 +116,54 @@ public void clientStartsInStreamingMode() throws Exception {
112116
}
113117
}
114118

119+
@Test
120+
public void clientStartsInStreamingModeAfterRecoverableError() throws Exception {
121+
MockResponse errorResp = new MockResponse().setResponseCode(503);
122+
123+
String streamData = "event: put\n" +
124+
"data: {\"data\":" + makeAllDataJson() + "}\n\n";
125+
MockResponse streamResp = TestHttpUtil.eventStreamResponse(streamData);
126+
127+
try (MockWebServer server = makeStartedServer(errorResp, streamResp)) {
128+
LDConfig config = new LDConfig.Builder()
129+
.dataSource(baseStreamingConfig(server))
130+
.events(noEvents())
131+
.build();
132+
133+
try (LDClient client = new LDClient(sdkKey, config)) {
134+
assertTrue(client.isInitialized());
135+
assertTrue(client.boolVariation(flagKey, user, false));
136+
}
137+
}
138+
}
139+
115140
@Test
116141
public void clientFailsInStreamingModeWith401Error() throws Exception {
117142
MockResponse resp = new MockResponse().setResponseCode(401);
118143

119-
try (MockWebServer server = makeStartedServer(resp)) {
144+
try (MockWebServer server = makeStartedServer(resp, resp, resp)) {
120145
LDConfig config = new LDConfig.Builder()
121-
.dataSource(baseStreamingConfig(server))
146+
.dataSource(baseStreamingConfig(server).initialReconnectDelay(Duration.ZERO))
122147
.events(noEvents())
123148
.build();
124149

125150
try (LDClient client = new LDClient(sdkKey, config)) {
126151
assertFalse(client.isInitialized());
127152
assertFalse(client.boolVariation(flagKey, user, false));
153+
154+
BlockingQueue<DataSourceStatusProvider.Status> statuses = new LinkedBlockingQueue<>();
155+
client.getDataSourceStatusProvider().addStatusListener(statuses::add);
156+
157+
Thread.sleep(100); // make sure it didn't retry the connection
158+
assertThat(client.getDataSourceStatusProvider().getStatus().getState(),
159+
equalTo(DataSourceStatusProvider.State.OFF));
160+
while (!statuses.isEmpty()) {
161+
// The status listener may or may not have been registered early enough to receive
162+
// the OFF notification, but we should at least not see any *other* statuses.
163+
assertThat(statuses.take().getState(), equalTo(DataSourceStatusProvider.State.OFF));
164+
}
165+
assertThat(statuses.isEmpty(), equalTo(true));
166+
assertThat(server.getRequestCount(), equalTo(1)); // no retries
128167
}
129168
}
130169
}

0 commit comments

Comments
 (0)