Add it test for rpc exporter opts (final)

This commit is contained in:
ionutboangiu
2022-03-04 16:36:43 +02:00
committed by Dan Christian Bogos
parent 4a2b8ff6e1
commit c9ea90014e
6 changed files with 326 additions and 74 deletions

View File

@@ -0,0 +1,81 @@
{
"general": {
"log_level": 7,
"reply_timeout": "50s"
},
"listen": {
"rpc_json": ":2012",
"rpc_gob": ":2013",
"http": ":2080"
},
"data_db": {
"db_type": "mongo",
"db_name": "10",
"db_port": 27017
},
"stor_db": {
"db_type": "mongo",
"db_name": "cgrates",
"db_port": 27017
},
"ees": {
"enabled": true,
"exporters": [
{
"id": "thProcessEv1",
"type": "*rpc",
"opts": {
"rpcCodec": "*json",
"connIDs": ["rplConn"],
"serviceMethod": "ThresholdSv1.ProcessEvent",
"keyPath": "" ,
"certPath": "",
"caPath": "",
"tls": false,
"rpcConnTimeout" : "1s",
"rpcReplyTimeout":"5s"
}
},
{
"id": "thProcessEv2",
"type": "*rpc",
"opts": {
"rpcCodec": "*json",
"connIDs": ["rplConn"],
"serviceMethod": "ThresholdSv1.ProcessEvent",
"keyPath": "" ,
"certPath": "",
"caPath": "",
"tls": false,
"rpcConnTimeout" : "1s",
"rpcReplyTimeout":"5s",
"rpcAPIOpts": {
"*thdProfileIDs": ["THD_3"]
}
}
}
]
},
"rpc_conns": {
"rplConn": {
"strategy": "*broadcast_sync",
"conns": [{"address": "127.0.0.1:22012", "transport": "*json"}]
}
},
"sessions": {
"enabled": true,
"replication_conns": ["rplConn"]
},
"admins": {
"enabled": true
}
}

View File

@@ -0,0 +1,78 @@
{
"general": {
"log_level": 7,
"reply_timeout": "50s"
},
"listen": {
"rpc_json": ":2012",
"rpc_gob": ":2013",
"http": ":2080"
},
"data_db": {
"db_type": "redis",
"db_port": 6379,
"db_name": "10"
},
"stor_db": {
"db_password": "CGRateS.org"
},
"ees": {
"enabled": true,
"exporters": [
{
"id": "thProcessEv1",
"type": "*rpc",
"opts": {
"rpcCodec": "*json",
"connIDs": ["rplConn"],
"serviceMethod": "ThresholdSv1.ProcessEvent",
"keyPath": "" ,
"certPath": "",
"caPath": "",
"tls": false,
"rpcConnTimeout" : "1s",
"rpcReplyTimeout":"5s"
}
},
{
"id": "thProcessEv2",
"type": "*rpc",
"opts": {
"rpcCodec": "*json",
"connIDs": ["rplConn"],
"serviceMethod": "ThresholdSv1.ProcessEvent",
"keyPath": "" ,
"certPath": "",
"caPath": "",
"tls": false,
"rpcConnTimeout" : "1s",
"rpcReplyTimeout":"5s",
"rpcAPIOpts": {
"*thdProfileIDs": ["THD_3"]
}
}
}
]
},
"rpc_conns": {
"rplConn": {
"strategy": "*broadcast_sync",
"conns": [{"address": "127.0.0.1:22012", "transport": "*json"}]
}
},
"sessions": {
"enabled": true,
"replication_conns": ["rplConn"]
},
"admins": {
"enabled": true
}
}

View File

