Skip to content

Commit

Permalink
add OpenJDK 7 build + fix test race condition + javadoc fix (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
eli-darkly authored Sep 28, 2020
1 parent 1d95560 commit 34a7b83
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 26 deletions.
35 changes: 26 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
version: 2
version: 2.1

workflows:
test:
jobs:
- openjdk8
- openjdk7

jobs:
build:
docker:
- image: circleci/openjdk:8
environment:
- TERM: dumb
steps:
- checkout
- run: ./gradlew test sourcesJar javadocJar
openjdk8:
docker:
- image: circleci/openjdk:8
environment:
- TERM: dumb
steps:
- checkout
- run: ./gradlew test sourcesJar javadocJar

openjdk7:
# This build uses LaunchDarkly's ld-jdk7-jdk8 image which has both OpenJDK 7 and
# OpenJDK 8 installed, with 8 being the default that is used to run Gradle.
# See: https://github.com/launchdarkly/sdks-ci-docker
docker:
- image: ldcircleci/ld-jdk7-jdk8
steps:
- checkout
- run: ./gradlew -i -Dorg.gradle.project.overrideJavaHome=$JDK7_HOME test sourcesJar javadocJar
31 changes: 31 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,34 @@ nexusPublishing {
signing {
sign publishing.publications.mavenJava
}

// Overriding JAVA_HOME/executable paths allows us to build/test under Java 7 even though
// Gradle itself has to run in Java 8+.

tasks.withType(AbstractCompile) {
options.with {
if (overrideJavaHome != "") {
System.out.println("Building with JAVA_HOME=" + overrideJavaHome)
fork = true
forkOptions.javaHome = file(overrideJavaHome)
}
}
}

tasks.withType(Javadoc) {
if (overrideJavaHome != "") {
executable = new File(overrideJavaHome, "bin/javadoc")
}
}

tasks.withType(Test) {
if (overrideJavaHome != "") {
executable = new File(overrideJavaHome, "bin/java")
}
}

tasks.withType(JavaExec) {
if (overrideJavaHome != "") {
executable = new File(overrideJavaHome, "bin/java")
}
}
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ version=1.11.1
ossrhUsername=
ossrhPassword=

# See build.gradle
overrideJavaHome=

# See https://github.com/gradle/gradle/issues/11308 regarding the following property
systemProp.org.gradle.internal.publish.checksums.insecure=true
8 changes: 5 additions & 3 deletions src/main/java/com/launchdarkly/eventsource/EventSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,12 @@ private void connect() {

// Reset the backoff if we had a successful connection that stayed good for at least
// backoffResetThresholdMs milliseconds.
if (connectedTime >= 0 && (System.currentTimeMillis() - connectedTime) >= backoffResetThresholdMs) {
reconnectAttempts = 0;
if (nextState != SHUTDOWN) {
if (connectedTime >= 0 && (System.currentTimeMillis() - connectedTime) >= backoffResetThresholdMs) {
reconnectAttempts = 0;
}
maybeWaitWithBackoff(++reconnectAttempts);
}
maybeWaitWithBackoff(++reconnectAttempts);
}
}
} catch (RejectedExecutionException ignored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Socket createSocket(InetAddress inetAddress, int i, InetAddress inetAddre
* If the socket does not make these modern TLS protocols available at all, then just return the socket unchanged.
*
* @param s the socket
* @return
* @return the updated socket
*/
static Socket setModernTlsVersionsOnSocket(Socket s) {
if (s != null && (s instanceof SSLSocket)) {
Expand Down
23 changes: 10 additions & 13 deletions src/test/java/com/launchdarkly/eventsource/EventSourceHttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,11 @@ public void eventSourceReconnectsAgainAfterErrorOnFirstReconnect() throws Except

@Test
public void streamDoesNotReconnectIfConnectionErrorHandlerSaysToStop() throws Exception {
final AtomicBoolean calledHandler = new AtomicBoolean(false);
final AtomicReference<Throwable> receivedError = new AtomicReference<Throwable>();
final BlockingQueue<Throwable> receivedError = new ArrayBlockingQueue<Throwable>(1);

ConnectionErrorHandler connectionErrorHandler = new ConnectionErrorHandler() {
public Action onConnectionError(Throwable t) {
calledHandler.set(true);
receivedError.set(t);
receivedError.add(t);
return Action.SHUTDOWN;
}
};
Expand All @@ -222,19 +220,18 @@ public Action onConnectionError(Throwable t) {
.reconnectTimeMs(10)
.build()) {
es.start();

// If a ConnectionErrorHandler returns SHUTDOWN, EventSource does not call onClosed() or onError()
// on the regular event handler, since it assumes that the caller already knows what happened.
// Therefore we don't expect to see any items in eventSink.
eventSink.assertNoMoreLogItems();

Throwable t = receivedError.poll(500, TimeUnit.MILLISECONDS);
assertNotNull(t);
assertEquals(UnsuccessfulResponseException.class, t.getClass());

// There's no way to know exactly when EventSource has transitioned its state to
// SHUTDOWN after calling the error handler, so this is an arbitrary delay
Thread.sleep(100);

assertEquals(ReadyState.SHUTDOWN, es.getState());
}
}

assertTrue(calledHandler.get());
assertNotNull(receivedError.get());
assertEquals(UnsuccessfulResponseException.class, receivedError.get().getClass());
}

@Test
Expand Down

0 comments on commit 34a7b83

Please sign in to comment.