Skip to content

Commit

Permalink
chore: Restore v2 support for SDK test harness (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
keelerm84 authored Nov 26, 2024
1 parent 37e7d66 commit 987583a
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
86 changes: 86 additions & 0 deletions testservice/sdk_client_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,92 @@ func makeSDKConfig(config servicedef.SDKConfigParams, sdkLog ldlog.Loggers) (ld.

sdkLog.Debugf("Data system configuration: %+v", dataSystemBuilder)
ret.DataSystem = dataSystemBuilder
} else {
if config.ServiceEndpoints != nil {
ret.ServiceEndpoints.Streaming = config.ServiceEndpoints.Streaming
ret.ServiceEndpoints.Polling = config.ServiceEndpoints.Polling
ret.ServiceEndpoints.Events = config.ServiceEndpoints.Events
}

if config.Streaming != nil {
if config.Streaming.BaseURI != "" {
ret.ServiceEndpoints.Streaming = config.Streaming.BaseURI
}
builder := ldcomponents.StreamingDataSource()
if config.Streaming.InitialRetryDelayMS != nil {
builder.InitialReconnectDelay(time.Millisecond * time.Duration(*config.Streaming.InitialRetryDelayMS))
}
if config.Streaming.Filter.IsDefined() {
builder.PayloadFilter(config.Streaming.Filter.String())
}
ret.DataSource = builder
} else if config.Polling != nil {
if config.Polling.BaseURI != "" {
ret.ServiceEndpoints.Polling = config.Polling.BaseURI
}
builder := ldcomponents.PollingDataSource()
if config.Polling.PollIntervalMS != nil {
builder.PollInterval(time.Millisecond * time.Duration(*config.Polling.PollIntervalMS))
}
if config.Polling.Filter.IsDefined() {
builder.PayloadFilter(config.Polling.Filter.String())
}
ret.DataSource = builder
} else if config.ServiceEndpoints == nil {
ret.DataSource = ldcomponents.ExternalUpdatesOnly()
}

if config.PersistentDataStore != nil {
var builder *ldcomponents.PersistentDataStoreBuilder
switch config.PersistentDataStore.Store.Type {
case servicedef.Redis:
dsBuilder := ldredis.DataStore().URL(config.PersistentDataStore.Store.DSN)
if config.PersistentDataStore.Store.Prefix != nil {
dsBuilder.Prefix(*config.PersistentDataStore.Store.Prefix)
}
builder = ldcomponents.PersistentDataStore(dsBuilder)
case servicedef.Consul:
dsBuilder := ldconsul.DataStore().Address(config.PersistentDataStore.Store.DSN)
if config.PersistentDataStore.Store.Prefix != nil {
dsBuilder.Prefix(*config.PersistentDataStore.Store.Prefix)
}
builder = ldcomponents.PersistentDataStore(dsBuilder)
case servicedef.DynamoDB:
cfg, err := awsconfig.LoadDefaultConfig(context.Background(),
awsconfig.WithRegion("us-east-1"),
awsconfig.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("dummy", "dummy", "dummy")),
)
if err != nil {
return ret, err
}

svc := dynamodb.NewFromConfig(cfg, func(o *dynamodb.Options) {
o.EndpointResolver = dynamodb.EndpointResolverFromURL(config.PersistentDataStore.Store.DSN)
})

dsBuilder := lddynamodb.DataStore("sdk-contract-tests").DynamoClient(svc)
if config.PersistentDataStore.Store.Prefix != nil {
dsBuilder.Prefix(*config.PersistentDataStore.Store.Prefix)
}

builder = ldcomponents.PersistentDataStore(dsBuilder)
default:
return ret, errors.New(fmt.Sprintf("unsupported data store type (%s) requested", config.PersistentDataStore.Store.Type))
}

if builder != nil {
switch config.PersistentDataStore.Cache.Mode {
case servicedef.TTL:
builder.CacheSeconds(*config.PersistentDataStore.Cache.TTL)
case servicedef.Infinite:
builder.CacheForever()
case servicedef.Off:
builder.NoCaching()
}

ret.DataStore = builder
}
}
}

if config.Events != nil {
Expand Down
9 changes: 9 additions & 0 deletions testservice/servicedef/sdk_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type SDKConfigParams struct {
Credential string `json:"credential"`
StartWaitTimeMS ldtime.UnixMillisecondTime `json:"startWaitTimeMs,omitempty"`
InitCanFail bool `json:"initCanFail,omitempty"`
ServiceEndpoints *SDKConfigServiceEndpointsParams `json:"serviceEndpoints,omitempty"`
Streaming *SDKConfigStreamingParams `json:"streaming,omitempty"`
Polling *SDKConfigPollingParams `json:"polling,omitempty"`
Events *SDKConfigEventParams `json:"events,omitempty"`
Expand All @@ -19,6 +20,12 @@ type SDKConfigParams struct {
DataSystem *DataSystem `json:"dataSystem,omitempty"`
}

type SDKConfigServiceEndpointsParams struct {
Streaming string `json:"streaming,omitempty"`
Polling string `json:"polling,omitempty"`
Events string `json:"events,omitempty"`
}

type DataStoreMode int

const (
Expand Down Expand Up @@ -59,11 +66,13 @@ type Synchronizer struct {
type SDKConfigStreamingParams struct {
BaseURI string `json:"baseUri,omitempty"`
InitialRetryDelayMS *ldtime.UnixMillisecondTime `json:"initialRetryDelayMs,omitempty"`
Filter ldvalue.OptionalString `json:"filter,omitempty"`
}

type SDKConfigPollingParams struct {
BaseURI string `json:"baseUri,omitempty"`
PollIntervalMS *ldtime.UnixMillisecondTime `json:"pollIntervalMs,omitempty"`
Filter ldvalue.OptionalString `json:"filter,omitempty"`
}

type SDKConfigEventParams struct {
Expand Down

0 comments on commit 987583a

Please sign in to comment.