diff --git a/lib/sdk/server/build.gradle b/lib/sdk/server/build.gradle index 2ee46f5a..3f0c8633 100644 --- a/lib/sdk/server/build.gradle +++ b/lib/sdk/server/build.gradle @@ -73,7 +73,7 @@ ext.versions = [ "jackson": "2.11.2", "jsr305": "3.0.2", "launchdarklyJavaSdkCommon": "2.3.0", - "launchdarklyJavaSdkInternal": "1.13.0", + "launchdarklyJavaSdkInternal": "1.13.1", "launchdarklyLogging": "1.1.0", "okhttp": "4.12.0", // specify this for the SDK build instead of relying on the transitive dependency from okhttp-eventsource "okhttpEventsource": "5.0.1", diff --git a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/DataSourceSynchronizerAdapter.java b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/DataSourceSynchronizerAdapter.java index e80c4a41..3ac7f40d 100644 --- a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/DataSourceSynchronizerAdapter.java +++ b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/DataSourceSynchronizerAdapter.java @@ -88,7 +88,7 @@ public CompletableFuture next() { e.getCause() != null ? e.getCause().toString() : e.toString(), Instant.now() ); - resultQueue.put(FDv2SourceResult.interrupted(errorInfo, false)); + resultQueue.put(FDv2SourceResult.interrupted(errorInfo, null)); } catch (CancellationException e) { // Start future was canceled (during close) - exit cleanly } catch (InterruptedException e) { @@ -159,7 +159,7 @@ public boolean init(DataStoreTypes.FullDataSet allData) { environmentId, allData.shouldPersist() ); - resultQueue.put(FDv2SourceResult.changeSet(changeSet, false)); + resultQueue.put(FDv2SourceResult.changeSet(changeSet, null)); return true; } @@ -181,7 +181,7 @@ public boolean upsert(DataKind kind, String key, ItemDescriptor item) { environmentId, true // default to true as this adapter is used for adapting FDv1 data sources which are always persistent ); - resultQueue.put(FDv2SourceResult.changeSet(changeSet, false)); + resultQueue.put(FDv2SourceResult.changeSet(changeSet, null)); return true; } @@ -200,15 +200,15 @@ public void updateStatus(DataSourceStatusProvider.State newState, DataSourceStat if (newError != null && newError.getKind() == DataSourceStatusProvider.ErrorKind.ERROR_RESPONSE && HttpErrors.classifyHttpFailure(newError.getStatusCode()) == FailureClass.UNEXPECTED) { - resultQueue.put(FDv2SourceResult.terminalError(newError, false)); + resultQueue.put(FDv2SourceResult.terminalError(newError, null)); } else { - resultQueue.put(FDv2SourceResult.interrupted(newError, false)); + resultQueue.put(FDv2SourceResult.interrupted(newError, null)); } break; case OFF: consecutiveSuccessfulResults = 0; if (newError != null) { - resultQueue.put(FDv2SourceResult.terminalError(newError, false)); + resultQueue.put(FDv2SourceResult.terminalError(newError, null)); } else { resultQueue.put(FDv2SourceResult.shutdown()); } @@ -224,7 +224,7 @@ public void updateStatus(DataSourceStatusProvider.State newState, DataSourceStat Collections.emptyList(), environmentId, /* shouldPersist= */ true); - resultQueue.put(FDv2SourceResult.changeSet(noChanges, false).withResetThresholdMet()); + resultQueue.put(FDv2SourceResult.changeSet(noChanges, null).withResetThresholdMet()); } break; case INITIALIZING: diff --git a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/FDv2DataSource.java b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/FDv2DataSource.java index 3de69ebf..833ca87b 100644 --- a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/FDv2DataSource.java +++ b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/FDv2DataSource.java @@ -5,6 +5,7 @@ import com.launchdarkly.logging.LogValues; import com.launchdarkly.sdk.fdv2.SourceSignal; import com.launchdarkly.sdk.server.datasources.FDv2SourceResult; +import com.launchdarkly.sdk.server.datasources.FDv1Fallback; import com.launchdarkly.sdk.server.datasources.Initializer; import com.launchdarkly.sdk.server.datasources.Synchronizer; import com.launchdarkly.sdk.server.interfaces.DataSourceStatusProvider; @@ -182,8 +183,8 @@ private void run() { } // If an initializer signalled FDv1 fallback, fall back to FDv1 before any synchronizer runs. - if (initializerOutcome.fallbackToFDv1) { - fallBackToFDv1(jittered(defaultFDv1FallbackTTL), initializerOutcome.errorInfo); + if (initializerOutcome.fallback != null) { + fallBackToFDv1(fallbackTTL(initializerOutcome.fallback), initializerOutcome.errorInfo); } if (!sourceManager.hasFDv2Synchronizers() && !sourceManager.hasAvailableSynchronizers()) { @@ -245,7 +246,7 @@ private InitializerOutcome runInitializers() { dataSourceUpdates.updateStatus(DataSourceStatusProvider.State.VALID, null); startFuture.complete(true); if (result.isFdv1Fallback()) { - return InitializerOutcome.fallbackToFDv1(null); + return InitializerOutcome.fallbackToFDv1(null, result.getFdv1Fallback()); } return InitializerOutcome.completed(); } @@ -281,7 +282,7 @@ private InitializerOutcome runInitializers() { // to the FDv1 fallback synchronizer; the eventual VALID status will come // from the FDv1 synchronizer once it serves a full payload. if (result.isFdv1Fallback()) { - return InitializerOutcome.fallbackToFDv1(fallbackErrorInfo); + return InitializerOutcome.fallbackToFDv1(fallbackErrorInfo, result.getFdv1Fallback()); } } } catch (ExecutionException | InterruptedException | CancellationException e) { @@ -318,20 +319,20 @@ private InitializerOutcome runInitializers() { * server-directed FDv1 fallback before the synchronizer phase begins. */ private static final class InitializerOutcome { - final boolean fallbackToFDv1; + final FDv1Fallback fallback; final DataSourceStatusProvider.ErrorInfo errorInfo; - private InitializerOutcome(boolean fallbackToFDv1, DataSourceStatusProvider.ErrorInfo errorInfo) { - this.fallbackToFDv1 = fallbackToFDv1; + private InitializerOutcome(FDv1Fallback fallback, DataSourceStatusProvider.ErrorInfo errorInfo) { + this.fallback = fallback; this.errorInfo = errorInfo; } static InitializerOutcome completed() { - return new InitializerOutcome(false, null); + return new InitializerOutcome(null, null); } - static InitializerOutcome fallbackToFDv1(DataSourceStatusProvider.ErrorInfo errorInfo) { - return new InitializerOutcome(true, errorInfo); + static InitializerOutcome fallbackToFDv1(DataSourceStatusProvider.ErrorInfo errorInfo, FDv1Fallback fallback) { + return new InitializerOutcome(fallback, errorInfo); } } @@ -458,13 +459,13 @@ private void runSynchronizers() { if (result.isFdv1Fallback()) { if (sourceManager.isCurrentSynchronizerFDv1Fallback()) { // A directive during the FDv1 fallback replaces its TTL, and FDv1 keeps running. - Duration fallbackTTL = jittered(defaultFDv1FallbackTTL); + Duration fallbackTTL = fallbackTTL(result.getFdv1Fallback()); sourceManager.startFDv1Fallback(MonotonicTime.now().plus(fallbackTTL)); logger.info("Retrying the configured synchronizers in {}s.", fallbackTTL.getSeconds()); } else { // A directive to fall back to FDv1 ends the run of an FDv2 synchronizer. fallBackToFDv1( - jittered(defaultFDv1FallbackTTL), + fallbackTTL(result.getFdv1Fallback()), result.getStatus() != null ? result.getStatus().getErrorInfo() : null); // The directive takes over, so there is no failover delay after a park. parked = false; @@ -619,6 +620,13 @@ private static MonotonicTime earliest(MonotonicTime... times) { return earliest; } + Duration fallbackTTL(FDv1Fallback fallback) { + Duration serverTTL = fallback.getTtl(); + return serverTTL != null && serverTTL.compareTo(Duration.ZERO) > 0 + && serverTTL.compareTo(Duration.ofHours(1)) <= 0 + ? serverTTL : jittered(defaultFDv1FallbackTTL); + } + /** * Subtracts a random jitter of up to half of the given delay. * diff --git a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/HeaderConstants.java b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/HeaderConstants.java index 66ad1495..22e075a9 100644 --- a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/HeaderConstants.java +++ b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/HeaderConstants.java @@ -1,8 +1,13 @@ package com.launchdarkly.sdk.server; +import com.launchdarkly.sdk.server.datasources.FDv1Fallback; + +import java.time.Duration; + enum HeaderConstants { ENVIRONMENT_ID("x-ld-envid"), - FDV1_FALLBACK("x-ld-fd-fallback"); + FDV1_FALLBACK("x-ld-fd-fallback"), + FDV1_FALLBACK_TTL("x-ld-fd-fallback-ttl"); private final String headerName; @@ -10,6 +15,19 @@ enum HeaderConstants { this.headerName = headerName; } + static FDv1Fallback getFallback(String directive, String value) { + if (!"true".equalsIgnoreCase(directive)) { + return null; + } + Duration ttl = null; + try { + ttl = value == null ? null : Duration.ofSeconds(Long.parseLong(value)); + } catch (NumberFormatException e) { + ttl = null; + } + return new FDv1Fallback(ttl); + } + public String getHeaderName() { return headerName; } diff --git a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/PollingBase.java b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/PollingBase.java index cb429c60..82957e30 100644 --- a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/PollingBase.java +++ b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/PollingBase.java @@ -6,6 +6,7 @@ import com.launchdarkly.sdk.internal.fdv2.sources.FDv2ProtocolHandler; import com.launchdarkly.sdk.fdv2.Selector; import com.launchdarkly.sdk.server.datasources.FDv2SourceResult; +import com.launchdarkly.sdk.server.datasources.FDv1Fallback; import com.launchdarkly.sdk.server.interfaces.DataSourceStatusProvider; import com.launchdarkly.sdk.fdv2.ChangeSet; import com.launchdarkly.sdk.fdv2.ChangeSetType; @@ -16,6 +17,7 @@ import com.launchdarkly.sdk.json.SerializationException; import java.io.IOException; +import java.time.Duration; import java.util.Collections; import java.util.Map; import java.util.Date; @@ -36,13 +38,14 @@ protected void internalShutdown() { requestor.close(); } - private static boolean getFallback(FDv2Requestor.FDv2PayloadResponse response) { + private static FDv1Fallback getFallback(FDv2Requestor.FDv2PayloadResponse response) { if (response != null && response.getHeaders() != null) { - String headerValue = response.getHeaders().get(HeaderConstants.FDV1_FALLBACK.getHeaderName()); - return headerValue != null && headerValue.equalsIgnoreCase("true"); + return HeaderConstants.getFallback( + response.getHeaders().get(HeaderConstants.FDV1_FALLBACK.getHeaderName()), + response.getHeaders().get(HeaderConstants.FDV1_FALLBACK_TTL.getHeaderName())); } - return false; + return null; } private static String getEnvironmentId(FDv2Requestor.FDv2PayloadResponse response) { @@ -54,7 +57,7 @@ private static String getEnvironmentId(FDv2Requestor.FDv2PayloadResponse respons protected CompletableFuture poll(Selector selector, boolean oneShot) { return requestor.Poll(selector).handle(((pollingResponse, ex) -> { - boolean fdv1Fallback = getFallback(pollingResponse); + FDv1Fallback fdv1Fallback = getFallback(pollingResponse); String environmentId = getEnvironmentId(pollingResponse); if (ex != null) { if (ex instanceof IOException) { @@ -101,7 +104,7 @@ protected CompletableFuture poll(Selector selector, boolean on true // Polling data from LaunchDarkly should be persisted ), // Headers would have been processed from the initial response. - false); + null); } if(!pollingResponse.isSuccess()) { int statusCode = pollingResponse.getStatusCode(); @@ -150,9 +153,12 @@ protected CompletableFuture poll(Selector selector, boolean on return oneShot ? FDv2SourceResult.terminalError(info, fdv1Fallback) : FDv2SourceResult.interrupted(info, fdv1Fallback); } case GOODBYE: - String reason = ((FDv2ProtocolHandler.FDv2ActionGoodbye) res).getReason(); + FDv2ProtocolHandler.FDv2ActionGoodbye goodbye = (FDv2ProtocolHandler.FDv2ActionGoodbye) res; + String reason = goodbye.getReason(); + Long ttlMillis = goodbye.getProtocolFallbackTTLMillis(); logger.info("Goodbye was received from the LaunchDarkly connection with reason: '{}'.", reason); - return FDv2SourceResult.goodbye(reason, fdv1Fallback); + return FDv2SourceResult.goodbye(reason, + ttlMillis == null ? fdv1Fallback : new FDv1Fallback(Duration.ofMillis(ttlMillis))); case NONE: break; case INTERNAL_ERROR: { diff --git a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/StreamingSynchronizerImpl.java b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/StreamingSynchronizerImpl.java index d2c2847c..6d02e374 100644 --- a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/StreamingSynchronizerImpl.java +++ b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/StreamingSynchronizerImpl.java @@ -7,6 +7,7 @@ import com.launchdarkly.eventsource.HttpConnectStrategy; import com.launchdarkly.eventsource.MessageEvent; import com.launchdarkly.eventsource.RetryDelayStrategy; +import com.launchdarkly.eventsource.ResponseHeaders; import com.launchdarkly.eventsource.StreamClosedByCallerException; import com.launchdarkly.eventsource.StreamEvent; import com.launchdarkly.eventsource.StreamException; @@ -23,6 +24,7 @@ import com.launchdarkly.sdk.internal.http.HttpHelpers; import com.launchdarkly.sdk.internal.http.HttpProperties; import com.launchdarkly.sdk.server.datasources.FDv2SourceResult; +import com.launchdarkly.sdk.server.datasources.FDv1Fallback; import com.launchdarkly.sdk.server.datasources.SelectorSource; import com.launchdarkly.sdk.server.datasources.Synchronizer; import com.launchdarkly.sdk.server.interfaces.DataSourceStatusProvider; @@ -312,7 +314,7 @@ private void reportResetThresholdMet() { Collections.emptyList(), /* environmentId= */ null, /* shouldPersist= */ true); - resultQueue.put(FDv2SourceResult.changeSet(noChanges, /* fdv1Fallback= */ false).withResetThresholdMet()); + resultQueue.put(FDv2SourceResult.changeSet(noChanges, /* fdv1Fallback= */ null).withResetThresholdMet()); } } @@ -393,9 +395,12 @@ private void handleMessage(MessageEvent event) { break; case GOODBYE: - String reason = ((FDv2ProtocolHandler.FDv2ActionGoodbye) action).getReason(); + FDv2ProtocolHandler.FDv2ActionGoodbye goodbye = (FDv2ProtocolHandler.FDv2ActionGoodbye) action; + String reason = goodbye.getReason(); + Long ttlMillis = goodbye.getProtocolFallbackTTLMillis(); logger.info("Goodbye was received from the LaunchDarkly connection with reason: '{}'.", reason); - result = FDv2SourceResult.goodbye(reason, getFallback(event)); + result = FDv2SourceResult.goodbye(reason, + ttlMillis == null ? getFallback(event) : new FDv1Fallback(Duration.ofMillis(ttlMillis))); // We drop this current connection and attempt to restart the stream. restartStream(false); // Not a failure - deliberate server-initiated restart break; @@ -537,23 +542,21 @@ private FDv2Event parseFDv2Event(String eventName, Reader eventDataReader) throw } } - private static boolean getFallback(Exception ex) { - if(ex instanceof StreamHttpErrorException) { - String headerValue = ((StreamHttpErrorException) ex).getHeaders() - .value(HeaderConstants.FDV1_FALLBACK.getHeaderName()); - return headerValue != null && headerValue.equalsIgnoreCase("true"); - } - return false; + private static FDv1Fallback getFallback(Exception ex) { + return ex instanceof StreamHttpErrorException + ? getFallback(((StreamHttpErrorException) ex).getHeaders()) : null; } - private static boolean getFallback(StreamEvent event) { - String headerName = HeaderConstants.FDV1_FALLBACK.getHeaderName(); - String headerValue = null; - if(event instanceof FaultEvent) { - headerValue = ((FaultEvent) event).getHeaders().value(headerName); - } else if (event instanceof MessageEvent) { - headerValue = ((MessageEvent) event).getHeaders().value(headerName); + private static FDv1Fallback getFallback(StreamEvent event) { + if (event instanceof FaultEvent) { + return getFallback(((FaultEvent) event).getHeaders()); } - return headerValue != null && headerValue.equalsIgnoreCase("true"); + return event instanceof MessageEvent ? getFallback(((MessageEvent) event).getHeaders()) : null; + } + + private static FDv1Fallback getFallback(ResponseHeaders headers) { + return HeaderConstants.getFallback( + headers.value(HeaderConstants.FDV1_FALLBACK.getHeaderName()), + headers.value(HeaderConstants.FDV1_FALLBACK_TTL.getHeaderName())); } } diff --git a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/datasources/FDv1Fallback.java b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/datasources/FDv1Fallback.java new file mode 100644 index 00000000..4408b4cf --- /dev/null +++ b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/datasources/FDv1Fallback.java @@ -0,0 +1,30 @@ +package com.launchdarkly.sdk.server.datasources; + +import java.time.Duration; + +/** + * This type is currently experimental and not subject to semantic versioning. + *

+ * A server directive to fall back to FDv1. + */ +public final class FDv1Fallback { + private final Duration ttl; + + /** + * Creates a fallback directive with the server-provided TTL. + * + * @param ttl the TTL, or null if the server gave none + */ + public FDv1Fallback(Duration ttl) { + this.ttl = ttl; + } + + /** + * Returns the server-provided TTL. + * + * @return the TTL, or null if the server gave none + */ + public Duration getTtl() { + return ttl; + } +} diff --git a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/datasources/FDv2SourceResult.java b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/datasources/FDv2SourceResult.java index d25d77c1..359991dc 100644 --- a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/datasources/FDv2SourceResult.java +++ b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/datasources/FDv2SourceResult.java @@ -71,14 +71,14 @@ public String getReason() { private final ChangeSet>>> changeSet; private final Status status; private final SourceResultType resultType; - private final boolean fdv1Fallback; + private final FDv1Fallback fdv1Fallback; private final boolean resetThresholdMet; private final Function completionCallback; private FDv2SourceResult( ChangeSet>>> changeSet, Status status, SourceResultType resultType, - boolean fdv1Fallback, + FDv1Fallback fdv1Fallback, boolean resetThresholdMet, Function completionCallback ) { @@ -90,11 +90,11 @@ private FDv2SourceResult( this.completionCallback = completionCallback; } - public static FDv2SourceResult interrupted(DataSourceStatusProvider.ErrorInfo errorInfo, boolean fdv1Fallback) { + public static FDv2SourceResult interrupted(DataSourceStatusProvider.ErrorInfo errorInfo, FDv1Fallback fdv1Fallback) { return interrupted(errorInfo, fdv1Fallback, null); } - public static FDv2SourceResult interrupted(DataSourceStatusProvider.ErrorInfo errorInfo, boolean fdv1Fallback, Function completionCallback) { + public static FDv2SourceResult interrupted(DataSourceStatusProvider.ErrorInfo errorInfo, FDv1Fallback fdv1Fallback, Function completionCallback) { return new FDv2SourceResult( /* changeSet= */ null, Status.interrupted(errorInfo), @@ -113,16 +113,16 @@ public static FDv2SourceResult shutdown(Function completionCallback) /* changeSet= */ null, Status.shutdown(), SourceResultType.STATUS, - /* fdv1Fallback= */ false, + /* fdv1Fallback= */ null, /* resetThresholdMet= */ false, completionCallback); } - public static FDv2SourceResult terminalError(DataSourceStatusProvider.ErrorInfo errorInfo, boolean fdv1Fallback) { + public static FDv2SourceResult terminalError(DataSourceStatusProvider.ErrorInfo errorInfo, FDv1Fallback fdv1Fallback) { return terminalError(errorInfo, fdv1Fallback, null); } - public static FDv2SourceResult terminalError(DataSourceStatusProvider.ErrorInfo errorInfo, boolean fdv1Fallback, Function completionCallback) { + public static FDv2SourceResult terminalError(DataSourceStatusProvider.ErrorInfo errorInfo, FDv1Fallback fdv1Fallback, Function completionCallback) { return new FDv2SourceResult( /* changeSet= */ null, Status.terminalError(errorInfo), @@ -132,11 +132,11 @@ public static FDv2SourceResult terminalError(DataSourceStatusProvider.ErrorInfo completionCallback); } - public static FDv2SourceResult changeSet(ChangeSet>>> changeSet, boolean fdv1Fallback) { + public static FDv2SourceResult changeSet(ChangeSet>>> changeSet, FDv1Fallback fdv1Fallback) { return changeSet(changeSet, fdv1Fallback, null); } - public static FDv2SourceResult changeSet(ChangeSet>>> changeSet, boolean fdv1Fallback, Function completionCallback) { + public static FDv2SourceResult changeSet(ChangeSet>>> changeSet, FDv1Fallback fdv1Fallback, Function completionCallback) { return new FDv2SourceResult( changeSet, /* status= */ null, @@ -146,11 +146,11 @@ public static FDv2SourceResult changeSet(ChangeSet completionCallback) { + public static FDv2SourceResult goodbye(String reason, FDv1Fallback fdv1Fallback, Function completionCallback) { return new FDv2SourceResult( /* changeSet= */ null, Status.goodbye(reason), @@ -172,10 +172,14 @@ public ChangeSet>>> getC return changeSet; } - public boolean isFdv1Fallback() { + public FDv1Fallback getFdv1Fallback() { return fdv1Fallback; } + public boolean isFdv1Fallback() { + return fdv1Fallback != null; + } + /** * True if the source met its reset threshold at the time of this result. * diff --git a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/FileDataSourceBase.java b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/FileDataSourceBase.java index 85086d8b..2f0eec97 100644 --- a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/FileDataSourceBase.java +++ b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/FileDataSourceBase.java @@ -74,12 +74,12 @@ protected FDv2SourceResult loadData() { Instant.now() ); // For initializers, file errors are terminal. For synchronizers, they are recoverable. - return FDv2SourceResult.interrupted(errorInfo, false); + return FDv2SourceResult.interrupted(errorInfo, null); } Iterable>> data = builder.build(); ChangeSet>>> changeSet = buildChangeSet(data); - return FDv2SourceResult.changeSet(changeSet, false); + return FDv2SourceResult.changeSet(changeSet, null); } /** diff --git a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/FileInitializer.java b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/FileInitializer.java index 04f1528d..33c7b2b8 100644 --- a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/FileInitializer.java +++ b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/FileInitializer.java @@ -47,7 +47,7 @@ public CompletableFuture run() { result.getStatus().getState() == SourceSignal.INTERRUPTED) { return FDv2SourceResult.terminalError( result.getStatus().getErrorInfo(), - result.isFdv1Fallback() + result.getFdv1Fallback() ); } return result; diff --git a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/TestDataV2.java b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/TestDataV2.java index fcd21f7b..562266f7 100644 --- a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/TestDataV2.java +++ b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/TestDataV2.java @@ -129,7 +129,7 @@ public TestDataV2 delete(String key) { currentBuilders.remove(key); } - pushToSynchronizers(FDv2SourceResult.changeSet(makePartialChangeSet(key, tombstoneItem), false)); + pushToSynchronizers(FDv2SourceResult.changeSet(makePartialChangeSet(key, tombstoneItem), null)); return this; } @@ -163,7 +163,7 @@ public TestDataV2 update(TestData.FlagBuilder flagBuilder) { currentBuilders.put(key, clonedBuilder); } - pushToSynchronizers(FDv2SourceResult.changeSet(makePartialChangeSet(key, newItem), false)); + pushToSynchronizers(FDv2SourceResult.changeSet(makePartialChangeSet(key, newItem), null)); return this; } @@ -187,13 +187,13 @@ public TestDataV2 updateStatus(DataSourceStatusProvider.State newState, DataSour switch (newState) { case OFF: statusResult = newError != null - ? FDv2SourceResult.terminalError(newError, false) + ? FDv2SourceResult.terminalError(newError, null) : FDv2SourceResult.shutdown(); break; case INTERRUPTED: statusResult = FDv2SourceResult.interrupted( newError != null ? newError : new DataSourceStatusProvider.ErrorInfo(DataSourceStatusProvider.ErrorKind.UNKNOWN, 0, null, Instant.now()), - false); + null); break; case VALID: case INITIALIZING: @@ -314,7 +314,7 @@ public CompletableFuture next() { if (!initialSent.getAndSet(true)) { // Send full changeset first, before any partial changesets that // accumulated from update()/delete() calls made before next() was first called. - resultQueue.put(FDv2SourceResult.changeSet(makeFullChangeSet(), false)); + resultQueue.put(FDv2SourceResult.changeSet(makeFullChangeSet(), null)); } return CompletableFuture.anyOf(shutdownFuture, resultQueue.take()) .thenApply(r -> (FDv2SourceResult) r); diff --git a/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/FDv2DataSourceTest.java b/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/FDv2DataSourceTest.java index 81063522..1c4bf03b 100644 --- a/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/FDv2DataSourceTest.java +++ b/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/FDv2DataSourceTest.java @@ -8,6 +8,7 @@ import com.launchdarkly.sdk.internal.collections.IterableAsyncQueue; import com.launchdarkly.sdk.fdv2.Selector; import com.launchdarkly.sdk.server.datasources.FDv2SourceResult; +import com.launchdarkly.sdk.server.datasources.FDv1Fallback; import com.launchdarkly.sdk.server.datasources.Initializer; import com.launchdarkly.sdk.server.datasources.Synchronizer; import com.launchdarkly.sdk.server.interfaces.DataSourceStatusProvider; @@ -57,6 +58,91 @@ public void tearDown() { resourcesToClose.clear(); } + @Test + public void fallbackDirectiveSurvivesResultCopies() { + for (Duration ttl : Arrays.asList(null, Duration.ZERO, Duration.ofSeconds(30))) { + FDv1Fallback fallback = new FDv1Fallback(ttl); + assertEquals(ttl, fallback.getTtl()); + FDv2SourceResult[] results = { + FDv2SourceResult.changeSet(makeChangeSet(true), fallback), + FDv2SourceResult.goodbye("fallback", fallback), + FDv2SourceResult.interrupted(null, fallback), + FDv2SourceResult.terminalError(null, fallback) + }; + for (FDv2SourceResult result : results) { + AtomicBoolean completed = new AtomicBoolean(); + try (FDv2SourceResult copy = result.withResetThresholdMet().withCompletion(v -> { + completed.set(true); + return null; + })) { + assertTrue(copy.isFdv1Fallback()); + assertSame(fallback, copy.getFdv1Fallback()); + } + assertTrue(completed.get()); + } + } + FDv2SourceResult result = FDv2SourceResult.goodbye("no directive", null); + assertFalse(result.isFdv1Fallback()); + assertNull(result.withResetThresholdMet().withCompletion(v -> null).getFdv1Fallback()); + assertNull(FDv2SourceResult.shutdown().getFdv1Fallback()); + } + + @Test + public void serverFallbackTTLIsUnjitteredAndInvalidValuesUseDefault() { + FDv2DataSource dataSource = new FDv2DataSource(ImmutableList.of(), ImmutableList.of(), null, + new MockDataSourceUpdateSink(), Thread.NORM_PRIORITY, logger); + resourcesToClose.add(dataSource); + for (Duration ttl : Arrays.asList(Duration.ofMillis(1), Duration.ofSeconds(30), Duration.ofHours(1))) { + assertEquals(ttl, dataSource.fallbackTTL(new FDv1Fallback(ttl))); + } + for (Duration ttl : Arrays.asList(null, Duration.ZERO, Duration.ofSeconds(-1), Duration.ofSeconds(3601))) { + Duration actual = dataSource.fallbackTTL(new FDv1Fallback(ttl)); + assertTrue(actual.compareTo(Duration.ofMinutes(30)) >= 0); + assertTrue(actual.compareTo(Duration.ofHours(1)) <= 0); + } + } + + @Test + public void serverFallbackTTLControlsInitializerAndSynchronizerRecovery() throws Exception { + for (int scenario = 0; scenario < 6; scenario++) { + final int mode = scenario; + Duration ttl = Duration.ofMillis(50); + FDv2SourceResult directive = mode == 2 + ? FDv2SourceResult.goodbye("fallback", new FDv1Fallback(ttl), null) + : mode == 3 ? FDv2SourceResult.terminalError( + new DataSourceStatusProvider.ErrorInfo(DataSourceStatusProvider.ErrorKind.ERROR_RESPONSE, + 500, null, Instant.now()), new FDv1Fallback(ttl), null) + : FDv2SourceResult.changeSet(makeChangeSet(mode != 1), new FDv1Fallback(ttl), null); + ImmutableList> initializers = mode < 4 + ? ImmutableList.of(() -> new MockInitializer(CompletableFuture.completedFuture(directive))) + : ImmutableList.of(); + AtomicInteger builds = new AtomicInteger(); + BlockingQueue recovered = new LinkedBlockingQueue<>(); + ImmutableList> synchronizers = ImmutableList.of(() -> { + BlockingQueue results = new LinkedBlockingQueue<>(); + if (mode >= 4 && builds.incrementAndGet() == 1) { + results.add(mode == 5 ? FDv2SourceResult.changeSet(makeChangeSet(true), new FDv1Fallback(null)) : directive); + } else { + recovered.offer(true); + } + return new MockQueuedSynchronizer(results); + }); + FDv2DataSource.DataSourceFactory fallback = () -> { + BlockingQueue results = new LinkedBlockingQueue<>(); + if (mode == 5) { + results.add(FDv2SourceResult.changeSet(makeChangeSet(false), new FDv1Fallback(ttl), null)); + } + return new MockQueuedSynchronizer(results); + }; + try (FDv2DataSource dataSource = new FDv2DataSource(initializers, synchronizers, fallback, + new MockDataSourceUpdateSink(), Thread.NORM_PRIORITY, logger)) { + dataSource.start(); + assertNotNull("scenario " + mode + " should recover using the server TTL", + recovered.poll(2, TimeUnit.SECONDS)); + } + } + } + private ChangeSet>>> makeChangeSet(boolean withSelector) { Selector selector = withSelector ? Selector.make(1, "test-state") : Selector.EMPTY; return new ChangeSet<>( @@ -76,7 +162,7 @@ private FDv2SourceResult makeInterruptedResult() { null, Instant.now() ), - false + null ); } @@ -88,7 +174,7 @@ private FDv2SourceResult makeTerminalErrorResult() { null, Instant.now() ), - false + null ); } @@ -104,7 +190,7 @@ public void firstInitializerFailsSecondInitializerSucceedsWithSelector() throws firstInitializerFuture.completeExceptionally(new RuntimeException("First initializer failed")); CompletableFuture secondInitializerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), false) + FDv2SourceResult.changeSet(makeChangeSet(true), null) ); ImmutableList> initializers = ImmutableList.of( @@ -147,7 +233,7 @@ public void firstInitializerFailsSecondInitializerSucceedsWithoutSelector() thro firstInitializerFuture.completeExceptionally(new RuntimeException("First initializer failed")); CompletableFuture secondInitializerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), false) + FDv2SourceResult.changeSet(makeChangeSet(false), null) ); BlockingQueue synchronizerCalledQueue = new LinkedBlockingQueue<>(); @@ -157,7 +243,7 @@ public void firstInitializerFailsSecondInitializerSucceedsWithoutSelector() thro ); CompletableFuture synchronizerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), false) + FDv2SourceResult.changeSet(makeChangeSet(false), null) ); ImmutableList> synchronizers = ImmutableList.of( @@ -204,7 +290,7 @@ public void firstInitializerSucceedsWithSelectorSecondInitializerNotInvoked() th MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); CompletableFuture firstInitializerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), false) + FDv2SourceResult.changeSet(makeChangeSet(true), null) ); AtomicBoolean secondInitializerCalled = new AtomicBoolean(false); @@ -214,7 +300,7 @@ public void firstInitializerSucceedsWithSelectorSecondInitializerNotInvoked() th () -> { secondInitializerCalled.set(true); return new MockInitializer(CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), false) + FDv2SourceResult.changeSet(makeChangeSet(true), null) )); } ); @@ -261,7 +347,7 @@ public void allInitializersFailSwitchesToSynchronizers() throws Exception { BlockingQueue synchronizerCalledQueue = new LinkedBlockingQueue<>(); CompletableFuture synchronizerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), false) + FDv2SourceResult.changeSet(makeChangeSet(false), null) ); ImmutableList> synchronizers = ImmutableList.of( @@ -354,7 +440,7 @@ public void oneInitializerNoSynchronizerIsWellBehaved() throws Exception { MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); CompletableFuture initializerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), false) + FDv2SourceResult.changeSet(makeChangeSet(true), null) ); ImmutableList> initializers = ImmutableList.of( @@ -396,7 +482,7 @@ public void noInitializersOneSynchronizerIsWellBehaved() throws Exception { ImmutableList> initializers = ImmutableList.of(); CompletableFuture synchronizerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), false) + FDv2SourceResult.changeSet(makeChangeSet(false), null) ); ImmutableList> synchronizers = ImmutableList.of( @@ -427,7 +513,7 @@ public void oneInitializerOneSynchronizerIsWellBehaved() throws Exception { MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); CompletableFuture initializerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), false) + FDv2SourceResult.changeSet(makeChangeSet(false), null) ); ImmutableList> initializers = ImmutableList.of( @@ -435,7 +521,7 @@ public void oneInitializerOneSynchronizerIsWellBehaved() throws Exception { ); CompletableFuture synchronizerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), false) + FDv2SourceResult.changeSet(makeChangeSet(false), null) ); ImmutableList> synchronizers = ImmutableList.of( @@ -501,7 +587,7 @@ public void errorWithFDv1FallbackTriggersFallback() throws Exception { ImmutableList> initializers = ImmutableList.of(); CompletableFuture synchronizerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), true) // FDv1 fallback flag + FDv2SourceResult.changeSet(makeChangeSet(false), new FDv1Fallback(null)) // FDv1 fallback flag ); AtomicBoolean synchronizerCalled = new AtomicBoolean(false); @@ -537,13 +623,13 @@ public void fallbackAndRecoveryTasksWellBehaved() throws Exception { // First synchronizer sends INTERRUPTED, triggering fallback after timeout BlockingQueue firstSyncResults = new LinkedBlockingQueue<>(); - firstSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + firstSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); firstSyncResults.add(makeInterruptedResult()); // Keep it alive so fallback timeout triggers // The second synchronizer works fine, sends data BlockingQueue secondSyncResults = new LinkedBlockingQueue<>(); - secondSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + secondSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); // Keep alive for recovery AtomicInteger firstSyncCallCount = new AtomicInteger(0); @@ -612,7 +698,7 @@ public void canDisposeWhenSynchronizersFallingBack() throws Exception { // Synchronizer that sends INTERRUPTED to trigger fallback BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); syncResults.add(makeInterruptedResult()); ImmutableList> synchronizers = ImmutableList.of( @@ -651,12 +737,12 @@ public void terminalErrorFailsOverToNextSynchronizer() throws Exception { // First synchronizer sends terminal error BlockingQueue firstSyncResults = new LinkedBlockingQueue<>(); - firstSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + firstSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); firstSyncResults.add(makeTerminalErrorResult()); // The second synchronizer works fine BlockingQueue secondSyncResults = new LinkedBlockingQueue<>(); - secondSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + secondSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); BlockingQueue synchronizerCallQueue = new LinkedBlockingQueue<>(); @@ -719,7 +805,7 @@ public void terminalErrorParksSynchronizerAndRestartsItAfterUnparkTime() throws BlockingQueue firstInstanceResults = new LinkedBlockingQueue<>(); firstInstanceResults.add(makeTerminalErrorResult()); BlockingQueue secondInstanceResults = new LinkedBlockingQueue<>(); - secondInstanceResults.add(FDv2SourceResult.changeSet(makeChangeSet(true), false)); + secondInstanceResults.add(FDv2SourceResult.changeSet(makeChangeSet(true), null)); AtomicInteger buildCount = new AtomicInteger(); ImmutableList> synchronizers = ImmutableList.of( @@ -758,7 +844,7 @@ public void failedNextParksSynchronizer() throws Exception { throw new RuntimeException("next-boom"); }, "throwing-sync") : new MockSynchronizer( - CompletableFuture.completedFuture(FDv2SourceResult.changeSet(makeChangeSet(true), false)), + CompletableFuture.completedFuture(FDv2SourceResult.changeSet(makeChangeSet(true), null)), "throwing-sync") ); @@ -801,7 +887,7 @@ public void close() { } // The second instance delivers data. return new MockSynchronizer( - CompletableFuture.completedFuture(FDv2SourceResult.changeSet(makeChangeSet(true), false))); + CompletableFuture.completedFuture(FDv2SourceResult.changeSet(makeChangeSet(true), null))); } ); @@ -835,7 +921,7 @@ public void constructionFailureParksSynchronizer() throws Exception { } // The second build delivers data. return new MockSynchronizer( - CompletableFuture.completedFuture(FDv2SourceResult.changeSet(makeChangeSet(true), false))); + CompletableFuture.completedFuture(FDv2SourceResult.changeSet(makeChangeSet(true), null))); } ); @@ -868,7 +954,7 @@ public void resetThresholdMetReturnsParkDelayToBase() throws Exception { BlockingQueue results = new LinkedBlockingQueue<>(); if (buildCount.incrementAndGet() == 3) { // The third instance reports that it met its reset threshold before it fails. - results.add(FDv2SourceResult.changeSet(makeChangeSet(true), false).withResetThresholdMet()); + results.add(FDv2SourceResult.changeSet(makeChangeSet(true), null).withResetThresholdMet()); } // Every instance fails with a terminal error. results.add(makeTerminalErrorResult()); @@ -931,7 +1017,7 @@ public void fallbackWithNoOtherAvailableSynchronizerKeepsCurrentSynchronizer() t // to the instance of the secondary synchronizer that was already running. dataSource.start(); executor.schedule( - () -> secondaryResults.put(FDv2SourceResult.changeSet(makeChangeSet(true), false)), + () -> secondaryResults.put(FDv2SourceResult.changeSet(makeChangeSet(true), null)), 60, TimeUnit.MILLISECONDS); @@ -946,7 +1032,7 @@ public void unparkWhileCurrentSynchronizerIsHealthyKeepsIt() throws Exception { MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); AtomicInteger primaryBuildCount = new AtomicInteger(); IterableAsyncQueue secondaryResults = new IterableAsyncQueue<>(); - secondaryResults.put(FDv2SourceResult.changeSet(makeChangeSet(true), false)); + secondaryResults.put(FDv2SourceResult.changeSet(makeChangeSet(true), null)); ImmutableList> synchronizers = ImmutableList.of( // The primary synchronizer fails, so it is parked briefly. @@ -973,7 +1059,7 @@ public void unparkWhileCurrentSynchronizerIsHealthyKeepsIt() throws Exception { // Start the data system, and send another change set after the primary synchronizer unparks. dataSource.start(); executor.schedule( - () -> secondaryResults.put(FDv2SourceResult.changeSet(makeChangeSet(true), false)), + () -> secondaryResults.put(FDv2SourceResult.changeSet(makeChangeSet(true), null)), 100, TimeUnit.MILLISECONDS); @@ -995,7 +1081,7 @@ public void fallbackSwitchesWhenParkedSynchronizerUnparks() throws Exception { BlockingQueue results = new LinkedBlockingQueue<>(); results.add(primaryBuildCount.incrementAndGet() == 1 ? makeTerminalErrorResult() - : FDv2SourceResult.changeSet(makeChangeSet(true), false)); + : FDv2SourceResult.changeSet(makeChangeSet(true), null)); return new MockQueuedSynchronizer(results); }, // The secondary synchronizer reports that it is interrupted. @@ -1058,11 +1144,11 @@ public void changeSetAfterFallbackIsMetPreventsSwitchAtUnpark() throws Exception // Start the data system, send a change set after the fallback is met, and another after the unpark. dataSource.start(); executor.schedule( - () -> secondaryResults.put(FDv2SourceResult.changeSet(makeChangeSet(true), false)), + () -> secondaryResults.put(FDv2SourceResult.changeSet(makeChangeSet(true), null)), 50, TimeUnit.MILLISECONDS); executor.schedule( - () -> secondaryResults.put(FDv2SourceResult.changeSet(makeChangeSet(true), false)), + () -> secondaryResults.put(FDv2SourceResult.changeSet(makeChangeSet(true), null)), 210, TimeUnit.MILLISECONDS); @@ -1084,14 +1170,14 @@ public void recoveryWithPreferredSynchronizerParkedWaitsForItsUnpark() throws Ex BlockingQueue results = new LinkedBlockingQueue<>(); results.add(primaryBuildCount.incrementAndGet() == 1 ? makeTerminalErrorResult() - : FDv2SourceResult.changeSet(makeChangeSet(true), false)); + : FDv2SourceResult.changeSet(makeChangeSet(true), null)); return new MockQueuedSynchronizer(results); }, // The secondary synchronizer delivers data and stays healthy. () -> { secondaryBuildCount.incrementAndGet(); BlockingQueue results = new LinkedBlockingQueue<>(); - results.add(FDv2SourceResult.changeSet(makeChangeSet(true), false)); + results.add(FDv2SourceResult.changeSet(makeChangeSet(true), null)); return new MockQueuedSynchronizer(results); } ); @@ -1146,7 +1232,7 @@ public void changeSetDuringInterruptionRestartsFallbackTimeout() throws Exceptio long start = System.nanoTime(); dataSource.start(); executor.schedule( - () -> primaryResults.put(FDv2SourceResult.changeSet(makeChangeSet(true), false)), + () -> primaryResults.put(FDv2SourceResult.changeSet(makeChangeSet(true), null)), 50, TimeUnit.MILLISECONDS); executor.schedule(() -> primaryResults.put(makeInterruptedResult()), 90, TimeUnit.MILLISECONDS); @@ -1170,7 +1256,7 @@ public void unpromptedShutdownParksSynchronizer() throws Exception { BlockingQueue results = new LinkedBlockingQueue<>(); results.add(buildCount.incrementAndGet() == 1 ? FDv2SourceResult.shutdown() - : FDv2SourceResult.changeSet(makeChangeSet(true), false)); + : FDv2SourceResult.changeSet(makeChangeSet(true), null)); return new MockQueuedSynchronizer(results); } ); @@ -1303,12 +1389,12 @@ public void disabledDataSourceCannotTriggerActions() throws Exception { // First synchronizer that we'll close and try to trigger AtomicReference firstSyncRef = new AtomicReference<>(); BlockingQueue firstSyncResults = new LinkedBlockingQueue<>(); - firstSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + firstSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); firstSyncResults.add(makeTerminalErrorResult()); // Second synchronizer BlockingQueue secondSyncResults = new LinkedBlockingQueue<>(); - secondSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + secondSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); ImmutableList> synchronizers = ImmutableList.of( () -> { @@ -1338,7 +1424,7 @@ public void disabledDataSourceCannotTriggerActions() throws Exception { // Try to send more data from the first (now closed) synchronizer MockQueuedSynchronizer firstSync = firstSyncRef.get(); if (firstSync != null) { - firstSync.addResult(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + firstSync.addResult(FDv2SourceResult.changeSet(makeChangeSet(false), null)); } // Wait to ensure closed synchronizer's results aren't processed @@ -1364,7 +1450,7 @@ public void disposeCompletesStartFuture() throws Exception { // Synchronizer that never completes BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); ImmutableList> synchronizers = ImmutableList.of( () -> new MockQueuedSynchronizer(syncResults) @@ -1432,11 +1518,11 @@ public void startFutureCompletesExactlyOnce() throws Exception { MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); CompletableFuture initializerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), false) + FDv2SourceResult.changeSet(makeChangeSet(true), null) ); CompletableFuture synchronizerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), false) + FDv2SourceResult.changeSet(makeChangeSet(false), null) ); ImmutableList> initializers = ImmutableList.of( @@ -1468,7 +1554,7 @@ public void concurrentCloseAndStartHandledSafely() throws Exception { MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); ImmutableList> initializers = ImmutableList.of(); ImmutableList> synchronizers = ImmutableList.of( @@ -1497,7 +1583,7 @@ public void multipleStartCallsEventuallyComplete() throws Exception { MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); ImmutableList> initializers = ImmutableList.of(); ImmutableList> synchronizers = ImmutableList.of( @@ -1530,7 +1616,7 @@ public void isInitializedThreadSafe() throws Exception { MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); ImmutableList> initializers = ImmutableList.of(); ImmutableList> synchronizers = ImmutableList.of( @@ -1569,7 +1655,7 @@ public void dataSourceUpdatesApplyThreadSafe() throws Exception { BlockingQueue syncResults = new LinkedBlockingQueue<>(); for (int i = 0; i < 10; i++) { - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); } ImmutableList> initializers = ImmutableList.of(); @@ -1608,7 +1694,7 @@ public void initializerThrowsExecutionException() throws Exception { badFuture.completeExceptionally(new RuntimeException("Execution exception")); CompletableFuture goodFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), false) + FDv2SourceResult.changeSet(makeChangeSet(true), null) ); ImmutableList> initializers = ImmutableList.of( @@ -1640,7 +1726,7 @@ public void initializerThrowsInterruptedException() throws Exception { AtomicBoolean firstCalled = new AtomicBoolean(false); CompletableFuture goodFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), false) + FDv2SourceResult.changeSet(makeChangeSet(true), null) ); ImmutableList> initializers = ImmutableList.of( @@ -1680,7 +1766,7 @@ public void initializerThrowsCancellationException() throws Exception { cancelledFuture.cancel(true); CompletableFuture goodFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), false) + FDv2SourceResult.changeSet(makeChangeSet(true), null) ); ImmutableList> initializers = ImmutableList.of( @@ -1716,7 +1802,7 @@ public void synchronizerNextThrowsExecutionException() throws Exception { badFuture.completeExceptionally(new RuntimeException("Execution exception")); CompletableFuture goodFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), false) + FDv2SourceResult.changeSet(makeChangeSet(false), null) ); ImmutableList> synchronizers = ImmutableList.of( @@ -1748,7 +1834,7 @@ public void synchronizerNextThrowsInterruptedException() throws Exception { AtomicBoolean firstCalled = new AtomicBoolean(false); CompletableFuture goodFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), false) + FDv2SourceResult.changeSet(makeChangeSet(false), null) ); ImmutableList> synchronizers = ImmutableList.of( @@ -1788,7 +1874,7 @@ public void synchronizerNextThrowsCancellationException() throws Exception { cancelledFuture.cancel(true); CompletableFuture goodFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), false) + FDv2SourceResult.changeSet(makeChangeSet(false), null) ); ImmutableList> synchronizers = ImmutableList.of( @@ -1841,7 +1927,7 @@ public void closeAfterInitializersCompletesImmediately() throws Exception { MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); CompletableFuture initializerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), false) + FDv2SourceResult.changeSet(makeChangeSet(true), null) ); ImmutableList> initializers = ImmutableList.of( @@ -1872,7 +1958,7 @@ public void closeWhileSynchronizerRunningShutdownsSource() throws Exception { ImmutableList> initializers = ImmutableList.of(); BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); AtomicBoolean synchronizerClosed = new AtomicBoolean(false); @@ -1907,7 +1993,7 @@ public void multipleCloseCallsAreIdempotent() throws Exception { MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); CompletableFuture initializerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), false) + FDv2SourceResult.changeSet(makeChangeSet(true), null) ); ImmutableList> initializers = ImmutableList.of( @@ -1987,7 +2073,7 @@ public void dataSourceClosedDuringSynchronizationReportsOffWithoutError() throws ImmutableList> synchronizers = ImmutableList.of( () -> { BlockingQueue results = new LinkedBlockingQueue<>(); - results.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + results.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); return new MockQueuedSynchronizer(results); } ); @@ -2082,7 +2168,7 @@ public void closeInterruptsConditionWaiting() throws Exception { ImmutableList> initializers = ImmutableList.of(); BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); syncResults.add(makeInterruptedResult()); // Don't add more, so it waits on condition @@ -2116,7 +2202,7 @@ public void setActiveSourceReturnsShutdownStatus() throws Exception { MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); CompletableFuture initializerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), false) + FDv2SourceResult.changeSet(makeChangeSet(true), null) ); AtomicBoolean shutdownDetected = new AtomicBoolean(false); @@ -2156,11 +2242,11 @@ public void activeSourceClosedWhenSwitchingSynchronizers() throws Exception { ImmutableList> initializers = ImmutableList.of(); BlockingQueue firstSyncResults = new LinkedBlockingQueue<>(); - firstSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + firstSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); firstSyncResults.add(makeTerminalErrorResult()); BlockingQueue secondSyncResults = new LinkedBlockingQueue<>(); - secondSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + secondSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); AtomicBoolean firstSyncClosed = new AtomicBoolean(false); @@ -2279,7 +2365,7 @@ public void activeSourceClosedOnShutdown() throws Exception { ImmutableList> initializers = ImmutableList.of(); BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); AtomicBoolean syncClosed = new AtomicBoolean(false); @@ -2323,7 +2409,7 @@ public void setActiveSourceOnInitializerChecksShutdown() throws Exception { try { return slowResult.get(2, TimeUnit.SECONDS); } catch (Exception e) { - return FDv2SourceResult.changeSet(makeChangeSet(true), false); + return FDv2SourceResult.changeSet(makeChangeSet(true), null); } }) ); @@ -2347,7 +2433,7 @@ public void setActiveSourceOnInitializerChecksShutdown() throws Exception { dataSource.close(); // Complete the future so initializer can finish - slowResult.complete(FDv2SourceResult.changeSet(makeChangeSet(true), false)); + slowResult.complete(FDv2SourceResult.changeSet(makeChangeSet(true), null)); // Wait for the start method to complete startFuture.get(2, TimeUnit.SECONDS); @@ -2371,11 +2457,11 @@ public void parkedSynchronizerSkippedInRotation() throws Exception { // Second: works BlockingQueue secondSyncResults = new LinkedBlockingQueue<>(); - secondSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + secondSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); // Third: works BlockingQueue thirdSyncResults = new LinkedBlockingQueue<>(); - thirdSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + thirdSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); AtomicInteger firstCallCount = new AtomicInteger(0); AtomicInteger secondCallCount = new AtomicInteger(0); @@ -2420,12 +2506,12 @@ public void recoveryResetsToFirstAvailableSynchronizer() throws Exception { // First synchronizer: send data, then INTERRUPTED BlockingQueue firstSyncResults = new LinkedBlockingQueue<>(); - firstSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + firstSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); firstSyncResults.add(makeInterruptedResult()); // Second synchronizer: send data BlockingQueue secondSyncResults = new LinkedBlockingQueue<>(); - secondSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + secondSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); AtomicInteger firstCallCount = new AtomicInteger(0); AtomicInteger secondCallCount = new AtomicInteger(0); @@ -2469,12 +2555,12 @@ public void fallbackMovesToNextSynchronizer() throws Exception { // First: send INTERRUPTED to trigger fallback BlockingQueue firstSyncResults = new LinkedBlockingQueue<>(); - firstSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + firstSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); firstSyncResults.add(makeInterruptedResult()); // Second: works BlockingQueue secondSyncResults = new LinkedBlockingQueue<>(); - secondSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + secondSyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); BlockingQueue secondCalledQueue = new LinkedBlockingQueue<>(); @@ -2515,9 +2601,9 @@ public void conditionsInformedOfAllResults() throws Exception { ImmutableList> initializers = ImmutableList.of(); BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); syncResults.add(makeInterruptedResult()); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); ImmutableList> synchronizers = ImmutableList.of( () -> new MockQueuedSynchronizer(syncResults) @@ -2547,8 +2633,8 @@ public void conditionFutureNeverCompletesWhenNoConditions() throws Exception { ImmutableList> initializers = ImmutableList.of(); BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); ImmutableList> synchronizers = ImmutableList.of( () -> new MockQueuedSynchronizer(syncResults) @@ -2580,7 +2666,7 @@ public void changeSetAppliedToDataSourceUpdates() throws Exception { MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); CompletableFuture initializerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), false) + FDv2SourceResult.changeSet(makeChangeSet(true), null) ); ImmutableList> initializers = ImmutableList.of( @@ -2612,9 +2698,9 @@ public void multipleChangeSetsAppliedInOrder() throws Exception { ImmutableList> initializers = ImmutableList.of(); BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); ImmutableList> synchronizers = ImmutableList.of( () -> new MockQueuedSynchronizer(syncResults) @@ -2643,7 +2729,7 @@ public void selectorNonEmptyCompletesInitialization() throws Exception { MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); CompletableFuture firstInitializerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), false) + FDv2SourceResult.changeSet(makeChangeSet(true), null) ); BlockingQueue secondInitializerCalledQueue = new LinkedBlockingQueue<>(); @@ -2653,7 +2739,7 @@ public void selectorNonEmptyCompletesInitialization() throws Exception { () -> { secondInitializerCalledQueue.offer(true); return new MockInitializer(CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), false) + FDv2SourceResult.changeSet(makeChangeSet(false), null) )); } ); @@ -2683,7 +2769,7 @@ public void initializerChangeSetWithoutSelectorCompletesIfLastInitializer() thro MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); CompletableFuture initializerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), false) + FDv2SourceResult.changeSet(makeChangeSet(false), null) ); ImmutableList> initializers = ImmutableList.of( @@ -2723,7 +2809,7 @@ public void synchronizerChangeSetAlwaysCompletesStartFuture() throws Exception { ImmutableList> initializers = ImmutableList.of(); CompletableFuture synchronizerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), false) + FDv2SourceResult.changeSet(makeChangeSet(false), null) ); ImmutableList> synchronizers = ImmutableList.of( @@ -2756,9 +2842,9 @@ public void goodbyeStatusHandledGracefully() throws Exception { ImmutableList> initializers = ImmutableList.of(); BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); - syncResults.add(FDv2SourceResult.goodbye("server-requested", false)); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); + syncResults.add(FDv2SourceResult.goodbye("server-requested", null)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); ImmutableList> synchronizers = ImmutableList.of( () -> new MockQueuedSynchronizer(syncResults) @@ -2790,7 +2876,7 @@ public void shutdownStatusExitsImmediately() throws Exception { ImmutableList> initializers = ImmutableList.of(); BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); syncResults.add(FDv2SourceResult.shutdown()); AtomicBoolean secondSynchronizerCalled = new AtomicBoolean(false); @@ -2829,7 +2915,7 @@ public void fdv1FallbackFlagHonored() throws Exception { ImmutableList> initializers = ImmutableList.of(); BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), true)); // FDv1 fallback + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), new FDv1Fallback(null))); // FDv1 fallback ImmutableList> synchronizers = ImmutableList.of( () -> new MockQueuedSynchronizer(syncResults) @@ -2863,7 +2949,7 @@ public void emptyInitializerListSkipsToSynchronizers() throws Exception { AtomicBoolean synchronizerCalled = new AtomicBoolean(false); CompletableFuture synchronizerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), false) + FDv2SourceResult.changeSet(makeChangeSet(false), null) ); ImmutableList> synchronizers = ImmutableList.of( @@ -2899,7 +2985,7 @@ public void startedFlagPreventsMultipleRuns() throws Exception { () -> { runCount.incrementAndGet(); return new MockInitializer(CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), false) + FDv2SourceResult.changeSet(makeChangeSet(true), null) )); } ); @@ -2934,7 +3020,7 @@ public void startBeforeRunCompletesAllComplete() throws Exception { MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); ImmutableList> initializers = ImmutableList.of(); ImmutableList> synchronizers = ImmutableList.of( @@ -2970,7 +3056,7 @@ public void statusTransitionsToValidAfterInitialization() throws Exception { MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); CompletableFuture initializerFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), false) + FDv2SourceResult.changeSet(makeChangeSet(false), null) ); ImmutableList> initializers = ImmutableList.of( @@ -3018,7 +3104,7 @@ public void statusIncludesErrorInfoOnFailure() throws Exception { "Unauthorized", Instant.now() ), - false + null )); ImmutableList> synchronizers = ImmutableList.of( @@ -3060,9 +3146,9 @@ public void statusRemainsValidDuringSynchronizerOperation() throws Exception { // Synchronizer that sends multiple changesets BlockingQueue syncResults = new LinkedBlockingQueue<>(); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); - syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); + syncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); ImmutableList> synchronizers = ImmutableList.of( () -> new MockQueuedSynchronizer(syncResults) @@ -3103,7 +3189,7 @@ public void statusStaysInterruptedWhileOnlySynchronizerIsParked() throws Excepti // The first instance sends a changeset and then a terminal error. Later instances send nothing. BlockingQueue firstInstanceResults = new LinkedBlockingQueue<>(); - firstInstanceResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + firstInstanceResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); firstInstanceResults.add(FDv2SourceResult.terminalError( new DataSourceStatusProvider.ErrorInfo( DataSourceStatusProvider.ErrorKind.NETWORK_ERROR, @@ -3111,7 +3197,7 @@ public void statusStaysInterruptedWhileOnlySynchronizerIsParked() throws Excepti "Server error", Instant.now() ), - false + null )); AtomicInteger buildCount = new AtomicInteger(); BlockingQueue builds = new LinkedBlockingQueue<>(); @@ -3169,8 +3255,8 @@ public void fdv1FallbackActivatesWhenFlagSet() throws Exception { // First synchronizer sends a result with FDv1 fallback flag set BlockingQueue fdv2SyncResults = new LinkedBlockingQueue<>(); - fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); - fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), true)); // FDv1 fallback triggered + fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); + fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), new FDv1Fallback(null))); // FDv1 fallback triggered ImmutableList> synchronizers = ImmutableList.of( () -> new MockQueuedSynchronizer(fdv2SyncResults) @@ -3178,7 +3264,7 @@ public void fdv1FallbackActivatesWhenFlagSet() throws Exception { // Create FDv1 fallback synchronizer BlockingQueue fdv1SyncResults = new LinkedBlockingQueue<>(); - fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); BlockingQueue fdv1CalledQueue = new LinkedBlockingQueue<>(); FDv2DataSource.DataSourceFactory fdv1Fallback = () -> { @@ -3226,7 +3312,7 @@ public void fdv1FallbackSynchronizerIsParkedAndRestartedDuringDirectedFallback() results.add(FDv2SourceResult.interrupted( new DataSourceStatusProvider.ErrorInfo( DataSourceStatusProvider.ErrorKind.NETWORK_ERROR, 500, null, Instant.now()), - true)); + new FDv1Fallback(null))); return new MockQueuedSynchronizer(results); } ); @@ -3236,7 +3322,7 @@ public void fdv1FallbackSynchronizerIsParkedAndRestartedDuringDirectedFallback() BlockingQueue results = new LinkedBlockingQueue<>(); results.add(fdv1BuildCount.incrementAndGet() == 1 ? makeTerminalErrorResult() - : FDv2SourceResult.changeSet(makeChangeSet(true), false)); + : FDv2SourceResult.changeSet(makeChangeSet(true), null)); return new MockQueuedSynchronizer(results); }; @@ -3267,8 +3353,8 @@ public void fdv1FallbackNotCalledWithoutFlag() throws Exception { // Synchronizer sends normal results without FDv1 fallback flag BlockingQueue fdv2SyncResults = new LinkedBlockingQueue<>(); - fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); - fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); + fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); ImmutableList> synchronizers = ImmutableList.of( () -> new MockQueuedSynchronizer(fdv2SyncResults) @@ -3316,7 +3402,7 @@ public void fdv1FallbackWorksAfterInterruption() throws Exception { // First synchronizer sends data, then INTERRUPTED with fallback flag BlockingQueue fdv2SyncResults = new LinkedBlockingQueue<>(); - fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); fdv2SyncResults.add(FDv2SourceResult.interrupted( new DataSourceStatusProvider.ErrorInfo( DataSourceStatusProvider.ErrorKind.NETWORK_ERROR, @@ -3324,7 +3410,7 @@ public void fdv1FallbackWorksAfterInterruption() throws Exception { "Network error", Instant.now() ), - true // FDv1 fallback flag + new FDv1Fallback(null) )); ImmutableList> synchronizers = ImmutableList.of( @@ -3333,7 +3419,7 @@ public void fdv1FallbackWorksAfterInterruption() throws Exception { // Create FDv1 fallback synchronizer that sends data BlockingQueue fdv1SyncResults = new LinkedBlockingQueue<>(); - fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); BlockingQueue fdv1CalledQueue = new LinkedBlockingQueue<>(); FDv2DataSource.DataSourceFactory fdv1Fallback = () -> { @@ -3383,10 +3469,10 @@ public void fdv1FallbackOnSynchronizerWithoutFDv1ConfiguredRecoversAfterTTL() th () -> { BlockingQueue results = new LinkedBlockingQueue<>(); if (firstSyncBuildCount.incrementAndGet() == 1) { - results.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); - results.add(FDv2SourceResult.changeSet(makeChangeSet(false), true)); + results.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); + results.add(FDv2SourceResult.changeSet(makeChangeSet(false), new FDv1Fallback(null))); } else { - results.add(FDv2SourceResult.changeSet(makeChangeSet(true), false)); + results.add(FDv2SourceResult.changeSet(makeChangeSet(true), null)); } return new MockQueuedSynchronizer(results); }, @@ -3430,7 +3516,7 @@ public void directiveWithoutFDv1ClosesFDv2SynchronizerDuringFallback() throws Ex ImmutableList> synchronizers = ImmutableList.of( () -> { BlockingQueue results = new LinkedBlockingQueue<>(); - results.add(FDv2SourceResult.changeSet(makeChangeSet(true), true)); + results.add(FDv2SourceResult.changeSet(makeChangeSet(true), new FDv1Fallback(null))); return new MockQueuedSynchronizer(results) { @Override public void close() { @@ -3469,7 +3555,7 @@ public void fdv1FallbackEndsAfterTTL() throws Exception { // The first instance sends a payload with the directive. The second sends a payload. () -> { BlockingQueue results = new LinkedBlockingQueue<>(); - results.add(FDv2SourceResult.changeSet(makeChangeSet(true), fdv2BuildCount.incrementAndGet() == 1)); + results.add(FDv2SourceResult.changeSet(makeChangeSet(true), fdv2BuildCount.incrementAndGet() == 1 ? new FDv1Fallback(null) : null)); return new MockQueuedSynchronizer(results); } ); @@ -3477,7 +3563,7 @@ public void fdv1FallbackEndsAfterTTL() throws Exception { // The FDv1 fallback synchronizer sends a payload, and records when it is closed. FDv2DataSource.DataSourceFactory fdv1Fallback = () -> { BlockingQueue results = new LinkedBlockingQueue<>(); - results.add(FDv2SourceResult.changeSet(makeChangeSet(true), false)); + results.add(FDv2SourceResult.changeSet(makeChangeSet(true), null)); return new MockQueuedSynchronizer(results) { @Override public void close() { @@ -3521,9 +3607,9 @@ public void fdv1FallbackEndsWhileFDv1SynchronizerIsParked() throws Exception { results.add(FDv2SourceResult.interrupted( new DataSourceStatusProvider.ErrorInfo( DataSourceStatusProvider.ErrorKind.NETWORK_ERROR, 500, null, Instant.now()), - true)); + new FDv1Fallback(null))); } else { - results.add(FDv2SourceResult.changeSet(makeChangeSet(true), true)); + results.add(FDv2SourceResult.changeSet(makeChangeSet(true), new FDv1Fallback(null))); } return new MockQueuedSynchronizer(results); } @@ -3586,7 +3672,7 @@ public void directiveDuringFDv1FallbackExtendsTTL() throws Exception { () -> { BlockingQueue results = new LinkedBlockingQueue<>(); if (fdv2BuildCount.incrementAndGet() == 1) { - results.add(FDv2SourceResult.changeSet(makeChangeSet(true), true)); + results.add(FDv2SourceResult.changeSet(makeChangeSet(true), new FDv1Fallback(null))); } else { fdv2RestartTimes.offer(System.nanoTime()); } @@ -3622,7 +3708,7 @@ public void directiveDuringFDv1FallbackExtendsTTL() throws Exception { dataSource.start(); for (int delay = 50; delay <= 300; delay += 50) { executor.schedule( - () -> fdv1Results.put(FDv2SourceResult.changeSet(makeChangeSet(false), true)), + () -> fdv1Results.put(FDv2SourceResult.changeSet(makeChangeSet(false), new FDv1Fallback(null))), delay, TimeUnit.MILLISECONDS); } @@ -3647,7 +3733,7 @@ public void directiveDuringRecoveryFallsBackToFDv1Again() throws Exception { () -> { fdv2BuildCount.incrementAndGet(); BlockingQueue results = new LinkedBlockingQueue<>(); - results.add(FDv2SourceResult.changeSet(makeChangeSet(true), true)); + results.add(FDv2SourceResult.changeSet(makeChangeSet(true), new FDv1Fallback(null))); return new MockQueuedSynchronizer(results); } ); @@ -3656,7 +3742,7 @@ public void directiveDuringRecoveryFallsBackToFDv1Again() throws Exception { FDv2DataSource.DataSourceFactory fdv1Fallback = () -> { fdv1BuildCount.incrementAndGet(); BlockingQueue results = new LinkedBlockingQueue<>(); - results.add(FDv2SourceResult.changeSet(makeChangeSet(true), false)); + results.add(FDv2SourceResult.changeSet(makeChangeSet(true), null)); return new MockQueuedSynchronizer(results); }; @@ -3687,8 +3773,8 @@ public void fdv1FallbackBlocksOtherSynchronizers() throws Exception { // First synchronizer sends result with FDv1 fallback flag BlockingQueue fdv2SyncResults = new LinkedBlockingQueue<>(); - fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); - fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), true)); // FDv1 fallback + fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); + fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), new FDv1Fallback(null))); // FDv1 fallback // Second synchronizer that should not be called after fallback BlockingQueue secondSyncCalledQueue = new LinkedBlockingQueue<>(); @@ -3703,7 +3789,7 @@ public void fdv1FallbackBlocksOtherSynchronizers() throws Exception { // Create FDv1 fallback synchronizer BlockingQueue fdv1SyncResults = new LinkedBlockingQueue<>(); - fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); BlockingQueue fdv1CalledQueue = new LinkedBlockingQueue<>(); FDv2DataSource.DataSourceFactory fdv1Fallback = () -> { @@ -3747,8 +3833,8 @@ public void fdv1FallbackOnlyCalledOncePerDataSource() throws Exception { // Synchronizer sends multiple results with FDv1 fallback flags BlockingQueue fdv2SyncResults = new LinkedBlockingQueue<>(); - fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); - fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), true)); // First fallback + fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); + fdv2SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), new FDv1Fallback(null))); // First fallback ImmutableList> synchronizers = ImmutableList.of( () -> new MockQueuedSynchronizer(fdv2SyncResults) @@ -3756,8 +3842,8 @@ public void fdv1FallbackOnlyCalledOncePerDataSource() throws Exception { // Create FDv1 fallback synchronizer that also sends a fallback flag BlockingQueue fdv1SyncResults = new LinkedBlockingQueue<>(); - fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); - fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), true)); // Second fallback attempt + fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); + fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), new FDv1Fallback(null))); // Second fallback attempt BlockingQueue fdv1CalledQueue = new LinkedBlockingQueue<>(); FDv2DataSource.DataSourceFactory fdv1Fallback = () -> { @@ -3806,7 +3892,7 @@ public void fdv1FallbackOnInitializerSuccessAppliesPayloadAndSwitches() throws E // Initializer returns a payload with a selector AND the FDv1 fallback signal. CompletableFuture initFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), true) + FDv2SourceResult.changeSet(makeChangeSet(true), new FDv1Fallback(null)) ); ImmutableList> initializers = ImmutableList.of( () -> new MockInitializer(initFuture) @@ -3821,7 +3907,7 @@ public void fdv1FallbackOnInitializerSuccessAppliesPayloadAndSwitches() throws E ); BlockingQueue fdv1SyncResults = new LinkedBlockingQueue<>(); - fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); BlockingQueue fdv1CalledQueue = new LinkedBlockingQueue<>(); FDv2DataSource.DataSourceFactory fdv1Fallback = () -> { @@ -3874,7 +3960,7 @@ public void fdv1FallbackOnInitializerErrorSwitchesToFDv1() throws Exception { "fallback requested", Instant.now() ), - true + new FDv1Fallback(null) ) ); ImmutableList> initializers = ImmutableList.of( @@ -3890,7 +3976,7 @@ public void fdv1FallbackOnInitializerErrorSwitchesToFDv1() throws Exception { ); BlockingQueue fdv1SyncResults = new LinkedBlockingQueue<>(); - fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), false)); + fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(false), null)); BlockingQueue fdv1CalledQueue = new LinkedBlockingQueue<>(); FDv2DataSource.DataSourceFactory fdv1Fallback = () -> { @@ -3938,7 +4024,7 @@ public void fdv1FallbackOnInitializerWithoutFDv1ConfiguredRecoversAfterTTL() thr Instant.now() ); CompletableFuture initFuture = CompletableFuture.completedFuture( - FDv2SourceResult.terminalError(initError, true) + FDv2SourceResult.terminalError(initError, new FDv1Fallback(null)) ); ImmutableList> initializers = ImmutableList.of( () -> new MockInitializer(initFuture) @@ -3949,7 +4035,7 @@ public void fdv1FallbackOnInitializerWithoutFDv1ConfiguredRecoversAfterTTL() thr () -> { syncBuildCount.incrementAndGet(); BlockingQueue results = new LinkedBlockingQueue<>(); - results.add(FDv2SourceResult.changeSet(makeChangeSet(true), false)); + results.add(FDv2SourceResult.changeSet(makeChangeSet(true), null)); return new MockQueuedSynchronizer(results); } ); @@ -3985,7 +4071,7 @@ public void fdv1FallbackOnInitializerSuccessNoSelectorAppliesPayloadAndSwitches( MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); CompletableFuture initFuture = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(false), true) + FDv2SourceResult.changeSet(makeChangeSet(false), new FDv1Fallback(null)) ); ImmutableList> initializers = ImmutableList.of( () -> new MockInitializer(initFuture) @@ -3995,7 +4081,7 @@ public void fdv1FallbackOnInitializerSuccessNoSelectorAppliesPayloadAndSwitches( // The FDv1 synchronizer serves a full payload, which raises the readiness signal. BlockingQueue fdv1SyncResults = new LinkedBlockingQueue<>(); - fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(true), false)); + fdv1SyncResults.add(FDv2SourceResult.changeSet(makeChangeSet(true), null)); BlockingQueue fdv1CalledQueue = new LinkedBlockingQueue<>(); FDv2DataSource.DataSourceFactory fdv1Fallback = () -> { @@ -4063,7 +4149,7 @@ public void orchestrationLogging_logsInitializerStartSuccessAndErrorOnException( CompletableFuture first = new CompletableFuture<>(); first.completeExceptionally(new RuntimeException("first-init-failure")); CompletableFuture second = CompletableFuture.completedFuture( - FDv2SourceResult.changeSet(makeChangeSet(true), false) + FDv2SourceResult.changeSet(makeChangeSet(true), null) ); ImmutableList> initializers = ImmutableList.of( () -> new MockInitializer(first, "first-init"), @@ -4102,7 +4188,7 @@ public void orchestrationLogging_logsInitializerFailedOnStatusResult() throws Ex "bootstrap read failed", Instant.now() ), - false + null ) ); ImmutableList> initializers = ImmutableList.of( @@ -4140,7 +4226,7 @@ public void orchestrationLogging_logsSynchronizerStartingStatusInterruptedAndShu "temp outage", Instant.now() ), - false + null )); q.put(FDv2SourceResult.shutdown()); ImmutableList> synchronizers = ImmutableList.of( @@ -4216,7 +4302,7 @@ public void orchestrationLogging_logsErrorWhenSynchronizerNextThrows() throws Ex MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink(); // The second synchronizer delivers data, so start() completes. IterableAsyncQueue followUpQueue = new IterableAsyncQueue<>(); - followUpQueue.put(FDv2SourceResult.changeSet(makeChangeSet(true), false)); + followUpQueue.put(FDv2SourceResult.changeSet(makeChangeSet(true), null)); ImmutableList> synchronizers = ImmutableList.of( // The first synchronizer fails from next(). () -> new MockSynchronizer(() -> { diff --git a/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/PollingInitializerImplTest.java b/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/PollingInitializerImplTest.java index efb4c2dd..293bc667 100644 --- a/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/PollingInitializerImplTest.java +++ b/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/PollingInitializerImplTest.java @@ -12,6 +12,7 @@ import org.junit.Test; import java.io.IOException; +import java.time.Duration; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; @@ -443,6 +444,7 @@ public void fdv1FallbackFlagSetToTrueInSuccessResponse() throws Exception { okhttp3.Headers headers = new okhttp3.Headers.Builder() .add("x-ld-fd-fallback", "true") + .add("x-ld-fd-fallback-ttl", "30") .build(); FDv2Requestor.FDv2PayloadResponse response = FDv2Requestor.FDv2PayloadResponse.success( @@ -464,6 +466,7 @@ public void fdv1FallbackFlagSetToTrueInSuccessResponse() throws Exception { assertNotNull(result); assertEquals(SourceResultType.CHANGE_SET, result.getResultType()); assertEquals(true, result.isFdv1Fallback()); + assertEquals(Duration.ofSeconds(30), result.getFdv1Fallback().getTtl()); } @Test diff --git a/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/PollingSynchronizerImplTest.java b/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/PollingSynchronizerImplTest.java index 797f4ebb..a1a9d480 100644 --- a/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/PollingSynchronizerImplTest.java +++ b/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/PollingSynchronizerImplTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -81,6 +82,58 @@ private FDv2Requestor.FDv2PayloadResponse makeSuccessResponse() { } } + @Test + public void fallbackTTLFromHeaders() throws Exception { + String[] values = {"30", "invalid", "1.5"}; + Duration[] expected = {Duration.ofSeconds(30), null, null}; + for (int i = 0; i < values.length; i++) { + FDv2Requestor requestor = mockRequestor(); + okhttp3.Headers headers = new okhttp3.Headers.Builder() + .add("x-ld-fd-fallback", "true") + .add("x-ld-fd-fallback-ttl", values[i]).build(); + when(requestor.Poll(any(Selector.class))).thenReturn(CompletableFuture.completedFuture( + FDv2Requestor.FDv2PayloadResponse.success(makeSuccessResponse().getEvents(), headers, 200))); + ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); + try (PollingSynchronizerImpl synchronizer = new PollingSynchronizerImpl( + requestor, testLogger, mockSelectorSource(), executor, Duration.ofHours(1))) { + FDv2SourceResult result = synchronizer.next().get(5, TimeUnit.SECONDS); + assertTrue(result.isFdv1Fallback()); + assertEquals(expected[i], result.getFdv1Fallback().getTtl()); + assertEquals(expected[i], result.withResetThresholdMet().withCompletion(v -> null).getFdv1Fallback().getTtl()); + } finally { + executor.shutdownNow(); + } + } + } + + @Test + public void goodbyeFallbackTTL() throws Exception { + String[] fields = {"", ",\"protocolFallbackTTL\":0.05", ",\"protocolFallbackTTL\":\"invalid\"", ",\"protocolFallbackTTL\":null"}; + Duration[] expected = {null, Duration.ofMillis(50), Duration.ZERO, null}; + for (int i = 0; i < fields.length; i++) { + FDv2Requestor requestor = mockRequestor(); + String json = "{\"events\":[{\"event\":\"goodbye\",\"data\":{\"reason\":\"fallback\"" + fields[i] + "}}]}"; + when(requestor.Poll(any(Selector.class))).thenReturn(CompletableFuture.completedFuture( + FDv2Requestor.FDv2PayloadResponse.success( + com.launchdarkly.sdk.internal.fdv2.payloads.FDv2Event.parseEventsArray(json), + okhttp3.Headers.of(), 200))); + ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); + try (PollingSynchronizerImpl synchronizer = new PollingSynchronizerImpl( + requestor, testLogger, mockSelectorSource(), executor, Duration.ofHours(1))) { + FDv2SourceResult result = synchronizer.next().get(5, TimeUnit.SECONDS); + assertEquals(SourceSignal.GOODBYE, result.getStatus().getState()); + assertEquals(expected[i] != null, result.isFdv1Fallback()); + if (expected[i] == null) { + assertNull(result.getFdv1Fallback()); + } else { + assertEquals(expected[i], result.getFdv1Fallback().getTtl()); + } + } finally { + executor.shutdownNow(); + } + } + } + @Test public void nextWaitsWhenQueueEmpty() throws Exception { FDv2Requestor requestor = mockRequestor(); diff --git a/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/StreamingSynchronizerImplTest.java b/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/StreamingSynchronizerImplTest.java index 915abba2..05012d31 100644 --- a/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/StreamingSynchronizerImplTest.java +++ b/lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/StreamingSynchronizerImplTest.java @@ -356,6 +356,52 @@ public void shutdownAfterEventReceived() throws Exception { } } + @Test + public void goodbyeFallbackTTL() throws Exception { + String[] fields = {"", ",\"protocolFallbackTTL\":0.05", ",\"protocolFallbackTTL\":\"invalid\"", ",\"protocolFallbackTTL\":null"}; + Duration[] expected = {null, Duration.ofMillis(50), Duration.ZERO, null}; + for (int i = 0; i < fields.length; i++) { + String event = makeEvent("goodbye", "{\"reason\":\"fallback\"" + fields[i] + "}"); + try (HttpServer server = HttpServer.start(Handlers.all( + Handlers.SSE.start(), Handlers.SSE.event(event), Handlers.SSE.leaveOpen())); + StreamingSynchronizerImpl synchronizer = new StreamingSynchronizerImpl( + toHttpProperties(clientContext("sdk-key", baseConfig().build()).getHttp()), + server.getUri(), "/stream", testLogger, mockSelectorSource(), executor, null, + Duration.ofMillis(100), StreamingSynchronizerImpl.RESET_THRESHOLD, Thread.NORM_PRIORITY, null)) { + FDv2SourceResult result = synchronizer.next().get(5, TimeUnit.SECONDS); + assertEquals(SourceSignal.GOODBYE, result.getStatus().getState()); + assertEquals(expected[i] != null, result.isFdv1Fallback()); + if (expected[i] == null) { + assertNull(result.getFdv1Fallback()); + } else { + assertEquals(expected[i], result.getFdv1Fallback().getTtl()); + } + } + } + } + + @Test + public void headerFallbackTTL() throws Exception { + String[] values = {"30", "invalid", "1.5"}; + Duration[] expected = {Duration.ofSeconds(30), null, null}; + for (int i = 0; i < values.length; i++) { + try (HttpServer server = HttpServer.start(Handlers.all( + Handlers.header("x-ld-fd-fallback", "true"), + Handlers.header("x-ld-fd-fallback-ttl", values[i]), + Handlers.SSE.start(), + Handlers.SSE.event(makeEvent("goodbye", "{\"reason\":\"fallback\"}")), + Handlers.SSE.leaveOpen())); + StreamingSynchronizerImpl synchronizer = new StreamingSynchronizerImpl( + toHttpProperties(clientContext("sdk-key", baseConfig().build()).getHttp()), + server.getUri(), "/stream", testLogger, mockSelectorSource(), executor, null, + Duration.ofMillis(100), StreamingSynchronizerImpl.RESET_THRESHOLD, Thread.NORM_PRIORITY, null)) { + FDv2SourceResult result = synchronizer.next().get(5, TimeUnit.SECONDS); + assertTrue(result.isFdv1Fallback()); + assertEquals(expected[i], result.getFdv1Fallback().getTtl()); + } + } + } + @Test public void goodbyeEventInResponse() throws Exception { String goodbyeEvent = makeEvent("goodbye", "{\"reason\":\"service-unavailable\"}");