Add tests in cmd/cgr-tester for simple max usage of new and old AccountS

This commit is contained in:
TeoV
2021-02-18 17:24:28 +02:00
committed by Dan Christian Bogos
parent 71f9cfb8b6
commit 2f05e64c81
7 changed files with 212 additions and 0 deletions

View File

@@ -0,0 +1,145 @@
/*
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 main
import (
"flag"
"fmt"
"log"
"math/rand"
"net/rpc"
"net/rpc/jsonrpc"
"path"
"sync"
"time"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
var (
dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here")
requests = flag.Int("requests", 10000, "Number of requests")
gorutines = flag.Int("goroutines", 5, "Number of simultaneous goroutines")
)
// How to run:
// 1) Start the engine with the following configuration < cgr-engine -config_path=/usr/share/cgrates/conf/samples/accounts_mysql >
// 2) Load the data with < cgr-loader -config_path=/usr/share/cgrates/conf/samples/accounts_mysql -verbose -path=/usr/share/cgrates/tariffplans/oldaccvsnew >
// 3) Run the program with < go run simple_max_usage.go -requests=10000 -goroutines=5 >
func main() {
flag.Parse()
var err error
var rpc *rpc.Client
var cfgPath string
var cfg *config.CGRConfig
cfgPath = path.Join(*dataDir, "conf", "samples", "accounts_mysql")
if cfg, err = config.NewCGRConfigFromPath(cfgPath); err != nil {
log.Fatal("Got config error: ", err.Error())
}
if rpc, err = jsonrpc.Dial(utils.TCP, cfg.ListenCfg().RPCJSONListen); err != nil {
return
}
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
var wgAccountS sync.WaitGroup
var accountSTime time.Duration
var sumAccountS float64
var wgRALs sync.WaitGroup
var ralsTime time.Duration
var sumRALs float64
for i := 0; i < *requests; i++ {
wgAccountS.Add(1)
wgRALs.Add(1)
usage := fmt.Sprintf("%+vm", 1+r1.Intn(59))
go func() {
var eEc *utils.ExtEventCharges
arg := &utils.ArgsAccountsForEvent{CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Event: map[string]interface{}{
utils.AccountField: "1001",
utils.ToR: utils.MetaVoice,
utils.Usage: usage,
}}}
tNow := time.Now()
if err := rpc.Call(utils.AccountSv1MaxUsage,
arg, &eEc); err != nil {
return
}
accountSTime += time.Now().Sub(tNow)
sumAccountS += *eEc.Usage
wgAccountS.Done()
}()
go func() {
tStart := time.Date(2016, 3, 31, 0, 0, 0, 0, time.UTC)
usageDur, _ := utils.ParseDurationWithNanosecs(usage)
cd := &engine.CallDescriptorWithOpts{
CallDescriptor: &engine.CallDescriptor{
Category: "call",
Tenant: "cgrates.org",
Subject: "1001",
Account: "1001",
Destination: "1002",
TimeStart: tStart,
TimeEnd: tStart.Add(usageDur),
},
}
var rply time.Duration
tNow := time.Now()
if err := rpc.Call(utils.ResponderGetMaxSessionTime, cd, &rply); err != nil {
return
}
ralsTime += time.Now().Sub(tNow)
sumRALs += rply.Seconds()
wgRALs.Done()
}()
if i%*gorutines == 0 {
wgAccountS.Wait()
wgRALs.Wait()
}
}
wgAccountS.Wait()
wgRALs.Wait()
fmt.Println("Sum AccountS MaxUsage")
fmt.Println(sumAccountS)
fmt.Println("Average AccountS MaxUsage")
fmt.Println(accountSTime / time.Duration(*requests))
fmt.Println("Total AccountS MaxUsage Time")
fmt.Println(accountSTime)
fmt.Println("Sum RALs GetMaxSessionTime")
fmt.Println(sumRALs)
fmt.Println("Average RALs GetMaxSessionTime")
fmt.Println(ralsTime / time.Duration(*requests))
fmt.Println("Total RALs GetMaxSessionTime Time")
fmt.Println(ralsTime)
}

View File

@@ -27,6 +27,10 @@
},
"rals": {
"enabled": true,
},
"accounts": {
"enabled": true,

View File

@@ -0,0 +1,54 @@
{
// CGRateS sample configuration file
// Copyright (C) ITsysCOM GmbH
//
"data_db": {
"db_type": "redis",
"db_port": 6379,
"db_name": "10",
},
"stor_db": {
"db_password": "CGRateS.org",
},
"attributes": {
"enabled": true,
},
"rates": {
"enabled": true,
},
"schedulers": {
"enabled": true,
},
"rals": {
"enabled": true,
},
"accounts": {
"enabled": true,
"attributes_conns": ["*localhost"],
"rates_conns": ["*localhost"],
},
"apiers": {
"enabled": true,
},
}

View File

@@ -0,0 +1,2 @@
#Tenant,Account,ActionPlanId,ActionTriggersId,AllowNegative,Disabled
cgrates.org,1001,AP_PACKAGE_10,,,
1 #Tenant Account ActionPlanId ActionTriggersId AllowNegative Disabled
2 cgrates.org 1001 AP_PACKAGE_10

View File

@@ -0,0 +1,3 @@
#Tenant,ID,FilterIDs,ActivationInterval,Weights,Opts,BalanceID,BalanceFilterIDs,BalanceWeights,BalanceType,BalanceUnits,BalanceUnitFactors,BalanceOpts,BalanceCostIncrements,BalanceAttributeIDs,BalanceRateProfileIDs,ThresholdIDs
cgrates.org,1001,*string:~*req.Account:1001,,,,VoiceBalance,,;10,*abstract,3600000000000,,,*string:~*req.ToR:*voice;1000000000;0;0,,,
1 #Tenant ID FilterIDs ActivationInterval Weights Opts BalanceID BalanceFilterIDs BalanceWeights BalanceType BalanceUnits BalanceUnitFactors BalanceOpts BalanceCostIncrements BalanceAttributeIDs BalanceRateProfileIDs ThresholdIDs
2 cgrates.org 1001 *string:~*req.Account:1001 VoiceBalance ;10 *abstract 3600000000000 *string:~*req.ToR:*voice;1000000000;0;0

View File

@@ -0,0 +1,2 @@
#Id,ActionsId,TimingId,Weight
AP_PACKAGE_10,ACT_TOPUP_RST_10,*asap,10
1 #Id ActionsId TimingId Weight
2 AP_PACKAGE_10 ACT_TOPUP_RST_10 *asap 10

View File

@@ -0,0 +1,2 @@
#ActionsId[0],Action[1],ExtraParameters[2],Filter[3],BalanceId[4],BalanceType[5],Categories[6],DestinationIds[7],RatingSubject[8],SharedGroup[9],ExpiryTime[10],TimingIds[11],Units[12],BalanceWeight[13],BalanceBlocker[14],BalanceDisabled[15],Weight[16]
ACT_TOPUP_RST_10,*topup_reset,,,test,*voice,,*any,,,*unlimited,,3600000000000,10,false,false,10
1 #ActionsId[0] Action[1] ExtraParameters[2] Filter[3] BalanceId[4] BalanceType[5] Categories[6] DestinationIds[7] RatingSubject[8] SharedGroup[9] ExpiryTime[10] TimingIds[11] Units[12] BalanceWeight[13] BalanceBlocker[14] BalanceDisabled[15] Weight[16]
2 ACT_TOPUP_RST_10 *topup_reset test *voice *any *unlimited 3600000000000 10 false false 10