mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 00:28:44 +05:00
Merge branch 'master' into dcinrt
This commit is contained in:
@@ -18,7 +18,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package engine
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSharedSetGet(t *testing.T) {
|
||||
id := "TEST_SG100"
|
||||
sg := &SharedGroup{
|
||||
Id: id,
|
||||
AccountParameters: map[string]*SharingParameters{
|
||||
"test": &SharingParameters{Strategy: STRATEGY_HIGHEST},
|
||||
},
|
||||
MemberIds: []string{"1", "2", "3"},
|
||||
}
|
||||
err := accountingStorage.SetSharedGroup(sg)
|
||||
if err != nil {
|
||||
t.Error("Error storing Shared groudp: ", err)
|
||||
}
|
||||
received, err := accountingStorage.GetSharedGroup(id, true)
|
||||
if err != nil || received == nil || !reflect.DeepEqual(sg, received) {
|
||||
t.Error("Error getting shared group: ", err, received)
|
||||
}
|
||||
received, err = accountingStorage.GetSharedGroup(id, false)
|
||||
if err != nil || received == nil || !reflect.DeepEqual(sg, received) {
|
||||
t.Error("Error getting cached shared group: ", err, received)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestSharedPopBalanceByStrategyLow(t *testing.T) {
|
||||
bc := BalanceChain{
|
||||
|
||||
@@ -158,13 +158,14 @@ func (tpr *TpReader) LoadDestinationRates() (err error) {
|
||||
if !destinationExists {
|
||||
_, destinationExists = tpr.destinations[dr.DestinationId]
|
||||
}
|
||||
if !destinationExists {
|
||||
if dbExists, err := tpr.ratingStorage.HasData(DESTINATION_PREFIX, dr.DestinationId); err != nil {
|
||||
if !destinationExists && tpr.ratingStorage != nil {
|
||||
if destinationExists, err = tpr.ratingStorage.HasData(DESTINATION_PREFIX, dr.DestinationId); err != nil {
|
||||
return err
|
||||
} else if !dbExists {
|
||||
return fmt.Errorf("could not get destination for tag %v", dr.DestinationId)
|
||||
}
|
||||
}
|
||||
if !destinationExists {
|
||||
return fmt.Errorf("could not get destination for tag %v", dr.DestinationId)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -224,14 +225,19 @@ func (tpr *TpReader) LoadRatingPlansFiltered(tag string) (bool, error) {
|
||||
dms, err := TpDestinations(tpDests).GetDestinations()
|
||||
if err != nil {
|
||||
return false, err
|
||||
} else if len(dms) == 0 {
|
||||
}
|
||||
destsExist := len(dms) != 0
|
||||
if !destsExist && tpr.ratingStorage != nil {
|
||||
if dbExists, err := tpr.ratingStorage.HasData(DESTINATION_PREFIX, drate.DestinationId); err != nil {
|
||||
return false, err
|
||||
} else if !dbExists {
|
||||
return false, fmt.Errorf("could not get destination for tag %v", drate.DestinationId)
|
||||
} else if dbExists {
|
||||
destsExist = true
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !destsExist {
|
||||
return false, fmt.Errorf("could not get destination for tag %v", drate.DestinationId)
|
||||
}
|
||||
for _, destination := range dms {
|
||||
tpr.ratingStorage.SetDestination(destination)
|
||||
}
|
||||
@@ -298,13 +304,14 @@ func (tpr *TpReader) LoadRatingProfilesFiltered(qriedRpf *TpRatingProfile) error
|
||||
return fmt.Errorf("cannot parse activation time from %v", tpRa.ActivationTime)
|
||||
}
|
||||
_, exists := tpr.ratingPlans[tpRa.RatingPlanId]
|
||||
if !exists {
|
||||
if dbExists, err := tpr.ratingStorage.HasData(RATING_PLAN_PREFIX, tpRa.RatingPlanId); err != nil {
|
||||
if !exists && tpr.ratingStorage != nil {
|
||||
if exists, err = tpr.ratingStorage.HasData(RATING_PLAN_PREFIX, tpRa.RatingPlanId); err != nil {
|
||||
return err
|
||||
} else if !dbExists {
|
||||
return fmt.Errorf("could not load rating plans for tag: %v", tpRa.RatingPlanId)
|
||||
}
|
||||
}
|
||||
if !exists {
|
||||
return fmt.Errorf("could not load rating plans for tag: %v", tpRa.RatingPlanId)
|
||||
}
|
||||
resultRatingProfile.RatingPlanActivations = append(resultRatingProfile.RatingPlanActivations,
|
||||
&RatingPlanActivation{
|
||||
ActivationTime: at,
|
||||
@@ -347,13 +354,14 @@ func (tpr *TpReader) LoadRatingProfiles() (err error) {
|
||||
return fmt.Errorf("cannot parse activation time from %v", tpRa.ActivationTime)
|
||||
}
|
||||
_, exists := tpr.ratingPlans[tpRa.RatingPlanId]
|
||||
if !exists {
|
||||
if dbExists, err := tpr.ratingStorage.HasData(RATING_PLAN_PREFIX, tpRa.RatingPlanId); err != nil {
|
||||
if !exists && tpr.ratingStorage != nil { // Only query if there is a connection, eg on dry run there is none
|
||||
if exists, err = tpr.ratingStorage.HasData(RATING_PLAN_PREFIX, tpRa.RatingPlanId); err != nil {
|
||||
return err
|
||||
} else if !dbExists {
|
||||
return fmt.Errorf("could not load rating plans for tag: %v", tpRa.RatingPlanId)
|
||||
}
|
||||
}
|
||||
if !exists {
|
||||
return fmt.Errorf("could not load rating plans for tag: %v", tpRa.RatingPlanId)
|
||||
}
|
||||
rpf.RatingPlanActivations = append(rpf.RatingPlanActivations,
|
||||
&RatingPlanActivation{
|
||||
ActivationTime: at,
|
||||
@@ -422,18 +430,28 @@ func (tpr *TpReader) LoadLCRs() (err error) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
if keys, err := tpr.ratingStorage.GetKeysForPrefix(RATING_PROFILE_PREFIX + ratingProfileSearchKey); err != nil || len(keys) == 0 {
|
||||
return fmt.Errorf("[LCR] could not find ratingProfiles with prefix %s", ratingProfileSearchKey)
|
||||
if !found && tpr.ratingStorage != nil {
|
||||
if keys, err := tpr.ratingStorage.GetKeysForPrefix(RATING_PROFILE_PREFIX + ratingProfileSearchKey); err != nil {
|
||||
return fmt.Errorf("[LCR] error querying ratingDb %s", err.Error())
|
||||
} else if len(keys) != 0 {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return fmt.Errorf("[LCR] could not find ratingProfiles with prefix %s", ratingProfileSearchKey)
|
||||
}
|
||||
|
||||
// check destination tags
|
||||
if tpLcr.DestinationTag != "" && tpLcr.DestinationTag != utils.ANY {
|
||||
if _, found := tpr.destinations[tpLcr.DestinationTag]; !found {
|
||||
if found, err := tpr.ratingStorage.HasData(DESTINATION_PREFIX, tpLcr.DestinationTag); err != nil || !found {
|
||||
return fmt.Errorf("[LCR] could not find destination with tag %s", tpLcr.DestinationTag)
|
||||
_, found := tpr.destinations[tpLcr.DestinationTag]
|
||||
if !found && tpr.ratingStorage != nil {
|
||||
if found, err = tpr.ratingStorage.HasData(DESTINATION_PREFIX, tpLcr.DestinationTag); err != nil {
|
||||
return fmt.Errorf("[LCR] error querying ratingDb %s", err.Error())
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return fmt.Errorf("[LCR] could not find destination with tag %s", tpLcr.DestinationTag)
|
||||
}
|
||||
}
|
||||
tag := utils.LCRKey(tpLcr.Direction, tpLcr.Tenant, tpLcr.Category, tpLcr.Account, tpLcr.Subject)
|
||||
activationTime, _ := utils.ParseTimeDetectLayout(tpLcr.ActivationTime)
|
||||
@@ -545,12 +563,14 @@ func (tpr *TpReader) LoadActionPlans() (err error) {
|
||||
for _, at := range ats {
|
||||
|
||||
_, exists := tpr.actions[at.ActionsId]
|
||||
if !exists {
|
||||
if dbExists, err := tpr.ratingStorage.HasData(ACTION_PREFIX, at.ActionsId); err != nil || !dbExists {
|
||||
return fmt.Errorf("[ActionPlans] Could not load the action for tag: %v",
|
||||
at.ActionsId)
|
||||
if !exists && tpr.ratingStorage != nil {
|
||||
if exists, err = tpr.ratingStorage.HasData(ACTION_PREFIX, at.ActionsId); err != nil {
|
||||
return fmt.Errorf("[ActionPlans] Error querying actions: %v - %s", at.ActionsId, err.Error())
|
||||
}
|
||||
}
|
||||
if !exists {
|
||||
return fmt.Errorf("[ActionPlans] Could not load the action for tag: %v", at.ActionsId)
|
||||
}
|
||||
t, exists := tpr.timings[at.TimingId]
|
||||
if !exists {
|
||||
return fmt.Errorf("[ActionPlans] Could not load the timing for tag: %v", at.TimingId)
|
||||
|
||||
Reference in New Issue
Block a user