Skip to content

Commit

Permalink
Allow to run with specific Simulacron cluster version
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-antoniak committed Jun 18, 2024
1 parent 72e5518 commit 9de161b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion integration-tests/asyncreads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion integration-tests/connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()

Expand Down
10 changes: 5 additions & 5 deletions integration-tests/setup/testcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/simulacron/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions integration-tests/simulacron/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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 {
Expand Down

0 comments on commit 9de161b

Please sign in to comment.