Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Jan 25, 2025
1 parent 0c64bb8 commit 8b78ba0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
17 changes: 6 additions & 11 deletions go/api/config/request_routing_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ type Route interface {
IsMultiNode() bool
}

type notMultiNode struct{}
func (_ *notMultiNode) IsMultiNode() bool { return false }

type SimpleNodeRoute int

const (
Expand Down Expand Up @@ -96,6 +99,7 @@ func mapSlotType(slotType SlotType) (protobuf.SlotTypes, error) {
type SlotIdRoute struct {
slotType SlotType
slotID int32
notMultiNode
}

// - slotType: Defines type of the node being addressed.
Expand All @@ -122,15 +126,12 @@ func (slotIdRoute *SlotIdRoute) ToRoutesProtobuf() (*protobuf.Routes, error) {
return request, nil
}

func (route *SlotIdRoute) IsMultiNode() bool {
return false
}

// Request routing configuration overrides the [api.ReadFrom] connection configuration.
// If SlotTypeReplica is used, the request will be routed to a replica, even if the strategy is ReadFrom [api.PreferReplica].
type SlotKeyRoute struct {
slotType SlotType
slotKey string
notMultiNode
}

// - slotType: Defines type of the node being addressed.
Expand All @@ -156,14 +157,12 @@ func (slotKeyRoute *SlotKeyRoute) ToRoutesProtobuf() (*protobuf.Routes, error) {
return request, nil
}

func (route *SlotKeyRoute) IsMultiNode() bool {
return false
}

// Routes a request to a node by its address.
type ByAddressRoute struct {
host string
port int32
notMultiNode
}

// Create a route using hostname/address and port.
Expand Down Expand Up @@ -208,7 +207,3 @@ func (byAddressRoute *ByAddressRoute) ToRoutesProtobuf() (*protobuf.Routes, erro
}
return request, nil
}

func (route *ByAddressRoute) IsMultiNode() bool {
return false
}
5 changes: 3 additions & 2 deletions go/integTest/cluster_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/valkey-io/valkey-glide/go/glide/api"
"github.com/valkey-io/valkey-glide/go/glide/api/config"
)

func (suite *GlideTestSuite) TestClusterCustomCommandInfo() {
Expand Down Expand Up @@ -77,7 +78,7 @@ func (suite *GlideTestSuite) TestInfoCluster() {
// same sections with random route
opts = api.ClusterInfoOptions{
InfoOptions: &api.InfoOptions{Sections: sections},
Route: api.RandomRoute.ToPtr(),
Route: config.RandomRoute.ToPtr(),
}
response, err = client.InfoWithOptions(opts)
assert.NoError(t, err)
Expand All @@ -94,7 +95,7 @@ func (suite *GlideTestSuite) TestInfoCluster() {
// default sections, multi node route
opts = api.ClusterInfoOptions{
InfoOptions: nil,
Route: api.AllPrimaries.ToPtr(),
Route: config.AllPrimaries.ToPtr(),
}
response, err = client.InfoWithOptions(opts)
assert.NoError(t, err)
Expand Down
11 changes: 6 additions & 5 deletions go/integTest/glide_test_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/valkey-io/valkey-glide/go/glide/api"
"github.com/valkey-io/valkey-glide/go/glide/api/config"
)

type GlideTestSuite struct {
Expand Down Expand Up @@ -141,12 +142,12 @@ func runClusterManager(suite *GlideTestSuite, args []string, ignoreExitCode bool
func getServerVersion(suite *GlideTestSuite) string {
var err error = nil
if len(suite.standaloneHosts) > 0 {
config := api.NewGlideClientConfiguration().
clientConfig := api.NewGlideClientConfiguration().
WithAddress(&suite.standaloneHosts[0]).
WithUseTLS(suite.tls).
WithRequestTimeout(5000)

client, err := api.NewGlideClient(config)
client, err := api.NewGlideClient(clientConfig)
if err == nil && client != nil {
defer client.Close()
info, _ := client.InfoWithOptions(api.InfoOptions{Sections: []api.Section{api.Server}})
Expand All @@ -160,19 +161,19 @@ func getServerVersion(suite *GlideTestSuite) string {
suite.T().Fatal("No server hosts configured")
}

config := api.NewGlideClusterClientConfiguration().
clientConfig := api.NewGlideClusterClientConfiguration().
WithAddress(&suite.clusterHosts[0]).
WithUseTLS(suite.tls).
WithRequestTimeout(5000)

client, err := api.NewGlideClusterClient(config)
client, err := api.NewGlideClusterClient(clientConfig)
if err == nil && client != nil {
defer client.Close()

info, _ := client.InfoWithOptions(
api.ClusterInfoOptions{
InfoOptions: &api.InfoOptions{Sections: []api.Section{api.Server}},
Route: api.RandomRoute.ToPtr(),
Route: config.RandomRoute.ToPtr(),
},
)
return extractServerVersion(suite, info.SingleValue())
Expand Down

0 comments on commit 8b78ba0

Please sign in to comment.