Disaptcher opts tests

This commit is contained in:
adi
2022-09-16 17:22:54 +03:00
committed by Dan Christian Bogos
parent e494e1d270
commit 18c5e3d8bc
3 changed files with 68 additions and 21 deletions

View File

@@ -5,7 +5,12 @@
"log_level": 7,
},
"listen": {
"rpc_json": ":2012", // RPC JSON listening address
"rpc_gob": ":2013", // RPC GOB listening address
"http": ":2080", // HTTP listening address
},
"data_db": { // database used to store runtime data (eg: accounts, cdr stats)
"db_type": "redis", // data_db type: <redis|mongo>
"db_port": 6379, // data_db port to reach the database
@@ -17,20 +22,9 @@
},
"dispatchers":{
"dispatchers":{
"enabled": true,
// "attributes_conns": ["*internal"],
"opts": { //
// "*dispatcherS": [
// {
// "Tenant": "*any",
// "FilterIDs": [],
// "Value": false,
// },
// ],
},
},
},
"admins": {

View File

@@ -18,10 +18,23 @@
"db_name": "10", // data_db database name to connect to
},
/* "dispatchers":{
"enabled": true,
}, */
"admins": {
"enabled": true,
"caches_conns":["broadcast_cache"],
},
"rpc_conns": {
"broadcast_cache": {
"strategy": "*broadcast",
"conns": [
{"address": "127.0.0.1:2012", "transport":"*json"},
{"address": "127.0.0.1:4012", "transport":"*json"},
],
},
},
}

View File

