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

Commit 69aef50

Browse files
authored
clean up tests using java-test-helpers 1.1.0 (#296)
1 parent 767e3ac commit 69aef50

26 files changed

+255
-466
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ libraries.test = [
161161
"ch.qos.logback:logback-classic:1.1.7",
162162
"com.fasterxml.jackson.core:jackson-core:${versions.jackson}",
163163
"com.fasterxml.jackson.core:jackson-databind:${versions.jackson}",
164-
"com.launchdarkly:test-helpers:1.0.0"
164+
"com.launchdarkly:test-helpers:1.1.0"
165165
]
166166

167167
configurations {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import static com.launchdarkly.sdk.server.DataModel.FEATURES;
2626
import static com.launchdarkly.sdk.server.DataModel.SEGMENTS;
27+
import static com.launchdarkly.testhelpers.JsonAssertions.assertJsonEquals;
2728
import static org.junit.Assert.assertEquals;
2829
import static org.junit.Assert.assertFalse;
2930
import static org.junit.Assert.assertNotNull;
@@ -126,7 +127,7 @@ public void deletedFlagIsConvertedToAndFromJsonPlaceholder() {
126127
assertEquals(99, item.getVersion());
127128

128129
String json1 = FEATURES.serialize(item);
129-
assertEquals(LDValue.parse(json0), LDValue.parse(json1));
130+
assertJsonEquals(json0, json1);
130131
}
131132

132133
@Test
@@ -164,7 +165,7 @@ public void deletedSegmentIsConvertedToAndFromJsonPlaceholder() {
164165
assertEquals(99, item.getVersion());
165166

166167
String json1 = SEGMENTS.serialize(item);
167-
assertEquals(LDValue.parse(json0), LDValue.parse(json1));
168+
assertJsonEquals(json0, json1);
168169
}
169170

170171
@Test

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44
import com.launchdarkly.sdk.server.interfaces.DataSourceStatusProvider.ErrorInfo;
55
import com.launchdarkly.sdk.server.interfaces.DataSourceStatusProvider.State;
66
import com.launchdarkly.sdk.server.interfaces.DataSourceStatusProvider.Status;
7+
import com.launchdarkly.testhelpers.ConcurrentHelpers;
78

89
import org.junit.Test;
910

1011
import java.time.Duration;
1112
import java.time.Instant;
1213
import java.util.concurrent.BlockingQueue;
1314
import java.util.concurrent.LinkedBlockingQueue;
15+
import java.util.concurrent.TimeUnit;
1416

1517
import static com.launchdarkly.sdk.server.TestComponents.sharedExecutor;
16-
import static com.launchdarkly.sdk.server.TestUtil.awaitValue;
17-
import static com.launchdarkly.sdk.server.TestUtil.expectNoMoreValues;
18+
import static com.launchdarkly.testhelpers.ConcurrentHelpers.assertNoMoreValues;
19+
import static com.launchdarkly.testhelpers.ConcurrentHelpers.trySleep;
1820
import static org.hamcrest.MatcherAssert.assertThat;
1921
import static org.hamcrest.Matchers.equalTo;
2022
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@@ -62,10 +64,10 @@ public void statusListeners() throws Exception {
6264

6365
updates.updateStatus(State.VALID, null);
6466

65-
Status newStatus = awaitValue(statuses, Duration.ofMillis(500));
67+
Status newStatus = ConcurrentHelpers.awaitValue(statuses, 500, TimeUnit.MILLISECONDS);
6668
assertThat(newStatus.getState(), equalTo(State.VALID));
6769

68-
expectNoMoreValues(unwantedStatuses, Duration.ofMillis(100));
70+
assertNoMoreValues(unwantedStatuses, 100, TimeUnit.MILLISECONDS);
6971
}
7072

7173
@Test
@@ -79,9 +81,7 @@ public void waitForStatusWithStatusAlreadyCorrect() throws Exception {
7981
@Test
8082
public void waitForStatusSucceeds() throws Exception {
8183
new Thread(() -> {
82-
try {
83-
Thread.sleep(100);
84-
} catch (InterruptedException e) {}
84+
trySleep(100, TimeUnit.MILLISECONDS);
8585
updates.updateStatus(State.VALID, null);
8686
}).start();
8787

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.time.Instant;
2525
import java.util.concurrent.BlockingQueue;
2626
import java.util.concurrent.LinkedBlockingQueue;
27+
import java.util.concurrent.TimeUnit;
2728

2829
import static com.launchdarkly.sdk.server.DataModel.FEATURES;
2930
import static com.launchdarkly.sdk.server.DataModel.SEGMENTS;
@@ -33,9 +34,9 @@
3334
import static com.launchdarkly.sdk.server.ModelBuilders.segmentBuilder;
3435
import static com.launchdarkly.sdk.server.TestComponents.inMemoryDataStore;
3536
import static com.launchdarkly.sdk.server.TestComponents.sharedExecutor;
36-
import static com.launchdarkly.sdk.server.TestUtil.awaitValue;
3737
import static com.launchdarkly.sdk.server.TestUtil.expectEvents;
38-
import static com.launchdarkly.sdk.server.TestUtil.expectNoMoreValues;
38+
import static com.launchdarkly.testhelpers.ConcurrentHelpers.assertNoMoreValues;
39+
import static com.launchdarkly.testhelpers.ConcurrentHelpers.awaitValue;
3940
import static org.easymock.EasyMock.replay;
4041
import static org.hamcrest.MatcherAssert.assertThat;
4142
import static org.hamcrest.Matchers.containsString;
@@ -171,7 +172,7 @@ public void doesNotSendsEventOnUpdateIfItemWasNotReallyUpdated() throws Exceptio
171172

172173
storeUpdates.upsert(FEATURES, flag2.getKey(), new ItemDescriptor(flag2.getVersion(), flag2));
173174

174-
expectNoMoreValues(eventSink, Duration.ofMillis(100));
175+
assertNoMoreValues(eventSink, 100, TimeUnit.MILLISECONDS);
175176
}
176177

177178
@Test
@@ -360,7 +361,7 @@ public void updateStatusBroadcastsNewStatus() {
360361
ErrorInfo errorInfo = ErrorInfo.fromHttpError(401);
361362
updates.updateStatus(State.OFF, errorInfo);
362363

363-
Status status = awaitValue(statuses, Duration.ofMillis(500));
364+
Status status = awaitValue(statuses, 500, TimeUnit.MILLISECONDS);
364365

365366
assertThat(status.getState(), is(State.OFF));
366367
assertThat(status.getStateSince(), greaterThanOrEqualTo(timeBeforeUpdate));
@@ -382,7 +383,7 @@ public void updateStatusKeepsStateUnchangedIfStateWasInitializingAndNewStateIsIn
382383
ErrorInfo errorInfo = ErrorInfo.fromHttpError(401);
383384
updates.updateStatus(State.INTERRUPTED, errorInfo);
384385

385-
Status status = awaitValue(statuses, Duration.ofMillis(500));
386+
Status status = awaitValue(statuses, 500, TimeUnit.MILLISECONDS);
386387

387388
assertThat(status.getState(), is(State.INITIALIZING));
388389
assertThat(status.getStateSince(), is(originalTime));
@@ -401,7 +402,7 @@ public void updateStatusDoesNothingIfParametersHaveNoNewData() {
401402
updates.updateStatus(null, null);
402403
updates.updateStatus(State.INITIALIZING, null);
403404

404-
TestUtil.expectNoMoreValues(statuses, Duration.ofMillis(100));
405+
assertNoMoreValues(statuses, 100, TimeUnit.MILLISECONDS);
405406
}
406407

407408
@Test
@@ -426,15 +427,15 @@ public void outageTimeoutLogging() throws Exception {
426427
updates.updateStatus(State.VALID, null);
427428

428429
// wait till the timeout would have elapsed - no special message should be logged
429-
expectNoMoreValues(outageErrors, outageTimeout.plus(Duration.ofMillis(20)));
430+
assertNoMoreValues(outageErrors, outageTimeout.plus(Duration.ofMillis(20)).toMillis(), TimeUnit.MILLISECONDS);
430431

431432
// simulate another outage
432433
updates.updateStatus(State.INTERRUPTED, ErrorInfo.fromHttpError(501));
433434
updates.updateStatus(State.INTERRUPTED, ErrorInfo.fromHttpError(502));
434435
updates.updateStatus(State.INTERRUPTED, ErrorInfo.fromException(ErrorKind.NETWORK_ERROR, new IOException("x")));
435436
updates.updateStatus(State.INTERRUPTED, ErrorInfo.fromHttpError(501));
436437

437-
String errorsDesc = awaitValue(outageErrors, Duration.ofMillis(250)); // timing is approximate
438+
String errorsDesc = awaitValue(outageErrors, 250, TimeUnit.MILLISECONDS); // timing is approximate
438439
assertThat(errorsDesc, containsString("NETWORK_ERROR (1 time)"));
439440
assertThat(errorsDesc, containsString("ERROR_RESPONSE(501) (2 times)"));
440441
assertThat(errorsDesc, containsString("ERROR_RESPONSE(502) (1 time)"));

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
import org.junit.Test;
1313

1414
import java.io.IOException;
15-
import java.time.Duration;
1615
import java.util.concurrent.BlockingQueue;
1716
import java.util.concurrent.LinkedBlockingQueue;
17+
import java.util.concurrent.TimeUnit;
1818

1919
import static com.launchdarkly.sdk.server.TestComponents.sharedExecutor;
20-
import static com.launchdarkly.sdk.server.TestUtil.awaitValue;
21-
import static com.launchdarkly.sdk.server.TestUtil.expectNoMoreValues;
20+
import static com.launchdarkly.testhelpers.ConcurrentHelpers.assertNoMoreValues;
21+
import static com.launchdarkly.testhelpers.ConcurrentHelpers.awaitValue;
2222
import static org.hamcrest.MatcherAssert.assertThat;
2323
import static org.hamcrest.Matchers.equalTo;
2424
import static org.hamcrest.Matchers.nullValue;
@@ -56,10 +56,10 @@ public void statusListeners() throws Exception {
5656

5757
updates.updateStatus(new Status(false, false));
5858

59-
Status newStatus = awaitValue(statuses, Duration.ofMillis(500));
59+
Status newStatus = awaitValue(statuses, 500, TimeUnit.MILLISECONDS);
6060
assertThat(newStatus, equalTo(new Status(false, false)));
6161

62-
expectNoMoreValues(unwantedStatuses, Duration.ofMillis(100));
62+
assertNoMoreValues(unwantedStatuses, 100, TimeUnit.MILLISECONDS);
6363
}
6464

6565
@Test

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
import org.junit.Test;
77

8-
import java.time.Duration;
98
import java.util.concurrent.BlockingQueue;
109
import java.util.concurrent.LinkedBlockingQueue;
10+
import java.util.concurrent.TimeUnit;
1111

1212
import static com.launchdarkly.sdk.server.TestComponents.sharedExecutor;
13-
import static com.launchdarkly.sdk.server.TestUtil.expectNoMoreValues;
13+
import static com.launchdarkly.testhelpers.ConcurrentHelpers.assertNoMoreValues;
14+
import static com.launchdarkly.testhelpers.ConcurrentHelpers.awaitValue;
1415
import static org.hamcrest.MatcherAssert.assertThat;
1516
import static org.hamcrest.Matchers.equalTo;
1617

@@ -27,10 +28,10 @@ public void updateStatusBroadcastsNewStatus() {
2728

2829
updates.updateStatus(new Status(false, false));
2930

30-
Status newStatus = TestUtil.awaitValue(statuses, Duration.ofMillis(200));
31+
Status newStatus = awaitValue(statuses, 200, TimeUnit.MILLISECONDS);
3132
assertThat(newStatus, equalTo(new Status(false, false)));
3233

33-
expectNoMoreValues(statuses, Duration.ofMillis(100));
34+
assertNoMoreValues(statuses, 100, TimeUnit.MILLISECONDS);
3435
}
3536

3637
@Test
@@ -40,7 +41,7 @@ public void updateStatusDoesNothingIfNewStatusIsSame() {
4041

4142
updates.updateStatus(new Status(true, false));
4243

43-
expectNoMoreValues(statuses, Duration.ofMillis(100));
44+
assertNoMoreValues(statuses, 100, TimeUnit.MILLISECONDS);
4445
}
4546

4647
@Test
@@ -50,6 +51,6 @@ public void updateStatusDoesNothingIfNewStatusIsNull() {
5051

5152
updates.updateStatus(null);
5253

53-
expectNoMoreValues(statuses, Duration.ofMillis(100));
54+
assertNoMoreValues(statuses, 100, TimeUnit.MILLISECONDS);
5455
}
5556
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.launchdarkly.sdk.server.interfaces.Event;
1010
import com.launchdarkly.sdk.server.interfaces.EventProcessorFactory;
1111
import com.launchdarkly.sdk.server.interfaces.EventSender;
12+
import com.launchdarkly.testhelpers.JsonTestValue;
1213

1314
import org.hamcrest.Matchers;
1415
import org.junit.Test;
@@ -118,7 +119,7 @@ public void eventsAreFlushedAutomatically() throws Exception {
118119
// getEventsFromLastRequest will block until the MockEventSender receives a payload - we expect
119120
// both events to be in one payload, but if some unusual delay happened in between the two
120121
// sendEvent calls, they might be in two
121-
Iterable<LDValue> payload1 = es.getEventsFromLastRequest();
122+
Iterable<JsonTestValue> payload1 = es.getEventsFromLastRequest();
122123
if (Iterables.size(payload1) == 1) {
123124
assertThat(payload1, contains(isCustomEvent(event1, userJson)));
124125
assertThat(es.getEventsFromLastRequest(), contains(isCustomEvent(event2, userJson)));
@@ -297,7 +298,7 @@ public void eventCapacityDoesNotPreventSummaryEventFromBeingSent() throws Except
297298
}
298299

299300
ep.flush();
300-
Iterable<LDValue> eventsReceived = es.getEventsFromLastRequest();
301+
Iterable<JsonTestValue> eventsReceived = es.getEventsFromLastRequest();
301302

302303
assertThat(eventsReceived, Matchers.iterableWithSize(capacity + 1));
303304
assertThat(Iterables.get(eventsReceived, capacity), isSummaryEvent());

0 commit comments

Comments
 (0)