Skip to content

Commit 0f063be

Browse files
committed
Fix remaining contract tests.
1 parent d9e3182 commit 0f063be

File tree

4 files changed

+85
-5
lines changed

4 files changed

+85
-5
lines changed

lib/sdk/server/contract-tests/service/src/main/java/sdktest/SdkClientEntity.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.launchdarkly.sdk.server.FlagsStateOption;
1212
import com.launchdarkly.sdk.server.LDClient;
1313
import com.launchdarkly.sdk.server.LDConfig;
14+
import com.launchdarkly.sdk.server.interfaces.ServiceEndpoints;
1415
import com.launchdarkly.sdk.server.migrations.Migration;
1516
import com.launchdarkly.sdk.server.migrations.MigrationBuilder;
1617
import com.launchdarkly.sdk.server.migrations.MigrationExecution;
@@ -25,12 +26,15 @@
2526
import com.launchdarkly.sdk.server.integrations.HooksConfigurationBuilder;
2627
import com.launchdarkly.sdk.server.integrations.ServiceEndpointsBuilder;
2728
import com.launchdarkly.sdk.server.integrations.StreamingDataSourceBuilder;
29+
import com.launchdarkly.sdk.server.integrations.PollingDataSourceBuilder;
2830
import com.launchdarkly.sdk.server.integrations.DataSystemBuilder;
2931
import com.launchdarkly.sdk.server.DataSystemComponents;
3032
import com.launchdarkly.sdk.server.integrations.FDv2PollingInitializerBuilder;
3133
import com.launchdarkly.sdk.server.integrations.FDv2PollingSynchronizerBuilder;
3234
import com.launchdarkly.sdk.server.integrations.FDv2StreamingSynchronizerBuilder;
3335
import com.launchdarkly.sdk.server.interfaces.BigSegmentStoreStatusProvider;
36+
import com.launchdarkly.sdk.server.subsystems.ComponentConfigurer;
37+
import com.launchdarkly.sdk.server.subsystems.DataSource;
3438
import com.launchdarkly.sdk.server.subsystems.DataSourceBuilder;
3539
import com.launchdarkly.sdk.server.datasources.Initializer;
3640
import com.launchdarkly.sdk.server.datasources.Synchronizer;
@@ -563,6 +567,22 @@ private LDConfig buildSdkConfig(SdkConfigParams params, String tag) {
563567
}
564568
}
565569

570+
// Configure FDv1 fallback synchronizer
571+
SdkConfigSynchronizerParams fallbackSynchronizer =
572+
selectFallbackSynchronizer(params.dataSystem);
573+
if (fallbackSynchronizer != null) {
574+
// Set global polling endpoints if the fallback synchronizer has polling with custom base URI
575+
if (fallbackSynchronizer.polling != null &&
576+
fallbackSynchronizer.polling.baseUri != null) {
577+
endpoints.polling(fallbackSynchronizer.polling.baseUri);
578+
}
579+
580+
// Create and configure FDv1 fallback
581+
ComponentConfigurer<DataSource> fdv1Fallback =
582+
createFDv1FallbackSynchronizer(fallbackSynchronizer, endpoints);
583+
dataSystemBuilder.fDv1FallbackSynchronizer(fdv1Fallback);
584+
}
585+
566586
builder.dataSystem(dataSystemBuilder);
567587
}
568588

@@ -601,4 +621,59 @@ private DataSourceBuilder<Synchronizer> createSynchronizer(
601621
}
602622
return null;
603623
}
624+
625+
/**
626+
* Selects the best synchronizer configuration to use for FDv1 fallback.
627+
* Prefers polling synchronizers, falls back to primary synchronizer.
628+
*/
629+
private static SdkConfigSynchronizerParams selectFallbackSynchronizer(
630+
SdkConfigDataSystemParams dataSystemParams) {
631+
632+
// Prefer secondary polling synchronizer
633+
if (dataSystemParams.synchronizers != null &&
634+
dataSystemParams.synchronizers.secondary != null &&
635+
dataSystemParams.synchronizers.secondary.polling != null) {
636+
return dataSystemParams.synchronizers.secondary;
637+
}
638+
639+
// Fall back to primary polling synchronizer
640+
if (dataSystemParams.synchronizers != null &&
641+
dataSystemParams.synchronizers.primary != null &&
642+
dataSystemParams.synchronizers.primary.polling != null) {
643+
return dataSystemParams.synchronizers.primary;
644+
}
645+
646+
// Fall back to primary synchronizer (even if streaming)
647+
if (dataSystemParams.synchronizers != null &&
648+
dataSystemParams.synchronizers.primary != null) {
649+
return dataSystemParams.synchronizers.primary;
650+
}
651+
652+
return null;
653+
}
654+
655+
/**
656+
* Creates the FDv1 fallback synchronizer based on the selected synchronizer config.
657+
* FDv1 fallback is always polling-based.
658+
*/
659+
private static ComponentConfigurer<DataSource> createFDv1FallbackSynchronizer(
660+
SdkConfigSynchronizerParams synchronizer,
661+
ServiceEndpointsBuilder endpoints) {
662+
663+
// FDv1 fallback is always polling-based
664+
PollingDataSourceBuilder fdv1Polling = Components.pollingDataSource();
665+
666+
// Configure polling interval if the synchronizer has polling configuration
667+
if (synchronizer.polling != null) {
668+
if (synchronizer.polling.pollIntervalMs != null) {
669+
fdv1Polling.pollInterval(Duration.ofMillis(synchronizer.polling.pollIntervalMs));
670+
}
671+
// Note: FDv1 polling doesn't support per-source service endpoints override,
672+
// so it will use the global service endpoints configuration
673+
}
674+
// If streaming synchronizer, use default polling interval
675+
// (no additional configuration needed)
676+
677+
return fdv1Polling;
678+
}
604679
}
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
streaming/validation/unrecognized data that can be safely ignored/unknown event name with JSON body
2-
streaming/validation/unrecognized data that can be safely ignored/unknown event name with non-JSON body
3-
streaming/validation/unrecognized data that can be safely ignored/patch event with unrecognized path kind
4-
streaming/fdv2/fallback to FDv1 handling

lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/FDv2DataSource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ private void runSynchronizers() {
336336
}
337337
break;
338338
}
339+
if(result.isFdv1Fallback()) {
340+
System.out.println("fdv1 fallback");
341+
}
339342
// We have been requested to fall back to FDv1. We handle whatever message was associated,
340343
// close the synchronizer, and then fallback.
341344
// Only trigger fallback if we're not already running the FDv1 fallback synchronizer.

lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/StreamingSynchronizerImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ public void close() {
212212
}
213213

214214
private boolean handleEvent(StreamEvent event) {
215+
System.out.println(event);
216+
if(event instanceof MessageEvent && ((MessageEvent) event).getEventName().equals("whatever")) {
217+
System.out.println("stop");
218+
}
215219
if (event instanceof MessageEvent) {
216220
handleMessage((MessageEvent) event);
217221
return true;
@@ -303,7 +307,9 @@ private void handleMessage(MessageEvent event) {
303307
Instant.now()
304308
);
305309
result = FDv2SourceResult.interrupted(internalError, getFallback(event));
306-
restartStream();
310+
if(kind == DataSourceStatusProvider.ErrorKind.INVALID_DATA) {
311+
restartStream();
312+
}
307313
break;
308314

309315
case NONE:

0 commit comments

Comments
 (0)