@@ -58,12 +58,14 @@ var (
testDispatcherOptsAdminSetDispatcherHost4012,
testDispatcherOptsCoreStatusHost4012,
testDispatcherOptsAdminSetDispatcherHostWithRouteID,
testDispatcherOptsAdminSetDispatcherProfileDoubleHost,
testDispatcherOptsCoreStatusWithRouteID,
testDispatcherOptsAdminSetDispatcherHostInexistent,
testDispatcherOptsCoreStatusWithRouteID2,
testDispatcherOptsCoreStatusWithoutRouteID,
testDispatcherOptsDSPStopEngine,
testDispatcherOptsAdminStopEngine,
}
@@ -114,7 +116,7 @@ func testDispatcherOptsAdminSetDispatcherProfile(t *testing.T) {
Tenant: "cgrates.org",
RemoteHost: &config.RemoteHost{
ID: "SELF_ENGINE",
Address: "*localhost",
Address: "*internal",
Transport: "*json",
ConnectAttempts: 1,
Reconnects: 3,
@@ -122,6 +124,9 @@ func testDispatcherOptsAdminSetDispatcherProfile(t *testing.T) {
ReplyTimeout: 2 * time.Minute,
},
},
APIOpts: map[string]interface{}{
utils.MetaDispatchers: false,
},
}
if err := adminsRPC.Call(context.Background(), utils.AdminSv1SetDispatcherHost, setDispatcherHost, &replyStr); err != nil {
t.Error("Unexpected error when calling AdminSv1.SetDispatcherHost: ", err)
@@ -143,6 +148,9 @@ func testDispatcherOptsAdminSetDispatcherProfile(t *testing.T) {
},
},
},
APIOpts: map[string]interface{}{
utils.MetaDispatchers: false,
},
}
if err := adminsRPC.Call(context.Background(), utils.AdminSv1SetDispatcherProfile, setDispatcherProfile, &replyStr); err != nil {
t.Error("Unexpected error when calling AdminSv1.SetDispatcherProfile: ", err)
@@ -177,6 +185,7 @@ func testDispatcherOptsDSPRPCConn(t *testing.T) {
}
func testDispatcherOptsCoreStatus(t *testing.T) {
//SELF_ENGINE HOST
var reply map[string]interface{}
ev := utils.TenantWithAPIOpts{
Tenant: "cgrates.org",
@@ -209,6 +218,9 @@ func testDispatcherOptsAdminSetDispatcherHost4012(t *testing.T) {
ReplyTimeout: 2 * time.Minute,
},
},
APIOpts: map[string]interface{}{
utils.MetaDispatchers: false,
},
}
if err := adminsRPC.Call(context.Background(), utils.AdminSv1SetDispatcherHost, setDispatcherHost, &replyStr); err != nil {
t.Error("Unexpected error when calling AdminSv1.SetDispatcherHost: ", err)
@@ -230,6 +242,9 @@ func testDispatcherOptsAdminSetDispatcherHost4012(t *testing.T) {
},
},
},
APIOpts: map[string]interface{}{
utils.MetaDispatchers: false,
},
}
if err := adminsRPC.Call(context.Background(), utils.AdminSv1SetDispatcherProfile, setDispatcherProfile, &replyStr); err != nil {
t.Error("Unexpected error when calling AdminSv1.SetDispatcherProfile: ", err)
@@ -253,8 +268,7 @@ func testDispatcherOptsCoreStatusHost4012(t *testing.T) {
}
}
func testDispatcherOptsAdminSetDispatcherHostWithRouteID(t *testing.T) {
var replyStr string
func testDispatcherOptsAdminSetDispatcherProfileDoubleHost(t *testing.T) {
// Set DispatcherProfile with both engines
setDispatcherProfile := &engine.DispatcherProfileWithAPIOpts{
DispatcherProfile: &engine.DispatcherProfile{
@@ -273,7 +287,11 @@ func testDispatcherOptsAdminSetDispatcherHostWithRouteID(t *testing.T) {
},
},
},
APIOpts: map[string]interface{}{
utils.MetaDispatchers: false,
},
}
var replyStr string
if err := adminsRPC.Call(context.Background(), utils.AdminSv1SetDispatcherProfile, setDispatcherProfile, &replyStr); err != nil {
t.Error("Unexpected error when calling AdminSv1.SetDispatcherProfile: ", err)
} else if replyStr != utils.OK {
@@ -315,6 +333,9 @@ func testDispatcherOptsAdminSetDispatcherHostInexistent(t *testing.T) {
ReplyTimeout: 2 * time.Minute,
},
},
APIOpts: map[string]interface{}{
utils.MetaDispatchers: false,
},
}
if err := adminsRPC.Call(context.Background(), utils.AdminSv1SetDispatcherHost, setDispatcherHost, &replyStr); err != nil {
t.Error("Unexpected error when calling AdminSv1.SetDispatcherHost: ", err)
@@ -326,7 +347,7 @@ func testDispatcherOptsAdminSetDispatcherHostInexistent(t *testing.T) {
setDispatcherProfile := &engine.DispatcherProfileWithAPIOpts{
DispatcherProfile: &engine.DispatcherProfile{
Tenant: "cgrates.org",
ID: "DSP2",
ID: "DSP1",
Strategy: "*weight",
Weight: 20,
Hosts: engine.DispatcherHostProfiles{
@@ -336,6 +357,9 @@ func testDispatcherOptsAdminSetDispatcherHostInexistent(t *testing.T) {
},
},
},
APIOpts: map[string]interface{}{
utils.MetaDispatchers: false,
},
}
if err := adminsRPC.Call(context.Background(), utils.AdminSv1SetDispatcherProfile, setDispatcherProfile, &replyStr); err != nil {
t.Error("Unexpected error when calling AdminSv1.SetDispatcherProfile: ", err)
@@ -345,7 +369,7 @@ func testDispatcherOptsAdminSetDispatcherHostInexistent(t *testing.T) {
}
func testDispatcherOptsCoreStatusWithRouteID2(t *testing.T) {
// even if DSP2 must be the dispatcher matching, because we have the routeID it will match DSP1
// because we have the routeID it will match DSP1 and last host matched, host4012
// so again, both engines will match
var reply map[string]interface{}
ev := utils.TenantWithAPIOpts{
@@ -363,6 +387,22 @@ func testDispatcherOptsCoreStatusWithRouteID2(t *testing.T) {
}
}
func testDispatcherOptsCoreStatusWithoutRouteID(t *testing.T) {
// because we have the routeID it will match DSP1 and last host matched, host4012
// so again, both engines will match
var reply map[string]interface{}
ev := utils.TenantWithAPIOpts{
Tenant: "cgrates.org",
}
if err := dspOptsRPC.Call(context.Background(), utils.CoreSv1Status, &ev, &reply); err != nil {
t.Error(err)
} else {
/*
t.Errorf("Received: %s", utils.ToJSON(reply))
*/
}
}
func testDispatcherOptsDSPStopEngine(t *testing.T) {
if err := engine.KillEngine(*waitRater); err != nil {
t.Error(err)