Skip to content

Commit

Permalink
Propagate cassandra port in load schema (cadence-workflow#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
madhuravi authored Feb 12, 2018
1 parent 9c2d1a1 commit 9b56a18
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
12 changes: 7 additions & 5 deletions common/cassandra_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ package common

import (
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/uber/cadence/common/logging"

"io/ioutil"
"os"
"github.com/uber/cadence/tools/cassandra"

"github.com/gocql/gocql"
log "github.com/sirupsen/logrus"
"github.com/uber/cadence/tools/cassandra"
)

// NewCassandraCluster creates a cassandra cluster given comma separated list of clusterHosts
Expand Down Expand Up @@ -89,7 +88,9 @@ func DropCassandraKeyspace(s *gocql.Session, keyspace string) (err error) {
}

// LoadCassandraSchema loads the schema from the given .cql files on this keyspace
func LoadCassandraSchema(dir string, fileNames []string, keyspace string, override bool) (err error) {
func LoadCassandraSchema(
dir string, fileNames []string, port int, keyspace string, override bool,
) (err error) {

tmpFile, err := ioutil.TempFile("", "_cadence_")
if err != nil {
Expand All @@ -111,6 +112,7 @@ func LoadCassandraSchema(dir string, fileNames []string, keyspace string, overri
config := &cassandra.SetupSchemaConfig{
BaseConfig: cassandra.BaseConfig{
CassHosts: "127.0.0.1",
CassPort: port,
CassKeyspace: keyspace,
},
SchemaFilePath: tmpFile.Name(),
Expand Down
18 changes: 10 additions & 8 deletions common/persistence/persistenceTestBase.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import (
"sync/atomic"
"time"

"github.com/gocql/gocql"
"github.com/pborman/uuid"
log "github.com/sirupsen/logrus"
"github.com/uber-common/bark"

workflow "github.com/uber/cadence/.gen/go/shared"
"github.com/uber/cadence/common"
"github.com/uber/cadence/common/cluster"
"github.com/uber/cadence/common/logging"

"github.com/gocql/gocql"
"github.com/pborman/uuid"
log "github.com/sirupsen/logrus"
"github.com/uber-common/bark"
)

const (
Expand Down Expand Up @@ -93,6 +93,7 @@ type (

// CassandraTestCluster allows executing cassandra operations in testing.
CassandraTestCluster struct {
port int
keyspace string
cluster *gocql.ClusterConfig
session *gocql.Session
Expand Down Expand Up @@ -862,7 +863,8 @@ func (s *CassandraTestCluster) tearDownTestCluster() {
s.session.Close()
}

func (s *CassandraTestCluster) createCluster(clusterHosts string, port int, user, password, dc string,
func (s *CassandraTestCluster) createCluster(
clusterHosts string, port int, user, password, dc string,
cons gocql.Consistency, keyspace string) {
s.cluster = common.NewCassandraCluster(clusterHosts, port, user, password, dc)
s.cluster.Consistency = cons
Expand Down Expand Up @@ -898,7 +900,7 @@ func (s *CassandraTestCluster) loadSchema(fileNames []string, schemaDir string)
workflowSchemaDir = schemaDir + "/schema/cadence"
}

err := common.LoadCassandraSchema(workflowSchemaDir, fileNames, s.keyspace, true)
err := common.LoadCassandraSchema(workflowSchemaDir, fileNames, s.cluster.Port, s.keyspace, true)
if err != nil && !strings.Contains(err.Error(), "AlreadyExists") {
log.Fatal(err)
}
Expand All @@ -910,7 +912,7 @@ func (s *CassandraTestCluster) loadVisibilitySchema(fileNames []string, schemaDi
workflowSchemaDir = schemaDir + "/schema/visibility"
}

err := common.LoadCassandraSchema(workflowSchemaDir, fileNames, s.keyspace, false)
err := common.LoadCassandraSchema(workflowSchemaDir, fileNames, s.cluster.Port, s.keyspace, false)
if err != nil && !strings.Contains(err.Error(), "AlreadyExists") {
log.Fatal(err)
}
Expand Down

0 comments on commit 9b56a18

Please sign in to comment.