@@ -22,7 +22,7 @@
"enabled":true,
"store_interval": "-1",
"opts":{
"*thresholdsIDs": [
"*profileIDs": [
{
"Tenant": "",
"FilterIDs": [],

View File

@@ -0,0 +1,49 @@
{
"general": {
"log_level": 7,
"reply_timeout": "50s"
},
"listen": {
"rpc_json": ":22012",
"rpc_gob": ":22013",
"http": ":22080"
},
"data_db": {
"db_type": "mongo",
"db_name": "10",
"db_port": 27017
},
"stor_db": {
"db_type": "mongo",
"db_name": "cgrates",
"db_port": 27017
},
"thresholds": {
"enabled":true,
"store_interval": "-1",
"opts":{
"*profileIDs": [
{
"Tenant": "",
"FilterIDs": [],
"Value": ["THD_1"]
}
]
}
},
"sessions": {
"enabled": true,
"listen_bijson": "127.0.0.1:22014"
},
"admins": {
"enabled": true
}
}

View File

@@ -0,0 +1,46 @@
{
"general": {
"log_level": 7,
"reply_timeout": "50s"
},
"listen": {
"rpc_json": ":22012",
"rpc_gob": ":22013",
"http": ":22080"
},
"data_db": {
"db_type": "redis",
"db_port": 6379,
"db_name": "10"
},
"stor_db": {
"db_password": "CGRateS.org"
},
"thresholds": {
"enabled":true,
"store_interval": "-1",
"opts":{
"*profileIDs": [
{
"Tenant": "",
"FilterIDs": [],
"Value": ["THD_1"]
}
]
}
},
"sessions": {
"enabled": true,
"listen_bijson": "127.0.0.1:22014"
},
"admins": {
"enabled": true
}
}

View File

@@ -45,8 +45,8 @@ var (
testRPCExpStartEngine,
testRPCExpRPCConn,
testRPCExpSetThresholdProfilesBeforeProcessEv,
// testRPCExpProcessEventWithConfigOpts,
// testRPCExpGetThresholdsAfterFirstEvent,
testRPCExpProcessEventWithConfigOpts,
testRPCExpGetThresholdsAfterFirstEvent,
testRPCExpProcessEventWithAPIOpts,
testRPCExpGetThresholdsAfterSecondEvent,
testRPCExpProcessEventWithRPCAPIOpts,
@@ -61,13 +61,11 @@ func TestRPCExpIT(t *testing.T) {
ng1ConfDIR = "rpcexp_opts_engine1_internal"
ng2ConfDIR = "rpcexp_opts_engine2_internal"
case utils.MetaMySQL:
t.SkipNow()
// ng1ConfDIR = "rpcexp_opts_engine1_mysql"
// ng2ConfDIR = "rpcexp_opts_engine2_mysql"
ng1ConfDIR = "rpcexp_opts_engine1_mysql"
ng2ConfDIR = "rpcexp_opts_engine2_mysql"
case utils.MetaMongo:
t.SkipNow()
// ng1ConfDIR = "rpcexp_opts_engine1_mongo"
// ng2ConfDIR = "rpcexp_opts_engine2_mongo"
ng1ConfDIR = "rpcexp_opts_engine1_mongo"
ng2ConfDIR = "rpcexp_opts_engine2_mongo"
case utils.MetaPostgres:
t.SkipNow()
default:
@@ -205,72 +203,72 @@ func testRPCExpSetThresholdProfilesBeforeProcessEv(t *testing.T) {
}
}
// func testRPCExpProcessEventWithConfigOpts(t *testing.T) {
// args := utils.CGREventWithEeIDs{
// EeIDs: []string{"thProcessEv1"},
// CGREvent: &utils.CGREvent{
// Tenant: "cgrates.org",
// ID: "ThresholdProcessEv1",
// Event: map[string]interface{}{
// utils.AccountField: "1001",
// },
// APIOpts: map[string]interface{}{},
// },
// }
// var reply map[string]map[string]interface{}
// if err := ng1RPC.Call(context.Background(), utils.EeSv1ProcessEvent, args, &reply); err != nil {
// t.Error(err)
// }
// time.Sleep(50 * time.Millisecond)
func testRPCExpProcessEventWithConfigOpts(t *testing.T) {
args := utils.CGREventWithEeIDs{
EeIDs: []string{"thProcessEv1"},
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
ID: "ThresholdProcessEv1",
Event: map[string]interface{}{
utils.AccountField: "1001",
},
APIOpts: map[string]interface{}{},
},
}
var reply map[string]map[string]interface{}
if err := ng1RPC.Call(context.Background(), utils.EeSv1ProcessEvent, args, &reply); err != nil {
t.Error(err)
}
time.Sleep(50 * time.Millisecond)
// }
}
// func testRPCExpGetThresholdsAfterFirstEvent(t *testing.T) {
// args := &utils.CGREvent{
// Tenant: "cgrates.org",
// ID: "ThresholdEventTest1",
// Event: map[string]interface{}{
// utils.AccountField: "1001",
// },
// APIOpts: map[string]interface{}{
// utils.OptsThresholdsProfileIDs: []string{"THD_1", "THD_2", "THD_3"},
// },
// }
// expThs := engine.Thresholds{
// &engine.Threshold{
// Tenant: "cgrates.org",
// ID: "THD_1",
// Hits: 1,
// },
// &engine.Threshold{
// Tenant: "cgrates.org",
// ID: "THD_2",
// Hits: 0,
// },
// &engine.Threshold{
// Tenant: "cgrates.org",
// ID: "THD_3",
// Hits: 0,
// },
// }
func testRPCExpGetThresholdsAfterFirstEvent(t *testing.T) {
args := &utils.CGREvent{
Tenant: "cgrates.org",
ID: "ThresholdEventTest1",
Event: map[string]interface{}{
utils.AccountField: "1001",
},
APIOpts: map[string]interface{}{
utils.OptsThresholdsProfileIDs: []string{"THD_1", "THD_2", "THD_3"},
},
}
expThs := engine.Thresholds{
&engine.Threshold{
Tenant: "cgrates.org",
ID: "THD_1",
Hits: 1,
},
&engine.Threshold{
Tenant: "cgrates.org",
ID: "THD_2",
Hits: 0,
},
&engine.Threshold{
Tenant: "cgrates.org",
ID: "THD_3",
Hits: 0,
},
}
// var rplyThs engine.Thresholds
// if err := ng2RPC.Call(context.Background(), utils.ThresholdSv1GetThresholdsForEvent,
// args, &rplyThs); err != nil {
// t.Error(err)
// } else {
// sort.Slice(rplyThs, func(i, j int) bool {
// return rplyThs[i].ID < rplyThs[j].ID
// })
// for idx, thd := range rplyThs {
// thd.Snooze = expThs[idx].Snooze
// }
// if !reflect.DeepEqual(rplyThs, expThs) {
// t.Errorf("expected: <%+v>, \nreceived: <%+v>",
// utils.ToJSON(expThs), utils.ToJSON(rplyThs))
// }
// }
// }
var rplyThs engine.Thresholds
if err := ng2RPC.Call(context.Background(), utils.ThresholdSv1GetThresholdsForEvent,
args, &rplyThs); err != nil {
t.Error(err)
} else {
sort.Slice(rplyThs, func(i, j int) bool {
return rplyThs[i].ID < rplyThs[j].ID
})
for idx, thd := range rplyThs {
thd.Snooze = expThs[idx].Snooze
}
if !reflect.DeepEqual(rplyThs, expThs) {
t.Errorf("expected: <%+v>, \nreceived: <%+v>",
utils.ToJSON(expThs), utils.ToJSON(rplyThs))
}
}
}
func testRPCExpProcessEventWithAPIOpts(t *testing.T) {
args := utils.CGREventWithEeIDs{
@@ -308,7 +306,7 @@ func testRPCExpGetThresholdsAfterSecondEvent(t *testing.T) {
&engine.Threshold{
Tenant: "cgrates.org",
ID: "THD_1",
// Hits: 1,
Hits: 1,
},
&engine.Threshold{
Tenant: "cgrates.org",
@@ -376,7 +374,7 @@ func testRPCExpGetThresholdsAfterThirdEvent(t *testing.T) {
&engine.Threshold{
Tenant: "cgrates.org",
ID: "THD_1",
// Hits: 1,
Hits: 1,
},
&engine.Threshold{
Tenant: "cgrates.org",