From 9de161bf7c211097103f210f63773aa0f245d02a Mon Sep 17 00:00:00 2001 From: Lukasz Antoniak Date: Tue, 18 Jun 2024 13:32:53 +0200 Subject: [PATCH] Allow to run with specific Simulacron cluster version --- integration-tests/asyncreads_test.go | 2 +- integration-tests/connect_test.go | 3 ++- integration-tests/setup/testcluster.go | 10 +++++----- integration-tests/simulacron/cluster.go | 4 ++-- integration-tests/simulacron/http.go | 12 ++++++++++-- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/integration-tests/asyncreads_test.go b/integration-tests/asyncreads_test.go index 3510d0b2..d487f2aa 100644 --- a/integration-tests/asyncreads_test.go +++ b/integration-tests/asyncreads_test.go @@ -287,7 +287,7 @@ func TestAsyncReadsRequestTypes(t *testing.T) { } testSetup, err := setup.NewSimulacronTestSetupWithSessionAndNodesAndConfig( - t, false, false, 1, nil) + t, false, false, 1, nil, nil) require.Nil(t, err) defer testSetup.Cleanup() diff --git a/integration-tests/connect_test.go b/integration-tests/connect_test.go index b3dbff43..19ae101f 100644 --- a/integration-tests/connect_test.go +++ b/integration-tests/connect_test.go @@ -10,6 +10,7 @@ import ( "github.com/datastax/zdm-proxy/integration-tests/client" "github.com/datastax/zdm-proxy/integration-tests/env" "github.com/datastax/zdm-proxy/integration-tests/setup" + "github.com/datastax/zdm-proxy/integration-tests/simulacron" "github.com/datastax/zdm-proxy/integration-tests/utils" "github.com/datastax/zdm-proxy/proxy/pkg/config" "github.com/rs/zerolog" @@ -54,7 +55,7 @@ func TestProtocolVersionNegotiation(t *testing.T) { }() c := setup.NewTestConfig("", "") c.ControlConnMaxProtocolVersion = 4 // configure unsupported protocol version - testSetup, err := setup.NewSimulacronTestSetupWithConfig(t, c) + testSetup, err := setup.NewSimulacronTestSetupWithSessionAndNodesAndConfig(t, true, false, 1, c, &simulacron.ClusterVersion{"2.1", "2.1"}) require.Nil(t, err) defer testSetup.Cleanup() diff --git a/integration-tests/setup/testcluster.go b/integration-tests/setup/testcluster.go index 929850c4..7791cab2 100644 --- a/integration-tests/setup/testcluster.go +++ b/integration-tests/setup/testcluster.go @@ -127,22 +127,22 @@ func NewSimulacronTestSetupWithSession(t *testing.T, createProxy bool, createSes } func NewSimulacronTestSetupWithSessionAndConfig(t *testing.T, createProxy bool, createSession bool, config *config.Config) (*SimulacronTestSetup, error) { - return NewSimulacronTestSetupWithSessionAndNodesAndConfig(t, createProxy, createSession, 1, config) + return NewSimulacronTestSetupWithSessionAndNodesAndConfig(t, createProxy, createSession, 1, config, nil) } func NewSimulacronTestSetupWithSessionAndNodes(t *testing.T, createProxy bool, createSession bool, nodes int) (*SimulacronTestSetup, error) { - return NewSimulacronTestSetupWithSessionAndNodesAndConfig(t, createProxy, createSession, nodes, nil) + return NewSimulacronTestSetupWithSessionAndNodesAndConfig(t, createProxy, createSession, nodes, nil, nil) } -func NewSimulacronTestSetupWithSessionAndNodesAndConfig(t *testing.T, createProxy bool, createSession bool, nodes int, config *config.Config) (*SimulacronTestSetup, error) { +func NewSimulacronTestSetupWithSessionAndNodesAndConfig(t *testing.T, createProxy bool, createSession bool, nodes int, config *config.Config, version *simulacron.ClusterVersion) (*SimulacronTestSetup, error) { if !env.RunMockTests { t.Skip("Skipping Simulacron tests, RUN_MOCKTESTS is set false") } - origin, err := simulacron.GetNewCluster(createSession, nodes) + origin, err := simulacron.GetNewCluster(createSession, nodes, version) if err != nil { log.Panic("simulacron origin startup failed: ", err) } - target, err := simulacron.GetNewCluster(createSession, nodes) + target, err := simulacron.GetNewCluster(createSession, nodes, version) if err != nil { log.Panic("simulacron target startup failed: ", err) } diff --git a/integration-tests/simulacron/cluster.go b/integration-tests/simulacron/cluster.go index 0c98387c..6423c833 100644 --- a/integration-tests/simulacron/cluster.go +++ b/integration-tests/simulacron/cluster.go @@ -83,14 +83,14 @@ func (baseSimulacron *baseSimulacron) GetId() string { return baseSimulacron.id } -func GetNewCluster(startSession bool, numberOfNodes int) (*Cluster, error) { +func GetNewCluster(startSession bool, numberOfNodes int, version *ClusterVersion) (*Cluster, error) { process, err := GetOrCreateGlobalSimulacronProcess() if err != nil { return nil, err } - cluster, createErr := process.Create(startSession, numberOfNodes) + cluster, createErr := process.Create(startSession, numberOfNodes, version) if createErr != nil { return nil, createErr diff --git a/integration-tests/simulacron/http.go b/integration-tests/simulacron/http.go index cfb18241..ff18967b 100644 --- a/integration-tests/simulacron/http.go +++ b/integration-tests/simulacron/http.go @@ -18,6 +18,11 @@ type ClusterData struct { Datacenters []*DatacenterData `json:"data_centers"` } +type ClusterVersion struct { + Cassandra string + Dse string +} + type DatacenterData struct { Id int `json:"id"` Nodes []*NodeData `json:"nodes"` @@ -31,11 +36,14 @@ type NodeData struct { const createUrl = "/cluster?data_centers=%s&cassandra_version=%s&dse_version=%s&name=%s&activity_log=%s&num_tokens=%d" -func (process *Process) Create(startSession bool, numberOfNodes int) (*Cluster, error) { +func (process *Process) Create(startSession bool, numberOfNodes int, version *ClusterVersion) (*Cluster, error) { + if version == nil { + version = &ClusterVersion{env.CassandraVersion, env.DseVersion} + } name := "test_" + uuid.New().String() resp, err := process.execHttp( "POST", - fmt.Sprintf(createUrl, strconv.FormatInt(int64(numberOfNodes), 10), env.CassandraVersion, env.DseVersion, name, "true", 1), + fmt.Sprintf(createUrl, strconv.FormatInt(int64(numberOfNodes), 10), version.Cassandra, version.Dse, name, "true", 1), nil) if err != nil {