mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Active test from migrator
This commit is contained in:
committed by
Dan Christian Bogos
parent
69089da500
commit
741e084a1a
@@ -1990,7 +1990,8 @@ func (tps TpStatsS) AsTPStats() (result []*utils.TPStats) {
|
||||
}
|
||||
metricSplit := strings.Split(tp.Metrics, utils.INFIELD_SEP)
|
||||
for _, metric := range metricSplit {
|
||||
metricmap[tp.Tenant][tp.ID][metric] = &utils.MetricWithParams{MetricID: metric, Parameters: tp.Parameters}
|
||||
metricmap[tp.Tenant][tp.ID][metric] = &utils.MetricWithParams{
|
||||
MetricID: metric, Parameters: tp.Parameters}
|
||||
}
|
||||
}
|
||||
if tp.ThresholdIDs != "" {
|
||||
@@ -2094,8 +2095,10 @@ func APItoModelStats(st *utils.TPStats) (mdls TpStatsS) {
|
||||
for i, val := range st.Metrics {
|
||||
if i != 0 {
|
||||
mdl.Metrics += utils.INFIELD_SEP
|
||||
mdl.Parameters += utils.INFIELD_SEP
|
||||
}
|
||||
mdl.Metrics += val.MetricID
|
||||
mdl.Parameters += val.Parameters
|
||||
}
|
||||
for i, val := range st.ThresholdIDs {
|
||||
if i != 0 {
|
||||
|
||||
@@ -151,11 +151,6 @@ func testCdrITMigrateAndMove(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error when setting version for CDRs ", err.Error())
|
||||
}
|
||||
if rcvCDRs, _, err := cdrMigrator.storDBOut.GetCDRs(new(utils.CDRsFilter), false); err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
} else if len(rcvCDRs) != 0 {
|
||||
t.Errorf("Unexpected number of CDRs returned: %d", len(rcvCDRs))
|
||||
}
|
||||
err, _ = cdrMigrator.Migrate([]string{utils.MetaCDRs})
|
||||
if err != nil {
|
||||
t.Error("Error when migrating CDRs ", err.Error())
|
||||
|
||||
@@ -32,21 +32,28 @@ func (m *Migrator) migrateCurrentTPresources() (err error) {
|
||||
}
|
||||
|
||||
for _, tpid := range tpids {
|
||||
ids, err := m.storDBIn.GetTpTableIds(tpid, utils.TBLTPResources, utils.TPDistinctIds{"id"}, map[string]string{}, nil)
|
||||
ids, err := m.storDBIn.GetTpTableIds(tpid, utils.TBLTPResources,
|
||||
utils.TPDistinctIds{"id"}, map[string]string{}, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
|
||||
dest, err := m.storDBIn.GetTPResources(tpid, id)
|
||||
resources, err := m.storDBIn.GetTPResources(tpid, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if dest != nil {
|
||||
if resources != nil {
|
||||
if m.dryRun != true {
|
||||
if err := m.storDBOut.SetTPResources(dest); err != nil {
|
||||
if err := m.storDBOut.SetTPResources(resources); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, resource := range resources {
|
||||
if err := m.storDBIn.RemTpData(utils.TBLTPResources, resource.TPid,
|
||||
map[string]string{"id": resource.ID}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
m.stats[utils.TpResources] += 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,21 +32,28 @@ func (m *Migrator) migrateCurrentTPstats() (err error) {
|
||||
}
|
||||
|
||||
for _, tpid := range tpids {
|
||||
ids, err := m.storDBIn.GetTpTableIds(tpid, utils.TBLTPStats, utils.TPDistinctIds{"id"}, map[string]string{}, nil)
|
||||
ids, err := m.storDBIn.GetTpTableIds(tpid, utils.TBLTPStats,
|
||||
utils.TPDistinctIds{"id"}, map[string]string{}, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
|
||||
dest, err := m.storDBIn.GetTPStats(tpid, id)
|
||||
stats, err := m.storDBIn.GetTPStats(tpid, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if dest != nil {
|
||||
if stats != nil {
|
||||
if m.dryRun != true {
|
||||
if err := m.storDBOut.SetTPStats(dest); err != nil {
|
||||
if err := m.storDBOut.SetTPStats(stats); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, stat := range stats {
|
||||
if err := m.storDBIn.RemTpData(utils.TBLTPStats, stat.TPid,
|
||||
map[string]string{"id": stat.ID}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
m.stats[utils.TpStats] += 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ func testTpStatsITPopulate(t *testing.T) {
|
||||
Stored: false,
|
||||
Weight: 20,
|
||||
MinItems: 1,
|
||||
ThresholdIDs: []string{"ThreshValue", "ThreshValueTwo"},
|
||||
ThresholdIDs: []string{"ThreshValueTwo"},
|
||||
},
|
||||
}
|
||||
if err := tpStatsMigrator.storDBIn.SetTPStats(tpStats); err != nil {
|
||||
@@ -156,7 +156,8 @@ func testTpStatsITCheckData(t *testing.T) {
|
||||
t.Error("Error when getting TpFilter ", err.Error())
|
||||
}
|
||||
if !reflect.DeepEqual(tpStats[0], result[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tpStats[0], result[0])
|
||||
t.Errorf("Expecting: %+v, received: %+v",
|
||||
utils.ToJSON(tpStats[0]), utils.ToJSON(result[0]))
|
||||
}
|
||||
result, err = tpStatsMigrator.storDBIn.GetTPStats(
|
||||
tpStats[0].TPid, tpStats[0].ID)
|
||||
|
||||
Reference in New Issue
Block a user