forked from momentohq/client-sdk-elixir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: grpc configuration (momentohq#35)
* feat: add transport strategy / grpc config to configuration This commit attempts to bulid out the first few bits of the configuration API. It creates a module for transport strategy and grpc config, and adds them to the configuration struct. --------- Co-authored-by: Chris Price <[email protected]>
- Loading branch information
Showing
7 changed files
with
111 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule Momento.Config.Configuration do | ||
@moduledoc """ | ||
Configuration for Momento CacheClient | ||
""" | ||
@enforce_keys[:transport_strategy] | ||
defstruct [:transport_strategy] | ||
|
||
@opaque t() :: %__MODULE__{ | ||
transport_strategy: Momento.Config.Transport.TransportStrategy.t() | ||
} | ||
|
||
@spec with_transport_strategy( | ||
config :: Momento.Config.Configuration.t(), | ||
transport_strategy :: Momento.Config.Transport.TransportStrategy.t() | ||
) :: Momento.Config.Configuration.t() | ||
def with_transport_strategy(config, transport_strategy) do | ||
%{config | transport_strategy: transport_strategy} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
defmodule Momento.Config.Transport.GrpcConfiguration do | ||
@moduledoc """ | ||
Encapsulates gRPC configuration tunables. | ||
""" | ||
@enforce_keys [:deadline_millis] | ||
defstruct [:deadline_millis] | ||
|
||
@opaque t() :: %__MODULE__{ | ||
deadline_millis: number() | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule Momento.Config.Transport.TransportStrategy do | ||
alias Momento.Config.Transport.TransportStrategy, as: TransportStrategy | ||
alias Momento.Config.Transport.GrpcConfiguration, as: GrpcConfiguration | ||
|
||
@moduledoc """ | ||
Configuration for the low-level Momento transport layer | ||
""" | ||
@enforce_keys [:grpc_config] | ||
defstruct [:grpc_config] | ||
|
||
@opaque t() :: %__MODULE__{ | ||
grpc_config: GrpcConfiguration.t() | ||
} | ||
|
||
@doc """ | ||
Copy constructor for overriding the gRPC configuration | ||
""" | ||
@spec with_grpc_config( | ||
transport_strategy :: TransportStrategy.t(), | ||
grpc_config :: GrpcConfiguration.t() | ||
) :: TransportStrategy.t() | ||
def with_grpc_config(transport_strategy, grpc_config) do | ||
%TransportStrategy{ | ||
grpc_config: grpc_config | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule Momento.Config.ConfigurationTest do | ||
alias Momento.Config.Transport.TransportStrategy, as: TransportStrategy | ||
alias Momento.Config.Transport.GrpcConfiguration, as: GrpcConfiguration | ||
|
||
use ExUnit.Case | ||
doctest Momento.Config.Configuration | ||
|
||
@test_grpc_configuration %GrpcConfiguration{ | ||
deadline_millis: 90210 | ||
} | ||
|
||
@test_transport_strategy %TransportStrategy{ | ||
grpc_config: @test_grpc_configuration | ||
} | ||
|
||
@test_configuration %Momento.Config.Configuration{ | ||
transport_strategy: @test_transport_strategy | ||
} | ||
|
||
describe "Constructing Configuration" do | ||
test "overriding transport strategy" do | ||
new_grpc_configuration = %GrpcConfiguration{ | ||
deadline_millis: 424_242 | ||
} | ||
|
||
new_transport_strategy = %TransportStrategy{ | ||
grpc_config: new_grpc_configuration | ||
} | ||
|
||
new_config = | ||
Momento.Config.Configuration.with_transport_strategy( | ||
@test_configuration, | ||
new_transport_strategy | ||
) | ||
|
||
assert new_config.transport_strategy == new_transport_strategy | ||
assert new_config.transport_strategy.grpc_config == new_grpc_configuration | ||
end | ||
end | ||
end |