mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 22:58:44 +05:00
SessionSv1.UpdateSession, SessionSv1.TerminateSession, SessionSv1.ProcessCDR with integration tests
This commit is contained in:
@@ -489,9 +489,9 @@ func (fsev FSEvent) V1UpdateSessionArgs() (args *sessionmanager.V1UpdateSessionA
|
||||
if strings.Index(subsystems, SubSAccountS) == -1 {
|
||||
args.UpdateSession = false
|
||||
}
|
||||
if strings.Index(subsystems, SubSResourceS) != -1 {
|
||||
args.AllocateResources = true
|
||||
}
|
||||
//if strings.Index(subsystems, SubSResourceS) != -1 {
|
||||
// args.AllocateResources = true
|
||||
//}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -199,6 +199,7 @@ func TestSSv1ItInitiateSession(t *testing.T) {
|
||||
utils.Account: "1001",
|
||||
utils.Destination: "1002",
|
||||
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
|
||||
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
|
||||
utils.Usage: initUsage,
|
||||
},
|
||||
},
|
||||
@@ -226,12 +227,94 @@ func TestSSv1ItInitiateSession(t *testing.T) {
|
||||
"OriginID": "TestSSv1It",
|
||||
"RequestType": "*prepaid",
|
||||
"SetupTime": "2018-01-07T17:00:00Z",
|
||||
"AnswerTime": "2018-01-07T17:00:10Z",
|
||||
"Usage": 300000000000.0,
|
||||
},
|
||||
},
|
||||
}
|
||||
if !reflect.DeepEqual(eAttrs, rply.Attributes) {
|
||||
t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes))
|
||||
t.Errorf("expecting: %+v, received: %+v",
|
||||
utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSSv1ItUpdateSession(t *testing.T) {
|
||||
reqUsage := 5 * time.Minute
|
||||
args := &sessionmanager.V1UpdateSessionArgs{
|
||||
UpdateSession: true,
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestSSv1ItUpdateSession",
|
||||
Event: map[string]interface{}{
|
||||
utils.ACCID: "TestSSv1It",
|
||||
utils.RequestType: utils.META_PREPAID,
|
||||
utils.Account: "1001",
|
||||
utils.Destination: "1002",
|
||||
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
|
||||
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
|
||||
utils.Usage: reqUsage,
|
||||
},
|
||||
},
|
||||
}
|
||||
var rply sessionmanager.V1UpdateSessionReply
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1UpdateSession,
|
||||
args, &rply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if *rply.MaxUsage != reqUsage {
|
||||
t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSSv1ItTerminateSession(t *testing.T) {
|
||||
args := &sessionmanager.V1TerminateSessionArgs{
|
||||
TerminateSession: true,
|
||||
ReleaseResources: false,
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestSSv1ItUpdateSession",
|
||||
Event: map[string]interface{}{
|
||||
utils.ACCID: "TestSSv1It",
|
||||
utils.RequestType: utils.META_PREPAID,
|
||||
utils.Account: "1001",
|
||||
utils.Destination: "1002",
|
||||
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
|
||||
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
|
||||
utils.Usage: 10 * time.Minute,
|
||||
},
|
||||
},
|
||||
}
|
||||
var rply string
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1TerminateSession,
|
||||
args, &rply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if rply != utils.OK {
|
||||
t.Errorf("Unexpected reply: %s", rply)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSSv1ItProcessCDR(t *testing.T) {
|
||||
args := utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestSSv1ItProcessCDR",
|
||||
Event: map[string]interface{}{
|
||||
utils.ACCID: "TestSSv1It",
|
||||
utils.RequestType: utils.META_PREPAID,
|
||||
utils.Account: "1001",
|
||||
utils.Destination: "1002",
|
||||
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
|
||||
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
|
||||
utils.Usage: 10 * time.Minute,
|
||||
},
|
||||
}
|
||||
var rply string
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1ProcessCDR,
|
||||
args, &rply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if rply != utils.OK {
|
||||
t.Errorf("Unexpected reply: %s", rply)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1462,14 +1462,12 @@ func (smg *SMGeneric) BiRPCv1InitiateSession(clnt *rpc2.Client,
|
||||
}
|
||||
|
||||
type V1UpdateSessionArgs struct {
|
||||
UpdateSession bool
|
||||
AllocateResources bool
|
||||
UpdateSession bool
|
||||
utils.CGREvent
|
||||
}
|
||||
|
||||
type V1UpdateSessionReply struct {
|
||||
MaxUsage time.Duration
|
||||
ResAllocMessage string
|
||||
MaxUsage *time.Duration
|
||||
}
|
||||
|
||||
// BiRPCV1UpdateSession updates an existing session, returning the duration which the session can still last
|
||||
@@ -1479,33 +1477,37 @@ func (smg *SMGeneric) BiRPCv1UpdateSession(clnt *rpc2.Client,
|
||||
if smg.rals == nil {
|
||||
return utils.NewErrNotConnected(utils.RALService)
|
||||
}
|
||||
if rply.MaxUsage, err = smg.UpdateSession(args.CGREvent.Event, clnt); err != nil {
|
||||
if maxUsage, err := smg.UpdateSession(args.CGREvent.Event, clnt); err != nil {
|
||||
if err != rpcclient.ErrSessionNotFound {
|
||||
err = utils.NewErrServerError(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
if args.AllocateResources {
|
||||
if smg.resS == nil {
|
||||
return utils.NewErrNotConnected(utils.ResourceS)
|
||||
}
|
||||
originID, err := args.CGREvent.FieldAsString(utils.ACCID)
|
||||
if err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
attrRU := utils.ArgRSv1ResourceUsage{
|
||||
CGREvent: args.CGREvent,
|
||||
UsageID: originID,
|
||||
Units: 1,
|
||||
}
|
||||
var allocMessage string
|
||||
if err = smg.resS.Call(utils.ResourceSv1AllocateResources,
|
||||
attrRU, &allocMessage); err != nil {
|
||||
return err
|
||||
} else {
|
||||
rply.MaxUsage = &maxUsage
|
||||
}
|
||||
rply.ResAllocMessage = allocMessage
|
||||
}
|
||||
/*
|
||||
if args.AllocateResources {
|
||||
if smg.resS == nil {
|
||||
return utils.NewErrNotConnected(utils.ResourceS)
|
||||
}
|
||||
originID, err := args.CGREvent.FieldAsString(utils.ACCID)
|
||||
if err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
attrRU := utils.ArgRSv1ResourceUsage{
|
||||
CGREvent: args.CGREvent,
|
||||
UsageID: originID,
|
||||
Units: 1,
|
||||
}
|
||||
var allocMessage string
|
||||
if err = smg.resS.Call(utils.ResourceSv1AllocateResources,
|
||||
attrRU, &allocMessage); err != nil {
|
||||
return err
|
||||
}
|
||||
rply.ResAllocMessage = allocMessage
|
||||
}
|
||||
*/
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user