mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 12:49:54 +05:00
Added OriginID filter in SMGenericV1.ActiveSessions, disabled sessionEnd in SMGeneric.ttlTerminate for testing purposes, testing total usage in active sessions
This commit is contained in:
@@ -97,6 +97,9 @@ func (self *SMGenericV1) ActiveSessions(attrs utils.AttrSMGGetActiveSessions, re
|
||||
if attrs.ToR != nil && *attrs.ToR != as.TOR {
|
||||
continue
|
||||
}
|
||||
if attrs.OriginID != nil && *attrs.OriginID != as.OriginID {
|
||||
continue
|
||||
}
|
||||
if attrs.RunID != nil && *attrs.RunID != as.RunId {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ func (s *Session) AsActiveSessions() []*ActiveSession {
|
||||
aSession := &ActiveSession{
|
||||
CgrId: s.eventStart.GetCgrId(s.sessionManager.Timezone()),
|
||||
TOR: utils.VOICE,
|
||||
AccId: s.eventStart.GetUUID(),
|
||||
OriginID: s.eventStart.GetUUID(),
|
||||
CdrHost: s.eventStart.GetOriginatorIP(utils.META_DEFAULT),
|
||||
CdrSource: "FS_" + s.eventStart.GetName(),
|
||||
ReqType: s.eventStart.GetReqType(utils.META_DEFAULT),
|
||||
@@ -309,7 +309,7 @@ func (s *Session) AsActiveSessions() []*ActiveSession {
|
||||
type ActiveSession struct {
|
||||
CgrId string
|
||||
TOR string // type of record, meta-field, should map to one of the TORs hardcoded inside the server <*voice|*data|*sms|*generic>
|
||||
AccId string // represents the unique accounting id given by the telecom switch generating the CDR
|
||||
OriginID string // represents the unique accounting id given by the telecom switch generating the CDR
|
||||
CdrHost string // represents the IP address of the host generating the CDR (automatically populated by the server)
|
||||
CdrSource string // formally identifies the source of the CDR (free form field)
|
||||
ReqType string // matching the supported request types by the **CGRateS**, accepted values are hardcoded in the server <prepaid|postpaid|pseudoprepaid|rated>.
|
||||
|
||||
@@ -40,7 +40,7 @@ var daCfg *config.CGRConfig
|
||||
var smgRPC *rpc.Client
|
||||
var err error
|
||||
|
||||
func TestSMGInitCfg(t *testing.T) {
|
||||
func TestSMGVoiceInitCfg(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func TestSMGInitCfg(t *testing.T) {
|
||||
}
|
||||
|
||||
// Remove data in both rating and accounting db
|
||||
func TestSMGResetDataDb(t *testing.T) {
|
||||
func TestSMGVoiceResetDataDb(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
@@ -66,7 +66,7 @@ func TestSMGResetDataDb(t *testing.T) {
|
||||
}
|
||||
|
||||
// Wipe out the cdr database
|
||||
func TestSMGResetStorDb(t *testing.T) {
|
||||
func TestSMGVoiceResetStorDb(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
@@ -76,7 +76,7 @@ func TestSMGResetStorDb(t *testing.T) {
|
||||
}
|
||||
|
||||
// Start CGR Engine
|
||||
func TestSMGStartEngine(t *testing.T) {
|
||||
func TestSMGVoiceStartEngine(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func TestSMGStartEngine(t *testing.T) {
|
||||
}
|
||||
|
||||
// Connect rpc client to rater
|
||||
func TestSMGApierRpcConn(t *testing.T) {
|
||||
func TestSMGVoiceApierRpcConn(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
@@ -98,7 +98,7 @@ func TestSMGApierRpcConn(t *testing.T) {
|
||||
}
|
||||
|
||||
// Load the tariff plan, creating accounts and their balances
|
||||
func TestSMGTPFromFolder(t *testing.T) {
|
||||
func TestSMGVoiceTPFromFolder(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
@@ -110,7 +110,7 @@ func TestSMGTPFromFolder(t *testing.T) {
|
||||
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
|
||||
}
|
||||
|
||||
func TestSMGMonetaryRefund(t *testing.T) {
|
||||
func TestSMGVoiceMonetaryRefund(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
@@ -171,7 +171,7 @@ func TestSMGMonetaryRefund(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSMGVoiceRefund(t *testing.T) {
|
||||
func TestSMGVoiceVoiceRefund(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
@@ -232,7 +232,7 @@ func TestSMGVoiceRefund(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSMGMixedRefund(t *testing.T) {
|
||||
func TestSMGVoiceMixedRefund(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
@@ -306,7 +306,7 @@ func TestSMGMixedRefund(t *testing.T) {
|
||||
t.Logf("After voice: %f", acnt.BalanceMap[utils.VOICE].GetTotalValue())
|
||||
}
|
||||
|
||||
func TestSMGLastUsed(t *testing.T) {
|
||||
func TestSMGVoiceLastUsed(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
@@ -321,7 +321,7 @@ func TestSMGLastUsed(t *testing.T) {
|
||||
smgEv := SMGenericEvent{
|
||||
utils.EVENT_NAME: "TEST_EVENT",
|
||||
utils.TOR: utils.VOICE,
|
||||
utils.ACCID: "12349",
|
||||
utils.ACCID: "12350",
|
||||
utils.DIRECTION: utils.OUT,
|
||||
utils.ACCOUNT: "1001",
|
||||
utils.SUBJECT: "1001",
|
||||
@@ -349,7 +349,7 @@ func TestSMGLastUsed(t *testing.T) {
|
||||
smgEv = SMGenericEvent{
|
||||
utils.EVENT_NAME: "TEST_EVENT",
|
||||
utils.TOR: utils.VOICE,
|
||||
utils.ACCID: "12349",
|
||||
utils.ACCID: "12350",
|
||||
utils.DIRECTION: utils.OUT,
|
||||
utils.ACCOUNT: "1001",
|
||||
utils.SUBJECT: "1001",
|
||||
@@ -375,7 +375,7 @@ func TestSMGLastUsed(t *testing.T) {
|
||||
smgEv = SMGenericEvent{
|
||||
utils.EVENT_NAME: "TEST_EVENT",
|
||||
utils.TOR: utils.VOICE,
|
||||
utils.ACCID: "12349",
|
||||
utils.ACCID: "12350",
|
||||
utils.DIRECTION: utils.OUT,
|
||||
utils.ACCOUNT: "1001",
|
||||
utils.SUBJECT: "1001",
|
||||
@@ -401,7 +401,7 @@ func TestSMGLastUsed(t *testing.T) {
|
||||
smgEv = SMGenericEvent{
|
||||
utils.EVENT_NAME: "TEST_EVENT",
|
||||
utils.TOR: utils.VOICE,
|
||||
utils.ACCID: "12349",
|
||||
utils.ACCID: "12350",
|
||||
utils.DIRECTION: utils.OUT,
|
||||
utils.ACCOUNT: "1001",
|
||||
utils.SUBJECT: "1001",
|
||||
@@ -423,7 +423,7 @@ func TestSMGLastUsed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSMGLastUsedEnd(t *testing.T) {
|
||||
func TestSMGVoiceLastUsedEnd(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
@@ -514,7 +514,7 @@ func TestSMGLastUsedEnd(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSMGLastUsedNotFixed(t *testing.T) {
|
||||
func TestSMGVoiceLastUsedNotFixed(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
@@ -605,7 +605,7 @@ func TestSMGLastUsedNotFixed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSMGSessionTTL(t *testing.T) {
|
||||
func TestSMGVoiceSessionTTL(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
@@ -620,7 +620,7 @@ func TestSMGSessionTTL(t *testing.T) {
|
||||
smgEv := SMGenericEvent{
|
||||
utils.EVENT_NAME: "TEST_EVENT_SESSION_TTL",
|
||||
utils.TOR: utils.VOICE,
|
||||
utils.ACCID: "12350",
|
||||
utils.ACCID: "12360",
|
||||
utils.DIRECTION: utils.OUT,
|
||||
utils.ACCOUNT: "1001",
|
||||
utils.SUBJECT: "1001",
|
||||
@@ -639,6 +639,14 @@ func TestSMGSessionTTL(t *testing.T) {
|
||||
if maxUsage != 120 {
|
||||
t.Error("Bad max usage: ", maxUsage)
|
||||
}
|
||||
var aSessions []*ActiveSession
|
||||
if err := smgRPC.Call("SMGenericV1.ActiveSessions", utils.AttrSMGGetActiveSessions{RunID: utils.StringPointer(utils.META_DEFAULT), OriginID: utils.StringPointer("12360")}, &aSessions); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(aSessions) != 1 {
|
||||
t.Errorf("Unexpected number of sessions received: %+v", aSessions)
|
||||
} else if aSessions[0].Usage != time.Duration(120)*time.Second {
|
||||
t.Errorf("Expecting 2m, received usage: %v", aSessions[0].Usage)
|
||||
}
|
||||
eAcntVal = 4.190020
|
||||
if err := smgRPC.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
@@ -648,7 +656,7 @@ func TestSMGSessionTTL(t *testing.T) {
|
||||
smgEv = SMGenericEvent{
|
||||
utils.EVENT_NAME: "TEST_EVENT_SESSION_TTL",
|
||||
utils.TOR: utils.VOICE,
|
||||
utils.ACCID: "12350",
|
||||
utils.ACCID: "12360",
|
||||
utils.DIRECTION: utils.OUT,
|
||||
utils.ACCOUNT: "1001",
|
||||
utils.SUBJECT: "1001",
|
||||
@@ -665,6 +673,13 @@ func TestSMGSessionTTL(t *testing.T) {
|
||||
if maxUsage != 120 {
|
||||
t.Error("Bad max usage: ", maxUsage)
|
||||
}
|
||||
if err := smgRPC.Call("SMGenericV1.ActiveSessions", utils.AttrSMGGetActiveSessions{RunID: utils.StringPointer(utils.META_DEFAULT), OriginID: utils.StringPointer("12360")}, &aSessions); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(aSessions) != 1 {
|
||||
t.Errorf("Unexpected number of sessions received: %+v", aSessions)
|
||||
} else if aSessions[0].Usage != time.Duration(150)*time.Second {
|
||||
t.Errorf("Expecting 2m30s, received usage: %v", aSessions[0].Usage)
|
||||
}
|
||||
eAcntVal = 4.090030
|
||||
if err := smgRPC.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
@@ -673,25 +688,39 @@ func TestSMGSessionTTL(t *testing.T) {
|
||||
}
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
eAcntVal = 4.089900
|
||||
if err := smgRPC.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
if err := smgRPC.Call("SMGenericV1.ActiveSessions", utils.AttrSMGGetActiveSessions{RunID: utils.StringPointer(utils.META_DEFAULT), OriginID: utils.StringPointer("12360")}, &aSessions); err != nil {
|
||||
t.Error(err)
|
||||
} else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal {
|
||||
t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MONETARY].GetTotalValue())
|
||||
} else if len(aSessions) != 1 {
|
||||
t.Errorf("Unexpected number of sessions received: %+v", aSessions)
|
||||
} else if aSessions[0].Usage != time.Duration(150)*time.Second+time.Duration(10)*time.Millisecond {
|
||||
t.Errorf("Expecting 2m30s10ms, received usage: %v", aSessions[0].Usage)
|
||||
}
|
||||
var cdrs []*engine.ExternalCDR
|
||||
req := utils.RPCCDRsFilter{RunIDs: []string{utils.META_DEFAULT}, DestinationPrefixes: []string{"1008"}}
|
||||
if err := smgRPC.Call("ApierV2.GetCdrs", req, &cdrs); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if len(cdrs) != 1 {
|
||||
t.Error("Unexpected number of CDRs returned: ", len(cdrs))
|
||||
} else {
|
||||
if cdrs[0].Usage != "150" {
|
||||
t.Errorf("Unexpected CDR Usage received, cdr: %v %+v ", cdrs[0].Usage, cdrs[0])
|
||||
|
||||
/*
|
||||
if err := smgRPC.Call("SMGenericV1.ActiveSessions", utils.AttrSMGGetActiveSessions{RunID: utils.StringPointer(utils.META_DEFAULT), OriginID: utils.StringPointer("12360")}, &aSessions); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(aSessions) != 0 {
|
||||
t.Errorf("Unexpected number of sessions received: %+v", aSessions)
|
||||
}
|
||||
if cdrs[0].Cost != 1.5 {
|
||||
t.Errorf("Unexpected CDR Cost received, cdr: %v %+v ", cdrs[0].Cost, cdrs[0])
|
||||
eAcntVal = 4.089900
|
||||
if err := smgRPC.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal {
|
||||
t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MONETARY].GetTotalValue())
|
||||
}
|
||||
}
|
||||
var cdrs []*engine.ExternalCDR
|
||||
req := utils.RPCCDRsFilter{RunIDs: []string{utils.META_DEFAULT}, DestinationPrefixes: []string{"1008"}}
|
||||
if err := smgRPC.Call("ApierV2.GetCdrs", req, &cdrs); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if len(cdrs) != 1 {
|
||||
t.Error("Unexpected number of CDRs returned: ", len(cdrs))
|
||||
} else {
|
||||
if cdrs[0].Usage != "150" {
|
||||
t.Errorf("Unexpected CDR Usage received, cdr: %v %+v ", cdrs[0].Usage, cdrs[0])
|
||||
}
|
||||
if cdrs[0].Cost != 1.5 {
|
||||
t.Errorf("Unexpected CDR Cost received, cdr: %v %+v ", cdrs[0].Cost, cdrs[0])
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -279,13 +279,12 @@ func (self *SMGSession) TotalUsage() time.Duration {
|
||||
func (self *SMGSession) AsActiveSession(timezone string) *ActiveSession {
|
||||
sTime, _ := self.eventStart.GetSetupTime(utils.META_DEFAULT, timezone)
|
||||
aTime, _ := self.eventStart.GetAnswerTime(utils.META_DEFAULT, timezone)
|
||||
usage, _ := self.eventStart.GetUsage(utils.META_DEFAULT)
|
||||
pdd, _ := self.eventStart.GetPdd(utils.META_DEFAULT)
|
||||
aSession := &ActiveSession{
|
||||
CgrId: self.eventStart.GetCgrId(timezone),
|
||||
TOR: utils.VOICE,
|
||||
RunId: self.runId,
|
||||
AccId: self.eventStart.GetUUID(),
|
||||
OriginID: self.eventStart.GetUUID(),
|
||||
CdrHost: self.eventStart.GetOriginatorIP(utils.META_DEFAULT),
|
||||
CdrSource: self.eventStart.GetCdrSource(),
|
||||
ReqType: self.eventStart.GetReqType(utils.META_DEFAULT),
|
||||
@@ -297,7 +296,7 @@ func (self *SMGSession) AsActiveSession(timezone string) *ActiveSession {
|
||||
Destination: self.eventStart.GetDestination(utils.META_DEFAULT),
|
||||
SetupTime: sTime,
|
||||
AnswerTime: aTime,
|
||||
Usage: usage,
|
||||
Usage: self.TotalUsage(),
|
||||
Pdd: pdd,
|
||||
ExtraFields: self.eventStart.GetExtraFields(),
|
||||
Supplier: self.eventStart.GetSupplier(utils.META_DEFAULT),
|
||||
|
||||
@@ -87,11 +87,12 @@ func (self *SMGeneric) ttlTerminate(s *SMGSession, tmtr *smgSessionTerminator) {
|
||||
evUpdate[utils.LastUsed] = tmtr.ttlLastUsed.Seconds()
|
||||
}
|
||||
self.SessionUpdate(evUpdate, nil)
|
||||
self.sessionEnd(s.eventStart.GetUUID(), s.TotalUsage())
|
||||
/*self.sessionEnd(s.eventStart.GetUUID(), s.TotalUsage())
|
||||
cdr := s.eventStart.AsStoredCdr(self.cgrCfg, self.timezone)
|
||||
cdr.Usage = s.TotalUsage()
|
||||
var reply string
|
||||
self.cdrsrv.ProcessCdr(cdr, &reply)
|
||||
*/
|
||||
}
|
||||
|
||||
func (self *SMGeneric) indexSession(uuid string, s *SMGSession) {
|
||||
|
||||
@@ -1160,6 +1160,7 @@ type AliasValue struct {
|
||||
// AttrSMGGetActiveSessions will filter returned sessions by SMGenericV1
|
||||
type AttrSMGGetActiveSessions struct {
|
||||
ToR *string
|
||||
OriginID *string
|
||||
RunID *string
|
||||
RequestType *string
|
||||
Tenant *string
|
||||
|
||||
Reference in New Issue
Block a user