mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
`ClientConnector` is no longer defined within `rpcclient` in its latest
version. It has been changed to be obtained from the `cgrates/birpc`
library instead.
Replaced `net/rpc` with `cgrates/birpc` and `net/rpc/jsonrpc` with
`cgrates/birpc/jsonrpc` libraries.
The implementations of `CallBiRPC()` and `Handlers()` were removed,
along with the methods associated with them.
The `rpcclient.BIRPCConector` and the methods prefixed with `BiRPC` were
removed from the `BiRPClient` interface.
The `BiRPClient` interface was renamed to `BIRPCClient`, although not
sure if needed (seems useful just to test if the structure is correct).
`rpcclient.BiRPCConector` has been replaced with `context.ClientConnector`,
which is now passed alongside `context.Context` within the same struct
(`cgrates/birpc/context.Context`). Consequently, functions that were
previously relying on it are now receiving the context instead. The
changes were made in the following functions:
- `engine/connmanager.go` - `*ConnManager.Call`
- `engine/connmanager.go` - `*ConnManager.getConn`
- `engine/connmanager.go` - `*ConnManager.getConnWithConfig`
- `engine/libengine.go` - `NewRPCPool`
- `engine/libengine.go` - `NewRPCConnection`
- `agents/libagents.go` - `processRequest`
Compilation errors related to the `rpcclient.NewRPCClient` function were
resolved by adding the missing `context`, `max_reconnect_interval`, and
`delayFunc` parameters. Additionally, context was added to all calls made
by the client. An effort was made to avoid passing hardcoded values as
much as possible, and extra flags were added where necessary for cgr
binaries.
The `max_reconnect_interval` parameter is now passed from parent
functions, which required adjustments to the function signature.
A new context field was added to all agent objects to ensure access to
it before sending it to the `connmanager's Call`, effectively replacing
`birpcclient`. Although an alternative would have been to create the
new service and add it to the context right before passing it to the
handlers, the chosen approach is definitely more comfortable.
With the addition of a context field for the SIP servers agents, an
additional error needed to be handled, coming from the creation of the
service. Agent constructors within the services package log errors as
they occur and return. Alternate solutions considered were either
shutting down the engine instead of returning, or just logging the
occurrence as a warning, particularly when the `ctx.Client` isn't
required, especially in cases where bidirectional connections are not
needed. For the latter option, it's crucial to return the object with
the error rather than nil or to make the error nil immediately after
logging.
Context has been integrated into all internal Call implementations to
ensure the objects conform to the `birpc.ClientConnector` interface.
These implementations will be removed in the near future as all service
objects are being wrapped in a `birpc.Service` type that satisfies the
`birpc.ClientConnector` interface. Currently, they are being retained
as a reference in case of any unexpected issues that arise.
Ensured that the `birpc.Service` wrapped service objects are passed to
the internal channel getters rather than the objects themselves.
Add context.TODO() to all \*ConnManager.Call function calls. To be
replaced with the context passed to the Method, when available.
For all `*ConnManager.Call` function calls, `context.TODO()` has been
added. This will be replaced with the context passed to the method when
it becomes available.
The value returned by StringGetOpts is now passed directly to the
FirstNonEmpty function, instead of being assigned to a variable
first.
The implementation of the `*AnalyzerService.GetInternalBiRPCCodec`
function has been removed from the services package. Additionally,
the AnalyzerBiRPCConnector type definition and its associated methods
have been removed.
The codec implementation has been revised to include the following
changes:
- `rpc.ServerCodec` -> `birpc.ServerCodec`;
- `rpc2.ServerCodec` -> `birpc.BirpcCodec`;
- `rpc2.Request` -> `birpc.Request`;
- `rpc2.Response` -> `birpc.Response`;
- The constructors for json and gob birpc codecs in `cenkalti/rpc`
have been replaced with ones from the `birpc/jsonrpc` library;
- The gob codec implementation has been removed in favor of the
version already implemented in the birpc external library.
The server implementation has been updated with the following changes:
- A field that represents a simple RPC server has been added to the
Server struct;
- Both the simple and bidirectional RPC servers are now initialized
inside the Server constructor, eliminating the need for nil checks;
- Usage of `net/rpc` and `cenkalti/rpc2` has been replaced with
`cgrates/birpc`;
- Additional `(Bi)RPCUnregisterName` methods have been added;
- The implementations for (bi)json/gob servers have been somewhat
simplified.
Before deleting the Call functions and using the `birpc.NewService`
method to register the methods for all cgrates components, update the
Call functions to satisfy the `birpc.ClientConnector` interface. This
way it will be a bit safer. Had to be done for SessionS though.
The `BiRPCCall` method has been removed from coreutils.go. The
`RPCCall` and `APIerRPCCall` methods are also to be removed in the
future.
Ensured that all methods for `SessionSv1` and `SessionS` have the
correct function signature with context. The same adjustments were made
for the session dispatcher methods and for the `SessionSv1Interface`.
Also removed sessionsbirpc.go and smgbirpc.go files.
Implemented the following methods to help with the registration of
methods across all subsystems:
- `NewServiceWithName`;
- `NewDispatcherService` for all dispatcher methods;
- `NewService` for the remaining methods that are already named
correctly.
Compared to the constructor from the external library, these also make
sure that the naming of the methods is consistent with our constants.
Added context to the Call methods for the mock client connectors (used
in tests).
Removed unused rpc fields from inside the following services:
- EeS
- LoaderS
- ResourceS
- RouteS
- StatS
- ThresholdS
- SessionS
- CoreS
Updated the methods implementing the logic for API methods to align
with the latest changes, ensuring consistency and correctness. The
modifications include:
- Adjusting the function signature to the new format
(ctx, args, reply).
- Prefixing names with 'V*' to indicate that they are utilized by
or registered as APIs.
- Containing the complete logic within the methods, enabling APIs
to call them and return their reply directly.
The subsystems affected by these changes are detailed as follows:
- CoreS: Additional methods were implementing utilizing the
existing ones. Though modifying them directly was possible, certain
methods (e.g., StopCPUProfiling()) were used elsewhere and not as
RPC requests.
- CDRs: Renamed V1CountCDRs to V1GetCDRsCount.
- StatS: V1GetQueueFloatMetrics, V1GetQueueStringMetrics,
V1GetStatQueue accept different arguments compared to API functions
(opted to register StatSv1 instead).
- ResourceS: Renamed V1ResourcesForEvent to V1GetResourcesForEvent
to align with API naming.
- DispatcherS: Renamed V1GetProfilesForEvent to
DispatcherSv1GetProfilesForEvent.
- For the rest, adding context to the function signature was enough.
In the unit tests, wrapping the object within a biprc.Service is now
ensured before passing it to the internal connections map under the
corresponding key.
Some tests that are covering error cases, are also checking the other
return value besides the error. That check has been removed since it
is redundant.
Revised the RPC/BiRPC clients' constructors (for use in tests)
A different approach has been chosen for the handling of ping methods
within subsystems. Instead of defining the same structure in every file,
the ping methods were added inside the Service constructor function.
Though the existing Ping methods were left as they were, they will be
removed in the future.
An additional method has been implemented to register the Ping method
from outside of the engine package.
Implemented Sleep and CapsError methods for SessionS (before they were
exclusively for bidirectional use, I believe).
A specific issue has been fixed within the CapsError SessionSv1 API
implementation, which is designed to overwrite methods that cannot be
allocated due to the threshold limit being reached. Previously, it was
deallocating when writing the response, even when a spot hadn't been
allocated in the first place (due to the cap being hit). The reason
behind this, especially why the test was passing before, still needs
to be looked into, as the problem should have occurred from before.
Implement `*SessionSv1.RegisterInternalBiJSONConn` method in apier.
All agent methods have been registered under the SessionSv1 name. For
the correct method names, the leading "V1" prefix has been trimmed
using the `birpc.NewServiceWithMethodsRename` function.
Revise the RegisterRpcParams function to populate the parameters
while relying on the `*birpc.Service` type instead. This will
automatically also deal with the validation. At the moment,
any error encountered is logged without being returned. Might
be changed in the future.
Inside the cgrRPCAction function, `mapstructure.Decode`'s output parameter
is now guaranteed to always be a pointer.
Updated go.mod and go.sum.
Fixed some typos.
1467 lines
67 KiB
Go
1467 lines
67 KiB
Go
//go:build integration
|
|
// +build integration
|
|
|
|
/*
|
|
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 general_tests
|
|
|
|
// import (
|
|
// "net/rpc"
|
|
// "net/rpc/jsonrpc"
|
|
// "os"
|
|
// "path"
|
|
// "reflect"
|
|
// "testing"
|
|
// "time"
|
|
|
|
// "github.com/cgrates/cgrates/apier/v1"
|
|
// "github.com/cgrates/cgrates/apier/v2"
|
|
// "github.com/cgrates/cgrates/config"
|
|
// "github.com/cgrates/cgrates/engine"
|
|
// "github.com/cgrates/cgrates/utils"
|
|
// )
|
|
|
|
// var tutLocalCfgPath string
|
|
// var tutFsLocalCfg *config.CGRConfig
|
|
// var tutLocalRpc *birpc.Client
|
|
// var loadInst utils.LoadInstance // Share load information between tests
|
|
|
|
// func TestTutITInitCfg(t *testing.T) {
|
|
// tutLocalCfgPath = path.Join(**dataDir, "conf", "samples", "tutmysql")
|
|
// // Init config first
|
|
// var err error
|
|
// tutFsLocalCfg, err = config.NewCGRConfigFromPath(tutLocalCfgPath)
|
|
// if err != nil {
|
|
// t.Error(err)
|
|
// }
|
|
// tutFsLocalCfg.DataFolderPath = **dataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
|
// config.SetCgrConfig(tutFsLocalCfg)
|
|
// }
|
|
|
|
// // Remove data in dataDB
|
|
// func TestTutITResetDataDb(t *testing.T) {
|
|
// if err := engine.InitDataDb(tutFsLocalCfg); err != nil {
|
|
// t.Fatal(err)
|
|
// }
|
|
// }
|
|
|
|
// // Wipe out the cdr database
|
|
// func TestTutITResetStorDb(t *testing.T) {
|
|
// if err := engine.InitStorDb(tutFsLocalCfg); err != nil {
|
|
// t.Fatal(err)
|
|
// }
|
|
// }
|
|
|
|
// // Start CGR Engine
|
|
// func TestTutITStartEngine(t *testing.T) {
|
|
// if _, err := engine.StopStartEngine(tutLocalCfgPath, **waitRater); err != nil {
|
|
// t.Fatal(err)
|
|
// }
|
|
// }
|
|
|
|
// // Connect rpc client to rater
|
|
// func TestTutITRpcConn(t *testing.T) {
|
|
// var err error
|
|
// tutLocalRpc, err = jsonrpc.Dial(utils.TCP, tutFsLocalCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
|
// if err != nil {
|
|
// t.Fatal(err)
|
|
// }
|
|
// }
|
|
|
|
// // Load the tariff plan, creating accounts and their balances
|
|
// func TestTutITLoadTariffPlanFromFolder(t *testing.T) {
|
|
// attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(**dataDir, "tariffplans", "oldtutorial")}
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil {
|
|
// t.Error(err)
|
|
// }
|
|
// time.Sleep(100*time.Millisecond + time.Duration(**waitRater)*time.Millisecond) // Give time for scheduler to execute topups
|
|
// }
|
|
|
|
// // Check loaded stats
|
|
// func TestTutITCacheStats(t *testing.T) {
|
|
// var reply string
|
|
// if err := tutLocalRpc.Call("APIerSv1.LoadCache", utils.AttrReloadCache{}, &reply); err != nil {
|
|
// t.Error(err)
|
|
// } else if reply != utils.OK {
|
|
// t.Error(reply)
|
|
// }
|
|
// var rcvStats *utils.CacheStats
|
|
// expectedStats := &utils.CacheStats{Destinations: 5, ReverseDestinations: 7, RatingPlans: 4, RatingProfiles: 10,
|
|
// Actions: 9, ActionPlans: 4, AccountActionPlans: 5, SharedGroups: 1, DerivedChargers: 1, LcrProfiles: 5,
|
|
// Aliases: 1, ReverseAliases: 2, ResourceProfiles: 3, Resources: 3, StatQueues: 1, StatQueueProfiles: 1, Thresholds: 7,
|
|
// ThresholdProfiles: 7, Filters: 16, SupplierProfiles: 3, AttributeProfiles: 1,
|
|
// CdrStats: 0, Users: 0} // CdrStats and Users are 0 because deprecated. To be removed
|
|
// var args utils.AttrCacheStats
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv1GetCacheStats, args, &rcvStats); err != nil {
|
|
// t.Error("Got error on APIerSv1.GetCacheStats: ", err.Error())
|
|
// } else if !reflect.DeepEqual(expectedStats, rcvStats) {
|
|
// t.Errorf("Calling APIerSv1.GetCacheStats expected: %+v, received: %+v", utils.ToJSON(expectedStats), utils.ToJSON(rcvStats))
|
|
// }
|
|
// expKeys := utils.ArgsCache{
|
|
// DestinationIDs: &[]string{"DST_1003", "DST_1002", "DST_DE_MOBILE", "DST_1007", "DST_FS"},
|
|
// RatingPlanIDs: &[]string{"RP_RETAIL1", "RP_GENERIC"},
|
|
// }
|
|
// var rcvKeys utils.ArgsCache
|
|
// argsAPI := utils.ArgsCacheKeys{ArgsCache: utils.ArgsCache{
|
|
// DestinationIDs: &[]string{}, RatingPlanIDs: &[]string{"RP_RETAIL1", "RP_GENERIC", "NONEXISTENT"}}}
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv1GetCacheKeys, argsAPI, &rcvKeys); err != nil {
|
|
// t.Error("Got error on APIerSv1.GetCacheStats: ", err.Error())
|
|
// } else {
|
|
// if rcvKeys.DestinationIDs == nil {
|
|
// t.Errorf("Expecting rcvKeys.DestinationIDs to not be nil")
|
|
// // rcvKeys.DestinationIDs shoud not be nil so exit function
|
|
// // to avoid nil segmentation fault;
|
|
// // if this happens try to run this test manualy
|
|
// return
|
|
// }
|
|
// if len(*expKeys.DestinationIDs) != len(*rcvKeys.DestinationIDs) {
|
|
// t.Errorf("Expected: %+v, received: %+v", expKeys.DestinationIDs, rcvKeys.DestinationIDs)
|
|
// }
|
|
// if !reflect.DeepEqual(*expKeys.RatingPlanIDs, *rcvKeys.RatingPlanIDs) {
|
|
// t.Errorf("Expected: %+v, received: %+v", expKeys.RatingPlanIDs, rcvKeys.RatingPlanIDs)
|
|
// }
|
|
// }
|
|
// if _, err := engine.StopStartEngine(tutLocalCfgPath, 1500); err != nil {
|
|
// t.Fatal(err)
|
|
// }
|
|
// var err error
|
|
// tutLocalRpc, err = jsonrpc.Dial(utils.TCP, tutFsLocalCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
|
// if err != nil {
|
|
// t.Fatal(err)
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv1GetCacheStats, args, &rcvStats); err != nil {
|
|
// t.Error("Got error on APIerSv1.GetCacheStats: ", err.Error())
|
|
// } else if !reflect.DeepEqual(expectedStats, rcvStats) {
|
|
// t.Errorf("Calling APIerSv1.GetCacheStats expected: %+v, received: %+v", expectedStats, rcvStats)
|
|
// }
|
|
// }
|
|
|
|
// // Deprecated
|
|
// // func TestTutITGetUsers(t *testing.T) {
|
|
// // var users engine.UserProfiles
|
|
// // if err := tutLocalRpc.Call("UsersV1.GetUsers", engine.UserProfile{}, &users); err != nil {
|
|
// // t.Error("Got error on UsersV1.GetUsers: ", err.Error())
|
|
// // } else if len(users) != 3 {
|
|
// // t.Error("Calling UsersV1.GetUsers got users:", len(users))
|
|
// // }
|
|
// // }
|
|
|
|
// // func TestTutITGetMatchingAlias(t *testing.T) {
|
|
// // args := engine.AttrMatchingAlias{
|
|
// // Destination: "1005",
|
|
// // Tenant: "cgrates.org",
|
|
// // Category: "call",
|
|
// // Account: "1006",
|
|
// // Subject: "1006",
|
|
// // Context: utils.MetaRating,
|
|
// // Target: "Account",
|
|
// // Original: "1006",
|
|
// // }
|
|
// // eMatchingAlias := "1002"
|
|
// // var matchingAlias string
|
|
// // if err := tutLocalRpc.Call("AliasesV1.GetMatchingAlias", args, &matchingAlias); err != nil {
|
|
// // t.Error(err)
|
|
// // } else if matchingAlias != eMatchingAlias {
|
|
// // t.Errorf("Expecting: %s, received: %+v", eMatchingAlias, matchingAlias)
|
|
// // }
|
|
// // }
|
|
|
|
// // Check call costs
|
|
// func TestTutITGetCosts(t *testing.T) {
|
|
// tStart, _ := utils.ParseDate("2014-08-04T13:00:00Z")
|
|
// tEnd, _ := utils.ParseDate("2014-08-04T13:00:20Z")
|
|
// cd := engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1002",
|
|
// DurationIndex: 0,
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// }
|
|
// var cc engine.CallCost
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.Cost != 0.6 {
|
|
// t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost)
|
|
// }
|
|
// // Make sure that the same cost is returned via users aliasing
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: utils.USERS,
|
|
// Subject: utils.USERS,
|
|
// Account: utils.USERS,
|
|
// Destination: "1002",
|
|
// DurationIndex: 0,
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// ExtraFields: map[string]string{"Uuid": "388539dfd4f5cefee8f488b78c6c244b9e19138e"},
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.Cost != 0.6 {
|
|
// t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost)
|
|
// }
|
|
// tStart, _ = utils.ParseDate("2014-08-04T13:00:00Z")
|
|
// tEnd, _ = utils.ParseDate("2014-08-04T13:01:25Z")
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1002",
|
|
// DurationIndex: 0,
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.Cost != 0.6418 { // 0.01 first minute, 0.04 25 seconds with RT_20CNT
|
|
// t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost)
|
|
// }
|
|
// tStart, _ = utils.ParseDate("2014-08-04T13:00:00Z")
|
|
// tEnd, _ = utils.ParseDate("2014-08-04T13:00:20Z")
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1003",
|
|
// DurationIndex: 0,
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.Cost != 1 {
|
|
// t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost)
|
|
// }
|
|
// tStart, _ = utils.ParseDate("2014-08-04T13:00:00Z")
|
|
// tEnd, _ = utils.ParseDate("2014-08-04T13:01:25Z")
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1003",
|
|
// DurationIndex: 0,
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.Cost != 1.3 {
|
|
// t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost)
|
|
// }
|
|
// tStart, _ = utils.ParseDate("2014-08-04T13:00:00Z")
|
|
// tEnd, _ = utils.ParseDate("2014-08-04T13:00:20Z")
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1004",
|
|
// DurationIndex: 0,
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.Cost != 1 {
|
|
// t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost)
|
|
// }
|
|
// tStart, _ = utils.ParseDate("2014-08-04T13:00:00Z")
|
|
// tEnd, _ = utils.ParseDate("2014-08-04T13:01:25Z")
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1004",
|
|
// DurationIndex: 0,
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.Cost != 1.3 {
|
|
// t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost)
|
|
// }
|
|
// tStart = time.Date(2014, 8, 4, 13, 0, 0, 0, time.UTC)
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1007",
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tStart.Add(50 * time.Second),
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.Cost != 0.5 {
|
|
// t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
|
|
// }
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1007",
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tStart.Add(70 * time.Second),
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.Cost != 0.62 {
|
|
// t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost)
|
|
// }
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1002",
|
|
// Account: "1002",
|
|
// Destination: "1007",
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tStart.Add(50 * time.Second),
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.Cost != 0.5 {
|
|
// t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
|
|
// }
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1002",
|
|
// Account: "1002",
|
|
// Destination: "1007",
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tStart.Add(70 * time.Second),
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.Cost != 0.7 { // In case of *disconnect strategy, it will not be applied so we can go on negative costs
|
|
// t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
|
|
// }
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1004",
|
|
// TimeStart: time.Date(2016, 1, 6, 19, 0, 0, 0, time.UTC),
|
|
// TimeEnd: time.Date(2016, 1, 6, 19, 1, 30, 0, time.UTC),
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.Cost != 0.3249 { //
|
|
// t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
|
|
// }
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1004",
|
|
// TimeStart: time.Date(2016, 1, 6, 18, 31, 5, 0, time.UTC),
|
|
// TimeEnd: time.Date(2016, 1, 6, 18, 32, 35, 0, time.UTC),
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.Cost != 1.3 { //
|
|
// t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
|
|
// }
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1002",
|
|
// TimeStart: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC),
|
|
// TimeEnd: time.Date(2014, 12, 7, 8, 44, 26, 0, time.UTC),
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.Cost != 0.3498 { //
|
|
// t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
|
|
// }
|
|
// }
|
|
|
|
// // Check call costs
|
|
// func TestTutITMaxDebit(t *testing.T) {
|
|
// tStart := time.Date(2014, 8, 4, 13, 0, 0, 0, time.UTC)
|
|
// cd := engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1002",
|
|
// DurationIndex: 0,
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tStart.Add(20 * time.Second),
|
|
// }
|
|
// var cc engine.CallCost
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderMaxDebit, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.GetDuration() == 20 {
|
|
// t.Errorf("Calling Responder.MaxDebit got callcost: %v", cc.GetDuration())
|
|
// }
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1003",
|
|
// DurationIndex: 0,
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tStart.Add(200 * time.Second),
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderMaxDebit, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.MaxDebit: ", err.Error())
|
|
// } else if cc.GetDuration() == 200 {
|
|
// t.Errorf("Calling Responder.MaxDebit got duration: %v", cc.GetDuration())
|
|
// }
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1007",
|
|
// DurationIndex: 0,
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tStart.Add(120 * time.Second),
|
|
// }
|
|
// cd.CgrID = "1"
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderMaxDebit, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.GetDuration() == 120 {
|
|
// t.Errorf("Calling Responder.MaxDebit got callcost: %v", cc.GetDuration())
|
|
// }
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1004",
|
|
// Account: "1004",
|
|
// Destination: "1007",
|
|
// DurationIndex: 0,
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tStart.Add(120 * time.Second),
|
|
// }
|
|
// cd.CgrID = "2"
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.ResponderMaxDebit, cd, &cc); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if cc.GetDuration() != 62*time.Second { // We have as strategy *dsconnect
|
|
// t.Errorf("Calling Responder.MaxDebit got callcost: %v", cc.GetDuration())
|
|
// }
|
|
// var maxTime float64
|
|
// if err := tutLocalRpc.Call("Responder.GetMaxSessionTime", cd, &maxTime); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if maxTime != 62000000000 { // We have as strategy *dsconnect
|
|
// t.Errorf("Calling Responder.GetMaxSessionTime got maxTime: %f", maxTime)
|
|
// }
|
|
// }
|
|
|
|
// // Check call costs
|
|
// func TestTutITDerivedMaxSessionTime(t *testing.T) {
|
|
// tStart := time.Date(2014, 8, 4, 13, 0, 0, 0, time.UTC)
|
|
// ev := engine.CDR{
|
|
// CGRID: utils.Sha1("testevent1", tStart.String()),
|
|
// ToR: utils.VOICE,
|
|
// OriginID: "testevent1",
|
|
// OriginHost: "127.0.0.1",
|
|
// RequestType: utils.META_PREPAID,
|
|
// Tenant: "cgrates.org",
|
|
// Category: "call",
|
|
// Account: "1004",
|
|
// Subject: "1004",
|
|
// Destination: "1007",
|
|
// SetupTime: tStart,
|
|
// AnswerTime: tStart,
|
|
// Usage: 120 * time.Second,
|
|
// Cost: -1,
|
|
// }
|
|
// var maxTime float64
|
|
// if err := tutLocalRpc.Call("Responder.GetDerivedMaxSessionTime", ev, &maxTime); err != nil {
|
|
// t.Error("Got error on Responder.GetCost: ", err.Error())
|
|
// } else if maxTime != 62000000000 { // We have as strategy *dsconnect
|
|
// t.Errorf("Calling Responder.GetMaxSessionTime got maxTime: %f", maxTime)
|
|
// }
|
|
// }
|
|
|
|
// // Check MaxUsage
|
|
// func TestTutITMaxUsage(t *testing.T) {
|
|
// setupReq := &engine.UsageRecord{ToR: utils.VOICE,
|
|
// RequestType: utils.META_PREPAID, Tenant: "cgrates.org", Category: "call",
|
|
// Account: "1003", Subject: "1003", Destination: "1001",
|
|
// SetupTime: "2014-08-04T13:00:00Z", Usage: "1s",
|
|
// }
|
|
// var maxTime float64
|
|
// if err := tutLocalRpc.Call("APIerSv2.GetMaxUsage", setupReq, &maxTime); err != nil {
|
|
// t.Error(err)
|
|
// } else if maxTime != 1 {
|
|
// t.Errorf("Calling APIerSv2.MaxUsage got maxTime: %f", maxTime)
|
|
// }
|
|
// setupReq = &engine.UsageRecord{ToR: utils.VOICE, RequestType: utils.MetaRated, Tenant: "cgrates.org", Category: "call",
|
|
// Account: "test_max_usage", Destination: "1001",
|
|
// SetupTime: "2014-08-04T13:00:00Z",
|
|
// }
|
|
// if err := tutLocalRpc.Call("APIerSv2.GetMaxUsage", setupReq, &maxTime); err != nil {
|
|
// t.Error(err)
|
|
// } else if maxTime != -1 {
|
|
// t.Errorf("Calling APIerSv2.MaxUsage got maxTime: %f", maxTime)
|
|
// }
|
|
// }
|
|
|
|
// // Check DebitUsage
|
|
// func TestTutITDebitUsage(t *testing.T) {
|
|
// setupReq := &engine.UsageRecord{ToR: utils.VOICE, RequestType: utils.META_PREPAID, Tenant: "cgrates.org", Category: "call",
|
|
// Account: "1003", Subject: "1003", Destination: "1001",
|
|
// AnswerTime: "2014-08-04T13:00:00Z", Usage: "1",
|
|
// }
|
|
// var reply string
|
|
// if err := tutLocalRpc.Call("APIerSv2.DebitUsage", setupReq, &reply); err != nil {
|
|
// t.Error(err)
|
|
// } else if reply != utils.OK {
|
|
// t.Error("Calling APIerSv2.DebitUsage reply: ", reply)
|
|
// }
|
|
// }
|
|
|
|
// // Test CDR from external sources
|
|
// func TestTutITProcessExternalCdr(t *testing.T) {
|
|
// cdr := &engine.ExternalCDR{ToR: utils.VOICE,
|
|
// OriginID: "testextcdr1", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.MetaRated,
|
|
// Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1001",
|
|
// SetupTime: "2014-08-04T13:00:00Z", AnswerTime: "2014-08-04T13:00:07Z",
|
|
// Usage: "1", ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"},
|
|
// }
|
|
// var reply string
|
|
// if err := tutLocalRpc.Call("CdrsV1.ProcessExternalCdr", cdr, &reply); err != nil {
|
|
// t.Error("Unexpected error: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Error("Unexpected reply received: ", reply)
|
|
// }
|
|
// }
|
|
|
|
// // Test CDR involving UserProfile
|
|
// func TestTutITProcessExternalCdrUP(t *testing.T) {
|
|
// cdr := &engine.ExternalCDR{ToR: utils.VOICE,
|
|
// OriginID: "testextcdr2", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST,
|
|
// RequestType: utils.USERS, Tenant: utils.USERS, Account: utils.USERS, Destination: "1001",
|
|
// SetupTime: "2014-08-04T13:00:00Z", AnswerTime: "2014-08-04T13:00:07Z", Usage: "2s",
|
|
// ExtraFields: map[string]string{"Cli": "+4986517174964", "fieldextr2": "valextr2", "SysUserName": utils.USERS},
|
|
// }
|
|
// var reply string
|
|
// if err := tutLocalRpc.Call("CdrsV1.ProcessExternalCdr", cdr, &reply); err != nil {
|
|
// t.Error("Unexpected error: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Error("Unexpected reply received: ", reply)
|
|
// }
|
|
// time.Sleep(time.Duration(**waitRater) * time.Millisecond)
|
|
// eCdr := &engine.ExternalCDR{CGRID: "63a8d2bfeca2cfb790826c3ec461696d6574cfde", OrderID: 2,
|
|
// ToR: utils.VOICE,
|
|
// OriginID: "testextcdr2", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.MetaRated,
|
|
// Tenant: "cgrates.org", Category: "call", Account: "1004", Subject: "1004", Destination: "1001",
|
|
// SetupTime: time.Date(2014, 8, 4, 13, 0, 0, 0, time.UTC).Local().Format(time.RFC3339),
|
|
// AnswerTime: time.Date(2014, 8, 4, 13, 0, 7, 0, time.UTC).Local().Format(time.RFC3339), Usage: "2s",
|
|
// ExtraFields: map[string]string{"Cli": "+4986517174964", "fieldextr2": "valextr2", "SysUserName": "danb4"},
|
|
// RunID: utils.MetaDefault, Cost: 1}
|
|
// var cdrs []*engine.ExternalCDR
|
|
// req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault},
|
|
// Accounts: []string{"1004"}, DestinationPrefixes: []string{"1001"}}
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2GetCDRs, 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].CGRID != eCdr.CGRID {
|
|
// t.Errorf("Unexpected CGRID for CDR: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].ToR != eCdr.ToR {
|
|
// t.Errorf("Unexpected ToR for CDR: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].Source != eCdr.Source {
|
|
// t.Errorf("Unexpected Source for CDR: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].RequestType != eCdr.RequestType {
|
|
// t.Errorf("Unexpected RequestType for CDR: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].Tenant != eCdr.Tenant {
|
|
// t.Errorf("Unexpected Tenant for CDR: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].Category != eCdr.Category {
|
|
// t.Errorf("Unexpected Category for CDR: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].Account != eCdr.Account {
|
|
// t.Errorf("Unexpected Account for CDR: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].Subject != eCdr.Subject {
|
|
// t.Errorf("Unexpected Subject for CDR: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].Destination != eCdr.Destination {
|
|
// t.Errorf("Unexpected Destination for CDR: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].SetupTime != eCdr.SetupTime {
|
|
// t.Errorf("Unexpected SetupTime for CDR: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].AnswerTime != eCdr.AnswerTime {
|
|
// t.Errorf("Unexpected AnswerTime for CDR: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].Usage != eCdr.Usage {
|
|
// t.Errorf("Unexpected Usage for CDR: %+v", cdrs[0])
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// func TestTutITCostErrors(t *testing.T) {
|
|
// cdr := &engine.ExternalCDR{ToR: utils.VOICE,
|
|
// OriginID: "TestTutIT_1", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.MetaRated,
|
|
// Tenant: "cgrates.org", Category: "fake", Account: "2001", Subject: "2001", Destination: "1001",
|
|
// SetupTime: "2014-08-04T13:00:00Z", AnswerTime: "2014-08-04T13:00:07Z",
|
|
// Usage: "1", ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"},
|
|
// }
|
|
// var reply string
|
|
// if err := tutLocalRpc.Call("CdrsV1.ProcessExternalCdr", cdr, &reply); err != nil {
|
|
// t.Error("Unexpected error: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Error("Unexpected reply received: ", reply)
|
|
// }
|
|
// time.Sleep(time.Duration(**waitRater) * time.Millisecond)
|
|
// var cdrs []*engine.ExternalCDR
|
|
// req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, Accounts: []string{cdr.Account}, DestinationPrefixes: []string{cdr.Destination}}
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2GetCDRs, 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].OriginID != cdr.OriginID {
|
|
// t.Errorf("Unexpected OriginID for Cdr received: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].Cost != -1 {
|
|
// t.Errorf("Unexpected Cost for Cdr received: %+v", cdrs[0])
|
|
// }
|
|
// }
|
|
// cdr2 := &engine.ExternalCDR{ToR: utils.VOICE,
|
|
// OriginID: "TestTutIT_2", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.MetaPostpaid ,
|
|
// Tenant: "cgrates.org", Category: "fake", Account: "2002", Subject: "2002", Destination: "1001",
|
|
// SetupTime: "2014-08-04T13:00:00Z", AnswerTime: "2014-08-04T13:00:07Z",
|
|
// Usage: "1", ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"},
|
|
// }
|
|
// if err := tutLocalRpc.Call("CdrsV1.ProcessExternalCdr", cdr2, &reply); err != nil {
|
|
// t.Error("Unexpected error: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Error("Unexpected reply received: ", reply)
|
|
// }
|
|
// time.Sleep(time.Duration(**waitRater) * time.Millisecond) // Give time for CDR to be processed
|
|
// req = utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, Accounts: []string{cdr2.Account}, DestinationPrefixes: []string{cdr2.Destination}}
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2GetCDRs, 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].OriginID != cdr2.OriginID {
|
|
// t.Errorf("Unexpected OriginID for Cdr received: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].Cost != -1 {
|
|
// t.Errorf("Unexpected Cost for Cdr received: %+v", cdrs[0])
|
|
// }
|
|
// }
|
|
// cdr3 := &engine.ExternalCDR{ToR: utils.VOICE,
|
|
// OriginID: "TestTutIT_3", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.MetaPostpaid ,
|
|
// Tenant: "cgrates.org", Category: "fake", Account: "1001", Subject: "1001", Destination: "2002",
|
|
// SetupTime: "2014-08-04T13:00:00Z", AnswerTime: "2014-08-04T13:00:07Z",
|
|
// Usage: "1", ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"},
|
|
// }
|
|
// if err := tutLocalRpc.Call("CdrsV1.ProcessExternalCdr", cdr3, &reply); err != nil {
|
|
// t.Error("Unexpected error: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Error("Unexpected reply received: ", reply)
|
|
// }
|
|
// time.Sleep(time.Duration(**waitRater) * time.Millisecond) // Give time for CDR to be processed
|
|
// req = utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, Accounts: []string{cdr3.Account}, DestinationPrefixes: []string{cdr3.Destination}}
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2GetCDRs, 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].OriginID != cdr3.OriginID {
|
|
// t.Errorf("Unexpected OriginID for Cdr received: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].Cost != -1 {
|
|
// t.Errorf("Unexpected Cost for Cdr received: %+v", cdrs[0])
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// // Make sure queueids were created
|
|
// func TestTutITCdrStats(t *testing.T) {
|
|
// var queueIds []string
|
|
// eQueueIds := []string{"CDRST1", "CDRST_1001", "CDRST_1002", "CDRST_1003", "STATS_SUPPL1", "STATS_SUPPL2"}
|
|
// if err := tutLocalRpc.Call("CDRStatsV1.GetQueueIds", "", &queueIds); err != nil {
|
|
// t.Error("Calling CDRStatsV1.GetQueueIds, got error: ", err.Error())
|
|
// } else if len(eQueueIds) != len(queueIds) {
|
|
// t.Errorf("Expecting: %v, received: %v", eQueueIds, queueIds)
|
|
// }
|
|
// }
|
|
|
|
// func TestTutITLeastCost(t *testing.T) {
|
|
// tStart, _ := utils.ParseDate("2014-08-04T13:00:00Z")
|
|
// tEnd, _ := utils.ParseDate("2014-08-04T13:01:00Z")
|
|
// cd := engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1005",
|
|
// Account: "1005",
|
|
// Destination: "1002",
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// }
|
|
// eStLcr := &engine.LCRCost{
|
|
// Entry: &engine.LCREntry{DestinationId: "DST_1002", RPCategory: "lcr_profile2", Strategy: engine.LCR_STRATEGY_LOWEST, StrategyParams: "", Weight: 10.0},
|
|
// SupplierCosts: []*engine.LCRSupplierCost{
|
|
// {Supplier: "*out:cgrates.org:lcr_profile2:suppl3", Cost: 0.01, Duration: 60 * time.Second},
|
|
// {Supplier: "*out:cgrates.org:lcr_profile2:suppl1", Cost: 0.6, Duration: 60 * time.Second},
|
|
// {Supplier: "*out:cgrates.org:lcr_profile2:suppl2", Cost: 1.2, Duration: 60 * time.Second},
|
|
// },
|
|
// }
|
|
// var lcr engine.LCRCost
|
|
// cd.CgrID = "10"
|
|
// cd.RunID = "10"
|
|
// if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil {
|
|
// t.Error(err)
|
|
// } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry)
|
|
// } else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts, lcr.SupplierCosts)
|
|
// }
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1005",
|
|
// Account: "1005",
|
|
// Destination: "1003",
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// }
|
|
// eStLcr = &engine.LCRCost{
|
|
// Entry: &engine.LCREntry{DestinationId: utils.ANY, RPCategory: "lcr_profile1", Strategy: engine.LCR_STRATEGY_LOWEST, StrategyParams: "", Weight: 10.0},
|
|
// SupplierCosts: []*engine.LCRSupplierCost{
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl1", Cost: 1.2, Duration: 60 * time.Second},
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl2", Cost: 1.2, Duration: 60 * time.Second},
|
|
// },
|
|
// }
|
|
// eStLcr2 := &engine.LCRCost{
|
|
// Entry: &engine.LCREntry{DestinationId: utils.ANY, RPCategory: "lcr_profile1", Strategy: engine.LCR_STRATEGY_LOWEST, StrategyParams: "", Weight: 10.0},
|
|
// SupplierCosts: []*engine.LCRSupplierCost{
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl2", Cost: 1.2, Duration: 60 * time.Second},
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl1", Cost: 1.2, Duration: 60 * time.Second},
|
|
// },
|
|
// }
|
|
// cd.CgrID = "11"
|
|
// cd.RunID = "11"
|
|
// if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil {
|
|
// t.Error(err)
|
|
// } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry)
|
|
// } else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) && !reflect.DeepEqual(eStLcr2.SupplierCosts, lcr.SupplierCosts) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts[0], lcr.SupplierCosts[0])
|
|
// }
|
|
// }
|
|
|
|
// // Check LCR
|
|
// func TestTutITLcrStatic(t *testing.T) {
|
|
// tStart, _ := utils.ParseDate("2014-08-04T13:00:00Z")
|
|
// tEnd, _ := utils.ParseDate("2014-08-04T13:01:00Z")
|
|
// cd := engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1002",
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// }
|
|
// eStLcr := &engine.LCRCost{
|
|
// Entry: &engine.LCREntry{DestinationId: "DST_1002", RPCategory: "lcr_profile1", Strategy: engine.LCR_STRATEGY_STATIC, StrategyParams: "suppl2;suppl1", Weight: 10.0},
|
|
// SupplierCosts: []*engine.LCRSupplierCost{
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl2", Cost: 0.6, Duration: 60 * time.Second},
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl1", Cost: 1.2, Duration: 60 * time.Second},
|
|
// },
|
|
// }
|
|
// var lcr engine.LCRCost
|
|
// cd.CgrID = "1"
|
|
// cd.RunID = "1"
|
|
// if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil {
|
|
// t.Error(err)
|
|
// } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry)
|
|
// } else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts[0], lcr.SupplierCosts[0])
|
|
// }
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1001",
|
|
// Account: "1001",
|
|
// Destination: "1003",
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// }
|
|
// eStLcr = &engine.LCRCost{
|
|
// Entry: &engine.LCREntry{DestinationId: utils.ANY, RPCategory: "lcr_profile1", Strategy: engine.LCR_STRATEGY_STATIC, StrategyParams: "suppl1;suppl2", Weight: 10.0},
|
|
// SupplierCosts: []*engine.LCRSupplierCost{
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl1", Cost: 1.2, Duration: 60 * time.Second},
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl2", Cost: 1.2, Duration: 60 * time.Second},
|
|
// },
|
|
// }
|
|
// cd.CgrID = "2"
|
|
// cd.RunID = "2"
|
|
// if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil {
|
|
// t.Error(err)
|
|
// } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry)
|
|
// } else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts[0], lcr.SupplierCosts[0])
|
|
// }
|
|
// }
|
|
|
|
// func TestTutITLcrHighestCost(t *testing.T) {
|
|
// tStart, _ := utils.ParseDate("2014-08-04T13:00:00Z")
|
|
// tEnd, _ := utils.ParseDate("2014-08-04T13:01:00Z")
|
|
// cd := engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1002",
|
|
// Account: "1002",
|
|
// Destination: "1002",
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// }
|
|
// eStLcr := &engine.LCRCost{
|
|
// Entry: &engine.LCREntry{DestinationId: "DST_1002", RPCategory: "lcr_profile1", Strategy: engine.LCR_STRATEGY_HIGHEST, StrategyParams: "", Weight: 10.0},
|
|
// SupplierCosts: []*engine.LCRSupplierCost{
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl1", Cost: 1.2, Duration: 60 * time.Second},
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl2", Cost: 0.6, Duration: 60 * time.Second},
|
|
// },
|
|
// }
|
|
// var lcr engine.LCRCost
|
|
// if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil {
|
|
// t.Error(err)
|
|
// } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry)
|
|
// } else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts[0], lcr.SupplierCosts[0])
|
|
// }
|
|
// // LCR with Alias
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1006",
|
|
// Account: "1006",
|
|
// Destination: "1002",
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// }
|
|
// if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil {
|
|
// t.Error(err)
|
|
// } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eStLcr.Entry), utils.ToJSON(lcr.Entry))
|
|
// } else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts[0], lcr.SupplierCosts[0])
|
|
// }
|
|
// }
|
|
|
|
// func TestTutITLcrQos(t *testing.T) {
|
|
// tStart, _ := utils.ParseDate("2014-08-04T13:00:00Z")
|
|
// tEnd, _ := utils.ParseDate("2014-08-04T13:01:00Z")
|
|
// cd := engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1002",
|
|
// Account: "1002",
|
|
// Destination: "1003",
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// }
|
|
// eStLcr := &engine.LCRCost{
|
|
// Entry: &engine.LCREntry{DestinationId: utils.ANY, RPCategory: "lcr_profile1",
|
|
// Strategy: engine.LCR_STRATEGY_QOS, StrategyParams: "", Weight: 10.0},
|
|
// SupplierCosts: []*engine.LCRSupplierCost{
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl1",
|
|
// Cost: 1.2, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: -1, engine.ACC: -1, engine.TCC: -1,
|
|
// engine.ASR: -1, engine.ACD: -1, engine.DDC: -1}},
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl2",
|
|
// Cost: 1.2, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: -1, engine.ACC: -1, engine.TCC: -1,
|
|
// engine.ASR: -1, engine.ACD: -1, engine.DDC: -1}},
|
|
// },
|
|
// }
|
|
// /*
|
|
// eStLcr2 := &engine.LCRCost{
|
|
// Entry: &engine.LCREntry{DestinationId: utils.ANY, RPCategory: "lcr_profile1",
|
|
// Strategy: engine.LCR_STRATEGY_QOS, StrategyParams: "", Weight: 10.0},
|
|
// SupplierCosts: []*engine.LCRSupplierCost{
|
|
// &engine.LCRSupplierCost{Supplier: "*out:cgrates.org:lcr_profile1:suppl2",
|
|
// Cost: 1.2, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: -1, engine.ACC: -1, engine.TCC: -1,
|
|
// engine.ASR: -1, engine.ACD: -1, engine.DDC: -1}},
|
|
// &engine.LCRSupplierCost{Supplier: "*out:cgrates.org:lcr_profile1:suppl1",
|
|
// Cost: 1.2, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: -1, engine.ACC: -1, engine.TCC: -1,
|
|
// engine.ASR: -1, engine.ACD: -1, engine.DDC: -1}},
|
|
// },
|
|
// }
|
|
// */
|
|
// var lcr engine.LCRCost
|
|
// // Since there is no real quality difference, the suppliers will come in random order here
|
|
// cd.CgrID = "3"
|
|
// cd.RunID = "3"
|
|
// /*
|
|
// if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil {
|
|
// t.Error(err)
|
|
// } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry)
|
|
// } else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) &&
|
|
// !reflect.DeepEqual(eStLcr2.SupplierCosts, lcr.SupplierCosts) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts[0], lcr.SupplierCosts[0])
|
|
// }
|
|
// */
|
|
// // Post some CDRs to influence stats
|
|
// testCdr1 := &engine.CDR{CGRID: utils.Sha1("testcdr1",
|
|
// time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC).String()),
|
|
// ToR: utils.VOICE, OriginID: "testcdr1", OriginHost: "192.168.1.1",
|
|
// Source: "TEST_QOS_LCR", RequestType: utils.MetaRated,
|
|
// Tenant: "cgrates.org", Category: "call", Account: "1001",
|
|
// Subject: "1001", Destination: "1002",
|
|
// SetupTime: time.Date(2014, 12, 7, 8, 42, 24, 0, time.UTC),
|
|
// AnswerTime: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC),
|
|
// Usage: 2 * time.Minute,
|
|
// ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}}
|
|
// testCdr2 := &engine.CDR{CGRID: utils.Sha1("testcdr2",
|
|
// time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC).String()),
|
|
// ToR: utils.VOICE, OriginID: "testcdr2", OriginHost: "192.168.1.1",
|
|
// Source: "TEST_QOS_LCR", RequestType: utils.MetaRated,
|
|
// Tenant: "cgrates.org", Category: "call", Account: "1002",
|
|
// Subject: "1002", Destination: "1003",
|
|
// SetupTime: time.Date(2014, 12, 7, 8, 42, 24, 0, time.UTC),
|
|
// AnswerTime: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC),
|
|
// Usage: 90 * time.Second,
|
|
// ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}}
|
|
// var reply string
|
|
// for _, cdr := range []*engine.CDR{testCdr1, testCdr2} {
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.CDRsV1ProcessCDR, cdr, &reply); err != nil {
|
|
// t.Error("Unexpected error: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Error("Unexpected reply received: ", reply)
|
|
// }
|
|
// }
|
|
// // Based on stats, supplier1 should always be better since he has a higer ACD
|
|
// eStLcr = &engine.LCRCost{
|
|
// Entry: &engine.LCREntry{DestinationId: utils.ANY,
|
|
// RPCategory: "lcr_profile1", Strategy: engine.LCR_STRATEGY_QOS,
|
|
// StrategyParams: "", Weight: 10.0},
|
|
// SupplierCosts: []*engine.LCRSupplierCost{
|
|
// {
|
|
// Supplier: "*out:cgrates.org:lcr_profile1:suppl1",
|
|
// Cost: 1.2, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: 240, engine.ACC: 0.35,
|
|
// engine.TCC: 0.7, engine.ASR: 100, engine.ACD: 120}},
|
|
// {
|
|
// Supplier: "*out:cgrates.org:lcr_profile1:suppl2",
|
|
// Cost: 1.2, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: 90, engine.ACC: 0.325,
|
|
// engine.TCC: 0.325, engine.ASR: 100, engine.ACD: 90}},
|
|
// },
|
|
// }
|
|
// cd.CgrID = "4"
|
|
// cd.RunID = "4"
|
|
// if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil {
|
|
// t.Error(err)
|
|
// } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry)
|
|
// //} else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) && !reflect.DeepEqual(eStLcr2.SupplierCosts, lcr.SupplierCosts) {
|
|
// // t.Errorf("Expecting: %+v, %+v, received: %+v, %+v", eStLcr.SupplierCosts[0], eStLcr.SupplierCosts[1], lcr.SupplierCosts[0], lcr.SupplierCosts[1])
|
|
// }
|
|
// testCdr3 := &engine.CDR{CGRID: utils.Sha1("testcdr3", time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC).String()),
|
|
// ToR: utils.VOICE, OriginID: "testcdr3", OriginHost: "192.168.1.1", Source: "TEST_QOS_LCR", RequestType: utils.MetaRated,
|
|
// Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1004",
|
|
// SetupTime: time.Date(2014, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC),
|
|
// Usage: 180 * time.Second}
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.CDRsV1ProcessCDR, testCdr3, &reply); err != nil {
|
|
// t.Error("Unexpected error: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Error("Unexpected reply received: ", reply)
|
|
// }
|
|
// // Since ACD has considerably increased for supplier2, we should have it as first prio now
|
|
// eStLcr = &engine.LCRCost{
|
|
// Entry: &engine.LCREntry{DestinationId: utils.ANY, RPCategory: "lcr_profile1", Strategy: engine.LCR_STRATEGY_QOS, StrategyParams: "", Weight: 10.0},
|
|
// SupplierCosts: []*engine.LCRSupplierCost{
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl2", Cost: 1.2, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: 270, engine.ACC: 0.3625, engine.TCC: 0.725, engine.ASR: 100, engine.ACD: 135}},
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl1", Cost: 1.2, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: 240, engine.ACC: 0.35, engine.TCC: 0.7, engine.ASR: 100, engine.ACD: 120}},
|
|
// },
|
|
// }
|
|
// cd.CgrID = "5"
|
|
// cd.RunID = "5"
|
|
// if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil {
|
|
// t.Error(err)
|
|
// } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry)
|
|
// //} else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) && !reflect.DeepEqual(eStLcr2.SupplierCosts, lcr.SupplierCosts) {
|
|
// // t.Errorf("Expecting: %+v, %+v, received: %+v, %+v", eStLcr.SupplierCosts[0], eStLcr.SupplierCosts[1], lcr.SupplierCosts[0], lcr.SupplierCosts[1])
|
|
// }
|
|
// }
|
|
|
|
// func TestTutITLcrQosThreshold(t *testing.T) {
|
|
// tStart, _ := utils.ParseDate("2014-08-04T13:00:00Z")
|
|
// tEnd, _ := utils.ParseDate("2014-08-04T13:01:00Z")
|
|
// cd := engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1003",
|
|
// Account: "1003",
|
|
// Destination: "1002",
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// }
|
|
// eLcr := &engine.LCRCost{
|
|
// Entry: &engine.LCREntry{DestinationId: "DST_1002", RPCategory: "lcr_profile1", Strategy: engine.LCR_STRATEGY_QOS_THRESHOLD, StrategyParams: "20;;;;2m;;;;;;;", Weight: 10.0},
|
|
// SupplierCosts: []*engine.LCRSupplierCost{
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl2", Cost: 0.6, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: 270, engine.ACC: 0.3625, engine.TCC: 0.725, engine.ASR: 100, engine.ACD: 135}},
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl1", Cost: 1.2, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: 240, engine.ACC: 0.35, engine.TCC: 0.7, engine.ASR: 100, engine.ACD: 120}},
|
|
// },
|
|
// }
|
|
// var lcr engine.LCRCost
|
|
// cd.CgrID = "6"
|
|
// cd.RunID = "6"
|
|
// if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil {
|
|
// t.Error(err)
|
|
// } else if !reflect.DeepEqual(eLcr.Entry, lcr.Entry) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eLcr.Entry, lcr.Entry)
|
|
// //} else if !reflect.DeepEqual(eLcr.SupplierCosts, lcr.SupplierCosts) {
|
|
// // t.Errorf("Expecting: %+v, %+v received: %+v, %+v", eLcr.SupplierCosts[0], eLcr.SupplierCosts[1], lcr.SupplierCosts[0], lcr.SupplierCosts[1])
|
|
// }
|
|
// testCdr4 := &engine.CDR{CGRID: utils.Sha1("testcdr4", time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC).String()),
|
|
// ToR: utils.VOICE, OriginID: "testcdr4", OriginHost: "192.168.1.1", Source: "TEST_QOS_LCR", RequestType: utils.MetaRated,
|
|
// Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1004",
|
|
// SetupTime: time.Date(2014, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC),
|
|
// Usage: 60 * time.Second}
|
|
// var reply string
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.CDRsV1ProcessCDR, testCdr4, &reply); err != nil { // Should drop ACD under the 2m required by threshold, removing suppl2 from lcr
|
|
// t.Error("Unexpected error: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Error("Unexpected reply received: ", reply)
|
|
// }
|
|
// eLcr = &engine.LCRCost{
|
|
// Entry: &engine.LCREntry{DestinationId: "DST_1002", RPCategory: "lcr_profile1", Strategy: engine.LCR_STRATEGY_QOS_THRESHOLD, StrategyParams: "20;;;;2m;;;;;;;", Weight: 10.0},
|
|
// SupplierCosts: []*engine.LCRSupplierCost{
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl1", Cost: 1.2, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: 240, engine.ACC: 0.35, engine.TCC: 0.7, engine.ASR: 100, engine.ACD: 120}},
|
|
// },
|
|
// }
|
|
// cd.CgrID = "7"
|
|
// cd.RunID = "7"
|
|
// if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil {
|
|
// t.Error(err)
|
|
// } else if !reflect.DeepEqual(eLcr.Entry, lcr.Entry) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eLcr.Entry, lcr.Entry)
|
|
// //} else if !reflect.DeepEqual(eLcr.SupplierCosts, lcr.SupplierCosts) {
|
|
// // t.Errorf("Expecting: %+v, received: %+v", eLcr.SupplierCosts[0], lcr.SupplierCosts[0])
|
|
// }
|
|
// cd = engine.CallDescriptor{
|
|
// Category: "call",
|
|
// Tenant: "cgrates.org",
|
|
// Subject: "1003",
|
|
// Account: "1003",
|
|
// Destination: "1004",
|
|
// TimeStart: tStart,
|
|
// TimeEnd: tEnd,
|
|
// }
|
|
// eLcr = &engine.LCRCost{
|
|
// Entry: &engine.LCREntry{DestinationId: utils.ANY, RPCategory: "lcr_profile1", Strategy: engine.LCR_STRATEGY_QOS_THRESHOLD, StrategyParams: "40;;;;90s;;;;;;;", Weight: 10.0},
|
|
// SupplierCosts: []*engine.LCRSupplierCost{
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl1", Cost: 1.2, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: 240, engine.ACC: 0.35, engine.TCC: 0.7, engine.ASR: 100, engine.ACD: 120}},
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl2", Cost: 1.2, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: 330, engine.ACC: 0.3416666667, engine.TCC: 1.025, engine.ASR: 100, engine.ACD: 110}},
|
|
// },
|
|
// }
|
|
// /*eLcr2 := &engine.LCRCost{
|
|
// Entry: &engine.LCREntry{DestinationId: utils.ANY, RPCategory: "lcr_profile1", Strategy: engine.LCR_STRATEGY_QOS_THRESHOLD, StrategyParams: "40;;90s;;;;;;;", Weight: 10.0},
|
|
// SupplierCosts: []*engine.LCRSupplierCost{
|
|
// &engine.LCRSupplierCost{Supplier: "*out:cgrates.org:lcr_profile1:suppl2", Cost: 1.2, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: 330, engine.ACC: 0.3416666667, engine.TCC: 1.025, engine.ASR: 100, engine.ACD: 110}},
|
|
// &engine.LCRSupplierCost{Supplier: "*out:cgrates.org:lcr_profile1:suppl1", Cost: 1.2, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: 240, engine.ACC: 0.35, engine.TCC: 0.7, engine.ASR: 100, engine.ACD: 120}},
|
|
// },
|
|
// }
|
|
// */
|
|
// cd.CgrID = "8"
|
|
// cd.RunID = "8"
|
|
// if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil {
|
|
// t.Error(err)
|
|
// } else if !reflect.DeepEqual(eLcr.Entry, lcr.Entry) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eLcr.Entry, lcr.Entry)
|
|
// //} else if !reflect.DeepEqual(eLcr.SupplierCosts, lcr.SupplierCosts) && !reflect.DeepEqual(eLcr2.SupplierCosts, lcr.SupplierCosts) {
|
|
// // t.Errorf("Expecting: %+v, received: %+v", eLcr.SupplierCosts[1], lcr.SupplierCosts[1])
|
|
// }
|
|
// testCdr5 := &engine.CDR{CGRID: utils.Sha1("testcdr5", time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC).String()),
|
|
// ToR: utils.VOICE, OriginID: "testcdr5", OriginHost: "192.168.1.1", Source: "TEST_QOS_LCR", RequestType: utils.MetaRated,
|
|
// Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1004",
|
|
// SetupTime: time.Date(2014, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC),
|
|
// Usage: time.Second}
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.CDRsV1ProcessCDR, testCdr5, &reply); err != nil { // Should drop ACD under the 1m required by threshold, removing suppl2 from lcr
|
|
// t.Error("Unexpected error: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Error("Unexpected reply received: ", reply)
|
|
// }
|
|
// eLcr = &engine.LCRCost{
|
|
// Entry: &engine.LCREntry{DestinationId: utils.ANY, RPCategory: "lcr_profile1", Strategy: engine.LCR_STRATEGY_QOS_THRESHOLD, StrategyParams: "40;;;;90s;;;;;;;", Weight: 10.0},
|
|
// SupplierCosts: []*engine.LCRSupplierCost{
|
|
// {Supplier: "*out:cgrates.org:lcr_profile1:suppl1", Cost: 1.2, Duration: 60 * time.Second,
|
|
// QOS: map[string]float64{engine.TCD: 240, engine.ACC: 0.35, engine.TCC: 0.7, engine.ASR: 100, engine.ACD: 120}},
|
|
// },
|
|
// }
|
|
// cd.CgrID = "9"
|
|
// cd.RunID = "9"
|
|
// if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil {
|
|
// t.Error(err)
|
|
// } else if !reflect.DeepEqual(eLcr.Entry, lcr.Entry) {
|
|
// t.Errorf("Expecting: %+v, received: %+v", eLcr.Entry, lcr.Entry)
|
|
// //} else if !reflect.DeepEqual(eLcr.SupplierCosts, lcr.SupplierCosts) {
|
|
// // t.Errorf("Expecting: %+v, received: %+v", eLcr.SupplierCosts[0], lcr.SupplierCosts[0])
|
|
// }
|
|
// }
|
|
|
|
// // Test adding the account via API, using the data previously devined in .csv
|
|
// func TestTutITSetAccount(t *testing.T) {
|
|
// var reply string
|
|
// attrs := &v2.AttrSetAccount{Tenant: "cgrates.org", Account: "tutacnt1", ActionPlanIDs: &[]string{"PACKAGE_10"}, ActionTriggerIDs: &[]string{"STANDARD_TRIGGERS"}, ReloadScheduler: true}
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2SetAccount, attrs, &reply); err != nil {
|
|
// t.Error("Got error on APIerSv2.SetAccount: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Errorf("Calling APIerSv2.SetAccount received: %s", reply)
|
|
// }
|
|
// type AttrGetAccounts struct {
|
|
// Tenant string
|
|
// AccountIds []string
|
|
// Offset int // Set the item offset
|
|
// Limit int // Limit number of items retrieved
|
|
// }
|
|
// time.Sleep(time.Duration(**waitRater) * time.Millisecond) // Give time for scheduler to execute topups
|
|
// var acnts []*engine.Account
|
|
// if err := tutLocalRpc.Call("APIerSv2.GetAccounts", utils.AttrGetAccounts{Tenant: attrs.Tenant, AccountIds: []string{attrs.Account}}, &acnts); err != nil {
|
|
// t.Error(err)
|
|
// } else if len(acnts) != 1 {
|
|
// t.Errorf("Accounts received: %+v", acnts)
|
|
// } else {
|
|
// acnt := acnts[0]
|
|
// dta, _ := utils.NewTAFromAccountKey(acnt.ID)
|
|
// if dta.Tenant != attrs.Tenant || dta.Account != attrs.Account {
|
|
// t.Error("Unexpected account id received: ", acnt.ID)
|
|
// }
|
|
// if balances := acnt.BalanceMap["*monetary"]; len(balances) != 1 {
|
|
// t.Errorf("Unexpected balances found: %+v", balances)
|
|
// }
|
|
// if len(acnt.ActionTriggers) != 4 {
|
|
// t.Errorf("Unexpected action triggers for account: %+v", acnt.ActionTriggers)
|
|
// }
|
|
// if acnt.AllowNegative {
|
|
// t.Error("AllowNegative should not be set")
|
|
// }
|
|
// if acnt.Disabled {
|
|
// t.Error("Disabled should not be set")
|
|
// }
|
|
// }
|
|
// attrs = &v2.AttrSetAccount{Tenant: "cgrates.org", Account: "tutacnt1", ActionPlanIDs: &[]string{"PACKAGE_10"}, ActionTriggerIDs: &[]string{"STANDARD_TRIGGERS"}, AllowNegative: utils.BoolPointer(true), Disabled: utils.BoolPointer(true), ReloadScheduler: true}
|
|
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2SetAccount, attrs, &reply); err != nil {
|
|
// t.Error("Got error on APIerSv2.SetAccount: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Errorf("Calling APIerSv2.SetAccount received: %s", reply)
|
|
// }
|
|
// if err := tutLocalRpc.Call("APIerSv2.GetAccounts", utils.AttrGetAccounts{Tenant: attrs.Tenant, AccountIds: []string{attrs.Account}}, &acnts); err != nil {
|
|
// t.Error(err)
|
|
// } else if len(acnts) != 1 {
|
|
// t.Errorf("Accounts received: %+v", acnts)
|
|
// } else {
|
|
// acnt := acnts[0]
|
|
// dta, _ := utils.NewTAFromAccountKey(acnt.ID)
|
|
// if dta.Tenant != attrs.Tenant || dta.Account != attrs.Account {
|
|
// t.Error("Unexpected account id received: ", acnt.ID)
|
|
// }
|
|
// if balances := acnt.BalanceMap["*monetary"]; len(balances) != 1 {
|
|
// t.Errorf("Unexpected balances found: %+v", balances)
|
|
// }
|
|
// if len(acnt.ActionTriggers) != 4 {
|
|
// t.Errorf("Unexpected action triggers for account: %+v", acnt.ActionTriggers)
|
|
// }
|
|
// if !acnt.AllowNegative {
|
|
// t.Error("AllowNegative should be set")
|
|
// }
|
|
// if !acnt.Disabled {
|
|
// t.Error("Disabled should be set")
|
|
// }
|
|
// }
|
|
// attrs = &v2.AttrSetAccount{Tenant: "cgrates.org", Account: "tutacnt1", ActionPlanIDs: &[]string{"PACKAGE_1001"}, ActionTriggerIDs: &[]string{"CDRST1_WARN"}, AllowNegative: utils.BoolPointer(true), Disabled: utils.BoolPointer(true), ReloadScheduler: true}
|
|
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2SetAccount, attrs, &reply); err != nil {
|
|
// t.Error("Got error on APIerSv2.SetAccount: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Errorf("Calling APIerSv2.SetAccount received: %s", reply)
|
|
// }
|
|
// time.Sleep(100*time.Millisecond + time.Duration(**waitRater)*time.Millisecond) // Give time for scheduler to execute topups
|
|
// if err := tutLocalRpc.Call("APIerSv2.GetAccounts", utils.AttrGetAccounts{Tenant: attrs.Tenant, AccountIds: []string{attrs.Account}}, &acnts); err != nil {
|
|
// t.Error(err)
|
|
// } else if len(acnts) != 1 {
|
|
// t.Errorf("Accounts received: %+v", acnts)
|
|
// } else {
|
|
// acnt := acnts[0]
|
|
// dta, _ := utils.NewTAFromAccountKey(acnt.ID)
|
|
// if dta.Tenant != attrs.Tenant || dta.Account != attrs.Account {
|
|
// t.Error("Unexpected account id received: ", acnt.ID)
|
|
// }
|
|
// if balances := acnt.BalanceMap["*monetary"]; len(balances) != 3 {
|
|
// t.Errorf("Unexpected balances found: %+v", balances)
|
|
// }
|
|
// if len(acnt.ActionTriggers) != 7 {
|
|
// t.Errorf("Unexpected action triggers for account: %+v", acnt.ActionTriggers)
|
|
// }
|
|
// if !acnt.AllowNegative {
|
|
// t.Error("AllowNegative should be set")
|
|
// }
|
|
// if !acnt.Disabled {
|
|
// t.Error("Disabled should be set")
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// /*
|
|
// // Make sure all stats queues were updated
|
|
// func TestTutITCdrStatsAfter(t *testing.T) {
|
|
// var statMetrics map[string]float64
|
|
// eMetrics := map[string]float64{engine.ACD: 90.2, engine.ASR: 100, engine.TCC: 1.675, engine.TCD: 451, engine.ACC: 0.335}
|
|
// if err := tutLocalRpc.Call("CDRStatsV1.GetMetrics", v1.AttrGetMetrics{StatsQueueId: "CDRST1"}, &statMetrics); err != nil {
|
|
// t.Error("Calling CDRStatsV1.GetMetrics, got error: ", err.Error())
|
|
// } else if !reflect.DeepEqual(eMetrics, statMetrics) {
|
|
// t.Errorf("Expecting: %v, received: %v", eMetrics, statMetrics)
|
|
// }
|
|
// eMetrics = map[string]float64{engine.ACC: 0.35, engine.ACD: 120, engine.ASR: 100, engine.TCC: 1.675, engine.TCD: 451}
|
|
// if err := tutLocalRpc.Call("CDRStatsV1.GetMetrics", v1.AttrGetMetrics{StatsQueueId: "CDRST_1001"}, &statMetrics); err != nil {
|
|
// t.Error("Calling CDRStatsV1.GetMetrics, got error: ", err.Error())
|
|
// } else if !reflect.DeepEqual(eMetrics, statMetrics) {
|
|
// t.Errorf("Expecting: %v, received: %v", eMetrics, statMetrics)
|
|
// }
|
|
// eMetrics = map[string]float64{engine.TCD: 451, engine.ACC: 0.325, engine.ACD: 90, engine.ASR: 100, engine.TCC: 1.675}
|
|
// if err := tutLocalRpc.Call("CDRStatsV1.GetMetrics", v1.AttrGetMetrics{StatsQueueId: "CDRST_1002"}, &statMetrics); err != nil {
|
|
// t.Error("Calling CDRStatsV1.GetMetrics, got error: ", err.Error())
|
|
// } else if !reflect.DeepEqual(eMetrics, statMetrics) {
|
|
// t.Errorf("Expecting: %v, received: %v", eMetrics, statMetrics)
|
|
// }
|
|
// eMetrics = map[string]float64{engine.TCC: 1.675, engine.TCD: 451, engine.ACC: 0.325, engine.ACD: 90, engine.ASR: 100}
|
|
// if err := tutLocalRpc.Call("CDRStatsV1.GetMetrics", v1.AttrGetMetrics{StatsQueueId: "CDRST_1003"}, &statMetrics); err != nil {
|
|
// t.Error("Calling CDRStatsV1.GetMetrics, got error: ", err.Error())
|
|
// } else if !reflect.DeepEqual(eMetrics, statMetrics) {
|
|
// t.Errorf("Expecting: %v, received: %v", eMetrics, statMetrics)
|
|
// }
|
|
// eMetrics = map[string]float64{engine.TCC: 0.7, engine.TCD: 240, engine.ACC: 0.35, engine.ACD: 120, engine.ASR: 100}
|
|
// if err := tutLocalRpc.Call("CDRStatsV1.GetMetrics", v1.AttrGetMetrics{StatsQueueId: "STATS_SUPPL1"}, &statMetrics); err != nil {
|
|
// t.Error("Calling CDRStatsV1.GetMetrics, got error: ", err.Error())
|
|
// //} else if !reflect.DeepEqual(eMetrics, statMetrics) {
|
|
// // t.Errorf("Expecting: %v, received: %v", eMetrics, statMetrics)
|
|
// }
|
|
// eMetrics = map[string]float64{engine.TCD: 331, engine.ACC: 0.33125, engine.ACD: 82.75, engine.ASR: 100, engine.TCC: 1.325}
|
|
// if err := tutLocalRpc.Call("CDRStatsV1.GetMetrics", v1.AttrGetMetrics{StatsQueueId: "STATS_SUPPL2"}, &statMetrics); err != nil {
|
|
// t.Error("Calling CDRStatsV1.GetMetrics, got error: ", err.Error())
|
|
// } else if !reflect.DeepEqual(eMetrics, statMetrics) {
|
|
// t.Errorf("Expecting: %v, received: %v", eMetrics, statMetrics)
|
|
// }
|
|
// }
|
|
// */
|
|
|
|
// /* FixMe : In CallCost (Timespans) Increments is not populated so does not convert properly CallCost to Event
|
|
|
|
// func TestTutITPrepaidCDRWithSMCost(t *testing.T) {
|
|
// cdr := &engine.CDR{CGRID: utils.Sha1("testprepaid1", time.Date(2016, 4, 6, 13, 29, 24, 0, time.UTC).String()),
|
|
// ToR: utils.VOICE, OriginID: "testprepaid1", OriginHost: "192.168.1.1",
|
|
// Source: "TEST_PREPAID_CDR_SMCOST1", RequestType: utils.META_PREPAID, Tenant: "cgrates.org",
|
|
// RunID: utils.MetaDefault,
|
|
// Category: "call", Account: "1001", Subject: "1001", Destination: "1003",
|
|
// SetupTime: time.Date(2016, 4, 6, 13, 29, 24, 0, time.UTC),
|
|
// AnswerTime: time.Date(2016, 4, 6, 13, 30, 0, 0, time.UTC),
|
|
// Usage: 90 * time.Second,
|
|
// ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}}
|
|
|
|
// cc := &engine.CallCost{
|
|
// Category: "call",
|
|
// Account: "1001",
|
|
// Subject: "1001",
|
|
// Tenant: "cgrates.org",
|
|
// Destination: "1003",
|
|
// Timespans: []*engine.TimeSpan{
|
|
// &engine.TimeSpan{
|
|
// TimeStart: time.Date(2016, 4, 6, 13, 30, 0, 0, time.UTC),
|
|
// TimeEnd: time.Date(2016, 4, 6, 13, 31, 30, 0, time.UTC),
|
|
// DurationIndex: 0,
|
|
// RateInterval: &engine.RateInterval{
|
|
// Rating: &engine.RIRate{
|
|
// Rates: engine.RateGroups{
|
|
// &engine.Rate{
|
|
// GroupIntervalStart: 0,
|
|
// Value: 0.01,
|
|
// RateIncrement: 10 * time.Second,
|
|
// RateUnit: time.Second}}}},
|
|
// },
|
|
// },
|
|
// ToR: utils.VOICE}
|
|
// smCost := &engine.SMCost{CGRID: cdr.CGRID,
|
|
// RunID: utils.MetaDefault,
|
|
// OriginHost: cdr.OriginHost,
|
|
// OriginID: cdr.OriginID,
|
|
// CostSource: "TestTutITPrepaidCDRWithSMCost",
|
|
// Usage: cdr.Usage,
|
|
// CostDetails: engine.NewEventCostFromCallCost(cc, cdr.CGRID, utils.MetaDefault),
|
|
// }
|
|
// var reply string
|
|
// if err := tutLocalRpc.Call("CdrsV1.StoreSMCost", &engine.AttrCDRSStoreSMCost{Cost: smCost}, &reply); err != nil {
|
|
// t.Error("Unexpected error: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Error("Unexpected reply received: ", reply)
|
|
// }
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.CDRsV1ProcessCDR, cdr, &reply); err != nil {
|
|
// t.Error("Unexpected error: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Error("Unexpected reply received: ", reply)
|
|
// }
|
|
// time.Sleep(time.Duration(**waitRater) * time.Millisecond) // Give time for CDR to be processed
|
|
// var cdrs []*engine.ExternalCDR
|
|
// req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, CGRIDs: []string{cdr.CGRID}}
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2GetCDRs, 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].OriginID != cdr.OriginID {
|
|
// t.Errorf("Unexpected OriginID for Cdr received: %+v", cdrs[0].OriginID)
|
|
// }
|
|
// if cdrs[0].Cost != 0.9 {
|
|
// t.Errorf("Unexpected Cost for Cdr received: %+v", utils.ToJSON(cdrs[0].Cost))
|
|
// }
|
|
// }
|
|
// }
|
|
// */
|
|
|
|
// func TestTutITPrepaidCDRWithoutSMCost(t *testing.T) {
|
|
// cdr := &engine.CDR{CGRID: utils.Sha1("testprepaid2", time.Date(2016, 4, 6, 13, 29, 24, 0, time.UTC).String()),
|
|
// ToR: utils.VOICE, OriginID: "testprepaid2", OriginHost: "192.168.1.1", Source: "TEST_PREPAID_CDR_NO_SMCOST1", RequestType: utils.META_PREPAID,
|
|
// Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1003",
|
|
// SetupTime: time.Date(2016, 4, 6, 13, 29, 24, 0, time.UTC), AnswerTime: time.Date(2016, 4, 6, 13, 30, 0, 0, time.UTC),
|
|
// Usage: 90 * time.Second,
|
|
// ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}}
|
|
// var reply string
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.CDRsV1ProcessCDR, cdr, &reply); err != nil {
|
|
// t.Error("Unexpected error: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Error("Unexpected reply received: ", reply)
|
|
// }
|
|
// /*
|
|
// time.Sleep(7000 * time.Millisecond) // Give time for CDR to be processed
|
|
// var cdrs []*engine.ExternalCDR
|
|
// req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, CGRIDs: []string{cdr.CGRID}}
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2GetCDRs, 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].OriginID != cdr.OriginID {
|
|
// t.Errorf("Unexpected OriginID for Cdr received: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].Cost != 0.9 {
|
|
// t.Errorf("Unexpected Cost for Cdr received: %+v", cdrs[0])
|
|
// }
|
|
// }
|
|
// */
|
|
// }
|
|
|
|
// func TestTutITExportCDR(t *testing.T) {
|
|
// cdr := &engine.CDR{ToR: utils.VOICE, OriginID: "testexportcdr1", OriginHost: "192.168.1.1", Source: "TestTutITExportCDR", RequestType: utils.MetaRated,
|
|
// Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1003",
|
|
// SetupTime: time.Date(2016, 11, 30, 17, 5, 24, 0, time.UTC), AnswerTime: time.Date(2016, 11, 30, 17, 6, 4, 0, time.UTC),
|
|
// Usage: 98 * time.Second,
|
|
// ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}}
|
|
// cdr.ComputeCGRID()
|
|
// var reply string
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.CDRsV1ProcessCDR, cdr, &reply); err != nil {
|
|
// t.Error("Unexpected error: ", err.Error())
|
|
// } else if reply != utils.OK {
|
|
// t.Error("Unexpected reply received: ", reply)
|
|
// }
|
|
// time.Sleep(50 * time.Millisecond) // Give time for CDR to be processed
|
|
// var cdrs []*engine.ExternalCDR
|
|
// req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, CGRIDs: []string{cdr.CGRID}}
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2GetCDRs, 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].OriginID != cdr.OriginID {
|
|
// t.Errorf("Unexpected OriginID for Cdr received: %+v", cdrs[0])
|
|
// }
|
|
// if cdrs[0].Cost != 1.3334 {
|
|
// t.Errorf("Unexpected Cost for Cdr received: %+v", cdrs[0])
|
|
// }
|
|
// }
|
|
// var replyExport v1.RplExportedCDRs
|
|
// exportArgs := v1.ArgExportCDRs{
|
|
// ExportPath: utils.StringPointer("/tmp"),
|
|
// ExportFileName: utils.StringPointer("TestTutITExportCDR.csv"),
|
|
// ExportTemplate: utils.StringPointer("TestTutITExportCDR"),
|
|
// RPCCDRsFilter: utils.RPCCDRsFilter{CGRIDs: []string{cdr.CGRID}, NotRunIDs: []string{utils.MetaRaw}}}
|
|
// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv1ExportCDRs, exportArgs, &replyExport); err != nil {
|
|
// t.Error(err)
|
|
// }
|
|
// eExportContent := `f0a92222a7d21b4d9f72744aabe82daef52e20d8,*default,testexportcdr1,*rated,cgrates.org,call,1001,1003,2016-11-30T18:06:04+01:00,98,1.33340,RETA
|
|
// f0a92222a7d21b4d9f72744aabe82daef52e20d8,derived_run1,testexportcdr1,*rated,cgrates.org,call,1001,1003,2016-11-30T18:06:04+01:00,98,1.33340,RETA
|
|
// `
|
|
// eExportContent2 := `f0a92222a7d21b4d9f72744aabe82daef52e20d8,derived_run1,testexportcdr1,*rated,cgrates.org,call,1001,1003,2016-11-30T18:06:04+01:00,98,1.33340,RETA
|
|
// f0a92222a7d21b4d9f72744aabe82daef52e20d8,*default,testexportcdr1,*rated,cgrates.org,call,1001,1003,2016-11-30T18:06:04+01:00,98,1.33340,RETA
|
|
// `
|
|
// expFilePath := path.Join(*exportArgs.ExportPath, *exportArgs.ExportFileName)
|
|
// if expContent, err := os.ReadFile(expFilePath); err != nil {
|
|
// t.Error(err)
|
|
// } else if eExportContent != string(expContent) && eExportContent2 != string(expContent) { // CDRs are showing up randomly so we cannot predict order of export
|
|
// t.Errorf("Expecting: <%q> or <%q> received: <%q>", eExportContent, eExportContent2, string(expContent))
|
|
// }
|
|
// if err := os.Remove(expFilePath); err != nil {
|
|
// t.Error(err)
|
|
// }
|
|
|
|
// }
|
|
|
|
// func TestTutITStopCgrEngine(t *testing.T) {
|
|
// if err := engine.KillEngine(1000); err != nil {
|
|
// t.Error(err)
|
|
// }
|
|
// }
|