Skip to content

Commit 2e47e40

Browse files
authored
Use environment.GetCassandraPort() instead of defaultCassandraPort in tests (#660)
1 parent 04058a5 commit 2e47e40

File tree

6 files changed

+28
-27
lines changed

6 files changed

+28
-27
lines changed

environment/env.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,35 @@ const (
3939
// CassandraPort env
4040
CassandraPort = "CASSANDRA_PORT"
4141
// CassandraDefaultPort Cassandra default port
42-
CassandraDefaultPort = "9042"
42+
CassandraDefaultPort = 9042
4343

4444
// MySQLSeeds env
4545
MySQLSeeds = "MYSQL_SEEDS"
4646
// MySQLPort env
4747
MySQLPort = "MYSQL_PORT"
4848
// MySQLDefaultPort MySQL default port
49-
MySQLDefaultPort = "3306"
49+
MySQLDefaultPort = 3306
5050

5151
// KafkaSeeds env
5252
KafkaSeeds = "KAFKA_SEEDS"
5353
// KafkaPort env
5454
KafkaPort = "KAFKA_PORT"
5555
// KafkaDefaultPort Kafka default port
56-
KafkaDefaultPort = "9092"
56+
KafkaDefaultPort = 9092
5757

5858
// ESSeeds env
5959
ESSeeds = "ES_SEEDS"
6060
// ESPort env
6161
ESPort = "ES_PORT"
6262
// ESDefaultPort ES default port
63-
ESDefaultPort = "9200"
63+
ESDefaultPort = 9200
6464

6565
// PostgresSeeds env
6666
PostgresSeeds = "POSTGRES_SEEDS"
6767
// PostgresPort env
6868
PostgresPort = "POSTGRES_PORT"
6969
// PostgresDefaultPort Postgres default port
70-
PostgresDefaultPort = "5432"
70+
PostgresDefaultPort = 5432
7171
)
7272

7373
// SetupEnv setup the necessary env
@@ -80,7 +80,7 @@ func SetupEnv() {
8080
}
8181

8282
if os.Getenv(CassandraPort) == "" {
83-
err := os.Setenv(CassandraPort, CassandraDefaultPort)
83+
err := os.Setenv(CassandraPort, strconv.Itoa(CassandraDefaultPort))
8484
if err != nil {
8585
panic(fmt.Sprintf("error setting env %v", CassandraPort))
8686
}
@@ -94,7 +94,7 @@ func SetupEnv() {
9494
}
9595

9696
if os.Getenv(MySQLPort) == "" {
97-
err := os.Setenv(MySQLPort, MySQLDefaultPort)
97+
err := os.Setenv(MySQLPort, strconv.Itoa(MySQLDefaultPort))
9898
if err != nil {
9999
panic(fmt.Sprintf("error setting env %v", MySQLPort))
100100
}
@@ -108,7 +108,7 @@ func SetupEnv() {
108108
}
109109

110110
if os.Getenv(PostgresPort) == "" {
111-
err := os.Setenv(PostgresPort, PostgresDefaultPort)
111+
err := os.Setenv(PostgresPort, strconv.Itoa(PostgresDefaultPort))
112112
if err != nil {
113113
panic(fmt.Sprintf("error setting env %v", PostgresPort))
114114
}
@@ -122,7 +122,7 @@ func SetupEnv() {
122122
}
123123

124124
if os.Getenv(KafkaPort) == "" {
125-
err := os.Setenv(KafkaPort, KafkaDefaultPort)
125+
err := os.Setenv(KafkaPort, strconv.Itoa(KafkaDefaultPort))
126126
if err != nil {
127127
panic(fmt.Sprintf("error setting env %v", KafkaPort))
128128
}
@@ -136,7 +136,7 @@ func SetupEnv() {
136136
}
137137

138138
if os.Getenv(ESPort) == "" {
139-
err := os.Setenv(ESPort, ESDefaultPort)
139+
err := os.Setenv(ESPort, strconv.Itoa(ESDefaultPort))
140140
if err != nil {
141141
panic(fmt.Sprintf("error setting env %v", ESPort))
142142
}
@@ -156,7 +156,7 @@ func GetCassandraAddress() string {
156156
func GetCassandraPort() int {
157157
port := os.Getenv(CassandraPort)
158158
if port == "" {
159-
port = CassandraDefaultPort
159+
return CassandraDefaultPort
160160
}
161161
p, err := strconv.Atoi(port)
162162
if err != nil {
@@ -178,7 +178,7 @@ func GetMySQLAddress() string {
178178
func GetMySQLPort() int {
179179
port := os.Getenv(MySQLPort)
180180
if port == "" {
181-
port = MySQLDefaultPort
181+
return MySQLDefaultPort
182182
}
183183
p, err := strconv.Atoi(port)
184184
if err != nil {
@@ -200,7 +200,7 @@ func GetPostgresAddress() string {
200200
func GetPostgresPort() int {
201201
port := os.Getenv(PostgresPort)
202202
if port == "" {
203-
port = PostgresDefaultPort
203+
return PostgresDefaultPort
204204
}
205205
p, err := strconv.Atoi(port)
206206
if err != nil {
@@ -222,7 +222,7 @@ func GetKafkaAddress() string {
222222
func GetKafkaPort() int {
223223
port := os.Getenv(KafkaPort)
224224
if port == "" {
225-
port = KafkaDefaultPort
225+
return KafkaDefaultPort
226226
}
227227
p, err := strconv.Atoi(port)
228228
if err != nil {
@@ -244,7 +244,7 @@ func GetESAddress() string {
244244
func GetESPort() int {
245245
port := os.Getenv(ESPort)
246246
if port == "" {
247-
port = ESDefaultPort
247+
return ESDefaultPort
248248
}
249249
p, err := strconv.Atoi(port)
250250
if err != nil {

tools/cassandra/cqlclient.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ var errNoHosts = errors.New("Cassandra Hosts list is empty or malformed")
6161
var errGetSchemaVersion = errors.New("Failed to get current schema version from cassandra")
6262

6363
const (
64-
defaultTimeout = 30 // Timeout in seconds
65-
cqlProtoVersion = 4 // default CQL protocol version
66-
defaultConsistency = "ALL" // schema updates must always be ALL
67-
defaultCassandraPort = 9042
68-
systemKeyspace = "system"
64+
defaultTimeout = 30 // Timeout in seconds
65+
cqlProtoVersion = 4 // default CQL protocol version
66+
defaultConsistency = "ALL" // schema updates must always be ALL
67+
systemKeyspace = "system"
6968
)
7069

7170
const (

tools/cassandra/cqlclient_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (s *CQLClientTestSuite) TestCQLClient() {
7979
func newTestCQLClient(keyspace string) (*cqlClient, error) {
8080
return newCQLClient(&CQLClientConfig{
8181
Hosts: environment.GetCassandraAddress(),
82-
Port: defaultCassandraPort,
82+
Port: environment.GetCassandraPort(),
8383
Keyspace: keyspace,
8484
Timeout: defaultTimeout,
8585
numReplicas: 1,

tools/cassandra/handler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232

3333
"go.temporal.io/server/common/auth"
3434
"go.temporal.io/server/common/service/config"
35+
"go.temporal.io/server/environment"
3536
"go.temporal.io/server/schema/cassandra"
3637
"go.temporal.io/server/tools/common/schema"
3738
)
@@ -216,7 +217,7 @@ func validateCQLClientConfig(config *CQLClientConfig, isDryRun bool) error {
216217
config.Keyspace = schema.DryrunDBName
217218
}
218219
if config.Port == 0 {
219-
config.Port = defaultCassandraPort
220+
config.Port = environment.GetCassandraPort()
220221
}
221222
if config.numReplicas == 0 {
222223
config.numReplicas = defaultNumReplicas

tools/cassandra/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
"github.com/urfave/cli"
3131

32+
"go.temporal.io/server/environment"
3233
"go.temporal.io/server/tools/common/schema"
3334
)
3435

@@ -75,7 +76,7 @@ func buildCLIOptions() *cli.App {
7576
},
7677
cli.IntFlag{
7778
Name: schema.CLIFlagPort,
78-
Value: defaultCassandraPort,
79+
Value: environment.GetCassandraPort(),
7980
Usage: "Port of cassandra host to connect to",
8081
EnvVar: "CASSANDRA_PORT",
8182
},

tools/cassandra/version_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (s *VersionTestSuite) TestVerifyCompatibleVersion() {
7979

8080
defaultCfg := config.Cassandra{
8181
Hosts: environment.GetCassandraAddress(),
82-
Port: defaultCassandraPort,
82+
Port: environment.GetCassandraPort(),
8383
User: "",
8484
Password: "",
8585
Keyspace: keyspace,
@@ -118,7 +118,7 @@ func (s *VersionTestSuite) TestCheckCompatibleVersion() {
118118
func (s *VersionTestSuite) createKeyspace(keyspace string) func() {
119119
cfg := &CQLClientConfig{
120120
Hosts: environment.GetCassandraAddress(),
121-
Port: defaultCassandraPort,
121+
Port: environment.GetCassandraPort(),
122122
Keyspace: "system",
123123
Timeout: defaultTimeout,
124124
numReplicas: 1,
@@ -128,7 +128,7 @@ func (s *VersionTestSuite) createKeyspace(keyspace string) func() {
128128

129129
err = client.createKeyspace(keyspace)
130130
if err != nil {
131-
log.Fatalf("error creating Keyspace, err=%v", err)
131+
log.Fatalf("error creating keyspace, err=%v", err)
132132
}
133133
return func() {
134134
s.NoError(client.dropKeyspace(keyspace))
@@ -166,7 +166,7 @@ func (s *VersionTestSuite) runCheckCompatibleVersion(
166166

167167
cfg := config.Cassandra{
168168
Hosts: environment.GetCassandraAddress(),
169-
Port: defaultCassandraPort,
169+
Port: environment.GetCassandraPort(),
170170
User: "",
171171
Password: "",
172172
Keyspace: keyspace,

0 commit comments

Comments
 (0)