mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 06:09:53 +05:00
Updated tests with dispatcher hosts
This commit is contained in:
committed by
Dan Christian Bogos
parent
ad54df15f7
commit
b2cd78af5d
@@ -21,6 +21,7 @@ package engine
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
@@ -404,7 +405,7 @@ func IfaceAsEventCost(itm interface{}) (ec *EventCost, err error) {
|
||||
case map[string]interface{}:
|
||||
ec, err = IfaceAsEventCost(utils.ToJSON(otm))
|
||||
default:
|
||||
err = utils.ErrNotConvertibleNoCaps
|
||||
err = utils.ErrNotConvertibleTF(reflect.TypeOf(otm).String(), "*EventCost")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ package engine
|
||||
import (
|
||||
"log"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -267,6 +269,11 @@ cgrates.org,Charger1,*string:Account:1001,2014-07-29T15:00:00Z,*rated,ATTR_1001_
|
||||
#Tenant,ID,FilterIDs,ActivationInterval,Strategy,Hosts,Weight
|
||||
cgrates.org,D1,*any,*string:Account:1001,2014-07-29T15:00:00Z,*first,,C1,*gt:Usage:10,10,false,192.168.56.203,20
|
||||
cgrates.org,D1,,,,*first,,C2,*lt:Usage:10,10,false,192.168.56.204,
|
||||
`
|
||||
dispatcherHosts = `
|
||||
#Tenant[0],ID[1],Address[2],Transport[3]
|
||||
cgrates.org,ALL1,127.0.0.1:2012,*json
|
||||
cgrates.org,ALL1,127.0.0.1:3012,*json
|
||||
`
|
||||
)
|
||||
|
||||
@@ -275,8 +282,8 @@ var csvr *TpReader
|
||||
func init() {
|
||||
csvr = NewTpReader(dm.dataDB, NewStringCSVStorage(',', destinations, timings, rates, destinationRates,
|
||||
ratingPlans, ratingProfiles, sharedGroups, actions, actionPlans, actionTriggers,
|
||||
accountActions, resProfiles, stats, thresholds,
|
||||
filters, sppProfiles, attributeProfiles, chargerProfiles, dispatcherProfiles), testTPID, "", nil)
|
||||
accountActions, resProfiles, stats, thresholds, filters, sppProfiles, attributeProfiles,
|
||||
chargerProfiles, dispatcherProfiles, dispatcherHosts), testTPID, "", nil)
|
||||
|
||||
if err := csvr.LoadDestinations(); err != nil {
|
||||
log.Print("error in LoadDestinations:", err)
|
||||
@@ -335,6 +342,9 @@ func init() {
|
||||
if err := csvr.LoadDispatcherProfiles(); err != nil {
|
||||
log.Print("error in LoadDispatcherProfiles:", err)
|
||||
}
|
||||
if err := csvr.LoadDispatcherHosts(); err != nil {
|
||||
log.Print("error in LoadDispatcherHosts:", err)
|
||||
}
|
||||
csvr.WriteToDatabase(false, false, false)
|
||||
Cache.Clear(nil)
|
||||
//dm.LoadDataDBCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
|
||||
@@ -1624,6 +1634,35 @@ func TestLoadDispatcherProfiles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadDispatcherHosts(t *testing.T) {
|
||||
eDispatcherHosts := &utils.TPDispatcherHost{
|
||||
TPid: testTPID,
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ALL1",
|
||||
Conns: []*utils.TPDispatcherHostConn{
|
||||
&utils.TPDispatcherHostConn{
|
||||
Address: "127.0.0.1:2012",
|
||||
Transport: utils.MetaJSONrpc,
|
||||
},
|
||||
&utils.TPDispatcherHostConn{
|
||||
Address: "127.0.0.1:3012",
|
||||
Transport: utils.MetaJSONrpc,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
dphKey := utils.TenantID{Tenant: "cgrates.org", ID: "ALL1"}
|
||||
if len(csvr.dispatcherHosts) != 1 {
|
||||
t.Fatalf("Failed to load chargerProfiles: %s", utils.ToIJSON(csvr.chargerProfiles))
|
||||
}
|
||||
sort.Slice(csvr.dispatcherHosts[dphKey].Conns, func(i, j int) bool {
|
||||
return strings.Compare(csvr.dispatcherHosts[dphKey].Conns[i].Address, csvr.dispatcherHosts[dphKey].Conns[j].Address) == -1
|
||||
})
|
||||
if !reflect.DeepEqual(eDispatcherHosts, csvr.dispatcherHosts[dphKey]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eDispatcherHosts), utils.ToJSON(csvr.dispatcherHosts[dphKey]))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadResource(t *testing.T) {
|
||||
eResources := []*utils.TenantID{
|
||||
&utils.TenantID{
|
||||
|
||||
@@ -115,6 +115,7 @@ func TestLoaderITRemoveLoad(t *testing.T) {
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.AttributesCsv),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ChargersCsv),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatchersCsv),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatcherHostsCsv),
|
||||
), "", "", nil)
|
||||
|
||||
if err = loader.LoadDestinations(); err != nil {
|
||||
@@ -169,7 +170,10 @@ func TestLoaderITRemoveLoad(t *testing.T) {
|
||||
t.Error("Failed loading Charger profiles: ", err.Error())
|
||||
}
|
||||
if err = loader.LoadDispatcherProfiles(); err != nil {
|
||||
t.Error("Failed loading Charger profiles: ", err.Error())
|
||||
t.Error("Failed loading Dispatcher profiles: ", err.Error())
|
||||
}
|
||||
if err = loader.LoadDispatcherHosts(); err != nil {
|
||||
t.Error("Failed loading Dispatcher hosts: ", err.Error())
|
||||
}
|
||||
if err := loader.WriteToDatabase(true, false, false); err != nil {
|
||||
t.Error("Could not write data into dataDb: ", err.Error())
|
||||
@@ -207,6 +211,7 @@ func TestLoaderITLoadFromCSV(t *testing.T) {
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.AttributesCsv),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ChargersCsv),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatchersCsv),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatcherHostsCsv),
|
||||
), "", "", nil)
|
||||
|
||||
if err = loader.LoadDestinations(); err != nil {
|
||||
@@ -261,7 +266,10 @@ func TestLoaderITLoadFromCSV(t *testing.T) {
|
||||
t.Error("Failed loading Charger profiles: ", err.Error())
|
||||
}
|
||||
if err = loader.LoadDispatcherProfiles(); err != nil {
|
||||
t.Error("Failed loading Charger profiles: ", err.Error())
|
||||
t.Error("Failed loading Dispatcher profiles: ", err.Error())
|
||||
}
|
||||
if err = loader.LoadDispatcherHosts(); err != nil {
|
||||
t.Error("Failed loading Dispatcher hosts: ", err.Error())
|
||||
}
|
||||
if err := loader.WriteToDatabase(true, false, false); err != nil {
|
||||
t.Error("Could not write data into dataDb: ", err.Error())
|
||||
@@ -458,6 +466,17 @@ func TestLoaderITWriteToDatabase(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
for tenatid, dph := range loader.dispatcherHosts {
|
||||
rcv, err := loader.dm.GetDispatcherHost(tenatid.Tenant, tenatid.ID, false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Errorf("Failed GetDispatcherHost, tenant: %s, id: %s, error: %s ", dph.Tenant, dph.ID, err.Error())
|
||||
}
|
||||
dp := APItoDispatcherHost(dph)
|
||||
if !reflect.DeepEqual(dp, rcv) {
|
||||
t.Errorf("Expecting: %v, received: %v", dp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Imports data from csv files in tpScenario to storDb
|
||||
|
||||
@@ -412,4 +412,5 @@ type TPDispatcherHost struct {
|
||||
ID string `index:"1" re:""`
|
||||
Address string `index:"2" re:""`
|
||||
Transport string `index:"3" re:""`
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ func (ms *MapStorage) HasDataDrv(category, subject, tenant string) (bool, error)
|
||||
case utils.ResourcesPrefix, utils.ResourceProfilesPrefix, utils.StatQueuePrefix,
|
||||
utils.StatQueueProfilePrefix, utils.ThresholdPrefix, utils.ThresholdProfilePrefix,
|
||||
utils.FilterPrefix, utils.SupplierProfilePrefix, utils.AttributeProfilePrefix,
|
||||
utils.ChargerProfilePrefix, utils.DispatcherProfilePrefix:
|
||||
utils.ChargerProfilePrefix, utils.DispatcherProfilePrefix, utils.DispatcherHostPrefix:
|
||||
_, exists := ms.dict[category+utils.ConcatenatedKey(tenant, subject)]
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user