From 62e878574ee0d1d397ef619b04c446cb5c01dd5f Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Tue, 12 Jul 2022 11:51:53 +0300 Subject: [PATCH] Solve the remaining compilation errors and replace SSLMode with PgSSLMode --- config/config_defaults.go | 6 +- config/config_test.go | 2 +- config/eescfg.go | 14 +- config/erscfg.go | 28 ++-- config/libconfig_json.go | 6 +- data/conf/cgrates/cgrates.json | 2 +- data/conf/samples/ees/cgrates.json | 4 +- ees/sql.go | 4 +- ees/sql_test.go | 2 +- ers/libers.go | 4 +- ers/sql.go | 8 +- ers/sql_test.go | 12 +- services/datadb_it_test.go | 219 ++++------------------------- services/datadb_test.go | 23 +-- services/stordb_it_test.go | 103 -------------- utils/consts.go | 2 +- 16 files changed, 91 insertions(+), 348 deletions(-) diff --git a/config/config_defaults.go b/config/config_defaults.go index d35394e76..c6ff12aa4 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -164,7 +164,7 @@ const CGRATES_CFG_JSON = ` "opts": { "sqlMaxOpenConns": 100, // maximum database connections opened, not applying for mongo "sqlMaxIdleConns": 10, // maximum database connections idle, not applying for mongo - "sqlConnMaxLifetime": 0, // maximum amount of time in seconds a connection may be reused (0 for unlimited), not applying for mongo + "sqlConnMaxLifetime": "0", // maximum amount of time a connection may be reused (0 for unlimited), not applying for mongo "mysqlDSNParams": {}, // DSN extra paramss "mongoQueryTimeout":"10s", // timeout for query when mongo is used "pgSSLMode":"disable", // pgSSLMode in case of *postgres @@ -516,13 +516,13 @@ const CGRATES_CFG_JSON = ` // SQL // "sqlMaxIdleConns": 0, // SQLMaxIdleConns // "sqlMaxOpenConns": 0, // SQLMaxOpenConns - // "sqlConnMaxLifetime": 0, // SQLConnMaxLifetime + // "sqlConnMaxLifetime": "0", // SQLConnMaxLifetime // "mysqlDSNParams": {}, // DSN params // "sqlTableName":"cdrs", // the name of the table from where the events are exported // "sqlDBName": "cgrates", // the name of the database from where the events are exported - // "sslMode": "disable", // the postgresSSLMode for postgres + // "pgSSLMode": "disable", // the SSLMode for postgres // Kafka diff --git a/config/config_test.go b/config/config_test.go index d683fb4d1..64ce460a7 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -4755,7 +4755,7 @@ func TestV1GetConfigAsJSONDataDB(t *testing.T) { func TestV1GetConfigAsJSONStorDB(t *testing.T) { var reply string - expected := `{"stor_db":{"db_host":"127.0.0.1","db_name":"cgrates","db_password":"","db_port":3306,"db_type":"*mysql","db_user":"cgrates","items":{"*cdrs":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*session_costs":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_account_actions":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_action_plans":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_action_triggers":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_actions":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_attributes":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_chargers":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_destination_rates":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_destinations":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_dispatcher_hosts":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_dispatcher_profiles":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_filters":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_rates":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_rating_plans":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_rating_profiles":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_resources":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_routes":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_shared_groups":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_stats":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_thresholds":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_timings":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*versions":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false}},"opts":{"mongoQueryTimeout":"10s","mysqlDSNParams":{},"mysqlLocation":"Local","postgresSSLMode":"disable","sqlConnMaxLifetime":0,"sqlMaxIdleConns":10,"sqlMaxOpenConns":100},"prefix_indexed_fields":[],"remote_conns":null,"replication_conns":null,"string_indexed_fields":[]}}` + expected := `{"stor_db":{"db_host":"127.0.0.1","db_name":"cgrates","db_password":"","db_port":3306,"db_type":"*mysql","db_user":"cgrates","items":{"*cdrs":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*session_costs":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_account_actions":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_action_plans":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_action_triggers":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_actions":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_attributes":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_chargers":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_destination_rates":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_destinations":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_dispatcher_hosts":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_dispatcher_profiles":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_filters":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_rates":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_rating_plans":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_rating_profiles":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_resources":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_routes":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_shared_groups":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_stats":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_thresholds":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_timings":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*versions":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false}},"opts":{"mongoQueryTimeout":"10s","mysqlDSNParams":{},"mysqlLocation":"Local","pgSSLMode":"disable","sqlConnMaxLifetime":0,"sqlMaxIdleConns":10,"sqlMaxOpenConns":100},"prefix_indexed_fields":[],"remote_conns":null,"replication_conns":null,"string_indexed_fields":[]}}` cfgCgr := NewDefaultCGRConfig() if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: STORDB_JSN}, &reply); err != nil { t.Error(err) diff --git a/config/eescfg.go b/config/eescfg.go index 39fb9e865..d3c271857 100644 --- a/config/eescfg.go +++ b/config/eescfg.go @@ -171,7 +171,7 @@ type EventExporterOpts struct { MYSQLDSNParams map[string]string SQLTableName *string SQLDBName *string - SSLMode *string + PgSSLMode *string KafkaTopic *string AMQPRoutingKey *string AMQPQueueID *string @@ -289,8 +289,8 @@ func (eeOpts *EventExporterOpts) loadFromJSONCfg(jsnCfg *EventExporterOptsJson) if jsnCfg.SQLDBName != nil { eeOpts.SQLDBName = jsnCfg.SQLDBName } - if jsnCfg.SSLMode != nil { - eeOpts.SSLMode = jsnCfg.SSLMode + if jsnCfg.PgSSLMode != nil { + eeOpts.PgSSLMode = jsnCfg.PgSSLMode } if jsnCfg.KafkaTopic != nil { eeOpts.KafkaTopic = jsnCfg.KafkaTopic @@ -549,8 +549,8 @@ func (eeOpts *EventExporterOpts) Clone() *EventExporterOpts { if eeOpts.SQLDBName != nil { cln.SQLDBName = utils.StringPointer(*eeOpts.SQLDBName) } - if eeOpts.SSLMode != nil { - cln.SSLMode = utils.StringPointer(*eeOpts.SSLMode) + if eeOpts.PgSSLMode != nil { + cln.PgSSLMode = utils.StringPointer(*eeOpts.PgSSLMode) } if eeOpts.KafkaTopic != nil { cln.KafkaTopic = utils.StringPointer(*eeOpts.KafkaTopic) @@ -748,8 +748,8 @@ func (eeC *EventExporterCfg) AsMapInterface(separator string) (initialMP map[str if eeC.Opts.SQLDBName != nil { opts[utils.SQLDBNameOpt] = *eeC.Opts.SQLDBName } - if eeC.Opts.SSLMode != nil { - opts[utils.SSLMode] = *eeC.Opts.SSLMode + if eeC.Opts.PgSSLMode != nil { + opts[utils.PgSSLModeCfg] = *eeC.Opts.PgSSLMode } if eeC.Opts.KafkaTopic != nil { opts[utils.KafkaTopic] = *eeC.Opts.KafkaTopic diff --git a/config/erscfg.go b/config/erscfg.go index e9eb35b38..c1c0f35d0 100644 --- a/config/erscfg.go +++ b/config/erscfg.go @@ -160,10 +160,10 @@ type EventReaderOpts struct { KafkaTopicProcessed *string SQLDBName *string SQLTableName *string - SSLMode *string + PgSSLMode *string SQLDBNameProcessed *string SQLTableNameProcessed *string - SSLModeProcessed *string + PgSSLModeProcessed *string AWSRegion *string AWSKey *string AWSSecret *string @@ -295,8 +295,8 @@ func (erOpts *EventReaderOpts) loadFromJSONCfg(jsnCfg *EventReaderOptsJson) (err if jsnCfg.SQLTableName != nil { erOpts.SQLTableName = jsnCfg.SQLTableName } - if jsnCfg.SSLMode != nil { - erOpts.SSLMode = jsnCfg.SSLMode + if jsnCfg.PgSSLMode != nil { + erOpts.PgSSLMode = jsnCfg.PgSSLMode } if jsnCfg.SQLDBNameProcessed != nil { erOpts.SQLDBNameProcessed = jsnCfg.SQLDBNameProcessed @@ -304,8 +304,8 @@ func (erOpts *EventReaderOpts) loadFromJSONCfg(jsnCfg *EventReaderOptsJson) (err if jsnCfg.SQLTableNameProcessed != nil { erOpts.SQLTableNameProcessed = jsnCfg.SQLTableNameProcessed } - if jsnCfg.SSLModeProcessed != nil { - erOpts.SSLModeProcessed = jsnCfg.SSLModeProcessed + if jsnCfg.PgSSLModeProcessed != nil { + erOpts.PgSSLModeProcessed = jsnCfg.PgSSLModeProcessed } if jsnCfg.AWSRegion != nil { erOpts.AWSRegion = jsnCfg.AWSRegion @@ -562,8 +562,8 @@ func (erOpts *EventReaderOpts) Clone() *EventReaderOpts { if erOpts.SQLTableName != nil { cln.SQLTableName = utils.StringPointer(*erOpts.SQLTableName) } - if erOpts.SSLMode != nil { - cln.SSLMode = utils.StringPointer(*erOpts.SSLMode) + if erOpts.PgSSLMode != nil { + cln.PgSSLMode = utils.StringPointer(*erOpts.PgSSLMode) } if erOpts.SQLDBNameProcessed != nil { cln.SQLDBNameProcessed = utils.StringPointer(*erOpts.SQLDBNameProcessed) @@ -571,8 +571,8 @@ func (erOpts *EventReaderOpts) Clone() *EventReaderOpts { if erOpts.SQLTableNameProcessed != nil { cln.SQLTableNameProcessed = utils.StringPointer(*erOpts.SQLTableNameProcessed) } - if erOpts.SSLModeProcessed != nil { - cln.SSLModeProcessed = utils.StringPointer(*erOpts.SSLModeProcessed) + if erOpts.PgSSLModeProcessed != nil { + cln.PgSSLModeProcessed = utils.StringPointer(*erOpts.PgSSLModeProcessed) } if erOpts.AWSRegion != nil { cln.AWSRegion = utils.StringPointer(*erOpts.AWSRegion) @@ -787,8 +787,8 @@ func (er *EventReaderCfg) AsMapInterface(separator string) (initialMP map[string if er.Opts.SQLTableName != nil { opts[utils.SQLTableNameOpt] = *er.Opts.SQLTableName } - if er.Opts.SSLMode != nil { - opts[utils.PgSSLModeCfg] = *er.Opts.SSLMode + if er.Opts.PgSSLMode != nil { + opts[utils.PgSSLModeCfg] = *er.Opts.PgSSLMode } if er.Opts.SQLDBNameProcessed != nil { opts[utils.SQLDBNameProcessedCfg] = *er.Opts.SQLDBNameProcessed @@ -796,8 +796,8 @@ func (er *EventReaderCfg) AsMapInterface(separator string) (initialMP map[string if er.Opts.SQLTableNameProcessed != nil { opts[utils.SQLTableNameProcessedCfg] = *er.Opts.SQLTableNameProcessed } - if er.Opts.SSLModeProcessed != nil { - opts[utils.SSLModeProcessedCfg] = *er.Opts.SSLModeProcessed + if er.Opts.PgSSLModeProcessed != nil { + opts[utils.PgSSLModeProcessedCfg] = *er.Opts.PgSSLModeProcessed } if er.Opts.AWSRegion != nil { opts[utils.AWSRegion] = *er.Opts.AWSRegion diff --git a/config/libconfig_json.go b/config/libconfig_json.go index ada033a25..6a927c882 100644 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -230,10 +230,10 @@ type EventReaderOptsJson struct { KafkaTopicProcessed *string `json:"kafkaTopicProcessed"` SQLDBName *string `json:"sqlDBName"` SQLTableName *string `json:"sqlTableName"` - SSLMode *string `json:"postgresSSLMode"` + PgSSLMode *string `json:"pgSSLMode"` SQLDBNameProcessed *string `json:"sqlDBNameProcessed"` SQLTableNameProcessed *string `json:"sqlTableNameProcessed"` - SSLModeProcessed *string `json:"postgresSSLModeProcessed"` + PgSSLModeProcessed *string `json:"pgSSLModeProcessed"` AWSRegion *string `json:"awsRegion"` AWSKey *string `json:"awsKey"` AWSSecret *string `json:"awsSecret"` @@ -311,7 +311,7 @@ type EventExporterOptsJson struct { MYSQLDSNParams map[string]string `json:"mysqlDSNParams"` SQLTableName *string `json:"sqlTableName"` SQLDBName *string `json:"sqlDBName"` - SSLMode *string `json:"sslMode"` + PgSSLMode *string `json:"pgSSLMode"` KafkaTopic *string `json:"kafkaTopic"` AMQPQueueID *string `json:"amqpQueueID"` AMQPRoutingKey *string `json:"amqpRoutingKey"` diff --git a/data/conf/cgrates/cgrates.json b/data/conf/cgrates/cgrates.json index 8e339dd6e..204a6ccc0 100755 --- a/data/conf/cgrates/cgrates.json +++ b/data/conf/cgrates/cgrates.json @@ -492,7 +492,7 @@ // // "sqlTableName":"cdrs", // the name of the table from where the events are exported // // "sqlDBName": "cgrates", // the name of the database from where the events are exported -// // "sslMode": "disable", // the postgresSSLMode for postgres +// // "pgSSLMode": "disable", // the SSLMode for postgres // // Kafka diff --git a/data/conf/samples/ees/cgrates.json b/data/conf/samples/ees/cgrates.json index e895f3f98..52a6c3b5d 100644 --- a/data/conf/samples/ees/cgrates.json +++ b/data/conf/samples/ees/cgrates.json @@ -386,7 +386,7 @@ "opts": { "sqlDBName": "cgrates2", // if dbName is not present "cgrates" will be used as default "sqlTableName": "expTable", // tableName is mandatory in opts for sql exporter - "postgresSSLMode": "disable", + "pgSSLMode": "disable", "sqlMaxIdleConns": 10, "sqlMaxOpenConns": 100, "sqlConnMaxLifetime": "0", @@ -411,7 +411,7 @@ "opts": { "sqlDBName": "cgrates2", "sqlTableName": "expTable", - "postgresSSLMode": "disable", + "pgSSLMode": "disable", "sqlMaxIdleConns": 10, "sqlMaxOpenConns": 100, "sqlConnMaxLifetime": "0", diff --git a/ees/sql.go b/ees/sql.go index 70ea41e29..fcd70da49 100644 --- a/ees/sql.go +++ b/ees/sql.go @@ -76,8 +76,8 @@ func (sqlEe *SQLEe) initDialector() (err error) { dbname = *sqlEe.Cfg().Opts.SQLDBName } ssl := utils.SQLDefaultSSLMode - if sqlEe.Cfg().Opts.SSLMode != nil { - ssl = *sqlEe.Cfg().Opts.SSLMode + if sqlEe.Cfg().Opts.PgSSLMode != nil { + ssl = *sqlEe.Cfg().Opts.PgSSLMode } // tableName is mandatory in opts if sqlEe.Cfg().Opts.SQLTableName != nil { diff --git a/ees/sql_test.go b/ees/sql_test.go index 9ed0f15a2..4d787f0fe 100644 --- a/ees/sql_test.go +++ b/ees/sql_test.go @@ -48,7 +48,7 @@ func TestNewSQLeUrl(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() cgrCfg.EEsCfg().Exporters[0].Opts.SQLTableName = utils.StringPointer("expTable") cgrCfg.EEsCfg().Exporters[0].Opts.SQLDBName = utils.StringPointer("postgres") - cgrCfg.EEsCfg().Exporters[0].Opts.SSLMode = utils.StringPointer("test") + cgrCfg.EEsCfg().Exporters[0].Opts.PgSSLMode = utils.StringPointer("test") sqlEe := &SQLEe{ cfg: cgrCfg.EEsCfg().Exporters[0], reqs: newConcReq(0), diff --git a/ers/libers.go b/ers/libers.go index 6abf971b7..387969ef7 100644 --- a/ers/libers.go +++ b/ers/libers.go @@ -162,11 +162,11 @@ func getProcessOptions(erOpts *config.EventReaderOpts) (eeOpts *config.EventExpo } eeOpts.SQSQueueID = erOpts.SQSQueueIDProcessed } - if erOpts.SSLModeProcessed != nil { + if erOpts.PgSSLModeProcessed != nil { if eeOpts == nil { eeOpts = new(config.EventExporterOpts) } - eeOpts.SSLMode = erOpts.SSLModeProcessed + eeOpts.PgSSLMode = erOpts.PgSSLModeProcessed } return } diff --git a/ers/sql.go b/ers/sql.go index f0047b609..9bf4870eb 100644 --- a/ers/sql.go +++ b/ers/sql.go @@ -279,8 +279,8 @@ func (rdr *SQLEventReader) setURL(inURL, outURL string, opts *config.EventReader dbname = *opts.SQLDBName } ssl := utils.SQLDefaultSSLMode - if opts.SSLMode != nil { - ssl = *opts.SSLMode + if opts.PgSSLMode != nil { + ssl = *opts.PgSSLMode } rdr.tableName = utils.CDRsTBL @@ -330,8 +330,8 @@ func (rdr *SQLEventReader) setURL(inURL, outURL string, opts *config.EventReader outDBname = *processedOpt.SQLDBName } outSSL = utils.SQLDefaultSSLMode - if processedOpt.SSLMode != nil { - outSSL = *processedOpt.SSLMode + if processedOpt.PgSSLMode != nil { + outSSL = *processedOpt.PgSSLMode } rdr.expTableName = utils.CDRsTBL if processedOpt.SQLTableName != nil { diff --git a/ers/sql_test.go b/ers/sql_test.go index 722b9ea96..8bb118a69 100644 --- a/ers/sql_test.go +++ b/ers/sql_test.go @@ -43,11 +43,11 @@ func TestSQLSetURL(t *testing.T) { if err := sql.setURL(inURL, outURL, &config.EventReaderOpts{ SQLDBName: utils.StringPointer("cgrates2"), SQLTableName: utils.StringPointer("cdrs2"), - SSLMode: utils.StringPointer("enabled"), + PgSSLMode: utils.StringPointer("enabled"), SQLDBNameProcessed: utils.StringPointer("cgrates3"), SQLTableNameProcessed: utils.StringPointer("cdrs3"), - SSLModeProcessed: utils.StringPointer("enabled"), + PgSSLModeProcessed: utils.StringPointer("enabled"), }); err != nil { t.Fatal(err) } else if expsql.connString != sql.connString { @@ -78,11 +78,11 @@ func TestSQLSetURL(t *testing.T) { if err := sql.setURL(inURL, outURL, &config.EventReaderOpts{ SQLDBName: utils.StringPointer("cgrates2"), SQLTableName: utils.StringPointer("cdrs2"), - SSLMode: utils.StringPointer("enabled"), + PgSSLMode: utils.StringPointer("enabled"), SQLDBNameProcessed: utils.StringPointer("cgrates3"), SQLTableNameProcessed: utils.StringPointer("cdrs3"), - SSLModeProcessed: utils.StringPointer("enabled"), + PgSSLModeProcessed: utils.StringPointer("enabled"), }); err != nil { t.Fatal(err) } else if expsql.connString != sql.connString { @@ -113,11 +113,11 @@ func TestSQLSetURL(t *testing.T) { if err := sql.setURL(inURL, outURL, &config.EventReaderOpts{ SQLDBName: utils.StringPointer("cgrates2"), SQLTableName: utils.StringPointer("cdrs2"), - SSLMode: utils.StringPointer("enabled"), + PgSSLMode: utils.StringPointer("enabled"), SQLDBNameProcessed: utils.StringPointer("cgrates2"), SQLTableNameProcessed: utils.StringPointer("cdrs2"), - SSLModeProcessed: utils.StringPointer("enabled"), + PgSSLModeProcessed: utils.StringPointer("enabled"), }); err != nil { t.Fatal(err) } else if expsql.connString != sql.connString { diff --git a/services/datadb_it_test.go b/services/datadb_it_test.go index 5ed8608f8..2cee8a55c 100644 --- a/services/datadb_it_test.go +++ b/services/datadb_it_test.go @@ -656,58 +656,40 @@ func TestDataDBReloadCastError(t *testing.T) { time.Sleep(10 * time.Millisecond) } -func TestDataDBReloadIfaceAsDurationError(t *testing.T) { - cfg, err := config.NewCGRConfigFromPath(path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo")) - if err != nil { - t.Fatal(err) - } - dbConn, err := engine.NewDataDBConn(cfg.DataDbCfg().Type, - cfg.DataDbCfg().Host, cfg.DataDbCfg().Port, - cfg.DataDbCfg().Name, cfg.DataDbCfg().User, - cfg.DataDbCfg().Password, cfg.GeneralCfg().DBDataEncoding, - cfg.DataDbCfg().Opts, cfg.DataDbCfg().Items) - if err != nil { - t.Fatal(err) - } - defer func() { - dbConn.Flush("") - dbConn.Close() - }() - - err = dbConn.SetVersions(engine.Versions{ - utils.StatS: 4, - utils.Accounts: 3, - utils.Actions: 2, - utils.ActionTriggers: 2, - utils.ActionPlans: 3, - utils.SharedGroups: 2, - utils.Thresholds: 4, - utils.Routes: 2, - // old version for Attributes - utils.Attributes: 5, - utils.Timing: 1, - utils.RQF: 5, - utils.Resource: 1, - utils.Subscribers: 1, - utils.Destinations: 1, - utils.ReverseDestinations: 1, - utils.RatingPlan: 1, - utils.RatingProfile: 1, - utils.Chargers: 2, - utils.Dispatchers: 2, - utils.LoadIDsVrs: 1, - }, true) - if err != nil { - t.Fatal(err) - } - utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID) - utils.Logger.SetLogLevel(7) - shdChan := utils.NewSyncedChan() - filterSChan := make(chan *engine.FilterS, 1) - filterSChan <- nil +func TestDataDBStartSessionSCfgErr(t *testing.T) { + cfg := config.NewDefaultCGRConfig() srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} cM := engine.NewConnManager(cfg, nil) db := NewDataDBService(cfg, cM, srvDep) + cfg.DataDbCfg().Type = "badtype" + cfg.SessionSCfg().Enabled = true + cfg.SessionSCfg().ListenBijson = "" + err := db.Start() + if err != nil { + t.Errorf("\nExpecting <%+v>,\n Received <%+v>", nil, err) + } +} + +func TestDataDBStartRalsSCfgErr(t *testing.T) { + cfg := config.NewDefaultCGRConfig() + srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} + cM := engine.NewConnManager(cfg, nil) + db := NewDataDBService(cfg, cM, srvDep) + cfg.DataDbCfg().Type = "badtype" + db.cfg.RalsCfg().Enabled = true + cfg.SessionSCfg().ListenBijson = "" + err := db.Start() + if err == nil || err.Error() != "unsupported db_type " { + t.Errorf("\nExpecting <%+v>,\n Received <%+v>", "unsupported db_type ", err) + } +} + +func TestDataDBReloadError(t *testing.T) { + cfg := config.NewDefaultCGRConfig() + srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} + cM := engine.NewConnManager(cfg, nil) + db := NewDataDBService(cfg, cM, srvDep) + cfg.GeneralCfg().DBDataEncoding = utils.JSON db.oldDBCfg = &config.DataDbCfg{ Type: utils.Mongo, Host: "127.0.0.1", @@ -804,145 +786,6 @@ func TestDataDBReloadIfaceAsDurationError(t *testing.T) { Remote: false}, }, } - cfg.DataDbCfg().Opts.MongoQueryTimeout = true - db.dm = nil - err = db.Reload() - if err == nil || err.Error() != "cannot convert field: true to time.Duration" { - t.Fatal(err) - } - - shdChan.CloseOnce() - time.Sleep(10 * time.Millisecond) -} - -func TestDataDBStartSessionSCfgErr(t *testing.T) { - cfg := config.NewDefaultCGRConfig() - srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - cM := engine.NewConnManager(cfg, nil) - db := NewDataDBService(cfg, cM, srvDep) - cfg.DataDbCfg().Type = "badtype" - cfg.SessionSCfg().Enabled = true - cfg.SessionSCfg().ListenBijson = "" - err := db.Start() - if err != nil { - t.Errorf("\nExpecting <%+v>,\n Received <%+v>", nil, err) - } -} - -func TestDataDBStartRalsSCfgErr(t *testing.T) { - cfg := config.NewDefaultCGRConfig() - srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - cM := engine.NewConnManager(cfg, nil) - db := NewDataDBService(cfg, cM, srvDep) - cfg.DataDbCfg().Type = "badtype" - db.cfg.RalsCfg().Enabled = true - cfg.SessionSCfg().ListenBijson = "" - err := db.Start() - if err == nil || err.Error() != "unsupported db_type " { - t.Errorf("\nExpecting <%+v>,\n Received <%+v>", "unsupported db_type ", err) - } -} - -func TestDataDBReloadError(t *testing.T) { - cfg := config.NewDefaultCGRConfig() - srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - cM := engine.NewConnManager(cfg, nil) - db := NewDataDBService(cfg, cM, srvDep) - cfg.GeneralCfg().DBDataEncoding = utils.JSON - db.oldDBCfg = &config.DataDbCfg{ - Type: utils.Mongo, - Host: "127.0.0.1", - Port: "27017", - Name: "10", - User: "cgrates", - Opts: map[string]interface{}{ - utils.MongoQueryTimeoutCfg: "10s", - utils.RedisClusterOnDownDelayCfg: "0", - utils.RedisClusterSyncCfg: "5s", - utils.RedisClusterCfg: false, - utils.RedisSentinelNameCfg: "", - utils.RedisTLS: false, - utils.RedisClientCertificate: "", - utils.RedisClientKey: "", - utils.RedisCACertificate: "", - }, - RmtConns: []string{}, - RplConns: []string{}, - Items: map[string]*config.ItemOpt{ - utils.MetaAccounts: { - Replicate: false, - Remote: false}, - utils.MetaReverseDestinations: { - Replicate: false, - Remote: false}, - utils.MetaDestinations: { - Replicate: false, - Remote: false}, - utils.MetaRatingPlans: { - Replicate: false, - Remote: false}, - utils.MetaRatingProfiles: { - Replicate: false, - Remote: false}, - utils.MetaActions: { - Replicate: false, - Remote: false}, - utils.MetaActionPlans: { - Replicate: false, - Remote: false}, - utils.MetaAccountActionPlans: { - Replicate: false, - Remote: false}, - utils.MetaActionTriggers: { - Replicate: false, - Remote: false}, - utils.MetaSharedGroups: { - Replicate: false, - Remote: false}, - utils.MetaTimings: { - Replicate: false, - Remote: false}, - utils.MetaResourceProfile: { - Replicate: false, - Remote: false}, - utils.MetaStatQueues: { - Replicate: false, - Remote: false}, - utils.MetaResources: { - Replicate: false, - Remote: false}, - utils.MetaStatQueueProfiles: { - Replicate: false, - Remote: false}, - utils.MetaThresholds: { - Replicate: false, - Remote: false}, - utils.MetaThresholdProfiles: { - Replicate: false, - Remote: false}, - utils.MetaFilters: { - Replicate: false, - Remote: false}, - utils.MetaRouteProfiles: { - Replicate: false, - Remote: false}, - utils.MetaAttributeProfiles: { - Replicate: false, - Remote: false}, - utils.MetaDispatcherHosts: { - Replicate: false, - Remote: false}, - utils.MetaChargerProfiles: { - Replicate: false, - Remote: false}, - utils.MetaDispatcherProfiles: { - Replicate: false, - Remote: false}, - utils.MetaLoadIDs: { - Replicate: false, - Remote: false}, - }, - } data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) db.dm = engine.NewDataManager(data, nil, nil) err := db.Reload() diff --git a/services/datadb_test.go b/services/datadb_test.go index 420042bb9..752a19d7e 100644 --- a/services/datadb_test.go +++ b/services/datadb_test.go @@ -21,6 +21,7 @@ import ( "reflect" "sync" "testing" + "time" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -52,16 +53,18 @@ func TestDataDBCoverage(t *testing.T) { Port: "27017", Name: "10", User: "cgrates", - Opts: map[string]interface{}{ - utils.MongoQueryTimeoutCfg: "10s", - utils.RedisClusterOnDownDelayCfg: "0", - utils.RedisClusterSyncCfg: "5s", - utils.RedisClusterCfg: false, - utils.RedisSentinelNameCfg: "", - utils.RedisTLS: false, - utils.RedisClientCertificate: "", - utils.RedisClientKey: "", - utils.RedisCACertificate: "", + Opts: &config.DataDBOpts{ + RedisMaxConns: 10, + RedisConnectAttempts: 20, + RedisSentinel: "", + RedisCluster: false, + RedisClusterSync: 5 * time.Second, + RedisClusterOndownDelay: 0, + RedisConnectTimeout: 0, + RedisReadTimeout: 0, + RedisWriteTimeout: 0, + MongoQueryTimeout: 10 * time.Second, + RedisTLS: false, }, RmtConns: []string{}, RplConns: []string{}, diff --git a/services/stordb_it_test.go b/services/stordb_it_test.go index 3b6595d92..d5c8ddbfc 100644 --- a/services/stordb_it_test.go +++ b/services/stordb_it_test.go @@ -422,109 +422,6 @@ func TestStorDBReloadNewStorDBConnError(t *testing.T) { shdChan.CloseOnce() } -func TestStorDBReloadCanCastError(t *testing.T) { - cfg := config.NewDefaultCGRConfig() - utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID) - utils.Logger.SetLogLevel(7) - filterSChan := make(chan *engine.FilterS, 1) - filterSChan <- nil - shdChan := utils.NewSyncedChan() - cfg.ChargerSCfg().Enabled = true - srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - cfg.StorDbCfg().Password = "CGRateS.org" - cfg.StorDbCfg().Type = utils.Mongo - stordb := NewStorDBService(cfg, srvDep) - stordb.cfg.StorDbCfg().Opts = map[string]interface{}{ - utils.MongoQueryTimeoutCfg: false, - } - stordb.db = &engine.MongoStorage{} - stordb.oldDBCfg = cfg.StorDbCfg().Clone() - err := stordb.Reload() - if err == nil || err.Error() != "cannot convert field: false to time.Duration" { - t.Errorf("\nExpecting <%+v>,\n Received <%+v>", "cannot convert field: false to time.Duration", err) - } - shdChan.CloseOnce() -} - -func TestStorDBReloadIfaceAsTIntMaxOpenConnsCfgError(t *testing.T) { - cfg := config.NewDefaultCGRConfig() - utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID) - utils.Logger.SetLogLevel(7) - filterSChan := make(chan *engine.FilterS, 1) - filterSChan <- nil - shdChan := utils.NewSyncedChan() - cfg.ChargerSCfg().Enabled = true - srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - cfg.StorDbCfg().Password = "CGRateS.org" - cfg.StorDbCfg().Type = utils.MySQL - stordb := NewStorDBService(cfg, srvDep) - stordb.cfg.StorDbCfg().Opts = map[string]interface{}{ - utils.SQLMaxOpenConnsCfg: false, - } - stordb.db = &engine.SQLStorage{} - stordb.oldDBCfg = cfg.StorDbCfg().Clone() - err := stordb.Reload() - expected := "cannot convert field: false to int" - if err == nil || err.Error() != expected { - t.Errorf("\nExpecting <%+v>,\n Received <%+v>", expected, err) - } - shdChan.CloseOnce() -} - -func TestStorDBReloadIfaceAsTIntConnMaxLifetimeCfgError(t *testing.T) { - cfg := config.NewDefaultCGRConfig() - utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID) - utils.Logger.SetLogLevel(7) - filterSChan := make(chan *engine.FilterS, 1) - filterSChan <- nil - shdChan := utils.NewSyncedChan() - cfg.ChargerSCfg().Enabled = true - srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - cfg.StorDbCfg().Password = "CGRateS.org" - cfg.StorDbCfg().Type = utils.MySQL - stordb := NewStorDBService(cfg, srvDep) - stordb.cfg.StorDbCfg().Opts = map[string]interface{}{ - utils.SQLMaxOpenConnsCfg: 1, - utils.SQLMaxIdleConnsCfg: 1, - utils.SQLConnMaxLifetimeCfg: false, - } - stordb.db = &engine.SQLStorage{} - stordb.oldDBCfg = cfg.StorDbCfg().Clone() - err := stordb.Reload() - expected := "cannot convert field: false to int" - if err == nil || err.Error() != expected { - t.Errorf("\nExpecting <%+v>,\n Received <%+v>", expected, err) - } - shdChan.CloseOnce() -} - -func TestStorDBReloadIfaceAsTIntMaxIdleConnsCfgError(t *testing.T) { - cfg := config.NewDefaultCGRConfig() - utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID) - utils.Logger.SetLogLevel(7) - filterSChan := make(chan *engine.FilterS, 1) - filterSChan <- nil - shdChan := utils.NewSyncedChan() - cfg.ChargerSCfg().Enabled = true - srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - cfg.StorDbCfg().Password = "CGRateS.org" - cfg.StorDbCfg().Type = utils.MySQL - stordb := NewStorDBService(cfg, srvDep) - stordb.cfg.StorDbCfg().Opts = map[string]interface{}{ - utils.SQLMaxOpenConnsCfg: 1, - utils.SQLMaxIdleConnsCfg: false, - utils.SQLConnMaxLifetimeCfg: 1, - } - stordb.db = &engine.SQLStorage{} - stordb.oldDBCfg = cfg.StorDbCfg().Clone() - err := stordb.Reload() - expected := "cannot convert field: false to int" - if err == nil || err.Error() != expected { - t.Errorf("\nExpecting <%+v>,\n Received <%+v>", expected, err) - } - shdChan.CloseOnce() -} - func TestStorDBReloadStartDBError(t *testing.T) { cfg := config.NewDefaultCGRConfig() utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID) diff --git a/utils/consts.go b/utils/consts.go index 1285ec6fd..0ebe19fc1 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -2653,7 +2653,7 @@ const ( SQLDBNameProcessedCfg = "sqlDBNameProcessed" SQLTableNameProcessedCfg = "sqlTableNameProcessed" - SSLModeProcessedCfg = "sslModeProcessed" + PgSSLModeProcessedCfg = "pgSSLModeProcessed" AWSRegionProcessedCfg = "awsRegionProcessed" AWSKeyProcessedCfg = "awsKeyProcessed"