Browse Source

cover more

topic
yedf2 5 years ago
parent
commit
46b14d5432
  1. 12
      conf.sample.yml
  2. 3
      dtmsvr/config/config_test.go
  3. 4
      dtmsvr/storage/sql/sql.go
  4. 3
      test/common_test.go

12
conf.sample.yml

@ -1,4 +1,4 @@
Store: # specify which engine to store trans status # Store: # specify which engine to store trans status
# Driver: 'boltdb' # default store engine # Driver: 'boltdb' # default store engine
# Driver: 'redis' # Driver: 'redis'
@ -7,11 +7,11 @@ Store: # specify which engine to store trans status
# Password: '' # Password: ''
# Port: 6379 # Port: 6379
Driver: 'mysql' # Driver: 'mysql'
Host: 'localhost' # Host: 'localhost'
User: 'root' # User: 'root'
Password: '' # Password: ''
Port: 3306 # Port: 3306
# Driver: 'postgres' # Driver: 'postgres'
# Host: 'localhost' # Host: 'localhost'

3
dtmsvr/config/config_test.go

@ -18,12 +18,15 @@ func TestLoadFromEnv(t *testing.T) {
} }
func TestCheckConfig(t *testing.T) { func TestCheckConfig(t *testing.T) {
MustLoadConfig("../../conf.sample.yml")
config := &Config config := &Config
config.RetryInterval = 1
retryIntervalErr := checkConfig() retryIntervalErr := checkConfig()
retryIntervalExpect := errors.New("RetryInterval should not be less than 10") retryIntervalExpect := errors.New("RetryInterval should not be less than 10")
assert.Equal(t, retryIntervalErr, retryIntervalExpect) assert.Equal(t, retryIntervalErr, retryIntervalExpect)
config.RetryInterval = 10 config.RetryInterval = 10
config.TimeoutToFail = 5
timeoutToFailErr := checkConfig() timeoutToFailErr := checkConfig()
timeoutToFailExpect := errors.New("TimeoutToFail should not be less than RetryInterval") timeoutToFailExpect := errors.New("TimeoutToFail should not be less than RetryInterval")
assert.Equal(t, timeoutToFailErr, timeoutToFailExpect) assert.Equal(t, timeoutToFailErr, timeoutToFailExpect)

4
dtmsvr/storage/sql/sql.go

@ -144,7 +144,7 @@ func (s *SqlStore) LockOneGlobalTrans(expireIn time.Duration) *storage.TransGlob
return global return global
} }
func setDBConn(db *gorm.DB) { func SetDBConn(db *gorm.DB) {
sqldb, _ := db.DB() sqldb, _ := db.DB()
sqldb.SetMaxOpenConns(int(conf.Store.MaxOpenConns)) sqldb.SetMaxOpenConns(int(conf.Store.MaxOpenConns))
sqldb.SetMaxIdleConns(int(conf.Store.MaxIdleConns)) sqldb.SetMaxIdleConns(int(conf.Store.MaxIdleConns))
@ -152,7 +152,7 @@ func setDBConn(db *gorm.DB) {
} }
func dbGet() *dtmutil.DB { func dbGet() *dtmutil.DB {
return dtmutil.DbGet(conf.Store.GetDBConf(), setDBConn) return dtmutil.DbGet(conf.Store.GetDBConf(), SetDBConn)
} }
func wrapError(err error) error { func wrapError(err error) error {

3
test/common_test.go

@ -4,6 +4,7 @@ import (
"testing" "testing"
"github.com/dtm-labs/dtm/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmcli/dtmimp"
"github.com/dtm-labs/dtm/dtmsvr/storage/sql"
"github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/dtmutil"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -16,7 +17,7 @@ func TestGeneralDB(t *testing.T) {
} }
func testSql(t *testing.T) { func testSql(t *testing.T) {
db := dtmutil.DbGet(conf.Store.GetDBConf()) db := dtmutil.DbGet(conf.Store.GetDBConf(), sql.SetDBConn)
err := func() (rerr error) { err := func() (rerr error) {
defer dtmimp.P2E(&rerr) defer dtmimp.P2E(&rerr)
db.Must().Exec("select a") db.Must().Exec("select a")

Loading…
Cancel
Save