Files
cgrates/dispatchers/replicator_it_test.go
ionutboangiu 47af22c724 Update rpcclient library to latest version
`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.
2023-09-01 11:23:54 +02:00

1470 lines
52 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 dispatchers
import (
"reflect"
"testing"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var sTestsDspRpl = []func(t *testing.T){
testDspRplPingFailover,
testDspRplAccount,
testDspRplSupplierProfile,
testDspRplAttributeProfile,
testDspRplChargerProfile,
testDspRplDispatcherProfile,
testDspRplDispatcherHost,
testDspRplFilter,
testDspRplThreshold,
testDspRplThresholdProfile,
testDspRplStatQueue,
testDspRplStatQueueProfile,
testDspRplResource,
testDspRplResourceProfile,
testDspRplTiming,
testDspRplActionTriggers,
testDspRplSharedGroup,
testDspRplActions,
testDspRplActionPlan,
// testDspRplAccountActionPlans,
testDspRplRatingPlan,
testDspRplRatingProfile,
testDspRplDestination,
}
// Test start here
func TestDspReplicator(t *testing.T) {
var config1, config2, config3 string
switch *dbType {
case utils.MetaInternal:
t.SkipNow()
case utils.MetaMySQL:
config1 = "all_mysql"
config2 = "all2_mysql"
config3 = "dispatchers_mysql"
case utils.MetaMongo:
config1 = "all_mongo"
config2 = "all2_mongo"
config3 = "dispatchers_mongo"
case utils.MetaPostgres:
t.SkipNow()
default:
t.Fatal("Unknown Database type")
}
dispDIR := "dispatchers"
if *encoding == utils.MetaGOB {
dispDIR += "_gob"
}
testDsp(t, sTestsDspRpl, "TestDspReplicator", config1, config2, config3, "tutorial", "oldtutorial", dispDIR)
}
func testDspRplPingFailover(t *testing.T) {
var reply string
if err := allEngine.RPC.Call(context.Background(), utils.ReplicatorSv1Ping, new(utils.CGREvent), &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
reply = utils.EmptyString
if err := allEngine2.RPC.Call(context.Background(), utils.ReplicatorSv1Ping, new(utils.CGREvent), &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
reply = utils.EmptyString
ev := utils.CGREvent{
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1Ping, &ev, &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
allEngine.stopEngine(t)
reply = utils.EmptyString
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1Ping, &ev, &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
allEngine2.stopEngine(t)
reply = utils.EmptyString
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1Ping, &ev, &reply); err == nil {
t.Errorf("Expected error but received %v and reply %v\n", err, reply)
}
allEngine.startEngine(t)
allEngine2.startEngine(t)
reply = utils.EmptyString
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1Ping, &ev, &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
}
func testDspRplAccount(t *testing.T) {
// Set
var replyStr string
attrSetAccount := &engine.AccountWithAPIOpts{
Account: &engine.Account{
ID: "cgrates.org:1008",
AllowNegative: true,
Disabled: true,
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetAccount, attrSetAccount, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetAccount: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get
var reply *engine.Account
argsGetAccount := &utils.StringWithAPIOpts{
Arg: "cgrates.org:1008",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAccount, argsGetAccount, &reply); err != nil {
t.Errorf("Expecting: %+v, received: %+v", utils.ErrNotFound, err)
} else if reply.ID != attrSetAccount.Account.ID {
t.Errorf("Expecting: %+v, received: %+v", attrSetAccount.Account.ID, reply.ID)
} else if reply.AllowNegative != true {
t.Errorf("Expecting: true, received: %+v", reply.AllowNegative)
} else if reply.Disabled != true {
t.Errorf("Expecting: true, received: %+v", reply.Disabled)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAccount, argsGetAccount, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove Account
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveAccount, &utils.StringWithAPIOpts{
Arg: "cgrates.org:1008",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get Account
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAccount, argsGetAccount, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplSupplierProfile(t *testing.T) {
// Set RouteProfile
var replyStr string
argSetSupplierProfile := &engine.RouteProfileWithAPIOpts{
RouteProfile: &engine.RouteProfile{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetRouteProfile, argSetSupplierProfile, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetSupplierProfile: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get RouteProfile
var reply *engine.RouteProfile
argRouteProfile := &utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRouteProfile, argRouteProfile, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetSupplierProfile: ", err)
} else if reply.ID != argSetSupplierProfile.ID {
t.Errorf("Expecting: %+v, received: %+v", argSetSupplierProfile.ID, reply.ID)
} else if reply.Tenant != argSetSupplierProfile.Tenant {
t.Errorf("Expecting: %+v, received: %+v", argSetSupplierProfile.Tenant, reply.Tenant)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get RouteProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRouteProfile, argRouteProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove SupplierProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveRouteProfile, argRouteProfile, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get RouteProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRouteProfile, argRouteProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplAttributeProfile(t *testing.T) {
// Set AttributeProfile
var replyStr string
setAttributeProfile := &engine.AttributeProfileWithAPIOpts{
AttributeProfile: &engine.AttributeProfile{
Tenant: "cgrates.org",
ID: "id",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetAttributeProfile, setAttributeProfile, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetAttributeProfile: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get AttributeProfile
var reply engine.AttributeProfile
argAttributeProfile := &utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "id",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAttributeProfile, argAttributeProfile, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetAttributeProfile: ", err)
} else if reply.ID != setAttributeProfile.ID {
t.Errorf("Expecting: %+v, received: %+v", setAttributeProfile.ID, reply.ID)
} else if reply.Tenant != setAttributeProfile.Tenant {
t.Errorf("Expecting: %+v, received: %+v", setAttributeProfile.Tenant, reply.Tenant)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get AttributeProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAttributeProfile, argAttributeProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove AttributeProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveAttributeProfile, argAttributeProfile, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get AttributeProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAttributeProfile, argAttributeProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplChargerProfile(t *testing.T) {
// Set ChargerProfile
var replyStr string
setChargerProfile := &engine.ChargerProfileWithAPIOpts{
ChargerProfile: &engine.ChargerProfile{
ID: "id",
Tenant: "cgrates.org",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetChargerProfile, setChargerProfile, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetChargerProfile: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get ChargerProfile
var reply engine.ChargerProfile
argsChargerProfile := &utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "id",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetChargerProfile, argsChargerProfile, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetChargerProfile: ", err)
} else if reply.ID != argsChargerProfile.ID {
t.Errorf("Expecting: %+v, received: %+v", argsChargerProfile.ID, reply.ID)
} else if reply.Tenant != argsChargerProfile.Tenant {
t.Errorf("Expecting: %+v, received: %+v", argsChargerProfile.Tenant, reply.Tenant)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get ChargerProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetChargerProfile, argsChargerProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove ChargerProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveChargerProfile, argsChargerProfile, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get ChargerProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetChargerProfile, argsChargerProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplDispatcherProfile(t *testing.T) {
// Set DispatcherProfile
var replyStr string
setDispatcherProfile := &engine.DispatcherProfileWithAPIOpts{
DispatcherProfile: &engine.DispatcherProfile{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetDispatcherProfile, setDispatcherProfile, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetDispatcherProfile: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get DispatcherProfile
var reply engine.DispatcherProfile
argsDispatcherProfile := &utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDispatcherProfile, argsDispatcherProfile, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetDispatcherProfile: ", err)
} else if reply.ID != argsDispatcherProfile.ID {
t.Errorf("Expecting: %+v, received: %+v", argsDispatcherProfile.ID, reply.ID)
} else if reply.Tenant != argsDispatcherProfile.Tenant {
t.Errorf("Expecting: %+v, received: %+v", argsDispatcherProfile.Tenant, reply.Tenant)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get DispatcherProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDispatcherProfile, argsDispatcherProfile, &reply); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove DispatcherProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveDispatcherProfile, argsDispatcherProfile, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get DispatcherProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDispatcherProfile, argsDispatcherProfile, &reply); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplDispatcherHost(t *testing.T) {
// Set DispatcherHost
var replyStr string
setDispatcherHost := &engine.DispatcherHostWithAPIOpts{
DispatcherHost: &engine.DispatcherHost{
Tenant: "cgrates.org",
RemoteHost: &config.RemoteHost{
ID: "ID",
},
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetDispatcherHost, setDispatcherHost, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetDispatcherHost: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get DispatcherHost
var reply engine.DispatcherHost
argsDispatcherHost := &utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDispatcherHost, argsDispatcherHost, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetDispatcherHost: ", err)
} else if reply.ID != argsDispatcherHost.ID {
t.Errorf("Expecting: %+v, received: %+v", argsDispatcherHost.ID, reply.ID)
} else if reply.Tenant != argsDispatcherHost.Tenant {
t.Errorf("Expecting: %+v, received: %+v", argsDispatcherHost.Tenant, reply.Tenant)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get DispatcherHost
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDispatcherHost, argsDispatcherHost, &reply); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove DispatcherHost
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveDispatcherHost, argsDispatcherHost, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get DispatcherHost
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDispatcherHost, argsDispatcherHost, &reply); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplFilter(t *testing.T) {
// Set Filter
var replyStr string
setFilter := &engine.FilterWithAPIOpts{
Filter: &engine.Filter{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetFilter, setFilter, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetFilter: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get Filter
var reply engine.Filter
argsFilter := &utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetFilter, argsFilter, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetFilter: ", err)
} else if reply.ID != argsFilter.ID {
t.Errorf("Expecting: %+v, received: %+v", argsFilter.ID, reply.ID)
} else if reply.Tenant != argsFilter.Tenant {
t.Errorf("Expecting: %+v, received: %+v", argsFilter.Tenant, reply.Tenant)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get Filter
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetFilter, argsFilter, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove Filter
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveFilter, argsFilter, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get Filter
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetFilter, argsFilter, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplThreshold(t *testing.T) {
// Set Threshold
var replyStr string
setThreshold := &engine.ThresholdWithAPIOpts{
Threshold: &engine.Threshold{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetThreshold, setThreshold, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetThreshold: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get Threshold
var reply engine.Threshold
argsThreshold := &utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetThreshold, argsThreshold, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetThreshold: ", err)
} else if reply.ID != argsThreshold.ID {
t.Errorf("Expecting: %+v, received: %+v", argsThreshold.ID, reply.ID)
} else if reply.Tenant != argsThreshold.Tenant {
t.Errorf("Expecting: %+v, received: %+v", argsThreshold.Tenant, reply.Tenant)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get Threshold
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetThreshold, argsThreshold, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove Threshold
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveThreshold, argsThreshold, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get Threshold
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetThreshold, argsThreshold, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplThresholdProfile(t *testing.T) {
// Set ThresholdProfile
var replyStr string
setThresholdProfile := &engine.ThresholdProfileWithAPIOpts{
ThresholdProfile: &engine.ThresholdProfile{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetThresholdProfile, setThresholdProfile, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetThresholdProfile: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get ThresholdProfile
var reply engine.ThresholdProfile
argsThresholdProfile := &utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetThresholdProfile, argsThresholdProfile, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetThresholdProfile: ", err)
} else if reply.ID != argsThresholdProfile.ID {
t.Errorf("Expecting: %+v, received: %+v", argsThresholdProfile.ID, reply.ID)
} else if reply.Tenant != argsThresholdProfile.Tenant {
t.Errorf("Expecting: %+v, received: %+v", argsThresholdProfile.Tenant, reply.Tenant)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get ThresholdProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetThresholdProfile, argsThresholdProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove ThresholdProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveThresholdProfile, argsThresholdProfile, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get ThresholdProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetThresholdProfile, argsThresholdProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplStatQueue(t *testing.T) {
// Set StatQueue
var replyStr string
setStatQueue := &engine.StatQueueWithAPIOpts{
StatQueue: &engine.StatQueue{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetStatQueue, setStatQueue, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetStatQueue: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get StatQueue
var reply engine.StatQueue
argsStatQueue := &utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueue, argsStatQueue, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetStatQueue: ", err)
} else if reply.ID != argsStatQueue.ID {
t.Errorf("Expecting: %+v, received: %+v", argsStatQueue.ID, reply.ID)
} else if reply.Tenant != argsStatQueue.Tenant {
t.Errorf("Expecting: %+v, received: %+v", argsStatQueue.Tenant, reply.Tenant)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get StatQueue
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueue, argsStatQueue, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove StatQueue
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveStatQueue, argsStatQueue, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get StatQueue
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueue, argsStatQueue, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplStatQueueProfile(t *testing.T) {
// Set StatQueueProfile
var replyStr string
setStatQueueProfile := &engine.StatQueueProfileWithAPIOpts{
StatQueueProfile: &engine.StatQueueProfile{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetStatQueueProfile, setStatQueueProfile, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetStatQueueProfile: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get StatQueueProfile
var reply engine.StatQueueProfile
argsStatQueueProfile := &utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueueProfile, argsStatQueueProfile, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetStatQueueProfile: ", err)
} else if reply.ID != argsStatQueueProfile.ID {
t.Errorf("Expecting: %+v, received: %+v", argsStatQueueProfile.ID, reply.ID)
} else if reply.Tenant != argsStatQueueProfile.Tenant {
t.Errorf("Expecting: %+v, received: %+v", argsStatQueueProfile.Tenant, reply.Tenant)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get StatQueueProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueueProfile, argsStatQueueProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove StatQueueProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveStatQueueProfile, argsStatQueueProfile, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get StatQueueProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueueProfile, argsStatQueueProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplResource(t *testing.T) {
// Set Resource
var replyStr string
setResource := &engine.ResourceWithAPIOpts{
Resource: &engine.Resource{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetResource, setResource, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetResource: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get Resource
var reply engine.Resource
argsResource := &utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetResource, argsResource, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetResource: ", err)
} else if reply.ID != argsResource.ID {
t.Errorf("Expecting: %+v, received: %+v", argsResource.ID, reply.ID)
} else if reply.Tenant != argsResource.Tenant {
t.Errorf("Expecting: %+v, received: %+v", argsResource.Tenant, reply.Tenant)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get Resource
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetResource, argsResource, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove Resource
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveResource, argsResource, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get Resource
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetResource, argsResource, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplResourceProfile(t *testing.T) {
// Set ResourceProfile
var replyStr string
setResourceProfile := &engine.ResourceProfileWithAPIOpts{
ResourceProfile: &engine.ResourceProfile{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetResourceProfile, setResourceProfile, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetResourceProfile: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get ResourceProfile
var reply engine.ResourceProfile
argsResourceProfile := &utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "ID",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetResourceProfile, argsResourceProfile, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetResourceProfile: ", err)
} else if reply.ID != argsResourceProfile.ID {
t.Errorf("Expecting: %+v, received: %+v", argsResourceProfile.ID, reply.ID)
} else if reply.Tenant != argsResourceProfile.Tenant {
t.Errorf("Expecting: %+v, received: %+v", argsResourceProfile.Tenant, reply.Tenant)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get ResourceProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetResourceProfile, argsResourceProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove ResourceProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveResourceProfile, argsResourceProfile, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get ResourceProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetResourceProfile, argsResourceProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplTiming(t *testing.T) {
// Set Timing
var replyStr string
setTiming := &utils.TPTimingWithAPIOpts{
TPTiming: &utils.TPTiming{
ID: "testTimings",
Years: utils.Years{1999},
},
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetTiming, setTiming, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetTiming: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get Timing
var reply utils.TPTiming
argsTiming := &utils.StringWithAPIOpts{
Arg: "testTimings",
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetTiming, argsTiming, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetTiming: ", err)
} else if reply.ID != argsTiming.Arg {
t.Errorf("Expecting: %+v, received: %+v", argsTiming.Arg, reply.ID)
} else if reply.Years[0] != 1999 {
t.Errorf("Expecting: %+v, received: %+v", utils.Years{1999}, reply.Years)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get Timing
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetTiming, argsTiming, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove Timing
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveTiming, argsTiming, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get Timing
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetTiming, argsTiming, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplActionTriggers(t *testing.T) {
// Set ActionTriggers
var replyStr string
setActionTriggers := &engine.SetActionTriggersArgWithAPIOpts{
Key: "testActionTriggers",
Attrs: engine.ActionTriggers{
&engine.ActionTrigger{ID: "testActionTriggers"}},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetActionTriggers, setActionTriggers, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetActionTriggers: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get ActionTriggers
var reply engine.ActionTriggers
argsActionTriggers := &utils.StringWithAPIOpts{
Arg: "testActionTriggers",
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActionTriggers, argsActionTriggers, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetActionTriggers: ", err)
} else if reply[0].ID != argsActionTriggers.Arg {
t.Errorf("Expecting: %+v, received: %+v", argsActionTriggers.Arg, reply[0].ID)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get ActionTriggers
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActionTriggers, argsActionTriggers, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove ActionTriggers
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveActionTriggers, argsActionTriggers, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get ActionTriggers
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActionTriggers, argsActionTriggers, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplSharedGroup(t *testing.T) {
// Set SharedGroup
var replyStr string
setSharedGroup := &engine.SharedGroupWithAPIOpts{
SharedGroup: &engine.SharedGroup{
Id: "IDSharedGroup",
},
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetSharedGroup, setSharedGroup, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetSharedGroup: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get SharedGroup
var reply engine.SharedGroup
argsSharedGroup := &utils.StringWithAPIOpts{
Arg: "IDSharedGroup",
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetSharedGroup, argsSharedGroup, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetSharedGroup: ", err)
} else if reply.Id != setSharedGroup.Id {
t.Errorf("Expecting: %+v, received: %+v", setSharedGroup.Id, reply.Id)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get SharedGroup
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetSharedGroup, argsSharedGroup, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove SharedGroup
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveSharedGroup, argsSharedGroup, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get SharedGroup
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetSharedGroup, argsSharedGroup, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplActions(t *testing.T) {
// Set Actions
var replyStr string
setActions := &engine.SetActionsArgsWithAPIOpts{
Acs: engine.Actions{
&engine.Action{
Id: "Action1",
ActionType: utils.MetaLog,
},
},
Key: "KeyActions",
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetActions, setActions, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetActions: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get Actions
var reply engine.Actions
argsActions := &utils.StringWithAPIOpts{
Arg: "KeyActions",
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActions, argsActions, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetActions: ", err)
} else if reply[0].Id != setActions.Acs[0].Id {
t.Errorf("Expecting: %+v, received: %+v", setActions.Acs[0].Id, reply[0].Id)
} else if len(reply) != len(setActions.Acs) {
t.Errorf("Expecting: %+v, received: %+v", len(setActions.Acs), len(reply))
}
// Stop engine 1
allEngine.stopEngine(t)
// Get Actions
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActions, argsActions, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove Actions
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveActions, argsActions, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get Actions
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActions, argsActions, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplActionPlan(t *testing.T) {
// Set ActionPlan
var replyStr string
setActionPlan := &engine.SetActionPlanArgWithAPIOpts{
Ats: &engine.ActionPlan{
Id: "idtas",
AccountIDs: utils.StringMap{
"AccountTest": true,
},
ActionTimings: []*engine.ActionTiming{
{
ActionsID: "ActionsID",
},
},
},
Key: "KeyActionPlan",
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetActionPlan, setActionPlan, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetActionPlan: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get ActionPlan
var reply engine.ActionPlan
argsActionPlan := &utils.StringWithAPIOpts{
Arg: "KeyActionPlan",
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActionPlan, argsActionPlan, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetActionPlan: ", err)
} else if reply.Id != setActionPlan.Ats.Id {
t.Errorf("Expecting: %+v, received: %+v", setActionPlan.Ats.Id, reply.Id)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get ActionPlan
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActionPlan, argsActionPlan, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove ActionPlan
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveActionPlan, argsActionPlan, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get ActionPlan
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActionPlan, argsActionPlan, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplAccountActionPlans(t *testing.T) {
// Set AccountActionPlans
var replyStr string
setAccountActionPlans := &engine.SetAccountActionPlansArgWithAPIOpts{
AplIDs: []string{"KeyAccountActionPlans"},
AcntID: "KeyAccountActionPlans",
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetAccountActionPlans, setAccountActionPlans, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetAccountActionPlans: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get AccountActionPlans
var reply []string
argsAccountActionPlans := &utils.StringWithAPIOpts{
Arg: "KeyAccountActionPlans",
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAccountActionPlans, argsAccountActionPlans, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetAccountActionPlans: ", err)
} else if reply[0] != setAccountActionPlans.AcntID {
t.Errorf("Expecting: %+v, received: %+v", setAccountActionPlans.AcntID, reply[0])
}
// Stop engine 1
allEngine.stopEngine(t)
// Get AccountActionPlans
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAccountActionPlans, argsAccountActionPlans, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove AccountActionPlans
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemAccountActionPlans, argsAccountActionPlans, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get AccountActionPlans
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAccountActionPlans, argsAccountActionPlans, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplRatingPlan(t *testing.T) {
// Set RatingPlan
var replyStr string
setRatingPlan := &engine.RatingPlanWithAPIOpts{
RatingPlan: &engine.RatingPlan{
Id: "id",
DestinationRates: map[string]engine.RPRateList{
"DestinationRates": {&engine.RPRate{Rating: "Rating"}}},
Ratings: map[string]*engine.RIRate{"Ratings": {ConnectFee: 0.7}},
Timings: map[string]*engine.RITiming{"Timings": {Months: utils.Months{4}}},
},
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetRatingPlan, setRatingPlan, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetRatingPlan: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get RatingPlan
var reply engine.RatingPlan
argsRatingPlan := &utils.StringWithAPIOpts{
Arg: "id",
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRatingPlan, argsRatingPlan, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetRatingPlan: ", err)
} else if reply.Id != setRatingPlan.Id {
t.Errorf("Expecting: %+v, received: %+v", setRatingPlan.Id, reply.Id)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get RatingPlan
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRatingPlan, argsRatingPlan, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove RatingPlan
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveRatingPlan, argsRatingPlan, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get RatingPlan
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRatingPlan, argsRatingPlan, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplRatingProfile(t *testing.T) {
// Set RatingProfile
var replyStr string
setRatingProfile := &engine.RatingProfileWithAPIOpts{
RatingProfile: &engine.RatingProfile{
Id: "idRatingProfile",
RatingPlanActivations: engine.RatingPlanActivations{
&engine.RatingPlanActivation{RatingPlanId: "RatingPlanId"}},
},
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetRatingProfile, setRatingProfile, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetRatingProfile: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get RatingProfile
var reply engine.RatingProfile
argsRatingProfile := &utils.StringWithAPIOpts{
Arg: "idRatingProfile",
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRatingProfile, argsRatingProfile, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetRatingProfile: ", err)
} else if reply.Id != setRatingProfile.Id {
t.Errorf("Expecting: %+v, received: %+v", setRatingProfile.Id, reply.Id)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get RatingProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRatingProfile, argsRatingProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove RatingProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveRatingProfile, argsRatingProfile, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get RatingProfile
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRatingProfile, argsRatingProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
// Destination
func testDspRplDestination(t *testing.T) {
// Set Destination
var replyStr string
setDestination := &engine.DestinationWithAPIOpts{
Destination: &engine.Destination{
Id: "idDestination"},
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetDestination, setDestination, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetDestination: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get Destination
var reply engine.Destination
argsDestination := &utils.StringWithAPIOpts{
Arg: "idDestination",
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDestination, argsDestination, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetDestination: ", err)
} else if reply.Id != setDestination.Id {
t.Errorf("Expecting: %+v, received: %+v", setDestination.Id, reply.Id)
}
// Stop engine 1
allEngine.stopEngine(t)
// Get Destination
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDestination, argsDestination, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
// Remove Destination
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveDestination, argsDestination, &replyStr); err != nil {
t.Error(err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get Destination
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDestination, argsDestination, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
}
func testDspRplLoadIDs(t *testing.T) {
// Set LoadIDs
var replyStr string
setLoadIDs := &utils.LoadIDsWithAPIOpts{
LoadIDs: map[string]int64{
"LoadID1": 1,
"LoadID2": 2},
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetLoadIDs, setLoadIDs, &replyStr); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.SetLoadIDs: ", err)
} else if replyStr != utils.OK {
t.Error("Unexpected reply returned", replyStr)
}
// Get LoadIDs
var reply map[string]int64
argsLoadIDs := &utils.StringWithAPIOpts{
Arg: "idLoadIDs",
Tenant: "cgrates.org",
APIOpts: map[string]any{
utils.OptsAPIKey: "repl12345",
},
}
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetItemLoadIDs, argsLoadIDs, &reply); err != nil {
t.Error("Unexpected error when calling ReplicatorSv1.GetItemLoadIDs: ", err)
} else if reflect.DeepEqual(reply, setLoadIDs) {
t.Errorf("Expecting: %+v, received: %+v", setLoadIDs, reply)
} else if len(reply) != len(setLoadIDs.LoadIDs) {
t.Errorf("Expecting: %+v, received: %+v, ", len(setLoadIDs.LoadIDs), len(reply))
} else if reply["LoadID1"] != setLoadIDs.LoadIDs["LoadID1"] {
t.Errorf("Expecting: %+v, received: %+v, ", setLoadIDs.LoadIDs["LoadID1"], reply["LoadID1"])
}
// Stop engine 1
allEngine.stopEngine(t)
// Get LoadIDs
if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetItemLoadIDs, argsLoadIDs, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
}
// Start engine 1
allEngine.startEngine(t)
}