From 18c5e3d8bcee5cab2e34d8d36cd580589a0252b3 Mon Sep 17 00:00:00 2001 From: adi Date: Fri, 16 Sep 2022 17:22:54 +0300 Subject: [PATCH] Disaptcher opts tests --- .../conf/samples/dispatcher_opts/cgrates.json | 22 +++----- .../dispatcher_opts_admin/cgrates.json | 15 +++++- general_tests/dispatcher_opts_it_test.go | 52 ++++++++++++++++--- 3 files changed, 68 insertions(+), 21 deletions(-) diff --git a/data/conf/samples/dispatcher_opts/cgrates.json b/data/conf/samples/dispatcher_opts/cgrates.json index 520866a8e..694551dd7 100644 --- a/data/conf/samples/dispatcher_opts/cgrates.json +++ b/data/conf/samples/dispatcher_opts/cgrates.json @@ -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: "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": { diff --git a/data/conf/samples/dispatcher_opts_admin/cgrates.json b/data/conf/samples/dispatcher_opts_admin/cgrates.json index 94f6ca7ea..58a0723cf 100644 --- a/data/conf/samples/dispatcher_opts_admin/cgrates.json +++ b/data/conf/samples/dispatcher_opts_admin/cgrates.json @@ -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"}, + ], + }, + }, } \ No newline at end of file diff --git a/general_tests/dispatcher_opts_it_test.go b/general_tests/dispatcher_opts_it_test.go index 1c7d3b6c1..3e8fd7cf4 100644 --- a/general_tests/dispatcher_opts_it_test.go +++ b/general_tests/dispatcher_opts_it_test.go @@ -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)