Added migrator tests and updated tests to work with new migrator structure

This commit is contained in:
Anevo
2018-05-11 06:28:33 -04:00
committed by Dan Christian Bogos
parent 5f82c34cad
commit 0420254b8b
27 changed files with 1350 additions and 359 deletions

View File

@@ -1637,6 +1637,7 @@ func (tps TpAliases) AsMapTPAliases() (map[string]*utils.TPAliases, error) {
var found bool
if as, found = result[tp.GetId()]; !found {
as = &utils.TPAliases{
TPid: tp.Tpid,
Direction: tp.Direction,
Tenant: tp.Tenant,
Category: tp.Category,

View File

@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package migrator
/*
import (
"log"
"path"
@@ -67,7 +66,7 @@ func testTpAccActITConnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storDBIn, err := engine.ConfigureStorDB(tpAccActCfgIn.StorDBType, tpAccActCfgIn.StorDBHost,
storDBIn, err := NewMigratorStorDB(tpAccActCfgIn.StorDBType, tpAccActCfgIn.StorDBHost,
tpAccActCfgIn.StorDBPort, tpAccActCfgIn.StorDBName,
tpAccActCfgIn.StorDBUser, tpAccActCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -77,7 +76,7 @@ func testTpAccActITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
storDBOut, err := engine.ConfigureStorDB(tpAccActCfgOut.StorDBType,
storDBOut, err := NewMigratorStorDB(tpAccActCfgOut.StorDBType,
tpAccActCfgOut.StorDBHost, tpAccActCfgOut.StorDBPort, tpAccActCfgOut.StorDBName,
tpAccActCfgOut.StorDBUser, tpAccActCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -87,22 +86,19 @@ func testTpAccActITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
tpAccActMigrator, err = NewMigrator(nil, nil, tpAccActCfgIn.DataDbType,
tpAccActCfgIn.DBDataEncoding, storDBIn, storDBOut, tpAccActCfgIn.StorDBType, nil,
tpAccActCfgIn.DataDbType, tpAccActCfgIn.DBDataEncoding, nil,
tpAccActCfgIn.StorDBType, false, false, false, false, false)
tpAccActMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpAccActITFlush(t *testing.T) {
if err := tpAccActMigrator.storDBIn.Flush(
if err := tpAccActMigrator.storDBIn.StorDB().Flush(
path.Join(tpAccActCfgIn.DataFolderPath, "storage", tpAccActCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpAccActMigrator.storDBOut.Flush(
if err := tpAccActMigrator.storDBOut.StorDB().Flush(
path.Join(tpAccActCfgOut.DataFolderPath, "storage", tpAccActCfgOut.StorDBType)); err != nil {
t.Error(err)
}
@@ -120,11 +116,11 @@ func testTpAccActITPopulate(t *testing.T) {
Disabled: false,
},
}
if err := tpAccActMigrator.storDBIn.SetTPAccountActions(tpAccountActions); err != nil {
if err := tpAccActMigrator.storDBIn.StorDB().SetTPAccountActions(tpAccountActions); err != nil {
t.Error("Error when setting TpAccountActions ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpAccActMigrator.storDBOut.SetVersions(currentVersion, false)
err := tpAccActMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpAccountActions ", err.Error())
}
@@ -139,7 +135,7 @@ func testTpAccActITMove(t *testing.T) {
func testTpAccActITCheckData(t *testing.T) {
filter := &utils.TPAccountActions{TPid: tpAccountActions[0].TPid}
result, err := tpAccActMigrator.storDBOut.GetTPAccountActions(filter)
result, err := tpAccActMigrator.storDBOut.StorDB().GetTPAccountActions(filter)
if err != nil {
t.Error("Error when getting TpAccountActions ", err.Error())
}
@@ -147,9 +143,8 @@ func testTpAccActITCheckData(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v",
utils.ToJSON(tpAccountActions[0]), utils.ToJSON(result[0]))
}
result, err = tpAccActMigrator.storDBIn.GetTPAccountActions(filter)
result, err = tpAccActMigrator.storDBIn.StorDB().GetTPAccountActions(filter)
if err != utils.ErrNotFound {
t.Error(err)
}
}
*/

View File

@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package migrator
/*
import (
"log"
"path"
@@ -67,7 +66,7 @@ func testTpActPlnITConnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storDBIn, err := engine.ConfigureStorDB(tpActPlnCfgIn.StorDBType, tpActPlnCfgIn.StorDBHost,
storDBIn, err := NewMigratorStorDB(tpActPlnCfgIn.StorDBType, tpActPlnCfgIn.StorDBHost,
tpActPlnCfgIn.StorDBPort, tpActPlnCfgIn.StorDBName,
tpActPlnCfgIn.StorDBUser, tpActPlnCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -77,7 +76,7 @@ func testTpActPlnITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
storDBOut, err := engine.ConfigureStorDB(tpActPlnCfgOut.StorDBType,
storDBOut, err := NewMigratorStorDB(tpActPlnCfgOut.StorDBType,
tpActPlnCfgOut.StorDBHost, tpActPlnCfgOut.StorDBPort, tpActPlnCfgOut.StorDBName,
tpActPlnCfgOut.StorDBUser, tpActPlnCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -87,22 +86,19 @@ func testTpActPlnITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
tpActPlnMigrator, err = NewMigrator(nil, nil, tpActPlnCfgIn.DataDbType,
tpActPlnCfgIn.DBDataEncoding, storDBIn, storDBOut, tpActPlnCfgIn.StorDBType, nil,
tpActPlnCfgIn.DataDbType, tpActPlnCfgIn.DBDataEncoding, nil,
tpActPlnCfgIn.StorDBType, false, false, false, false, false)
tpActPlnMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpActPlnITFlush(t *testing.T) {
if err := tpActPlnMigrator.storDBIn.Flush(
if err := tpActPlnMigrator.storDBIn.StorDB().Flush(
path.Join(tpActPlnCfgIn.DataFolderPath, "storage", tpActPlnCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpActPlnMigrator.storDBOut.Flush(
if err := tpActPlnMigrator.storDBOut.StorDB().Flush(
path.Join(tpActPlnCfgOut.DataFolderPath, "storage", tpActPlnCfgOut.StorDBType)); err != nil {
t.Error(err)
}
@@ -127,11 +123,11 @@ func testTpActPlnITPopulate(t *testing.T) {
},
},
}
if err := tpActPlnMigrator.storDBIn.SetTPActionPlans(tpActionPlans); err != nil {
if err := tpActPlnMigrator.storDBIn.StorDB().SetTPActionPlans(tpActionPlans); err != nil {
t.Error("Error when setting TpActionPlan ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpActPlnMigrator.storDBOut.SetVersions(currentVersion, false)
err := tpActPlnMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpActionPlan ", err.Error())
}
@@ -145,7 +141,7 @@ func testTpActPlnITMove(t *testing.T) {
}
func testTpActPlnITCheckData(t *testing.T) {
result, err := tpActPlnMigrator.storDBOut.GetTPActionPlans(
result, err := tpActPlnMigrator.storDBOut.StorDB().GetTPActionPlans(
tpActionPlans[0].TPid, tpActionPlans[0].ID)
if err != nil {
t.Error("Error when getting TpActionPlan ", err.Error())
@@ -154,10 +150,9 @@ func testTpActPlnITCheckData(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v",
utils.ToJSON(tpActionPlans[0]), utils.ToJSON(result[0]))
}
result, err = tpActPlnMigrator.storDBIn.GetTPActionPlans(
result, err = tpActPlnMigrator.storDBIn.StorDB().GetTPActionPlans(
tpActionPlans[0].TPid, tpActionPlans[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}
*/

View File

@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package migrator
/*
import (
"log"
"path"
@@ -67,7 +66,7 @@ func testTpActTrgITConnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storDBIn, err := engine.ConfigureStorDB(tpActTrgCfgIn.StorDBType, tpActTrgCfgIn.StorDBHost,
storDBIn, err := NewMigratorStorDB(tpActTrgCfgIn.StorDBType, tpActTrgCfgIn.StorDBHost,
tpActTrgCfgIn.StorDBPort, tpActTrgCfgIn.StorDBName,
tpActTrgCfgIn.StorDBUser, tpActTrgCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -77,7 +76,7 @@ func testTpActTrgITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
storDBOut, err := engine.ConfigureStorDB(tpActTrgCfgOut.StorDBType,
storDBOut, err := NewMigratorStorDB(tpActTrgCfgOut.StorDBType,
tpActTrgCfgOut.StorDBHost, tpActTrgCfgOut.StorDBPort, tpActTrgCfgOut.StorDBName,
tpActTrgCfgOut.StorDBUser, tpActTrgCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -87,22 +86,19 @@ func testTpActTrgITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
tpActTrgMigrator, err = NewMigrator(nil, nil, tpActTrgCfgIn.DataDbType,
tpActTrgCfgIn.DBDataEncoding, storDBIn, storDBOut, tpActTrgCfgIn.StorDBType, nil,
tpActTrgCfgIn.DataDbType, tpActTrgCfgIn.DBDataEncoding, nil,
tpActTrgCfgIn.StorDBType, false, false, false, false, false)
tpActTrgMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpActTrgITFlush(t *testing.T) {
if err := tpActTrgMigrator.storDBIn.Flush(
if err := tpActTrgMigrator.storDBIn.StorDB().Flush(
path.Join(tpActTrgCfgIn.DataFolderPath, "storage", tpActTrgCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpActTrgMigrator.storDBOut.Flush(
if err := tpActTrgMigrator.storDBOut.StorDB().Flush(
path.Join(tpActTrgCfgOut.DataFolderPath, "storage", tpActTrgCfgOut.StorDBType)); err != nil {
t.Error(err)
}
@@ -167,11 +163,11 @@ func testTpActTrgITPopulate(t *testing.T) {
},
},
}
if err := tpActTrgMigrator.storDBIn.SetTPActionTriggers(tpActionTriggers); err != nil {
if err := tpActTrgMigrator.storDBIn.StorDB().SetTPActionTriggers(tpActionTriggers); err != nil {
t.Error("Error when setting TpActionTriggers ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpActTrgMigrator.storDBOut.SetVersions(currentVersion, false)
err := tpActTrgMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpActionTriggers ", err.Error())
}
@@ -185,7 +181,7 @@ func testTpActTrgITMove(t *testing.T) {
}
func testTpActTrgITCheckData(t *testing.T) {
result, err := tpActTrgMigrator.storDBOut.GetTPActionTriggers(
result, err := tpActTrgMigrator.storDBOut.StorDB().GetTPActionTriggers(
tpActionTriggers[0].TPid, tpActionTriggers[0].ID)
if err != nil {
t.Error("Error when getting TpActionTriggers ", err.Error())
@@ -194,10 +190,9 @@ func testTpActTrgITCheckData(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v",
utils.ToJSON(tpActionTriggers[0]), utils.ToJSON(result[0]))
}
result, err = tpActTrgMigrator.storDBIn.GetTPActionTriggers(
result, err = tpActTrgMigrator.storDBIn.StorDB().GetTPActionTriggers(
tpActionTriggers[0].TPid, tpActionTriggers[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}
*/

View File

@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package migrator
/*
import (
"log"
"path"
@@ -67,7 +66,7 @@ func testTpActITConnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storDBIn, err := engine.ConfigureStorDB(tpActCfgIn.StorDBType, tpActCfgIn.StorDBHost,
storDBIn, err := NewMigratorStorDB(tpActCfgIn.StorDBType, tpActCfgIn.StorDBHost,
tpActCfgIn.StorDBPort, tpActCfgIn.StorDBName,
tpActCfgIn.StorDBUser, tpActCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -77,7 +76,7 @@ func testTpActITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
storDBOut, err := engine.ConfigureStorDB(tpActCfgOut.StorDBType,
storDBOut, err := NewMigratorStorDB(tpActCfgOut.StorDBType,
tpActCfgOut.StorDBHost, tpActCfgOut.StorDBPort, tpActCfgOut.StorDBName,
tpActCfgOut.StorDBUser, tpActCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -87,22 +86,19 @@ func testTpActITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
tpActMigrator, err = NewMigrator(nil, nil, tpActCfgIn.DataDbType,
tpActCfgIn.DBDataEncoding, storDBIn, storDBOut, tpActCfgIn.StorDBType, nil,
tpActCfgIn.DataDbType, tpActCfgIn.DBDataEncoding, nil,
tpActCfgIn.StorDBType, false, false, false, false, false)
tpActMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpActITFlush(t *testing.T) {
if err := tpActMigrator.storDBIn.Flush(
if err := tpActMigrator.storDBIn.StorDB().Flush(
path.Join(tpActCfgIn.DataFolderPath, "storage", tpActCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpActMigrator.storDBOut.Flush(
if err := tpActMigrator.storDBOut.StorDB().Flush(
path.Join(tpActCfgOut.DataFolderPath, "storage", tpActCfgOut.StorDBType)); err != nil {
t.Error(err)
}
@@ -157,11 +153,11 @@ func testTpActITPopulate(t *testing.T) {
},
},
}
if err := tpActMigrator.storDBIn.SetTPActions(tpActions); err != nil {
if err := tpActMigrator.storDBIn.StorDB().SetTPActions(tpActions); err != nil {
t.Error("Error when setting TpActions ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpActMigrator.storDBOut.SetVersions(currentVersion, false)
err := tpActMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpActions ", err.Error())
}
@@ -175,7 +171,7 @@ func testTpActITMove(t *testing.T) {
}
func testTpActITCheckData(t *testing.T) {
result, err := tpActMigrator.storDBOut.GetTPActions(
result, err := tpActMigrator.storDBOut.StorDB().GetTPActions(
tpActions[0].TPid, tpActions[0].ID)
if err != nil {
t.Error("Error when getting TpActions ", err.Error())
@@ -184,10 +180,9 @@ func testTpActITCheckData(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v",
utils.ToJSON(tpActions[0]), utils.ToJSON(result[0]))
}
result, err = tpActMigrator.storDBIn.GetTPActions(
result, err = tpActMigrator.storDBIn.StorDB().GetTPActions(
tpActions[0].TPid, tpActions[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}
*/

View File

@@ -44,7 +44,8 @@ func (m *Migrator) migrateCurrentTPaliases() (err error) {
return err
}
for _, ali := range alias {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPAliases, ali.TPid, map[string]string{"tag": ali.GetId()}); err != nil {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPAliases, ali.TPid, map[string]string{"direction": ali.Direction,
"tenant": ali.Tenant, "category": ali.Category, "account": ali.Account, "subject": ali.Subject, "context": ali.Context}); err != nil {
return err
}
}

View File

@@ -20,161 +20,158 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package migrator
// import (
// "log"
// "path"
// "reflect"
// "testing"
import (
"log"
"path"
"reflect"
"testing"
// "github.com/cgrates/cgrates/config"
// "github.com/cgrates/cgrates/engine"
// "github.com/cgrates/cgrates/utils"
// )
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
// var (
// tpAliPathIn string
// tpAliPathOut string
// tpAliCfgIn *config.CGRConfig
// tpAliCfgOut *config.CGRConfig
// tpAliMigrator *Migrator
// tpAliases []*utils.TPAliases
// )
var (
tpAliPathIn string
tpAliPathOut string
tpAliCfgIn *config.CGRConfig
tpAliCfgOut *config.CGRConfig
tpAliMigrator *Migrator
tpAliases []*utils.TPAliases
)
// var sTestsTpAliIT = []func(t *testing.T){
// testTpAliITConnect,
// testTpAliITFlush,
// testTpAliITPopulate,
// testTpAliITMove,
// testTpAliITCheckData,
// }
var sTestsTpAliIT = []func(t *testing.T){
testTpAliITConnect,
testTpAliITFlush,
testTpAliITPopulate,
testTpAliITMove,
testTpAliITCheckData,
}
// func TestTpAliMove(t *testing.T) {
// for _, stest := range sTestsTpAliIT {
// t.Run("TestTpAliMove", stest)
// }
// }
func TestTpAliMove(t *testing.T) {
for _, stest := range sTestsTpAliIT {
t.Run("TestTpAliMove", stest)
}
}
// func testTpAliITConnect(t *testing.T) {
// var err error
// tpAliPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
// tpAliCfgIn, err = config.NewCGRConfigFromFolder(tpAliPathIn)
// if err != nil {
// t.Fatal(err)
// }
// tpAliPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
// tpAliCfgOut, err = config.NewCGRConfigFromFolder(tpAliPathOut)
// if err != nil {
// t.Fatal(err)
// }
// storDBIn, err := engine.ConfigureStorDB(tpAliCfgIn.StorDBType, tpAliCfgIn.StorDBHost,
// tpAliCfgIn.StorDBPort, tpAliCfgIn.StorDBName,
// tpAliCfgIn.StorDBUser, tpAliCfgIn.StorDBPass,
// config.CgrConfig().StorDBMaxOpenConns,
// config.CgrConfig().StorDBMaxIdleConns,
// config.CgrConfig().StorDBConnMaxLifetime,
// config.CgrConfig().StorDBCDRSIndexes)
// if err != nil {
// log.Fatal(err)
// }
// storDBOut, err := engine.ConfigureStorDB(tpAliCfgOut.StorDBType,
// tpAliCfgOut.StorDBHost, tpAliCfgOut.StorDBPort, tpAliCfgOut.StorDBName,
// tpAliCfgOut.StorDBUser, tpAliCfgOut.StorDBPass,
// config.CgrConfig().StorDBMaxOpenConns,
// config.CgrConfig().StorDBMaxIdleConns,
// config.CgrConfig().StorDBConnMaxLifetime,
// config.CgrConfig().StorDBCDRSIndexes)
// if err != nil {
// log.Fatal(err)
// }
// tpAliMigrator, err = NewMigrator(nil, nil, tpAliCfgIn.DataDbType,
// tpAliCfgIn.DBDataEncoding, storDBIn, storDBOut, tpAliCfgIn.StorDBType, nil,
// tpAliCfgIn.DataDbType, tpAliCfgIn.DBDataEncoding, nil,
// tpAliCfgIn.StorDBType, false, false, false, false, false)
// if err != nil {
// log.Fatal(err)
// }
// }
func testTpAliITConnect(t *testing.T) {
var err error
tpAliPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
tpAliCfgIn, err = config.NewCGRConfigFromFolder(tpAliPathIn)
if err != nil {
t.Fatal(err)
}
tpAliPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
tpAliCfgOut, err = config.NewCGRConfigFromFolder(tpAliPathOut)
if err != nil {
t.Fatal(err)
}
storDBIn, err := NewMigratorStorDB(tpAliCfgIn.StorDBType, tpAliCfgIn.StorDBHost,
tpAliCfgIn.StorDBPort, tpAliCfgIn.StorDBName,
tpAliCfgIn.StorDBUser, tpAliCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
config.CgrConfig().StorDBMaxIdleConns,
config.CgrConfig().StorDBConnMaxLifetime,
config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
storDBOut, err := NewMigratorStorDB(tpAliCfgOut.StorDBType,
tpAliCfgOut.StorDBHost, tpAliCfgOut.StorDBPort, tpAliCfgOut.StorDBName,
tpAliCfgOut.StorDBUser, tpAliCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
config.CgrConfig().StorDBMaxIdleConns,
config.CgrConfig().StorDBConnMaxLifetime,
config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
tpAliMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
// func testTpAliITFlush(t *testing.T) {
// if err := tpAliMigrator.storDBIn.Flush(
// path.Join(tpAliCfgIn.DataFolderPath, "storage", tpAliCfgIn.StorDBType)); err != nil {
// t.Error(err)
// }
func testTpAliITFlush(t *testing.T) {
if err := tpAliMigrator.storDBIn.StorDB().Flush(
path.Join(tpAliCfgIn.DataFolderPath, "storage", tpAliCfgIn.StorDBType)); err != nil {
t.Error(err)
}
// if err := tpAliMigrator.storDBOut.Flush(
// path.Join(tpAliCfgOut.DataFolderPath, "storage", tpAliCfgOut.StorDBType)); err != nil {
// t.Error(err)
// }
// }
if err := tpAliMigrator.storDBOut.StorDB().Flush(
path.Join(tpAliCfgOut.DataFolderPath, "storage", tpAliCfgOut.StorDBType)); err != nil {
t.Error(err)
}
}
// func testTpAliITPopulate(t *testing.T) {
// tpAliases = []*utils.TPAliases{
// &utils.TPAliases{
// TPid: "testTPid1",
// Direction: "*out",
// Tenant: "cgrates.org",
// Category: "call",
// Account: "1006",
// Subject: "1006",
// Context: "*rating",
// Values: []*utils.TPAliasValue{
// &utils.TPAliasValue{
// DestinationId: "*any",
// Target: "Subject",
// Original: "1006",
// Alias: "1001",
// Weight: 2,
// },
// },
// },
// &utils.TPAliases{
// TPid: "testTPid2",
// Direction: "*out",
// Tenant: "cgrates.org",
// Category: "call",
// Account: "1001",
// Subject: "1001",
// Context: "*rating",
// Values: []*utils.TPAliasValue{
// &utils.TPAliasValue{
// DestinationId: "*any",
// Target: "Subject",
// Original: "1001",
// Alias: "1002",
// Weight: 2,
// },
// },
// },
// }
// if err := tpAliMigrator.storDBIn.SetTPAliases(tpAliases); err != nil {
// t.Error("Error when setting TpAliases ", err.Error())
// }
// currentVersion := engine.CurrentStorDBVersions()
// err := tpAliMigrator.storDBOut.SetVersions(currentVersion, false)
// if err != nil {
// t.Error("Error when setting version for TpAliases ", err.Error())
// }
// }
func testTpAliITPopulate(t *testing.T) {
tpAliases = []*utils.TPAliases{
&utils.TPAliases{
TPid: "testTPid1",
Direction: "*out",
Tenant: "cgrates.org",
Category: "call",
Account: "1006",
Subject: "1006",
Context: "*rating",
Values: []*utils.TPAliasValue{
&utils.TPAliasValue{
DestinationId: "*any",
Target: "Subject",
Original: "1006",
Alias: "1001",
Weight: 2,
},
},
},
&utils.TPAliases{
TPid: "testTPid2",
Direction: "*out",
Tenant: "cgrates.org",
Category: "call",
Account: "1001",
Subject: "1001",
Context: "*rating",
Values: []*utils.TPAliasValue{
&utils.TPAliasValue{
DestinationId: "*any",
Target: "Subject",
Original: "1001",
Alias: "1002",
Weight: 2,
},
},
},
}
if err := tpAliMigrator.storDBIn.StorDB().SetTPAliases(tpAliases); err != nil {
t.Error("Error when setting TpAliases ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpAliMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpAliases ", err.Error())
}
}
// func testTpAliITMove(t *testing.T) {
// err, _ := tpAliMigrator.Migrate([]string{utils.MetaTpAliases})
// if err != nil {
// t.Error("Error when migrating TpAliases ", err.Error())
// }
// }
func testTpAliITMove(t *testing.T) {
err, _ := tpAliMigrator.Migrate([]string{utils.MetaTpAliases})
if err != nil {
t.Error("Error when migrating TpAliases ", err.Error())
}
}
// func testTpAliITCheckData(t *testing.T) {
// filter := &utils.TPAliases{TPid: tpAliases[0].TPid}
// result, err := tpAliMigrator.storDBOut.GetTPAliases(filter)
// if err != nil {
// t.Error("Error when getting TpAliases ", err.Error())
// }
// if !reflect.DeepEqual(tpAliases[0], result[0]) {
// t.Errorf("Expecting: %+v, received: %+v",
// utils.ToJSON(tpAliases[0]), utils.ToJSON(result[0]))
// }
// result, err = tpAliMigrator.storDBIn.GetTPAliases(filter)
// if err != utils.ErrNotFound {
// t.Error(err)
// }
// }
func testTpAliITCheckData(t *testing.T) {
filter := &utils.TPAliases{TPid: tpAliases[0].TPid}
result, err := tpAliMigrator.storDBOut.StorDB().GetTPAliases(filter)
if err != nil {
t.Error("Error when getting TpAliases ", err.Error())
}
if !reflect.DeepEqual(tpAliases[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v",
utils.ToJSON(tpAliases[0]), utils.ToJSON(result[0]))
}
result, err = tpAliMigrator.storDBIn.StorDB().GetTPAliases(filter)
if err != utils.ErrNotFound {
t.Error(err)
}
}

View File

@@ -36,15 +36,20 @@ func (m *Migrator) migrateCurrentTPcdrstats() (err error) {
return err
}
for _, id := range ids {
dest, err := m.storDBIn.StorDB().GetTPCdrStats(tpid, id)
cdrStat, err := m.storDBIn.StorDB().GetTPCdrStats(tpid, id)
if err != nil {
return err
}
if dest != nil {
if cdrStat != nil {
if m.dryRun != true {
if err := m.storDBOut.StorDB().SetTPCdrStats(dest); err != nil {
if err := m.storDBOut.StorDB().SetTPCdrStats(cdrStat); err != nil {
return err
}
for _, cdrSt := range cdrStat {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPCdrStats, cdrSt.TPid, map[string]string{"tag": cdrSt.ID}); err != nil {
return err
}
}
m.stats[utils.TpCdrStats] += 1
}
}

View File

@@ -0,0 +1,211 @@
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"log"
"path"
"reflect"
"testing"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var (
tpCdrStatPathIn string
tpCdrStatPathOut string
tpCdrStatCfgIn *config.CGRConfig
tpCdrStatCfgOut *config.CGRConfig
tpCdrStatMigrator *Migrator
tpCdrStat []*utils.TPCdrStats
)
var sTestsTpCdrStatIT = []func(t *testing.T){
testTpCdrStatITConnect,
testTpCdrStatITFlush,
testTpCdrStatITPopulate,
testTpCdrStatITMove,
testTpCdrStatITCheckData,
}
func TestTpCdrStatMove(t *testing.T) {
for _, stest := range sTestsTpCdrStatIT {
t.Run("testTpCdrStatMove", stest)
}
}
func testTpCdrStatITConnect(t *testing.T) {
var err error
tpCdrStatPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
tpCdrStatCfgIn, err = config.NewCGRConfigFromFolder(tpCdrStatPathIn)
if err != nil {
t.Fatal(err)
}
tpCdrStatPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
tpCdrStatCfgOut, err = config.NewCGRConfigFromFolder(tpCdrStatPathOut)
if err != nil {
t.Fatal(err)
}
storDBIn, err := NewMigratorStorDB(tpCdrStatCfgIn.StorDBType, tpCdrStatCfgIn.StorDBHost,
tpCdrStatCfgIn.StorDBPort, tpCdrStatCfgIn.StorDBName,
tpCdrStatCfgIn.StorDBUser, tpCdrStatCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
config.CgrConfig().StorDBMaxIdleConns,
config.CgrConfig().StorDBConnMaxLifetime,
config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
storDBOut, err := NewMigratorStorDB(tpCdrStatCfgOut.StorDBType,
tpCdrStatCfgOut.StorDBHost, tpCdrStatCfgOut.StorDBPort, tpCdrStatCfgOut.StorDBName,
tpCdrStatCfgOut.StorDBUser, tpCdrStatCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
config.CgrConfig().StorDBMaxIdleConns,
config.CgrConfig().StorDBConnMaxLifetime,
config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
tpCdrStatMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpCdrStatITFlush(t *testing.T) {
if err := tpCdrStatMigrator.storDBIn.StorDB().Flush(
path.Join(tpCdrStatCfgIn.DataFolderPath, "storage", tpCdrStatCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpCdrStatMigrator.storDBOut.StorDB().Flush(
path.Join(tpCdrStatCfgOut.DataFolderPath, "storage", tpCdrStatCfgOut.StorDBType)); err != nil {
t.Error(err)
}
}
func testTpCdrStatITPopulate(t *testing.T) {
tpCdrStat = []*utils.TPCdrStats{
&utils.TPCdrStats{
TPid: "TPCdr",
ID: "ID",
CdrStats: []*utils.TPCdrStat{
&utils.TPCdrStat{
QueueLength: "10",
TimeWindow: "0",
SaveInterval: "10s",
Metrics: "ASR",
SetupInterval: "",
TORs: "",
CdrHosts: "",
CdrSources: "",
ReqTypes: "",
Directions: "",
Tenants: "cgrates.org",
Categories: "",
Accounts: "",
Subjects: "1001",
DestinationIds: "1003",
PddInterval: "",
UsageInterval: "",
Suppliers: "suppl1",
DisconnectCauses: "",
MediationRunIds: "*default",
RatedAccounts: "",
RatedSubjects: "",
CostInterval: "",
ActionTriggers: "CDRST1_WARN",
},
&utils.TPCdrStat{
QueueLength: "10",
TimeWindow: "0",
SaveInterval: "10s",
Metrics: "ACC",
SetupInterval: "",
TORs: "",
CdrHosts: "",
CdrSources: "",
ReqTypes: "",
Directions: "",
Tenants: "cgrates.org",
Categories: "",
Accounts: "",
Subjects: "1002",
DestinationIds: "1003",
PddInterval: "",
UsageInterval: "",
Suppliers: "suppl1",
DisconnectCauses: "",
MediationRunIds: "*default",
RatedAccounts: "",
RatedSubjects: "",
CostInterval: "",
ActionTriggers: "CDRST1_WARN",
},
},
},
}
if err := tpCdrStatMigrator.storDBIn.StorDB().SetTPCdrStats(tpCdrStat); err != nil {
t.Error("Error when setting TpCdrStats ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpCdrStatMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpCdrStats ", err.Error())
}
}
func testTpCdrStatITMove(t *testing.T) {
err, _ := tpCdrStatMigrator.Migrate([]string{utils.MetaTpCdrStats})
if err != nil {
t.Error("Error when migrating TpCdrStats ", err.Error())
}
}
func testTpCdrStatITCheckData(t *testing.T) {
// reverseRatingPlanBindings := []*utils.TPRatingPlanBinding{
// &utils.TPRatingPlanBinding{
// DestinationRatesId: "DR_FREESWITCH_USERS",
// TimingId: "ALWAYS",
// Weight: 10,
// },
// &utils.TPRatingPlanBinding{
// DestinationRatesId: "RateId",
// TimingId: "TimingID",
// Weight: 12,
// },
// }
result, err := tpCdrStatMigrator.storDBOut.StorDB().GetTPCdrStats(
tpCdrStat[0].TPid, tpCdrStat[0].ID)
if err != nil {
t.Error("Error when getting TpCdrStats ", err.Error())
}
if !reflect.DeepEqual(tpCdrStat[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v", tpCdrStat[0], result[0])
}
result, err = tpCdrStatMigrator.storDBIn.StorDB().GetTPCdrStats(
tpCdrStat[0].TPid, tpCdrStat[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}

View File

@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package migrator
/*
import (
"log"
"path"
@@ -68,7 +67,7 @@ func testTpDrChgITConnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storDBIn, err := engine.ConfigureStorDB(tpDrChgCfgIn.StorDBType, tpDrChgCfgIn.StorDBHost,
storDBIn, err := NewMigratorStorDB(tpDrChgCfgIn.StorDBType, tpDrChgCfgIn.StorDBHost,
tpDrChgCfgIn.StorDBPort, tpDrChgCfgIn.StorDBName,
tpDrChgCfgIn.StorDBUser, tpDrChgCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -78,7 +77,7 @@ func testTpDrChgITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
storDBOut, err := engine.ConfigureStorDB(tpDrChgCfgOut.StorDBType,
storDBOut, err := NewMigratorStorDB(tpDrChgCfgOut.StorDBType,
tpDrChgCfgOut.StorDBHost, tpDrChgCfgOut.StorDBPort, tpDrChgCfgOut.StorDBName,
tpDrChgCfgOut.StorDBUser, tpDrChgCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -88,22 +87,19 @@ func testTpDrChgITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
tpDrChgMigrator, err = NewMigrator(nil, nil, tpDrChgCfgIn.DataDbType,
tpDrChgCfgIn.DBDataEncoding, storDBIn, storDBOut, tpDrChgCfgIn.StorDBType, nil,
tpDrChgCfgIn.DataDbType, tpDrChgCfgIn.DBDataEncoding, nil,
tpDrChgCfgIn.StorDBType, false, false, false, false, false)
tpDrChgMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpDrChgITFlush(t *testing.T) {
if err := tpDrChgMigrator.storDBIn.Flush(
if err := tpDrChgMigrator.storDBIn.StorDB().Flush(
path.Join(tpDrChgCfgIn.DataFolderPath, "storage", tpDrChgCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpDrChgMigrator.storDBOut.Flush(
if err := tpDrChgMigrator.storDBOut.StorDB().Flush(
path.Join(tpDrChgCfgOut.DataFolderPath, "storage", tpDrChgCfgOut.StorDBType)); err != nil {
t.Error(err)
}
@@ -143,11 +139,11 @@ func testTpDrChgITPopulate(t *testing.T) {
},
},
}
if err := tpDrChgMigrator.storDBIn.SetTPDerivedChargers(tpDerivedChargers); err != nil {
if err := tpDrChgMigrator.storDBIn.StorDB().SetTPDerivedChargers(tpDerivedChargers); err != nil {
t.Error("Error when setting TpDerivedChargers ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
if err := tpDrChgMigrator.storDBOut.SetVersions(currentVersion, false); err != nil {
if err := tpDrChgMigrator.storDBOut.StorDB().SetVersions(currentVersion, false); err != nil {
t.Error("Error when setting version for TpDerivedChargers ", err.Error())
}
}
@@ -161,7 +157,7 @@ func testTpDrChgITMove(t *testing.T) {
func testTpDrChgITCheckData(t *testing.T) {
filter := &utils.TPDerivedChargers{TPid: tpDerivedChargers[0].TPid}
result, err := tpDrChgMigrator.storDBOut.GetTPDerivedChargers(filter)
result, err := tpDrChgMigrator.storDBOut.StorDB().GetTPDerivedChargers(filter)
if err != nil {
t.Error("Error when getting TpDerivedChargers ", err.Error())
}
@@ -169,9 +165,8 @@ func testTpDrChgITCheckData(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v",
utils.ToJSON(tpDerivedChargers[0]), utils.ToJSON(result[0]))
}
result, err = tpDrChgMigrator.storDBIn.GetTPDerivedChargers(filter)
result, err = tpDrChgMigrator.storDBIn.StorDB().GetTPDerivedChargers(filter)
if err != utils.ErrNotFound {
t.Error(err)
}
}
*/

View File

@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package migrator
/*
import (
"log"
"path"
@@ -67,7 +66,7 @@ func testTpDstRtITConnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storDBIn, err := engine.ConfigureStorDB(tpDstRtCfgIn.StorDBType, tpDstRtCfgIn.StorDBHost,
storDBIn, err := NewMigratorStorDB(tpDstRtCfgIn.StorDBType, tpDstRtCfgIn.StorDBHost,
tpDstRtCfgIn.StorDBPort, tpDstRtCfgIn.StorDBName,
tpDstRtCfgIn.StorDBUser, tpDstRtCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -77,7 +76,7 @@ func testTpDstRtITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
storDBOut, err := engine.ConfigureStorDB(tpDstRtCfgOut.StorDBType,
storDBOut, err := NewMigratorStorDB(tpDstRtCfgOut.StorDBType,
tpDstRtCfgOut.StorDBHost, tpDstRtCfgOut.StorDBPort, tpDstRtCfgOut.StorDBName,
tpDstRtCfgOut.StorDBUser, tpDstRtCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -87,22 +86,19 @@ func testTpDstRtITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
tpDstRtMigrator, err = NewMigrator(nil, nil, tpDstRtCfgIn.DataDbType,
tpDstRtCfgIn.DBDataEncoding, storDBIn, storDBOut, tpDstRtCfgIn.StorDBType, nil,
tpDstRtCfgIn.DataDbType, tpDstRtCfgIn.DBDataEncoding, nil,
tpDstRtCfgIn.StorDBType, false, false, false, false, false)
tpDstRtMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpDstRtITFlush(t *testing.T) {
if err := tpDstRtMigrator.storDBIn.Flush(
if err := tpDstRtMigrator.storDBIn.StorDB().Flush(
path.Join(tpDstRtCfgIn.DataFolderPath, "storage", tpDstRtCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpDstRtMigrator.storDBOut.Flush(
if err := tpDstRtMigrator.storDBOut.StorDB().Flush(
path.Join(tpDstRtCfgOut.DataFolderPath, "storage", tpDstRtCfgOut.StorDBType)); err != nil {
t.Error(err)
}
@@ -122,11 +118,11 @@ func testTpDstRtITPopulate(t *testing.T) {
},
},
}
if err := tpDstRtMigrator.storDBIn.SetTPDestinationRates(tpDestinationRate); err != nil {
if err := tpDstRtMigrator.storDBIn.StorDB().SetTPDestinationRates(tpDestinationRate); err != nil {
t.Error("Error when setting TpDestinationRate ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpDstRtMigrator.storDBOut.SetVersions(currentVersion, false)
err := tpDstRtMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpDestinationRate ", err.Error())
}
@@ -140,7 +136,7 @@ func testTpDstRtITMove(t *testing.T) {
}
func testTpDstRtITCheckData(t *testing.T) {
result, err := tpDstRtMigrator.storDBOut.GetTPDestinationRates(
result, err := tpDstRtMigrator.storDBOut.StorDB().GetTPDestinationRates(
tpDestinationRate[0].TPid, tpDestinationRate[0].ID, nil)
if err != nil {
t.Error("Error when getting TpDestinationRate ", err.Error())
@@ -149,10 +145,9 @@ func testTpDstRtITCheckData(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v",
utils.ToJSON(tpDestinationRate[0]), utils.ToJSON(result[0]))
}
result, err = tpDstRtMigrator.storDBIn.GetTPDestinationRates(
result, err = tpDstRtMigrator.storDBIn.StorDB().GetTPDestinationRates(
tpDestinationRate[0].TPid, tpDestinationRate[0].ID, nil)
if err != utils.ErrNotFound {
t.Error(err)
}
}
*/

View File

@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package migrator
/*
import (
"log"
"path"
@@ -67,7 +66,7 @@ func testTpDstITConnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storDBIn, err := engine.ConfigureStorDB(tpDstCfgIn.StorDBType, tpDstCfgIn.StorDBHost,
storDBIn, err := NewMigratorStorDB(tpDstCfgIn.StorDBType, tpDstCfgIn.StorDBHost,
tpDstCfgIn.StorDBPort, tpDstCfgIn.StorDBName,
tpDstCfgIn.StorDBUser, tpDstCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -77,7 +76,7 @@ func testTpDstITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
storDBOut, err := engine.ConfigureStorDB(tpDstCfgOut.StorDBType,
storDBOut, err := NewMigratorStorDB(tpDstCfgOut.StorDBType,
tpDstCfgOut.StorDBHost, tpDstCfgOut.StorDBPort, tpDstCfgOut.StorDBName,
tpDstCfgOut.StorDBUser, tpDstCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -87,22 +86,19 @@ func testTpDstITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
tpDstMigrator, err = NewMigrator(nil, nil, tpDstCfgIn.DataDbType,
tpDstCfgIn.DBDataEncoding, storDBIn, storDBOut, tpDstCfgIn.StorDBType, nil,
tpDstCfgIn.DataDbType, tpDstCfgIn.DBDataEncoding, nil,
tpDstCfgIn.StorDBType, false, false, false, false, false)
tpDstMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpDstITFlush(t *testing.T) {
if err := tpDstMigrator.storDBIn.Flush(
if err := tpDstMigrator.storDBIn.StorDB().Flush(
path.Join(tpDstCfgIn.DataFolderPath, "storage", tpDstCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpDstMigrator.storDBOut.Flush(
if err := tpDstMigrator.storDBOut.StorDB().Flush(
path.Join(tpDstCfgOut.DataFolderPath, "storage", tpDstCfgOut.StorDBType)); err != nil {
t.Error(err)
}
@@ -116,11 +112,11 @@ func testTpDstITPopulate(t *testing.T) {
Prefixes: []string{"+49", "+4915"},
},
}
if err := tpDstMigrator.storDBIn.SetTPDestinations(tpDestination); err != nil {
if err := tpDstMigrator.storDBIn.StorDB().SetTPDestinations(tpDestination); err != nil {
t.Error("Error when setting TpDestination ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpDstMigrator.storDBOut.SetVersions(currentVersion, false)
err := tpDstMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpDestination ", err.Error())
}
@@ -134,7 +130,7 @@ func testTpDstITMove(t *testing.T) {
}
func testTpDstITCheckData(t *testing.T) {
result, err := tpDstMigrator.storDBOut.GetTPDestinations(
result, err := tpDstMigrator.storDBOut.StorDB().GetTPDestinations(
tpDestination[0].TPid, tpDestination[0].ID)
if err != nil {
t.Error("Error when getting TpDestination ", err.Error())
@@ -143,10 +139,9 @@ func testTpDstITCheckData(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v",
utils.ToJSON(tpDestination[0]), utils.ToJSON(result[0]))
}
result, err = tpDstMigrator.storDBIn.GetTPDestinations(
result, err = tpDstMigrator.storDBIn.StorDB().GetTPDestinations(
tpDestination[0].TPid, tpDestination[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}
*/

View File

@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package migrator
/*
import (
"log"
"path"
@@ -67,7 +66,7 @@ func testTpFltrITConnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storDBIn, err := engine.ConfigureStorDB(tpFltrCfgIn.StorDBType, tpFltrCfgIn.StorDBHost,
storDBIn, err := NewMigratorStorDB(tpFltrCfgIn.StorDBType, tpFltrCfgIn.StorDBHost,
tpFltrCfgIn.StorDBPort, tpFltrCfgIn.StorDBName,
tpFltrCfgIn.StorDBUser, tpFltrCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -77,7 +76,7 @@ func testTpFltrITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
storDBOut, err := engine.ConfigureStorDB(tpFltrCfgOut.StorDBType,
storDBOut, err := NewMigratorStorDB(tpFltrCfgOut.StorDBType,
tpFltrCfgOut.StorDBHost, tpFltrCfgOut.StorDBPort, tpFltrCfgOut.StorDBName,
tpFltrCfgOut.StorDBUser, tpFltrCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -87,22 +86,19 @@ func testTpFltrITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
tpFltrMigrator, err = NewMigrator(nil, nil, tpFltrCfgIn.DataDbType,
tpFltrCfgIn.DBDataEncoding, storDBIn, storDBOut, tpFltrCfgIn.StorDBType, nil,
tpFltrCfgIn.DataDbType, tpFltrCfgIn.DBDataEncoding, nil,
tpFltrCfgIn.StorDBType, false, false, false, false, false)
tpFltrMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpFltrITFlush(t *testing.T) {
if err := tpFltrMigrator.storDBIn.Flush(
if err := tpFltrMigrator.storDBIn.StorDB().Flush(
path.Join(tpFltrCfgIn.DataFolderPath, "storage", tpFltrCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpFltrMigrator.storDBOut.Flush(
if err := tpFltrMigrator.storDBOut.StorDB().Flush(
path.Join(tpFltrCfgOut.DataFolderPath, "storage", tpFltrCfgOut.StorDBType)); err != nil {
t.Error(err)
}
@@ -127,11 +123,11 @@ func testTpFltrITPopulate(t *testing.T) {
},
},
}
if err := tpFltrMigrator.storDBIn.SetTPFilters(tpFilters); err != nil {
if err := tpFltrMigrator.storDBIn.StorDB().SetTPFilters(tpFilters); err != nil {
t.Error("Error when setting TpFilter ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpFltrMigrator.storDBOut.SetVersions(currentVersion, false)
err := tpFltrMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpFilter ", err.Error())
}
@@ -145,7 +141,7 @@ func testTpFltrITMove(t *testing.T) {
}
func testTpFltrITCheckData(t *testing.T) {
result, err := tpFltrMigrator.storDBOut.GetTPFilters(
result, err := tpFltrMigrator.storDBOut.StorDB().GetTPFilters(
tpFilters[0].TPid, tpFilters[0].ID)
if err != nil {
t.Error("Error when getting TpFilter ", err.Error())
@@ -153,10 +149,9 @@ func testTpFltrITCheckData(t *testing.T) {
if !reflect.DeepEqual(tpFilters[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v", tpFilters[0], result[0])
}
result, err = tpFltrMigrator.storDBIn.GetTPFilters(
result, err = tpFltrMigrator.storDBIn.StorDB().GetTPFilters(
tpFilters[0].TPid, tpFilters[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}
*/

View File

@@ -37,15 +37,20 @@ func (m *Migrator) migrateCurrentTPrates() (err error) {
}
for _, id := range ids {
dest, err := m.storDBIn.StorDB().GetTPRates(tpid, id)
rates, err := m.storDBIn.StorDB().GetTPRates(tpid, id)
if err != nil {
return err
}
if dest != nil {
if rates != nil {
if m.dryRun != true {
if err := m.storDBOut.StorDB().SetTPRates(dest); err != nil {
if err := m.storDBOut.StorDB().SetTPRates(rates); err != nil {
return err
}
for _, rate := range rates {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPRates, rate.TPid, map[string]string{"tag": rate.ID}); err != nil {
return err
}
}
m.stats[utils.TpRates] += 1
}
}

View File

@@ -0,0 +1,167 @@
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"log"
"path"
"reflect"
"testing"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var (
tpRatesPathIn string
tpRatesPathOut string
tpRatesCfgIn *config.CGRConfig
tpRatesCfgOut *config.CGRConfig
tpRatesMigrator *Migrator
tpRates []*utils.TPRate
)
var sTestsTpRatesIT = []func(t *testing.T){
testTpRatesITConnect,
testTpRatesITFlush,
testTpRatesITPopulate,
testTpRatesITMove,
testTpRatesITCheckData,
}
func TestTpRatesMove(t *testing.T) {
for _, stest := range sTestsTpRatesIT {
t.Run("testTpRatesMove", stest)
}
}
func testTpRatesITConnect(t *testing.T) {
var err error
tpRatesPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
tpRatesCfgIn, err = config.NewCGRConfigFromFolder(tpRatesPathIn)
if err != nil {
t.Fatal(err)
}
tpRatesPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
tpRatesCfgOut, err = config.NewCGRConfigFromFolder(tpRatesPathOut)
if err != nil {
t.Fatal(err)
}
storDBIn, err := NewMigratorStorDB(tpRatesCfgIn.StorDBType, tpRatesCfgIn.StorDBHost,
tpRatesCfgIn.StorDBPort, tpRatesCfgIn.StorDBName,
tpRatesCfgIn.StorDBUser, tpRatesCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
config.CgrConfig().StorDBMaxIdleConns,
config.CgrConfig().StorDBConnMaxLifetime,
config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
storDBOut, err := NewMigratorStorDB(tpRatesCfgOut.StorDBType,
tpRatesCfgOut.StorDBHost, tpRatesCfgOut.StorDBPort, tpRatesCfgOut.StorDBName,
tpRatesCfgOut.StorDBUser, tpRatesCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
config.CgrConfig().StorDBMaxIdleConns,
config.CgrConfig().StorDBConnMaxLifetime,
config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
tpRatesMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpRatesITFlush(t *testing.T) {
if err := tpRatesMigrator.storDBIn.StorDB().Flush(
path.Join(tpRatesCfgIn.DataFolderPath, "storage", tpRatesCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpRatesMigrator.storDBOut.StorDB().Flush(
path.Join(tpRatesCfgOut.DataFolderPath, "storage", tpRatesCfgOut.StorDBType)); err != nil {
t.Error(err)
}
}
func testTpRatesITPopulate(t *testing.T) {
tpRates = []*utils.TPRate{
&utils.TPRate{
TPid: "TPidTpRate",
ID: "RT_FS_USERS",
RateSlots: []*utils.RateSlot{
&utils.RateSlot{
ConnectFee: 12,
Rate: 3,
RateUnit: "6s",
RateIncrement: "6s",
GroupIntervalStart: "0s",
},
&utils.RateSlot{
ConnectFee: 12,
Rate: 3,
RateUnit: "4s",
RateIncrement: "6s",
GroupIntervalStart: "1s",
},
},
},
}
if err := tpRatesMigrator.storDBIn.StorDB().SetTPRates(tpRates); err != nil {
t.Error("Error when setting TpRate ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpRatesMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpRate ", err.Error())
}
}
func testTpRatesITMove(t *testing.T) {
err, _ := tpRatesMigrator.Migrate([]string{utils.MetaTpRates})
if err != nil {
t.Error("Error when migrating TpRate ", err.Error())
}
}
func testTpRatesITCheckData(t *testing.T) {
result, err := tpRatesMigrator.storDBOut.StorDB().GetTPRates(
tpRates[0].TPid, tpRates[0].ID)
if err != nil {
t.Error("Error when getting TpRate ", err.Error())
}
if err := tpRates[0].RateSlots[0].SetDurations(); err != nil {
t.Error(err)
}
if err := tpRates[0].RateSlots[1].SetDurations(); err != nil {
t.Error(err)
}
if !reflect.DeepEqual(tpRates[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v", tpRates[0], result[0])
}
result, err = tpRatesMigrator.storDBIn.StorDB().GetTPRates(
tpRates[0].TPid, tpRates[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}

View File

@@ -37,15 +37,20 @@ func (m *Migrator) migrateCurrentTPratingplans() (err error) {
}
if len(ids) != 0 {
for _, id := range ids {
rps, err := m.storDBIn.StorDB().GetTPRatingPlans(tpid, id, nil)
ratingPlan, err := m.storDBIn.StorDB().GetTPRatingPlans(tpid, id, nil)
if err != nil {
return err
}
if rps != nil {
if ratingPlan != nil {
if m.dryRun != true {
if err := m.storDBOut.StorDB().SetTPRatingPlans(rps); err != nil {
if err := m.storDBOut.StorDB().SetTPRatingPlans(ratingPlan); err != nil {
return err
}
for _, ratPln := range ratingPlan {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPRatingPlans, ratPln.TPid, map[string]string{"tag": ratPln.ID}); err != nil {
return err
}
}
m.stats[utils.TpRatingPlans] += 1
}
}

View File

@@ -0,0 +1,174 @@
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"log"
"path"
"reflect"
"testing"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var (
tpRatPlnPathIn string
tpRatPlnPathOut string
tpRatPlnCfgIn *config.CGRConfig
tpRatPlnCfgOut *config.CGRConfig
tpRatPlnMigrator *Migrator
tpRatingPlan []*utils.TPRatingPlan
)
var sTestsTpRatPlnIT = []func(t *testing.T){
testTpRatPlnITConnect,
testTpRatPlnITFlush,
testTpRatPlnITPopulate,
testTpRatPlnITMove,
testTpRatPlnITCheckData,
}
func TestTpRatPlnMove(t *testing.T) {
for _, stest := range sTestsTpRatPlnIT {
t.Run("testTpRatPlnMove", stest)
}
}
func testTpRatPlnITConnect(t *testing.T) {
var err error
tpRatPlnPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
tpRatPlnCfgIn, err = config.NewCGRConfigFromFolder(tpRatPlnPathIn)
if err != nil {
t.Fatal(err)
}
tpRatPlnPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
tpRatPlnCfgOut, err = config.NewCGRConfigFromFolder(tpRatPlnPathOut)
if err != nil {
t.Fatal(err)
}
storDBIn, err := NewMigratorStorDB(tpRatPlnCfgIn.StorDBType, tpRatPlnCfgIn.StorDBHost,
tpRatPlnCfgIn.StorDBPort, tpRatPlnCfgIn.StorDBName,
tpRatPlnCfgIn.StorDBUser, tpRatPlnCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
config.CgrConfig().StorDBMaxIdleConns,
config.CgrConfig().StorDBConnMaxLifetime,
config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
storDBOut, err := NewMigratorStorDB(tpRatPlnCfgOut.StorDBType,
tpRatPlnCfgOut.StorDBHost, tpRatPlnCfgOut.StorDBPort, tpRatPlnCfgOut.StorDBName,
tpRatPlnCfgOut.StorDBUser, tpRatPlnCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
config.CgrConfig().StorDBMaxIdleConns,
config.CgrConfig().StorDBConnMaxLifetime,
config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
tpRatPlnMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpRatPlnITFlush(t *testing.T) {
if err := tpRatPlnMigrator.storDBIn.StorDB().Flush(
path.Join(tpRatPlnCfgIn.DataFolderPath, "storage", tpRatPlnCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpRatPlnMigrator.storDBOut.StorDB().Flush(
path.Join(tpRatPlnCfgOut.DataFolderPath, "storage", tpRatPlnCfgOut.StorDBType)); err != nil {
t.Error(err)
}
}
func testTpRatPlnITPopulate(t *testing.T) {
tpRatingPlan = []*utils.TPRatingPlan{
&utils.TPRatingPlan{
TPid: "TPRP1",
ID: "IDPlan2",
RatingPlanBindings: []*utils.TPRatingPlanBinding{
&utils.TPRatingPlanBinding{
DestinationRatesId: "RateId",
TimingId: "TimingID",
Weight: 12,
},
&utils.TPRatingPlanBinding{
DestinationRatesId: "DR_FREESWITCH_USERS",
TimingId: "ALWAYS",
Weight: 10,
},
},
},
}
if err := tpRatPlnMigrator.storDBIn.StorDB().SetTPRatingPlans(tpRatingPlan); err != nil {
t.Error("Error when setting TpRatingPlans ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpRatPlnMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpRatingPlans ", err.Error())
}
}
func testTpRatPlnITMove(t *testing.T) {
err, _ := tpRatPlnMigrator.Migrate([]string{utils.MetaTpRatingPlans})
if err != nil {
t.Error("Error when migrating TpRatingPlans ", err.Error())
}
}
func testTpRatPlnITCheckData(t *testing.T) {
reverseRatingPlanBindings := []*utils.TPRatingPlanBinding{
&utils.TPRatingPlanBinding{
DestinationRatesId: "DR_FREESWITCH_USERS",
TimingId: "ALWAYS",
Weight: 10,
},
&utils.TPRatingPlanBinding{
DestinationRatesId: "RateId",
TimingId: "TimingID",
Weight: 12,
},
}
result, err := tpRatPlnMigrator.storDBOut.StorDB().GetTPRatingPlans(
tpRatingPlan[0].TPid, tpRatingPlan[0].ID, nil)
if err != nil {
t.Error("Error when getting TpRatingPlans ", err.Error())
}
if !reflect.DeepEqual(tpRatingPlan[0].TPid, result[0].TPid) {
t.Errorf("Expecting: %+v, received: %+v", tpRatingPlan[0].TPid, result[0].TPid)
} else if !reflect.DeepEqual(tpRatingPlan[0].ID, result[0].ID) {
t.Errorf("Expecting: %+v, received: %+v", tpRatingPlan[0].ID, result[0].ID)
} else if !reflect.DeepEqual(tpRatingPlan[0].RatingPlanBindings, result[0].RatingPlanBindings) &&
!reflect.DeepEqual(result[0].RatingPlanBindings, reverseRatingPlanBindings) {
t.Errorf("Expecting: %+v, received: %+v", reverseRatingPlanBindings, result[0].RatingPlanBindings)
}
result, err = tpRatPlnMigrator.storDBIn.StorDB().GetTPRatingPlans(
tpRatingPlan[0].TPid, tpRatingPlan[0].ID, nil)
if err != utils.ErrNotFound {
t.Error(err)
}
}

View File

@@ -33,15 +33,21 @@ func (m *Migrator) migrateCurrentTPratingprofiles() (err error) {
}
for _, tpid := range tpids {
dest, err := m.storDBIn.StorDB().GetTPRatingProfiles(&utils.TPRatingProfile{TPid: tpid})
ratingProfile, err := m.storDBIn.StorDB().GetTPRatingProfiles(&utils.TPRatingProfile{TPid: tpid})
if err != nil {
return err
}
if dest != nil {
if ratingProfile != nil {
if m.dryRun != true {
if err := m.storDBOut.StorDB().SetTPRatingProfiles(dest); err != nil {
if err := m.storDBOut.StorDB().SetTPRatingProfiles(ratingProfile); err != nil {
return err
}
for _, ratPrf := range ratingProfile {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPRateProfiles, ratPrf.TPid, map[string]string{"loadid": ratPrf.LoadId,
"direction": ratPrf.Direction, "tenant": ratPrf.Tenant, "category": ratPrf.Category, "subject": ratPrf.Subject}); err != nil {
return err
}
}
m.stats[utils.TpRatingProfiles] += 1
}
}

View File

@@ -0,0 +1,162 @@
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"log"
"path"
"reflect"
"testing"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var (
tpRatPrfPathIn string
tpRatPrfPathOut string
tpRatPrfCfgIn *config.CGRConfig
tpRatPrfCfgOut *config.CGRConfig
tpRatPrfMigrator *Migrator
tpRatingProfile []*utils.TPRatingProfile
)
var sTestsTpRatPrfIT = []func(t *testing.T){
testTpRatPrfITConnect,
testTpRatPrfITFlush,
testTpRatPrfITPopulate,
testTpRatPrfITMove,
testTpRatPrfITCheckData,
}
func TestTpRatPrfMove(t *testing.T) {
for _, stest := range sTestsTpRatPrfIT {
t.Run("testTpRatPrfMove", stest)
}
}
func testTpRatPrfITConnect(t *testing.T) {
var err error
tpRatPrfPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
tpRatPrfCfgIn, err = config.NewCGRConfigFromFolder(tpRatPrfPathIn)
if err != nil {
t.Fatal(err)
}
tpRatPrfPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
tpRatPrfCfgOut, err = config.NewCGRConfigFromFolder(tpRatPrfPathOut)
if err != nil {
t.Fatal(err)
}
storDBIn, err := NewMigratorStorDB(tpRatPrfCfgIn.StorDBType, tpRatPrfCfgIn.StorDBHost,
tpRatPrfCfgIn.StorDBPort, tpRatPrfCfgIn.StorDBName,
tpRatPrfCfgIn.StorDBUser, tpRatPrfCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
config.CgrConfig().StorDBMaxIdleConns,
config.CgrConfig().StorDBConnMaxLifetime,
config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
storDBOut, err := NewMigratorStorDB(tpRatPrfCfgOut.StorDBType,
tpRatPrfCfgOut.StorDBHost, tpRatPrfCfgOut.StorDBPort, tpRatPrfCfgOut.StorDBName,
tpRatPrfCfgOut.StorDBUser, tpRatPrfCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
config.CgrConfig().StorDBMaxIdleConns,
config.CgrConfig().StorDBConnMaxLifetime,
config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
tpRatPrfMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpRatPrfITFlush(t *testing.T) {
if err := tpRatPrfMigrator.storDBIn.StorDB().Flush(
path.Join(tpRatPrfCfgIn.DataFolderPath, "storage", tpRatPrfCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpRatPrfMigrator.storDBOut.StorDB().Flush(
path.Join(tpRatPrfCfgOut.DataFolderPath, "storage", tpRatPrfCfgOut.StorDBType)); err != nil {
t.Error(err)
}
}
func testTpRatPrfITPopulate(t *testing.T) {
tpRatingProfile = []*utils.TPRatingProfile{
&utils.TPRatingProfile{
TPid: "TPRProf1",
LoadId: "RPrf",
Direction: "*out",
Tenant: "Tenant1",
Category: "Category",
Subject: "Subject",
RatingPlanActivations: []*utils.TPRatingActivation{
&utils.TPRatingActivation{
ActivationTime: "2014-07-29T15:00:00Z",
RatingPlanId: "PlanOne",
FallbackSubjects: "FallBack",
CdrStatQueueIds: "RandomId",
},
&utils.TPRatingActivation{
ActivationTime: "2015-07-29T10:00:00Z",
RatingPlanId: "PlanTwo",
FallbackSubjects: "FallOut",
CdrStatQueueIds: "RandomIdTwo",
},
},
},
}
if err := tpRatPrfMigrator.storDBIn.StorDB().SetTPRatingProfiles(tpRatingProfile); err != nil {
t.Error("Error when setting TpRatingProfiles ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpRatPrfMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpRatingProfiles ", err.Error())
}
}
func testTpRatPrfITMove(t *testing.T) {
err, _ := tpRatPrfMigrator.Migrate([]string{utils.MetaTpRatingProfiles})
if err != nil {
t.Error("Error when migrating TpRatingProfiles ", err.Error())
}
}
func testTpRatPrfITCheckData(t *testing.T) {
filter := &utils.TPRatingProfile{TPid: tpRatingProfile[0].TPid, LoadId: tpRatingProfile[0].LoadId}
result, err := tpRatPrfMigrator.storDBOut.StorDB().GetTPRatingProfiles(filter)
if err != nil {
t.Error("Error when getting TpRatingProfiles ", err.Error())
}
if !reflect.DeepEqual(tpRatingProfile[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v", tpRatingProfile[0], result[0])
}
result, err = tpRatPrfMigrator.storDBIn.StorDB().GetTPRatingProfiles(filter)
if err != utils.ErrNotFound {
t.Error(err)
}
}

View File

@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package migrator
/*
import (
"log"
"path"
@@ -67,7 +66,7 @@ func testTpResITConnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storDBIn, err := engine.ConfigureStorDB(tpResCfgIn.StorDBType, tpResCfgIn.StorDBHost,
storDBIn, err := NewMigratorStorDB(tpResCfgIn.StorDBType, tpResCfgIn.StorDBHost,
tpResCfgIn.StorDBPort, tpResCfgIn.StorDBName,
tpResCfgIn.StorDBUser, tpResCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -77,7 +76,7 @@ func testTpResITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
storDBOut, err := engine.ConfigureStorDB(tpResCfgOut.StorDBType,
storDBOut, err := NewMigratorStorDB(tpResCfgOut.StorDBType,
tpResCfgOut.StorDBHost, tpResCfgOut.StorDBPort, tpResCfgOut.StorDBName,
tpResCfgOut.StorDBUser, tpResCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -87,22 +86,20 @@ func testTpResITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
tpResMigrator, err = NewMigrator(nil, nil, tpResCfgIn.DataDbType,
tpResCfgIn.DBDataEncoding, storDBIn, storDBOut, tpResCfgIn.StorDBType, nil,
tpResCfgIn.DataDbType, tpResCfgIn.DBDataEncoding, nil,
tpResCfgIn.StorDBType, false, false, false, false, false)
tpResMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut,
false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpResITFlush(t *testing.T) {
if err := tpResMigrator.storDBIn.Flush(
if err := tpResMigrator.storDBIn.StorDB().Flush(
path.Join(tpResCfgIn.DataFolderPath, "storage", tpResCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpResMigrator.storDBOut.Flush(
if err := tpResMigrator.storDBOut.StorDB().Flush(
path.Join(tpResCfgOut.DataFolderPath, "storage", tpResCfgOut.StorDBType)); err != nil {
t.Error(err)
}
@@ -128,36 +125,35 @@ func testTpResITPopulate(t *testing.T) {
ThresholdIDs: []string{"ValOne", "ValTwo"},
},
}
if err := tpResMigrator.storDBIn.SetTPResources(tpResources); err != nil {
t.Error("Error when setting TpFilter ", err.Error())
if err := tpResMigrator.storDBIn.StorDB().SetTPResources(tpResources); err != nil {
t.Error("Error when setting TpResources ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpResMigrator.storDBOut.SetVersions(currentVersion, false)
err := tpResMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpFilter ", err.Error())
t.Error("Error when setting version for TpResources ", err.Error())
}
}
func testTpResITMove(t *testing.T) {
err, _ := tpResMigrator.Migrate([]string{utils.MetaTpResources})
if err != nil {
t.Error("Error when migrating TpFilter ", err.Error())
t.Error("Error when migrating TpResources ", err.Error())
}
}
func testTpResITCheckData(t *testing.T) {
result, err := tpResMigrator.storDBOut.GetTPResources(
result, err := tpResMigrator.storDBOut.StorDB().GetTPResources(
tpResources[0].TPid, tpResources[0].ID)
if err != nil {
t.Error("Error when getting TpFilter ", err.Error())
t.Error("Error when getting TpResources ", err.Error())
}
if !reflect.DeepEqual(tpResources[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v", tpResources[0], result[0])
}
result, err = tpResMigrator.storDBIn.GetTPResources(
result, err = tpResMigrator.storDBIn.StorDB().GetTPResources(
tpResources[0].TPid, tpResources[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}
*/

View File

@@ -38,15 +38,21 @@ func (m *Migrator) migrateCurrentTPsharedgroups() (err error) {
}
for _, id := range ids {
dest, err := m.storDBIn.StorDB().GetTPSharedGroups(tpid, id)
sharedGroup, err := m.storDBIn.StorDB().GetTPSharedGroups(tpid, id)
if err != nil {
return err
}
if dest != nil {
if sharedGroup != nil {
if m.dryRun != true {
if err := m.storDBOut.StorDB().SetTPSharedGroups(dest); err != nil {
if err := m.storDBOut.StorDB().SetTPSharedGroups(sharedGroup); err != nil {
return err
}
for _, shrGr := range sharedGroup {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPSharedGroups, shrGr.TPid,
map[string]string{"id": shrGr.ID}); err != nil {
return err
}
}
m.stats[utils.TpSharedGroups] += 1
}
}

View File

@@ -0,0 +1,158 @@
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"log"
"path"
"reflect"
"testing"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var (
tpShrGrPathIn string
tpShrGrPathOut string
tpShrGrCfgIn *config.CGRConfig
tpShrGrCfgOut *config.CGRConfig
tpShrGrMigrator *Migrator
tpSharedGroups []*utils.TPSharedGroups
)
var sTestsTpShrGrIT = []func(t *testing.T){
testTpShrGrITConnect,
testTpShrGrITFlush,
testTpShrGrITPopulate,
testTpShrGrITMove,
testTpShrGrITCheckData,
}
func TestTpShrGrMove(t *testing.T) {
for _, stest := range sTestsTpShrGrIT {
t.Run("testTpShrGrMove", stest)
}
}
func testTpShrGrITConnect(t *testing.T) {
var err error
tpShrGrPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
tpShrGrCfgIn, err = config.NewCGRConfigFromFolder(tpShrGrPathIn)
if err != nil {
t.Fatal(err)
}
tpShrGrPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
tpShrGrCfgOut, err = config.NewCGRConfigFromFolder(tpShrGrPathOut)
if err != nil {
t.Fatal(err)
}
storDBIn, err := NewMigratorStorDB(tpShrGrCfgIn.StorDBType, tpShrGrCfgIn.StorDBHost,
tpShrGrCfgIn.StorDBPort, tpShrGrCfgIn.StorDBName,
tpShrGrCfgIn.StorDBUser, tpShrGrCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
config.CgrConfig().StorDBMaxIdleConns,
config.CgrConfig().StorDBConnMaxLifetime,
config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
storDBOut, err := NewMigratorStorDB(tpShrGrCfgOut.StorDBType,
tpShrGrCfgOut.StorDBHost, tpShrGrCfgOut.StorDBPort, tpShrGrCfgOut.StorDBName,
tpShrGrCfgOut.StorDBUser, tpShrGrCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
config.CgrConfig().StorDBMaxIdleConns,
config.CgrConfig().StorDBConnMaxLifetime,
config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
tpShrGrMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpShrGrITFlush(t *testing.T) {
if err := tpShrGrMigrator.storDBIn.StorDB().Flush(
path.Join(tpShrGrCfgIn.DataFolderPath, "storage", tpShrGrCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpShrGrMigrator.storDBOut.StorDB().Flush(
path.Join(tpShrGrCfgOut.DataFolderPath, "storage", tpShrGrCfgOut.StorDBType)); err != nil {
t.Error(err)
}
}
func testTpShrGrITPopulate(t *testing.T) {
tpSharedGroups = []*utils.TPSharedGroups{
&utils.TPSharedGroups{
TPid: "TPS1",
ID: "Group1",
SharedGroups: []*utils.TPSharedGroup{
&utils.TPSharedGroup{
Account: "AccOne",
Strategy: "StrategyOne",
RatingSubject: "SubOne",
},
&utils.TPSharedGroup{
Account: "AccTow",
Strategy: "StrategyTwo",
RatingSubject: "SubTwo",
},
},
},
}
if err := tpShrGrMigrator.storDBIn.StorDB().SetTPSharedGroups(tpSharedGroups); err != nil {
t.Error("Error when setting TpSharedGroups ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpShrGrMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpSharedGroups ", err.Error())
}
}
func testTpShrGrITMove(t *testing.T) {
err, _ := tpShrGrMigrator.Migrate([]string{utils.MetaTpSharedGroups})
if err != nil {
t.Error("Error when migrating TpSharedGroups ", err.Error())
}
}
func testTpShrGrITCheckData(t *testing.T) {
//filter := &utils.TPSharedGroups{TPid: tpSharedGroups[0].TPid}
result, err := tpShrGrMigrator.storDBOut.StorDB().GetTPSharedGroups(
tpSharedGroups[0].TPid, tpSharedGroups[0].ID)
if err != nil {
t.Error("Error when getting TpSharedGroups ", err.Error())
}
if !reflect.DeepEqual(tpSharedGroups[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v", tpSharedGroups[0], result[0])
}
result, err = tpShrGrMigrator.storDBIn.StorDB().GetTPSharedGroups(
tpSharedGroups[0].TPid, tpSharedGroups[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}

View File

@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package migrator
/*
import (
"log"
"path"
@@ -67,7 +66,7 @@ func testTpStatsITConnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storDBIn, err := engine.ConfigureStorDB(tpStatsCfgIn.StorDBType, tpStatsCfgIn.StorDBHost,
storDBIn, err := NewMigratorStorDB(tpStatsCfgIn.StorDBType, tpStatsCfgIn.StorDBHost,
tpStatsCfgIn.StorDBPort, tpStatsCfgIn.StorDBName,
tpStatsCfgIn.StorDBUser, tpStatsCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -77,7 +76,7 @@ func testTpStatsITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
storDBOut, err := engine.ConfigureStorDB(tpStatsCfgOut.StorDBType,
storDBOut, err := NewMigratorStorDB(tpStatsCfgOut.StorDBType,
tpStatsCfgOut.StorDBHost, tpStatsCfgOut.StorDBPort, tpStatsCfgOut.StorDBName,
tpStatsCfgOut.StorDBUser, tpStatsCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -87,22 +86,19 @@ func testTpStatsITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
tpStatsMigrator, err = NewMigrator(nil, nil, tpStatsCfgIn.DataDbType,
tpStatsCfgIn.DBDataEncoding, storDBIn, storDBOut, tpStatsCfgIn.StorDBType, nil,
tpStatsCfgIn.DataDbType, tpStatsCfgIn.DBDataEncoding, nil,
tpStatsCfgIn.StorDBType, false, false, false, false, false)
tpStatsMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpStatsITFlush(t *testing.T) {
if err := tpStatsMigrator.storDBIn.Flush(
if err := tpStatsMigrator.storDBIn.StorDB().Flush(
path.Join(tpStatsCfgIn.DataFolderPath, "storage", tpStatsCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpStatsMigrator.storDBOut.Flush(
if err := tpStatsMigrator.storDBOut.StorDB().Flush(
path.Join(tpStatsCfgOut.DataFolderPath, "storage", tpStatsCfgOut.StorDBType)); err != nil {
t.Error(err)
}
@@ -133,11 +129,11 @@ func testTpStatsITPopulate(t *testing.T) {
ThresholdIDs: []string{"ThreshValueTwo"},
},
}
if err := tpStatsMigrator.storDBIn.SetTPStats(tpStats); err != nil {
if err := tpStatsMigrator.storDBIn.StorDB().SetTPStats(tpStats); err != nil {
t.Error("Error when setting TpStat ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpStatsMigrator.storDBOut.SetVersions(currentVersion, false)
err := tpStatsMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpStat ", err.Error())
}
@@ -151,7 +147,7 @@ func testTpStatsITMove(t *testing.T) {
}
func testTpStatsITCheckData(t *testing.T) {
result, err := tpStatsMigrator.storDBOut.GetTPStats(
result, err := tpStatsMigrator.storDBOut.StorDB().GetTPStats(
tpStats[0].TPid, tpStats[0].ID)
if err != nil {
t.Error("Error when getting TpStat ", err.Error())
@@ -160,10 +156,9 @@ func testTpStatsITCheckData(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v",
utils.ToJSON(tpStats[0]), utils.ToJSON(result[0]))
}
result, err = tpStatsMigrator.storDBIn.GetTPStats(
result, err = tpStatsMigrator.storDBIn.StorDB().GetTPStats(
tpStats[0].TPid, tpStats[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}
*/

View File

@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package migrator
/*
import (
"log"
"path"
@@ -67,7 +66,7 @@ func testTpSplITConnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storDBIn, err := engine.ConfigureStorDB(tpSplCfgIn.StorDBType, tpSplCfgIn.StorDBHost,
storDBIn, err := NewMigratorStorDB(tpSplCfgIn.StorDBType, tpSplCfgIn.StorDBHost,
tpSplCfgIn.StorDBPort, tpSplCfgIn.StorDBName,
tpSplCfgIn.StorDBUser, tpSplCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -77,7 +76,7 @@ func testTpSplITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
storDBOut, err := engine.ConfigureStorDB(tpSplCfgOut.StorDBType,
storDBOut, err := NewMigratorStorDB(tpSplCfgOut.StorDBType,
tpSplCfgOut.StorDBHost, tpSplCfgOut.StorDBPort, tpSplCfgOut.StorDBName,
tpSplCfgOut.StorDBUser, tpSplCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -87,22 +86,19 @@ func testTpSplITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
tpSplMigrator, err = NewMigrator(nil, nil, tpSplCfgIn.DataDbType,
tpSplCfgIn.DBDataEncoding, storDBIn, storDBOut, tpSplCfgIn.StorDBType, nil,
tpSplCfgIn.DataDbType, tpSplCfgIn.DBDataEncoding, nil,
tpSplCfgIn.StorDBType, false, false, false, false, false)
tpSplMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpSplITFlush(t *testing.T) {
if err := tpSplMigrator.storDBIn.Flush(
if err := tpSplMigrator.storDBIn.StorDB().Flush(
path.Join(tpSplCfgIn.DataFolderPath, "storage", tpSplCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpSplMigrator.storDBOut.Flush(
if err := tpSplMigrator.storDBOut.StorDB().Flush(
path.Join(tpSplCfgOut.DataFolderPath, "storage", tpSplCfgOut.StorDBType)); err != nil {
t.Error(err)
}
@@ -137,36 +133,35 @@ func testTpSplITPopulate(t *testing.T) {
Weight: 20,
},
}
if err := tpSplMigrator.storDBIn.SetTPSuppliers(tpSuppliers); err != nil {
t.Error("Error when setting TpFilter ", err.Error())
if err := tpSplMigrator.storDBIn.StorDB().SetTPSuppliers(tpSuppliers); err != nil {
t.Error("Error when setting TpSuppliers ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpSplMigrator.storDBOut.SetVersions(currentVersion, false)
err := tpSplMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpFilter ", err.Error())
t.Error("Error when setting version for TpSuppliers ", err.Error())
}
}
func testTpSplITMove(t *testing.T) {
err, _ := tpSplMigrator.Migrate([]string{utils.MetaTpSuppliers})
if err != nil {
t.Error("Error when migrating TpFilter ", err.Error())
t.Error("Error when migrating TpSuppliers ", err.Error())
}
}
func testTpSplITCheckData(t *testing.T) {
result, err := tpSplMigrator.storDBOut.GetTPSuppliers(
result, err := tpSplMigrator.storDBOut.StorDB().GetTPSuppliers(
tpSuppliers[0].TPid, tpSuppliers[0].ID)
if err != nil {
t.Error("Error when getting TpFilter ", err.Error())
t.Error("Error when getting TpSuppliers ", err.Error())
}
if !reflect.DeepEqual(tpSuppliers[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v", tpSuppliers[0], result[0])
}
result, err = tpSplMigrator.storDBIn.GetTPSuppliers(
result, err = tpSplMigrator.storDBIn.StorDB().GetTPSuppliers(
tpSuppliers[0].TPid, tpSuppliers[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}
*/

View File

@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package migrator
/*
import (
"log"
"path"
@@ -67,7 +66,7 @@ func testTpTresITConnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storDBIn, err := engine.ConfigureStorDB(tpTresCfgIn.StorDBType, tpTresCfgIn.StorDBHost,
storDBIn, err := NewMigratorStorDB(tpTresCfgIn.StorDBType, tpTresCfgIn.StorDBHost,
tpTresCfgIn.StorDBPort, tpTresCfgIn.StorDBName,
tpTresCfgIn.StorDBUser, tpTresCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -77,7 +76,7 @@ func testTpTresITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
storDBOut, err := engine.ConfigureStorDB(tpTresCfgOut.StorDBType,
storDBOut, err := NewMigratorStorDB(tpTresCfgOut.StorDBType,
tpTresCfgOut.StorDBHost, tpTresCfgOut.StorDBPort, tpTresCfgOut.StorDBName,
tpTresCfgOut.StorDBUser, tpTresCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -87,22 +86,19 @@ func testTpTresITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
tpTresMigrator, err = NewMigrator(nil, nil, tpTresCfgIn.DataDbType,
tpTresCfgIn.DBDataEncoding, storDBIn, storDBOut, tpTresCfgIn.StorDBType, nil,
tpTresCfgIn.DataDbType, tpTresCfgIn.DBDataEncoding, nil,
tpTresCfgIn.StorDBType, false, false, false, false, false)
tpTresMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpTresITFlush(t *testing.T) {
if err := tpTresMigrator.storDBIn.Flush(
if err := tpTresMigrator.storDBIn.StorDB().Flush(
path.Join(tpTresCfgIn.DataFolderPath, "storage", tpTresCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpTresMigrator.storDBOut.Flush(
if err := tpTresMigrator.storDBOut.StorDB().Flush(
path.Join(tpTresCfgOut.DataFolderPath, "storage", tpTresCfgOut.StorDBType)); err != nil {
t.Error(err)
}
@@ -127,36 +123,35 @@ func testTpTresITPopulate(t *testing.T) {
Async: true,
},
}
if err := tpTresMigrator.storDBIn.SetTPThresholds(tpThresholds); err != nil {
t.Error("Error when setting TpFilter ", err.Error())
if err := tpTresMigrator.storDBIn.StorDB().SetTPThresholds(tpThresholds); err != nil {
t.Error("Error when setting TpThresholds ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpTresMigrator.storDBOut.SetVersions(currentVersion, false)
err := tpTresMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpFilter ", err.Error())
t.Error("Error when setting version for TpThresholds ", err.Error())
}
}
func testTpTresITMove(t *testing.T) {
err, _ := tpTresMigrator.Migrate([]string{utils.MetaTpThresholds})
if err != nil {
t.Error("Error when migrating TpFilter ", err.Error())
t.Error("Error when migrating TpThresholds ", err.Error())
}
}
func testTpTresITCheckData(t *testing.T) {
result, err := tpTresMigrator.storDBOut.GetTPThresholds(
result, err := tpTresMigrator.storDBOut.StorDB().GetTPThresholds(
tpThresholds[0].TPid, tpThresholds[0].ID)
if err != nil {
t.Error("Error when getting TpFilter ", err.Error())
t.Error("Error when getting TpThresholds ", err.Error())
}
if !reflect.DeepEqual(tpThresholds[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v", tpThresholds[0], result[0])
}
result, err = tpTresMigrator.storDBIn.GetTPThresholds(
result, err = tpTresMigrator.storDBIn.StorDB().GetTPThresholds(
tpThresholds[0].TPid, tpThresholds[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}
*/

View File

@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package migrator
/*
import (
"log"
"path"
@@ -67,7 +66,7 @@ func testTpTimITConnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storDBIn, err := engine.ConfigureStorDB(tpTimCfgIn.StorDBType, tpTimCfgIn.StorDBHost,
storDBIn, err := NewMigratorStorDB(tpTimCfgIn.StorDBType, tpTimCfgIn.StorDBHost,
tpTimCfgIn.StorDBPort, tpTimCfgIn.StorDBName,
tpTimCfgIn.StorDBUser, tpTimCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -77,7 +76,7 @@ func testTpTimITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
storDBOut, err := engine.ConfigureStorDB(tpTimCfgOut.StorDBType,
storDBOut, err := NewMigratorStorDB(tpTimCfgOut.StorDBType,
tpTimCfgOut.StorDBHost, tpTimCfgOut.StorDBPort, tpTimCfgOut.StorDBName,
tpTimCfgOut.StorDBUser, tpTimCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
@@ -87,22 +86,19 @@ func testTpTimITConnect(t *testing.T) {
if err != nil {
log.Fatal(err)
}
tpTimMigrator, err = NewMigrator(nil, nil, tpTimCfgIn.DataDbType,
tpTimCfgIn.DBDataEncoding, storDBIn, storDBOut, tpTimCfgIn.StorDBType, nil,
tpTimCfgIn.DataDbType, tpTimCfgIn.DBDataEncoding, nil,
tpTimCfgIn.StorDBType, false, false, false, false, false)
tpTimMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpTimITFlush(t *testing.T) {
if err := tpTimMigrator.storDBIn.Flush(
if err := tpTimMigrator.storDBIn.StorDB().Flush(
path.Join(tpTimCfgIn.DataFolderPath, "storage", tpTimCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpTimMigrator.storDBOut.Flush(
if err := tpTimMigrator.storDBOut.StorDB().Flush(
path.Join(tpTimCfgOut.DataFolderPath, "storage", tpTimCfgOut.StorDBType)); err != nil {
t.Error(err)
}
@@ -120,11 +116,11 @@ func testTpTimITPopulate(t *testing.T) {
Time: "15:00:00Z",
},
}
if err := tpTimMigrator.storDBIn.SetTPTimings(tpTimings); err != nil {
t.Error("Error when setting TpFilter ", err.Error())
if err := tpTimMigrator.storDBIn.StorDB().SetTPTimings(tpTimings); err != nil {
t.Error("Error when setting TpTimings ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpTimMigrator.storDBOut.SetVersions(currentVersion, false)
err := tpTimMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpTimings ", err.Error())
}
@@ -138,7 +134,7 @@ func testTpTimITMove(t *testing.T) {
}
func testTpTimITCheckData(t *testing.T) {
result, err := tpTimMigrator.storDBOut.GetTPTimings(
result, err := tpTimMigrator.storDBOut.StorDB().GetTPTimings(
tpTimings[0].TPid, tpTimings[0].ID)
if err != nil {
t.Error("Error when getting TpTimings ", err.Error())
@@ -146,10 +142,9 @@ func testTpTimITCheckData(t *testing.T) {
if !reflect.DeepEqual(tpTimings[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v", tpTimings[0], result[0])
}
result, err = tpTimMigrator.storDBIn.GetTPTimings(
result, err = tpTimMigrator.storDBIn.StorDB().GetTPTimings(
tpTimings[0].TPid, tpTimings[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}
*/

View File

@@ -0,0 +1,157 @@
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"log"
"path"
"reflect"
"testing"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var (
tpUserPathIn string
tpUserPathOut string
tpUserCfgIn *config.CGRConfig
tpUserCfgOut *config.CGRConfig
tpUserMigrator *Migrator
tpUsers []*utils.TPUsers
)
var sTestsTpUserIT = []func(t *testing.T){
testTpUserITConnect,
testTpUserITFlush,
testTpUserITPopulate,
testTpUserITMove,
testTpUserITCheckData,
}
func TestTpUserMove(t *testing.T) {
for _, stest := range sTestsTpUserIT {
t.Run("TestTpUserMove", stest)
}
}
func testTpUserITConnect(t *testing.T) {
var err error
tpUserPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
tpUserCfgIn, err = config.NewCGRConfigFromFolder(tpUserPathIn)
if err != nil {
t.Fatal(err)
}
tpUserPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
tpUserCfgOut, err = config.NewCGRConfigFromFolder(tpUserPathOut)
if err != nil {
t.Fatal(err)
}
storDBIn, err := NewMigratorStorDB(tpUserCfgIn.StorDBType, tpUserCfgIn.StorDBHost,
tpUserCfgIn.StorDBPort, tpUserCfgIn.StorDBName,
tpUserCfgIn.StorDBUser, tpUserCfgIn.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
config.CgrConfig().StorDBMaxIdleConns,
config.CgrConfig().StorDBConnMaxLifetime,
config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
storDBOut, err := NewMigratorStorDB(tpUserCfgOut.StorDBType,
tpUserCfgOut.StorDBHost, tpUserCfgOut.StorDBPort, tpUserCfgOut.StorDBName,
tpUserCfgOut.StorDBUser, tpUserCfgOut.StorDBPass,
config.CgrConfig().StorDBMaxOpenConns,
config.CgrConfig().StorDBMaxIdleConns,
config.CgrConfig().StorDBConnMaxLifetime,
config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
tpUserMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpUserITFlush(t *testing.T) {
if err := tpUserMigrator.storDBIn.StorDB().Flush(
path.Join(tpUserCfgIn.DataFolderPath, "storage", tpUserCfgIn.StorDBType)); err != nil {
t.Error(err)
}
if err := tpUserMigrator.storDBOut.StorDB().Flush(
path.Join(tpUserCfgOut.DataFolderPath, "storage", tpUserCfgOut.StorDBType)); err != nil {
t.Error(err)
}
}
func testTpUserITPopulate(t *testing.T) {
tpUsers = []*utils.TPUsers{
&utils.TPUsers{
TPid: "TPU1",
UserName: "User1",
Tenant: "Tenant1",
Masked: true,
Weight: 20,
Profile: []*utils.TPUserProfile{
&utils.TPUserProfile{
AttrName: "UserProfile1",
AttrValue: "ValUP1",
},
&utils.TPUserProfile{
AttrName: "UserProfile2",
AttrValue: "ValUP2",
},
},
},
}
if err := tpUserMigrator.storDBIn.StorDB().SetTPUsers(tpUsers); err != nil {
t.Error("Error when setting TpUsers ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpUserMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpUsers ", err.Error())
}
}
func testTpUserITMove(t *testing.T) {
err, _ := tpUserMigrator.Migrate([]string{utils.MetaTpUsers})
if err != nil {
t.Error("Error when migrating TpUsers ", err.Error())
}
}
func testTpUserITCheckData(t *testing.T) {
filter := &utils.TPUsers{TPid: tpUsers[0].TPid}
result, err := tpUserMigrator.storDBOut.StorDB().GetTPUsers(filter)
if err != nil {
t.Error("Error when getting TpUsers ", err.Error())
}
if !reflect.DeepEqual(tpUsers[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v", tpUsers[0], result[0])
}
result, err = tpUserMigrator.storDBIn.StorDB().GetTPUsers(filter)
if err != utils.ErrNotFound {
t.Error(err)
}
}