mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add test in migrator for dispatcher
This commit is contained in:
committed by
Dan Christian Bogos
parent
8e07676fb2
commit
ddee1efe6a
@@ -45,6 +45,10 @@ func (m *Migrator) migrateCurrentDispatcher() (err error) {
|
||||
if err := m.dmOut.DataManager().SetDispatcherProfile(dpp, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.dmIN.DataManager().RemoveDispatcherProfile(tenant,
|
||||
idg, utils.NonTransactional, false); err != nil {
|
||||
return err
|
||||
}
|
||||
m.stats[utils.Dispatchers] += 1
|
||||
}
|
||||
}
|
||||
|
||||
211
migrator/dispatchers_it_test.go
Normal file
211
migrator/dispatchers_it_test.go
Normal 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"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
dspPathIn string
|
||||
dspPathOut string
|
||||
dspCfgIn *config.CGRConfig
|
||||
dspCfgOut *config.CGRConfig
|
||||
dspMigrator *Migrator
|
||||
dspAction string
|
||||
)
|
||||
|
||||
var sTestsDspIT = []func(t *testing.T){
|
||||
testDspITConnect,
|
||||
testDspITFlush,
|
||||
testDspITMigrateAndMove,
|
||||
}
|
||||
|
||||
func TestDispatcherITMove1(t *testing.T) {
|
||||
var err error
|
||||
dspPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
|
||||
dspCfgIn, err = config.NewCGRConfigFromFolder(dspPathIn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dspPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
|
||||
dspCfgOut, err = config.NewCGRConfigFromFolder(dspPathOut)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dspAction = utils.Move
|
||||
for _, stest := range sTestsDspIT {
|
||||
t.Run("TestDispatcherITMove", stest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatcherITMove2(t *testing.T) {
|
||||
var err error
|
||||
dspPathIn = path.Join(*dataDir, "conf", "samples", "tutmysql")
|
||||
dspCfgIn, err = config.NewCGRConfigFromFolder(dspPathIn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dspPathOut = path.Join(*dataDir, "conf", "samples", "tutmongo")
|
||||
dspCfgOut, err = config.NewCGRConfigFromFolder(dspPathOut)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dspAction = utils.Move
|
||||
for _, stest := range sTestsDspIT {
|
||||
t.Run("TestDispatcherITMove", stest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatcherITMoveEncoding(t *testing.T) {
|
||||
var err error
|
||||
dspPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
|
||||
dspCfgIn, err = config.NewCGRConfigFromFolder(dspPathIn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dspPathOut = path.Join(*dataDir, "conf", "samples", "tutmongojson")
|
||||
dspCfgOut, err = config.NewCGRConfigFromFolder(dspPathOut)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dspAction = utils.Move
|
||||
for _, stest := range sTestsDspIT {
|
||||
t.Run("TestDispatcherITMoveEncoding", stest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatcherITMoveEncoding2(t *testing.T) {
|
||||
var err error
|
||||
dspPathIn = path.Join(*dataDir, "conf", "samples", "tutmysql")
|
||||
dspCfgIn, err = config.NewCGRConfigFromFolder(dspPathIn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dspPathOut = path.Join(*dataDir, "conf", "samples", "tutmysqljson")
|
||||
dspCfgOut, err = config.NewCGRConfigFromFolder(dspPathOut)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dspAction = utils.Move
|
||||
for _, stest := range sTestsDspIT {
|
||||
t.Run("TestDispatcherITMoveEncoding2", stest)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspITConnect(t *testing.T) {
|
||||
dataDBIn, err := NewMigratorDataDB(dspCfgIn.DataDbCfg().DataDbType,
|
||||
dspCfgIn.DataDbCfg().DataDbHost, dspCfgIn.DataDbCfg().DataDbPort,
|
||||
dspCfgIn.DataDbCfg().DataDbName, dspCfgIn.DataDbCfg().DataDbUser,
|
||||
dspCfgIn.DataDbCfg().DataDbPass, dspCfgIn.GeneralCfg().DBDataEncoding,
|
||||
config.CgrConfig().CacheCfg(), "")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
dataDBOut, err := NewMigratorDataDB(dspCfgOut.DataDbCfg().DataDbType,
|
||||
dspCfgOut.DataDbCfg().DataDbHost, dspCfgOut.DataDbCfg().DataDbPort,
|
||||
dspCfgOut.DataDbCfg().DataDbName, dspCfgOut.DataDbCfg().DataDbUser,
|
||||
dspCfgOut.DataDbCfg().DataDbPass, dspCfgOut.GeneralCfg().DBDataEncoding,
|
||||
config.CgrConfig().CacheCfg(), "")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
dspMigrator, err = NewMigrator(dataDBIn, dataDBOut,
|
||||
nil, nil,
|
||||
false, false, false)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspITFlush(t *testing.T) {
|
||||
if err := dspMigrator.dmOut.DataManager().DataDB().Flush(""); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if isEmpty, err := dspMigrator.dmOut.DataManager().DataDB().IsDBEmpty(); err != nil {
|
||||
t.Error(err)
|
||||
} else if isEmpty != true {
|
||||
t.Errorf("\nExpecting: true got :%+v", isEmpty)
|
||||
}
|
||||
if err := dspMigrator.dmIN.DataManager().DataDB().Flush(""); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if isEmpty, err := dspMigrator.dmIN.DataManager().DataDB().IsDBEmpty(); err != nil {
|
||||
t.Error(err)
|
||||
} else if isEmpty != true {
|
||||
t.Errorf("\nExpecting: true got :%+v", isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspITMigrateAndMove(t *testing.T) {
|
||||
dspPrf := &engine.DispatcherProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Dsp1",
|
||||
FilterIDs: []string{"*string:Accont:1001"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
Strategy: utils.MetaRandom,
|
||||
Hosts: []string{"localhost", "192.168.56.203"},
|
||||
Weight: 20,
|
||||
}
|
||||
if err := dspMigrator.dmIN.DataManager().SetDispatcherProfile(dspPrf, false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
currentVersion := engine.CurrentDataDBVersions()
|
||||
err := dspMigrator.dmOut.DataManager().DataDB().SetVersions(currentVersion, false)
|
||||
if err != nil {
|
||||
t.Error("Error when setting version for Dispatchers ", err.Error())
|
||||
}
|
||||
|
||||
_, err = dspMigrator.dmOut.DataManager().GetDispatcherProfile("cgrates.org",
|
||||
"Dsp1", false, false, utils.NonTransactional)
|
||||
if err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err, _ = dspMigrator.Migrate([]string{utils.MetaDispatchers})
|
||||
if err != nil {
|
||||
t.Error("Error when migrating Dispatchers ", err.Error())
|
||||
}
|
||||
result, err := dspMigrator.dmOut.DataManager().GetDispatcherProfile("cgrates.org",
|
||||
"Dsp1", false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !reflect.DeepEqual(result, dspPrf) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", dspPrf, result)
|
||||
}
|
||||
result, err = dspMigrator.dmIN.DataManager().GetDispatcherProfile("cgrates.org",
|
||||
"Dsp1", false, false, utils.NonTransactional)
|
||||
if err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@@ -135,6 +135,8 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) {
|
||||
err = m.migrateSupplierProfiles()
|
||||
case utils.MetaChargers:
|
||||
err = m.migrateChargers()
|
||||
case utils.MetaDispatchers:
|
||||
err = m.migrateDispatchers()
|
||||
//TPs
|
||||
case utils.MetaTpRatingPlans:
|
||||
err = m.migrateTPratingplans()
|
||||
|
||||
@@ -384,6 +384,7 @@ const (
|
||||
MetaSuppliers = "*suppliers"
|
||||
MetaAttributes = "*attributes"
|
||||
MetaChargers = "*chargers"
|
||||
MetaDispatchers = "*dispatchers"
|
||||
MetaResources = "*resources"
|
||||
MetaFilters = "*filters"
|
||||
MetaCDRs = "*cdrs"
|
||||
|
||||
Reference in New Issue
Block a user